Skip to content

Feat/allow specifying multiple transforms #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you cannot leave spaces between the commas since separate arguments will be parsed, and ofc we rely on it being a single argument and we're splitting it by , - thus you'll need to change it to:

Suggested change
- `$ codeshift-cli --transform path/to/transform1.ts, path/to/transform2.ts, path/to/transform3.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