From 8da83317ba5575d683c0bc8a94acf079f372fbef Mon Sep 17 00:00:00 2001 From: Kipras Melnikovas Date: Wed, 3 Nov 2021 18:20:40 +0200 Subject: [PATCH 1/2] feat: allow specifying multiple transforms maybe would be nicer if the interface would be `-t t1 -t t2 -t t3` instead of current `-t t1,t2,t3` (you could separate into multiple lines and keep it cleaner), but don't know how to do that so this works just fine. Signed-off-by: Kipras Melnikovas --- packages/cli/src/index.ts | 2 +- packages/cli/src/main.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) 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) { From 2f5f72f988a95e7f9e3f4a4a1f4f7a5f986e3087 Mon Sep 17 00:00:00 2001 From: Daniel Del Core Date: Mon, 3 Jan 2022 12:38:11 +1100 Subject: [PATCH 2/2] docs + changeset --- .changeset/rotten-pears-count.md | 5 +++++ website/docs/api/codeshift-cli.mdx | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/rotten-pears-count.md 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/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