-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·77 lines (72 loc) · 2.16 KB
/
index.js
File metadata and controls
executable file
·77 lines (72 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env node
const jscodeshift = require('jscodeshift/src/Runner.js');
const { resolve } = require('node:path');
const { hideBin } = require('yargs/helpers');
const yargs = require('yargs/yargs');
const options = yargs(hideBin(process.argv))
.option('path', {
alias: 'p',
demandOption: true
})
.option('current-import-sources', {
alias: 's',
array: true,
demandOption: true
})
.option('target-import-source', {
alias: 't'
})
.option('resolve-import-mapping', {
alias: 'r',
boolean: true,
default: false
})
.option('tsconfig-path', {
alias: 'tsc'
})
.option('only-imported-exports', {
alias: 'e',
array: true,
default: []
})
.option('dry-run', {
alias: 'd',
boolean: true,
default: false
})
.option('fuzzy-match', {
alias: 'f',
boolean: true,
default: false
})
.option('parser', {
choices: ['ts', 'tsx'],
default: 'tsx'
})
.check(options => {
const targetImportSourceMode = options['target-import-source']?.length > 0;
const resolveImportMappingMode = options['resolve-import-mapping'] === true && options['tsconfig-path']?.length > 0;
if (!targetImportSourceMode && !resolveImportMappingMode) {
throw new Error('Either --target-import-source or --resolve-import-mapping with --tsconfig-path must be provided.');
}
return true;
})
.argv;
jscodeshift.run(
resolve(__dirname, 'transform.js'),
[options.path],
{
extensions: 'ts',
parser: 'ts',
dry: options.dryRun,
transformOptions: {
fuzzyMatch: options.fuzzyMatch,
currentImportSources: options.currentImportSources,
targetImportSource: options.targetImportSource,
onlyImportedExports: options.onlyImportedExports,
resolveImportMapping: options.resolveImportMapping,
tsconfigPath: options.tsconfigPath?.length > 0 ? resolve(process.cwd(), options.tsconfigPath) : undefined,
parser: options.parser
}
}
);