1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | const assert = require('assert');
|
10 |
|
11 | const cdn = require('../cdn-details.json');
|
12 | const errors = require('./errors');
|
13 |
|
14 | const getCDNOrigin = () => {
|
15 | return `${cdn.origin}/${cdn.bucketName}/${cdn.releasesDir}`;
|
16 | };
|
17 |
|
18 | const getVersionedCDNURL = () => {
|
19 | return `${getCDNOrigin()}/${cdn.latestVersion}`;
|
20 | };
|
21 |
|
22 | const getModuleURL = (moduleName, buildType) => {
|
23 | assert(moduleName, errors['no-module-name']);
|
24 |
|
25 | if (buildType) {
|
26 | const pkgJson = require(`${moduleName}/package.json`);
|
27 | if (buildType === 'dev' && pkgJson.workbox.prodOnly) {
|
28 |
|
29 |
|
30 | throw Error(`The 'dev' build of ${moduleName} is not available.`);
|
31 | }
|
32 | return `${getVersionedCDNURL()}/${moduleName}.${buildType.slice(0, 4)}.js`;
|
33 | }
|
34 | return `${getVersionedCDNURL()}/${moduleName}.js`;
|
35 | };
|
36 |
|
37 | module.exports = {
|
38 | getCDNOrigin,
|
39 | getModuleURL,
|
40 | };
|