-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
77 lines (64 loc) · 2.15 KB
/
index.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
#!/usr/bin/env node
const { resolve } = require('path');
const loader = require('./src/utils/loader');
const createProject = require('./src/utils/create-project');
const { createCommit, getPrettyMessage } = require('./src/utils/create-commit');
const project = createProject();
const args = require('yargs-parser')(process.argv.slice(2));
const srcPath = args._[0] || 'src';
const globPath = resolve(srcPath + '/**/*.{tsx,ts,jsx,js,mdx,md}');
project.addSourceFilesAtPaths(globPath);
console.log(`${project.getSourceFiles().length} files found at ${globPath} \n`);
const preset = args.preset || args.p;
const migration = args.migration || args.m;
const createCommits = args['create-commits'];
const migrations = [
// old deprecations
'use-deprecated-borderbox',
'use-deprecated-flex',
'use-deprecated-grid',
'use-deprecated-label',
'use-deprecated-position',
'use-deprecated-dropdown',
'use-deprecated-formgroup',
'use-deprecated-selectmenu',
// new deprecations
'use-deprecated-button',
'use-deprecated-actionlist',
'use-deprecated-actionmenu',
'use-deprecated-dropdownmenu',
'use-deprecated-inputfield',
'use-deprecated-choicefieldset',
'use-deprecated-choiceinputfield',
// promotions, should be run after deprecations
'use-main-label',
'use-main-button',
'use-main-actionlist',
'use-main-actionmenu',
'use-main-pagelayout'
];
if (preset === 'v35') {
async function runSequentially() {
for (const migrationName of migrations) {
const message = getPrettyMessage(migrationName);
const { success, skip } = loader(message);
require(`./src/${migrationName}.js`)(project);
if (createCommits) {
const changed = await createCommit(migrationName);
changed ? await success() : await skip();
} else await success();
}
}
runSequentially();
} else {
if (migrations.includes(migration)) {
const path = './src/' + migration + '.js';
require(path)(project);
if (createCommits) createCommit(migration);
} else {
console.log(
'Migration not found! Check the list of available migrations on https://github.com/primer/react-migrate'
);
}
}
module.export = { project };