-
Notifications
You must be signed in to change notification settings - Fork 11
/
publish-monaco-editor.js
116 lines (86 loc) · 3.73 KB
/
publish-monaco-editor.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
// @ts-check
const { execSync } = require("child_process");
const { existsSync } = require("fs");
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
}
}
// So, you can run this locally
const dontDeploy = !!process.env.SKIP_DEPLOY
const envUser = process.env.USER_ACCOUNT
// For example:
// USER_ACCOUNT="typescript-deploys" SKIP_DEPLOY="true" node ./publish-monaco-editor.js next
const step = msg => console.log("\n\n - " + msg);
function main() {
// TypeScript calls nightlies next... So should we.
const typescriptTag = args[0] ? args[0] : "next"
const typescriptModuleName = args[1] ? args[1] : "typescript"
const monacoTypescriptTag = args[0];
const isPushedTag = process.env.GITHUB_EVENT_NAME === "push";
const tagPrefix = isPushedTag || args[0].includes("http") || args[0].includes("-pr-") ? "" : `--tag ${monacoTypescriptTag}`;
console.log("## Creating build of Monaco Editor");
process.stdout.write("> node publish-monaco-editor.js");
const execME = cmd => exec(cmd, { cwd: "monaco-editor" });
const execRelease = cmd => exec(cmd, { cwd: "monaco-editor/out/monaco-editor" });
// Create a tarball of the current version
step("Cloning the repo");
if (existsSync("monaco-editor")) exec("rm -rf monaco-editor")
exec("git config --global user.email '[email protected]'")
exec("git config --global user.name 'TypeScript Bot'")
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")
const user = envUser || exec("npm whoami").toString().trim();
step("Renaming");
execME(`json -I -f package.json -e "this.name='@${user}/monaco-editor'"`);
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 "typescript@${typescriptTag}" --force`)
} else {
execME(`npm install --save "typescript@npm:${typescriptModuleName}@${typescriptTag}" --force`)
}
step("Matching the versions");
const typeScriptVersion = execME("json -f node_modules/typescript/package.json version").toString().trim();
execME(`json -I -f package.json -e "this.version='${typeScriptVersion}'"`);
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`);
// Run the final command inside the release dir
if (!dontDeploy) {
step("Publishing");
// execRelease(`npm publish --access public ${tagPrefix}`);
}
step("Done!");
}
main();