zova-cli-set-front 1.2.16 → 1.2.17

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
@@ -10,16 +10,17 @@ import { createRequire } from 'node:module';
10
10
  import { camelToKebab, replaceTemplate, toUpperCaseFirstChar, toLowerCaseFirstChar, skipPrefix, stringToCapitalize } from '@cabloy/word-utils';
11
11
  import fse from 'fs-extra';
12
12
  import { build as build$1 } from 'tsdown';
13
- import { createConfigUtils } from 'zova-vite';
14
- import { getOnionScenesMeta, getOnionMetasMeta } from '@cabloy/module-info';
13
+ import yaml from 'yaml';
14
+ import { saveJSONFile as saveJSONFile$1, createConfigUtils } from 'zova-vite';
15
15
  import fs from 'node:fs';
16
+ import 'node:url';
17
+ import { getOnionScenesMeta, getOnionMetasMeta } from '@cabloy/module-info';
16
18
  import compressing from 'compressing';
17
19
  import os from 'node:os';
18
20
  import urllib from 'urllib';
19
21
  import { extend } from '@cabloy/extend';
20
22
  import { catchError, matchSelector, getPropertyObject, evaluateSimple, StringPrefixRegexp } from '@cabloy/utils';
21
23
  import ts from 'typescript';
22
- import 'node:url';
23
24
  import { globbySync, globby } from 'globby';
24
25
  import gogocode from 'gogocode';
25
26
  import { optimize } from 'svgo';
@@ -153,6 +154,42 @@ class CliBinBuildModule extends BeanCliBase {
153
154
  }
154
155
  }
155
156
 
