Skip to content

Commit

Permalink
Rename CLI file
Browse files Browse the repository at this point in the history
The file extension .js is more correct. Leaving the .sh for backwards
compatibility.
  • Loading branch information
fkling committed Dec 3, 2018
1 parent a2becc5 commit 8eb9825
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 115 deletions.
127 changes: 127 additions & 0 deletions bin/jscodeshift.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/usr/bin/env node
/*
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

'use strict';

const Runner = require('../src/Runner.js');

const path = require('path');
const pkg = require('../package.json');
const parser = require('../src/argsParser')
.options({
transform: {
abbr: 't',
default: './transform.js',
help: 'path to the transform file. Can be either a local path or url',
metavar: 'FILE',
required: true
},
cpus: {
abbr: 'c',
help: 'start at most N child processes to process source files',
defaultHelp: 'max(all - 1, 1)',
metavar: 'N',
},
verbose: {
abbr: 'v',
choices: [0, 1, 2],
default: 0,
help: 'show more information about the transform process',
metavar: 'N',
},
dry: {
abbr: 'd',
flag: true,
default: false,
help: 'dry run (no changes are made to files)'
},
print: {
abbr: 'p',
flag: true,
default: false,
help: 'print transformed files to stdout, useful for development'
},
babel: {
flag: true,
default: true,
help: 'apply babeljs to the transform file'
},
extensions: {
default: 'js',
help: 'transform files with these file extensions (comma separated list)',
metavar: 'EXT',
},
ignorePattern: {
full: 'ignore-pattern',
list: true,
help: 'ignore files that match a provided glob expression',
metavar: 'GLOB',
},
ignoreConfig: {
full: 'ignore-config',
list: true,
help: 'ignore files if they match patterns sourced from a configuration file (e.g. a .gitignore)',
metavar: 'FILE'
},
runInBand: {
flag: true,
default: false,
full: 'run-in-band',
help: 'run serially in the current process'
},
silent: {
abbr: 's',
flag: true,
default: false,
help: 'do not write to stdout or stderr'
},
parser: {
choices: ['babel', 'babylon', 'flow', 'ts', 'tsx'],
default: 'babel',
help: 'the parser to use for parsing the source files'
},
version: {
help: 'print version and exit',
callback: function() {
const requirePackage = require('../utils/requirePackage');
return [
`jscodeshift: ${pkg.version}`,
` - babel: ${require('babel-core').version}`,
` - babylon: ${requirePackage('@babel/parser').version}`,
` - flow: ${requirePackage('flow-parser').version}`,
` - recast: ${requirePackage('recast').version}\n`,
].join('\n');
},
},
});

let options, positionalArguments;
try {
({options, positionalArguments} = parser.parse());
if (positionalArguments.length === 0) {
process.stderr.write(
'Error: You have to provide at least one file/directory to transform.' +
'\n\n---\n\n' +
parser.getHelpText()
);
process.exit(1);
}
} catch(e) {
const exitCode = e.exitCode === undefined ? 1 : e.exitCode;
(exitCode ? process.stderr : process.stdout).write(e.message);
process.exit(exitCode);
}

Runner.run(
/^https?/.test(options.transform) ? options.transform : path.resolve(options.transform),
positionalArguments,
options
);
115 changes: 1 addition & 114 deletions bin/jscodeshift.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,117 +11,4 @@

'use strict';

const Runner = require('../src/Runner.js');

const path = require('path');
const pkg = require('../package.json');
const parser = require('../src/argsParser')
.options({
transform: {
abbr: 't',
default: './transform.js',
help: 'path to the transform file. Can be either a local path or url',
metavar: 'FILE',
required: true
},
cpus: {
abbr: 'c',
help: 'start at most N child processes to process source files',
defaultHelp: 'max(all - 1, 1)',
metavar: 'N',
},
verbose: {
abbr: 'v',
choices: [0, 1, 2],
default: 0,
help: 'show more information about the transform process',
metavar: 'N',
},
dry: {
abbr: 'd',
flag: true,
default: false,
help: 'dry run (no changes are made to files)'
},
print: {
abbr: 'p',
flag: true,
default: false,
help: 'print transformed files to stdout, useful for development'
},
babel: {
flag: true,
default: true,
help: 'apply babeljs to the transform file'
},
extensions: {
default: 'js',
help: 'transform files with these file extensions (comma separated list)',
metavar: 'EXT',
},
ignorePattern: {
full: 'ignore-pattern',
list: true,
help: 'ignore files that match a provided glob expression',
metavar: 'GLOB',
},
ignoreConfig: {
full: 'ignore-config',
list: true,
help: 'ignore files if they match patterns sourced from a configuration file (e.g. a .gitignore)',
metavar: 'FILE'
},
runInBand: {
flag: true,
default: false,
full: 'run-in-band',
help: 'run serially in the current process'
},
silent: {
abbr: 's',
flag: true,
default: false,
help: 'do not write to stdout or stderr'
},
parser: {
choices: ['babel', 'babylon', 'flow', 'ts', 'tsx'],
default: 'babel',
help: 'the parser to use for parsing the source files'
},
version: {
help: 'print version and exit',
callback: function() {
const requirePackage = require('../utils/requirePackage');
return [
`jscodeshift: ${pkg.version}`,
` - babel: ${require('babel-core').version}`,
` - babylon: ${requirePackage('@babel/parser').version}`,
` - flow: ${requirePackage('flow-parser').version}`,
` - recast: ${requirePackage('recast').version}\n`,
].join('\n');
},
},
});

let options, positionalArguments;
try {
({options, positionalArguments} = parser.parse());
if (positionalArguments.length === 0) {
process.stderr.write(
'Error: You have to provide at least one file/directory to transform.' +
'\n\n---\n\n' +
parser.getHelpText()
);
process.exit(1);
}
} catch(e) {
const exitCode = e.exitCode === undefined ? 1 : e.exitCode;
(exitCode ? process.stderr : process.stdout).write(e.message);
process.exit(exitCode);
}

Runner.run(
/^https?/.test(options.transform) ? options.transform : path.resolve(options.transform),
positionalArguments,
options
);
require('./jscodeshift.js');
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"docs": "rm -rf docs && jsdoc -d docs -R README.md src/collections/* src/core.js src/Collection.js"
},
"bin": {
"jscodeshift": "./bin/jscodeshift.sh"
"jscodeshift": "./bin/jscodeshift.js"
},
"engines": {
"node": ">=4"
Expand Down

0 comments on commit 8eb9825

Please sign in to comment.