UNPKG

1.13 kBJavaScriptView Raw
1/*
2 Copyright 2018 Google LLC
3
4 Use of this source code is governed by an MIT-style
5 license that can be found in the LICENSE file or at
6 https://opensource.org/licenses/MIT.
7*/
8
9const assert = require('assert');
10
11const cdn = require('../cdn-details.json');
12const errors = require('./errors');
13
14const getCDNOrigin = () => {
15 return `${cdn.origin}/${cdn.bucketName}/${cdn.releasesDir}`;
16};
17
18const getVersionedCDNURL = () => {
19 return `${getCDNOrigin()}/${cdn.latestVersion}`;
20};
21
22const 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 // This is not due to a public-facing exception, so just throw an Error(),
29 // without creating an entry in errors.js.
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
37module.exports = {
38 getCDNOrigin,
39 getModuleURL,
40};