diff --git a/.dockerignore b/.dockerignore index 607ef1d3c..8f99edcc7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -43,5 +43,4 @@ vercel.json .git/hooks # rsshub auxiliary files -lib/radar-rules.js lib/v2/**/radar.js diff --git a/.github/labeler.yml b/.github/labeler.yml index 5c6fa9d19..a8b075766 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -10,7 +10,7 @@ core enhancement: - changed-files: - 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: - changed-files: diff --git a/.github/workflows/build-assets.yml b/.github/workflows/build-assets.yml index 68bd8233a..4cb13871f 100644 --- a/.github/workflows/build-assets.yml +++ b/.github/workflows/build-assets.yml @@ -6,7 +6,6 @@ on: - master paths: - 'assets/radar-rules.js' - - 'lib/**/radar-rules.js' permissions: contents: read diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 06ced2669..9fee83e5b 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -7,7 +7,6 @@ on: paths: - '.github/workflows/docker-release.yml' - 'lib/**' - - '!**/radar-rules.js' - '!lib/v2/test/**' - '!test/**' - 'Dockerfile' diff --git a/.github/workflows/docker-test.yml b/.github/workflows/docker-test.yml index b7ebd174e..99ac46992 100644 --- a/.github/workflows/docker-test.yml +++ b/.github/workflows/docker-test.yml @@ -7,7 +7,6 @@ on: paths: - '.github/workflows/docker-test.yml' - 'lib/**' - - '!**/radar-rules.js' - 'Dockerfile' - 'package.json' - 'pnpm-lock.yaml' diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index e0a9bb89b..d37f85eb5 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -7,7 +7,6 @@ on: paths: - '.github/workflows/npm-publish.yml' - 'lib/**' - - '!**/radar-rules.js' permissions: contents: read diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 51ba1a1fe..12822cf62 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,6 @@ on: paths: - 'test/**' - 'lib/**' - - '!**/radar-rules.js' - 'package.json' - 'pnpm-lock.yaml' - '.github/workflows/test.yml' diff --git a/package.json b/package.json index 22f70ee5b..c2a1be014 100644 --- a/package.json +++ b/package.json @@ -54,8 +54,7 @@ "lib/**/*.js", "!lib/routes/**/*.js", "!lib/v2/**/*.js", - "!lib/router.js", - "!lib/radar-rules.js" + "!lib/router.js" ], "coverageReporters": [ "text-summary", diff --git a/scripts/workflow/build-maintainer.js b/scripts/workflow/build-maintainer.js index f3f38b716..3fc93becd 100644 --- a/scripts/workflow/build-maintainer.js +++ b/scripts/workflow/build-maintainer.js @@ -1,7 +1,61 @@ const fs = require('fs'); const path = require('path'); 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 uniqueMaintainer = new Set(); diff --git a/scripts/workflow/build-radar.js b/scripts/workflow/build-radar.js index 66deadad0..246ee36bc 100644 --- a/scripts/workflow/build-radar.js +++ b/scripts/workflow/build-radar.js @@ -2,7 +2,7 @@ const fs = require('fs'); const path = require('path'); const targetJs = path.join(__dirname, '../../assets/build/radar-rules.js'); 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'); // Namespaces that do not require radar.js diff --git a/lib/radar-rules.js b/scripts/workflow/radar-rules.js similarity index 100% rename from lib/radar-rules.js rename to scripts/workflow/radar-rules.js