File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,9 +25,12 @@ module.exports.handler = function handler(options) {
2525 scripts : {
2626 test : 'codemod-cli test' ,
2727 } ,
28+ bin : './bin/cli.js' ,
2829 keywords : [ 'codemod-cli' ] ,
29- devDependencies : {
30+ dependencies : {
3031 'codemod-cli' : `^${ pkg . version } ` ,
32+ } ,
33+ devDependencies : {
3134 jest : pkg . devDependencies . jest ,
3235 } ,
3336 } ,
@@ -60,5 +63,22 @@ module.exports.handler = function handler(options) {
6063 - yarn test
6164 `
6265 ) ;
66+ fs . outputFileSync (
67+ projectName + '/bin/cli.js' ,
68+ stripIndent `
69+ #!/usr/bin/env node
70+ 'use strict';
71+
72+ require('codemod-cli').runTransform(
73+ __dirname,
74+ process.argv[2] /* transform name */,
75+ process.argv.slice(2) /* paths or globs */
76+ )
77+ ` ,
78+ {
79+ encoding : 'utf8' ,
80+ mode : 0o755 /* -rwxr-xr-x */ ,
81+ }
82+ ) ;
6383 fs . ensureFileSync ( projectName + '/transforms/.gitkeep' ) ;
6484} ;
Original file line number Diff line number Diff line change @@ -165,4 +165,47 @@ QUnit.module('codemod-cli', function(hooks) {
165165 ) ;
166166 } ) ;
167167 } ) ;
168+
169+ QUnit . module ( 'programmatic API' , function ( hooks ) {
170+ setupProject ( hooks ) ;
171+
172+ QUnit . module ( 'runTransform' , function ( hooks ) {
173+ let userProject ;
174+
175+ hooks . beforeEach (
176+ wrap ( function * ( ) {
177+ // includes simple identifier reverser
178+ yield execa ( EXECUTABLE_PATH , [ 'generate' , 'codemod' , 'main' ] ) ;
179+
180+ userProject = yield createTempDir ( ) ;
181+ process . chdir ( userProject . path ( ) ) ;
182+ } )
183+ ) ;
184+
185+ hooks . afterEach ( function ( ) {
186+ return userProject . dispose ( ) ;
187+ } ) ;
188+
189+ QUnit . test (
190+ 'runs transform' ,
191+ wrap ( function * ( assert ) {
192+ userProject . write ( {
193+ foo : {
194+ 'something.js' : 'let blah = bar' ,
195+ 'other.js' : 'let blah = bar' ,
196+ } ,
197+ } ) ;
198+
199+ yield CodemodCLI . runTransform ( codemodProject . path ( 'bin' ) , 'main' , 'foo/*thing.js' ) ;
200+
201+ assert . deepEqual ( userProject . read ( ) , {
202+ foo : {
203+ 'something.js' : 'let halb = rab' ,
204+ 'other.js' : 'let blah = bar' ,
205+ } ,
206+ } ) ;
207+ } )
208+ ) ;
209+ } ) ;
210+ } ) ;
168211} ) ;
You can’t perform that action at this time.
0 commit comments