-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Framework - Support named export codemod (#11688)
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env node | ||
|
||
/* | ||
This codemod generates named exports given a `default export { ... }`. | ||
How to use: | ||
./bin/codemods/commonjs-exports-named path-to-transform/ | ||
*/ | ||
|
||
const path = require( 'path' ); | ||
const child_process = require( 'child_process' ); | ||
|
||
const args = process.argv.slice( 2 ); | ||
if ( args.length === 0 ) { | ||
process.stdout.write( 'No files to transform\n' ); | ||
process.exit( 0 ); | ||
} | ||
|
||
const binArgs = [ | ||
'-t', | ||
'node_modules/5to6-codemod/transforms/named-export-generation.js', | ||
'--extensions=js,jsx', | ||
args[0], | ||
]; | ||
const binPath = path.join( '.', 'node_modules', '.bin', 'jscodeshift' ) | ||
const jscodeshift = child_process.spawn( binPath, binArgs ); | ||
|
||
jscodeshift.stdout.on( 'data', ( data ) => { | ||
process.stdout.write( data ); | ||
}); | ||
|
||
jscodeshift.stderr.on( 'data', ( data ) => { | ||
process.stderr.write( data ); | ||
}); |