forked from AzureAD/microsoft-authentication-library-for-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdn-upload.js
71 lines (55 loc) · 1.77 KB
/
cdn-upload.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
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
const dotenv = require("dotenv");
const { BlobServiceClient } = require("@azure/storage-blob");
const pkg = require("./package.json");
dotenv.config({
path: "../../.env"
});
const SIGNATURES = [
process.env.CDN_EUNO_SAS,
process.env.CDN_USWE_SAS
];
const FILES = [
"adal.min.js",
"adal-angular.min.js"
];
async function uploadToCdn(sas) {
const cdn = sas.split("?")[0];
console.log("Starting uploads to CDN:", cdn);
const blobServiceClient = new BlobServiceClient(sas);
const containerClient = blobServiceClient.getContainerClient("");
return Promise.all(FILES.map(async (file) => {
const blobName = `lib/${pkg.version}/js/${file}`;
console.log(cdn, blobName, "Uploading file");
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
const fileName = `./build/${file}`;
try {
const blobExists = await blockBlobClient.exists();
if (!blobExists) {
await blockBlobClient.uploadFile(fileName, {
blobHTTPHeaders: {
blobContentType: "text/javascript"
}
});
console.log(cdn, blobName, "Upload complete");
} else {
console.warn(cdn, blobName, "File exists");
}
} catch (e) {
console.error(cdn, blobName, "Upload failed");
}
}));
}
Promise.all(SIGNATURES.map(sas => uploadToCdn(sas)))
.then(results => {
console.log("Uploads complete");
})
.catch((error) => {
console.log("Upload error", error);
})
.finally(() => {
process.exit(0);
});