Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/lib/preLaunch.ts
3520 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
// @ts-check
7
8
import path from 'path';
9
import { spawn } from 'child_process';
10
import { promises as fs } from 'fs';
11
12
const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
13
const rootDir = path.resolve(__dirname, '..', '..');
14
15
function runProcess(command: string, args: ReadonlyArray<string> = []) {
16
return new Promise<void>((resolve, reject) => {
17
const child = spawn(command, args, { cwd: rootDir, stdio: 'inherit', env: process.env, shell: process.platform === 'win32' });
18
child.on('exit', err => !err ? resolve() : process.exit(err ?? 1));
19
child.on('error', reject);
20
});
21
}
22
23
async function exists(subdir: string) {
24
try {
25
await fs.stat(path.join(rootDir, subdir));
26
return true;
27
} catch {
28
return false;
29
}
30
}
31
32
async function ensureNodeModules() {
33
if (!(await exists('node_modules'))) {
34
await runProcess(npm, ['ci']);
35
}
36
}
37
38
async function getElectron() {
39
await runProcess(npm, ['run', 'electron']);
40
}
41
42
async function ensureCompiled() {
43
if (!(await exists('out'))) {
44
await runProcess(npm, ['run', 'compile']);
45
}
46
}
47
48
async function main() {
49
await ensureNodeModules();
50
await getElectron();
51
await ensureCompiled();
52
53
// Can't require this until after dependencies are installed
54
const { getBuiltInExtensions } = require('./builtInExtensions');
55
await getBuiltInExtensions();
56
}
57
58
if (require.main === module) {
59
main().catch(err => {
60
console.error(err);
61
process.exit(1);
62
});
63
}
64
65