fix: add check

This commit is contained in:
lisonge
2024-01-03 01:41:48 +08:00
parent 483d097cd5
commit 2b6237afab
2 changed files with 44 additions and 20 deletions

View File

@@ -2,7 +2,7 @@
GKD 默认订阅规则, 默认规则仅启用 `开屏广告` 一类规则, 其它所有规则均需用户手动打开 GKD 默认订阅规则, 默认规则仅启用 `开屏广告` 一类规则, 其它所有规则均需用户手动打开
当前订阅为 APP 自带, 无需手动添加, 当前版本: v179 当前订阅为 APP 自带, 无需手动添加, 当前版本: v180
当前订阅文件已适配 568 个 APP, 共有 1267 规则组 当前订阅文件已适配 568 个 APP, 共有 1267 规则组
@@ -12,4 +12,4 @@ GKD 默认订阅规则, 默认规则仅启用 `开屏广告` 一类规则, 其
## 感谢以下开发者的贡献 ## 感谢以下开发者的贡献
![img](https://contrib.rocks/image?repo=gkd-kit/subscription&_v=179) ![img](https://contrib.rocks/image?repo=gkd-kit/subscription&_v=180)

View File

@@ -135,8 +135,32 @@ export const validSnapshotUrl = (s: string) => {
}; };
export const checkConfig = (newConfig: RawSubscription) => { export const checkConfig = (newConfig: RawSubscription) => {
const categories = newConfig.categories || [];
categories.forEach((c) => {
if (
categories.some(
(c2) => (c2.key == c.key || c2.name == c.name) && c2 !== c,
)
) {
console.error({
configName: newConfig.name,
categoryName: c.name,
categoryKey: c.key,
});
throw new Error('invalid duplicated category');
}
});
const globalGroups = newConfig.globalGroups || []; const globalGroups = newConfig.globalGroups || [];
globalGroups.forEach((g) => { globalGroups.forEach((g) => {
if (globalGroups.some((g2) => g2.key == g.key && g2 !== g)) {
console.error({
configName: newConfig.name,
groupName: g.name,
groupKey: g.key,
});
throw new Error('invalid deprecated global group key');
}
// check rules selector syntax // check rules selector syntax
g.rules.forEach((r) => { g.rules.forEach((r) => {
[r.matches, r.excludeMatches] [r.matches, r.excludeMatches]
@@ -430,9 +454,7 @@ export const updateReadMeMd = async (
await fs.writeFile(process.cwd() + '/CHANGELOG.md', changeLogText); await fs.writeFile(process.cwd() + '/CHANGELOG.md', changeLogText);
} }
if (changeCount <= 0) return; if (changeCount > 0) {
console.log('更新文档: ' + changeCount);
const appListText = const appListText =
'| 名称 | ID | 规则组 |\n| - | - | - |\n' + '| 名称 | ID | 规则组 |\n| - | - | - |\n' +
newConfig newConfig
@@ -441,6 +463,16 @@ export const updateReadMeMd = async (
return `| ${app.name} | [${app.id}](/docs/${app.id}.md) | ${groups.length} |`; return `| ${app.name} | [${app.id}](/docs/${app.id}.md) | ${groups.length} |`;
}) })
.join('\n'); .join('\n');
const appListTemplateMd = await fs.readFile(
process.cwd() + '/AppListTemplate.md',
'utf-8',
);
await fs.writeFile(
process.cwd() + '/AppList.md',
appListTemplateMd.replaceAll('--APP_LIST--', appListText),
);
}
const mdTemplate = await fs.readFile(process.cwd() + '/Template.md', 'utf-8'); const mdTemplate = await fs.readFile(process.cwd() + '/Template.md', 'utf-8');
const readMeMdText = mdTemplate const readMeMdText = mdTemplate
.replaceAll('--APP_SIZE--', newConfig.apps!.length.toString()) .replaceAll('--APP_SIZE--', newConfig.apps!.length.toString())
@@ -452,12 +484,4 @@ export const updateReadMeMd = async (
) )
.replaceAll('--VERSION--', (newConfig.version || 0).toString()); .replaceAll('--VERSION--', (newConfig.version || 0).toString());
await fs.writeFile(process.cwd() + '/README.md', readMeMdText); await fs.writeFile(process.cwd() + '/README.md', readMeMdText);
const appListTemplateMd = await fs.readFile(
process.cwd() + '/AppListTemplate.md',
'utf-8',
);
await fs.writeFile(
process.cwd() + '/AppList.md',
appListTemplateMd.replaceAll('--APP_LIST--', appListText),
);
}; };