BlueGit

timfa hfy-novels

Files

hfy-novels / scripts / build-manifest.js

build-manifest.js

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