chore: interface

This commit is contained in:
AIsouler
2024-03-09 21:03:54 +08:00
parent 23d2d5844c
commit c2deaa03e9
6 changed files with 15 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
import type { RawCategory } from '@gkd-kit/api'; import { RawCategory } from '@gkd-kit/api';
const categories: RawCategory[] = [ const categories: RawCategory[] = [
{ {

View File

@@ -1,7 +1,7 @@
import categories from './categories'; import categories from './categories';
import globalGroups from './globalGroups'; import globalGroups from './globalGroups';
import apps from './rawApps'; import apps from './rawApps';
import type { RawSubscription } from '@gkd-kit/api'; import { RawSubscription } from '@gkd-kit/api';
const subsConfig: RawSubscription = { const subsConfig: RawSubscription = {
id: 666, id: 666,

View File

@@ -3,8 +3,8 @@ import fs from 'node:fs/promises';
import path from 'node:path'; import path from 'node:path';
import type PkgT from '../package.json'; import type PkgT from '../package.json';
import { parseSelector } from './selector'; import { parseSelector } from './selector';
import type { RawAppAddProp } from './types'; import { RawApp } from './types';
import type { import {
RawAppGroup, RawAppGroup,
RawGlobalGroup, RawGlobalGroup,
IArray, IArray,
@@ -206,7 +206,7 @@ export const checkConfig = (newConfig: RawSubscription) => {
// 检查组和规则的重复键 // 检查组和规则的重复键
const apps = newConfig.apps || []; const apps = newConfig.apps || [];
apps.forEach((app: RawAppAddProp) => { apps.forEach((app: RawApp) => {
const deprecatedKeys = app.deprecatedKeys || []; const deprecatedKeys = app.deprecatedKeys || [];
const keys = new Set<number>(); const keys = new Set<number>();
const oldGroups = oldConfig.apps?.find((a) => a.id == app.id)?.groups || []; const oldGroups = oldConfig.apps?.find((a) => a.id == app.id)?.groups || [];
@@ -377,7 +377,7 @@ export const checkAndDeleteFiles = async (): Promise<void> => {
}; };
// 导出一个异步函数,用于更新应用的 Markdown 文件 // 导出一个异步函数,用于更新应用的 Markdown 文件
export const updateAppMd = async (app: RawAppAddProp) => { export const updateAppMd = async (app: RawApp) => {
// 生成应用的 Markdown 文本内容 // 生成应用的 Markdown 文本内容
const appHeadMdText = [ const appHeadMdText = [
`# ${app.name}`, `# ${app.name}`,
@@ -509,7 +509,7 @@ const getGlobalDiffLog = (
// 定义一个类型,表示应用的变更日志 // 定义一个类型,表示应用的变更日志
type AppDiff = { type AppDiff = {
app: RawAppAddProp; app: RawApp;
addGroups: RawAppGroup[]; addGroups: RawAppGroup[];
changeGroups: RawAppGroup[]; changeGroups: RawAppGroup[];
removeGroups: RawAppGroup[]; removeGroups: RawAppGroup[];

View File

@@ -1,5 +1,5 @@
import apps from './rawApps'; import apps from './rawApps';
import type { RawGlobalGroup } from '@gkd-kit/api'; import { RawGlobalGroup } from '@gkd-kit/api';
import * as utils from './utils'; import * as utils from './utils';
// 全局禁用 // 全局禁用

View File

@@ -4,17 +4,15 @@ import url from 'node:url';
import picocolors from 'picocolors'; import picocolors from 'picocolors';
import { pinyin } from 'pinyin-pro'; import { pinyin } from 'pinyin-pro';
import { walk } from './file'; import { walk } from './file';
import type { RawAppAddProp } from './types'; import { RawApp } from './types';
import { OPEN_AD_ORDER } from './utils'; import { OPEN_AD_ORDER } from './utils';
const rawApps: RawAppAddProp[] = []; const rawApps: RawApp[] = [];
for await (const tsFp of walk(process.cwd() + '/src/apps')) { for await (const tsFp of walk(process.cwd() + '/src/apps')) {
if (!tsFp.endsWith('.ts')) { if (!tsFp.endsWith('.ts')) {
throw new Error('invalid typescript app config file: ' + tsFp); throw new Error('invalid typescript app config file: ' + tsFp);
} }
const mod: { default: RawAppAddProp } = await import( const mod: { default: RawApp } = await import(url.pathToFileURL(tsFp).href);
url.pathToFileURL(tsFp).href
);
const appConfig = mod.default; const appConfig = mod.default;
if (path.basename(tsFp, '.ts') != appConfig.id) { if (path.basename(tsFp, '.ts') != appConfig.id) {
throw new Error( throw new Error(

View File

@@ -1,16 +1,12 @@
import * as api from '@gkd-kit/api'; import * as api from '@gkd-kit/api';
export type RawAppAddProp = api.RawApp & { export interface RawApp extends api.RawApp {
/** /**
* 某些规则组被移除不使用时, 为了避免 key 在后续被复用, 需要将已经删除的规则组的 key 填入此数组做校验使用 * 某些规则组被移除不使用时, 为了避免 key 在后续被复用, 需要将已经删除的规则组的 key 填入此数组做校验使用
*/ */
deprecatedKeys?: number[]; deprecatedKeys?: api.Integer[];
}; }
export const defineSubsConfig = (config: api.RawSubscription) => { export const defineAppConfig = (config: RawApp) => {
return JSON.stringify(config, undefined, 2);
};
export const defineAppConfig = (config: RawAppAddProp) => {
return config; return config;
}; };