157
+ function getControllerFileName(module, type, beanName) {
158
+ const controllerFile = path.join(module.root, `src/${type}/${beanName}/controller.ts`);
159
+ if (fs.existsSync(controllerFile)) {
160
+ return 'controller.ts';
161
+ }
162
+ return 'controller.tsx';
163
+ }
164
+ async function loadJSONFile(fileName) {
165
+ const pkgContent = (await fse.readFile(fileName)).toString();
166
+ return JSON.parse(pkgContent);
167
+ }
168
+ async function saveJSONFile(fileName, json) {
169
+ await fse.writeFile(fileName, `${JSON.stringify(json, null, 2)}\n`);
170
+ }
171
+
172
+ function svgResolverPlugin() {
173
+ return {
174
+ name: 'svg-resolver',
175
+ resolveId: {
176
+ filter: {
177
+ id: /\.svg$/
178
+ },
179
+ handler(source, importer) {
180
+ return path.resolve(path.dirname(importer), source);
181
+ }
182
+ },
183
+ load: {
184
+ filter: {
185
+ id: /\.svg$/
186
+ },
187
+ handler(_id) {
188
+ return 'export default {};';
189
+ }
190
+ }
191
+ };
192
+ }
156
193
  const __template_package = `{
157
194
  "name": "{{Name}}",
158
195
  "version": "{{Version}}",
@@ -207,6 +244,15 @@ class CliBinBuildRest extends BeanCliBase {
207
244
  // index.ts
208
245
  await this._prepareResourcesIndex(context);
209
246
  }
247
+ _prepareBundleModules() {
248
+ const modules = [];
249
+ for (const module of this.modulesMeta.modulesArray) {
250
+ if (module.root.includes('/src/module/') || module.root.includes('/src/suite/')) {
251
+ modules.push(module.info.fullName);
252
+ }
253
+ }
254
+ return modules;
255
+ }
210
256
  async _build({
211
257
  projectPath,
212
258
  flavor,
@@ -214,6 +260,8 @@ class CliBinBuildRest extends BeanCliBase {
214
260
  srcDir,
215
261
  outDir
216
262
  }) {
263
+ const bundleModules = this._prepareBundleModules();
264
+ // entry
217
265
  const entry = path.join(srcDir, 'index.ts');
218
266
  // build
219
267
  await build$1({
@@ -222,15 +270,29 @@ class CliBinBuildRest extends BeanCliBase {
222
270
  outDir,
223
271
  tsconfig: 'tsconfig.rest.json',
224
272
  dts: {
225
- resolve: true,
273
+ // resolve: true,
226
274
  resolver: 'tsc',
227
275
  tsgo: true,
228
276
  eager: true,
229
277
  tsconfig: 'tsconfig.rest.json'
230
- }
278
+ },
279
+ plugins: [svgResolverPlugin()],
280
+ deps: {
281
+ alwaysBundle: id => {
282
+ if (bundleModules.includes(id)) return true;
283
+ return false;
284
+ }
285
+ },
286
+ minify: true
231
287
  });
288
+ // deps
289
+ const deps = await _extractDeps(path.join(outDir, 'index.d.mts'));
290
+ const depsVersion = await _extractDepsVersion(projectPath, deps);
232
291
  // package.json
233
- await fse.copyFile(path.join(srcDir, 'package.json'), path.join(outDir, 'package.json'));
292
+ const pkgContent = await loadJSONFile(path.join(srcDir, 'package.json'));
293
+ pkgContent.dependencies = depsVersion;
294
+ await saveJSONFile$1(path.join(outDir, 'package.json'), pkgContent);
295
+ // await fse.copyFile(path.join(srcDir, 'package.json'), path.join(outDir, 'package.json'));
234
296
  // release
235
297
  const outReleasesDir = path.join(projectPath, 'dist-releases', `rest-${flavor}-${process.env.APP_VERSION}`);
236
298
  await fse.copy(outDir, outReleasesDir);
@@ -267,69 +329,40 @@ class CliBinBuildRest extends BeanCliBase {
267
329
  async _prepareResourcesIndex({
268
330
  srcDir
269
331
  }) {
270
- let indexContent = '';
332
+ let indexContent = `import type { IIconRecord } from 'zova-module-a-icon';
333
+ export type { IIconRecord } from 'zova-module-a-icon';
334
+ export type { IPagePathRecord } from 'zova-module-a-router';
335
+ `;
271
336
  indexContent += await this._prepareResourcesIndex_rest(srcDir);
272
337
  indexContent += await this._prepareResourcesIndex_icons(srcDir);
273
- indexContent += await this._prepareResourcesIndex_pages(srcDir);
274
338
  await fse.writeFile(path.join(srcDir, 'index.ts'), indexContent);
275
339
  }
276
340
  async _prepareResourcesIndex_rest(srcDir) {
277
341
  let content = '';
278
342
  for (const module of this.modulesMeta.modulesArray) {
279
- const restIndexFile = path.join(module.root, 'rest/index.ts');
280
- if (!fse.existsSync(restIndexFile)) continue;
281
- const restIndexFileRelative = path.relative(srcDir, restIndexFile);
343
+ const restDir = path.join(module.root, 'rest');
344
+ if (!fse.existsSync(restDir)) continue;
345
+ let tempDir;
346
+ if (module.info.node_modules) {
347
+ tempDir = path.join(srcDir, 'modules', module.info.relativeName, 'rest');
348
+ await fse.copy(restDir, tempDir);
349
+ } else {
350
+ tempDir = path.join(module.root, 'rest');
351
+ }
352
+ const restIndexFile = path.join(tempDir, 'index.ts');
353
+ let restIndexFileRelative = path.relative(srcDir, restIndexFile);
354
+ if (!restIndexFileRelative.startsWith('.')) {
355
+ restIndexFileRelative = `./${restIndexFileRelative}`;
356
+ }
282
357
  content += `export * from '${restIndexFileRelative}';\n`;
283
358
  }
284
359
  return content;
285
360
  }
286
361
  async _prepareResourcesIndex_icons(_srcDir) {
287
- let content = '';
288
- for (const module of this.modulesMeta.modulesArray) {
289
- const restIconsFile = path.join(module.root, 'rest/icons.txt');
290
- if (!fse.existsSync(restIconsFile)) continue;
291
- const contentIcons = (await fse.readFile(restIconsFile)).toString();
292
- content += `${contentIcons}\n`;
293
- }
294
- if (content) {
295
- content = `export interface IIconRecord {
296
- ${content}
297
- }
298
- export function $iconName<K extends keyof IIconRecord>(name: K): any {
362
+ const content = `export function $iconName<K extends keyof IIconRecord>(name: K): any {
299
363
  return name;
300
364
  }
301
365
  `;
302
- }
303
- return content;
304
- }
305
- async _prepareResourcesIndex_pages(_srcDir) {
306
- let contentImport = '';
307
- let contentRecord = '';
308
- for (const module of this.modulesMeta.modulesArray) {
309
- const restPagesRecordFile = path.join(module.root, 'rest/pagesRecord.txt');
310
- if (!fse.existsSync(restPagesRecordFile)) continue;
311
- const restPagesImportFile = path.join(module.root, 'rest/pagesImport.txt');
312
- const contentPagesImport = (await fse.readFile(restPagesImportFile)).toString();
313
- const contentPagesRecord = (await fse.readFile(restPagesRecordFile)).toString();
314
- contentImport += `${contentPagesImport}\n`;
315
- contentRecord += `${contentPagesRecord}\n`;
316
- }
317
- let content = '';
318
- if (contentRecord) {
319
- content = `${contentImport}
320
- export interface TypePagePathSchema<PARAMS = unknown, QUERY = unknown> {
321
- params?: PARAMS;
322
- query?: QUERY;
323
- }
324
- export interface IPagePathRecord {
325
- ${contentRecord}
326
- '/': TypePagePathSchema<undefined,undefined>;
327
- presetLogin: TypePagePathSchema<undefined,undefined>;
328
- presetErrorExpired: TypePagePathSchema<undefined,undefined>;
329
- presetResource: TypePagePathSchema<undefined,undefined>;
330
- }
331
- `;
332
- }
333
366
  return content;
334
367
  }
