diff --git a/bin/codemods/generate-named-exports-from-default b/bin/codemods/generate-named-exports-from-default new file mode 100755 index 00000000000000..e5b102b320acad --- /dev/null +++ b/bin/codemods/generate-named-exports-from-default @@ -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 ); +});