Skip to content

Commit

Permalink
Add --ignore-pattern option to CLI (#17)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Silbermann <sebastian.silbermann@klarna.com>
  • Loading branch information
eps1lon and Sebastian Silbermann committed Apr 5, 2022
1 parent 2c214c7 commit 0ea3337
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-suits-pretend.md
@@ -0,0 +1,5 @@
---
"types-react-codemod": minor
---

Add `--ignore-pattern` option to CLI
10 changes: 8 additions & 2 deletions README.md
Expand Up @@ -17,10 +17,16 @@ Positionals:
paths [string] [required]

Options:
--version Show version number [boolean]
--help Show help [boolean]
--version Show version number [boolean]
--help Show help [boolean]
--dry [boolean] [default: false]
--ignore-pattern [string] [default: "**/node_modules/**"]
--verbose [boolean] [default: false]

Examples:
types-react-codemod preset-18 ./ Ignores `node_modules` and `build`
--ignore-pattern folders
"**/{node_modules,build}/**"
```

## Available transforms
Expand Down
43 changes: 27 additions & 16 deletions bin/types-react-codemod.cjs
Expand Up @@ -25,21 +25,32 @@ async function main() {
"$0 <codemod> <paths...>",
"",
(builder) => {
return builder
.positional("codemod", {
choices: transforms,
type: "string",
})
.positional("paths", {
array: true,
type: "string",
})
.option("dry", {
default: false,
type: "boolean",
})
.option("verbose", { default: false, type: "boolean" })
.demandOption(["codemod", "paths"]);
return (
builder
.positional("codemod", {
choices: transforms,
type: "string",
})
.positional("paths", {
array: true,
type: "string",
})
.option("dry", {
default: false,
type: "boolean",
})
.option("ignore-pattern", {
default: "**/node_modules/**",
type: "string",
})
.option("verbose", { default: false, type: "boolean" })
// Ignoring `build`: https://www.digitalocean.com/community/tools/glob?comments=true&glob=%2A%2A%2F%7Bnode_modules%2Cbuild%7D%2F%2A%2A&matches=false&tests=package%2Fnode_modules%2Ftest.js&tests=package%2Fbuild%2Ftest.js&tests=package%2Ftest.js
.example(
'$0 preset-18 ./ --ignore-pattern "**/{node_modules,build}/**"',
"Ignores `node_modules` and `build` folders"
)
.demandOption(["codemod", "paths"])
);
},
async (argv) => {
const { codemod, dry, paths, verbose } = argv;
Expand All @@ -52,7 +63,7 @@ async function main() {
*/
const args = [
"--extensions=tsx,ts",
"--ignore-pattern=**/node_modules/**",
`"--ignore-pattern=${argv.ignorePattern}"`,
`--transform ${path.join(transformsRoot, `${codemod}.js`)}`,
];

Expand Down

0 comments on commit 0ea3337

Please sign in to comment.