335
368
  }
@@ -344,6 +377,64 @@ function _copyToTarget(outDir, target, bundleNameCopy) {
344
377
  });
345
378
  }
346
379
  }
380
+ async function _extractDeps(filePath) {
381
+ let content = (await fse.readFile(filePath)).toString();
382
+ const pos = content.indexOf('//#region');
383
+ content = content.substring(0, pos);
384
+ const packageNames = new Set();
385
+ const re = /import\s+[\s\S]*?\s+from\s+['"]([^'"]+)['"]/g;
386
+ let match;
387
+ while (true) {
388
+ match = re.exec(content);
389
+ if (!match) break;
390
+ let pkg = match[1];
391
+ if (pkg.startsWith('.') || pkg.startsWith('/')) continue;
392
+ if (pkg.startsWith('@')) {
393
+ if (pkg.split('/').length > 2) {
394
+ pkg = pkg.split('/').slice(0, 2).join('/');
395
+ }
396
+ } else {
397
+ if (pkg.split('/').length > 1) {
398
+ pkg = pkg.split('/').slice(0, 1).join('/');
399
+ }
400
+ }
401
+ packageNames.add(pkg);
402
+ }
403
+ return Array.from(packageNames).sort();
404
+ }
405
+ async function _extractDepsVersion(projectPath, deps) {
406
+ const lockfilePath = path.join(projectPath, 'pnpm-lock.yaml');
407
+ const lockfileContent = (await fse.readFile(lockfilePath)).toString();
408
+ const parsedLockfile = yaml.parse(lockfileContent);
409
+ const depsVersion = {};
410
+ for (const dep of deps) {
411
+ let version = getPackageVersionFromLock(parsedLockfile, dep);
412
+ if (!version) {
413
+ version = await getPackageVersionFromNodeModules(projectPath, dep);
414
+ }
415
+ if (!version) {
416
+ console.warn('dep version not found: ', dep);
417
+ continue;
418
+ }
419
+ depsVersion[dep] = `^${version}`;
420
+ }
421
+ return depsVersion;
422
+ }
423
+ function getPackageVersionFromLock(parsedLockfile, packageName) {
424
+ const packages = parsedLockfile.packages || {};
425
+ for (const key in packages) {
426
+ if (key.startsWith(`${packageName}@`)) {
427
+ return key.substring(`${packageName}@`.length);
428
+ }
429
+ }
430
+ return null;
431
+ }
432
+ async function getPackageVersionFromNodeModules(projectPath, packageName) {
433
+ const pkgFile = path.join(projectPath, 'node_modules', packageName, 'package.json');
434
+ if (!fse.existsSync(pkgFile)) return null;
435
+ const pkgContent = await loadJSONFile(pkgFile);
436
+ return pkgContent.version;
437
+ }
347
438
 
348
439
  const __ThisSetName__ = 'front';
349
440
 
@@ -2176,21 +2267,6 @@ class CliRefactorAnotherStyle extends BeanCliBase {
2176
2267
  }
2177
2268
  }
2178
2269
 
