UNPKG

2 kBJavaScriptView Raw
1/*
2 * Copyright (c) Microsoft Corporation. All rights reserved.
3 * Licensed under the MIT License.
4 */
5
6const dotenv = require("dotenv");
7const { BlobServiceClient } = require("@azure/storage-blob");
8const pkg = require("./package.json");
9
10dotenv.config({
11 path: "../../.env"
12});
13
14const SIGNATURES = [
15 process.env.CDN_EUNO_SAS,
16 process.env.CDN_USWE_SAS
17];
18
19const FILES = [
20 "msal.js",
21 "msal.js.map",
22 "msal.min.js",
23 "msal.min.js.map"
24];
25
26async function uploadToCdn(sas) {
27 const cdn = sas.split("?")[0];
28
29 console.log("Starting uploads to CDN:", cdn);
30
31 const blobServiceClient = new BlobServiceClient(sas);
32 const containerClient = blobServiceClient.getContainerClient("");
33
34 return Promise.all(FILES.map(async (file) => {
35 const blobName = `lib/${pkg.version}/js/${file}`;
36
37 console.log(cdn, blobName, "Uploading file");
38
39 const blockBlobClient = containerClient.getBlockBlobClient(blobName);
40
41 const fileName = `./dist/${file}`;
42
43 try {
44 const blobExists = await blockBlobClient.exists();
45
46 if (!blobExists) {
47 await blockBlobClient.uploadFile(fileName, {
48 blobHTTPHeaders: {
49 blobContentType: "text/javascript"
50 }
51 });
52
53 console.log(cdn, blobName, "Upload complete");
54 } else {
55 console.warn(cdn, blobName, "File exists");
56 }
57 } catch (e) {
58 console.error(cdn, blobName, "Upload failed");
59 console.error(cdn, blobName, e.statusCode, e.details.errorCode);
60 }
61 }));
62}
63
64Promise.all(SIGNATURES.map(sas => uploadToCdn(sas)))
65 .then(results => {
66 console.log("Uploads complete");
67 })
68 .catch((error) => {
69 console.log("Upload error", error);
70 })
71 .finally(() => {
72 process.exit(0);
73 });
74