-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade.js
60 lines (50 loc) · 1.88 KB
/
upgrade.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
const fs = require('fs');
const path = require('path');
const execSync = require('child_process').execSync;
let exec = function(cmd) {
console.log(cmd);
execSync(cmd, { stdio: 'inherit' });
}
const package = JSON.parse(fs.readFileSync('package.json').toString());
package.version = '15.0.0';
fs.writeFileSync('package.json', JSON.stringify(package, undefined, 2));
exec('npm i --force --legacy-peer-deps');
exec('node node_modules/@angular/cli/bin/ng update @angular/core@15 @angular/cli@15 --force --allow-dirty');
exec('node node_modules/@angular/cli/bin/ng update @angular/material@15 --force --allow-dirty');
exec('npm install @firestitch/component-tools@15.0.5 --save-dev');
exec('npm install @firestitch/example@15.0.1 --save-dev');
exec('npm install @firestitch/message@15.0.0 --save-dev');
const walk = (dir) => {
try {
let results = [];
const list = fs.readdirSync(dir);
list.forEach(file => {
file = path.join(dir, file);
const stat = fs.statSync(file);
if (stat && stat.isDirectory()) {
// Recurse into subdir
results = [...results, ...walk(file)];
} else {
// Is a file
results.push(file);
}
});
return results;
} catch (error) {
console.error(`Error when walking dir ${dir}`, error);
}
};
const edit = (filePath, regex, replaceVal) => {
const oldContent = fs.readFileSync(filePath, {encoding: 'utf8'});
const newContent = oldContent.replace(regex, replaceVal);
fs.writeFileSync(filePath, newContent, {encoding: 'utf-8'});
console.log(`Edited file: ${filePath}`);
};
['playground', 'src'].forEach((dir) => {
walk(dir)
.forEach(filePath => edit(filePath, new RegExp('MAT_LEGACY_[^\\s]* as ', 'g'), ''));
walk(dir)
.forEach(filePath => edit(filePath, new RegExp('MatLegacy[^\\s]* as ', 'g'), ''));
walk(dir)
.forEach(filePath => edit(filePath, new RegExp('/legacy-', 'g'), '/'));
});