Skip to content

Commit

Permalink
Framework: Refactor 5to6 codemod config (#12520)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnmoon committed Apr 13, 2017
1 parent 7f1dc5d commit d58bfd7
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 20 deletions.
14 changes: 14 additions & 0 deletions bin/codemods/5to6-common-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const jscodeshiftArgs = [
'--extensions=js,jsx',
'--verbose=2',
];

const recastArgs = [
'--useTabs=true',
'--arrayBracketSpacing=true',
];

module.exports = {
jscodeshiftArgs,
recastArgs,
};
21 changes: 16 additions & 5 deletions bin/codemods/commonjs-exports
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,32 @@
./bin/codemods/commonjs-exports path-to-transform/
*/

/**
* External dependencies
*/
const path = require( 'path' );
const child_process = require( 'child_process' );

/**
* Internal dependencies
*/
const config = require( './5to6-common-config' );

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/exports.js',
'--extensions=js,jsx',
'--useTabs=true',
'--arrayBracketSpacing=true',
// jscodeshift options
'--transform=node_modules/5to6-codemod/transforms/exports.js',
...config.jscodeshiftArgs,

// Recast options via 5to6
...config.recastArgs,

// Transform target
args[ 0 ],
];
const binPath = path.join( '.', 'node_modules', '.bin', 'jscodeshift' );
Expand Down
21 changes: 16 additions & 5 deletions bin/codemods/commonjs-imports
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,32 @@
./bin/codemods/commonjs-imports path-to-transform/
*/

/**
* External dependencies
*/
const path = require( 'path' );
const child_process = require( 'child_process' );

/**
* Internal dependencies
*/
const config = require( './5to6-common-config' );

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/cjs.js',
'--extensions=js,jsx',
'--useTabs=true',
'--arrayBracketSpacing=true',
// jscodeshift options
'--transform=node_modules/5to6-codemod/transforms/cjs.js',
...config.jscodeshiftArgs,

// Recast options via 5to6
...config.recastArgs,

// Transform target
args[ 0 ],
];
const binPath = path.join( '.', 'node_modules', '.bin', 'jscodeshift' );
Expand Down
23 changes: 18 additions & 5 deletions bin/codemods/commonjs-imports-hoist
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,35 @@
./bin/codemods/commonjs-imports path-to-transform/
*/

/**
* External dependencies
*/
const path = require( 'path' );
const child_process = require( 'child_process' );

/**
* Internal dependencies
*/
const config = require( './5to6-common-config' );

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/cjs.js',
'--extensions=js,jsx',
'--useTabs=true',
'--arrayBracketSpacing=true',
// jscodeshift options
'--transform=node_modules/5to6-codemod/transforms/cjs.js',
...config.jscodeshiftArgs,

// Recast options via 5to6
...config.recastArgs,

// 5to6 transform options
'--hoist=true',

// Transform target
args[ 0 ],
];
const binPath = path.join( '.', 'node_modules', '.bin', 'jscodeshift' );
Expand Down
21 changes: 16 additions & 5 deletions bin/codemods/named-exports-from-default
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,32 @@
./bin/codemods/named-export-from-default path-to-transform/
*/

/**
* External dependencies
*/
const path = require( 'path' );
const child_process = require( 'child_process' );

/**
* Internal dependencies
*/
const config = require( './5to6-common-config' );

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',
'--useTabs=true',
'--arrayBracketSpacing=true',
// jscodeshift options
'--transform=node_modules/5to6-codemod/transforms/named-export-generation.js',
...config.jscodeshiftArgs,

// Recast options via 5to6
...config.recastArgs,

// Transform target
args[ 0 ],
];
const binPath = path.join( '.', 'node_modules', '.bin', 'jscodeshift' );
Expand Down

0 comments on commit d58bfd7

Please sign in to comment.