Skip to content

Commit 1cc1d14

Browse files
committed
Copy cli.js from Reselect codemod
1 parent 6bb5060 commit 1cc1d14

File tree

1 file changed

+35
-8
lines changed
  • packages/rtk-codemods/bin

1 file changed

+35
-8
lines changed

packages/rtk-codemods/bin/cli.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,39 @@
11
#!/usr/bin/env node
2-
const path = require('path');
2+
import { execaSync } from 'execa'
3+
import { globbySync } from 'globby'
4+
import { createRequire } from 'node:module'
5+
import path from 'node:path'
6+
import { fileURLToPath } from 'node:url'
37

4-
require('ts-node').register({
5-
project: path.join(__dirname, './tsconfig.json'),
6-
});
8+
const require = createRequire(import.meta.url)
79

8-
require('codemod-cli').runTransform(
10+
const __filename = fileURLToPath(import.meta.url)
11+
const __dirname = path.dirname(__filename)
12+
13+
const transformerDirectory = path.join(
914
__dirname,
10-
process.argv[2] /* transform name */,
11-
process.argv.slice(3) /* paths or globs */
12-
);
15+
'..',
16+
'transforms',
17+
`${process.argv[2]}/index.ts`
18+
)
19+
20+
const jscodeshiftExecutable = require.resolve('.bin/jscodeshift')
21+
22+
const extensions = 'ts,js,tsx,jsx'
23+
24+
execaSync(
25+
jscodeshiftExecutable,
26+
[
27+
'-t',
28+
transformerDirectory,
29+
'--extensions',
30+
extensions,
31+
...(process.argv.slice(3).length === 1
32+
? globbySync(process.argv[3])
33+
: process.argv.slice(3))
34+
],
35+
{
36+
stdio: 'inherit',
37+
stripFinalNewline: false
38+
}
39+
)

0 commit comments

Comments
 (0)