-
Notifications
You must be signed in to change notification settings - Fork 1
/
publish-monaco-ts.js
73 lines (54 loc) · 2.3 KB
/
publish-monaco-ts.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
// @ts-check
const { execSync } = require("child_process");
const args = process.argv.slice(2);
const exec = (cmd, opts) => {
console.log(`> ${cmd} ${opts ? JSON.stringify(opts) : ""}`);
return execSync(cmd, opts);
};
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 isPushedTag = process.env.GITHUB_EVENT_NAME === "push"
const tagPrefix = isPushedTag || args[0].includes("http") ? "" : `--tag ${typescriptTag}`
console.log("## Creating build of Monaco TypeScript");
process.stdout.write("> node publish-monaco-ts.js");
// Create a tarball of the current version
step("Cloning the repo");
exec("git clone https://github.com/microsoft/monaco-typescript.git");
const execMTS = (cmd) => exec(cmd, { cwd: "monaco-typescript" })
execMTS(`git config --global user.email "you@example.com"`)
execMTS(`git config --global user.name "Your Name"`)
step("Installing NPM");
execMTS("npm i")
// Grab the username from NPM
const user = execMTS("npm whoami").toString().trim()
step("Overwriting the version of TypeScript in Monaco TypeScript");
execMTS(`npm install --save "typescript@${typescriptTag}"`)
step("Updating the internal version of TS inside monaco");
execMTS("npm run import-typescript");
step("Adding Type Definitions and Source Map support");
execMTS(`json -I -f src/tsconfig.json -e "this.compilerOptions.declaration=true"`)
execMTS(`json -I -f src/tsconfig.json -e "this.compilerOptions.sourceMap=true"`)
let version = args[1]
if (version) {
step(`Setting the version to ${version}`);
} else {
step("Grabbing the version from the TypeScript build");
version = execMTS("json -f node_modules/typescript/package.json version").toString().trim()
}
execMTS(`json -I -f package.json -e "this.version='${version}'"`)
step("Setting the name");
execMTS(`json -I -f package.json -e "this.name='@${user}/monaco-typescript'"`)
step("Publishing to NPM");
try {
// Support this command failing when pushing a dupe
execMTS(`npm publish --access public ${tagPrefix}`)
} catch (error) {
console.log(error.message)
if (!error.message.includes("previously published versions")) {
throw error
}
}
}
main()