Skip to content

Commit

Permalink
Merge pull request #80 from CodeshiftCommunity/feat/allow-specifying-…
Browse files Browse the repository at this point in the history
…multiple-transforms

Feat/allow specifying multiple transforms
  • Loading branch information
danieldelcore authored Jan 3, 2022
2 parents 26e4a04 + 2f5f72f commit 8ab5311
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-pears-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@codeshift/cli': minor
---

Adds the ability to specify a comma seperated list of transforms via the -t flag
2 changes: 1 addition & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ program
.usage('[global options] <file-paths>...')
.option(
'-t, --transform <value>',
'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 <value>',
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion website/docs/api/codeshift-cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8ab5311

Please sign in to comment.