forked from OfficeDev/microsoft-teams-library-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-to-cdn.js
62 lines (54 loc) · 2.45 KB
/
deploy-to-cdn.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
const { argv } = require('yargs');
const deploy = require('deploy-azure-cdn');
const KeyVault = require('azure-keyvault');
const fs = require('fs-jetpack');
const path = require('path');
const AuthenticationContext = require('adal-node').AuthenticationContext;
const clientId = argv.clientId;
const clientSecret = argv.clientSecret;
const vaultUri = argv.vaultUri;
const secretName = argv.vaultSecretName;
function getConnectionString() {
const authenticator = function(challenge, callback) {
const context = new AuthenticationContext(challenge.authorization);
return context.acquireTokenWithClientCredentials(challenge.resource, clientId, clientSecret, function(
err,
tokenResponse,
) {
if (err) throw err;
const authorizationValue = tokenResponse.tokenType + ' ' + tokenResponse.accessToken;
return callback(null, authorizationValue);
});
};
const credentials = new KeyVault.KeyVaultCredentials(authenticator);
const keyVaultClient = new KeyVault.KeyVaultClient(credentials);
return keyVaultClient.getSecret(vaultUri, secretName, '').then(res => res.value);
}
(async () => {
const packageJson = fs.read('./package.json', 'json');
const version = packageJson.version;
if (version.includes('beta')) return;
const filePaths = [];
const files = await fs.listAsync('./dist');
files.forEach(file => {
filePaths.push({path: path.resolve(__dirname, 'dist', file)});
})
const logger = console.log;
getConnectionString().then(connectionString => {
const opts = {
serviceOptions: [connectionString], // custom arguments to azure.createBlobService
containerName: 'sdk', // container name in blob
containerOptions: { publicAccessLevel: 'blob' }, // container options
folder: 'v' + version + '/js', // path within container
deleteExistingBlobs: false, // true means recursively deleting anything under folder
concurrentUploadThreads: 2, // number of concurrent uploads, choose best for your network condition
zip: true, // gzip files if they become smaller after zipping, content-encoding header will change if file is zipped
metadata: { cacheControl: 'public, max-age=31556926' }, // metadata for each uploaded file
testRun: false, // test run - means no blobs will be actually deleted or uploaded, see log messages for details
};
deploy(opts, filePaths, logger, function(err) {
if (err) throw err;
console.log('Deployment Successful.');
});
});
})();