2179
- function getControllerFileName(module, type, beanName) {
2180
- const controllerFile = path.join(module.root, `src/${type}/${beanName}/controller.ts`);
2181
- if (fs.existsSync(controllerFile)) {
2182
- return 'controller.ts';
2183
- }
2184
- return 'controller.tsx';
2185
- }
2186
- async function loadJSONFile(fileName) {
2187
- const pkgContent = (await fse.readFile(fileName)).toString();
2188
- return JSON.parse(pkgContent);
2189
- }
2190
- async function saveJSONFile(fileName, json) {
2191
- await fse.writeFile(fileName, `${JSON.stringify(json, null, 2)}\n`);
2192
- }
2193
-
2194
2270
  class CliRefactorComponentEmits extends BeanCliBase {
2195
2271
  async execute() {
2196
2272
  const {
@@ -2904,15 +2980,18 @@ ${contentResourceIcons}
2904
2980
  /** icons: end */
2905
2981
  `;
2906
2982
  // restComponent
2907
- await generateRestIcon(moduleName, modulePath, resourceIcons);
2983
+ await generateRestIcon(moduleName, modulePath);
2908
2984
  // ok
2909
2985
  return content;
2910
2986
  }
2911
- async function generateRestIcon(_moduleName, modulePath, resourceIcons) {
2987
+ async function generateRestIcon(moduleName, modulePath, _resourceIcons) {
2912
2988
  // icons
2913
- const contentResourceIcons = resourceIcons.join('\n');
2914
- const fileIcons = path.join(modulePath, 'rest/icons.txt');
2989
+ const contentResourceIcons = `import 'zova-module-${moduleName}';\n`;
2990
+ const fileIcons = path.join(modulePath, 'rest/icons.ts');
2915
2991
  await fse.outputFile(fileIcons, contentResourceIcons);
2992
+ // index
2993
+ const exportIndexContent = "export * from './icons.js';";
2994
+ await generateRestIndex(modulePath, exportIndexContent);
2916
2995
  }
2917
2996
  async function _generateFileConfigIcons(groups) {
2918
2997
  const groupsFrontImport = [];
@@ -2996,6 +3075,18 @@ function _getRecordId(moduleName, groupName, iconName) {
2996
3075
  if (groupName === 'default') groupName = '';
2997
3076
  return `${moduleName}:${groupName}:${iconName}`;
2998
3077
  }
3078
+ async function generateRestIndex(modulePath, append) {
3079
+ // index
3080
+ const fileIndex = path.join(modulePath, 'rest/index.ts');
3081
+ let contentIndex = '';
3082
+ if (fse.existsSync(fileIndex)) {
3083
+ contentIndex = (await fse.readFile(fileIndex)).toString();
3084
+ }
3085
+ if (!contentIndex.includes(append)) {
3086
+ contentIndex = `${contentIndex}${append}\n`;
3087
+ await fse.outputFile(fileIndex, contentIndex);
3088
+ }
3089
+ }
2999
3090
 
3000
3091
  // import SVGCompiler from 'svg-baker';
3001
3092
  // const svgSymbol = await new SVGCompiler().addSymbol({
@@ -3462,6 +3553,9 @@ class CliToolsMetadata extends BeanCliBase {
3462
3553
  // do nothing
3463
3554
  return;
3464
3555
  }
3556
+ // rest
3557
+ await rimraf(path.join(modulePath, 'rest'));
3558
+ // metaDir
3465
3559
  await this.helper.ensureDir(metaDir);
3466
3560
  // relativeNameCapitalize
3467
3561
  const relativeNameCapitalize = this.helper.stringToCapitalize(moduleName, '-');
@@ -16,11 +16,11 @@ interface IBinBuildRestContext {
16
16
  export declare class CliBinBuildRest extends BeanCliBase {
17
17
  execute(): Promise<void>;
18
18
  _prepareResources(context: IBinBuildRestContext): Promise<void>;
19
+ _prepareBundleModules(): string[];
19
20
  _build({ projectPath, flavor, bundleNameCopy, srcDir, outDir }: IBinBuildRestContext): Promise<void>;
20
21
  _prepareResourcesPackage({ projectPath, flavor, bundleName, srcDir }: IBinBuildRestContext): Promise<void>;
21
22
  _prepareResourcesIndex({ srcDir }: IBinBuildRestContext): Promise<void>;
22
23
  _prepareResourcesIndex_rest(srcDir: string): Promise<string>;
23
24
  _prepareResourcesIndex_icons(_srcDir: string): Promise<string>;
24
- _prepareResourcesIndex_pages(_srcDir: string): Promise<string>;
25
25
  }
26
26
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zova-cli-set-front",
3
- "version": "1.2.16",
4
- "gitHead": "761a9baced655ccf3197e756c1d046ed651fafd5",
3
+ "version": "1.2.17",
4
+ "gitHead": "4caf955ae46d889cab5dd7efc981f562b3b54aa2",
5
5
  "description": "zova cli-set-front",
6
6
  "keywords": [
7
7
  "framework",
@@ -59,10 +59,11 @@
59
59
  "rolldown": "^1.0.0-rc.11",
60
60
  "rolldown-plugin-dts": "^0.22.5",
61
61
  "svgo": "^3.2.0",
62
- "tsdown": "^0.18.3",
62
+ "tsdown": "^0.21.7",
63
63
  "typescript": "^5.9.3",
64
64
  "urllib": "^4.6.11",
65
65
  "vite": "^8.0.2",
66
+ "yaml": "^2.8.3",
66
67
  "zova-openapi": "^1.1.7",
67
68
  "zova-vite": "^1.1.12"
68
69
  }