20c2b75b01
* refactor: Move Plugins Out and Consolidate with Multisrc * feat: Overhaul Playground UI * feat: Add Filters to New UI * feat: Persist Selected Plugin * feat: Add Direct Parse Novel/Chapter Options and Feedback Toasts [skip ci] * feat: UX Improvements * chore: Update Plugin Path in Publish Workflow * fix: Add Backward Compatibility * chore: Update Plugin Publishing Script
63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
import list from './sources.json' with { type: 'json' };
|
|
import defaultSettings from './settings.json' with { type: 'json' };
|
|
import { readFileSync } from 'fs';
|
|
import { fileURLToPath } from 'url';
|
|
import { dirname, join } from 'path';
|
|
|
|
const folder = dirname(fileURLToPath(import.meta.url));
|
|
const FilterTypes = {
|
|
TextInput: 'Text',
|
|
Picker: 'Picker',
|
|
CheckboxGroup: 'Checkbox',
|
|
Switch: 'Switch',
|
|
ExcludableCheckboxGroup: 'XCheckbox',
|
|
};
|
|
|
|
export const generateAll = function () {
|
|
return list
|
|
.map(p => {
|
|
if (p.filters) {
|
|
p.filters.cat.options.unshift(...defaultSettings.filters.cat.options);
|
|
}
|
|
p.filters = Object.assign(defaultSettings.filters, p.filters);
|
|
|
|
let d = false;
|
|
const filters = {};
|
|
for (const k in p.filters) {
|
|
const f = p.filters[k];
|
|
if (f) {
|
|
filters[k] = {
|
|
...f,
|
|
type: FilterTypes[f.type],
|
|
};
|
|
}
|
|
}
|
|
return { ...p, filters: d ? undefined : filters };
|
|
})
|
|
.map(source => {
|
|
console.log(`[rulate]: Generating`, source.id);
|
|
return generator(source);
|
|
});
|
|
};
|
|
|
|
const generator = function generator(source) {
|
|
const rulateTemplate = readFileSync(join(folder, 'template.ts'), {
|
|
encoding: 'utf-8',
|
|
});
|
|
|
|
const pluginScript = `
|
|
${rulateTemplate}
|
|
const plugin = new RulatePlugin(${JSON.stringify(source)
|
|
.replace(/"type":"([^"]+)"/g, '"type":FilterTypes.$1')
|
|
.replace(/\.XCheckbox/g, '.ExcludableCheckboxGroup') //remember to redo
|
|
.replace(/\.Checkbox/g, '.CheckboxGroup')});
|
|
export default plugin;
|
|
`.trim();
|
|
|
|
return {
|
|
lang: 'russian',
|
|
filename: source.sourceName,
|
|
pluginScript,
|
|
};
|
|
};
|