-
Notifications
You must be signed in to change notification settings - Fork 11
/
upload-assets-to-blob-storage.js
67 lines (49 loc) · 2.65 KB
/
upload-assets-to-blob-storage.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
// @ts-check
const { readFileSync, writeFileSync } = require("fs");
const exec = require("./exec");
const optionalTag = process.argv.slice(2)[0];
const step = msg => console.log("\n\n - " + msg);
function main() {
console.log("## Uploading build of Monaco Editor");
process.stdout.write("> node upload-assets-to-blob-storage.js");
const typescriptPackageJSON = JSON.parse(readFileSync("monaco-editor/package.json", "utf8"));
const safeTypeScriptPackage = typescriptPackageJSON.version;
// Upload the full monaco-editor
step("Uploading Monaco");
exec("rm -rf releases");
exec("mkdir releases");
exec(`mkdir releases/${safeTypeScriptPackage}`);
exec(`cp -r monaco-editor/out/monaco-editor releases/${safeTypeScriptPackage}/monaco/`);
// This is basically for nightlies, but if a 2nd arg is passed then we include a duped copy of the
// monaco-editor and monaco-typescript with the tag which was passed as an arg to the script
if (optionalTag) {
exec(`mkdir releases/${optionalTag}`);
exec(`cp -r monaco-editor/out/monaco-editor releases/${optionalTag}/monaco/`);
}
step("Uploading TypeScript");
exec(`cp -r monaco-editor/node_modules/typescript releases/${safeTypeScriptPackage}/typescript`);
if (optionalTag) {
exec(`cp -r monaco-editor/node_modules/typescript releases/${optionalTag}/typescript`);
}
exec(`az storage blob upload-batch --auth-mode login --source releases/ --destination '$web' --destination-path cdn/ --overwrite`);
step("Updating an index");
// Make sure we have some kind of index
const isPreRelease = safeTypeScriptPackage.includes("-");
const filename = isPreRelease ? "pre-releases.json" : "releases.json";
exec(`az storage blob download --auth-mode login --container-name '$web' --name indexes/${filename} --file ${filename}`);
exec(`json -I -f ${filename} -e "this.versions = Array.from(new Set([...this.versions, '${safeTypeScriptPackage}'])).sort()"`);
exec.continueOnError(`az storage blob upload --auth-mode login --file ${filename} --container-name '$web' --name indexes/${filename} --overwrite`);
// Update the next.json to be the latest _known_ nightly build of TS
if (isPreRelease) {
const existingReleases = JSON.parse(readFileSync(filename, "utf8")).versions;
const devReleases = existingReleases.filter(f => f.includes("-dev"));
const latest = devReleases.pop();
writeFileSync("releases/next.json", JSON.stringify({ version: latest }));
exec.continueOnError(`az storage blob upload --auth-mode login --file "releases/next.json" --container-name '$web' --name "indexes/next.json" --overwrite`);
}
step("Done!");
if (exec.hasError()) {
process.exit(1);
}
}
main();