BlueGit

timfa hfy-novels

Files

hfy-novels / scripts / build-manifest.js

build-manifest.js

build-manifest.js 2.3 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 coversSrc = path.join(ROOT, "plugin", "covers.js");
17const distDir = path.join(ROOT, ".dist");
18fs.mkdirSync(distDir, { recursive: true });
19
20const source = fs.readFileSync(coversSrc, "utf8") + "\n" + fs.readFileSync(pluginSrc, "utf8");
21fs.writeFileSync(path.join(distDir, "hfy-novels.js"), source);
22
23const iconSrc = path.join(ROOT, "plugin", "icon.png");
24const iconDest = path.join(distDir, "icon.png");
25if (fs.existsSync(iconSrc)) {
26 fs.copyFileSync(iconSrc, iconDest);
27}
28
29// Evalueer de plugin met stubs om id/name/version/settings te lezen.
30const stubs = {
31 "@libs/fetch": { fetchApi: async () => ({ ok: true, json: async () => ({}) }) },
32 "@libs/filterInputs": { FilterTypes: { Picker: "Picker", Switch: "Switch" } },
33 "@libs/defaultCover": { defaultCover: "default" },
34 "@libs/novelStatus": {
35 NovelStatus: { Completed: "Completed", Ongoing: "Ongoing", OnHiatus: "On Hiatus", Unknown: "Unknown" },
36 },
37 "@libs/storage": { storage: { get: () => undefined, set: () => {} } },
38};
39
40const pluginModule = { exports: {} };
41const fn = new Function("exports", "require", "module", source);
42fn(pluginModule.exports, (name) => stubs[name], pluginModule);
43const plugin = pluginModule.exports.default;
44if (!plugin || !plugin.id) {
45 throw new Error("plugin evalueerde niet tot een default-export met een id");
46}
47
48const entry = {
49 id: plugin.id,
50 name: plugin.name,
51 site: plugin.site,
52 lang: "English",
53 version: plugin.version,
54 url: raw(".dist/hfy-novels.js"),
55 iconUrl: raw(".dist/icon.png"),
56};
57if (plugin.pluginSettings) {
58 entry.hasSettings = true;
59}
60
61const manifest = [entry];
62const json = JSON.stringify(manifest, null, 2) + "\n";
63fs.writeFileSync(path.join(distDir, "plugins.json"), json);
64fs.writeFileSync(path.join(distDir, "plugins.min.json"), JSON.stringify(manifest) + "\n");
65console.log("✔️ manifest: " + plugin.id + " v" + plugin.version);
66console.log(" " + entry.url);