#!/usr/bin/env node "use strict"; const fs = require("fs"); const path = require("path"); const ROOT = path.resolve(__dirname, ".."); const RAW_BASE = "https://git.timfalken.com/timfa/hfy-novels/-/raw"; const REV = "master"; function raw(rel) { return RAW_BASE + "/" + rel.replace(/^\/+/, "") + "?rev=" + encodeURIComponent(REV); } const pluginSrc = path.join(ROOT, "plugin", "hfy-novels.js"); const distDir = path.join(ROOT, ".dist"); fs.mkdirSync(distDir, { recursive: true }); const source = fs.readFileSync(pluginSrc, "utf8"); fs.writeFileSync(path.join(distDir, "hfy-novels.js"), source); const iconSrc = path.join(ROOT, "plugin", "icon.png"); const iconDest = path.join(distDir, "icon.png"); if (fs.existsSync(iconSrc)) { fs.copyFileSync(iconSrc, iconDest); } const coversSrcDir = path.join(ROOT, "plugin", "covers"); const coversDestDir = path.join(distDir, "covers"); fs.mkdirSync(coversDestDir, { recursive: true }); for (const name of ["reddit.png", "arctic-shift.png", "index.png"]) { const src = path.join(coversSrcDir, name); if (!fs.existsSync(src)) { throw new Error("ontbrekende broncover: " + name); } fs.copyFileSync(src, path.join(coversDestDir, name)); } // Evalueer de plugin met stubs om id/name/version/settings te lezen. const stubs = { "@libs/fetch": { fetchApi: async () => ({ ok: true, json: async () => ({}) }) }, "@libs/filterInputs": { FilterTypes: { Picker: "Picker", Switch: "Switch" } }, "@libs/defaultCover": { defaultCover: "default" }, "@libs/novelStatus": { NovelStatus: { Completed: "Completed", Ongoing: "Ongoing", OnHiatus: "On Hiatus", Unknown: "Unknown" }, }, "@libs/storage": { storage: { get: () => undefined, set: () => {} } }, }; const pluginModule = { exports: {} }; const fn = new Function("exports", "require", "module", source); fn(pluginModule.exports, (name) => stubs[name], pluginModule); const plugin = pluginModule.exports.default; if (!plugin || !plugin.id) { throw new Error("plugin evalueerde niet tot een default-export met een id"); } const entry = { id: plugin.id, name: plugin.name, site: plugin.site, lang: "English", version: plugin.version, url: raw(".dist/hfy-novels.js"), iconUrl: raw(".dist/icon.png"), }; if (plugin.pluginSettings) { entry.hasSettings = true; } const manifest = [entry]; const json = JSON.stringify(manifest, null, 2) + "\n"; fs.writeFileSync(path.join(distDir, "plugins.json"), json); fs.writeFileSync(path.join(distDir, "plugins.min.json"), JSON.stringify(manifest) + "\n"); console.log("✔️ manifest: " + plugin.id + " v" + plugin.version); console.log(" " + entry.url);