add yargs

This commit is contained in:
liuyi 2025-06-16 23:12:40 +08:00
parent d8c1adf08b
commit b30f9bf7d1
4 changed files with 210 additions and 2 deletions

View File

@ -27,6 +27,7 @@
"@nestjs/platform-fastify": "^11.1.3",
"@nestjs/swagger": "^11.2.0",
"@nestjs/typeorm": "^11.0.0",
"bun": "^1.2.16",
"chalk": "^5.4.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.2",
@ -43,7 +44,8 @@
"sanitize-html": "^2.17.0",
"typeorm": "^0.3.24",
"validator": "^13.15.15",
"yaml": "^2.8.0"
"yaml": "^2.8.0",
"yargs": "^18.0.0"
},
"devDependencies": {
"@babel/core": "^7.27.4",
@ -69,9 +71,11 @@
"@types/sanitize-html": "^2.16.0",
"@types/supertest": "^6.0.3",
"@types/validator": "^13.15.1",
"@types/yargs": "^17.0.33",
"@typescript-eslint/eslint-plugin": "^8.34.0",
"@typescript-eslint/parser": "^8.34.0",
"babel-jest": "^30.0.0",
"bun-types": "^1.2.16",
"cross-env": "^7.0.3",
"eslint": "^9.29.0",
"eslint-config-airbnb-base": "^15.0.0",

View File

@ -26,6 +26,9 @@ importers:
'@nestjs/typeorm':
specifier: ^11.0.0
version: 11.0.0(@nestjs/common@11.1.3(class-transformer@0.5.1)(class-validator@0.14.2)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.3(@nestjs/common@11.1.3(class-transformer@0.5.1)(class-validator@0.14.2)(reflect-metadata@0.2.2)(rxjs@7.8.2))(reflect-metadata@0.2.2)(rxjs@7.8.2))(reflect-metadata@0.2.2)(rxjs@7.8.2)(typeorm@0.3.24(mysql2@3.14.1)(reflect-metadata@0.2.2)(ts-node@10.9.2(@swc/core@1.12.1)(@types/node@24.0.1)(typescript@5.8.3)))
bun:
specifier: ^1.2.16
version: 1.2.16
chalk:
specifier: ^5.4.1
version: 5.4.1
@ -77,6 +80,9 @@ importers:
yaml:
specifier: ^2.8.0
version: 2.8.0
yargs:
specifier: ^18.0.0
version: 18.0.0
devDependencies:
'@babel/core':
specifier: ^7.27.4
@ -147,6 +153,9 @@ importers:
'@types/validator':
specifier: ^13.15.1
version: 13.15.1
'@types/yargs':
specifier: ^17.0.33
version: 17.0.33
'@typescript-eslint/eslint-plugin':
specifier: ^8.34.0
version: 8.34.0(@typescript-eslint/parser@8.34.0(eslint@9.29.0)(typescript@5.8.3))(eslint@9.29.0)(typescript@5.8.3)
@ -156,6 +165,9 @@ importers:
babel-jest:
specifier: ^30.0.0
version: 30.0.0(@babel/core@7.27.4)
bun-types:
specifier: ^1.2.16
version: 1.2.16
cross-env:
specifier: ^7.0.3
version: 7.0.3
@ -1502,6 +1514,61 @@ packages:
engines: {node: ^14.18.0 || >=16.10.0, npm: '>=5.10.0'}
hasBin: true
'@oven/bun-darwin-aarch64@1.2.16':
resolution: {integrity: sha512-NLVU9YDORq/3WuJOE5TQv5of3R99n56gYZPfdqP4U0/5nllbC8yzRxA2BWwAS2RxxD0Y3bxqEVUsIGiTNN2jxg==}
cpu: [arm64]
os: [darwin]
'@oven/bun-darwin-x64-baseline@1.2.16':
resolution: {integrity: sha512-FtKr6FwLN+QfrF0/vJtOwBMU72krmrHlxhRSElbKEOWox2n2vWSZ/sNNkHePEsrxGfqaHC5GhEZk2lnaZTavBQ==}
cpu: [x64]
os: [darwin]
'@oven/bun-darwin-x64@1.2.16':
resolution: {integrity: sha512-HpcSVCTH9n+9bG2zu3OUJ9h22m6HzNgZpqib9r4NEVZg7Z2U86bOUMKlTCA0ZANaWsK9czl2VIhMWbLF4fgvLA==}
cpu: [x64]
os: [darwin]
'@oven/bun-linux-aarch64-musl@1.2.16':
resolution: {integrity: sha512-MhvQ0hecunZnbac9cEOqA1CGk/ISDhhnF35i9l90Jgc/osfgGndViLkMp3wk1EO5UG4/Kbil1OlfLmyOHKq0SQ==}
cpu: [aarch64]
os: [linux]
'@oven/bun-linux-aarch64@1.2.16':
resolution: {integrity: sha512-nd0eZhihfgrDtfI/NdEqOAQ8KY87SWNQLZKjRB8WoYkqcY1BGwtZqvJOc2bEn2oERJ8K2etJRynXz+MKngiYxw==}
cpu: [arm64]
os: [linux]
'@oven/bun-linux-x64-baseline@1.2.16':
resolution: {integrity: sha512-ZysDeqDfUAqKrQu2R+ddRgSCY30qSnn0LQLr6fAm7Pw9lU2yhWVNa8R3DavddmZQc1vUw6j3ITIAE+DDT9OBCg==}
cpu: [x64]
os: [linux]
'@oven/bun-linux-x64-musl-baseline@1.2.16':
resolution: {integrity: sha512-cWwny3cxYkvV9fYnSDb2brXodWV7IcG+Bwd3q3b8OUYbeC3ekHN3zm+TYdSxIVhMm7z46CkiDz5QnnQWVVfZ5A==}
cpu: [x64]
os: [linux]
'@oven/bun-linux-x64-musl@1.2.16':
resolution: {integrity: sha512-6o5Oi5ARKYErF6nIBrewxtl20PGhM97faPemJ+v26D47dRNAlUWN5lMVuOqZOhYjqzOe4V+NpxIFBHtXWEmoNQ==}
cpu: [x64]
os: [linux]
'@oven/bun-linux-x64@1.2.16':
resolution: {integrity: sha512-qYUXPXbT4S+MImv51+dLBHKFYy40QIowwCRtzUFGf3TG+9MQQUXHNXryMNSdHveHqecd9rO1EIQ8hroAPBl+Sg==}
cpu: [x64]
os: [linux]
'@oven/bun-windows-x64-baseline@1.2.16':
resolution: {integrity: sha512-tHdtHqH6c5ScNusLWOzZCTeuV2rSc3mvlLQQ+DYefTy+XwtjXmY47MbBSgNuBWVYePIob9BqDFOtTHYIWRZTww==}
cpu: [x64]
os: [win32]
'@oven/bun-windows-x64@1.2.16':
resolution: {integrity: sha512-1xUlHHbMZ3DMZlEcppBAQ5vQDgNHDMIGB/AXO+dxQJl/3GiO/Ek4pMDzcqMnlbGDaDcTmTXyZ6cEXEF4C2qygQ==}
cpu: [x64]
os: [win32]
'@paralleldrive/cuid2@2.2.2':
resolution: {integrity: sha512-ZOBkgDwEdoYVlSeRbYYXs0S9MejQofiVYoTbKzy/6GQa39/q5tQU2IX46+shYnUkpEl3wc+J6wRlar7r2EK2xA==}
@ -2238,6 +2305,14 @@ packages:
buffer@6.0.3:
resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==}
bun-types@1.2.16:
resolution: {integrity: sha512-ciXLrHV4PXax9vHvUrkvun9VPVGOVwbbbBF/Ev1cXz12lyEZMoJpIJABOfPcN9gDJRaiKF9MVbSygLg4NXu3/A==}
bun@1.2.16:
resolution: {integrity: sha512-sjZH6rr1P6yu44+XPA8r+ZojwmK9Kbz9lO6KAA/4HRIupdpC31k7b93crLBm19wEYmd6f2+3+57/7tbOcmHbGg==}
os: [darwin, linux, win32]
hasBin: true
cacheable-lookup@7.0.0:
resolution: {integrity: sha512-+qJyx4xiKra8mZrcwhjMRMUhD5NR1R8esPkzIYxX96JiecFoxAXFuz/GpR3+ev4PE1WamHip78wV0vcmPQtp8w==}
engines: {node: '>=14.16'}
@ -2333,6 +2408,10 @@ packages:
resolution: {integrity: sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==}
engines: {node: '>=12'}
cliui@9.0.1:
resolution: {integrity: sha512-k7ndgKhwoQveBL+/1tqGJYNz097I7WOvwbmmU2AR5+magtbjPWQTS1C5vzGkBC8Ym8UWRzfKUzUUqFLypY4Q+w==}
engines: {node: '>=20'}
clone@1.0.4:
resolution: {integrity: sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==}
engines: {node: '>=0.8'}
@ -2569,6 +2648,9 @@ packages:
resolution: {integrity: sha512-DeWwawk6r5yR9jFgnDKYt4sLS0LmHJJi3ZOnb5/JdbYwj3nW+FxQnHIjhBKz8YLC7oRNPVM9NQ47I3CVx34eqQ==}
engines: {node: '>=12'}
emoji-regex@10.4.0:
resolution: {integrity: sha512-EC+0oUMY1Rqm4O6LLrgjtYDvcVYTy7chDnM4Q7030tP4Kwj3u/pR6gP9ygnp2CJMK5Gq+9Q2oqmrFJAz01DXjw==}
emoji-regex@8.0.0:
resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==}
@ -2987,6 +3069,10 @@ packages:
resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==}
engines: {node: 6.* || 8.* || >= 10.*}
get-east-asian-width@1.3.0:
resolution: {integrity: sha512-vpeMIQKxczTD/0s2CdEWHcb0eeJe6TFjxb+J5xgX7hScxqrGuyjmv4c1D4A/gelKfyox0gJJwIHF+fLjeaM8kQ==}
engines: {node: '>=18'}
get-intrinsic@1.3.0:
resolution: {integrity: sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==}
engines: {node: '>= 0.4'}
@ -4337,6 +4423,10 @@ packages:
resolution: {integrity: sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==}
engines: {node: '>=12'}
string-width@7.2.0:
resolution: {integrity: sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==}
engines: {node: '>=18'}
string.prototype.trim@1.2.10:
resolution: {integrity: sha512-Rs66F0P/1kedk5lyYyH9uBzuiI/kNRmwJAR9quK6VOtIpZ2G+hMZd+HQbbv25MgCA6gEffoMZYxlTod4WcdrKA==}
engines: {node: '>= 0.4'}
@ -4801,6 +4891,10 @@ packages:
resolution: {integrity: sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==}
engines: {node: '>=12'}
wrap-ansi@9.0.0:
resolution: {integrity: sha512-G8ura3S+3Z2G+mkgNRq8dqaFZAuxfsxpBB8OCTGRTCtp+l/v9nbFNmCUP1BZMts3G1142MsZfn6eeUKrr4PD1Q==}
engines: {node: '>=18'}
wrappy@1.0.2:
resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==}
@ -4824,10 +4918,18 @@ packages:
resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==}
engines: {node: '>=12'}
yargs-parser@22.0.0:
resolution: {integrity: sha512-rwu/ClNdSMpkSrUb+d6BRsSkLUq1fmfsY6TOpYzTwvwkg1/NRG85KBy3kq++A8LKQwX6lsu+aWad+2khvuXrqw==}
engines: {node: ^20.19.0 || ^22.12.0 || >=23}
yargs@17.7.2:
resolution: {integrity: sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==}
engines: {node: '>=12'}
yargs@18.0.0:
resolution: {integrity: sha512-4UEqdc2RYGHZc7Doyqkrqiln3p9X2DZVxaGbwhn2pi7MrRagKaOcIKe8L3OxYcbhXLgLFUS3zAYuQjKBQgmuNg==}
engines: {node: ^20.19.0 || ^22.12.0 || >=23}
yauzl@3.2.0:
resolution: {integrity: sha512-Ow9nuGZE+qp1u4JIPvg+uCiUr7xGQWdff7JQSk5VGYTAZMDe2q8lxJ10ygv10qmSj031Ty/6FNJpLO4o1Sgc+w==}
engines: {node: '>=12'}
@ -6424,6 +6526,39 @@ snapshots:
dependencies:
consola: 3.4.2
'@oven/bun-darwin-aarch64@1.2.16':
optional: true
'@oven/bun-darwin-x64-baseline@1.2.16':
optional: true
'@oven/bun-darwin-x64@1.2.16':
optional: true
'@oven/bun-linux-aarch64-musl@1.2.16':
optional: true
'@oven/bun-linux-aarch64@1.2.16':
optional: true
'@oven/bun-linux-x64-baseline@1.2.16':
optional: true
'@oven/bun-linux-x64-musl-baseline@1.2.16':
optional: true
'@oven/bun-linux-x64-musl@1.2.16':
optional: true
'@oven/bun-linux-x64@1.2.16':
optional: true
'@oven/bun-windows-x64-baseline@1.2.16':
optional: true
'@oven/bun-windows-x64@1.2.16':
optional: true
'@paralleldrive/cuid2@2.2.2':
dependencies:
'@noble/hashes': 1.8.0
@ -7250,6 +7385,24 @@ snapshots:
base64-js: 1.5.1
ieee754: 1.2.1
bun-types@1.2.16:
dependencies:
'@types/node': 24.0.1
bun@1.2.16:
optionalDependencies:
'@oven/bun-darwin-aarch64': 1.2.16
'@oven/bun-darwin-x64': 1.2.16
'@oven/bun-darwin-x64-baseline': 1.2.16
'@oven/bun-linux-aarch64': 1.2.16
'@oven/bun-linux-aarch64-musl': 1.2.16
'@oven/bun-linux-x64': 1.2.16
'@oven/bun-linux-x64-baseline': 1.2.16
'@oven/bun-linux-x64-musl': 1.2.16
'@oven/bun-linux-x64-musl-baseline': 1.2.16
'@oven/bun-windows-x64': 1.2.16
'@oven/bun-windows-x64-baseline': 1.2.16
cacheable-lookup@7.0.0: {}
cacheable-request@10.2.14:
@ -7338,6 +7491,12 @@ snapshots:
strip-ansi: 6.0.1
wrap-ansi: 7.0.0
cliui@9.0.1:
dependencies:
string-width: 7.2.0
strip-ansi: 7.1.0
wrap-ansi: 9.0.0
clone@1.0.4: {}
co@4.6.0: {}
@ -7532,6 +7691,8 @@ snapshots:
emittery@0.13.1: {}
emoji-regex@10.4.0: {}
emoji-regex@8.0.0: {}
emoji-regex@9.2.2: {}
@ -8083,6 +8244,8 @@ snapshots:
get-caller-file@2.0.5: {}
get-east-asian-width@1.3.0: {}
get-intrinsic@1.3.0:
dependencies:
call-bind-apply-helpers: 1.0.2
@ -9618,6 +9781,12 @@ snapshots:
emoji-regex: 9.2.2
strip-ansi: 7.1.0
string-width@7.2.0:
dependencies:
emoji-regex: 10.4.0
get-east-asian-width: 1.3.0
strip-ansi: 7.1.0
string.prototype.trim@1.2.10:
dependencies:
call-bind: 1.0.8
@ -10133,6 +10302,12 @@ snapshots:
string-width: 5.1.2
strip-ansi: 7.1.0
wrap-ansi@9.0.0:
dependencies:
ansi-styles: 6.2.1
string-width: 7.2.0
strip-ansi: 7.1.0
wrappy@1.0.2: {}
write-file-atomic@5.0.1:
@ -10148,6 +10323,8 @@ snapshots:
yargs-parser@21.1.1: {}
yargs-parser@22.0.0: {}
yargs@17.7.2:
dependencies:
cliui: 8.0.1
@ -10158,6 +10335,15 @@ snapshots:
y18n: 5.0.8
yargs-parser: 21.1.1
yargs@18.0.0:
dependencies:
cliui: 9.0.1
escalade: 3.2.0
get-caller-file: 2.0.5
string-width: 7.2.0
y18n: 5.0.8
yargs-parser: 22.0.0
yauzl@3.2.0:
dependencies:
buffer-crc32: 0.2.13

