@ranx729/ducktape-assets 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/generate.mjs CHANGED
@@ -5,15 +5,18 @@ import { fileUrl } from './urls.mjs';
5
5
 
6
6
  const REPO = 'https://github.com/adrian729';
7
7
 
8
- export function indexEntry(manifest, { status = 'active' } = {}) {
9
- const mastersCdn = manifest.cdn.replace(`${manifest.package}@`, `${manifest.mastersPackage}@`);
8
+ // `cdnTemplate` (CDN contingency, level 1) replaces the jsDelivr bases with a host that folds a set's packages into
9
+ // one tree: `<set>` and `<version>` are substituted, and masters share the base.
10
+ export function indexEntry(manifest, { status = 'active', cdnTemplate } = {}) {
11
+ const cdn = cdnTemplate ? cdnTemplate.replaceAll('<set>', manifest.set).replaceAll('<version>', manifest.version) : manifest.cdn;
12
+ const mastersCdn = cdnTemplate ? cdn : manifest.cdn.replace(`${manifest.package}@`, `${manifest.mastersPackage}@`);
10
13
  return {
11
14
  version: manifest.version,
12
15
  package: manifest.package,
13
16
  parts: manifest.parts ?? [],
14
17
  mastersPackage: manifest.mastersPackage,
15
18
  mastersParts: manifest.mastersParts ?? [],
16
- cdn: manifest.cdn,
19
+ cdn,
17
20
  mastersCdn,
18
21
  assets: Object.keys(manifest.assets).length,
19
22
  license: { artwork: manifest.license.artwork },
@@ -58,12 +61,12 @@ export function catalogEntry(setId, manifest, entry, assetId, asset) {
58
61
  * @param {string} [o.generatedAt]
59
62
  * @returns {{index, catalog, sets, readme, agents}}
60
63
  */
61
- export function generateIndex({ manifests, previous, generatedAt } = {}) {
64
+ export function generateIndex({ manifests, previous, generatedAt, cdnTemplate } = {}) {
62
65
  const list = [...manifests].sort((a, b) => a.setId.localeCompare(b.setId));
63
66
  const sets = {};
64
67
  const entries = {};
65
68
  for (const { setId, manifest, status } of list) {
66
- sets[setId] = indexEntry(manifest, { status });
69
+ sets[setId] = indexEntry(manifest, { status, cdnTemplate });
67
70
  entries[setId] = manifest;
68
71
  }
69
72
  const unchanged = previous && JSON.stringify(previous.sets) === JSON.stringify(sets);