Files
lnreader-plugins/scripts/multisrc/lightnovelwp/generator.js
T
Justin COLLON 660b5bbf01 fix: Correct multiSrc Filters & Update Asura Light Novel to Srank Manga (#1082)
* Asura Light Novel => Srank Manga

* fix ‘npm run icons‘ & new icon asuralightnovel

* fix filters for multisrc:
- lightnovelwp
- madara
- readwn
2024-07-22 16:00:20 +05:30

44 lines
1.2 KiB
JavaScript

import list from './sources.json' with { type: 'json' };
import { existsSync, readFileSync } from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const folder = dirname(fileURLToPath(import.meta.url));
export const generateAll = function () {
return list.map(source => {
const exist = existsSync(join(folder, 'filters', source.id + '.json'));
if (exist) {
const filters = readFileSync(
join(folder, 'filters', source.id + '.json'),
);
source.filters = JSON.parse(filters).filters;
}
console.log(
`[lightnovelwp] Generating: ${source.id}${' '.repeat(20 - source.id.length)} ${source.filters ? '🔎with filters🔍' : '🚫no filters🚫'}`,
);
return generator(source);
});
};
const generator = function generator(source) {
const LightNovelWPTemplate = readFileSync(join(folder, 'template.ts'), {
encoding: 'utf-8',
});
const pluginScript = `
${LightNovelWPTemplate.replace(
'// CustomJS HERE',
source.options?.customJs || '',
)}
const plugin = new LightNovelWPPlugin(${JSON.stringify(source)});
export default plugin;
`.trim();
return {
lang: source.options?.lang || 'English',
filename: source.sourceName,
pluginScript,
};
};