| 1 | #!/usr/bin/env node |
| 2 | "use strict"; |
| 3 | |
| 4 | const fs = require("fs"); |
| 5 | const path = require("path"); |
| 6 | |
| 7 | const ROOT = path.resolve(__dirname, ".."); |
| 8 | const RAW_BASE = "https://git.timfalken.com/timfa/hfy-novels/-/raw"; |
| 9 | const REV = "master"; |
| 10 | |
| 11 | function raw(rel) { |
| 12 | return RAW_BASE + "/" + rel.replace(/^\/+/, "") + "?rev=" + encodeURIComponent(REV); |
| 13 | } |
| 14 | |
| 15 | const pluginSrc = path.join(ROOT, "plugin", "hfy-novels.js"); |
| 16 | const distDir = path.join(ROOT, ".dist"); |
| 17 | fs.mkdirSync(distDir, { recursive: true }); |
| 18 | |
| 19 | const source = fs.readFileSync(pluginSrc, "utf8"); |
| 20 | fs.writeFileSync(path.join(distDir, "hfy-novels.js"), source); |
| 21 | |
| 22 | const iconSrc = path.join(ROOT, "plugin", "icon.png"); |
| 23 | const iconDest = path.join(distDir, "icon.png"); |
| 24 | if (fs.existsSync(iconSrc)) { |
| 25 | fs.copyFileSync(iconSrc, iconDest); |
| 26 | } |
| 27 | |
| 28 | // Evalueer de plugin met stubs om id/name/version/settings te lezen. |
| 29 | const 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 | |
| 39 | const pluginModule = { exports: {} }; |
| 40 | const fn = new Function("exports", "require", "module", source); |
| 41 | fn(pluginModule.exports, (name) => stubs[name], pluginModule); |
| 42 | const plugin = pluginModule.exports.default; |
| 43 | if (!plugin || !plugin.id) { |
| 44 | throw new Error("plugin evalueerde niet tot een default-export met een id"); |
| 45 | } |
| 46 | |
| 47 | const 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 | }; |
| 56 | if (plugin.pluginSettings) { |
| 57 | entry.hasSettings = true; |
| 58 | } |
| 59 | |
| 60 | const manifest = [entry]; |
| 61 | const json = JSON.stringify(manifest, null, 2) + "\n"; |
| 62 | fs.writeFileSync(path.join(distDir, "plugins.json"), json); |
| 63 | fs.writeFileSync(path.join(distDir, "plugins.min.json"), JSON.stringify(manifest) + "\n"); |
| 64 | console.log("✔️ manifest: " + plugin.id + " v" + plugin.version); |
| 65 | console.log(" " + entry.url); |