BlueGit

timfa hfy-novels

Files

hfy-novels / scripts / build-manifest.js

build-manifest.js

build-manifest.js 2.6 KiB Download Raw
1#!/usr/bin/env node
2"use strict";
3
4const fs = require("fs");
5const path = require("path");
6
7const ROOT = path.resolve(__dirname, "..");
8const RAW_BASE = "https://git.timfalken.com/timfa/hfy-novels/-/raw";
9const REV = "master";
10
11function raw(rel) {
12 return RAW_BASE + "/" + rel.replace(/^\/+/, "") + "?rev=" + encodeURIComponent(REV);
13}
14
15const pluginSrc = path.join(ROOT, "plugin", "hfy-novels.js");
16const distDir = path.join(ROOT, ".dist");
17fs.mkdirSync(distDir, { recursive: true });
18
19const source = fs.readFileSync(pluginSrc, "utf8");
20fs.writeFileSync(path.join(distDir, "hfy-novels.js"), source);
21
22const iconSrc = path.join(ROOT, "plugin", "icon.png");
23const iconDest = path.join(distDir, "icon.png");
24if (fs.existsSync(iconSrc)) {
25 fs.copyFileSync(iconSrc, iconDest);
26}
27
28const coversSrcDir = path.join(ROOT, "plugin", "covers");
29const coversDestDir = path.join(distDir, "covers");
30fs.mkdirSync(coversDestDir, { recursive: true });
31for (const name of ["reddit.png", "arctic-shift.png", "index.png"]) {
32 const src = path.join(coversSrcDir, name);
33 if (!fs.existsSync(src)) {
34 throw new Error("ontbrekende broncover: " + name);
35 }
36 fs.copyFileSync(src, path.join(coversDestDir, name));
37}
38
39// Evalueer de plugin met stubs om id/name/version/settings te lezen.
40const stubs = {
41 "@libs/fetch": { fetchApi: async () => ({ ok: true, json: async () => ({}) }) },
42 "@libs/filterInputs": { FilterTypes: { Picker: "Picker", Switch: "Switch" } },
43 "@libs/defaultCover": { defaultCover: "default" },
44 "@libs/novelStatus": {
45 NovelStatus: { Completed: "Completed", Ongoing: "Ongoing", OnHiatus: "On Hiatus", Unknown: "Unknown" },
46 },
47 "@libs/storage": { storage: { get: () => undefined, set: () => {} } },
48};
49
50const pluginModule = { exports: {} };
51const fn = new Function("exports", "require", "module", source);
52fn(pluginModule.exports, (name) => stubs[name], pluginModule);
53const plugin = pluginModule.exports.default;
54if (!plugin || !plugin.id) {
55 throw new Error("plugin evalueerde niet tot een default-export met een id");
56}
57
58const entry = {
59 id: plugin.id,
60 name: plugin.name,
61 site: plugin.site,
62 lang: "English",
63 version: plugin.version,
64 url: raw(".dist/hfy-novels.js"),
65 iconUrl: raw(".dist/icon.png"),
66};
67if (plugin.pluginSettings) {
68 entry.hasSettings = true;
69}
70
71const manifest = [entry];
72const json = JSON.stringify(manifest, null, 2) + "\n";
73fs.writeFileSync(path.join(distDir, "plugins.json"), json);
74fs.writeFileSync(path.join(distDir, "plugins.min.json"), JSON.stringify(manifest) + "\n");
75console.log("✔️ manifest: " + plugin.id + " v" + plugin.version);
76console.log(" " + entry.url);