-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
103 lines (86 loc) · 2.86 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/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 { deprecate } = require('util');
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 v35Migrations = [
// 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'
];
const v37Migrations = [
// deprecrations
'use-deprecated-dialog',
'use-deprecated-tooltip',
'use-deprecated-octicon',
'use-deprecated-pagehead',
'use-deprecated-tabnav',
// drafts is renamed to experimental
'rename-drafts-to-experimental',
// promotions, should be run after deprecations
'use-main-dialog',
'use-main-tooltip',
'use-main-stack'
];
const allMigrations = [...v35Migrations, ...v37Migrations];
if (preset) {
if (preset === 'v35') runSequentially(v35Migrations);
else if (preset === 'v37') runSequentially(v37Migrations);
else {
console.log(
'Preset not found! Check the list of available presets on https://github.com/primer/react-migrate'
);
}
async function runSequentially(presetMigrations) {
for (const migrationName of presetMigrations) {
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();
}
}
} else {
if (allMigrations.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 };