@midwayjs/commander 4.0.0-beta.10 → 4.0.0-beta.2
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/framework.d.ts +2 -4
- package/dist/framework.js +7 -44
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/interface.d.ts +2 -10
- package/dist/response.d.ts +4 -5
- package/package.json +11 -13
- package/dist/enquirerService.d.ts +0 -17
- package/dist/enquirerService.js +0 -135
- package/dist/question.d.ts +0 -46
- package/dist/question.js +0 -81
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, IMidwayContext } from './interface';
|
|
3
3
|
import { Command } from 'commander';
|
|
4
|
-
export declare class MidwayCommanderFramework extends BaseFramework<IMidwayCommanderApplication,
|
|
4
|
+
export declare class MidwayCommanderFramework extends BaseFramework<IMidwayCommanderApplication, IMidwayContext, ICommanderConfigurationOptions> {
|
|
5
5
|
app: IMidwayCommanderApplication;
|
|
6
6
|
protected frameworkLoggerName: string;
|
|
7
7
|
private program;
|
|
@@ -16,8 +16,6 @@ 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;
|
|
21
19
|
private outputResult;
|
|
22
20
|
private outputChunk;
|
|
23
21
|
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
|
+
void error;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
@@ -42,31 +42,7 @@ let MidwayCommanderFramework = class MidwayCommanderFramework extends core_1.Bas
|
|
|
42
42
|
*/
|
|
43
43
|
async runCommand(...args) {
|
|
44
44
|
this.loadCommands();
|
|
45
|
-
|
|
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';
|
|
45
|
+
return this.program.parseAsync(args, { from: 'user' });
|
|
70
46
|
}
|
|
71
47
|
async outputResult(result) {
|
|
72
48
|
if (result == null) {
|
|
@@ -157,27 +133,14 @@ let MidwayCommanderFramework = class MidwayCommanderFramework extends core_1.Bas
|
|
|
157
133
|
}
|
|
158
134
|
}
|
|
159
135
|
cmd.action(async (...args) => {
|
|
136
|
+
const commandInstance = (await this.applicationContext.getAsync(module));
|
|
160
137
|
const commandObj = args[args.length - 1];
|
|
161
138
|
const actualArgs = args.slice(0, -2);
|
|
162
139
|
const actualOptions = commandObj.opts();
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
commandName: metadata.name,
|
|
168
|
-
});
|
|
169
|
-
ctx.command = commandObj;
|
|
170
|
-
ctx.args = actualArgs;
|
|
171
|
-
ctx.options = actualOptions;
|
|
172
|
-
ctx.commandName = metadata.name;
|
|
173
|
-
const fn = await this.applyMiddleware(async (ctx) => {
|
|
174
|
-
const commandInstance = (await ctx.requestContext.getAsync(module));
|
|
175
|
-
if (commandInstance.run) {
|
|
176
|
-
return await commandInstance.run(actualArgs, actualOptions);
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
const result = await fn(ctx);
|
|
180
|
-
await this.outputResult(result);
|
|
140
|
+
if (commandInstance.run) {
|
|
141
|
+
const result = await commandInstance.run(actualArgs, actualOptions);
|
|
142
|
+
await this.outputResult(result);
|
|
143
|
+
}
|
|
181
144
|
});
|
|
182
145
|
}
|
|
183
146
|
this.isCommandsLoaded = true;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export * from './interface';
|
|
2
2
|
export * from './decorator';
|
|
3
|
-
export * from './question';
|
|
4
|
-
export * from './enquirerService';
|
|
5
3
|
export * from './response';
|
|
6
4
|
export { MidwayCommanderFramework as Framework } from './framework';
|
|
7
5
|
export { CommanderConfiguration as Configuration } from './configuration';
|
package/dist/index.js
CHANGED
|
@@ -17,8 +17,6 @@ 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);
|
|
22
20
|
__exportStar(require("./response"), exports);
|
|
23
21
|
var framework_1 = require("./framework");
|
|
24
22
|
Object.defineProperty(exports, "Framework", { enumerable: true, get: function () { return framework_1.MidwayCommanderFramework; } });
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import { IConfigurationOptions, IMidwayApplication, IMidwayContext } from '@midwayjs/core';
|
|
2
|
-
import { Command } from 'commander';
|
|
3
2
|
export { IMidwayContext } from '@midwayjs/core';
|
|
4
3
|
export interface ICommanderConfigurationOptions extends IConfigurationOptions {
|
|
5
|
-
errorHandler?: (err: Error) => void;
|
|
6
4
|
}
|
|
7
|
-
export
|
|
8
|
-
command?: Command;
|
|
9
|
-
args?: string[];
|
|
10
|
-
options?: Record<string, any>;
|
|
11
|
-
commandName?: string;
|
|
12
|
-
}
|
|
13
|
-
export type IMidwayCommanderApplication = IMidwayApplication<IMidwayCommanderContext>;
|
|
5
|
+
export type IMidwayCommanderApplication = IMidwayApplication<IMidwayContext>;
|
|
14
6
|
export type Application = IMidwayCommanderApplication;
|
|
15
|
-
export type Context =
|
|
7
|
+
export type Context = IMidwayContext;
|
|
16
8
|
export interface CommandRunner {
|
|
17
9
|
run(passedParams: string[], options?: Record<string, any>): unknown | Promise<unknown>;
|
|
18
10
|
}
|
package/dist/response.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { ServerResponse, ServerStreamOptions } from '@midwayjs/core';
|
|
1
|
+
import { IMidwayContext, ServerResponse, ServerStreamOptions } from '@midwayjs/core';
|
|
2
2
|
import { Transform } from 'stream';
|
|
3
|
-
|
|
4
|
-
export declare class CliStreamResponse<CTX extends IMidwayCommanderContext = IMidwayCommanderContext> extends Transform {
|
|
3
|
+
export declare class CliStreamResponse<CTX extends IMidwayContext = IMidwayContext> extends Transform {
|
|
5
4
|
private readonly ctx;
|
|
6
5
|
private readonly options;
|
|
7
6
|
constructor(ctx: CTX, options?: ServerStreamOptions<CTX>);
|
|
@@ -9,8 +8,8 @@ export declare class CliStreamResponse<CTX extends IMidwayCommanderContext = IMi
|
|
|
9
8
|
send(data: unknown): void;
|
|
10
9
|
sendError(error: Error): void;
|
|
11
10
|
}
|
|
12
|
-
export declare class CliServerResponse<CTX extends
|
|
13
|
-
static STREAM_TPL: <CTX_1 extends
|
|
11
|
+
export declare class CliServerResponse<CTX extends IMidwayContext = IMidwayContext> extends ServerResponse<CTX> {
|
|
12
|
+
static STREAM_TPL: <CTX_1 extends IMidwayContext>(data: unknown, _ctx: CTX_1) => unknown;
|
|
14
13
|
stream(options?: ServerStreamOptions<CTX>): CliStreamResponse<any>;
|
|
15
14
|
}
|
|
16
15
|
//# 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-beta.
|
|
3
|
+
"version": "4.0.0-beta.2",
|
|
4
4
|
"description": "Midway Commander Framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -15,24 +15,22 @@
|
|
|
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
|
-
},
|
|
25
18
|
"dependencies": {
|
|
26
|
-
"@midwayjs/core": "^4.0.0-beta.10",
|
|
27
19
|
"commander": "14.0.2",
|
|
28
|
-
"
|
|
20
|
+
"@midwayjs/core": "^4.0.0-beta.9"
|
|
29
21
|
},
|
|
30
22
|
"devDependencies": {
|
|
31
|
-
"@midwayjs/mock": "^4.0.0-beta.
|
|
23
|
+
"@midwayjs/mock": "^4.0.0-beta.9"
|
|
32
24
|
},
|
|
33
25
|
"engines": {
|
|
34
26
|
"node": ">=20"
|
|
35
27
|
},
|
|
36
28
|
"license": "MIT",
|
|
37
|
-
"
|
|
38
|
-
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc",
|
|
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
|
+
}
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
package/dist/enquirerService.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
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/question.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
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
|