-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.js
136 lines (108 loc) · 3.64 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// @ts-check
// based on https://github.com/microsoft/TypeScript-Make-Monaco-Builds/blob/master/publish-monaco-editor.js
const { execSync } = require("child_process");
const fs = require("fs");
const bundle = require("./bundle");
const args = process.argv.slice(2);
const exec = (cmd, opts) => {
console.log(`> ${cmd} ${opts ? JSON.stringify(opts) : ""}`);
try {
return execSync(cmd, opts);
} catch (error) {
console.log("Command Failed:");
console.log("STDOUT:" + error.stdout.toString());
console.log("STDERR:" + error.stderr.toString());
throw error;
}
};
const failableMergeBranch = (exec, name) => {
try {
exec(`git merge ${name}`);
} catch (e) {
// NOOP
}
};
const patchEsmWorker = () => {
const path =
"monaco-editor/out/monaco-editor/esm/vs/base/browser/defaultWorkerFactory.js";
const content = fs.readFileSync(path, "utf8");
const patchedContent = content.replace(
"const isESM = true;",
"const isESM = false;"
);
fs.writeFileSync(path, patchedContent);
};
const step = (msg) => console.log("\n\n - " + msg);
function main() {
// TypeScript calls nightlies latest... So should we.
const typescriptTag = args[0] ? args[0] : "latest";
const typescriptModuleName = args[1] ? args[1] : "typescript";
console.log("## Creating build of Monaco Editor");
process.stdout.write("> node publish-monaco-editor.js");
const execME = (cmd) => exec(cmd, { cwd: "monaco-editor" });
// Create a tarball of the current version
step("Cloning the repo");
if (fs.existsSync("monaco-editor")) {
fs.rmSync("monaco-editor", { recursive: true, force: true });
}
exec("git clone https://github.com/microsoft/monaco-editor.git");
// Add typescript to the tsWorker export
// https://github.com/microsoft/monaco-editor/pull/2775
step("Merging in open PRs we want");
execME(
"git remote add andrewbranch https://github.com/andrewbranch/monaco-editor.git"
);
execME("git fetch andrewbranch");
failableMergeBranch(execME, "andrewbranch/update-ts");
execME(
"git remote add jakebailey https://github.com/jakebailey/monaco-editor.git"
);
execME("git fetch jakebailey");
failableMergeBranch(execME, "jakebailey/fix-compile-regex-parse");
failableMergeBranch(execME, "jakebailey/emit-file-diagnostics");
execME("git rev-parse HEAD");
step(
"Removing TypeDoc because its ships its own version of TypeScript and npm complains"
);
execME(`npm remove typedoc`);
step(
"Updating @types/node to ensure we compile on newer versions of TypeScript"
);
execME(`npm update @types/node`);
step("Overwriting the version of TypeScript");
if (typescriptModuleName === "typescript") {
execME(`npm install --save-exact "typescript@${typescriptTag}" --force`);
} else {
execME(
`npm install --save-exact "typescript@npm:${typescriptModuleName}@${typescriptTag}" --force`
);
}
step("Getting TypeScript and Monaco versions");
const typeScriptVersion = execME(
"npx json -f node_modules/typescript/package.json version"
)
.toString()
.trim();
const monacoVersion = execME("npx json -f package.json version")
.toString()
.trim();
step("Creating release folder");
execME(`npm run build-monaco-editor`);
step("Updating TS in monaco-typescript");
execME(`npm run import-typescript`);
step("Re-running release");
execME(`npm run build-monaco-editor`);
step("Apply patch to prevent using ESM workers");
patchEsmWorker();
step("Creating bundles");
bundle();
step(
"Build complete in `dist`!\n" +
"Monaco version: " +
monacoVersion +
"\nTypeScript version: " +
typeScriptVersion
);
step("Done!");
}
main();