diff --git a/plugins/multisrc/activeSources.js b/plugins/multisrc/activeSources.js new file mode 100644 index 000000000..7b79ffa4e --- /dev/null +++ b/plugins/multisrc/activeSources.js @@ -0,0 +1,11 @@ +// Sources marked `"options": { "down": true }` in a generator's sources.json +// stay listed there for reference but are not generated, so dead sites are +// not published as working plugins. +export const activeSources = (sources, generator) => + sources.filter(source => { + if (source.options?.down) { + console.log(`[${generator}]: Skipping down source`, source.id); + return false; + } + return true; + }); diff --git a/plugins/multisrc/fictioneer/generator.js b/plugins/multisrc/fictioneer/generator.js index 452a878e6..00007d97a 100644 --- a/plugins/multisrc/fictioneer/generator.js +++ b/plugins/multisrc/fictioneer/generator.js @@ -4,7 +4,10 @@ import { dirname, join } from 'path'; const folder = dirname(fileURLToPath(import.meta.url)); -import list from './sources.json' with { type: 'json' }; +import allSources from './sources.json' with { type: 'json' }; +import { activeSources } from '../activeSources.js'; + +const list = activeSources(allSources, 'fictioneer'); export const generateAll = function () { return list.map(source => { diff --git a/plugins/multisrc/generate-multisrc-plugins.js b/plugins/multisrc/generate-multisrc-plugins.js index 17cd119b0..bcbdd41bf 100644 --- a/plugins/multisrc/generate-multisrc-plugins.js +++ b/plugins/multisrc/generate-multisrc-plugins.js @@ -13,20 +13,36 @@ const isScriptGenerator = s => { return !!s && typeof s === 'function'; }; +const PLUGINS_DIR = './plugins'; + +// Drops a generator's previous output, so sources that are now skipped +// (e.g. marked down) or renamed do not linger when the playground runs +// generation without `clean:multisrc` first. +const removeGenerated = name => { + for (const lang of fs.readdirSync(PLUGINS_DIR)) { + const dir = path.join(PLUGINS_DIR, lang); + if (lang === 'multisrc' || !fs.lstatSync(dir).isDirectory()) continue; + for (const file of fs.readdirSync(dir)) { + if (file.endsWith(`[${name}].ts`)) fs.unlinkSync(path.join(dir, file)); + } + } +}; + const generate = async name => { try { const generateAll = (await import(`./${name}/generator.js`)).generateAll; if (!isScriptGenerator(generateAll)) return false; const sources = generateAll(); + // only after generateAll succeeded, so a broken generator keeps its output + removeGenerated(name); for (let source of sources) { const { lang, filename, pluginScript } = source; if (!lang || !filename || !pluginScript) { console.warn(name, ': lang, filename, pluginScript are required!'); continue; } - const pluginsDir = './plugins'; const filePath = path.join( - pluginsDir, + PLUGINS_DIR, lang.toLowerCase(), filename.replace(/[\s-.]+/g, '') + `[${name}].ts`, ); diff --git a/plugins/multisrc/hotnovelpub/generator.js b/plugins/multisrc/hotnovelpub/generator.js index 7daca0601..d395c5f42 100644 --- a/plugins/multisrc/hotnovelpub/generator.js +++ b/plugins/multisrc/hotnovelpub/generator.js @@ -1,8 +1,11 @@ -import list from './sources.json' with { type: 'json' }; +import allSources from './sources.json' with { type: 'json' }; +import { activeSources } from '../activeSources.js'; import { readFileSync } from 'fs'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; +const list = activeSources(allSources, 'hotnovelpub'); + const folder = dirname(fileURLToPath(import.meta.url)); const FilterTypes = { TextInput: 'Text', diff --git a/plugins/multisrc/ifreedom/generator.js b/plugins/multisrc/ifreedom/generator.js index 032768446..3e9f8f347 100644 --- a/plugins/multisrc/ifreedom/generator.js +++ b/plugins/multisrc/ifreedom/generator.js @@ -1,9 +1,12 @@ -import list from './sources.json' with { type: 'json' }; +import allSources from './sources.json' with { type: 'json' }; +import { activeSources } from '../activeSources.js'; import defaultSettings from './settings.json' with { type: 'json' }; import { readFileSync } from 'fs'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; +const list = activeSources(allSources, 'ifreedom'); + const folder = dirname(fileURLToPath(import.meta.url)); export const generateAll = function () { diff --git a/plugins/multisrc/lightnovelwp/generator.js b/plugins/multisrc/lightnovelwp/generator.js index d6bcd242e..52b84744c 100644 --- a/plugins/multisrc/lightnovelwp/generator.js +++ b/plugins/multisrc/lightnovelwp/generator.js @@ -1,8 +1,11 @@ -import list from './sources.json' with { type: 'json' }; +import allSources from './sources.json' with { type: 'json' }; +import { activeSources } from '../activeSources.js'; import { existsSync, readFileSync } from 'fs'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; +const list = activeSources(allSources, 'lightnovelwp'); + const folder = dirname(fileURLToPath(import.meta.url)); export const generateAll = function () { diff --git a/plugins/multisrc/madara/generator.js b/plugins/multisrc/madara/generator.js index cb3fa09c7..1da818295 100644 --- a/plugins/multisrc/madara/generator.js +++ b/plugins/multisrc/madara/generator.js @@ -1,8 +1,11 @@ -import list from './sources.json' with { type: 'json' }; +import allSources from './sources.json' with { type: 'json' }; +import { activeSources } from '../activeSources.js'; import { existsSync, readFileSync } from 'fs'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; +const list = activeSources(allSources, 'madara'); + const folder = dirname(fileURLToPath(import.meta.url)); export const generateAll = function () { diff --git a/plugins/multisrc/mtlnovel/generator.js b/plugins/multisrc/mtlnovel/generator.js index b058f439b..b45a55310 100644 --- a/plugins/multisrc/mtlnovel/generator.js +++ b/plugins/multisrc/mtlnovel/generator.js @@ -1,7 +1,10 @@ -import list from './sources.json' with { type: 'json' }; +import allSources from './sources.json' with { type: 'json' }; +import { activeSources } from '../activeSources.js'; import { readFileSync } from 'fs'; import { fileURLToPath } from 'url'; import { dirname } from 'path'; + +const list = activeSources(allSources, 'mtlnovel'); const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); diff --git a/plugins/multisrc/novelcool/generator.js b/plugins/multisrc/novelcool/generator.js index d9d05c9af..abf123a34 100644 --- a/plugins/multisrc/novelcool/generator.js +++ b/plugins/multisrc/novelcool/generator.js @@ -1,7 +1,10 @@ -import list from './sources.json' with { type: 'json' }; +import allSources from './sources.json' with { type: 'json' }; +import { activeSources } from '../activeSources.js'; import { readFileSync } from 'fs'; import { fileURLToPath } from 'url'; import { dirname } from 'path'; + +const list = activeSources(allSources, 'novelcool'); const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); diff --git a/plugins/multisrc/novelfire/generator.js b/plugins/multisrc/novelfire/generator.js index 387851414..38af85a11 100644 --- a/plugins/multisrc/novelfire/generator.js +++ b/plugins/multisrc/novelfire/generator.js @@ -1,8 +1,11 @@ -import list from './sources.json' with { type: 'json' }; +import allSources from './sources.json' with { type: 'json' }; +import { activeSources } from '../activeSources.js'; import { existsSync, readFileSync } from 'fs'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; +const list = activeSources(allSources, 'novelfire'); + const folder = dirname(fileURLToPath(import.meta.url)); export const generateAll = function () { diff --git a/plugins/multisrc/ranobes/generator.js b/plugins/multisrc/ranobes/generator.js index 07229b7e3..3ff93411f 100644 --- a/plugins/multisrc/ranobes/generator.js +++ b/plugins/multisrc/ranobes/generator.js @@ -1,8 +1,11 @@ -import list from './sources.json' with { type: 'json' }; +import allSources from './sources.json' with { type: 'json' }; +import { activeSources } from '../activeSources.js'; import { readFileSync } from 'fs'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; +const list = activeSources(allSources, 'ranobes'); + const folder = dirname(fileURLToPath(import.meta.url)); export const generateAll = function () { diff --git a/plugins/multisrc/readnovelfull/generator.js b/plugins/multisrc/readnovelfull/generator.js index b897ed2d6..53b69fcaa 100644 --- a/plugins/multisrc/readnovelfull/generator.js +++ b/plugins/multisrc/readnovelfull/generator.js @@ -1,8 +1,11 @@ -import list from './sources.json' with { type: 'json' }; +import allSources from './sources.json' with { type: 'json' }; +import { activeSources } from '../activeSources.js'; import { existsSync, readFileSync } from 'fs'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; +const list = activeSources(allSources, 'readnovelfull'); + const folder = dirname(fileURLToPath(import.meta.url)); export const generateAll = function () { diff --git a/plugins/multisrc/readwn/generator.js b/plugins/multisrc/readwn/generator.js index c4ae9e9b6..2985a6b1d 100644 --- a/plugins/multisrc/readwn/generator.js +++ b/plugins/multisrc/readwn/generator.js @@ -1,8 +1,11 @@ -import list from './sources.json' with { type: 'json' }; +import allSources from './sources.json' with { type: 'json' }; +import { activeSources } from '../activeSources.js'; import { existsSync, readFileSync } from 'fs'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; +const list = activeSources(allSources, 'readwn'); + const folder = dirname(fileURLToPath(import.meta.url)); export const generateAll = function () { diff --git a/plugins/multisrc/rulate/generator.js b/plugins/multisrc/rulate/generator.js index bfda48f34..7f93bbf0b 100644 --- a/plugins/multisrc/rulate/generator.js +++ b/plugins/multisrc/rulate/generator.js @@ -1,9 +1,12 @@ -import list from './sources.json' with { type: 'json' }; +import allSources from './sources.json' with { type: 'json' }; +import { activeSources } from '../activeSources.js'; import defaultSettings from './settings.json' with { type: 'json' }; import { existsSync, readFileSync } from 'fs'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; +const list = activeSources(allSources, 'rulate'); + const folder = dirname(fileURLToPath(import.meta.url)); const key = 'fpoiKLUues81werht039'; diff --git a/plugins/multisrc/webnovelworld/generator.js b/plugins/multisrc/webnovelworld/generator.js index 01b39e7a2..8402fa92f 100644 --- a/plugins/multisrc/webnovelworld/generator.js +++ b/plugins/multisrc/webnovelworld/generator.js @@ -1,8 +1,11 @@ -import list from './sources.json' with { type: 'json' }; +import allSources from './sources.json' with { type: 'json' }; +import { activeSources } from '../activeSources.js'; import { existsSync, readFileSync } from 'fs'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; +const list = activeSources(allSources, 'webnovelworld'); + const folder = dirname(fileURLToPath(import.meta.url)); export const generateAll = function () {