d7a76063bf
* Add XCheckboxFilter * Fix madara typo * Change the branch name in config * Add typing for madara popoularnovels filters * Add preview and refactor PluginWrapper * Add preview HTML sanitize and other improv. * Web improvements + sanitizeHTML * Add dark mode * Add git run less to compile less * Add less.js to remove the need for compiling less
54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
import { FilterTypes, Filters } from "../../../libs/filterInputs";
|
|
import { ScrpitGeneratorFunction } from "../generate";
|
|
import list from "./sources.json";
|
|
import { MadaraMetadata } from "./template";
|
|
import { readFileSync } from "fs";
|
|
import path from "path";
|
|
|
|
export const generateAll: ScrpitGeneratorFunction = function (name) {
|
|
return (
|
|
list
|
|
/* This map is changing `type` from string to FilterTypes */
|
|
.map<MadaraMetadata>((p) => {
|
|
let d = false;
|
|
const filters: Filters = {};
|
|
for (const k in p.filters) {
|
|
const f = p.filters[k as "sort" | "genres"];
|
|
if (f) {
|
|
filters[k] = {
|
|
...f,
|
|
type: FilterTypes.Picker,
|
|
};
|
|
}
|
|
}
|
|
return { ...p, filters: d ? undefined : filters };
|
|
})
|
|
.map((metadata: MadaraMetadata) => {
|
|
console.log(`[${name}]: Generating`, metadata.id);
|
|
return generator(metadata);
|
|
})
|
|
);
|
|
};
|
|
|
|
const generator = function generator(metadata: MadaraMetadata) {
|
|
const lang = metadata.options?.lang || "English";
|
|
|
|
const madaraTemplate = readFileSync(path.join(__dirname, "template.ts"), {
|
|
encoding: "utf-8",
|
|
});
|
|
|
|
const pluginScript = `
|
|
${madaraTemplate}
|
|
const plugin = new MadaraPlugin(${JSON.stringify(metadata).replace(
|
|
/"type":"Picker"/g,
|
|
`"type":FilterTypes.Picker`
|
|
)});
|
|
export default plugin;
|
|
`;
|
|
return {
|
|
lang,
|
|
filename: metadata.sourceName,
|
|
pluginScript,
|
|
};
|
|
};
|