diff --git a/.changeset/rotten-pears-count.md b/.changeset/rotten-pears-count.md new file mode 100644 index 000000000..0fae03a49 --- /dev/null +++ b/.changeset/rotten-pears-count.md @@ -0,0 +1,5 @@ +--- +'@codeshift/cli': minor +--- + +Adds the ability to specify a comma seperated list of transforms via the -t flag diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index b5ee325f2..08fc7ea69 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -16,7 +16,7 @@ program .usage('[global options] ...') .option( '-t, --transform ', - 'The transform to run, will prompt for a transform if not provided and no module is passed', + 'The transform(s) to run, will prompt for a transform if not provided and no module is passed\nTo provide multiple transforms, separate them with commas (e.g. "-t t1,t2,t3")', ) .option( '--packages ', diff --git a/packages/cli/src/main.ts b/packages/cli/src/main.ts index e35ac4eeb..94eefa873 100644 --- a/packages/cli/src/main.ts +++ b/packages/cli/src/main.ts @@ -94,7 +94,11 @@ export default async function main(paths: string[], flags: Flags) { } if (flags.transform) { - transforms.push(flags.transform); + if (flags.transform.includes(',')) { + flags.transform.split(',').forEach(t => transforms.push(t.trim())); + } else { + transforms.push(flags.transform); + } } if (flags.packages) { diff --git a/website/docs/api/codeshift-cli.mdx b/website/docs/api/codeshift-cli.mdx index adca44a9d..258267311 100644 --- a/website/docs/api/codeshift-cli.mdx +++ b/website/docs/api/codeshift-cli.mdx @@ -39,12 +39,16 @@ and run with: ### --transform, -t -The transform to run, transforms can be either a single file or directory with an index. +Allows you to execute local transform file(s). + +- Can be provided with a comma-separated list (see example below). +- Transforms can be either a single file or directory containing an "index" file. **example:** - `$ codeshift-cli --transform codemods/my-special-mod /project/src/file.js` - `$ codeshift-cli --transform codemods/my-special-mod/index.ts /project/src/file.js` +- `$ codeshift-cli --transform path/to/transform1.ts, path/to/transform2.ts, path/to/transform3.ts /project/src/file.js` ### --packages