@cabloy/cli 1.0.1
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/LICENSE.en-US +3 -0
- package/LICENSE.zh-CN +3 -0
- package/README.md +1 -0
- package/dist/bin/cabloy.d.ts +3 -0
- package/dist/bin/cabloy.js +6 -0
- package/dist/config.d.ts +43 -0
- package/dist/config.js +38 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +20 -0
- package/dist/lib/bean.cli.base.d.ts +34 -0
- package/dist/lib/bean.cli.base.js +142 -0
- package/dist/lib/bean.cli.d.ts +16 -0
- package/dist/lib/bean.cli.js +38 -0
- package/dist/lib/cli.d.ts +53 -0
- package/dist/lib/cli.js +189 -0
- package/dist/lib/commands.d.ts +6 -0
- package/dist/lib/commands.js +41 -0
- package/dist/lib/index.d.ts +3 -0
- package/dist/lib/index.js +19 -0
- package/dist/lib/lib/bean.cli.d.ts +2 -0
- package/dist/lib/lib/bean.cli.js +3 -0
- package/dist/lib/local.console.d.ts +11 -0
- package/dist/lib/local.console.js +47 -0
- package/dist/lib/local.helper.d.ts +79 -0
- package/dist/lib/local.helper.js +144 -0
- package/dist/lib/local.template.d.ts +97 -0
- package/dist/lib/local.template.js +299 -0
- package/dist/start.d.ts +22 -0
- package/dist/start.js +85 -0
- package/dist/types/argv.d.ts +22 -0
- package/dist/types/argv.js +3 -0
- package/dist/types/console.d.ts +9 -0
- package/dist/types/console.js +3 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +19 -0
- package/package.json +53 -0
package/LICENSE.en-US
ADDED
package/LICENSE.zh-CN
ADDED
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @cabloy/cli
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const commandsConfig: {
|
|
2
|
+
sets: {
|
|
3
|
+
core: string;
|
|
4
|
+
api: string;
|
|
5
|
+
front: string;
|
|
6
|
+
};
|
|
7
|
+
helper: {
|
|
8
|
+
chalk: {
|
|
9
|
+
options: {
|
|
10
|
+
level: number;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
boxen: {
|
|
14
|
+
options: {
|
|
15
|
+
padding: number;
|
|
16
|
+
margin: number;
|
|
17
|
+
align: string;
|
|
18
|
+
borderColor: string;
|
|
19
|
+
borderStyle: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
template: {
|
|
24
|
+
render: {
|
|
25
|
+
fileMapping: {
|
|
26
|
+
gitignore: string;
|
|
27
|
+
_gitignore: string;
|
|
28
|
+
'_.gitignore': string;
|
|
29
|
+
'_package.json': string;
|
|
30
|
+
'_.eslintrc': string;
|
|
31
|
+
'_.eslintignore': string;
|
|
32
|
+
'_.npmignore': string;
|
|
33
|
+
'_.eslintrc.js': string;
|
|
34
|
+
'_jsconfig.json': string;
|
|
35
|
+
'_tsconfig.json': string;
|
|
36
|
+
'_tsconfig.base.json': string;
|
|
37
|
+
'_tsconfig.build.json': string;
|
|
38
|
+
};
|
|
39
|
+
ignore: string[];
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.commandsConfig = void 0;
|
|
4
|
+
exports.commandsConfig = {
|
|
5
|
+
sets: {
|
|
6
|
+
core: '@cabloy/cli-set-core',
|
|
7
|
+
api: '@cabloy/cli-set-api',
|
|
8
|
+
front: '@cabloy/cli-set-front',
|
|
9
|
+
},
|
|
10
|
+
helper: {
|
|
11
|
+
chalk: {
|
|
12
|
+
options: { level: 2 },
|
|
13
|
+
},
|
|
14
|
+
boxen: {
|
|
15
|
+
options: { padding: 1, margin: 1, align: 'center', borderColor: 'yellow', borderStyle: 'round' },
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
template: {
|
|
19
|
+
render: {
|
|
20
|
+
fileMapping: {
|
|
21
|
+
gitignore: '.gitignore',
|
|
22
|
+
_gitignore: '.gitignore',
|
|
23
|
+
'_.gitignore': '.gitignore',
|
|
24
|
+
'_package.json': 'package.json',
|
|
25
|
+
'_.eslintrc': '.eslintrc',
|
|
26
|
+
'_.eslintignore': '.eslintignore',
|
|
27
|
+
'_.npmignore': '.npmignore',
|
|
28
|
+
'_.eslintrc.js': '.eslintrc.js',
|
|
29
|
+
'_jsconfig.json': 'jsconfig.json',
|
|
30
|
+
'_tsconfig.json': 'tsconfig.json',
|
|
31
|
+
'_tsconfig.base.json': 'tsconfig.base.json',
|
|
32
|
+
'_tsconfig.build.json': 'tsconfig.build.json',
|
|
33
|
+
},
|
|
34
|
+
ignore: ['.DS_Store'],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=config.js.map
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types/index.js"), exports);
|
|
18
|
+
__exportStar(require("./start.js"), exports);
|
|
19
|
+
__exportStar(require("./lib/index.js"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { glob } from '@cabloy/module-glob';
|
|
2
|
+
import { LocalConsole } from './local.console.js';
|
|
3
|
+
import { LocalHelper } from './local.helper.js';
|
|
4
|
+
import { LocalTemplate } from './local.template.js';
|
|
5
|
+
import { CmdOptions } from '../types/argv.js';
|
|
6
|
+
import { TypeProjectMode } from '@cabloy/module-info';
|
|
7
|
+
export declare class BeanCliBase {
|
|
8
|
+
options: CmdOptions;
|
|
9
|
+
terminal: any;
|
|
10
|
+
__console: LocalConsole;
|
|
11
|
+
__helper: LocalHelper;
|
|
12
|
+
__template: LocalTemplate;
|
|
13
|
+
modulesMeta: Awaited<ReturnType<typeof glob>>;
|
|
14
|
+
constructor(options: CmdOptions);
|
|
15
|
+
get console(): LocalConsole;
|
|
16
|
+
get helper(): LocalHelper;
|
|
17
|
+
get template(): LocalTemplate;
|
|
18
|
+
get context(): import("../types/argv.js").ICommandContext;
|
|
19
|
+
get cliFullName(): string;
|
|
20
|
+
meta(): Promise<any>;
|
|
21
|
+
execute(): Promise<any>;
|
|
22
|
+
_loadModulesMeta(projectMode?: TypeProjectMode): Promise<void>;
|
|
23
|
+
_commandMeta(): any;
|
|
24
|
+
_commandMeta_groups({ groups }: any): any;
|
|
25
|
+
_commandMeta_group({ group }: any): {
|
|
26
|
+
description: any;
|
|
27
|
+
condition: any;
|
|
28
|
+
questions: {};
|
|
29
|
+
};
|
|
30
|
+
_commandMeta_options({ options }: any): any;
|
|
31
|
+
_commandMeta_info({ info, argv }: any): any;
|
|
32
|
+
_commandMeta_info_welcomes({ info }: any): any;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=bean.cli.base.d.ts.map
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BeanCliBase = void 0;
|
|
4
|
+
const module_glob_1 = require("@cabloy/module-glob");
|
|
5
|
+
const local_console_js_1 = require("./local.console.js");
|
|
6
|
+
const local_helper_js_1 = require("./local.helper.js");
|
|
7
|
+
const local_template_js_1 = require("./local.template.js");
|
|
8
|
+
class BeanCliBase {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.options = options;
|
|
11
|
+
this.terminal = options.terminal !== false;
|
|
12
|
+
}
|
|
13
|
+
get console() {
|
|
14
|
+
if (!this.__console) {
|
|
15
|
+
this.__console = new local_console_js_1.LocalConsole(this);
|
|
16
|
+
}
|
|
17
|
+
return this.__console;
|
|
18
|
+
}
|
|
19
|
+
get helper() {
|
|
20
|
+
if (!this.__helper) {
|
|
21
|
+
this.__helper = new local_helper_js_1.LocalHelper(this);
|
|
22
|
+
}
|
|
23
|
+
return this.__helper;
|
|
24
|
+
}
|
|
25
|
+
get template() {
|
|
26
|
+
if (!this.__template) {
|
|
27
|
+
this.__template = new local_template_js_1.LocalTemplate(this);
|
|
28
|
+
}
|
|
29
|
+
return this.__template;
|
|
30
|
+
}
|
|
31
|
+
get context() {
|
|
32
|
+
return this.options.context;
|
|
33
|
+
}
|
|
34
|
+
get cliFullName() {
|
|
35
|
+
return this.options.context.argv.cliFullName;
|
|
36
|
+
}
|
|
37
|
+
async meta() {
|
|
38
|
+
await this._loadModulesMeta();
|
|
39
|
+
const metaLocale = this._commandMeta();
|
|
40
|
+
return metaLocale;
|
|
41
|
+
}
|
|
42
|
+
async execute() {
|
|
43
|
+
await this._loadModulesMeta();
|
|
44
|
+
}
|
|
45
|
+
async _loadModulesMeta(projectMode) {
|
|
46
|
+
//
|
|
47
|
+
if (this.modulesMeta)
|
|
48
|
+
return;
|
|
49
|
+
//
|
|
50
|
+
if (!projectMode) {
|
|
51
|
+
if (this.cliFullName.indexOf('api:') === 0) {
|
|
52
|
+
projectMode = 'api';
|
|
53
|
+
}
|
|
54
|
+
else if (this.cliFullName.indexOf('front:') === 0) {
|
|
55
|
+
projectMode = 'front';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (!projectMode)
|
|
59
|
+
return;
|
|
60
|
+
// all modules
|
|
61
|
+
this.modulesMeta = await (0, module_glob_1.glob)({
|
|
62
|
+
projectPath: this.context.argv.projectPath,
|
|
63
|
+
disabledModules: undefined,
|
|
64
|
+
disabledSuites: undefined,
|
|
65
|
+
log: false,
|
|
66
|
+
projectMode,
|
|
67
|
+
loadPackage: false,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
_commandMeta() {
|
|
71
|
+
const { command } = this.options;
|
|
72
|
+
const { argv } = this.context;
|
|
73
|
+
const meta = {};
|
|
74
|
+
meta.info = this._commandMeta_info({ info: command.info, argv });
|
|
75
|
+
meta.options = this._commandMeta_options({ options: command.options, argv });
|
|
76
|
+
meta.groups = this._commandMeta_groups({ groups: command.groups, argv });
|
|
77
|
+
return meta;
|
|
78
|
+
}
|
|
79
|
+
_commandMeta_groups({ groups }) {
|
|
80
|
+
const metaGroups = {};
|
|
81
|
+
if (groups) {
|
|
82
|
+
for (const groupName in groups) {
|
|
83
|
+
const group = groups[groupName];
|
|
84
|
+
metaGroups[groupName] = this._commandMeta_group({ group });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return metaGroups;
|
|
88
|
+
}
|
|
89
|
+
_commandMeta_group({ group }) {
|
|
90
|
+
const metaGroup = {
|
|
91
|
+
description: group.description,
|
|
92
|
+
condition: group.condition,
|
|
93
|
+
questions: {},
|
|
94
|
+
};
|
|
95
|
+
for (const key in group.questions) {
|
|
96
|
+
const question = group.questions[key];
|
|
97
|
+
metaGroup.questions[key] = {
|
|
98
|
+
...question,
|
|
99
|
+
message: question.message,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return metaGroup;
|
|
103
|
+
}
|
|
104
|
+
_commandMeta_options({ options }) {
|
|
105
|
+
const metaOptions = {};
|
|
106
|
+
if (options) {
|
|
107
|
+
for (const key in options) {
|
|
108
|
+
const option = options[key];
|
|
109
|
+
metaOptions[key] = {
|
|
110
|
+
...option,
|
|
111
|
+
description: option.description,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return metaOptions;
|
|
116
|
+
}
|
|
117
|
+
_commandMeta_info({ info, argv }) {
|
|
118
|
+
// info
|
|
119
|
+
const metaInfo = {
|
|
120
|
+
version: info.version,
|
|
121
|
+
title: info.title,
|
|
122
|
+
usage: info.usage,
|
|
123
|
+
};
|
|
124
|
+
// usage
|
|
125
|
+
if (!metaInfo.usage) {
|
|
126
|
+
metaInfo.usage = `${'Usage'}: npm run cli ${argv.cliFullName} -- [options] [-h] [-v] [-t]`;
|
|
127
|
+
}
|
|
128
|
+
// welcomes
|
|
129
|
+
metaInfo.welcomes = this._commandMeta_info_welcomes({ info });
|
|
130
|
+
// ok
|
|
131
|
+
return metaInfo;
|
|
132
|
+
}
|
|
133
|
+
_commandMeta_info_welcomes({ info }) {
|
|
134
|
+
let welcomes = info.welcomes || [];
|
|
135
|
+
if (!Array.isArray(welcomes))
|
|
136
|
+
welcomes = [welcomes];
|
|
137
|
+
welcomes = welcomes.map(item => item);
|
|
138
|
+
return welcomes;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.BeanCliBase = BeanCliBase;
|
|
142
|
+
//# sourceMappingURL=bean.cli.base.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ICommandContext } from '../types/argv.js';
|
|
2
|
+
export declare class BeanCli {
|
|
3
|
+
meta({ context }: {
|
|
4
|
+
context: ICommandContext;
|
|
5
|
+
}): Promise<any>;
|
|
6
|
+
execute({ context }: {
|
|
7
|
+
context: ICommandContext;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
_findCliCommand({ cliFullName }: {
|
|
10
|
+
cliFullName: string;
|
|
11
|
+
}): {
|
|
12
|
+
command: any;
|
|
13
|
+
BeanClass: any;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=bean.cli.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BeanCli = void 0;
|
|
4
|
+
const commands_js_1 = require("./commands.js");
|
|
5
|
+
class BeanCli {
|
|
6
|
+
async meta({ context }) {
|
|
7
|
+
// command
|
|
8
|
+
const { argv } = context;
|
|
9
|
+
const cliFullName = argv.cliFullName;
|
|
10
|
+
const { command, BeanClass } = await this._findCliCommand({ cliFullName });
|
|
11
|
+
// command bean
|
|
12
|
+
const beanCommand = new BeanClass({ command, context, terminal: false });
|
|
13
|
+
if (!beanCommand)
|
|
14
|
+
throw new Error(`cli command bean not found: ${command.beanFullName}`);
|
|
15
|
+
// meta
|
|
16
|
+
return await beanCommand.meta();
|
|
17
|
+
}
|
|
18
|
+
async execute({ context }) {
|
|
19
|
+
// command
|
|
20
|
+
const { argv } = context;
|
|
21
|
+
const cliFullName = argv.cliFullName;
|
|
22
|
+
const { command, BeanClass } = await this._findCliCommand({ cliFullName });
|
|
23
|
+
// command bean
|
|
24
|
+
const beanCommand = new BeanClass({ command, context, terminal: false });
|
|
25
|
+
if (!beanCommand)
|
|
26
|
+
throw new Error(`cli command bean not found: ${command.beanFullName}`);
|
|
27
|
+
// execute
|
|
28
|
+
await beanCommand.execute();
|
|
29
|
+
}
|
|
30
|
+
_findCliCommand({ cliFullName }) {
|
|
31
|
+
const { command, BeanClass } = (0, commands_js_1.findCommand)(cliFullName);
|
|
32
|
+
if (!command)
|
|
33
|
+
throw new Error(`cli command not found: ${cliFullName}`);
|
|
34
|
+
return { command, BeanClass };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.BeanCli = BeanCli;
|
|
38
|
+
//# sourceMappingURL=bean.cli.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export class CliCommand extends BaseCommand {
|
|
2
|
+
constructor(rawArgv: any, { meta, argv }: {
|
|
3
|
+
meta: any;
|
|
4
|
+
argv: any;
|
|
5
|
+
});
|
|
6
|
+
usage: any;
|
|
7
|
+
version: any;
|
|
8
|
+
options: any;
|
|
9
|
+
__meta: any;
|
|
10
|
+
__groups: any;
|
|
11
|
+
__argv: any;
|
|
12
|
+
__cabloyConfig: any;
|
|
13
|
+
cabloyConfig: any;
|
|
14
|
+
run({ argv, cwd, env, rawArgv }: {
|
|
15
|
+
argv: any;
|
|
16
|
+
cwd: any;
|
|
17
|
+
env: any;
|
|
18
|
+
rawArgv: any;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
_getMetaWelcomes(): any;
|
|
21
|
+
_logMetaWelcomes(): void;
|
|
22
|
+
_logCliDocs(): void;
|
|
23
|
+
_adjustEnv({ env }: {
|
|
24
|
+
env: any;
|
|
25
|
+
}): {};
|
|
26
|
+
_promptGroups({ context, groups }: {
|
|
27
|
+
context: any;
|
|
28
|
+
groups: any;
|
|
29
|
+
}): Promise<void>;
|
|
30
|
+
_promptGroup({ group, context }: {
|
|
31
|
+
group: any;
|
|
32
|
+
context: any;
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
_prepareQuestionPropertyExpression({ group, question, key, context, propName }: {
|
|
35
|
+
group: any;
|
|
36
|
+
question: any;
|
|
37
|
+
key: any;
|
|
38
|
+
context: any;
|
|
39
|
+
propName: any;
|
|
40
|
+
}): ((value: any) => any) | null;
|
|
41
|
+
_prepareQuestion({ group, question, key, context }: {
|
|
42
|
+
group: any;
|
|
43
|
+
question: any;
|
|
44
|
+
key: any;
|
|
45
|
+
context: any;
|
|
46
|
+
}): any;
|
|
47
|
+
_checkGroupCondition({ group, context }: {
|
|
48
|
+
group: any;
|
|
49
|
+
context: any;
|
|
50
|
+
}): any;
|
|
51
|
+
}
|
|
52
|
+
import BaseCommand from '@zhennann/common-bin';
|
|
53
|
+
//# sourceMappingURL=cli.d.ts.map
|
package/dist/lib/cli.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CliCommand = void 0;
|
|
7
|
+
const is_type_of_1 = __importDefault(require("is-type-of"));
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const enquirer_1 = __importDefault(require("enquirer"));
|
|
10
|
+
const egg_born_utils_1 = __importDefault(require("egg-born-utils"));
|
|
11
|
+
const common_bin_1 = __importDefault(require("@zhennann/common-bin"));
|
|
12
|
+
const bean_cli_js_1 = require("./bean.cli.js");
|
|
13
|
+
const __envFields = ['TERM', 'TERM_PROGRAM', 'TERM_PROGRAM_VERSION', 'SHELL', 'COLOR', 'LANG', 'npm_config_registry'];
|
|
14
|
+
const __comment_seperator = '====================================================================';
|
|
15
|
+
class CliCommand extends common_bin_1.default {
|
|
16
|
+
constructor(rawArgv, { meta, argv }) {
|
|
17
|
+
super(rawArgv);
|
|
18
|
+
this.usage = meta.info.usage;
|
|
19
|
+
this.version = meta.info.version;
|
|
20
|
+
this.options = meta.options;
|
|
21
|
+
this.__meta = meta;
|
|
22
|
+
this.__groups = meta.groups;
|
|
23
|
+
this.__argv = argv;
|
|
24
|
+
this.__cabloyConfig = null;
|
|
25
|
+
this.cabloyConfig = null;
|
|
26
|
+
}
|
|
27
|
+
async run({ argv, cwd, env, rawArgv }) {
|
|
28
|
+
// argv
|
|
29
|
+
argv = Object.assign({}, argv, this.__argv);
|
|
30
|
+
delete argv.t;
|
|
31
|
+
delete argv.token;
|
|
32
|
+
delete argv.$0;
|
|
33
|
+
// context
|
|
34
|
+
const context = { argv, cwd, env: this._adjustEnv({ env }), rawArgv };
|
|
35
|
+
// log start
|
|
36
|
+
console.log(`cabloy ${chalk_1.default.cyan(argv.cliFullName)} at %s\n`, cwd);
|
|
37
|
+
// log meta welcomes
|
|
38
|
+
this._logMetaWelcomes();
|
|
39
|
+
// prompt
|
|
40
|
+
await this._promptGroups({ context, groups: this.__groups });
|
|
41
|
+
// execute
|
|
42
|
+
const beanCli = new bean_cli_js_1.BeanCli();
|
|
43
|
+
await beanCli.execute({ context });
|
|
44
|
+
// done: log cli docs
|
|
45
|
+
this._logCliDocs();
|
|
46
|
+
// done
|
|
47
|
+
console.log(chalk_1.default.cyan('\n cli successfully!\n'));
|
|
48
|
+
}
|
|
49
|
+
_getMetaWelcomes() {
|
|
50
|
+
let welcomes = this.__meta.info.welcomes;
|
|
51
|
+
if (!welcomes)
|
|
52
|
+
return null;
|
|
53
|
+
if (!Array.isArray(welcomes))
|
|
54
|
+
welcomes = [welcomes];
|
|
55
|
+
if (welcomes.length === 0)
|
|
56
|
+
return null;
|
|
57
|
+
return welcomes;
|
|
58
|
+
}
|
|
59
|
+
_logMetaWelcomes() {
|
|
60
|
+
const welcomes = this._getMetaWelcomes();
|
|
61
|
+
if (!welcomes)
|
|
62
|
+
return;
|
|
63
|
+
console.log(__comment_seperator);
|
|
64
|
+
for (const welcome of welcomes) {
|
|
65
|
+
console.log(welcome);
|
|
66
|
+
}
|
|
67
|
+
console.log(__comment_seperator);
|
|
68
|
+
console.log('');
|
|
69
|
+
}
|
|
70
|
+
_logCliDocs() {
|
|
71
|
+
const welcomes = this._getMetaWelcomes();
|
|
72
|
+
if (!welcomes)
|
|
73
|
+
return;
|
|
74
|
+
const welcome = welcomes[0];
|
|
75
|
+
if (!welcome || welcome.indexOf('articles/cli-introduce.html') === -1)
|
|
76
|
+
return;
|
|
77
|
+
console.log('');
|
|
78
|
+
console.log(__comment_seperator);
|
|
79
|
+
console.log(welcome);
|
|
80
|
+
console.log(__comment_seperator);
|
|
81
|
+
}
|
|
82
|
+
_adjustEnv({ env }) {
|
|
83
|
+
const res = {};
|
|
84
|
+
for (const field of __envFields) {
|
|
85
|
+
if (env[field])
|
|
86
|
+
res[field] = env[field];
|
|
87
|
+
}
|
|
88
|
+
return res;
|
|
89
|
+
}
|
|
90
|
+
async _promptGroups({ context, groups }) {
|
|
91
|
+
for (const groupName in groups) {
|
|
92
|
+
const group = groups[groupName];
|
|
93
|
+
await this._promptGroup({ group, context });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async _promptGroup({ group, context }) {
|
|
97
|
+
const { argv } = context;
|
|
98
|
+
// check
|
|
99
|
+
const check = this._checkGroupCondition({ group, context });
|
|
100
|
+
if (!check)
|
|
101
|
+
return;
|
|
102
|
+
// prepare
|
|
103
|
+
const varsWant = [];
|
|
104
|
+
for (const key in group.questions) {
|
|
105
|
+
const value = argv[key];
|
|
106
|
+
if (value !== undefined)
|
|
107
|
+
continue;
|
|
108
|
+
const question = group.questions[key];
|
|
109
|
+
const varWant = this._prepareQuestion({ group, question, key, context });
|
|
110
|
+
if (varWant) {
|
|
111
|
+
varsWant.push(varWant);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (varsWant.length === 0)
|
|
115
|
+
return;
|
|
116
|
+
// log description
|
|
117
|
+
if (group.description) {
|
|
118
|
+
console.log('===>', group.description);
|
|
119
|
+
}
|
|
120
|
+
// prompt
|
|
121
|
+
await enquirer_1.default.prompt(varsWant);
|
|
122
|
+
}
|
|
123
|
+
_prepareQuestionPropertyExpression({ group, question, key, context, propName }) {
|
|
124
|
+
// expression
|
|
125
|
+
const expression = question[propName] && question[propName].expression;
|
|
126
|
+
if (!expression)
|
|
127
|
+
return null;
|
|
128
|
+
return function (value) {
|
|
129
|
+
return egg_born_utils_1.default.tools.evaluateExpression({ expression, scope: { value, group, question, key, context } });
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
_prepareQuestion({ group, question, key, context }) {
|
|
133
|
+
const { argv } = context;
|
|
134
|
+
// want
|
|
135
|
+
const varWant = {
|
|
136
|
+
name: key,
|
|
137
|
+
...question,
|
|
138
|
+
};
|
|
139
|
+
// message/skip/initial/format/validate
|
|
140
|
+
for (const propName of ['message', 'skip', 'initial', 'format', 'validate']) {
|
|
141
|
+
const propFunction = this._prepareQuestionPropertyExpression({ group, question, key, context, propName });
|
|
142
|
+
if (propFunction) {
|
|
143
|
+
varWant[propName] = propFunction;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// result
|
|
147
|
+
varWant.result = value => {
|
|
148
|
+
const propFunction = this._prepareQuestionPropertyExpression({
|
|
149
|
+
group,
|
|
150
|
+
question,
|
|
151
|
+
key,
|
|
152
|
+
context,
|
|
153
|
+
propName: 'result',
|
|
154
|
+
});
|
|
155
|
+
if (propFunction) {
|
|
156
|
+
value = propFunction(value);
|
|
157
|
+
}
|
|
158
|
+
argv[key] = value;
|
|
159
|
+
return value;
|
|
160
|
+
};
|
|
161
|
+
// required
|
|
162
|
+
if (question.required) {
|
|
163
|
+
varWant.validate = value => {
|
|
164
|
+
if (!value)
|
|
165
|
+
return 'Required';
|
|
166
|
+
return true;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
// silent
|
|
170
|
+
if (question.silent) {
|
|
171
|
+
let initial = varWant.initial;
|
|
172
|
+
if (is_type_of_1.default.function(initial)) {
|
|
173
|
+
initial = initial();
|
|
174
|
+
}
|
|
175
|
+
argv[key] = initial;
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
// ok
|
|
179
|
+
return varWant;
|
|
180
|
+
}
|
|
181
|
+
_checkGroupCondition({ group, context }) {
|
|
182
|
+
const expression = group.condition && group.condition.expression;
|
|
183
|
+
if (!expression)
|
|
184
|
+
return true;
|
|
185
|
+
return egg_born_utils_1.default.tools.evaluateExpression({ expression, scope: { group, context } });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
exports.CliCommand = CliCommand;
|
|
189
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findCommand = exports.commandsMeta = void 0;
|
|
4
|
+
const config_js_1 = require("../config.js");
|
|
5
|
+
let __commandsMap;
|
|
6
|
+
let __commandsAll;
|
|
7
|
+
function _collectCommands() {
|
|
8
|
+
const _commandsMap = {};
|
|
9
|
+
const _commandsAll = {};
|
|
10
|
+
const sets = config_js_1.commandsConfig.sets;
|
|
11
|
+
for (const setName in sets) {
|
|
12
|
+
const setModuleName = sets[setName];
|
|
13
|
+
const setModule = require(setModuleName);
|
|
14
|
+
const commands = setModule.commands;
|
|
15
|
+
if (!commands)
|
|
16
|
+
continue;
|
|
17
|
+
const _commandsSet = (_commandsAll[setName] = {});
|
|
18
|
+
for (const groupName in commands) {
|
|
19
|
+
const group = commands[groupName];
|
|
20
|
+
const _commandsGroup = (_commandsSet[groupName] = {});
|
|
21
|
+
for (const key in group) {
|
|
22
|
+
const command = group[key];
|
|
23
|
+
const fullKey = `${setName}:${groupName}:${key}`;
|
|
24
|
+
// command BeanClass
|
|
25
|
+
const BeanClass = setModule.beans[command.bean];
|
|
26
|
+
// ok
|
|
27
|
+
_commandsMap[fullKey] = _commandsGroup[key] = { command, BeanClass };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// ok
|
|
32
|
+
__commandsMap = _commandsMap;
|
|
33
|
+
__commandsAll = _commandsAll;
|
|
34
|
+
}
|
|
35
|
+
_collectCommands();
|
|
36
|
+
exports.commandsMeta = { commandsMap: __commandsMap, commandsAll: __commandsAll };
|
|
37
|
+
function findCommand(cliFullName) {
|
|
38
|
+
return __commandsMap[cliFullName];
|
|
39
|
+
}
|
|
40
|
+
exports.findCommand = findCommand;
|
|
41
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./bean.cli.base.js"), exports);
|
|
18
|
+
__exportStar(require("./commands.js"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|