This repository has been archived by the owner on May 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbuild-vsc.js
113 lines (89 loc) · 3.32 KB
/
build-vsc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// modified from https://github.com/Felx-B/vscode-web
const process = require('process');
const child_process = require('child_process');
const fs = require('fs');
const fse = require('fs-extra');
const glob = require('glob');
const rmdir = require('rimraf');
const vscodeVersion = '1.53.2';
if (!fs.existsSync('vscode')) {
child_process.execSync('git clone https://github.com/microsoft/vscode.git', {
stdio: 'inherit',
});
}
process.chdir('vscode');
child_process.execSync(`git checkout -q ${vscodeVersion}`, {
stdio: 'inherit',
});
child_process.execSync('yarn', { stdio: 'inherit' });
// Patch VSCode
const patchPath = '../vscode-patch';
const extendedSuffix = '.extended.ts';
glob.sync(`${patchPath}/**/*.*`).forEach((value) => {
const targetFile = value.slice(patchPath.length);
if (value.endsWith(extendedSuffix)) {
const targetPath = `.${targetFile.slice(0, -extendedSuffix.length)}.ts`;
child_process.execSync(`git checkout ${targetPath}`, {
stdio: 'inherit',
});
fs.appendFileSync(targetPath, fs.readFileSync(value));
return;
}
fse.copySync(value, `.${targetFile}`, { overwrite: true });
});
// Adapt compilation to web
const gulpfilePath = './build/gulpfile.vscode.js';
let gulpfile = fs.readFileSync(gulpfilePath, { encoding: 'utf8', flag: 'r' });
gulpfile = gulpfile
.replace(/vs\/workbench\/workbench.desktop.main/g, 'vs/workbench/workbench.web.api')
.replace(/buildfile.workbenchDesktop/g, 'buildfile.workbenchWeb,buildfile.keyboardMaps');
fs.writeFileSync(gulpfilePath, gulpfile);
// Compile
child_process.execSync('yarn gulp compile-build', { stdio: 'inherit' });
child_process.execSync('yarn gulp minify-vscode', { stdio: 'inherit' });
child_process.execSync('yarn compile-web', { stdio: 'inherit' });
// Remove maps
const mapFiles = glob.sync('out-vscode-min/**/*.js.map', {});
mapFiles.forEach((mapFile) => {
fs.unlinkSync(mapFile);
});
// Extract compiled files
if (fs.existsSync('../dist')) {
fs.rmdirSync('../dist', { recursive: true });
}
fs.mkdirSync('../dist');
fse.copySync('out-vscode-min', '../dist/vscode');
const extensionFilesToRemove = [
...glob.sync('extensions/**/node_modules', {}),
...glob.sync('extensions/**/*.js.map', {}),
];
extensionFilesToRemove.forEach((path) => {
rmdir.sync(path, { recursive: true });
});
fse.copySync('extensions', '../dist/extensions');
// Add built in extensions
const extensions = [];
const extensionsFolderPath = 'extensions';
const extensionsContent = fs.readdirSync(extensionsFolderPath);
for (const extension of extensionsContent) {
const extensionPath = `${extensionsFolderPath}/${extension}`;
if (fs.statSync(extensionPath).isDirectory()) {
const extensionPackagePath = `${extensionPath}/package.json`;
const extensionPackageNLSPath = `${extensionPath}/package.nls.json`;
if (!fs.existsSync(extensionPackagePath)) {
continue;
}
const packageJSON = JSON.parse(fs.readFileSync(extensionPackagePath));
let packageNLS = null;
if (fs.existsSync(extensionPackageNLSPath)) {
packageNLS = JSON.parse(fs.readFileSync(extensionPackageNLSPath));
}
extensions.push({
packageJSON,
extensionPath: extension,
packageNLS,
});
}
}
const extensionsVar = 'var extensions =' + JSON.stringify(extensions, { space: '\t', quote: '' });
fs.writeFileSync('../dist/extensions.js', extensionsVar);