@cabloy/cli 3.0.5 → 3.0.7

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.d.ts CHANGED
@@ -28,7 +28,7 @@ export declare class CliCommand extends BaseCommand {
28
28
  key: any;
29
29
  context: any;
30
30
  propName: any;
31
- }): ((value: any) => any) | null;
31
+ }): ((value: any) => unknown) | null;
32
32
  _prepareQuestion({ group, question, key, context }: {
33
33
  group: any;
34
34
  question: any;
@@ -38,5 +38,5 @@ export declare class CliCommand extends BaseCommand {
38
38
  _checkGroupCondition({ group, context }: {
39
39
  group: any;
40
40
  context: any;
41
- }): any;
41
+ }): unknown;
42
42
  }
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 eggBornUtils.tools.evaluateExpression({ expression, scope: { value, group, question, key, context } });
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 eggBornUtils.tools.evaluateExpression({ expression, scope: { group, context } });
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 }: any): Promise<string>;
88
- spawnCmd({ cmd, args, options }: any): Promise<string>;
89
- spawnExe({ cmd, args, options }: any): Promise<string>;
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: any;
92
- args?: never[] | undefined;
93
- options?: {} | undefined;
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
- private _createEsbuildConfig;
109
- private _pathToHref;
121
+ pathToHref(fileName: string): string;
110
122
  }
@@ -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';
@@ -179,7 +186,7 @@ export class LocalHelper {
179
186
  async invokeCli(args, options) {
180
187
  await this.processHelper.spawnExe({
181
188
  cmd: 'node',
182
- args: [this.parseBrandPath()].concat(args),
189
+ args: ['--experimental-transform-types', this.parseBrandPath()].concat(args),
183
190
  options,
184
191
  });
185
192
  }
@@ -236,18 +243,9 @@ export class LocalHelper {
236
243
  return name;
237
244
  }
238
245
  async importDynamic(fileName, fn) {
239
- return await this.tempFile(async (fileTemp) => {
240
- // build
241
- const esBuildConfig = this._createEsbuildConfig(fileName, fileTemp);
242
- await esBuild(esBuildConfig);
243
- // load
244
- const instance = await import(this._pathToHref(fileTemp));
245
- return await fn(instance);
246
- }, {
247
- tmpdir: path.dirname(fileName),
248
- prefix: '.temp-dynamic-',
249
- postfix: '.mjs',
250
- });
246
+ // load
247
+ const instance = await import(__rewriteRelativeImportExtension(this.pathToHref(fileName)));
248
+ return await fn(instance);
251
249
  }
252
250
  requireDynamic(file) {
253
251
  if (!file)
@@ -287,18 +285,35 @@ export class LocalHelper {
287
285
  fileTempObj.removeCallback();
288
286
  }
289
287
  }
290
- _createEsbuildConfig(fileSrc, fileDest) {
291
- return {
292
- platform: 'node',
293
- format: 'esm',
294
- bundle: true,
295
- packages: 'external',
296
- resolveExtensions: ['.mjs', '.js', '.mts', '.ts', '.json'],
297
- entryPoints: [fileSrc],
298
- outfile: fileDest,
299
- };
300
- }
301
- _pathToHref(fileName) {
302
- return path.sep === '\\' ? pathToFileURL(fileName).href : fileName;
288
+ pathToHref(fileName) {
289
+ return pathToFileURL(fileName).href;
303
290
  }
304
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<any>;
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 eggBornUtils from 'egg-born-utils';
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 = eggBornUtils.tools.globbySync('**/*', {
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 = eggBornUtils.tools.globbySync('*.{cjs,ts}', {
186
+ let files = await globby('*.{cjs,ts}', {
186
187
  cwd: snippetsDir,
187
188
  onlyFiles: true,
188
189
  });
@@ -217,9 +218,9 @@ export class LocalTemplate {
217
218
  async _loadSnippetInstance(snippetTemplatePath, fn) {
218
219
  if (snippetTemplatePath.endsWith('.cjs')) {
219
220
  const instance = this.helper.requireDynamic(snippetTemplatePath);
220
- await fn(instance);
221
+ return await fn(instance);
221
222
  }
222
- await this.helper.importDynamic(snippetTemplatePath, instance => {
223
+ return await this.helper.importDynamic(snippetTemplatePath, instance => {
223
224
  return fn(instance.default);
224
225
  });
225
226
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cabloy/cli",
3
3
  "type": "module",
4
- "version": "3.0.5",
4
+ "version": "3.0.7",
5
5
  "description": "@cabloy/cli",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -34,19 +34,19 @@
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-info": "^1.2.10",
48
- "@cabloy/module-glob": "^5.1.12",
49
- "@cabloy/process-helper": "^2.0.3"
46
+ "@cabloy/module-info": "^1.3.1",
47
+ "@cabloy/module-glob": "^5.2.0",
48
+ "@cabloy/process-helper": "^2.0.3",
49
+ "@cabloy/utils": "^1.0.6"
50
50
  },
51
51
  "gitHead": "2d40c063c115b230fdbc89f5a78b4412ebd0dfc9"
52
52
  }