refactor: Rulate (#1998)
* update * test * fix * restore * chapterNumber * up#
This commit is contained in:
@@ -1,43 +1,33 @@
|
||||
import list from './sources.json' with { type: 'json' };
|
||||
import defaultSettings from './settings.json' with { type: 'json' };
|
||||
import { readFileSync } from 'fs';
|
||||
import { existsSync, 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',
|
||||
};
|
||||
const key = 'fpoiKLUues81werht039';
|
||||
|
||||
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);
|
||||
return list.map(source => {
|
||||
source.key = key;
|
||||
source.filters = defaultSettings.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 exist = existsSync(
|
||||
join(folder, 'filters', source.sourceName + '.json'),
|
||||
);
|
||||
if (exist) {
|
||||
const filters = readFileSync(
|
||||
join(folder, 'filters', source.sourceName + '.json'),
|
||||
);
|
||||
source.filters = Object.assign(
|
||||
defaultSettings.filters,
|
||||
JSON.parse(filters).filters,
|
||||
);
|
||||
}
|
||||
|
||||
console.log(`[rulate]: Generating`, source.id);
|
||||
return generator(source);
|
||||
});
|
||||
};
|
||||
|
||||
const generator = function generator(source) {
|
||||
@@ -47,10 +37,7 @@ const generator = function generator(source) {
|
||||
|
||||
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')});
|
||||
const plugin = new RulatePlugin(${JSON.stringify(source)});
|
||||
export default plugin;
|
||||
`.trim();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user