mirror of
https://gitea.redwind.top/Austin/subscription
synced 2024-11-16 02:42:22 +08:00
feat: 新增 checkUpdateUrl 字段
This commit is contained in:
parent
bf3f98531d
commit
60d04f0cb2
37
package.json
37
package.json
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@gkd-kit/subscription",
|
||||
"type": "module",
|
||||
"version": "1.161.0",
|
||||
"version": "1.162.0",
|
||||
"main": "./dist/gkd.json",
|
||||
"unpkg": "./dist/gkd.json",
|
||||
"jsdelivr": "./dist/gkd.json",
|
||||
|
@ -21,27 +21,26 @@
|
|||
"updateSubs": "tsx ./scripts/updateSubs.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^17.7.1",
|
||||
"@commitlint/config-conventional": "^17.7.0",
|
||||
"@commitlint/types": "^17.4.4",
|
||||
"@commitlint/cli": "^17.8.1",
|
||||
"@commitlint/config-conventional": "^17.8.1",
|
||||
"@commitlint/types": "^17.8.1",
|
||||
"@gkd-kit/selector": "0.0.14",
|
||||
"@types/lodash": "^4.14.195",
|
||||
"@types/node": "^20.4.2",
|
||||
"@typescript-eslint/eslint-plugin": "6.5.0",
|
||||
"@typescript-eslint/parser": "6.5.0",
|
||||
"dayjs": "^1.11.9",
|
||||
"eslint": "^8.48.0",
|
||||
"@types/lodash": "^4.14.201",
|
||||
"@types/node": "^20.9.0",
|
||||
"@typescript-eslint/eslint-plugin": "6.11.0",
|
||||
"@typescript-eslint/parser": "6.11.0",
|
||||
"dayjs": "^1.11.10",
|
||||
"eslint": "^8.53.0",
|
||||
"eslint-config-prettier": "9.0.0",
|
||||
"eslint-define-config": "1.23.0",
|
||||
"eslint-define-config": "1.24.1",
|
||||
"husky": "^8.0.3",
|
||||
"lint-staged": "^14.0.1",
|
||||
"lint-staged": "^15.1.0",
|
||||
"lodash": "^4.17.21",
|
||||
"picocolors": "^1.0.0",
|
||||
"pinyin-pro": "3.16.6",
|
||||
"prettier": "^3.0.1",
|
||||
"tsx": "^3.12.7",
|
||||
"typescript": "^5.1.6",
|
||||
"undici": "^5.23.0"
|
||||
"pinyin-pro": "3.18.1",
|
||||
"prettier": "^3.1.0",
|
||||
"tsx": "^3.14.0",
|
||||
"typescript": "^5.2.2"
|
||||
},
|
||||
"author": "lisonge",
|
||||
"license": "MIT",
|
||||
|
@ -54,9 +53,9 @@
|
|||
"url": "git+https://github.com/gkd-kit/subscription.git"
|
||||
},
|
||||
"volta": {
|
||||
"node": "20.5.0"
|
||||
"node": "20.9.0"
|
||||
},
|
||||
"packageManager": "pnpm@8.7.1",
|
||||
"packageManager": "pnpm@8.10.2",
|
||||
"commitlint": {
|
||||
"extends": [
|
||||
"@commitlint/config-conventional"
|
||||
|
|
654
pnpm-lock.yaml
654
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
|||
import subsConfig from '../src/config';
|
||||
import { writeConfig } from '../src/file';
|
||||
|
||||
await writeConfig(process.cwd() + '/dist/gkd.json', subsConfig);
|
||||
await writeConfig(subsConfig);
|
||||
|
|
|
@ -27,6 +27,8 @@ const subsConfig: SubscriptionConfig = {
|
|||
name: '默认订阅',
|
||||
author: 'lisonge',
|
||||
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) => {
|
||||
const pyName = pinyin(a.name, { separator: '', toneType: 'none' });
|
||||
if (pyName === a.name) return a.name;
|
||||
|
|
19
src/file.ts
19
src/file.ts
|
@ -16,6 +16,7 @@ const sortKeys: (keyof SubscriptionConfig)[] = [
|
|||
'author',
|
||||
'supportUri',
|
||||
'updateUrl',
|
||||
'checkUpdateUrl',
|
||||
'apps',
|
||||
];
|
||||
|
||||
|
@ -39,9 +40,11 @@ const pkg: typeof PkgT = JSON.parse(
|
|||
);
|
||||
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(
|
||||
await fs.readFile(fp, 'utf-8').catch(() => '{}'),
|
||||
await fs.readFile(gkdFp, 'utf-8').catch(() => '{}'),
|
||||
);
|
||||
|
||||
const newConfig: SubscriptionConfig = {
|
||||
|
@ -72,7 +75,17 @@ export const writeConfig = async (fp: string, config: SubscriptionConfig) => {
|
|||
|
||||
// update gkd.json
|
||||
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(
|
||||
`更新订阅: v${newConfig.version}, 文件大小: ${
|
||||
|
|
|
@ -284,9 +284,18 @@ export type SubscriptionConfig = {
|
|||
|
||||
/**
|
||||
* APP 会定时或者用户手动请求这个链接, 如果返回的订阅的 version 大于 APP 订阅当前的 version , 则更新
|
||||
*
|
||||
* 如果这个字段不存在, 则使用添加订阅时填写的链接
|
||||
*/
|
||||
updateUrl?: string;
|
||||
|
||||
/**
|
||||
* 一个只需要 id 和 version 的 json 文件链接, 检测更新时, 优先检测此链接, 如果 id 相等并且 version 增加, 则再去请求 updateUrl
|
||||
*
|
||||
* 目的是防止订阅文件过大而消耗过多的流量
|
||||
*/
|
||||
checkUpdateUrl?: string;
|
||||
|
||||
/**
|
||||
* https url, custom android schema url
|
||||
*/
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true
|
||||
"skipLibCheck": true,
|
||||
"isolatedModules": true
|
||||
},
|
||||
"include": ["./src/**/*.ts", "./scripts/**/*.ts", "./types/**/*.ts"]
|
||||
}
|
||||
|
|
27
types/global.d.ts
vendored
27
types/global.d.ts
vendored
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user