feat: 新增 checkUpdateUrl 字段

This commit is contained in:
lisonge 2023-11-14 22:07:11 +08:00
parent bf3f98531d
commit 60d04f0cb2
8 changed files with 364 additions and 389 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "@gkd-kit/subscription", "name": "@gkd-kit/subscription",
"type": "module", "type": "module",
"version": "1.161.0", "version": "1.162.0",
"main": "./dist/gkd.json", "main": "./dist/gkd.json",
"unpkg": "./dist/gkd.json", "unpkg": "./dist/gkd.json",
"jsdelivr": "./dist/gkd.json", "jsdelivr": "./dist/gkd.json",
@ -21,27 +21,26 @@
"updateSubs": "tsx ./scripts/updateSubs.ts" "updateSubs": "tsx ./scripts/updateSubs.ts"
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^17.7.1", "@commitlint/cli": "^17.8.1",
"@commitlint/config-conventional": "^17.7.0", "@commitlint/config-conventional": "^17.8.1",
"@commitlint/types": "^17.4.4", "@commitlint/types": "^17.8.1",
"@gkd-kit/selector": "0.0.14", "@gkd-kit/selector": "0.0.14",
"@types/lodash": "^4.14.195", "@types/lodash": "^4.14.201",
"@types/node": "^20.4.2", "@types/node": "^20.9.0",
"@typescript-eslint/eslint-plugin": "6.5.0", "@typescript-eslint/eslint-plugin": "6.11.0",
"@typescript-eslint/parser": "6.5.0", "@typescript-eslint/parser": "6.11.0",
"dayjs": "^1.11.9", "dayjs": "^1.11.10",
"eslint": "^8.48.0", "eslint": "^8.53.0",
"eslint-config-prettier": "9.0.0", "eslint-config-prettier": "9.0.0",
"eslint-define-config": "1.23.0", "eslint-define-config": "1.24.1",
"husky": "^8.0.3", "husky": "^8.0.3",
"lint-staged": "^14.0.1", "lint-staged": "^15.1.0",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"picocolors": "^1.0.0", "picocolors": "^1.0.0",
"pinyin-pro": "3.16.6", "pinyin-pro": "3.18.1",
"prettier": "^3.0.1", "prettier": "^3.1.0",
"tsx": "^3.12.7", "tsx": "^3.14.0",
"typescript": "^5.1.6", "typescript": "^5.2.2"
"undici": "^5.23.0"
}, },
"author": "lisonge", "author": "lisonge",
"license": "MIT", "license": "MIT",
@ -54,9 +53,9 @@
"url": "git+https://github.com/gkd-kit/subscription.git" "url": "git+https://github.com/gkd-kit/subscription.git"
}, },
"volta": { "volta": {
"node": "20.5.0" "node": "20.9.0"
}, },
"packageManager": "pnpm@8.7.1", "packageManager": "pnpm@8.10.2",
"commitlint": { "commitlint": {
"extends": [ "extends": [
"@commitlint/config-conventional" "@commitlint/config-conventional"

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
import subsConfig from '../src/config'; import subsConfig from '../src/config';
import { writeConfig } from '../src/file'; import { writeConfig } from '../src/file';
await writeConfig(process.cwd() + '/dist/gkd.json', subsConfig); await writeConfig(subsConfig);

View File

@ -27,6 +27,8 @@ const subsConfig: SubscriptionConfig = {
name: '默认订阅', name: '默认订阅',
author: 'lisonge', author: 'lisonge',
supportUri: 'https://github.com/gkd-kit/subscription', supportUri: 'https://github.com/gkd-kit/subscription',
checkUpdateUrl:
'https://registry.npmmirror.com/@gkd-kit/subscription/latest/files/dist/gkd.version.json',
apps: _.sortBy(apps, (a) => { apps: _.sortBy(apps, (a) => {
const pyName = pinyin(a.name, { separator: '', toneType: 'none' }); const pyName = pinyin(a.name, { separator: '', toneType: 'none' });
if (pyName === a.name) return a.name; if (pyName === a.name) return a.name;

View File

@ -16,6 +16,7 @@ const sortKeys: (keyof SubscriptionConfig)[] = [
'author', 'author',
'supportUri', 'supportUri',
'updateUrl', 'updateUrl',
'checkUpdateUrl',
'apps', 'apps',
]; ];
@ -39,9 +40,11 @@ const pkg: typeof PkgT = JSON.parse(
); );
const pkgKeys = Object.keys(pkg); const pkgKeys = Object.keys(pkg);
export const writeConfig = async (fp: string, config: SubscriptionConfig) => { export const writeConfig = async (config: SubscriptionConfig) => {
const gkdFp = process.cwd() + '/dist/gkd.json';
const versionFp = process.cwd() + '/dist/gkd.version.json';
const oldConfig: SubscriptionConfig = JSON.parse( const oldConfig: SubscriptionConfig = JSON.parse(
await fs.readFile(fp, 'utf-8').catch(() => '{}'), await fs.readFile(gkdFp, 'utf-8').catch(() => '{}'),
); );
const newConfig: SubscriptionConfig = { const newConfig: SubscriptionConfig = {
@ -72,7 +75,17 @@ export const writeConfig = async (fp: string, config: SubscriptionConfig) => {
// update gkd.json // update gkd.json
const buffer = Buffer.from(orderdStringify(newConfig, sortKeys), 'utf-8'); const buffer = Buffer.from(orderdStringify(newConfig, sortKeys), 'utf-8');
await fs.writeFile(fp, buffer); await fs.writeFile(gkdFp, buffer);
// update gkd.version.json
await fs.writeFile(
versionFp,
JSON.stringify(
{ id: newConfig.id, version: newConfig.version },
undefined,
2,
),
);
console.log( console.log(
`更新订阅: v${newConfig.version}, 文件大小: ${ `更新订阅: v${newConfig.version}, 文件大小: ${

View File

@ -284,9 +284,18 @@ export type SubscriptionConfig = {
/** /**
* APP , version APP version , * APP , version APP version ,
*
* , 使
*/ */
updateUrl?: string; updateUrl?: string;
/**
* id version json , , , id version , updateUrl
*
*
*/
checkUpdateUrl?: string;
/** /**
* https url, custom android schema url * https url, custom android schema url
*/ */

View File

@ -11,7 +11,8 @@
"esModuleInterop": true, "esModuleInterop": true,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"strict": true, "strict": true,
"skipLibCheck": true "skipLibCheck": true,
"isolatedModules": true
}, },
"include": ["./src/**/*.ts", "./scripts/**/*.ts", "./types/**/*.ts"] "include": ["./src/**/*.ts", "./scripts/**/*.ts", "./types/**/*.ts"]
} }

27
types/global.d.ts vendored
View File

@ -1,27 +0,0 @@
import {
type FormData as FormDataType,
type Headers as HeadersType,
type Request as RequestType,
type Response as ResponseType,
} from 'undici';
declare global {
// Re-export undici fetch function and various classes to global scope.
// These are classes and functions expected to be at global scope according to Node.js v18 API
// documentation.
// See: https://nodejs.org/dist/latest-v18.x/docs/api/globals.html
export const {
FormData,
Headers,
Request,
Response,
fetch,
}: typeof import('undici');
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/60924
type FormData = FormDataType;
type Headers = HeadersType;
type Request = RequestType;
type Response = ResponseType;
}