Skip to content

Commit

Permalink
fixup! fixup! fixup! Feat(web-react): Add spirit-codemod package
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelklibani committed Mar 5, 2024
1 parent 3c8b0f9 commit 2a71020
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions packages/codemods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ To view the available arguments for this package, use `-h` or `--help` as shown
npx @lmc-eu/spirit-codemods -h
```

There are **two mandatory arguments**: `-p`/`--path` and `-c`/`--codemod`.
There are **two mandatory arguments**: `-p`/`--path` and `-t`/`--transformation`.
The former specifies the directory path where you want to execute transforms, while the latter specifies the desired codemod to run.

```shell
npx @lmc-eu/spirit-codemods -p ./ -c v2/web-react/codemod-name
npx @lmc-eu/spirit-codemods -p ./ -t v2/web-react/codemod-name
```

Other optional arguments include:
Expand All @@ -31,12 +31,12 @@ Other optional arguments include:
- `-h`/`--help` - Displays this message
- `-e`/`--extensions` - Extensions of the transformed files, default: `ts,tsx,js,jsx`
- `--parser` - Parser to use (babel, ts, tsx, flow), default: `tsx`
- `--ignore-pattern` - Ignore files or directories, default: `**/node_modules/**`
- `--ignore` - Ignore files or directories, default: `**/node_modules/**`

For example, this could be the command you will run:

```shell
npx @lmc-eu/spirit-codemods -p ./src -c v2/web-react/button-text -e js,jsx --parser babel
npx @lmc-eu/spirit-codemods -p ./src -t v2/web-react/button-text -e js,jsx --parser babel
```

[jscodeshift]: https://github.com/facebook/jscodeshift
12 changes: 6 additions & 6 deletions packages/codemods/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export default async function cli(args: string[]) {
.describe(packageJson.description)
.option('-p, --path', 'Path to the code to be transformed')
.example('-p ./')
.option('-c, --codemod', 'Codemod name to run')
.option('-t, --transformation', 'Codemod transformation name to run')
.example('-c v2/web-react/codemodName')
.option('-e, --extensions', 'Extensions to look for when transforming files, default: ts,tsx,js,jsx')
.example('-e ts, tsx, js, jsx')
.option('--ignore-pattern', 'Ignore files or directories, default: **/node_modules/**')
.option('--ignore', 'Ignore files or directories, default: **/node_modules/**')
.example('-i **/node_modules/**')
.option('--parser', 'Parser to use (babel, ts, tsx, flow), default: tsx')
.example('--parser babel')
.action(async ({ path: codePath, codemod, extensions, ignorePattern, parser }) => {
.action(async ({ path: codePath, transformation, extensions, ignore, parser }) => {
const defaultExtensions = 'ts,tsx,js,jsx';
const defaultIgnore = '**/node_modules/**';
const defaultParser = 'tsx';
Expand All @@ -30,12 +30,12 @@ export default async function cli(args: string[]) {
process.exit(1);
}

if (!codemod) {
if (!transformation) {
errorMessage('Please provide a codemod name');
process.exit(1);
}

const codemodPath = path.resolve(_dirname, `./transforms/${codemod}.ts`);
const codemodPath = path.resolve(_dirname, `./transforms/${transformation}.ts`);

if (!fs.existsSync(codemodPath)) {
errorMessage('Codemod does not exists');
Expand All @@ -44,7 +44,7 @@ export default async function cli(args: string[]) {

const { stdout } = await $`jscodeshift --transform ${codemodPath} --extensions ${
extensions || defaultExtensions
} --ignore-pattern=${ignorePattern || defaultIgnore} --parser=${parser || defaultParser} ${codePath}`;
} --ignore-pattern=${ignore || defaultIgnore} --parser=${parser || defaultParser} ${codePath}`;

// stdout object from jscodeshift
logMessage(stdout);
Expand Down

0 comments on commit 2a71020

Please sign in to comment.