Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/npm/update-all-grammars.ts
4770 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { spawn as _spawn } from 'child_process';
7
import { readdirSync, readFileSync } from 'fs';
8
import { join } from 'path';
9
10
async function spawn(cmd: string, args: string[], opts?: Parameters<typeof _spawn>[2]) {
11
return new Promise<void>((c, e) => {
12
const child = _spawn(cmd, args, { shell: true, stdio: 'inherit', env: process.env, ...opts });
13
child.on('close', code => code === 0 ? c() : e(`Returned ${code}`));
14
});
15
}
16
17
async function main() {
18
await spawn('npm', ['ci'], { cwd: 'extensions' });
19
20
for (const extension of readdirSync('extensions')) {
21
try {
22
const packageJSON = JSON.parse(readFileSync(join('extensions', extension, 'package.json')).toString());
23
if (!(packageJSON && packageJSON.scripts && packageJSON.scripts['update-grammar'])) {
24
continue;
25
}
26
} catch {
27
continue;
28
}
29
30
await spawn(`npm`, ['run', 'update-grammar'], { cwd: `extensions/${extension}` });
31
}
32
33
// run integration tests
34
35
if (process.platform === 'win32') {
36
_spawn('.\\scripts\\test-integration.bat', [], { shell: true, env: process.env, stdio: 'inherit' });
37
} else {
38
_spawn('/bin/bash', ['./scripts/test-integration.sh'], { env: process.env, stdio: 'inherit' });
39
}
40
}
41
42
if (import.meta.main) {
43
try {
44
await main();
45
} catch (err) {
46
console.error(err);
47
process.exit(1);
48
}
49
}
50
51