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