-
Notifications
You must be signed in to change notification settings - Fork 1
/
migrate.js
71 lines (60 loc) · 1.99 KB
/
migrate.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
var chalk = require('chalk');
var inquirer = require('inquirer');
var exec = require('child_process').execSync;
var fs = require('fs');
var path = require('path');
var newline = function () { console.log() };
console.log(fs.readFileSync(path.join(__dirname, 'resources', 'banner')).toString());
newline();
console.log(chalk.green('Let\'s migrate your templates!'));
newline();
var files = process.argv.slice(2, process.argv.length);
if (!files.length) {
console.log(chalk.red('Path is not provided!'));
console.log(chalk.white('Please use the tool with:'));
newline();
console.log(chalk.gray(' npm run migrate [PATH_TO_YOUR_FILES]'));
newline();
process.exit(0);
}
var command = path.join(__dirname, 'node_modules', '.bin', 'tslint') + ' -c ' + path.join(__dirname, 'migrate.json') + ' ' + files.join(' ');
var foundErrors = false;
try {
console.log(exec(command).toString());
} catch (e) {
foundErrors = true;
if (e && e.output && e.output[1]) {
console.log(chalk.cyan.bold('I found these deprecations:'));
console.log(e.output[1].toString());
inquirer.prompt([
{
type: 'confirm',
message: 'Do you want me to fix them for you?',
name: 'migrate'
}
])
.then(function (res) {
if (res.migrate) {
newline();
console.log(exec(command + ' --fix').toString());
console.log(chalk.cyan.bold('Done!'));
newline();
console.log(chalk.yellow('⚠️ Do not forget to "diff" the changes!'));
newline();
} else {
newline();
console.log(chalk.cyan('No problems!'), chalk.cyan.bold('Better take care of those before the next major release!'));
newline();
}
}).catch(function (e) {
if (e && e.output && e.output[1]) {
console.log(chalk.cyan.bold('Uuupsss. I hit an error:'));
console.log(e.output[1].toString());
}
});
}
}
if (!foundErrors) {
console.log(chalk.green.bold('I didn\'t find anything wrong! All seems fine!'));
newline();
}