zova-cli-set-front 1.2.60 → 1.2.61

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.js CHANGED
@@ -2867,7 +2867,7 @@ declare module 'zova' {
2867
2867
 
2868
2868
  async function generateConfig(modulePath) {
2869
2869
  const configFile = path.join(modulePath, 'src/config/config.ts');
2870
- if (!fse.existsSync(configFile)) return '';
2870
+ if (!(await fse.pathExists(configFile))) return '';
2871
2871
  // combine
2872
2872
  const content = `/** config: begin */
2873
2873
  export * from '../config/config.js';
@@ -2878,7 +2878,7 @@ import { config } from '../config/config.js';
2878
2878
  }
2879
2879
  async function generateConstant(modulePath) {
2880
2880
  const constantFile = path.join(modulePath, 'src/config/constants.ts');
2881
- if (!fse.existsSync(constantFile)) return '';
2881
+ if (!(await fse.pathExists(constantFile))) return '';
2882
2882
  // combine
2883
2883
  const content = `/** constant: begin */
2884
2884
  export * from '../config/constants.js';
@@ -2931,7 +2931,7 @@ import { locales } from './locales.js';
2931
2931
  }
2932
2932
  async function generateError(modulePath) {
2933
2933
  const errorFile = path.join(modulePath, 'src/config/errors.ts');
2934
- if (!fse.existsSync(errorFile)) return '';
2934
+ if (!(await fse.pathExists(errorFile))) return '';
2935
2935
  // combine
2936
2936
  const content = `/** error: begin */
2937
2937
  export * from '../config/errors.js';
@@ -3065,7 +3065,7 @@ async function generateMetadataCustom(cli, globFiles, sceneName, sceneMeta, modu
3065
3065
  if (globFiles.length === 0) return '';
3066
3066
  // custom
3067
3067
  let jsFile = path.join(sceneMeta.module.root, 'dist-cli', sceneMeta.metadataCustom.replace('.ts', '.js'));
3068
- if (!fse.existsSync(jsFile)) {
3068
+ if (!(await fse.pathExists(jsFile))) {
3069
3069
  jsFile = path.join(sceneMeta.module.root, 'cli', sceneMeta.metadataCustom);
3070
3070
  }
3071
3071
  return await cli.helper.importDynamic(jsFile, async instance => {
@@ -3096,7 +3096,7 @@ async function generateMainSys(modulePath) {
3096
3096
  }
3097
3097
  async function generateMonkey_common(modulePath, commandName) {
3098
3098
  const monkeyFile = path.join(modulePath, `src/${commandName}.ts`);
3099
- if (!fse.existsSync(monkeyFile)) return '';
3099
+ if (!(await fse.pathExists(monkeyFile))) return '';
3100
3100
  // combine
3101
3101
  const content = `/** ${commandName}: begin */
3102
3102
  export * from '../${commandName}.js';
@@ -3106,7 +3106,7 @@ export * from '../${commandName}.js';
3106
3106
  }
3107
3107
  async function generateMain_common(modulePath, commandName) {
3108
3108
  const monkeyFile = path.join(modulePath, `src/${commandName}.ts`);
3109
- if (!fse.existsSync(monkeyFile)) return '';
3109
+ if (!(await fse.pathExists(monkeyFile))) return '';
3110
3110
  // combine
3111
3111
  const content = `/** ${commandName}: begin */
3112
3112
  export * from '../${commandName}.js';
@@ -3115,6 +3115,9 @@ export * from '../${commandName}.js';
3115
3115
  return content;
3116
3116
  }
3117
3117
 
3118
+ function escapeRegExp(str) {
3119
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
3120
+ }
3118
3121
  function checkIgnoreOfParts(parts) {
3119
3122
  const indexLast = parts.length - 1;
3120
3123
  if (parts[indexLast].endsWith('_')) {
@@ -3182,12 +3185,12 @@ function extractBeanInfo(sceneName, fileContent, sceneMeta) {
3182
3185
  // optionsCustomInterface
3183
3186
  let optionsCustomInterface;
3184
3187
  let optionsCustomInterfaceFrom;
3185
- let reg = new RegExp(`@${sceneNameCapitalize}<(I${sceneNameCapitalize}Options[^>]*)>`);
3188
+ let reg = new RegExp(`@${escapeRegExp(sceneNameCapitalize)}<(I${escapeRegExp(sceneNameCapitalize)}Options[^>]*)>`);
3186
3189
  let matches = fileContent.match(reg);
3187
3190
  if (matches) {
3188
3191
  optionsCustomInterface = matches[1];
3189
3192
  // optionsCustomInterfaceFrom
3190
- reg = new RegExp(`import {[\\s\\S]*?${optionsCustomInterface}[, ][\\s\\S]*?} from '([^']*)'`);
3193
+ reg = new RegExp(`import {[\\s\\S]*?${escapeRegExp(optionsCustomInterface)}[, ][\\s\\S]*?} from '([^']*)'`);
3191
3194
  matches = fileContent.match(reg);
