@moostjs/event-cli 0.2.35 → 0.3.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/index.cjs +24 -4
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +24 -4
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -69,6 +69,7 @@ const CONTEXT_TYPE = 'CLI';
|
|
|
69
69
|
class MoostCli {
|
|
70
70
|
constructor(opts) {
|
|
71
71
|
this.opts = opts;
|
|
72
|
+
this.optionTypes = {};
|
|
72
73
|
const cliAppOpts = opts === null || opts === void 0 ? void 0 : opts.wooksCli;
|
|
73
74
|
if (cliAppOpts && cliAppOpts instanceof eventCli.WooksCli) {
|
|
74
75
|
this.cliApp = cliAppOpts;
|
|
@@ -104,7 +105,14 @@ class MoostCli {
|
|
|
104
105
|
}
|
|
105
106
|
onInit(moost) {
|
|
106
107
|
this.moost = moost;
|
|
107
|
-
|
|
108
|
+
const boolean = Object
|
|
109
|
+
.entries(this.optionTypes)
|
|
110
|
+
.filter(([_key, val]) => val.length === 1 && val[0] === Boolean)
|
|
111
|
+
.map(([key, _val]) => key);
|
|
112
|
+
console.log(boolean);
|
|
113
|
+
void this.cliApp.run(undefined, {
|
|
114
|
+
boolean,
|
|
115
|
+
});
|
|
108
116
|
}
|
|
109
117
|
bindHandler(opts) {
|
|
110
118
|
var _a, _b, _c, _d;
|
|
@@ -145,6 +153,7 @@ class MoostCli {
|
|
|
145
153
|
keys: param.cliOptionsKeys,
|
|
146
154
|
value: typeof param.value === 'string' ? param.value : '',
|
|
147
155
|
description: param.description || '',
|
|
156
|
+
type: param.type,
|
|
148
157
|
})) : []),
|
|
149
158
|
].forEach(o => cliOptions.set(o.keys[0], o));
|
|
150
159
|
const aliases = [];
|
|
@@ -154,18 +163,29 @@ class MoostCli {
|
|
|
154
163
|
aliases.push(targetPath);
|
|
155
164
|
}
|
|
156
165
|
}
|
|
166
|
+
const cliOptionsArray = Array.from(cliOptions.values());
|
|
167
|
+
cliOptionsArray.forEach(o => {
|
|
168
|
+
for (const key of o.keys) {
|
|
169
|
+
if (!this.optionTypes[key]) {
|
|
170
|
+
this.optionTypes[key] = [];
|
|
171
|
+
}
|
|
172
|
+
if (!(this.optionTypes[key].includes(o.type))) {
|
|
173
|
+
this.optionTypes[key].push(o.type);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
});
|
|
157
177
|
const args = {};
|
|
158
178
|
(_d = meta === null || meta === void 0 ? void 0 : meta.params) === null || _d === void 0 ? void 0 : _d.filter(p => p.paramSource === 'ROUTE' && p.description).forEach(p => args[p.paramName] = p.description);
|
|
159
179
|
const routerBinding = this.cliApp.cli(targetPath, {
|
|
160
180
|
description: (meta === null || meta === void 0 ? void 0 : meta.description) || '',
|
|
161
|
-
options:
|
|
181
|
+
options: cliOptionsArray,
|
|
162
182
|
args,
|
|
163
183
|
aliases,
|
|
164
184
|
examples: (meta === null || meta === void 0 ? void 0 : meta.cliExamples) || [],
|
|
165
185
|
handler: fn,
|
|
166
|
-
onRegister: (path, aliasType) => {
|
|
186
|
+
onRegister: (path, aliasType, route) => {
|
|
167
187
|
var _a;
|
|
168
|
-
opts.register(handler, path, routerBinding.getArgs());
|
|
188
|
+
opts.register(handler, path, (route === null || route === void 0 ? void 0 : route.getArgs()) || routerBinding.getArgs());
|
|
169
189
|
if ((_a = this.opts) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
170
190
|
opts.logHandler(`${'[36m'}(${aliasTypes[aliasType]})${'[32m'}${path}`);
|
|
171
191
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -181,6 +181,7 @@ export declare function CliOption(...keys: string[]): ParameterDecorator;
|
|
|
181
181
|
export declare class MoostCli implements TMoostAdapter<TCliHandlerMeta> {
|
|
182
182
|
protected opts?: TMoostCliOpts | undefined;
|
|
183
183
|
protected cliApp: WooksCli;
|
|
184
|
+
protected optionTypes: Record<string, TFunction[]>;
|
|
184
185
|
constructor(opts?: TMoostCliOpts | undefined);
|
|
185
186
|
onNotFound(): Promise<unknown>;
|
|
186
187
|
protected moost?: Moost;
|
|
@@ -192,6 +193,8 @@ export declare interface TCliHandlerMeta {
|
|
|
192
193
|
path: string;
|
|
193
194
|
}
|
|
194
195
|
|
|
196
|
+
declare type TFunction = Function;
|
|
197
|
+
|
|
195
198
|
export declare interface TMoostCliOpts {
|
|
196
199
|
/**
|
|
197
200
|
* WooksCli options or instance
|
|
@@ -207,6 +210,7 @@ export declare interface TMoostCliOpts {
|
|
|
207
210
|
globalCliOptions?: {
|
|
208
211
|
keys: string[];
|
|
209
212
|
description?: string;
|
|
213
|
+
type?: TFunction;
|
|
210
214
|
}[];
|
|
211
215
|
}
|
|
212
216
|
|
package/dist/index.mjs
CHANGED
|
@@ -68,6 +68,7 @@ const CONTEXT_TYPE = 'CLI';
|
|
|
68
68
|
class MoostCli {
|
|
69
69
|
constructor(opts) {
|
|
70
70
|
this.opts = opts;
|
|
71
|
+
this.optionTypes = {};
|
|
71
72
|
const cliAppOpts = opts === null || opts === void 0 ? void 0 : opts.wooksCli;
|
|
72
73
|
if (cliAppOpts && cliAppOpts instanceof WooksCli) {
|
|
73
74
|
this.cliApp = cliAppOpts;
|
|
@@ -103,7 +104,14 @@ class MoostCli {
|
|
|
103
104
|
}
|
|
104
105
|
onInit(moost) {
|
|
105
106
|
this.moost = moost;
|
|
106
|
-
|
|
107
|
+
const boolean = Object
|
|
108
|
+
.entries(this.optionTypes)
|
|
109
|
+
.filter(([_key, val]) => val.length === 1 && val[0] === Boolean)
|
|
110
|
+
.map(([key, _val]) => key);
|
|
111
|
+
console.log(boolean);
|
|
112
|
+
void this.cliApp.run(undefined, {
|
|
113
|
+
boolean,
|
|
114
|
+
});
|
|
107
115
|
}
|
|
108
116
|
bindHandler(opts) {
|
|
109
117
|
var _a, _b, _c, _d;
|
|
@@ -144,6 +152,7 @@ class MoostCli {
|
|
|
144
152
|
keys: param.cliOptionsKeys,
|
|
145
153
|
value: typeof param.value === 'string' ? param.value : '',
|
|
146
154
|
description: param.description || '',
|
|
155
|
+
type: param.type,
|
|
147
156
|
})) : []),
|
|
148
157
|
].forEach(o => cliOptions.set(o.keys[0], o));
|
|
149
158
|
const aliases = [];
|
|
@@ -153,18 +162,29 @@ class MoostCli {
|
|
|
153
162
|
aliases.push(targetPath);
|
|
154
163
|
}
|
|
155
164
|
}
|
|
165
|
+
const cliOptionsArray = Array.from(cliOptions.values());
|
|
166
|
+
cliOptionsArray.forEach(o => {
|
|
167
|
+
for (const key of o.keys) {
|
|
168
|
+
if (!this.optionTypes[key]) {
|
|
169
|
+
this.optionTypes[key] = [];
|
|
170
|
+
}
|
|
171
|
+
if (!(this.optionTypes[key].includes(o.type))) {
|
|
172
|
+
this.optionTypes[key].push(o.type);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
156
176
|
const args = {};
|
|
157
177
|
(_d = meta === null || meta === void 0 ? void 0 : meta.params) === null || _d === void 0 ? void 0 : _d.filter(p => p.paramSource === 'ROUTE' && p.description).forEach(p => args[p.paramName] = p.description);
|
|
158
178
|
const routerBinding = this.cliApp.cli(targetPath, {
|
|
159
179
|
description: (meta === null || meta === void 0 ? void 0 : meta.description) || '',
|
|
160
|
-
options:
|
|
180
|
+
options: cliOptionsArray,
|
|
161
181
|
args,
|
|
162
182
|
aliases,
|
|
163
183
|
examples: (meta === null || meta === void 0 ? void 0 : meta.cliExamples) || [],
|
|
164
184
|
handler: fn,
|
|
165
|
-
onRegister: (path, aliasType) => {
|
|
185
|
+
onRegister: (path, aliasType, route) => {
|
|
166
186
|
var _a;
|
|
167
|
-
opts.register(handler, path, routerBinding.getArgs());
|
|
187
|
+
opts.register(handler, path, (route === null || route === void 0 ? void 0 : route.getArgs()) || routerBinding.getArgs());
|
|
168
188
|
if ((_a = this.opts) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
169
189
|
opts.logHandler(`${'[36m'}(${aliasTypes[aliasType]})${'[32m'}${path}`);
|
|
170
190
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/event-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "@moostjs/event-cli",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://github.com/moostjs/moostjs/tree/main/packages/event-cli#readme",
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"moost": "0.
|
|
40
|
-
"wooks": "^0.
|
|
41
|
-
"@wooksjs/event-core": "^0.
|
|
39
|
+
"moost": "0.3.0",
|
|
40
|
+
"wooks": "^0.4.1",
|
|
41
|
+
"@wooksjs/event-core": "^0.4.1"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@wooksjs/event-cli": "^0.
|
|
44
|
+
"@wooksjs/event-cli": "^0.4.1",
|
|
45
45
|
"@prostojs/wf": "^0.0.3"
|
|
46
46
|
}
|
|
47
47
|
}
|