@aomex/commander
Advanced tools
Comparing version 0.0.11 to 0.0.12
# @aomex/commander | ||
## 0.0.12 | ||
### Patch Changes | ||
- [`5e84bab`](https://github.com/aomex/aomex/commit/5e84bab8d9f0b27911730b17771bec8a881ef9bb) Thanks [@geekact](https://github.com/geekact)! - feat(commander): support logics | ||
- Updated dependencies [[`77039d8`](https://github.com/aomex/aomex/commit/77039d8819944f27662866aab238bde6778d9a6f)]: | ||
- @aomex/console@0.0.12 | ||
- @aomex/core@0.0.12 | ||
## 0.0.11 | ||
@@ -4,0 +14,0 @@ |
@@ -10,9 +10,17 @@ import { ConsoleMiddlewareToken, ConsoleContext, ConsoleChain } from '@aomex/console'; | ||
type CollectArrayType<T> = T extends ConsoleMiddlewareToken<infer R> ? R : object; | ||
interface BuilderOptions<Props extends object, T extends ConsoleMiddlewareToken[] | []> { | ||
interface BuilderOptions<Props extends object, T extends ConsoleMiddlewareToken[] | [], Logics extends object> { | ||
showInHelp?: boolean; | ||
docs?: CommandDocs; | ||
mount?: T; | ||
action: (ctx: Props & Union2Intersection<CollectArrayType<T[number]>> & ConsoleContext) => any; | ||
logics?: Logics; | ||
action: (ctx: Props & Union2Intersection<CollectArrayType<T[number]>> & ConsoleContext, logic: { | ||
[K in keyof Logics]: Logics[K] extends (ctx: any, ...args: infer P) => infer R ? (...args: P) => R : never; | ||
}) => any; | ||
} | ||
declare class Builder<Props extends object = object, T extends ConsoleMiddlewareToken[] | [] = []> { | ||
declare namespace Builder { | ||
interface LogicFunction<Props extends object, T extends ConsoleMiddlewareToken[] | []> { | ||
[key: string]: (ctx: Props & Union2Intersection<CollectArrayType<T[number]>> & ConsoleContext, ...args: any[]) => any; | ||
} | ||
} | ||
declare class Builder<Props extends object = object, T extends ConsoleMiddlewareToken[] | [] = [], Logics extends Builder.LogicFunction<Props, T> = Builder.LogicFunction<Props, T>> { | ||
readonly chain: ConsoleChain; | ||
@@ -22,3 +30,3 @@ readonly commands: string[]; | ||
readonly docs: CommandDocs; | ||
constructor(prefix: string, commands: string[], options: BuilderOptions<Props, T>); | ||
constructor(prefix: string, commands: string[], options: BuilderOptions<Props, T, Logics>); | ||
match(command: string): boolean; | ||
@@ -40,3 +48,3 @@ } | ||
constructor(options?: CommanderOptions<Props>); | ||
create<T extends ConsoleMiddlewareToken<object>[] | []>(command: string | string[], options: BuilderOptions<Props, T>): void; | ||
create<T extends ConsoleMiddlewareToken<object>[] | [], Logics extends Builder.LogicFunction<Props, T>>(command: string | string[], options: BuilderOptions<Props, T, Logics>): void; | ||
protected toMiddleware(): Middleware; | ||
@@ -43,0 +51,0 @@ } |
@@ -24,3 +24,11 @@ // src/commanders.ts | ||
middlewareList.push( | ||
middleware.console((ctx, _) => options.action(ctx)) | ||
middleware.console((ctx, _) => { | ||
const logics = {}; | ||
if (options.logics) { | ||
Object.keys(options.logics).forEach((key) => { | ||
logics[key] = options.logics[key].bind(ctx); | ||
}); | ||
} | ||
options.action(ctx, logics); | ||
}) | ||
); | ||
@@ -58,5 +66,3 @@ this.showInHelp = options.showInHelp ?? true; | ||
create(command, options) { | ||
this.builders.push( | ||
new Builder(this.prefix, toArray(command), options) | ||
); | ||
this.builders.push(new Builder(this.prefix, toArray(command), options)); | ||
} | ||
@@ -63,0 +69,0 @@ toMiddleware() { |
{ | ||
"name": "@aomex/commander", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "", | ||
@@ -29,4 +29,4 @@ "type": "module", | ||
"peerDependencies": { | ||
"@aomex/console": "^0.0.11", | ||
"@aomex/core": "^0.0.11" | ||
"@aomex/console": "^0.0.12", | ||
"@aomex/core": "^0.0.12" | ||
}, | ||
@@ -37,6 +37,6 @@ "dependencies": { | ||
"devDependencies": { | ||
"@aomex/console": "^0.0.11", | ||
"@aomex/core": "^0.0.11" | ||
"@aomex/console": "^0.0.12", | ||
"@aomex/core": "^0.0.12" | ||
}, | ||
"scripts": {} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25003
232