3192
3195
  if (matches) {
3193
3196
  optionsCustomInterfaceFrom = matches[1];
@@ -3338,7 +3341,7 @@ async function generateOptionsPackage(cli, globFiles, onionScenesMeta, _moduleNa
3338
3341
  if (!sceneMeta) throw new Error(`sceneMeta not exists: ${sceneName}`);
3339
3342
  if (!sceneMeta.optionsPackage) continue;
3340
3343
  changed = true;
3341
- const matches = fileContent.match(new RegExp(`@${sceneNameCapitalize}[\\S]*?\\(([\\s\\S]*?)\\)\\s*?export class`));
3344
+ const matches = fileContent.match(new RegExp(`@${escapeRegExp(sceneNameCapitalize)}[\\S]*?\\(([\\s\\S]*?)\\)\\s*?export class`));
3342
3345
  if (!matches) throw new Error(`${sceneName} options parser error: ${beanNameFull}`);
3343
3346
  const onionOptionsStr = matches[1];
3344
3347
  const onionOptions = onionOptionsStr ? evaluateSimple(matches[1]) : {};
@@ -3513,13 +3516,14 @@ class CliToolsMetadata extends BeanCliBase {
3513
3516
  const modulePath = module.root;
3514
3517
  const metaDir = path.join(modulePath, 'src/.metadata');
3515
3518
  const metaIndexFile = path.join(metaDir, 'index.ts');
3516
- if (fse.existsSync(metaIndexFile) && !force) {
3519
+ if ((await fse.pathExists(metaIndexFile)) && !force) {
3517
3520
  // do nothing
3518
3521
  return;
3519
3522
  }
3520
- // rest
3521
- await rimraf(path.join(modulePath, 'rest'));
3522
3523
  // metaDir
3524
+ await fse.remove(path.join(metaDir, 'component'));
3525
+ await fse.remove(path.join(metaDir, 'page'));
3526
+ await fse.remove(path.join(metaDir, 'icons'));
3523
3527
  await this.helper.ensureDir(metaDir);
3524
3528
  // relativeNameCapitalize
3525
3529
  const relativeNameCapitalize = this.helper.stringToCapitalize(moduleName, '-');
@@ -3605,7 +3609,6 @@ class CliToolsMetadata extends BeanCliBase {
3605
3609
  }
3606
3610
  // save
3607
3611
  await fse.writeFile(metaIndexFile, content);
3608
- // await this.helper.formatFile({ fileName: metaIndexFile, logPrefix: 'format: ' });
3609
3612
  // locales
3610
3613
  await this._generateLocales(modulePath, contentLocales1);
3611
3614
  // generate this
@@ -3627,43 +3630,30 @@ class CliToolsMetadata extends BeanCliBase {
3627
3630
  }
3628
3631
  async _generateThis(moduleName, relativeNameCapitalize, modulePath) {
3629
3632
  const thisDest = path.join(modulePath, 'src/.metadata/this.ts');
3630
- if (fse.existsSync(thisDest)) return;
3633
+ if (await fse.pathExists(thisDest)) return;
3631
3634
  const content = `export const __ThisModule__ = '${moduleName}';
3632
3635
  export { ScopeModule${relativeNameCapitalize} as ScopeModule } from './index.js';
3633
3636
  `;
3634
3637
  // save
3635
3638
  await fse.writeFile(thisDest, content);
3636
3639
  }
3640
+ async _prependExportIfNeeded(jsContent, exportLine, sourceFile, modulePath) {
3641
+ const sourcePath = path.join(modulePath, sourceFile);
3642
+ if ((await fse.pathExists(sourcePath)) && !jsContent.includes(exportLine)) {
3643
+ return `${exportLine}\n${jsContent}`;
3644
+ }
3645
+ return jsContent;
3646
+ }
3637
3647
  async _generateIndex(modulePath) {
3638
3648
  let jsContent = '';
3639
3649
  const jsFile = path.join(modulePath, 'src/index.ts');
3640
- if (fse.existsSync(jsFile)) {
3650
+ if (await fse.pathExists(jsFile)) {
3641
3651
  jsContent = (await fse.readFile(jsFile)).toString();
3642
3652
  }
3643
- // jsTypes
3644
- const jsTypes = "export * from './types/index.js';";
3645
- const jsTypesFile = path.join(modulePath, 'src/types/index.ts');
3646
- if (fse.existsSync(jsTypesFile) && !jsContent.includes(jsTypes)) {
3647
- jsContent = `${jsTypes}\n${jsContent}`;
3648
- }
3649
- // jsLib
3650
- const jsLib = "export * from './lib/index.js';";
3651
- const jsLibFile = path.join(modulePath, 'src/lib/index.ts');
3652
- if (fse.existsSync(jsLibFile) && !jsContent.includes(jsLib)) {
3653
- jsContent = `${jsLib}\n${jsContent}`;
3654
- }
3655
- // jsLocales
3656
- const jsLocales = "export * from './.metadata/locales.js';";
3657
- const jsLocalesFile = path.join(modulePath, 'src/.metadata/locales.ts');
3658
- if (fse.existsSync(jsLocalesFile) && !jsContent.includes(jsLocales)) {
3659
- jsContent = `${jsLocales}\n${jsContent}`;
3660
- }
3661
- // jsMetadata
3662
- const jsMetadata = "export * from './.metadata/index.js';";
3663
- const jsMetadataFile = path.join(modulePath, 'src/.metadata/index.ts');
3664
- if (fse.existsSync(jsMetadataFile) && !jsContent.includes(jsMetadata)) {
3665
- jsContent = `${jsMetadata}\n${jsContent}`;
3666
- }
3653
+ jsContent = await this._prependExportIfNeeded(jsContent, "export * from './types/index.js';", 'src/types/index.ts', modulePath);
3654
+ jsContent = await this._prependExportIfNeeded(jsContent, "export * from './lib/index.js';", 'src/lib/index.ts', modulePath);
3655
+ jsContent = await this._prependExportIfNeeded(jsContent, "export * from './.metadata/locales.js';", 'src/.metadata/locales.ts', modulePath);
3656
+ jsContent = await this._prependExportIfNeeded(jsContent, "export * from './.metadata/index.js';", 'src/.metadata/index.ts', modulePath);
3667
3657
  // trim empty
3668
3658
  jsContent = jsContent.replace('export {};\n', '');
3669
3659
  // write
@@ -3693,11 +3683,12 @@ export { ScopeModule${relativeNameCapitalize} as ScopeModule } from './index.js'
3693
3683
  pkg.zovaModule.beansPreload = beansPreload;
3694
3684
  }
3695
3685
  }
3696
- // cli/rest
3697
- for (const name of ['cli', 'icons', 'rest']) {
3686
+ // cli
3687
+ for (const name of ['cli', 'icons']) {
3698
3688
  const cli = path.join(modulePath, name);
3699
- if (fse.existsSync(cli)) {
3689
+ if (await fse.pathExists(cli)) {
3700
3690
  pkg = await _loadPkg();
3691
+ pkg.files ??= [];
3701
3692
  const index = pkg.files.indexOf(name);
3702
3693
  if (index === -1) {
3703
3694
  changed = true;
@@ -9,6 +9,7 @@ export declare class CliToolsMetadata extends BeanCliBase {
9
9
  _generateMetadata(moduleName: string, force: boolean): Promise<void>;
10
10
  _generateLocales(modulePath: string, contentLocales: any): Promise<void>;
11
11
  _generateThis(moduleName: string, relativeNameCapitalize: string, modulePath: string): Promise<void>;
12
+ _prependExportIfNeeded(jsContent: string, exportLine: string, sourceFile: string, modulePath: string): Promise<string>;
12
13
  _generateIndex(modulePath: string): Promise<void>;
13
14
  _generatePackage(modulePath: string, beansPreload: string[]): Promise<void>;
14
15
  }
@@ -1,4 +1,5 @@
1
1
  import type { IGlobBeanFile, OnionSceneMeta } from '@cabloy/module-info';
2
+ export declare function escapeRegExp(str: string): string;
2
3
  export declare function checkIgnoreOfParts(parts: string[]): boolean;
3
4
  export declare function getScopeModuleName(moduleName: string): string;
4
5
  export declare function globAllTsFiles(moduleName: string, modulePath: string): Promise<IGlobBeanFile[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zova-cli-set-front",
3
- "version": "1.2.60",
3
+ "version": "1.2.61",
4
4
  "gitHead": "6f675a8cc46d596142c591c28a40cc4d82fcc6cc",
5
5
  "description": "zova cli-set-front",
6
6
  "keywords": [