-
Notifications
You must be signed in to change notification settings - Fork 0
/
codemod.js
executable file
·39 lines (35 loc) · 1.18 KB
/
codemod.js
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
#!/usr/bin/env node
const path = require('node:path');
const {Command} = require('commander');
const {run: jscodeshift} = require('jscodeshift/src/Runner');
const pkg = require('./package.json');
const program = new Command();
program
.name('codemod')
.description('Code modifications to assist with OpenLayers upgrades.')
.version(pkg.version)
.configureHelp({showGlobalOptions: true})
.option('--extensions <ext>', 'Extensions of files to be parsed', 'js,mjs')
.option(
'--verbose <mode>',
'Show more information about the transform process (made can be 0, 1, or 2)',
parseFloat,
0,
);
program
.command('replace-barrel-imports')
.description('Rewrite imports from barrel files.')
.argument('<src>', 'Path to files to rewrite.')
.option(
'--consider-relative-paths',
'By default, only imports starting with "ol" are considered. Add this flag to consider relative paths like "../ol/layer.js"',
)
.action(async (src, _, cmd) => {
const options = cmd.optsWithGlobals();
const replaceBarrelImports = path.resolve(
__dirname,
`./src/${cmd.name()}.js`,
);
await jscodeshift(replaceBarrelImports, [src], options);
});
program.parse();