feat: remove lib/radar-rules.js

This commit is contained in:
DIYgod
2024-02-21 20:32:09 +08:00
parent ad7292230b
commit bdb078c27d
11 changed files with 58 additions and 11 deletions

View File

@@ -43,5 +43,4 @@ vercel.json
.git/hooks .git/hooks
# rsshub auxiliary files # rsshub auxiliary files
lib/radar-rules.js
lib/v2/**/radar.js lib/v2/**/radar.js

2
.github/labeler.yml vendored
View File

@@ -10,7 +10,7 @@
core enhancement: core enhancement:
- changed-files: - changed-files:
- any-glob-to-any-file: ['lib/routes/index.js'] - any-glob-to-any-file: ['lib/routes/index.js']
- all-globs-to-any-file: ['lib/**', '!lib/radar-rules.js', '!/lib/config.js', '!lib/router.js', '!lib/routes/**', '!lib/v2/**'] - all-globs-to-any-file: ['lib/**', '!/lib/config.js', '!lib/router.js', '!lib/routes/**', '!lib/v2/**']
dependencies: dependencies:
- changed-files: - changed-files:

View File

@@ -6,7 +6,6 @@ on:
- master - master
paths: paths:
- 'assets/radar-rules.js' - 'assets/radar-rules.js'
- 'lib/**/radar-rules.js'
permissions: permissions:
contents: read contents: read

View File

@@ -7,7 +7,6 @@ on:
paths: paths:
- '.github/workflows/docker-release.yml' - '.github/workflows/docker-release.yml'
- 'lib/**' - 'lib/**'
- '!**/radar-rules.js'
- '!lib/v2/test/**' - '!lib/v2/test/**'
- '!test/**' - '!test/**'
- 'Dockerfile' - 'Dockerfile'

View File

@@ -7,7 +7,6 @@ on:
paths: paths:
- '.github/workflows/docker-test.yml' - '.github/workflows/docker-test.yml'
- 'lib/**' - 'lib/**'
- '!**/radar-rules.js'
- 'Dockerfile' - 'Dockerfile'
- 'package.json' - 'package.json'
- 'pnpm-lock.yaml' - 'pnpm-lock.yaml'

View File

@@ -7,7 +7,6 @@ on:
paths: paths:
- '.github/workflows/npm-publish.yml' - '.github/workflows/npm-publish.yml'
- 'lib/**' - 'lib/**'
- '!**/radar-rules.js'
permissions: permissions:
contents: read contents: read

View File

@@ -7,7 +7,6 @@ on:
paths: paths:
- 'test/**' - 'test/**'
- 'lib/**' - 'lib/**'
- '!**/radar-rules.js'
- 'package.json' - 'package.json'
- 'pnpm-lock.yaml' - 'pnpm-lock.yaml'
- '.github/workflows/test.yml' - '.github/workflows/test.yml'

View File

@@ -54,8 +54,7 @@
"lib/**/*.js", "lib/**/*.js",
"!lib/routes/**/*.js", "!lib/routes/**/*.js",
"!lib/v2/**/*.js", "!lib/v2/**/*.js",
"!lib/router.js", "!lib/router.js"
"!lib/radar-rules.js"
], ],
"coverageReporters": [ "coverageReporters": [
"text-summary", "text-summary",

View File

@@ -1,7 +1,61 @@
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const target = path.join(__dirname, '../../assets/build/maintainer.json'); const target = path.join(__dirname, '../../assets/build/maintainer.json');
const maintainer = require(path.join(__dirname, '../../lib/maintainer.js')); const dirname = path.join(__dirname + '../../../lib/v2');
// 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}".`);
}
}
// 遍历整个 routes 文件夹,收集模块 maintainer.js
const maintainerPath = require('require-all')({
dirname,
filter: /maintainer\.js$/,
});
const maintainers = {};
// 将收集到的自定义模块进行合并
for (const dir in maintainerPath) {
const routes = maintainerPath[dir]['maintainer.js']; // Do not merge other file
// typo check e.g., ✘ module.export, ✔ module.exports
if (!Object.keys(routes).length) {
throw new Error(`No maintainer in "${dir}".`);
}
for (const author of Object.values(routes)) {
if (!Array.isArray(author)) {
throw new TypeError(`Maintainers' name should be an array in "${dir}".`);
}
// check for [], [''] or ['Someone', '']
if (author.length < 1 || author.includes('')) {
throw new Error(`Empty maintainer in "${dir}".`);
}
}
for (const key in routes) {
maintainers['/' + dir + (key.endsWith('/') ? key.substring(0, key.length - 1) : key)] = routes[key];
}
}
// 兼容旧版路由
const router = require('../../lib/router.js');
for (const e of router.stack) {
if (!maintainers[e.path]) {
maintainers[e.path] = [];
}
}
const maintainer = Object.keys(maintainers)
.sort()
.reduce((obj, path) => {
obj[path] = maintainers[path];
return obj;
}, {});
const count = Object.keys(maintainer).length; const count = Object.keys(maintainer).length;
const uniqueMaintainer = new Set(); const uniqueMaintainer = new Set();

View File

@@ -2,7 +2,7 @@ const fs = require('fs');
const path = require('path'); const path = require('path');
const targetJs = path.join(__dirname, '../../assets/build/radar-rules.js'); const targetJs = path.join(__dirname, '../../assets/build/radar-rules.js');
const targetJson = path.join(__dirname, '../../assets/build/radar-rules.json'); const targetJson = path.join(__dirname, '../../assets/build/radar-rules.json');
const dirname = __dirname + '/v2'; const dirname = path.join(__dirname + '../../../lib/v2');
const toSource = require('tosource'); const toSource = require('tosource');
// Namespaces that do not require radar.js // Namespaces that do not require radar.js