forked from GoogleChrome/workbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish-cdn.js
More file actions
70 lines (57 loc) · 1.99 KB
/
publish-cdn.js
File metadata and controls
70 lines (57 loc) · 1.99 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
64
65
66
67
68
69
70
const gulp = require('gulp');
const path = require('path');
const cdnUploadHelper = require('./utils/cdn-helper');
const publishHelpers = require('./utils/publish-helpers');
const githubHelper = require('./utils/github-helper');
const logHelper = require('../infra/utils/log-helper');
// Git adds 'v' to tag name, lerna does not in package.json version.
// We are going to publish to CDN *without* the 'v'
const cleanTagName = (name) => {
let friendlyTagName = name;
if (friendlyTagName.indexOf('v') === 0) {
friendlyTagName = friendlyTagName.substring(1);
}
return friendlyTagName;
};
const findMissingCDNTags = async (tagsData) => {
const missingTags = [];
for (let tagData of tagsData) {
let exists = await cdnUploadHelper.tagExists(cleanTagName(tagData.name));
if (!exists) {
missingTags.push(tagData);
}
}
return missingTags;
};
const handleCDNUpload = async (tagName, gitBranch) => {
const buildFilesDir =
await publishHelpers.groupBuildFiles(tagName, gitBranch);
const friendlyTagName = cleanTagName(tagName);
logHelper.log(`Uploading '${tagName}' to CDN as ${friendlyTagName}.`);
const publishUrls = await cdnUploadHelper.upload(
friendlyTagName, buildFilesDir);
logHelper.log(`The following URLs are now avaiable:`);
publishUrls.forEach((url) => {
// Only print out the js files just for cleaner logs.
if (path.extname(url) === '.map') {
return;
}
logHelper.log(` ${url}`);
});
};
gulp.task('publish-cdn:generate-from-tags', async () => {
// Get all of the tags in the repo.
const tags = await githubHelper.getTags();
const missingTags = await findMissingCDNTags(tags);
if (missingTags.length === 0) {
logHelper.log(`No tags missing from CDN.`);
}
for (let tagData of missingTags) {
// Override the git branch here since we aren't actually
// using a tagged release.
await handleCDNUpload(tagData.name, tagData.name);
}
});
gulp.task('publish-cdn', gulp.series(
'publish-cdn:generate-from-tags',
));