Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/scripts/code-perf.js
5222 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
const path = require('path');
9
const fs = require('fs');
10
const perf = require('@vscode/vscode-perf');
11
12
const VSCODE_FOLDER = path.join(__dirname, '..');
13
14
async function main() {
15
16
const args = process.argv;
17
/** @type {string | undefined} */
18
let build = undefined;
19
20
if (args.indexOf('--help') === -1 && args.indexOf('-h') === -1) {
21
// get build arg from args
22
let buildArgIndex = args.indexOf('--build');
23
buildArgIndex = buildArgIndex === -1 ? args.indexOf('-b') : buildArgIndex;
24
if (buildArgIndex === -1) {
25
let runtimeArgIndex = args.indexOf('--runtime');
26
runtimeArgIndex = runtimeArgIndex === -1 ? args.indexOf('-r') : runtimeArgIndex;
27
if (runtimeArgIndex !== -1 && args[runtimeArgIndex + 1] !== 'desktop') {
28
console.error('Please provide the --build argument. It is an executable file for desktop or a URL for web');
29
process.exit(1);
30
}
31
build = getLocalCLIPath();
32
} else {
33
build = args[buildArgIndex + 1];
34
if (build !== 'insider' && build !== 'stable' && build !== 'exploration') {
35
build = getExePath(args[buildArgIndex + 1]);
36
}
37
args.splice(buildArgIndex + 1, 1);
38
}
39
40
args.push('--folder');
41
args.push(VSCODE_FOLDER);
42
args.push('--file');
43
args.push(path.join(VSCODE_FOLDER, 'package.json'));
44
}
45
46
if (build) {
47
args.push('--build');
48
args.push(build);
49
}
50
51
await perf.run();
52
process.exit(0);
53
}
54
55
/**
56
* @param {string} buildPath
57
* @returns {string}
58
*/
59
function getExePath(buildPath) {
60
buildPath = path.normalize(path.resolve(buildPath));
61
if (buildPath === path.normalize(getLocalCLIPath())) {
62
return buildPath;
63
}
64
let relativeExePath;
65
switch (process.platform) {
66
case 'darwin': {
67
const product = require(path.join(buildPath, 'Contents', 'Resources', 'app', 'product.json'));
68
relativeExePath = path.join('Contents', 'MacOS', product.nameShort);
69
if (!fs.existsSync(path.join(buildPath, relativeExePath))) {
70
relativeExePath = path.join('Contents', 'MacOS', 'Electron');
71
}
72
break;
73
}
74
case 'linux': {
75
const product = require(path.join(buildPath, 'resources', 'app', 'product.json'));
76
relativeExePath = product.applicationName;
77
break;
78
}
79
case 'win32': {
80
const product = require(path.join(buildPath, 'resources', 'app', 'product.json'));
81
relativeExePath = `${product.nameShort}.exe`;
82
break;
83
}
84
default:
85
throw new Error('Unsupported platform.');
86
}
87
return buildPath.endsWith(relativeExePath) ? buildPath : path.join(buildPath, relativeExePath);
88
}
89
90
/**
91
* @returns {string}
92
*/
93
function getLocalCLIPath() {
94
return process.platform === 'win32' ? path.join(VSCODE_FOLDER, 'scripts', 'code.bat') : path.join(VSCODE_FOLDER, 'scripts', 'code.sh');
95
}
96
97
main();
98
99