diff --git a/packages/codemods/README.md b/packages/codemods/README.md index 5db64ededa..9437f7da7c 100644 --- a/packages/codemods/README.md +++ b/packages/codemods/README.md @@ -18,11 +18,11 @@ To view the available arguments for this package, use `-h` or `--help` as shown npx @lmc-eu/spirit-codemods -h ``` -There are **two mandatory arguments**: `-p`/`--path` and `-c`/`--codemod`. +There are **two mandatory arguments**: `-p`/`--path` and `-t`/`--transformation`. The former specifies the directory path where you want to execute transforms, while the latter specifies the desired codemod to run. ```shell -npx @lmc-eu/spirit-codemods -p ./ -c v2/web-react/codemod-name +npx @lmc-eu/spirit-codemods -p ./ -t v2/web-react/codemod-name ``` Other optional arguments include: @@ -31,12 +31,12 @@ Other optional arguments include: - `-h`/`--help` - Displays this message - `-e`/`--extensions` - Extensions of the transformed files, default: `ts,tsx,js,jsx` - `--parser` - Parser to use (babel, ts, tsx, flow), default: `tsx` -- `--ignore-pattern` - Ignore files or directories, default: `**/node_modules/**` +- `--ignore` - Ignore files or directories, default: `**/node_modules/**` For example, this could be the command you will run: ```shell -npx @lmc-eu/spirit-codemods -p ./src -c v2/web-react/button-text -e js,jsx --parser babel +npx @lmc-eu/spirit-codemods -p ./src -t v2/web-react/button-text -e js,jsx --parser babel ``` [jscodeshift]: https://github.com/facebook/jscodeshift diff --git a/packages/codemods/src/cli.ts b/packages/codemods/src/cli.ts index 467e1eecbc..1f8b2cc684 100644 --- a/packages/codemods/src/cli.ts +++ b/packages/codemods/src/cli.ts @@ -11,15 +11,15 @@ export default async function cli(args: string[]) { .describe(packageJson.description) .option('-p, --path', 'Path to the code to be transformed') .example('-p ./') - .option('-c, --codemod', 'Codemod name to run') + .option('-t, --transformation', 'Codemod transformation name to run') .example('-c v2/web-react/codemodName') .option('-e, --extensions', 'Extensions to look for when transforming files, default: ts,tsx,js,jsx') .example('-e ts, tsx, js, jsx') - .option('--ignore-pattern', 'Ignore files or directories, default: **/node_modules/**') + .option('--ignore', 'Ignore files or directories, default: **/node_modules/**') .example('-i **/node_modules/**') .option('--parser', 'Parser to use (babel, ts, tsx, flow), default: tsx') .example('--parser babel') - .action(async ({ path: codePath, codemod, extensions, ignorePattern, parser }) => { + .action(async ({ path: codePath, transformation, extensions, ignore, parser }) => { const defaultExtensions = 'ts,tsx,js,jsx'; const defaultIgnore = '**/node_modules/**'; const defaultParser = 'tsx'; @@ -30,12 +30,12 @@ export default async function cli(args: string[]) { process.exit(1); } - if (!codemod) { + if (!transformation) { errorMessage('Please provide a codemod name'); process.exit(1); } - const codemodPath = path.resolve(_dirname, `./transforms/${codemod}.ts`); + const codemodPath = path.resolve(_dirname, `./transforms/${transformation}.ts`); if (!fs.existsSync(codemodPath)) { errorMessage('Codemod does not exists'); @@ -44,7 +44,7 @@ export default async function cli(args: string[]) { const { stdout } = await $`jscodeshift --transform ${codemodPath} --extensions ${ extensions || defaultExtensions - } --ignore-pattern=${ignorePattern || defaultIgnore} --parser=${parser || defaultParser} ${codePath}`; + } --ignore-pattern=${ignore || defaultIgnore} --parser=${parser || defaultParser} ${codePath}`; // stdout object from jscodeshift logMessage(stdout);