forked from maplibre/maplibre-gl-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codemods.js
97 lines (80 loc) · 2.01 KB
/
codemods.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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import replace from 'replace-in-file';
import {execSync} from 'child_process';
let file = process.argv[process.argv.length - 1];
const useAsync = process.argv.includes('--async');
const automate = process.argv.includes('--auto');
if (process.argv.length === 1) {
console.log('Error: Path argument missing.');
process.exit();
}
if (automate) {
let fileName = file.split('/').splice(-1)[0];
execSync(`git checkout -b ${fileName}`);
let destinationFile = file.replace('test/unit', 'src').replace('.js', '.ts');
execSync(`git mv ${file} ${destinationFile}`);
execSync('git commit -m "Move and rename"');
file = destinationFile;
execSync(`npx jscodeshift --parser babel --skipImportDetection -t node_modules/jest-codemods/dist/transformers/tape.js ${file}`);
execSync(`git add ${file}`);
execSync('git commit -m "Run jscodeshift"');
}
replace.sync({
files: [file],
from: /import {test} from '..\/..\/util\/test';\n/g,
to: '',
})
replace.sync({
files: [file],
from: /\ntest/g,
to: '\ndescribe',
});
replace.sync({
files: [file],
from: /\(t\) =>/g,
to: useAsync ? 'done =>' : '() =>',
});
replace.sync({
files: [file],
from: /t.end\(\);\n/g,
to: useAsync ? 'done();\n' : '',
});
replace.sync({
files: [file],
from: /t.pass\(\);/g,
to: ''
});
replace.sync({
files: [file],
from: /..\/..\/..\/rollup\/build\/tsc\/src\//g,
to: '../',
});
replace.sync({
files: [file],
from: /t.test\(/g,
to: 'test('
});
replace.sync({
files: [file],
from: /t.spy\(\)/g,
to: 'jest.fn()'
});
replace.sync({
files: [file],
from: /t.spy\(/g,
to: 'jest.spyOn('
});
replace.sync({
files: [file],
from: /.callCount\).toBe/g,
to: ').toHaveBeenCalledTimes'
});
replace.sync({
files: [file],
from: /.notCalled\).toBeTruthy/g,
to: ').not.toHaveBeenCalled'
});
if (automate) {
execSync('npm run lint -- --fix');
execSync(`git add ${file}`);
execSync('git commit -m "Run custom codemods and lint"');
}