@cabloy/cli 3.0.67 → 3.0.69

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.
@@ -1,10 +1,12 @@
1
1
  import type { IModulePackage } from '@cabloy/module-info';
2
+ import type { Stats } from 'fs-extra';
2
3
  import type { BeanCliBase } from './bean.cli.base.ts';
3
4
  type TypeDeps = Record<string, string>;
4
5
  export declare class LocalCommon {
5
6
  cli: BeanCliBase;
6
7
  constructor(cli: any);
7
8
  _generateTypeModulesFile(projectPath: string): Promise<void>;
9
+ _generateTypeModulesFileInner(typeFile: string, typeFileStat: Stats, moduleTypeFile: string): Promise<void>;
8
10
  _generatePackageJson(projectPath: string): Promise<void>;
9
11
  _generatePackageJson_prepareDeps(_projectPath: string): Promise<{
10
12
  deps: TypeDeps;
@@ -36,6 +36,7 @@ export type TypeParseResult<LANGUAGE extends TypeParseLanguage> = LANGUAGE exten
36
36
  export type TypeParseOptions<LANGUAGE extends TypeParseLanguage> = LANGUAGE extends 'plain' ? never : LANGUAGE extends 'json' ? never : ParserOptions;
37
37
  export interface ISnippet<LANGUAGE extends TypeParseLanguage = ''> {
38
38
  language: LANGUAGE;
39
+ format?: boolean;
39
40
  file: string | ((ejsData: IEjsData) => string);
40
41
  init?: string | ((initData: IInitData) => Promise<string>);
41
42
  parseOptions?: TypeParseOptions<LANGUAGE>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cabloy/cli",
3
3
  "type": "module",
4
- "version": "3.0.67",
4
+ "version": "3.0.69",
5
5
  "description": "@cabloy/cli",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -27,10 +27,10 @@
27
27
  ],
28
28
  "dependencies": {
29
29
  "@babel/parser": "^7.26.5",
30
- "@cabloy/module-glob": "^5.2.34",
31
- "@cabloy/module-info": "^1.3.31",
32
- "@cabloy/process-helper": "^2.0.21",
33
- "@cabloy/utils": "^1.0.48",
30
+ "@cabloy/module-glob": "^5.2.35",
31
+ "@cabloy/module-info": "^1.3.32",
32
+ "@cabloy/process-helper": "^2.0.22",
33
+ "@cabloy/utils": "^1.0.49",
34
34
  "@cabloy/word-utils": "^2.0.1",
35
35
  "@npmcli/config": "^10.4.2",
36
36
  "@zhennann/common-bin": "^4.0.0",
@@ -50,8 +50,7 @@
50
50
  },
51
51
  "gitHead": "0eab9dc4a5622caffe89e7b1b3f02c08ccbc4c4b",
52
52
  "scripts": {
53
- "lint": "eslint .",
54
53
  "clean": "rimraf dist tsconfig.tsbuildinfo",
55
- "tsc:publish": "npm run clean && tsc"
54
+ "tsc:publish": "npm run clean && vona :bin:buildGeneral && tsc"
56
55
  }
57
56
  }
package/dist/config.js DELETED
@@ -1,38 +0,0 @@
1
- export const commandsConfig = {
2
- sets: {
3
- zova: {
4
- front: 'zova-cli-set-front',
5
- },
6
- vona: {
7
- api: 'vona-cli-set-api',
8
- },
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
- '_.npmrc': '.npmrc',
29
- '_.eslintrc.js': '.eslintrc.js',
30
- '_jsconfig.json': 'jsconfig.json',
31
- '_tsconfig.json': 'tsconfig.json',
32
- '_tsconfig.base.json': 'tsconfig.base.json',
33
- '_tsconfig.build.json': 'tsconfig.build.json',
34
- },
35
- ignore: ['.DS_Store'],
36
- },
37
- },
38
- };
@@ -1,144 +0,0 @@
1
- import { glob } from '@cabloy/module-glob';
2
- import { patchFlavor } from "../utils.js";
3
- import { LocalCommon } from "./local.common.js";
4
- import { LocalConsole } from "./local.console.js";
5
- import { LocalHelper } from "./local.helper.js";
6
- import { LocalTemplate } from "./local.template.js";
7
- export class BeanCliBase {
8
- options;
9
- terminal;
10
- __console;
11
- __helper;
12
- __template;
13
- __common;
14
- modulesMeta;
15
- constructor(options) {
16
- this.options = options;
17
- this.terminal = options.terminal !== false;
18
- }
19
- get console() {
20
- if (!this.__console) {
21
- this.__console = new LocalConsole(this);
22
- }
23
- return this.__console;
24
- }
25
- get helper() {
26
- if (!this.__helper) {
27
- this.__helper = new LocalHelper(this);
28
- }
29
- return this.__helper;
30
- }
31
- get template() {
32
- if (!this.__template) {
33
- this.__template = new LocalTemplate(this);
34
- }
35
- return this.__template;
36
- }
37
- get common() {
38
- if (!this.__common) {
39
- this.__common = new LocalCommon(this);
40
- }
41
- return this.__common;
42
- }
43
- get context() {
44
- return this.options.context;
45
- }
46
- get cliFullName() {
47
- return this.options.context.argv.cliFullName;
48
- }
49
- async meta() {
50
- await this._loadModulesMeta();
51
- const metaLocale = this._commandMeta();
52
- return metaLocale;
53
- }
54
- async execute() {
55
- const { argv } = this.context;
56
- if (argv.flavor) {
57
- argv.flavor = patchFlavor(argv.flavor);
58
- }
59
- await this._loadModulesMeta();
60
- }
61
- async _loadModulesMeta() {
62
- //
63
- if (this.modulesMeta)
64
- return;
65
- // all modules
66
- this.modulesMeta = await glob({
67
- projectPath: this.context.argv.projectPath,
68
- disabledModules: undefined,
69
- disabledSuites: undefined,
70
- log: false,
71
- projectMode: process.env.CabloyCliBrandName,
72
- });
73
- }
74
- _commandMeta() {
75
- const { command } = this.options;
76
- const { argv } = this.context;
77
- const meta = {};
78
- meta.info = this._commandMeta_info({ info: command.info, argv });
79
- meta.options = this._commandMeta_options({ options: command.options, argv });
80
- meta.groups = this._commandMeta_groups({ groups: command.groups, argv });
81
- return meta;
82
- }
83
- _commandMeta_groups({ groups }) {
84
- const metaGroups = {};
85
- if (groups) {
86
- for (const groupName in groups) {
87
- const group = groups[groupName];
88
- metaGroups[groupName] = this._commandMeta_group({ group });
89
- }
90
- }
91
- return metaGroups;
92
- }
93
- _commandMeta_group({ group }) {
94
- const metaGroup = {
95
- description: group.description,
96
- condition: group.condition,
97
- questions: {},
98
- };
99
- for (const key in group.questions) {
100
- const question = group.questions[key];
101
- metaGroup.questions[key] = {
102
- ...question,
103
- message: question.message,
104
- };
105
- }
106
- return metaGroup;
107
- }
108
- _commandMeta_options({ options }) {
109
- const metaOptions = {};
110
- if (options) {
111
- for (const key in options) {
112
- const option = options[key];
113
- metaOptions[key] = {
114
- ...option,
115
- description: option.description,
116
- };
117
- }
118
- }
119
- return metaOptions;
120
- }
121
- _commandMeta_info({ info, argv }) {
122
- // info
123
- const metaInfo = {
124
- version: info.version,
125
- title: info.title,
126
- usage: info.usage,
127
- };
128
- // usage
129
- if (!metaInfo.usage) {
130
- metaInfo.usage = `${'Usage'}: ${process.env.CabloyCliBrandName} ${argv.cliFullName} [options] [-h] [-v]`;
131
- }
132
- // welcomes
133
- metaInfo.welcomes = this._commandMeta_info_welcomes({ info });
134
- // ok
135
- return metaInfo;
136
- }
137
- _commandMeta_info_welcomes({ info }) {
138
- let welcomes = info.welcomes || [];
139
- if (!Array.isArray(welcomes))
140
- welcomes = [welcomes];
141
- welcomes = welcomes.map(item => item);
142
- return welcomes;
143
- }
144
- }
@@ -1,33 +0,0 @@
1
- import { findCommand } from "./commands.js";
2
- export class BeanCli {
3
- async meta({ context }) {
4
- // command
5
- const { argv } = context;
6
- const cliFullName = argv.cliFullName;
7
- const { command, BeanClass } = await this._findCliCommand({ cliFullName });
8
- // command bean
9
- const beanCommand = new BeanClass({ command, context, terminal: false });
10
- if (!beanCommand)
11
- throw new Error(`cli command bean not found: ${command.beanFullName}`);
12
- // meta
13
- return await beanCommand.meta();
14
- }
15
- async execute({ context }) {
16
- // command
17
- const { argv } = context;
18
- const cliFullName = argv.cliFullName;
19
- const { command, BeanClass } = await this._findCliCommand({ cliFullName });
20
- // command bean
21
- const beanCommand = new BeanClass({ command, context, terminal: false });
22
- if (!beanCommand)
23
- throw new Error(`cli command bean not found: ${command.beanFullName}`);
24
- // execute
25
- await beanCommand.execute();
26
- }
27
- _findCliCommand({ cliFullName }) {
28
- const commandInfo = findCommand(cliFullName);
29
- if (!commandInfo || !commandInfo.command)
30
- throw new Error(`cli command not found: ${cliFullName}`);
31
- return commandInfo;
32
- }
33
- }
package/dist/lib/cli.js DELETED
@@ -1,217 +0,0 @@
1
- import { evaluate } from '@cabloy/utils';
2
- import BaseCommand from '@zhennann/common-bin';
3
- import chalk from 'chalk';
4
- import enquirer from 'enquirer';
5
- import is from 'is-type-of';
6
- import { BeanCli } from "./bean.cli.js";
7
- const __envFields = ['TERM', 'TERM_PROGRAM', 'TERM_PROGRAM_VERSION', 'SHELL', 'COLOR', 'LANG', 'npm_config_registry'];
8
- const __comment_seperator = '====================================================================';
9
- export class CliCommand extends BaseCommand {
10
- __meta;
11
- __groups;
12
- __argv;
13
- constructor(rawArgv, { meta, argv }) {
14
- super(rawArgv);
15
- this.usage = meta.info.usage; // readonly
16
- this.options = meta.options; // readonly
17
- this.version = meta.info.version;
18
- this.__meta = meta;
19
- this.__groups = meta.groups;
20
- this.__argv = argv;
21
- }
22
- async run(options) {
23
- let { argv, cwd, env, rawArgv } = options;
24
- // argv
25
- argv = this._prepareArgv(argv);
26
- // context
27
- const context = {
28
- brandName: process.env.CabloyCliBrandName,
29
- argv,
30
- cwd,
31
- env: this._adjustEnv({ env }),
32
- rawArgv,
33
- };
34
- // log start
35
- if (!argv.dummy) {
36
- // eslint-disable-next-line no-console
37
- console.log(`${process.env.CabloyCliBrandName} ${chalk.cyan(argv.cliFullName)} at %s\n`, cwd);
38
- }
39
- // log meta welcomes
40
- if (!argv.dummy) {
41
- this._logMetaWelcomes();
42
- }
43
- // prompt
44
- await this._promptGroups({ context, groups: this.__groups });
45
- // execute
46
- const beanCli = new BeanCli();
47
- await beanCli.execute({ context });
48
- // done: log cli docs
49
- if (!argv.dummy) {
50
- this._logCliDocs();
51
- }
52
- // done
53
- // console.log(chalk.cyan('\n cli successfully!\n'));
54
- }
55
- _getMetaWelcomes() {
56
- let welcomes = this.__meta.info.welcomes;
57
- if (!welcomes)
58
- return null;
59
- if (!Array.isArray(welcomes))
60
- welcomes = [welcomes];
61
- if (welcomes.length === 0)
62
- return null;
63
- return welcomes;
64
- }
65
- _logMetaWelcomes() {
66
- const welcomes = this._getMetaWelcomes();
67
- if (!welcomes)
68
- return;
69
- // eslint-disable-next-line no-console
70
- console.log(__comment_seperator);
71
- for (const welcome of welcomes) {
72
- // eslint-disable-next-line no-console
73
- console.log(welcome);
74
- }
75
- // eslint-disable-next-line no-console
76
- console.log(__comment_seperator);
77
- // eslint-disable-next-line no-console
78
- console.log('');
79
- }
80
- _logCliDocs() {
81
- const welcomes = this._getMetaWelcomes();
82
- if (!welcomes)
83
- return;
84
- const welcome = welcomes[0];
85
- if (!welcome || !welcome.includes('articles/cli-introduce.html'))
86
- return;
87
- // eslint-disable-next-line no-console
88
- console.log('');
89
- // eslint-disable-next-line no-console
90
- console.log(__comment_seperator);
91
- // eslint-disable-next-line no-console
92
- console.log(welcome);
93
- // eslint-disable-next-line no-console
94
- console.log(__comment_seperator);
95
- }
96
- _adjustEnv({ env }) {
97
- const res = {};
98
- for (const field of __envFields) {
99
- if (env[field])
100
- res[field] = env[field];
101
- }
102
- return res;
103
- }
104
- async _promptGroups({ context, groups }) {
105
- for (const groupName in groups) {
106
- const group = groups[groupName];
107
- await this._promptGroup({ group, context });
108
- }
109
- }
110
- async _promptGroup({ group, context }) {
111
- const { argv } = context;
112
- // check
113
- const check = this._checkGroupCondition({ group, context });
114
- if (!check)
115
- return;
116
- // prepare
117
- const varsWant = [];
118
- for (const key in group.questions) {
119
- const value = argv[key];
120
- if (value !== undefined)
121
- continue;
122
- const question = group.questions[key];
123
- const varWant = this._prepareQuestion({ group, question, key, context });
124
- if (varWant) {
125
- varsWant.push(varWant);
126
- }
127
- }
128
- if (varsWant.length === 0)
129
- return;
130
- // log description
131
- if (group.description) {
132
- // eslint-disable-next-line no-console
133
- console.log('===>', group.description);
134
- }
135
- // prompt
136
- await enquirer.prompt(varsWant);
137
- }
138
- _prepareQuestionPropertyExpression({ group, question, key, context, propName }) {
139
- // expression
140
- const expression = question[propName] && question[propName].expression;
141
- if (!expression)
142
- return null;
143
- return function (value) {
144
- return evaluate(expression, { value, group, question, key, context });
145
- };
146
- }
147
- _prepareQuestion({ group, question, key, context }) {
148
- const { argv } = context;
149
- // want
150
- const varWant = {
151
- name: key,
152
- ...question,
153
- };
154
- // message/skip/initial/format/validate
155
- for (const propName of ['message', 'skip', 'initial', 'format', 'validate']) {
156
- const propFunction = this._prepareQuestionPropertyExpression({ group, question, key, context, propName });
157
- if (propFunction) {
158
- varWant[propName] = propFunction;
159
- }
160
- }
161
- // special check initial
162
- let initial = varWant.initial;
163
- if (initial && is.function(initial)) {
164
- initial = initial();
165
- if (initial !== undefined) {
166
- argv[key] = initial;
167
- return null;
168
- }
169
- }
170
- // result
171
- varWant.result = value => {
172
- const propFunction = this._prepareQuestionPropertyExpression({
173
- group,
174
- question,
175
- key,
176
- context,
177
- propName: 'result',
178
- });
179
- if (propFunction) {
180
- value = propFunction(value);
181
- }
182
- argv[key] = value;
183
- return value;
184
- };
185
- // required
186
- if (question.required) {
187
- varWant.validate = value => {
188
- if (!value)
189
- return 'Required';
190
- return true;
191
- };
192
- }
193
- // ok
194
- return varWant;
195
- }
196
- _checkGroupCondition({ group, context }) {
197
- const expression = group.condition && group.condition.expression;
198
- if (!expression)
199
- return true;
200
- return evaluate(expression, { group, context });
201
- }
202
- _prepareArgv(argv) {
203
- argv = Object.assign({}, argv, this.__argv);
204
- delete argv.$0;
205
- // alias
206
- const options = this.__meta.options;
207
- if (options) {
208
- for (const key in options) {
209
- const option = options[key];
210
- if (option.alias && argv[key] === undefined) {
211
- argv[key] = argv[option.alias];
212
- }
213
- }
214
- }
215
- return argv;
216
- }
217
- }
@@ -1,52 +0,0 @@
1
- var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
- if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
- return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
- return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
- });
6
- }
7
- return path;
8
- };
9
- import { commandsConfig } from "../config.js";
10
- let __commandsMeta;
11
- export async function getCommandsMeta() {
12
- await collectCommands();
13
- return __commandsMeta;
14
- }
15
- export function findCommand(cliFullName) {
16
- return __commandsMeta.map[cliFullName];
17
- }
18
- export async function collectCommands() {
19
- await _collectCommands();
20
- }
21
- async function _collectCommands() {
22
- if (__commandsMeta)
23
- return;
24
- const _commandsMap = {};
25
- const _commandsAll = {};
26
- const sets = commandsConfig.sets[process.env.CabloyCliBrandName];
27
- for (const setName in sets) {
28
- const setModuleName = sets[setName];
29
- const setModule = await import(__rewriteRelativeImportExtension(setModuleName)); // 270ms
30
- const commands = setModule.commands;
31
- if (!commands)
32
- continue;
33
- const _commandsSet = (_commandsAll[setName] = {});
34
- for (const groupName in commands) {
35
- const group = commands[groupName];
36
- const _commandsGroup = (_commandsSet[groupName] = {});
37
- for (const key in group) {
38
- const command = group[key];
39
- const fullKey = `${setName}:${groupName}:${key}`;
40
- // command BeanClass
41
- const BeanClass = setModule.beans[command.bean];
42
- // ok
43
- _commandsMap[fullKey] = _commandsGroup[key] = { command, BeanClass };
44
- }
45
- }
46
- }
47
- // ok
48
- __commandsMeta = {
49
- map: _commandsMap,
50
- all: _commandsAll,
51
- };
52
- }
package/dist/lib/index.js DELETED
@@ -1,7 +0,0 @@
1
- export * from "./bean.cli.base.js";
2
- export * from "./bean.cli.js";
3
- export * from "./cli.js";
4
- export * from "./commands.js";
5
- export * from "./local.console.js";
6
- export * from "./local.helper.js";
7
- export * from "./local.template.js";