Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions plugins/multisrc/activeSources.js
Original file line number Diff line number Diff line change
@@ -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;
Comment thread
RikCost marked this conversation as resolved.
}
return true;
});
5 changes: 4 additions & 1 deletion plugins/multisrc/fictioneer/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
20 changes: 18 additions & 2 deletions plugins/multisrc/generate-multisrc-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
);
Expand Down
5 changes: 4 additions & 1 deletion plugins/multisrc/hotnovelpub/generator.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
5 changes: 4 additions & 1 deletion plugins/multisrc/ifreedom/generator.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
5 changes: 4 additions & 1 deletion plugins/multisrc/lightnovelwp/generator.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
5 changes: 4 additions & 1 deletion plugins/multisrc/madara/generator.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
5 changes: 4 additions & 1 deletion plugins/multisrc/mtlnovel/generator.js
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
5 changes: 4 additions & 1 deletion plugins/multisrc/novelcool/generator.js
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
5 changes: 4 additions & 1 deletion plugins/multisrc/novelfire/generator.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
5 changes: 4 additions & 1 deletion plugins/multisrc/ranobes/generator.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
5 changes: 4 additions & 1 deletion plugins/multisrc/readnovelfull/generator.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
5 changes: 4 additions & 1 deletion plugins/multisrc/readwn/generator.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
5 changes: 4 additions & 1 deletion plugins/multisrc/rulate/generator.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
5 changes: 4 additions & 1 deletion plugins/multisrc/webnovelworld/generator.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
Loading