@cabloy/cli 3.0.4 → 3.0.6
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/lib/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { evaluate } from '@cabloy/utils';
|
|
1
2
|
import BaseCommand from '@zhennann/common-bin';
|
|
2
3
|
import chalk from 'chalk';
|
|
3
|
-
import eggBornUtils from 'egg-born-utils';
|
|
4
4
|
import enquirer from 'enquirer';
|
|
5
5
|
import is from 'is-type-of';
|
|
6
6
|
import { BeanCli } from "./bean.cli.js";
|
|
@@ -136,7 +136,7 @@ export class CliCommand extends BaseCommand {
|
|
|
136
136
|
if (!expression)
|
|
137
137
|
return null;
|
|
138
138
|
return function (value) {
|
|
139
|
-
return
|
|
139
|
+
return evaluate(expression, { value, group, question, key, context });
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
142
|
_prepareQuestion({ group, question, key, context }) {
|
|
@@ -192,6 +192,6 @@ export class CliCommand extends BaseCommand {
|
|
|
192
192
|
const expression = group.condition && group.condition.expression;
|
|
193
193
|
if (!expression)
|
|
194
194
|
return true;
|
|
195
|
-
return
|
|
195
|
+
return evaluate(expression, { group, context });
|
|
196
196
|
}
|
|
197
197
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IProcessHelperSpawnOptions } from '@cabloy/process-helper';
|
|
1
2
|
import type { TableConstructorOptions } from 'cli-table3';
|
|
2
3
|
import type { NameMeta } from '../types/helper.ts';
|
|
3
4
|
import type { BeanCliBase } from './bean.cli.base.ts';
|
|
@@ -84,13 +85,25 @@ export declare class LocalHelper {
|
|
|
84
85
|
ensureDir(dir: any): Promise<any>;
|
|
85
86
|
pnpmInstall(): Promise<void>;
|
|
86
87
|
formatFile({ fileName, logPrefix }: any): Promise<void>;
|
|
87
|
-
spawnBin({ cmd, args, options }:
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
spawnBin({ cmd, args, options }: {
|
|
89
|
+
cmd: string;
|
|
90
|
+
args?: string[];
|
|
91
|
+
options?: IProcessHelperSpawnOptions;
|
|
92
|
+
}): Promise<string>;
|
|
93
|
+
spawnCmd({ cmd, args, options }: {
|
|
94
|
+
cmd: string;
|
|
95
|
+
args?: string[];
|
|
96
|
+
options?: IProcessHelperSpawnOptions;
|
|
97
|
+
}): Promise<string>;
|
|
98
|
+
spawnExe({ cmd, args, options }: {
|
|
99
|
+
cmd: string;
|
|
100
|
+
args?: string[];
|
|
101
|
+
options?: IProcessHelperSpawnOptions;
|
|
102
|
+
}): Promise<string>;
|
|
90
103
|
spawn({ cmd, args, options }: {
|
|
91
|
-
cmd:
|
|
92
|
-
args?:
|
|
93
|
-
options?:
|
|
104
|
+
cmd: string;
|
|
105
|
+
args?: string[];
|
|
106
|
+
options?: IProcessHelperSpawnOptions;
|
|
94
107
|
}): Promise<string>;
|
|
95
108
|
gitCommit({ cwd, message }: any): Promise<void>;
|
|
96
109
|
getRegistry(): Promise<string>;
|
|
@@ -105,6 +118,5 @@ export declare class LocalHelper {
|
|
|
105
118
|
requireDynamic(file: string): any;
|
|
106
119
|
private _requireDynamic_getFileTime;
|
|
107
120
|
tempFile<RESULT>(fn: (fileTemp: string) => Promise<RESULT>, options?: ITempFileOptions): Promise<RESULT>;
|
|
108
|
-
|
|
109
|
-
private _pathToHref;
|
|
121
|
+
pathToHref(fileName: string): string;
|
|
110
122
|
}
|
package/dist/lib/local.helper.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
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
|
+
};
|
|
1
9
|
import { createRequire } from 'node:module';
|
|
2
10
|
import path from 'node:path';
|
|
3
11
|
import { pathToFileURL } from 'node:url';
|
|
@@ -7,7 +15,6 @@ import { combineWordsDeduplicate, parseFirstWord } from '@cabloy/word-utils';
|
|
|
7
15
|
import Boxen from 'boxen';
|
|
8
16
|
import Chalk from 'chalk';
|
|
9
17
|
import TableClass from 'cli-table3';
|
|
10
|
-
import { build as esBuild } from 'esbuild';
|
|
11
18
|
import fse from 'fs-extra';
|
|
12
19
|
import gogocode from 'gogocode';
|
|
13
20
|
import tmp from 'tmp';
|
|
@@ -167,13 +174,19 @@ export class LocalHelper {
|
|
|
167
174
|
return await getRegistry();
|
|
168
175
|
}
|
|
169
176
|
parseBrandPath() {
|
|
177
|
+
const require = createRequire(import.meta.url);
|
|
170
178
|
const modulePath = require.resolve(`${process.env.CabloyCliBrandName}-cli/package.json`);
|
|
171
|
-
|
|
179
|
+
// ts or js
|
|
180
|
+
let file = path.join(path.dirname(modulePath), `src/bin/${process.env.CabloyCliBrandName}.ts`);
|
|
181
|
+
if (!fse.existsSync(file)) {
|
|
182
|
+
file = path.join(path.dirname(modulePath), `dist/bin/${process.env.CabloyCliBrandName}.js`);
|
|
183
|
+
}
|
|
184
|
+
return file;
|
|
172
185
|
}
|
|
173
186
|
async invokeCli(args, options) {
|
|
174
187
|
await this.processHelper.spawnExe({
|
|
175
188
|
cmd: 'node',
|
|
176
|
-
args: [this.parseBrandPath()].concat(args),
|
|
189
|
+
args: ['--experimental-transform-types', this.parseBrandPath()].concat(args),
|
|
177
190
|
options,
|
|
178
191
|
});
|
|
179
192
|
}
|
|
@@ -230,18 +243,9 @@ export class LocalHelper {
|
|
|
230
243
|
return name;
|
|
231
244
|
}
|
|
232
245
|
async importDynamic(fileName, fn) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
await esBuild(esBuildConfig);
|
|
237
|
-
// load
|
|
238
|
-
const instance = await import(this._pathToHref(fileTemp));
|
|
239
|
-
return await fn(instance);
|
|
240
|
-
}, {
|
|
241
|
-
tmpdir: path.dirname(fileName),
|
|
242
|
-
prefix: '.temp-dynamic-',
|
|
243
|
-
postfix: '.mjs',
|
|
244
|
-
});
|
|
246
|
+
// load
|
|
247
|
+
const instance = await import(__rewriteRelativeImportExtension(this.pathToHref(fileName)));
|
|
248
|
+
return await fn(instance);
|
|
245
249
|
}
|
|
246
250
|
requireDynamic(file) {
|
|
247
251
|
if (!file)
|
|
@@ -281,18 +285,35 @@ export class LocalHelper {
|
|
|
281
285
|
fileTempObj.removeCallback();
|
|
282
286
|
}
|
|
283
287
|
}
|
|
284
|
-
|
|
285
|
-
return
|
|
286
|
-
platform: 'node',
|
|
287
|
-
format: 'esm',
|
|
288
|
-
bundle: true,
|
|
289
|
-
packages: 'external',
|
|
290
|
-
resolveExtensions: ['.mjs', '.js', '.mts', '.ts', '.json'],
|
|
291
|
-
entryPoints: [fileSrc],
|
|
292
|
-
outfile: fileDest,
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
_pathToHref(fileName) {
|
|
296
|
-
return path.sep === '\\' ? pathToFileURL(fileName).href : fileName;
|
|
288
|
+
pathToHref(fileName) {
|
|
289
|
+
return pathToFileURL(fileName).href;
|
|
297
290
|
}
|
|
298
291
|
}
|
|
292
|
+
// async importDynamic<RESULT>(fileName: string, fn: (instance: any) => Promise<RESULT>): Promise<RESULT> {
|
|
293
|
+
// return await this.tempFile(
|
|
294
|
+
// async fileTemp => {
|
|
295
|
+
// // build
|
|
296
|
+
// const esBuildConfig = this._createEsbuildConfig(fileName, fileTemp);
|
|
297
|
+
// await esBuild(esBuildConfig as any);
|
|
298
|
+
// // load
|
|
299
|
+
// const instance = await import(this._pathToHref(fileTemp));
|
|
300
|
+
// return await fn(instance);
|
|
301
|
+
// },
|
|
302
|
+
// {
|
|
303
|
+
// tmpdir: path.dirname(fileName),
|
|
304
|
+
// prefix: '.temp-dynamic-',
|
|
305
|
+
// postfix: '.mjs',
|
|
306
|
+
// },
|
|
307
|
+
// );
|
|
308
|
+
// }
|
|
309
|
+
// private _createEsbuildConfig(fileSrc: string, fileDest: string) {
|
|
310
|
+
// return {
|
|
311
|
+
// platform: 'node',
|
|
312
|
+
// format: 'esm',
|
|
313
|
+
// bundle: true,
|
|
314
|
+
// packages: 'external',
|
|
315
|
+
// resolveExtensions: ['.mjs', '.js', '.mts', '.ts', '.json'],
|
|
316
|
+
// entryPoints: [fileSrc],
|
|
317
|
+
// outfile: fileDest,
|
|
318
|
+
// };
|
|
319
|
+
// }
|
|
@@ -76,7 +76,7 @@ export declare class LocalTemplate {
|
|
|
76
76
|
snippetsPath?: string | null | undefined;
|
|
77
77
|
boilerplatePath?: string | null | undefined;
|
|
78
78
|
}): Promise<void>;
|
|
79
|
-
renderDir(targetDir: string, templateDir: string): Promise<
|
|
79
|
+
renderDir(targetDir: string, templateDir: string): Promise<string[]>;
|
|
80
80
|
replaceTemplate(content: any, scope: any): any;
|
|
81
81
|
getProperty(obj: any, name: any, sep?: any): any;
|
|
82
82
|
_getProperty(obj: any, name: any, sep: any, forceObject: any): any;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import ejs from '@zhennann/ejs';
|
|
4
|
-
import
|
|
5
|
+
import { globby } from 'globby';
|
|
5
6
|
import gogocode from 'gogocode';
|
|
6
7
|
import isTextOrBinary from 'istextorbinary';
|
|
7
8
|
import { commandsConfig } from "../config.js";
|
|
@@ -35,6 +36,7 @@ export class LocalTemplate {
|
|
|
35
36
|
if (path.isAbsolute(_path))
|
|
36
37
|
return _path;
|
|
37
38
|
const sets = this.moduleConfig.sets;
|
|
39
|
+
const require = createRequire(import.meta.url);
|
|
38
40
|
const modulePath = require.resolve(`${sets[process.env.CabloyCliBrandName][setName]}/package.json`);
|
|
39
41
|
return path.join(path.dirname(modulePath), 'cli/templates', _path);
|
|
40
42
|
}
|
|
@@ -53,11 +55,10 @@ export class LocalTemplate {
|
|
|
53
55
|
async renderDir(targetDir, templateDir) {
|
|
54
56
|
const { argv } = this.context;
|
|
55
57
|
// files
|
|
56
|
-
const files =
|
|
58
|
+
const files = await globby('**/*', {
|
|
57
59
|
cwd: templateDir,
|
|
58
60
|
dot: true,
|
|
59
61
|
onlyFiles: false,
|
|
60
|
-
followSymlinkedDirectories: false,
|
|
61
62
|
});
|
|
62
63
|
// loop
|
|
63
64
|
for (const file of files) {
|
|
@@ -182,7 +183,7 @@ export class LocalTemplate {
|
|
|
182
183
|
}
|
|
183
184
|
async applySnippets(targetDir, snippetsDir) {
|
|
184
185
|
// snippets
|
|
185
|
-
let files =
|
|
186
|
+
let files = await globby('*.{cjs,ts}', {
|
|
186
187
|
cwd: snippetsDir,
|
|
187
188
|
onlyFiles: true,
|
|
188
189
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cabloy/cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.6",
|
|
5
5
|
"description": "@cabloy/cli",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -27,26 +27,26 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@babel/parser": "^7.26.5",
|
|
30
|
-
"@cabloy/word-utils": "^
|
|
30
|
+
"@cabloy/word-utils": "^2.0.0",
|
|
31
31
|
"@npmcli/config": "^8.3.4",
|
|
32
32
|
"@zhennann/common-bin": "^4.0.0",
|
|
33
33
|
"@zhennann/ejs": "^3.0.1",
|
|
34
34
|
"boxen": "^4.2.0",
|
|
35
35
|
"chalk": "^3.0.0",
|
|
36
36
|
"cli-table3": "^0.6.5",
|
|
37
|
-
"egg-born-utils": "^1.2.0",
|
|
38
37
|
"enquirer": "^2.3.6",
|
|
39
|
-
"esbuild": "^0.23.0",
|
|
40
38
|
"fs-extra": "^11.2.0",
|
|
39
|
+
"globby": "^14.1.0",
|
|
41
40
|
"gogocode": "^1.0.53",
|
|
42
41
|
"is-type-of": "^2.1.0",
|
|
43
42
|
"istextorbinary": "^3.3.0",
|
|
44
43
|
"semver": "^7.6.2",
|
|
45
44
|
"tmp": "^0.2.3",
|
|
46
45
|
"urllib": "^3.24.0",
|
|
47
|
-
"@cabloy/module-glob": "^5.
|
|
48
|
-
"@cabloy/module-info": "^1.
|
|
49
|
-
"@cabloy/process-helper": "^2.0.3"
|
|
46
|
+
"@cabloy/module-glob": "^5.2.0",
|
|
47
|
+
"@cabloy/module-info": "^1.3.1",
|
|
48
|
+
"@cabloy/process-helper": "^2.0.3",
|
|
49
|
+
"@cabloy/utils": "^1.0.3"
|
|
50
50
|
},
|
|
51
51
|
"gitHead": "2d40c063c115b230fdbc89f5a78b4412ebd0dfc9"
|
|
52
52
|
}
|