1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | const dotenv = require("dotenv");
|
7 | const { BlobServiceClient } = require("@azure/storage-blob");
|
8 | const pkg = require("./package.json");
|
9 |
|
10 | dotenv.config({
|
11 | path: "../../.env"
|
12 | });
|
13 |
|
14 | const SIGNATURES = [
|
15 | process.env.CDN_EUNO_SAS,
|
16 | process.env.CDN_USWE_SAS
|
17 | ];
|
18 |
|
19 | const FILES = [
|
20 | "msal.js",
|
21 | "msal.js.map",
|
22 | "msal.min.js",
|
23 | "msal.min.js.map"
|
24 | ];
|
25 |
|
26 | async 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 |
|
64 | Promise.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 |
|