forked from Felx-B/vscode-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
104 lines (84 loc) · 2.84 KB
/
build.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
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.54.1";
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",
});
if (!fs.existsSync("node_modules")) {
child_process.execSync("yarn", { stdio: "inherit" });
}
// Use simple workbench
fs.copyFileSync(
"../workbench.ts",
"src/vs/code/browser/workbench/workbench.ts"
);
// 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 extensionNM = glob.sync("extensions/**/node_modules", {});
extensionNM.forEach((modules) => {
rmdir.sync(modules, { 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);