6bc3900d30
* remove .env file * remove dotenv, move json dir * fix: create dir if not exists * test actions * fix: specific branch * test double commit * fix: only add dist dir * cleanup * test push without updating json * test actions without plugins diff * plugins: update json files for new plugins (#7) * test without config.json * plugins: update json files for new plugins (#8) * fix: ordering in Win is not the same as Linux * plugins: update json files for new plugins (#10) * test no update * test: create PR if there're changes * fix: wrong path * test: if there're changes * fix: wrong operator * fix: assign boolean to github output * plugins: update json files for new plugins (#13) * clean up and update README * clean up * last cleant up xD
53 lines
1.8 KiB
JavaScript
53 lines
1.8 KiB
JavaScript
const fs = require('fs');
|
|
const languages = require('@libs/languages');
|
|
const path = require('path')
|
|
const root = path.dirname(require.main.filename);
|
|
|
|
const all_plugins = () => {
|
|
const res = {}
|
|
for (let language in languages) { //language with English name
|
|
const langPath = path.join(root, 'plugins', language.toLowerCase());
|
|
if (!fs.existsSync(langPath)) continue;
|
|
const plugins = fs.readdirSync(langPath);
|
|
res[languages[language]] = [];
|
|
plugins.forEach(plugin => {
|
|
if(plugin.startsWith('.')) return;
|
|
const requirePath = `@plugins/${language.toLowerCase()}/${plugin.split('.')[0]}`
|
|
const instance = require(requirePath);
|
|
const { id, name, lang, version, description } = instance;
|
|
const info = { id, name, lang, version, description } // lang: language with native name
|
|
info.requirePath = requirePath;
|
|
res[lang].push(info);
|
|
});
|
|
}
|
|
return res;
|
|
}
|
|
|
|
const popularNovels = async (pluginRequirePath, {showLatestNovels, filters}) => {
|
|
return await require(pluginRequirePath).popularNovels(1, {showLatestNovels, filters});
|
|
}
|
|
|
|
const searchNovels = async (pluginRequirePath, searchTerm) => {
|
|
return await require(pluginRequirePath).searchNovels(searchTerm);
|
|
}
|
|
|
|
const parseNovelAndChapters = async(pluginRequirePath, novelUrl) => {
|
|
return await require(pluginRequirePath).parseNovelAndChapters(novelUrl);
|
|
}
|
|
|
|
const parseChapter = async (pluginRequirePath, chapterUrl) => {
|
|
return await require(pluginRequirePath).parseChapter(chapterUrl);
|
|
}
|
|
|
|
const fetchImage = async (pluginRequirePath, url) => {
|
|
return await require(pluginRequirePath).fetchImage(url);
|
|
}
|
|
|
|
module.exports = {
|
|
all_plugins,
|
|
popularNovels,
|
|
searchNovels,
|
|
parseNovelAndChapters,
|
|
parseChapter,
|
|
fetchImage
|
|
} |