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