feat: 全局规则自动禁用

This commit is contained in:
lisonge
2023-12-25 17:39:27 +08:00
parent 795102ad68
commit 2985909726
4 changed files with 88 additions and 64 deletions

39
src/rawApps.ts Normal file
View File

@@ -0,0 +1,39 @@
import _ from 'lodash';
import path from 'node:path';
import url from 'node:url';
import picocolors from 'picocolors';
import { pinyin } from 'pinyin-pro';
import { walk } from './file';
import type { RawApp } from './types';
const rawApps: RawApp[] = [];
for await (const tsFp of walk(process.cwd() + '/src/apps')) {
const mod: { default: RawApp } = await import(url.pathToFileURL(tsFp).href);
const appConfig = mod.default;
if (path.basename(tsFp, '.ts') != appConfig.id) {
throw new Error(
`${picocolors.blue(
tsFp,
)} file basename is not equal to its app id ${picocolors.blue(
appConfig.id,
)} `,
);
}
appConfig.groups?.forEach((g) => {
if (!g.name.startsWith('开屏广告')) {
g.enable = false;
}
});
rawApps.push(appConfig);
}
const apps = _.sortBy(rawApps, (a) => {
const showName = a.name || a.id;
const pyName = pinyin(showName, {
separator: '',
toneType: 'none',
});
if (pyName === showName) return showName;
return '\uFFFF' + pyName; // 让带拼音的全排在后面
});
export default apps;