@midwayjs/commander 4.0.0-beta.2 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/enquirerService.d.ts +17 -0
- package/dist/enquirerService.js +135 -0
- package/dist/framework.d.ts +4 -2
- package/dist/framework.js +79 -7
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/interface.d.ts +10 -2
- package/dist/question.d.ts +46 -0
- package/dist/question.js +81 -0
- package/dist/response.d.ts +5 -4
- package/package.json +14 -12
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { QuestionValue } from './question';
|
|
2
|
+
export interface PromptResult {
|
|
3
|
+
[key: string]: QuestionValue;
|
|
4
|
+
}
|
|
5
|
+
type QuestionSetModule = new (...args: unknown[]) => object;
|
|
6
|
+
export declare class EnquirerService {
|
|
7
|
+
private applicationContext;
|
|
8
|
+
prompt<T extends PromptResult = PromptResult>(questionSet: string, initialAnswers?: PromptResult): Promise<T>;
|
|
9
|
+
prompt<T extends PromptResult = PromptResult>(questionSet: QuestionSetModule, initialAnswers?: PromptResult): Promise<T>;
|
|
10
|
+
private resolveQuestionSetModule;
|
|
11
|
+
private buildQuestions;
|
|
12
|
+
private applyQuestionFor;
|
|
13
|
+
private runQuestions;
|
|
14
|
+
private resolveWhen;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=enquirerService.d.ts.map
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EnquirerService = void 0;
|
|
13
|
+
const core_1 = require("@midwayjs/core");
|
|
14
|
+
const enquirer = require("enquirer");
|
|
15
|
+
const question_1 = require("./question");
|
|
16
|
+
let EnquirerService = class EnquirerService {
|
|
17
|
+
applicationContext;
|
|
18
|
+
async prompt(questionSet, initialAnswers = {}) {
|
|
19
|
+
// Resolve question set by name or class reference.
|
|
20
|
+
const questionSetModule = this.resolveQuestionSetModule(questionSet);
|
|
21
|
+
const questionSetInstance = (await this.applicationContext.getAsync(questionSetModule));
|
|
22
|
+
// Build enquirer questions from decorators.
|
|
23
|
+
const questions = this.buildQuestions(questionSetModule, questionSetInstance);
|
|
24
|
+
const answers = await this.runQuestions(questions, initialAnswers);
|
|
25
|
+
return answers;
|
|
26
|
+
}
|
|
27
|
+
resolveQuestionSetModule(questionSet) {
|
|
28
|
+
if (typeof questionSet !== 'string') {
|
|
29
|
+
return questionSet;
|
|
30
|
+
}
|
|
31
|
+
const questionSetName = questionSet;
|
|
32
|
+
const modules = core_1.DecoratorManager.listModule(question_1.CLI_QUESTION_SET_KEY);
|
|
33
|
+
for (const module of modules) {
|
|
34
|
+
const metadata = core_1.MetadataManager.getMetadata(question_1.CLI_QUESTION_SET_KEY, module);
|
|
35
|
+
if (metadata?.name === questionSetName) {
|
|
36
|
+
return module;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
throw new core_1.MidwayCommonError(`QuestionSet "${questionSetName}" not found`);
|
|
40
|
+
}
|
|
41
|
+
buildQuestions(module, instance) {
|
|
42
|
+
const questionMetaList = core_1.MetadataManager.getMetadata(question_1.CLI_QUESTION_KEY, module) || [];
|
|
43
|
+
const questionForMetaList = core_1.MetadataManager.getMetadata(question_1.CLI_QUESTION_FOR_KEY, module) || [];
|
|
44
|
+
return questionMetaList.map(meta => {
|
|
45
|
+
const question = {
|
|
46
|
+
...meta.options,
|
|
47
|
+
};
|
|
48
|
+
if (!question.name) {
|
|
49
|
+
throw new core_1.MidwayCommonError(`Question name is required in ${module?.name || 'QuestionSet'}`);
|
|
50
|
+
}
|
|
51
|
+
const candidate = instance[meta.propertyKey];
|
|
52
|
+
const handler = typeof candidate === 'function'
|
|
53
|
+
? candidate.bind(instance)
|
|
54
|
+
: undefined;
|
|
55
|
+
if (handler) {
|
|
56
|
+
// Question method acts as enquirer "result" transformer.
|
|
57
|
+
question.result = handler;
|
|
58
|
+
}
|
|
59
|
+
const forHandlers = questionForMetaList.filter(item => item.options?.name === question.name);
|
|
60
|
+
for (const forMeta of forHandlers) {
|
|
61
|
+
const forCandidate = instance[forMeta.propertyKey];
|
|
62
|
+
const bound = typeof forCandidate === 'function'
|
|
63
|
+
? forCandidate.bind(instance)
|
|
64
|
+
: undefined;
|
|
65
|
+
if (bound !== undefined) {
|
|
66
|
+
this.applyQuestionFor(question, forMeta.type, bound);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (question.default !== undefined && question.initial === undefined) {
|
|
70
|
+
// Align "default" with enquirer "initial".
|
|
71
|
+
question.initial = question.default;
|
|
72
|
+
delete question.default;
|
|
73
|
+
}
|
|
74
|
+
return question;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
applyQuestionFor(question, type, handler) {
|
|
78
|
+
switch (type) {
|
|
79
|
+
case 'default':
|
|
80
|
+
question.initial = handler;
|
|
81
|
+
return;
|
|
82
|
+
case 'validate':
|
|
83
|
+
question.validate = handler;
|
|
84
|
+
return;
|
|
85
|
+
case 'choices':
|
|
86
|
+
question.choices = handler;
|
|
87
|
+
return;
|
|
88
|
+
case 'message':
|
|
89
|
+
question.message = handler;
|
|
90
|
+
return;
|
|
91
|
+
case 'when':
|
|
92
|
+
question.when = handler;
|
|
93
|
+
return;
|
|
94
|
+
default:
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async runQuestions(questions, initialAnswers) {
|
|
99
|
+
const answers = { ...initialAnswers };
|
|
100
|
+
for (const question of questions) {
|
|
101
|
+
// Evaluate "when" with accumulated answers to decide whether to ask.
|
|
102
|
+
const shouldAsk = await this.resolveWhen(question.when, answers);
|
|
103
|
+
if (!shouldAsk) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const currentQuestion = { ...question };
|
|
107
|
+
delete currentQuestion.when;
|
|
108
|
+
if (!currentQuestion.type) {
|
|
109
|
+
throw new core_1.MidwayCommonError(`Question "${currentQuestion.name}" type is required`);
|
|
110
|
+
}
|
|
111
|
+
const result = await enquirer.prompt(currentQuestion);
|
|
112
|
+
Object.assign(answers, result);
|
|
113
|
+
}
|
|
114
|
+
return answers;
|
|
115
|
+
}
|
|
116
|
+
async resolveWhen(whenValue, answers) {
|
|
117
|
+
if (typeof whenValue === 'function') {
|
|
118
|
+
return Boolean(await whenValue(answers));
|
|
119
|
+
}
|
|
120
|
+
if (typeof whenValue === 'boolean') {
|
|
121
|
+
return whenValue;
|
|
122
|
+
}
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
exports.EnquirerService = EnquirerService;
|
|
127
|
+
__decorate([
|
|
128
|
+
(0, core_1.ApplicationContext)(),
|
|
129
|
+
__metadata("design:type", Object)
|
|
130
|
+
], EnquirerService.prototype, "applicationContext", void 0);
|
|
131
|
+
exports.EnquirerService = EnquirerService = __decorate([
|
|
132
|
+
(0, core_1.Provide)(),
|
|
133
|
+
(0, core_1.Scope)(core_1.ScopeEnum.Singleton)
|
|
134
|
+
], EnquirerService);
|
|
135
|
+
//# sourceMappingURL=enquirerService.js.map
|
package/dist/framework.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseFramework, IMidwayBootstrapOptions } from '@midwayjs/core';
|
|
2
|
-
import { ICommanderConfigurationOptions, IMidwayCommanderApplication,
|
|
2
|
+
import { ICommanderConfigurationOptions, IMidwayCommanderApplication, IMidwayCommanderContext } from './interface';
|
|
3
3
|
import { Command } from 'commander';
|
|
4
|
-
export declare class MidwayCommanderFramework extends BaseFramework<IMidwayCommanderApplication,
|
|
4
|
+
export declare class MidwayCommanderFramework extends BaseFramework<IMidwayCommanderApplication, IMidwayCommanderContext, ICommanderConfigurationOptions> {
|
|
5
5
|
app: IMidwayCommanderApplication;
|
|
6
6
|
protected frameworkLoggerName: string;
|
|
7
7
|
private program;
|
|
@@ -16,6 +16,8 @@ export declare class MidwayCommanderFramework extends BaseFramework<IMidwayComma
|
|
|
16
16
|
* 从而避免测试环境(Jest/Node)对命令行参数的污染。
|
|
17
17
|
*/
|
|
18
18
|
runCommand(...args: string[]): Promise<Command>;
|
|
19
|
+
private handleError;
|
|
20
|
+
private isCommanderHelpExit;
|
|
19
21
|
private outputResult;
|
|
20
22
|
private outputChunk;
|
|
21
23
|
private isReadableLike;
|
package/dist/framework.js
CHANGED
|
@@ -31,7 +31,7 @@ let MidwayCommanderFramework = class MidwayCommanderFramework extends core_1.Bas
|
|
|
31
31
|
await this.program.parseAsync(process.argv);
|
|
32
32
|
}
|
|
33
33
|
catch (error) {
|
|
34
|
-
|
|
34
|
+
this.handleError(error, true);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
@@ -42,7 +42,31 @@ let MidwayCommanderFramework = class MidwayCommanderFramework extends core_1.Bas
|
|
|
42
42
|
*/
|
|
43
43
|
async runCommand(...args) {
|
|
44
44
|
this.loadCommands();
|
|
45
|
-
|
|
45
|
+
try {
|
|
46
|
+
return await this.program.parseAsync(args, { from: 'user' });
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
this.handleError(error, false);
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
handleError(error, useDefault) {
|
|
54
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
55
|
+
const handler = this.configurationOptions?.errorHandler ??
|
|
56
|
+
(useDefault
|
|
57
|
+
? (err) => {
|
|
58
|
+
if (this.isCommanderHelpExit(err)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.logger.error(err);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
: undefined);
|
|
65
|
+
handler?.(err);
|
|
66
|
+
}
|
|
67
|
+
isCommanderHelpExit(err) {
|
|
68
|
+
const code = err?.code;
|
|
69
|
+
return code === 'commander.help' || code === 'commander.version';
|
|
46
70
|
}
|
|
47
71
|
async outputResult(result) {
|
|
48
72
|
if (result == null) {
|
|
@@ -133,14 +157,62 @@ let MidwayCommanderFramework = class MidwayCommanderFramework extends core_1.Bas
|
|
|
133
157
|
}
|
|
134
158
|
}
|
|
135
159
|
cmd.action(async (...args) => {
|
|
136
|
-
const commandInstance = (await this.applicationContext.getAsync(module));
|
|
137
160
|
const commandObj = args[args.length - 1];
|
|
138
161
|
const actualArgs = args.slice(0, -2);
|
|
139
162
|
const actualOptions = commandObj.opts();
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
163
|
+
const ctx = this.app.createAnonymousContext({
|
|
164
|
+
command: commandObj,
|
|
165
|
+
args: actualArgs,
|
|
166
|
+
options: actualOptions,
|
|
167
|
+
commandName: metadata.name,
|
|
168
|
+
});
|
|
169
|
+
ctx.command = commandObj;
|
|
170
|
+
ctx.args = actualArgs;
|
|
171
|
+
ctx.options = actualOptions;
|
|
172
|
+
ctx.commandName = metadata.name;
|
|
173
|
+
const traceService = this.applicationContext.get(core_1.MidwayTraceService);
|
|
174
|
+
const traceMetaResolver = this.configurationOptions?.tracing
|
|
175
|
+
?.meta;
|
|
176
|
+
const traceEnabled = this.configurationOptions?.tracing?.enable !== false;
|
|
177
|
+
const traceExtractor = this.configurationOptions?.tracing
|
|
178
|
+
?.extractor;
|
|
179
|
+
const entryCarrier = typeof traceExtractor === 'function'
|
|
180
|
+
? traceExtractor({
|
|
181
|
+
ctx,
|
|
182
|
+
custom: {
|
|
183
|
+
commandName: metadata.name,
|
|
184
|
+
args: actualArgs,
|
|
185
|
+
options: actualOptions,
|
|
186
|
+
},
|
|
187
|
+
})
|
|
188
|
+
: {};
|
|
189
|
+
const result = await traceService.runWithEntrySpan(`commander ${metadata.name}`, {
|
|
190
|
+
enable: traceEnabled,
|
|
191
|
+
carrier: entryCarrier,
|
|
192
|
+
attributes: {
|
|
193
|
+
'midway.protocol': 'commander',
|
|
194
|
+
'midway.command.name': metadata.name,
|
|
195
|
+
},
|
|
196
|
+
meta: traceMetaResolver,
|
|
197
|
+
metaArgs: {
|
|
198
|
+
ctx,
|
|
199
|
+
carrier: entryCarrier,
|
|
200
|
+
custom: {
|
|
201
|
+
commandName: metadata.name,
|
|
202
|
+
args: actualArgs,
|
|
203
|
+
options: actualOptions,
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
}, async () => {
|
|
207
|
+
const fn = await this.applyMiddleware(async (ctx) => {
|
|
208
|
+
const commandInstance = (await ctx.requestContext.getAsync(module));
|
|
209
|
+
if (commandInstance.run) {
|
|
210
|
+
return await commandInstance.run(actualArgs, actualOptions);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
return await fn(ctx);
|
|
214
|
+
});
|
|
215
|
+
await this.outputResult(result);
|
|
144
216
|
});
|
|
145
217
|
}
|
|
146
218
|
this.isCommandsLoaded = true;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './interface';
|
|
2
2
|
export * from './decorator';
|
|
3
|
+
export * from './question';
|
|
4
|
+
export * from './enquirerService';
|
|
3
5
|
export * from './response';
|
|
4
6
|
export { MidwayCommanderFramework as Framework } from './framework';
|
|
5
7
|
export { CommanderConfiguration as Configuration } from './configuration';
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.Configuration = exports.Framework = void 0;
|
|
18
18
|
__exportStar(require("./interface"), exports);
|
|
19
19
|
__exportStar(require("./decorator"), exports);
|
|
20
|
+
__exportStar(require("./question"), exports);
|
|
21
|
+
__exportStar(require("./enquirerService"), exports);
|
|
20
22
|
__exportStar(require("./response"), exports);
|
|
21
23
|
var framework_1 = require("./framework");
|
|
22
24
|
Object.defineProperty(exports, "Framework", { enumerable: true, get: function () { return framework_1.MidwayCommanderFramework; } });
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { IConfigurationOptions, IMidwayApplication, IMidwayContext } from '@midwayjs/core';
|
|
2
|
+
import { Command } from 'commander';
|
|
2
3
|
export { IMidwayContext } from '@midwayjs/core';
|
|
3
4
|
export interface ICommanderConfigurationOptions extends IConfigurationOptions {
|
|
5
|
+
errorHandler?: (err: Error) => void;
|
|
4
6
|
}
|
|
5
|
-
export
|
|
7
|
+
export interface IMidwayCommanderContext extends IMidwayContext {
|
|
8
|
+
command?: Command;
|
|
9
|
+
args?: string[];
|
|
10
|
+
options?: Record<string, any>;
|
|
11
|
+
commandName?: string;
|
|
12
|
+
}
|
|
13
|
+
export type IMidwayCommanderApplication = IMidwayApplication<IMidwayCommanderContext>;
|
|
6
14
|
export type Application = IMidwayCommanderApplication;
|
|
7
|
-
export type Context =
|
|
15
|
+
export type Context = IMidwayCommanderContext;
|
|
8
16
|
export interface CommandRunner {
|
|
9
17
|
run(passedParams: string[], options?: Record<string, any>): unknown | Promise<unknown>;
|
|
10
18
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export declare const CLI_QUESTION_SET_KEY = "commander:questionSet";
|
|
2
|
+
export declare const CLI_QUESTION_KEY = "commander:question";
|
|
3
|
+
export declare const CLI_QUESTION_FOR_KEY = "commander:questionFor";
|
|
4
|
+
export interface QuestionSetOptions {
|
|
5
|
+
name?: string;
|
|
6
|
+
}
|
|
7
|
+
export type QuestionValue = unknown;
|
|
8
|
+
export type QuestionWhen = (answers: Record<string, QuestionValue>) => boolean | Promise<boolean>;
|
|
9
|
+
export type QuestionValidate = (value: QuestionValue, answers?: Record<string, QuestionValue>) => boolean | string | Promise<boolean | string>;
|
|
10
|
+
export type QuestionChoices = Array<unknown> | ((answers?: Record<string, QuestionValue>) => Array<unknown> | Promise<Array<unknown>>);
|
|
11
|
+
export type QuestionMessage = string | ((answers?: Record<string, QuestionValue>) => string | Promise<string>);
|
|
12
|
+
export type QuestionInitial = QuestionValue | ((answers?: Record<string, QuestionValue>) => QuestionValue | Promise<QuestionValue>);
|
|
13
|
+
export type QuestionResult = (value: QuestionValue, answers?: Record<string, QuestionValue>) => QuestionValue | Promise<QuestionValue>;
|
|
14
|
+
export interface QuestionOptions {
|
|
15
|
+
name: string;
|
|
16
|
+
type?: string;
|
|
17
|
+
message?: QuestionMessage;
|
|
18
|
+
choices?: QuestionChoices;
|
|
19
|
+
validate?: QuestionValidate;
|
|
20
|
+
when?: QuestionWhen | boolean;
|
|
21
|
+
default?: QuestionInitial;
|
|
22
|
+
initial?: QuestionInitial;
|
|
23
|
+
result?: QuestionResult;
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
}
|
|
26
|
+
export interface QuestionMeta {
|
|
27
|
+
propertyKey: string | symbol;
|
|
28
|
+
options: QuestionOptions;
|
|
29
|
+
}
|
|
30
|
+
export type QuestionForType = 'validate' | 'choices' | 'message' | 'default' | 'when';
|
|
31
|
+
export interface QuestionForOptions {
|
|
32
|
+
name: string;
|
|
33
|
+
}
|
|
34
|
+
export interface QuestionForMeta {
|
|
35
|
+
propertyKey: string | symbol;
|
|
36
|
+
options: QuestionForOptions;
|
|
37
|
+
type: QuestionForType;
|
|
38
|
+
}
|
|
39
|
+
export declare function QuestionSet(options?: QuestionSetOptions): ClassDecorator;
|
|
40
|
+
export declare function Question(options: QuestionOptions): MethodDecorator;
|
|
41
|
+
export declare function ValidateFor(options: QuestionForOptions): MethodDecorator;
|
|
42
|
+
export declare function ChoicesFor(options: QuestionForOptions): MethodDecorator;
|
|
43
|
+
export declare function MessageFor(options: QuestionForOptions): MethodDecorator;
|
|
44
|
+
export declare function DefaultFor(options: QuestionForOptions): MethodDecorator;
|
|
45
|
+
export declare function WhenFor(options: QuestionForOptions): MethodDecorator;
|
|
46
|
+
//# sourceMappingURL=question.d.ts.map
|
package/dist/question.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CLI_QUESTION_FOR_KEY = exports.CLI_QUESTION_KEY = exports.CLI_QUESTION_SET_KEY = void 0;
|
|
4
|
+
exports.QuestionSet = QuestionSet;
|
|
5
|
+
exports.Question = Question;
|
|
6
|
+
exports.ValidateFor = ValidateFor;
|
|
7
|
+
exports.ChoicesFor = ChoicesFor;
|
|
8
|
+
exports.MessageFor = MessageFor;
|
|
9
|
+
exports.DefaultFor = DefaultFor;
|
|
10
|
+
exports.WhenFor = WhenFor;
|
|
11
|
+
const core_1 = require("@midwayjs/core");
|
|
12
|
+
exports.CLI_QUESTION_SET_KEY = 'commander:questionSet';
|
|
13
|
+
exports.CLI_QUESTION_KEY = 'commander:question';
|
|
14
|
+
exports.CLI_QUESTION_FOR_KEY = 'commander:questionFor';
|
|
15
|
+
function QuestionSet(options = {}) {
|
|
16
|
+
return (target) => {
|
|
17
|
+
core_1.DecoratorManager.saveModule(exports.CLI_QUESTION_SET_KEY, target);
|
|
18
|
+
core_1.MetadataManager.defineMetadata(exports.CLI_QUESTION_SET_KEY, options, target);
|
|
19
|
+
(0, core_1.Scope)(core_1.ScopeEnum.Singleton)(target);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function Question(options) {
|
|
23
|
+
return (target, propertyKey, _descriptor) => {
|
|
24
|
+
void _descriptor;
|
|
25
|
+
core_1.MetadataManager.attachMetadata(exports.CLI_QUESTION_KEY, {
|
|
26
|
+
propertyKey,
|
|
27
|
+
options,
|
|
28
|
+
}, target.constructor);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function ValidateFor(options) {
|
|
32
|
+
return (target, propertyKey, descriptor) => {
|
|
33
|
+
void descriptor;
|
|
34
|
+
core_1.MetadataManager.attachMetadata(exports.CLI_QUESTION_FOR_KEY, {
|
|
35
|
+
propertyKey,
|
|
36
|
+
type: 'validate',
|
|
37
|
+
options,
|
|
38
|
+
}, target.constructor);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function ChoicesFor(options) {
|
|
42
|
+
return (target, propertyKey, descriptor) => {
|
|
43
|
+
void descriptor;
|
|
44
|
+
core_1.MetadataManager.attachMetadata(exports.CLI_QUESTION_FOR_KEY, {
|
|
45
|
+
propertyKey,
|
|
46
|
+
type: 'choices',
|
|
47
|
+
options,
|
|
48
|
+
}, target.constructor);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function MessageFor(options) {
|
|
52
|
+
return (target, propertyKey, descriptor) => {
|
|
53
|
+
void descriptor;
|
|
54
|
+
core_1.MetadataManager.attachMetadata(exports.CLI_QUESTION_FOR_KEY, {
|
|
55
|
+
propertyKey,
|
|
56
|
+
type: 'message',
|
|
57
|
+
options,
|
|
58
|
+
}, target.constructor);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function DefaultFor(options) {
|
|
62
|
+
return (target, propertyKey, descriptor) => {
|
|
63
|
+
void descriptor;
|
|
64
|
+
core_1.MetadataManager.attachMetadata(exports.CLI_QUESTION_FOR_KEY, {
|
|
65
|
+
propertyKey,
|
|
66
|
+
type: 'default',
|
|
67
|
+
options,
|
|
68
|
+
}, target.constructor);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function WhenFor(options) {
|
|
72
|
+
return (target, propertyKey, descriptor) => {
|
|
73
|
+
void descriptor;
|
|
74
|
+
core_1.MetadataManager.attachMetadata(exports.CLI_QUESTION_FOR_KEY, {
|
|
75
|
+
propertyKey,
|
|
76
|
+
type: 'when',
|
|
77
|
+
options,
|
|
78
|
+
}, target.constructor);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=question.js.map
|
package/dist/response.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ServerResponse, ServerStreamOptions } from '@midwayjs/core';
|
|
2
2
|
import { Transform } from 'stream';
|
|
3
|
-
|
|
3
|
+
import { IMidwayCommanderContext } from './interface';
|
|
4
|
+
export declare class CliStreamResponse<CTX extends IMidwayCommanderContext = IMidwayCommanderContext> extends Transform {
|
|
4
5
|
private readonly ctx;
|
|
5
6
|
private readonly options;
|
|
6
7
|
constructor(ctx: CTX, options?: ServerStreamOptions<CTX>);
|
|
@@ -8,8 +9,8 @@ export declare class CliStreamResponse<CTX extends IMidwayContext = IMidwayConte
|
|
|
8
9
|
send(data: unknown): void;
|
|
9
10
|
sendError(error: Error): void;
|
|
10
11
|
}
|
|
11
|
-
export declare class CliServerResponse<CTX extends
|
|
12
|
-
static STREAM_TPL: <CTX_1 extends
|
|
12
|
+
export declare class CliServerResponse<CTX extends IMidwayCommanderContext = IMidwayCommanderContext> extends ServerResponse<CTX> {
|
|
13
|
+
static STREAM_TPL: <CTX_1 extends IMidwayCommanderContext>(data: unknown, _ctx: CTX_1) => unknown;
|
|
13
14
|
stream(options?: ServerStreamOptions<CTX>): CliStreamResponse<any>;
|
|
14
15
|
}
|
|
15
16
|
//# sourceMappingURL=response.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/commander",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Midway Commander Framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -15,22 +15,24 @@
|
|
|
15
15
|
"dist/**/*.d.ts",
|
|
16
16
|
"index.d.ts"
|
|
17
17
|
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"test": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand",
|
|
21
|
+
"cov": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand --coverage --forceExit",
|
|
22
|
+
"ci": "npm run test",
|
|
23
|
+
"lint": "mwts check"
|
|
24
|
+
},
|
|
18
25
|
"dependencies": {
|
|
19
|
-
"
|
|
20
|
-
"
|
|
26
|
+
"@midwayjs/core": "^4.0.0",
|
|
27
|
+
"commander": "14.0.3",
|
|
28
|
+
"enquirer": "2.4.1"
|
|
21
29
|
},
|
|
22
30
|
"devDependencies": {
|
|
23
|
-
"@midwayjs/mock": "^4.0.0
|
|
31
|
+
"@midwayjs/mock": "^4.0.0"
|
|
24
32
|
},
|
|
25
33
|
"engines": {
|
|
26
34
|
"node": ">=20"
|
|
27
35
|
},
|
|
28
36
|
"license": "MIT",
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
"test": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand",
|
|
32
|
-
"cov": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand --coverage --forceExit",
|
|
33
|
-
"ci": "npm run test",
|
|
34
|
-
"lint": "mwts check"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
+
"gitHead": "014f32c23ebc1d5ac21777c76be2fd373ce992d8"
|
|
38
|
+
}
|