mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-03 10:38:03 +08:00
feat: build-maintainer.ts
This commit is contained in:
@@ -1,27 +1,33 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { directoryImport } from 'directory-import';
|
||||
|
||||
const target = path.join(__dirname, '../../assets/build/maintainer.json');
|
||||
const dirname = path.join(__dirname + '../../../lib/routes');
|
||||
|
||||
// Presence Check
|
||||
for (const dir of fs.readdirSync(dirname)) {
|
||||
const dirPath = path.join(dirname, dir);
|
||||
if (fs.existsSync(path.join(dirPath, 'router.js')) && !fs.existsSync(path.join(dirPath, 'maintainer.js'))) {
|
||||
throw new Error(`No maintainer.js in "${dirPath}".`);
|
||||
if (fs.existsSync(path.join(dirPath, 'router.ts')) && !fs.existsSync(path.join(dirPath, 'maintainer.ts'))) {
|
||||
throw new Error(`No maintainer.ts in "${dirPath}".`);
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历整个 routes 文件夹,收集模块 maintainer.js
|
||||
const maintainerPath = require('require-all')({
|
||||
dirname,
|
||||
filter: /maintainer\.js$/,
|
||||
// 遍历整个 routes 文件夹,收集模块 maintainer.ts
|
||||
// const maintainerPath = require('require-all')({
|
||||
// dirname,
|
||||
// filter: /maintainer\.ts$/,
|
||||
// });
|
||||
const imports = directoryImport({
|
||||
targetDirectoryPath: dirname,
|
||||
importPattern: /maintainer\.ts$/,
|
||||
});
|
||||
|
||||
const maintainers = {};
|
||||
|
||||
// 将收集到的自定义模块进行合并
|
||||
for (const dir in maintainerPath) {
|
||||
const routes = maintainerPath[dir]['maintainer.js']; // Do not merge other file
|
||||
for (const dir in imports) {
|
||||
const routes = imports[dir].default; // Do not merge other file
|
||||
|
||||
// typo check e.g., ✘ module.export, ✔ module.exports
|
||||
if (!Object.keys(routes).length) {
|
||||
@@ -38,7 +44,7 @@ for (const dir in maintainerPath) {
|
||||
}
|
||||
|
||||
for (const key in routes) {
|
||||
maintainers['/' + dir + (key.endsWith('/') ? key.substring(0, key.length - 1) : key)] = routes[key];
|
||||
maintainers[dir.replace('/maintainer.ts', '') + (key.endsWith('/') ? key.substring(0, key.length - 1) : key)] = routes[key];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user