forked from AzureAD/microsoft-authentication-library-for-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcdn-upload.js
More file actions
65 lines (49 loc) · 1.63 KB
/
cdn-upload.js
File metadata and controls
65 lines (49 loc) · 1.63 KB
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
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 = [
'msal-browser.js',
'msal-browser.js.map',
'msal-browser.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 = `browser/${pkg.version}/js/${file}`;
console.log(cdn, blobName, 'Uploading file');
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
const fileName = `./lib/${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(() => {
console.log('Uploads complete');
})
.finally(() => {
process.exit(0);
})