fae73534dd
* test * cleanup deleted unused `fetchFile` import replaced fetch with `fetchApi` * eslint * fix * fix multi * Hmm, what to do next. * test URLSearchParams * fix
37 lines
1007 B
JavaScript
37 lines
1007 B
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));
|
|
|
|
export const generateAll = function () {
|
|
return list.map(metadata => {
|
|
metadata.filters = Object.assign(defaultSettings.filters, metadata.filters);
|
|
console.log(`[ifreedom]: Generating`, metadata.id);
|
|
return generator(metadata);
|
|
});
|
|
};
|
|
|
|
const generator = function generator(metadata) {
|
|
const IfreedomTemplate = readFileSync(join(folder, 'template.ts'), {
|
|
encoding: 'utf-8',
|
|
});
|
|
|
|
const pluginScript = `
|
|
${IfreedomTemplate}
|
|
const plugin = new IfreedomPlugin(${JSON.stringify(metadata).replace(
|
|
/"type":"([^"]+)"/g,
|
|
'"type":FilterTypes.$1',
|
|
)});
|
|
export default plugin;
|
|
`.trim();
|
|
|
|
return {
|
|
lang: 'russian',
|
|
filename: metadata.sourceName,
|
|
pluginScript,
|
|
};
|
|
};
|