View File

@ -18,7 +18,7 @@ import { App, AppConfig, CreateOptions } from '../types';
import { CreateModule } from './utils';
export const app: App = { configure: new Configure() };
export const app: App = { configure: new Configure(), commands: [] };
export const createApp = (options: CreateOptions) => async (): Promise<App> => {
const { config, builder } = options;

View File

@ -1,6 +1,8 @@
import { ModuleMetadata, PipeTransform, Type } from '@nestjs/common';
import { NestFastifyApplication } from '@nestjs/platform-fastify';
import { CommandModule } from 'yargs';
import { Configure } from '../config/configure';
import { ConfigStorageOption, ConfigureFactory } from '../config/types';
@ -8,6 +10,8 @@ export type App = {
container?: NestFastifyApplication;
configure: Configure;
commands: CommandModule<RecordAny, RecordAny>[];
};
export interface CreateOptions {
@ -61,3 +65,17 @@ export interface PanicOption {
exit?: boolean;
}
export interface CommandOption<T = RecordAny, P = RecordAny> extends CommandModule<T, P> {
instant?: boolean;
}
export type CommandItem<T = RecordAny, P = RecordAny> = (
app: Required<App>,
) => Promise<CommandOption<T, P>>;
export type CommandCollection = Array<CommandItem<any, any>>;
export interface CreateOption {
commands: () => CommandCollection;
}