Repository navigation
Expand file tree
/
Copy pathskill.js
More file actions
37 lines (33 loc) · 1.85 KB
/
Copy pathskill.js
File metadata and controls
37 lines (33 loc) · 1.85 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
import { existsSync, readdirSync, readFileSync } from "node:fs";
import { join, relative, sep } from "node:path";
import { contentTypes, openPack } from "@missing-elements/h5p-author";
// The h5p-author skill as the pinned @missing-elements/h5p-author carries it since 0.9.0: its
// SKILL.md, licence and references/, which eleventy.config.js copies to /h5p/skill/ as they are.
// src/h5p/skill/ lists them, each at its full address.
const author = "node_modules/@missing-elements/h5p-author";
const { version } = JSON.parse(readFileSync(`${author}/package.json`, "utf8"));
if (!existsSync(`${author}/SKILL.md`)) throw new Error(`@missing-elements/h5p-author ${version} carries no SKILL.md: 0.9.0 is the first that does`);
const references = readdirSync(`${author}/references`, { recursive: true, withFileTypes: true })
.filter((entry) => entry.isFile())
.map((entry) => relative(author, join(entry.parentPath, entry.name)).split(sep).join("/"))
.sort();
const types = references.filter((path) => path.startsWith("references/types/"));
// What a build where npm cannot be reached fetches (SKILL.md's step 3), which vite.config.ts
// writes to /h5p/bundles/ after this page: the command line, and a bundle per content type, named
// by the author package's own list of them, the one its `writeBundles` writes from.
const pack = await openPack();
let bundles;
try {
bundles = (await contentTypes(pack)).map((part) => `${part.library.machineName}.zip`);
} finally {
await pack.close();
}
export default {
version,
// What SKILL.md names and the type files, apart, as the page lists them; `files` is every one.
named: [...references.filter((path) => !types.includes(path)), "LICENSE"],
types,
files: ["SKILL.md", ...references.filter((path) => !types.includes(path)), "LICENSE", ...types],
// In /h5p/bundles/, the tool first.
bundles: ["h5p-author.mjs", ...bundles],
};