forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-xterm.js
84 lines (73 loc) · 2.64 KB
/
update-xterm.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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
const cp = require('child_process');
const path = require('path');
const moduleNames = [
'xterm',
'xterm-addon-search',
'xterm-addon-unicode11',
'xterm-addon-webgl'
];
const backendOnlyModuleNames = [
'xterm-headless',
'xterm-addon-serialize'
];
const vscodeDir = process.argv.length >= 3 ? process.argv[2] : process.cwd();
if (path.basename(vscodeDir) !== 'vscode') {
console.error('The cwd is not named "vscode"');
return;
}
function getLatestModuleVersion(moduleName) {
return new Promise((resolve, reject) => {
cp.exec(`npm view ${moduleName} versions --json`, { cwd: vscodeDir }, (err, stdout, stderr) => {
if (err) {
reject(err);
}
const versions = JSON.parse(stdout);
resolve(versions[versions.length - 1]);
});
});
}
async function update() {
console.log('Fetching latest versions');
const allModules = moduleNames.concat(backendOnlyModuleNames);
const versionPromises = [];
for (const m of allModules) {
versionPromises.push(getLatestModuleVersion(m));
}
const latestVersionsArray = await Promise.all(versionPromises);
const latestVersions = {};
for (const [i, v] of latestVersionsArray.entries()) {
latestVersions[allModules[i]] = v;
}
console.log('Detected versions:');
for (const m of moduleNames.concat(backendOnlyModuleNames)) {
console.log(` ${m}@${latestVersions[m]}`);
}
const pkg = require(path.join(vscodeDir, 'package.json'));
for (const m of moduleNames) {
const moduleWithVersion = `${m}@${latestVersions[m]}`;
if (pkg.dependencies[m] === latestVersions[m]) {
console.log(`Skipping ${moduleWithVersion}, already up to date`);
continue;
}
for (const cwd of [vscodeDir, path.join(vscodeDir, 'remote'), path.join(vscodeDir, 'remote/web')]) {
console.log(`${path.join(cwd, 'package.json')}: Updating ${moduleWithVersion}`);
cp.execSync(`yarn add ${moduleWithVersion}`, { cwd });
}
}
for (const m of backendOnlyModuleNames) {
const moduleWithVersion = `${m}@${latestVersions[m]}`;
if (pkg.dependencies[m] === latestVersions[m]) {
console.log(`Skipping ${moduleWithVersion}, already up to date`);
continue;
}
for (const cwd of [vscodeDir, path.join(vscodeDir, 'remote')]) {
console.log(`${path.join(cwd, 'package.json')}: Updating ${moduleWithVersion}`);
cp.execSync(`yarn add ${moduleWithVersion}`, { cwd });
}
}
}
update();