Files
lnreader-plugins/scripts/multisrc/generate.ts
T
nyagami 20efcf404c refactor: Classes for Plugins (#631)
* set target to ES5

* refactor types

* use .gitkeep

* use dot to make dist/js dirs on top

* add hako

* add Hako

* add madara

* fix: url path js -> .js

* fix: branch

* freestyle for using UA, cookie

* add parseNovels for Hako

* update readme

* fix: conflict types

* add Kolnovel, remove node-fetch

* add bestlightnovel

* add plugins

* WQMangaStreamScraper
* PandaMTL
* NobleMTL
* LightNovelBrasil
* WPMangaStream

* add filters for popularNovels

* fix undefined json

* Linovelib (#26)

* linovelib CN

* icon for linovelib

* fix undefined chapter

* add check

* fix: add artist

* TuNovelaLigera ES + Madara Fix (#28)

* app repo test

* POST is now working

* update madara template + run generator

* template fix didnt get pushed commited idk why

* template update POST

* generated

* fix: useNewChapterEndpoint update (#29)

* useNewChapterEndpoint update

* Update Selectors

---------

Co-authored-by: K1ngfish3r <trulyihu@gmail.com>
2023-11-04 15:45:49 +05:30

52 lines
1.5 KiB
TypeScript

import path from "path";
import fs from "fs";
type GeneratedScript = {
lang: string;
filename: string;
pluginScript: string;
};
export type ScrpitGeneratorFunction = () => GeneratedScript[];
const isScriptGenerator = (s: unknown): s is ScrpitGeneratorFunction => {
return !!s && typeof s === "function";
};
const generate = async (name: string): Promise<boolean> => {
const generateAll: ScrpitGeneratorFunction | unknown =
require(`./${name}/generator`).generateAll;
if (!isScriptGenerator(generateAll)) return false;
const sources = generateAll();
for (let source of sources) {
const { lang, filename, pluginScript } = source;
if(!lang || !filename || !pluginScript){
console.warn(name, ": lang, filename, pluginScript are required!");
continue;
}
const pluginsDir = path.join(
path.dirname(path.dirname(__dirname)),
"plugins"
);
const filePath = path.join(pluginsDir, lang.toLowerCase(), filename.replace(/[\s-\.]+/g, "") + `[${name}].ts`);
fs.writeFileSync(filePath, pluginScript, { encoding: "utf-8" });
}
return true;
};
const run = async () => {
const sources = fs
.readdirSync(__dirname)
.filter((name) =>
fs.lstatSync(path.join(__dirname, name)).isDirectory()
);
for (let name of sources) {
const success = await generate(name);
if (success) console.log(name + " OK");
}
};
run();