vona-cli-set-api 1.0.402 → 1.0.406

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.
Files changed (96) hide show
  1. package/cli/templates/create/project/basic/boilerplate/env/.env +1 -1
  2. package/cli/templates/create/project/basic/boilerplate/env/.env.prod +1 -1
  3. package/cli/templates/create/project/basic/boilerplate/package.original.json +1 -1
  4. package/cli/templates/create/project/basic/boilerplate/src/backend/config/config/config.ts +1 -0
  5. package/cli/templates/tools/crud/snippets/2-meta.index.ts +10 -5
  6. package/cli/templates/tools/crud/snippets/2-meta.version.ts +11 -9
  7. package/cli/templates/tools/crud/snippets/3-en-us.ts +1 -1
  8. package/cli/templates/tools/crud/snippets/4-zh-cn.ts +1 -1
  9. package/cli/templates/tools/crud/utils.ts +15 -15
  10. package/dist/index.js +3314 -3
  11. package/dist/lib/bean/cli.bin.buildGeneral.d.ts +12 -0
  12. package/dist/lib/beans.d.ts +2 -0
  13. package/dist/lib/command/bin.buildGeneral.d.ts +19 -0
  14. package/dist/lib/commands.d.ts +18 -0
  15. package/dist/lib/utils.d.ts +0 -1
  16. package/dist/utils.d.ts +1 -0
  17. package/package.json +9 -9
  18. package/dist/lib/bean/cli.bin.build.js +0 -185
  19. package/dist/lib/bean/cli.bin.buildModule.js +0 -106
  20. package/dist/lib/bean/cli.bin.dbReset.js +0 -48
  21. package/dist/lib/bean/cli.bin.dev.js +0 -66
  22. package/dist/lib/bean/cli.bin.play.js +0 -92
  23. package/dist/lib/bean/cli.bin.test.js +0 -93
  24. package/dist/lib/bean/cli.bin.tsc.js +0 -48
  25. package/dist/lib/bean/cli.create.bean.js +0 -81
  26. package/dist/lib/bean/cli.create.module.js +0 -73
  27. package/dist/lib/bean/cli.create.project.js +0 -119
  28. package/dist/lib/bean/cli.create.suite.js +0 -35
  29. package/dist/lib/bean/cli.create.test.js +0 -39
  30. package/dist/lib/bean/cli.default.list.js +0 -93
  31. package/dist/lib/bean/cli.init.appMonkey.js +0 -24
  32. package/dist/lib/bean/cli.init.asset.js +0 -28
  33. package/dist/lib/bean/cli.init.config.js +0 -38
  34. package/dist/lib/bean/cli.init.constant.js +0 -38
  35. package/dist/lib/bean/cli.init.error.js +0 -49
  36. package/dist/lib/bean/cli.init.lib.js +0 -38
  37. package/dist/lib/bean/cli.init.locale.js +0 -38
  38. package/dist/lib/bean/cli.init.main.js +0 -38
  39. package/dist/lib/bean/cli.init.monkey.js +0 -64
  40. package/dist/lib/bean/cli.init.static.js +0 -38
  41. package/dist/lib/bean/cli.init.types.js +0 -38
  42. package/dist/lib/bean/cli.tools.crud.js +0 -46
  43. package/dist/lib/bean/cli.tools.deps.js +0 -42
  44. package/dist/lib/bean/cli.tools.metadata.js +0 -234
  45. package/dist/lib/bean/toolsBin/configUtils.js +0 -56
  46. package/dist/lib/bean/toolsBin/dbReset.js +0 -8
  47. package/dist/lib/bean/toolsBin/generateEntryFiles.js +0 -90
  48. package/dist/lib/bean/toolsBin/generateVonaMeta.js +0 -17
  49. package/dist/lib/bean/toolsBin/generateZod.js +0 -48
  50. package/dist/lib/bean/toolsBin/play.js +0 -59
  51. package/dist/lib/bean/toolsBin/test.js +0 -137
  52. package/dist/lib/bean/toolsBin/types.js +0 -1
  53. package/dist/lib/bean/toolsMetadata/generateBeanGenerals.js +0 -33
  54. package/dist/lib/bean/toolsMetadata/generateConfig.js +0 -62
  55. package/dist/lib/bean/toolsMetadata/generateMetadataCustom.js +0 -23
  56. package/dist/lib/bean/toolsMetadata/generateMonkey.js +0 -24
  57. package/dist/lib/bean/toolsMetadata/generateOnions.js +0 -112
  58. package/dist/lib/bean/toolsMetadata/generateScope.js +0 -83
  59. package/dist/lib/bean/toolsMetadata/generateScopeResources.js +0 -33
  60. package/dist/lib/bean/toolsMetadata/generateScopeResourcesMeta.js +0 -13
  61. package/dist/lib/bean/toolsMetadata/utils.js +0 -84
  62. package/dist/lib/beans.js +0 -56
  63. package/dist/lib/command/bin.build.js +0 -18
  64. package/dist/lib/command/bin.buildModule.js +0 -18
  65. package/dist/lib/command/bin.dbReset.js +0 -14
  66. package/dist/lib/command/bin.dev.js +0 -18
  67. package/dist/lib/command/bin.play.js +0 -27
  68. package/dist/lib/command/bin.test.js +0 -18
  69. package/dist/lib/command/bin.tsc.js +0 -14
  70. package/dist/lib/command/create.bean.js +0 -46
  71. package/dist/lib/command/create.module.js +0 -36
  72. package/dist/lib/command/create.project.js +0 -43
  73. package/dist/lib/command/create.suite.js +0 -23
  74. package/dist/lib/command/create.test.js +0 -33
  75. package/dist/lib/command/default.list.js +0 -18
  76. package/dist/lib/command/init.appMonkey.js +0 -10
  77. package/dist/lib/command/init.asset.js +0 -33
  78. package/dist/lib/command/init.config.js +0 -10
  79. package/dist/lib/command/init.constant.js +0 -10
  80. package/dist/lib/command/init.error.js +0 -10
  81. package/dist/lib/command/init.lib.js +0 -10
  82. package/dist/lib/command/init.locale.js +0 -10
  83. package/dist/lib/command/init.main.js +0 -10
  84. package/dist/lib/command/init.monkey.js +0 -10
  85. package/dist/lib/command/init.static.js +0 -10
  86. package/dist/lib/command/init.types.js +0 -10
  87. package/dist/lib/command/tools.crud.js +0 -33
  88. package/dist/lib/command/tools.deps.js +0 -9
  89. package/dist/lib/command/tools.metadata.js +0 -14
  90. package/dist/lib/commands.js +0 -67
  91. package/dist/lib/this.js +0 -1
  92. package/dist/lib/utils.js +0 -80
  93. package/dist/typings.js +0 -1
  94. /package/dist/lib/bean/{toolsBin → toolsIsolate}/dbReset.d.ts +0 -0
  95. /package/dist/lib/bean/{toolsBin → toolsIsolate}/play.d.ts +0 -0
  96. /package/dist/lib/bean/{toolsBin → toolsIsolate}/test.d.ts +0 -0
package/dist/index.js CHANGED
@@ -1,3 +1,3314 @@
1
- export * from "./lib/beans.js";
2
- export * from "./lib/commands.js";
3
- export * from "./lib/utils.js";
1
+ import path from 'node:path';
2
+ import { BeanCliBase, getCommandsMeta } from '@cabloy/cli';
3
+ import aliasImport from '@rollup/plugin-alias';
4
+ import babelImport from '@rollup/plugin-babel';
5
+ import commonjsImport from '@rollup/plugin-commonjs';
6
+ import jsonImport from '@rollup/plugin-json';
7
+ import resolveImport from '@rollup/plugin-node-resolve';
8
+ import replaceImport from '@rollup/plugin-replace';
9
+ import terserImport from '@rollup/plugin-terser';
10
+ import fse from 'fs-extra';
11
+ import { globby } from 'globby';
12
+ import { rimraf } from 'rimraf';
13
+ import { rollup } from 'rollup';
14
+ import { createRequire } from 'node:module';
15
+ import { pathToFileURL, fileURLToPath } from 'node:url';
16
+ import compileTemplate from 'lodash/template.js';
17
+ import os from 'node:os';
18
+ import * as dotenv from '@cabloy/dotenv';
19
+ import { getEnvFiles } from '@cabloy/dotenv';
20
+ import { glob } from '@cabloy/module-glob';
21
+ import chalk from 'chalk';
22
+ import nodemon from 'nodemon';
23
+ import { catchError, combineApiPathControllerAndActionRaw, replaceTemplate } from '@cabloy/utils';
24
+ import fs from 'node:fs';
25
+ import { getOnionScenesMeta, getOnionMetasMeta, relativeNameToCapitalize } from '@cabloy/module-info';
26
+ import { toUpperCaseFirstChar, stringToCapitalize, replaceTemplate as replaceTemplate$1 } from '@cabloy/word-utils';
27
+ import compressing from 'compressing';
28
+ import randomize from 'randomatic';
29
+ import urllib from 'urllib';
30
+ import * as uuid from 'uuid';
31
+ import { beanFullNameFromOnionName } from 'vona-core';
32
+
33
+ function getEnvMeta(configMeta) {
34
+ return {
35
+ flavor: configMeta.flavor,
36
+ mode: configMeta.mode,
37
+ mine: 'mine'
38
+ };
39
+ }
40
+ function getNodeEnv(mode) {
41
+ return mode === 'test' ? 'test' : mode === 'dev' ? 'development' : 'production';
42
+ }
43
+ function generateConfigDefine(env, translates) {
44
+ const acc = {};
45
+ for (const key in env) {
46
+ if (!translates || translates.includes(key)) {
47
+ acc[`process.env.${key}`] = JSON.stringify(env[key]);
48
+ } else {
49
+ acc[`process.env.${key}`] = `'process.env.${key}->app.meta.env.${key}'`;
50
+ }
51
+ }
52
+ return acc;
53
+ }
54
+ function getAbsolutePathOfModule(id, postfix = 'index.js') {
55
+ const require = createRequire(import.meta.url);
56
+ let modulePath = require.resolve(id);
57
+ if (postfix) {
58
+ const pos = modulePath.lastIndexOf(postfix);
59
+ if (pos > -1) {
60
+ modulePath = modulePath.substring(0, modulePath.length - postfix.length - 1);
61
+ }
62
+ }
63
+ return modulePath;
64
+ }
65
+ function requireModule(id) {
66
+ const require = createRequire(import.meta.url);
67
+ return require(id);
68
+ }
69
+ async function copyTemplateFile(fileSrc, fileDest, variables) {
70
+ if (!variables) {
71
+ await fse.copyFile(fileSrc, fileDest);
72
+ return;
73
+ }
74
+ // src
75
+ const contentSrc = (await fse.readFile(fileSrc, 'utf-8')).toString();
76
+ const template = compileTemplate(contentSrc);
77
+ // dest
78
+ const contentDest = template(variables);
79
+ await fse.writeFile(fileDest, contentDest, 'utf-8');
80
+ }
81
+ async function loadJSONFile(fileName) {
82
+ const pkgContent = (await fse.readFile(fileName)).toString();
83
+ return JSON.parse(pkgContent);
84
+ }
85
+ async function saveJSONFile(fileName, json) {
86
+ await fse.writeFile(fileName, `${JSON.stringify(json, null, 2)}\n`);
87
+ }
88
+ function pathToHref(fileName) {
89
+ return pathToFileURL(fileName).href;
90
+ }
91
+ function getOutDir() {
92
+ return process.env.BUILD_OUTDIR || `dist/${process.env.META_FLAVOR}`;
93
+ }
94
+ function getOutReleasesDir() {
95
+ return `dist-releases/${process.env.META_FLAVOR}-${process.env.APP_VERSION}`;
96
+ }
97
+ function copyTemplateIfNeed(fileSrc, fileDest) {
98
+ if (!fse.existsSync(fileDest)) {
99
+ fse.copyFileSync(fileSrc, fileDest);
100
+ }
101
+ }
102
+ function getImportEsm() {
103
+ // return '--loader=ts-node/esm';
104
+ return '--import=./.vona/register.js';
105
+ }
106
+
107
+ function createConfigUtils(configMeta, configOptions) {
108
+ let __modulesMeta;
109
+ return {
110
+ loadEnvs: __loadEnvs,
111
+ loadModulesMeta: __loadModulesMeta
112
+ };
113
+
114
+ //////////////////////////////
115
+
116
+ function __loadEnvs() {
117
+ const meta = getEnvMeta(configMeta);
118
+ const envDir = path.join(configOptions.appDir, 'env');
119
+ const envs = dotenv.loadEnvs(meta, envDir, '.env');
120
+ const res = Object.assign({
121
+ NODE_ENV: getNodeEnv(meta.mode)
122
+ }, envs, {
123
+ META_FLAVOR: meta.flavor,
124
+ META_MODE: meta.mode
125
+ });
126
+ if (configOptions.workers !== undefined) {
127
+ res.SERVER_WORKERS = configOptions.workers.toString();
128
+ }
129
+ // maybe empty string
130
+ if (!res.SERVER_WORKERS) {
131
+ if (meta.mode === 'prod') {
132
+ res.SERVER_WORKERS = os.cpus().length.toString();
133
+ } else {
134
+ res.SERVER_WORKERS = '1';
135
+ }
136
+ }
137
+ for (const key of ['NODE_ENV', 'SERVER_WORKERS', 'META_FLAVOR', 'META_MODE']) {
138
+ if (res[key] !== false) {
139
+ process.env[key] = res[key];
140
+ }
141
+ }
142
+ // ok
143
+ return res;
144
+ }
145
+ async function __loadModulesMeta() {
146
+ const meta = getEnvMeta(configMeta);
147
+ // modules
148
+ __modulesMeta = await glob({
149
+ projectMode: 'vona',
150
+ projectPath: configOptions.appDir,
151
+ disabledModules: process.env.PROJECT_DISABLED_MODULES,
152
+ disabledSuites: process.env.PROJECT_DISABLED_SUITES,
153
+ log: false,
154
+ meta
155
+ });
156
+ return __modulesMeta;
157
+ }
158
+ }
159
+
160
+ function resolveTemplatePath(file) {
161
+ const url = new URL(path.join('../templates', file), import.meta.url);
162
+ return fileURLToPath(url);
163
+ }
164
+
165
+ const __ImportZodCore = 'zod/v4/core';
166
+ async function generateZod(configOptions) {
167
+ await __generateZodCoreUtil(configOptions);
168
+ await __generateZodCoreSchemas(configOptions);
169
+ }
170
+ async function __generateZodCoreUtil(configOptions) {
171
+ const pathZodCore = parseZodCorePath(configOptions.appDir);
172
+ const fileSrc = path.join(pathZodCore, 'util.js');
173
+ const fileSrcBak = path.join(pathZodCore, 'util-origin.js');
174
+ copyTemplateIfNeed(fileSrc, fileSrcBak);
175
+ const content = fse.readFileSync(fileSrcBak).toString();
176
+ const contentNew = content.replace('export function finalizeIssue', `let __localeAdapterFn;
177
+ export function setLocaleAdapter(localeAdapterFn) {
178
+ __localeAdapterFn=localeAdapterFn;
179
+ }
180
+ export function finalizeIssue`).replace('const message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ??', `const msg = unwrapMessage(iss.inst?._zod.def?.error?.(iss));
181
+ const message = (__localeAdapterFn?__localeAdapterFn(msg, iss):msg) ??`);
182
+ fse.writeFileSync(fileSrc, contentNew);
183
+ }
184
+ async function __generateZodCoreSchemas(configOptions) {
185
+ const pathZodCore = parseZodCorePath(configOptions.appDir);
186
+ const fileSrc = path.join(pathZodCore, 'schemas.js');
187
+ const fileSrcBak = path.join(pathZodCore, 'schemas-origin.js');
188
+ copyTemplateIfNeed(fileSrc, fileSrcBak);
189
+ const content = fse.readFileSync(fileSrcBak).toString();
190
+ const contentNew = content.replace('export const $ZodType =', `let __parseAdapterFn;
191
+ export function setParseAdapter(parseAdapterFn) {
192
+ __parseAdapterFn = parseAdapterFn;
193
+ }
194
+ export const $ZodType =`).replace('inst._zod.run = inst._zod.parse;', 'inst._zod.run = __parseAdapterFn ? __parseAdapterFn(inst, inst._zod.parse) : inst._zod.parse;').replace(/inst._zod.run = (\(payload, ctx\) => \{[\s\S]*?return runChecks\(result, checks, ctx\);\s*\};)/, (_, $0) => {
195
+ return `const __run = ${$0}\ninst._zod.run = __parseAdapterFn ? __parseAdapterFn(inst, __run) : __run;`;
196
+ });
197
+ fse.writeFileSync(fileSrc, contentNew);
198
+ }
199
+ function parseZodCorePath(appDir) {
200
+ const require = createRequire(pathToHref(path.join(appDir, '/')));
201
+ const fileCoreIndex = require.resolve(__ImportZodCore);
202
+ return path.dirname(fileCoreIndex);
203
+ }
204
+
205
+ async function generateEntryFiles(configMeta, configOptions, modulesMeta, env) {
206
+ // config
207
+ await __generateConfig();
208
+ // modules meta
209
+ await __generateModulesMeta();
210
+ // env
211
+ await __generateEnvJson();
212
+ // app
213
+ await __generateApp();
214
+ // others
215
+ await __generateOthers();
216
+ // zod
217
+ await generateZod(configOptions);
218
+
219
+ //////////////////////////////
220
+
221
+ async function __generateConfig() {
222
+ // check config
223
+ let configDir = path.join(configOptions.appDir, 'src/backend/config');
224
+ if (!fse.existsSync(configDir)) {
225
+ // eslint-disable-next-line
226
+ console.log(chalk.red('path not found: src/backend/config\n'));
227
+ process.exit(0);
228
+ }
229
+ // meta
230
+ const meta = getEnvMeta(configMeta);
231
+ configDir = path.join(configOptions.appDir, 'src/backend/config/config');
232
+ const files = getEnvFiles(meta, configDir, 'config', '.ts');
233
+ const filenames = files.map(item => path.basename(item));
234
+ const imports = [];
235
+ const constNames = [];
236
+ for (const filename of filenames) {
237
+ const parts = filename.split('.');
238
+ let constName = parts[0];
239
+ for (let index = 1; index < parts.length - 1; index++) {
240
+ constName += parts[index].charAt(0).toUpperCase() + parts[index].substring(1);
241
+ }
242
+ imports.push(`import ${constName} from '../src/backend/config/config/${filename}';`);
243
+ constNames.push(constName);
244
+ }
245
+ const contentDest = `${imports.join('\n')}\nexport default [${constNames.join(', ')}];`;
246
+ // output
247
+ const fileDest = path.join(configOptions.appDir, configOptions.runtimeDir, 'config.ts');
248
+ fse.ensureFileSync(fileDest);
249
+ fse.writeFileSync(fileDest, contentDest, 'utf-8');
250
+ }
251
+ async function __generateApp() {
252
+ const templates = [['app/bootstrap.ejs', 'bootstrap.ts'], ['app/app.ejs', 'app.ts']];
253
+ for (const [templateSrc, templateDest] of templates) {
254
+ const fileSrc = resolveTemplatePath(templateSrc);
255
+ const fileDest = path.join(configOptions.appDir, configOptions.runtimeDir, templateDest);
256
+ await fse.ensureDir(path.join(configOptions.appDir, configOptions.runtimeDir));
257
+ const vars = {
258
+ appMonkey: fse.existsSync(path.join(configOptions.appDir, 'src/backend/config/monkey.ts'))
259
+ };
260
+ await copyTemplateFile(fileSrc, fileDest, vars);
261
+ }
262
+ }
263
+ async function __generateOthers() {
264
+ const templates = [['app/register.js', 'register.js']];
265
+ for (const [templateSrc, templateDest] of templates) {
266
+ const fileSrc = resolveTemplatePath(templateSrc);
267
+ const fileDest = path.join(configOptions.appDir, configOptions.runtimeDir, templateDest);
268
+ await fse.ensureDir(path.join(configOptions.appDir, configOptions.runtimeDir));
269
+ const vars = {};
270
+ await copyTemplateFile(fileSrc, fileDest, vars);
271
+ }
272
+ }
273
+ async function __generateModulesMeta() {
274
+ // modules
275
+ const {
276
+ modules,
277
+ modulesArray
278
+ } = modulesMeta;
279
+ const moduleNames = modulesArray.map(item => item.info.relativeName);
280
+ // src
281
+ const fileSrc = resolveTemplatePath('app/vona-modules-meta.ejs');
282
+ const fileDest = path.join(configOptions.appDir, configOptions.runtimeDir, 'modules-meta.ts');
283
+ await fse.ensureDir(path.join(configOptions.appDir, configOptions.runtimeDir));
284
+ await copyTemplateFile(fileSrc, fileDest, {
285
+ modules,
286
+ moduleNames
287
+ });
288
+ }
289
+ async function __generateEnvJson() {
290
+ const contentDest = `export default ${JSON.stringify(env, null, 2)} as unknown as NodeJS.ProcessEnv;\n`;
291
+ // output
292
+ const fileDest = path.join(configOptions.appDir, configOptions.runtimeDir, 'env.ts');
293
+ fse.ensureFileSync(fileDest);
294
+ fse.writeFileSync(fileDest, contentDest, 'utf-8');
295
+ }
296
+ }
297
+
298
+ async function generateVonaMeta(configMeta, configOptions) {
299
+ // config utils
300
+ const configUtils = createConfigUtils(configMeta, configOptions);
301
+ // env
302
+ const env = configUtils.loadEnvs();
303
+ // modulesMeta
304
+ const modulesMeta = await configUtils.loadModulesMeta();
305
+ // generateEntryFiles
306
+ await generateEntryFiles(configMeta, configOptions, modulesMeta, env);
307
+ // ok
308
+ return {
309
+ env,
310
+ modulesMeta
311
+ };
312
+ }
313
+
314
+ const commonjs$2 = commonjsImport;
315
+ const resolve$2 = resolveImport;
316
+ // const swc = swcImport as any as typeof swcImport.default;
317
+ const json$2 = jsonImport;
318
+ const babel$2 = babelImport;
319
+ const terser$2 = terserImport;
320
+ const alias$2 = aliasImport;
321
+ const replace = replaceImport;
322
+ const __dialectDriversAll = ['pg', 'mysql2', 'better-sqlite3', 'mysql', 'oracledb', 'pg-native', 'pg-query-stream', 'sqlite3', 'tedious', 'cloudflare:sockets'];
323
+ class CliBinBuild extends BeanCliBase {
324
+ async execute() {
325
+ const {
326
+ argv
327
+ } = this.context;
328
+ // super
329
+ await super.execute();
330
+ const projectPath = argv.projectPath;
331
+ await this._build(projectPath);
332
+ }
333
+ async _build(projectPath) {
334
+ const {
335
+ argv
336
+ } = this.context;
337
+ const mode = 'prod';
338
+ const flavor = argv.flavor || 'normal';
339
+ const configMeta = {
340
+ flavor,
341
+ mode
342
+ };
343
+ const configOptions = {
344
+ appDir: projectPath,
345
+ runtimeDir: '.vona',
346
+ workers: argv.workers
347
+ };
348
+ const {
349
+ env,
350
+ modulesMeta
351
+ } = await generateVonaMeta(configMeta, configOptions);
352
+ const outDir = path.join(projectPath, getOutDir());
353
+ await rimraf(outDir);
354
+ await this._rollup(projectPath, env, outDir);
355
+ await this._assets(projectPath, modulesMeta, outDir);
356
+ // custom
357
+ await this._custom(projectPath, env, outDir);
358
+ // remove .vona
359
+ await rimraf(path.join(projectPath, '.vona'));
360
+ // copy
361
+ const outReleasesDir = path.join(projectPath, getOutReleasesDir());
362
+ await rimraf(outReleasesDir);
363
+ fse.copySync(outDir, outReleasesDir);
364
+ // copy
365
+ if (process.env.BUILD_COPY_DIST) {
366
+ const envDist = path.isAbsolute(process.env.BUILD_COPY_DIST) ? process.env.BUILD_COPY_DIST : path.join(projectPath, process.env.BUILD_COPY_DIST);
367
+ const outDirCopy = path.join(envDist, path.basename(outDir));
368
+ fse.removeSync(outDirCopy);
369
+ fse.copySync(outDir, outDirCopy);
370
+ }
371
+ if (process.env.BUILD_COPY_RELEASE) {
372
+ const envRelease = path.isAbsolute(process.env.BUILD_COPY_RELEASE) ? process.env.BUILD_COPY_RELEASE : path.join(projectPath, process.env.BUILD_COPY_RELEASE);
373
+ const outReleasesDirCopy = path.join(envRelease, path.basename(outReleasesDir));
374
+ fse.removeSync(outReleasesDirCopy);
375
+ fse.copySync(outDir, outReleasesDirCopy);
376
+ }
377
+ }
378
+ async _custom(projectPath, env, outDir) {
379
+ // custom
380
+ const jsFile = path.join(projectPath, 'src/backend/cli.ts');
381
+ if (!fse.existsSync(jsFile)) return;
382
+ return await this.helper.importDynamic(jsFile, async instance => {
383
+ const options = {
384
+ cli: this,
385
+ env,
386
+ outDir,
387
+ projectPath
388
+ };
389
+ return await instance.afterBuild(options);
390
+ });
391
+ }
392
+ async _assets(_projectPath, modulesMeta, outDir) {
393
+ const assetsPath = path.join(outDir, 'assets');
394
+ for (const relativeName in modulesMeta.modules) {
395
+ const module = modulesMeta.modules[relativeName];
396
+ const scenes = await globby('assets/*', {
397
+ cwd: module.root,
398
+ onlyDirectories: true
399
+ });
400
+ for (const scene2 of scenes) {
401
+ const scene = scene2.substring('assets/'.length);
402
+ const scenePath = path.join(module.root, scene2);
403
+ const destPath = path.join(assetsPath, scene, relativeName);
404
+ await fse.copy(scenePath, destPath);
405
+ }
406
+ }
407
+ }
408
+ async _rollup(projectPath, env, outDir) {
409
+ const aliasEntries = [];
410
+ const dialectDrivers = (process.env.BUILD_DIALECT_DRIVERS || '').split(',');
411
+ for (const name of __dialectDriversAll) {
412
+ if (dialectDrivers.includes(name)) continue;
413
+ aliasEntries.push({
414
+ find: name,
415
+ replacement: 'vona-shared'
416
+ });
417
+ }
418
+ const replaceValues = generateConfigDefine(env, ['NODE_ENV', 'META_MODE', 'META_FLAVOR']);
419
+ const babelPluginZovaBeanModule = getAbsolutePathOfModule('babel-plugin-zova-bean-module', '');
420
+ const babelPluginTransformTypescriptMetadata = getAbsolutePathOfModule('babel-plugin-transform-typescript-metadata', '');
421
+ const babelPluginProposalDecorators = getAbsolutePathOfModule('@babel/plugin-proposal-decorators', '');
422
+ const babelPluginTransformClassProperties = getAbsolutePathOfModule('@babel/plugin-transform-class-properties', '');
423
+ const babelPluginTransformTypescript = getAbsolutePathOfModule('@babel/plugin-transform-typescript', '');
424
+ const plugins = [alias$2({
425
+ entries: aliasEntries
426
+ }), resolve$2({
427
+ preferBuiltins: true
428
+ }), replace({
429
+ values: replaceValues,
430
+ preventAssignment: false
431
+ }), json$2(), commonjs$2(), babel$2({
432
+ include: '**/*.ts',
433
+ extensions: ['.ts', '.tsx'],
434
+ babelHelpers: 'bundled',
435
+ skipPreflightCheck: true,
436
+ babelrc: false,
437
+ configFile: false,
438
+ plugins: [[babelPluginZovaBeanModule, {
439
+ brandName: 'vona'
440
+ }], [babelPluginTransformTypescriptMetadata], [babelPluginProposalDecorators, {
441
+ version: 'legacy'
442
+ }], [babelPluginTransformClassProperties, {
443
+ loose: true
444
+ }], [babelPluginTransformTypescript]]
445
+ })];
446
+ if (process.env.BUILD_MINIFY === 'true') {
447
+ plugins.push(terser$2({
448
+ keep_classnames: true
449
+ }));
450
+ }
451
+ const inputOptions = {
452
+ input: path.join(projectPath, '.vona/bootstrap.ts'),
453
+ plugins,
454
+ onLog: (level, log, defaultHandler) => {
455
+ if (log.code === 'CIRCULAR_DEPENDENCY' && process.env.BUILD_LOG_CIRCULAR_DEPENDENCY === 'false') return;
456
+ if (log.code === 'THIS_IS_UNDEFINED' && (log.message.includes('ramda/es/partialObject.js') || log.message.includes("The 'this' keyword is equivalent to 'undefined' at the top level of an ES module"))) return;
457
+ if (log.code === 'EVAL' && log.message.includes('depd/index.js')) return;
458
+ if (log.code === 'EVAL' && log.message.includes('bluebird/js/release/util.js')) return;
459
+ defaultHandler(level, log);
460
+ }
461
+ };
462
+ const outputOption = {
463
+ dir: outDir,
464
+ // file: path.join(projectPath, 'dist/index.js'),
465
+ format: 'esm',
466
+ sourcemap: process.env.BUILD_SOURCEMAP === 'true',
467
+ // https://github.com/rollup/rollup/issues/4166
468
+ inlineDynamicImports: false // should not true
469
+ };
470
+ let bundle;
471
+ try {
472
+ bundle = await rollup(inputOptions);
473
+ await bundle.write(outputOption);
474
+ } finally {
475
+ if (bundle) {
476
+ // closes the bundle
477
+ await bundle.close();
478
+ }
479
+ }
480
+ }
481
+ }
482
+
483
+ const commonjs$1 = commonjsImport;
484
+ const resolve$1 = resolveImport;
485
+ // const swc = swcImport as any as typeof swcImport.default;
486
+ const json$1 = jsonImport;
487
+ const babel$1 = babelImport;
488
+ const terser$1 = terserImport;
489
+ const alias$1 = aliasImport;
490
+ class CliBinBuildGeneral extends BeanCliBase {
491
+ async execute() {
492
+ const {
493
+ argv
494
+ } = this.context;
495
+ // super
496
+ await super.execute();
497
+ const projectPath = argv.projectPath;
498
+ await this._build(projectPath);
499
+ }
500
+ async _build(projectPath) {
501
+ await rimraf(path.join(projectPath, 'dist'));
502
+ await this._rollup(projectPath);
503
+ }
504
+ async _rollup(projectPath) {
505
+ const {
506
+ argv
507
+ } = this.context;
508
+ const aliasEntries = [];
509
+ const plugins = [alias$1({
510
+ entries: aliasEntries
511
+ }), resolve$1({
512
+ preferBuiltins: true
513
+ }), json$1(), commonjs$1(), babel$1({
514
+ include: '**/*.ts',
515
+ extensions: ['.ts', '.tsx'],
516
+ babelHelpers: 'bundled',
517
+ skipPreflightCheck: true,
518
+ babelrc: false,
519
+ configFile: false,
520
+ plugins: [['babel-plugin-transform-typescript-metadata'], ['@babel/plugin-proposal-decorators', {
521
+ version: 'legacy'
522
+ }], ['@babel/plugin-transform-class-properties', {
523
+ loose: true
524
+ }], ['@babel/plugin-transform-typescript']]
525
+ })];
526
+ if (argv.minify) {
527
+ plugins.push(terser$1({
528
+ keep_classnames: true
529
+ }));
530
+ }
531
+ const inputOptions = {
532
+ input: path.join(projectPath, 'src/index.ts'),
533
+ plugins,
534
+ onLog: (level, log, defaultHandler) => {
535
+ if (log.code === 'CIRCULAR_DEPENDENCY') return;
536
+ if (log.code === 'THIS_IS_UNDEFINED' && (log.message.includes('ramda/es/partialObject.js') || log.message.includes("The 'this' keyword is equivalent to 'undefined' at the top level of an ES module"))) return;
537
+ if (log.code === 'EVAL' && log.message.includes('depd/index.js')) return;
538
+ if (log.code === 'EVAL' && log.message.includes('bluebird/js/release/util.js')) return;
539
+ defaultHandler(level, log);
540
+ },
541
+ external(source, _importer, _isResolved) {
542
+ if (source.includes('/src/') || source.startsWith('.')) return false;
543
+ return true;
544
+ }
545
+ };
546
+ const outputOption = {
547
+ dir: path.join(projectPath, 'dist'),
548
+ // file: path.join(projectPath, 'dist/index.js'),
549
+ format: 'esm',
550
+ sourcemap: argv.sourcemap,
551
+ // https://github.com/rollup/rollup/issues/4166
552
+ inlineDynamicImports: true
553
+ };
554
+ let bundle;
555
+ try {
556
+ bundle = await rollup(inputOptions);
557
+ await bundle.write(outputOption);
558
+ } finally {
559
+ if (bundle) {
560
+ // closes the bundle
561
+ await bundle.close();
562
+ }
563
+ }
564
+ }
565
+ }
566
+
567
+ const commonjs = commonjsImport;
568
+ const resolve = resolveImport;
569
+ // const swc = swcImport as any as typeof swcImport.default;
570
+ const json = jsonImport;
571
+ const babel = babelImport;
572
+ const terser = terserImport;
573
+ const alias = aliasImport;
574
+ class CliBinBuildModule extends BeanCliBase {
575
+ async execute() {
576
+ const {
577
+ argv
578
+ } = this.context;
579
+ // super
580
+ await super.execute();
581
+ const projectPath = argv.projectPath;
582
+ await this._build(projectPath);
583
+ }
584
+ async _build(projectPath) {
585
+ await rimraf(path.join(projectPath, 'dist'));
586
+ await this._rollup(projectPath);
587
+ }
588
+ async _rollup(projectPath) {
589
+ const {
590
+ argv
591
+ } = this.context;
592
+ const aliasEntries = [];
593
+ for (const name of ['better-sqlite3', 'mysql', 'oracledb', 'pg-native', 'pg-query-stream', 'sqlite3', 'tedious', 'cloudflare:sockets']) {
594
+ aliasEntries.push({
595
+ find: name,
596
+ replacement: 'vona-shared'
597
+ });
598
+ }
599
+ const plugins = [alias({
600
+ entries: aliasEntries
601
+ }), resolve({
602
+ preferBuiltins: true
603
+ }), json(), commonjs(), babel({
604
+ include: '**/*.ts',
605
+ extensions: ['.ts', '.tsx'],
606
+ babelHelpers: 'bundled',
607
+ skipPreflightCheck: true,
608
+ babelrc: false,
609
+ configFile: false,
610
+ plugins: [['babel-plugin-zova-bean-module', {
611
+ brandName: 'vona'
612
+ }], ['babel-plugin-transform-typescript-metadata'], ['@babel/plugin-proposal-decorators', {
613
+ version: 'legacy'
614
+ }], ['@babel/plugin-transform-class-properties', {
615
+ loose: true
616
+ }], ['@babel/plugin-transform-typescript']]
617
+ })];
618
+ if (argv.minify) {
619
+ plugins.push(terser({
620
+ keep_classnames: true
621
+ }));
622
+ }
623
+ const inputOptions = {
624
+ input: path.join(projectPath, 'src/index.ts'),
625
+ plugins,
626
+ onLog: (level, log, defaultHandler) => {
627
+ if (log.code === 'CIRCULAR_DEPENDENCY') return;
628
+ if (log.code === 'THIS_IS_UNDEFINED' && (log.message.includes('ramda/es/partialObject.js') || log.message.includes("The 'this' keyword is equivalent to 'undefined' at the top level of an ES module"))) return;
629
+ if (log.code === 'EVAL' && log.message.includes('depd/index.js')) return;
630
+ if (log.code === 'EVAL' && log.message.includes('bluebird/js/release/util.js')) return;
631
+ defaultHandler(level, log);
632
+ },
633
+ external(source, _importer, _isResolved) {
634
+ if (source.includes('/src/') || source.startsWith('.')) return false;
635
+ return true;
636
+ }
637
+ };
638
+ const outputOption = {
639
+ dir: path.join(projectPath, 'dist'),
640
+ // file: path.join(projectPath, 'dist/index.js'),
641
+ format: 'esm',
642
+ sourcemap: argv.sourcemap,
643
+ // https://github.com/rollup/rollup/issues/4166
644
+ inlineDynamicImports: true
645
+ };
646
+ let bundle;
647
+ try {
648
+ bundle = await rollup(inputOptions);
649
+ await bundle.write(outputOption);
650
+ } finally {
651
+ if (bundle) {
652
+ // closes the bundle
653
+ await bundle.close();
654
+ }
655
+ }
656
+ }
657
+ }
658
+
659
+ class CliBinDbReset extends BeanCliBase {
660
+ async execute() {
661
+ const {
662
+ argv
663
+ } = this.context;
664
+ // super
665
+ await super.execute();
666
+ const projectPath = argv.projectPath;
667
+ // test
668
+ await this._dbReset(projectPath);
669
+ }
670
+ async _dbReset(projectPath) {
671
+ const {
672
+ argv
673
+ } = this.context;
674
+ const mode = 'test';
675
+ const flavor = argv.flavor || 'normal';
676
+ const configMeta = {
677
+ flavor,
678
+ mode
679
+ };
680
+ const configOptions = {
681
+ appDir: projectPath,
682
+ runtimeDir: '.vona',
683
+ workers: 1
684
+ };
685
+ const {
686
+ modulesMeta
687
+ } = await generateVonaMeta(configMeta, configOptions);
688
+ await this._run(projectPath, modulesMeta);
689
+ await rimraf(path.join(projectPath, '.vona'));
690
+ }
691
+ async _run(projectPath, _modulesMeta) {
692
+ // testFile
693
+ let testFile = path.join(import.meta.dirname, './toolsIsolate/dbReset.ts');
694
+ if (!fse.existsSync(testFile)) {
695
+ testFile = path.join(import.meta.dirname, './toolsIsolate/dbReset.js');
696
+ }
697
+ // run
698
+ let args = [];
699
+ args = args.concat([getImportEsm(), testFile, projectPath]);
700
+ // args = args.concat(['--experimental-transform-types', getImportEsm(), testFile, projectPath]);
701
+ await this.helper.spawnExe({
702
+ cmd: 'node',
703
+ args,
704
+ options: {
705
+ cwd: projectPath
706
+ }
707
+ });
708
+ }
709
+ }
710
+
711
+ class CliBinDev extends BeanCliBase {
712
+ async execute() {
713
+ const {
714
+ argv
715
+ } = this.context;
716
+ // super
717
+ await super.execute();
718
+ const projectPath = argv.projectPath;
719
+ // run
720
+ await this._dev(projectPath);
721
+ }
722
+ async _dev(projectPath) {
723
+ const {
724
+ argv
725
+ } = this.context;
726
+ const mode = 'dev';
727
+ const flavor = argv.flavor || 'normal';
728
+ const configMeta = {
729
+ flavor,
730
+ mode
731
+ };
732
+ const configOptions = {
733
+ appDir: projectPath,
734
+ runtimeDir: '.vona',
735
+ workers: argv.workers
736
+ };
737
+ const {
738
+ modulesMeta
739
+ } = await generateVonaMeta(configMeta, configOptions);
740
+ await this._run(projectPath, modulesMeta);
741
+ await rimraf(path.join(projectPath, '.vona'));
742
+ }
743
+ async _run(projectPath, _modulesMeta) {
744
+ let closed = false;
745
+ return new Promise((resolve, _reject) => {
746
+ nodemon({
747
+ script: '.vona/bootstrap.ts',
748
+ cwd: projectPath,
749
+ exec: 'node',
750
+ execArgs: [getImportEsm()],
751
+ // execArgs: ['--experimental-transform-types', getImportEsm(), '--trace-deprecation'],
752
+ // signal: 'SIGHUP',
753
+ watch: ['packages-utils', 'packages-vona', './src'],
754
+ ignore: ['**/node_modules/**', '**/dist/**', '**/test/**/*.test.ts', 'src/backend/play/**', 'src/backend/typing/**', '**/src/config/errors.ts', '**/src/config/locale/*.ts', '**/src/config/config.ts', '**/src/config/constants.ts', '**/src/types/**', '**/src/controller/*.ts', '**/src/model/*.ts', '**/src/service/*.ts', '**/src/bean/*.*.ts']
755
+ });
756
+ nodemon.on('quit', () => {
757
+ closed = true;
758
+ resolve(undefined);
759
+ }).on('restart', files => {
760
+ if (closed) {
761
+ // force exit
762
+ process.exit(0);
763
+ }
764
+ // eslint-disable-next-line
765
+ console.log('App restarted due to: ', files);
766
+ });
767
+ });
768
+ // await this.helper.spawnExe({
769
+ // cmd: 'node',
770
+ // args: ['--experimental-transform-types', '--loader=ts-node/esm', '.vona/bootstrap.ts'],
771
+ // options: {
772
+ // cwd: projectPath,
773
+ // },
774
+ // });
775
+ }
776
+ }
777
+
778
+ class CliBinPlay extends BeanCliBase {
779
+ async execute() {
780
+ const {
781
+ argv
782
+ } = this.context;
783
+ // super
784
+ await super.execute();
785
+ const projectPath = argv.projectPath;
786
+ // test
787
+ await this._play(projectPath);
788
+ }
789
+ async _play(projectPath) {
790
+ const {
791
+ argv
792
+ } = this.context;
793
+ const mode = argv.mode || 'dev';
794
+ const flavor = argv.flavor || 'play';
795
+ const configMeta = {
796
+ flavor,
797
+ mode
798
+ };
799
+ if (!argv.retainRuntime || !fse.existsSync(path.join(projectPath, '.vona'))) {
800
+ const configOptions = {
801
+ appDir: projectPath,
802
+ runtimeDir: '.vona',
803
+ workers: 1
804
+ };
805
+ await generateVonaMeta(configMeta, configOptions);
806
+ }
807
+ if (argv.attach) {
808
+ await this._runAttach(projectPath);
809
+ } else {
810
+ await this._runIsolate(projectPath);
811
+ }
812
+ }
813
+ async _runAttach(projectPath) {
814
+ const runtimeFile = path.join(projectPath, '.app/runtime/-.json');
815
+ if (!fse.existsSync(runtimeFile)) throw new Error('dev server not running');
816
+ // args
817
+ let args = [];
818
+ const pos = process.argv.indexOf(':bin:play');
819
+ if (pos > -1) {
820
+ args = args.concat(process.argv.slice(pos + 1));
821
+ }
822
+ const body = {
823
+ args,
824
+ projectPath
825
+ };
826
+ //
827
+ const runtime = await loadJSONFile(runtimeFile);
828
+ const runtimeCore = runtime['a-core'];
829
+ const runtimeUser = runtime['a-user'];
830
+ const result = await fetch(`${runtimeCore?.protocol}://${runtimeCore?.host}/api/play`, {
831
+ method: 'post',
832
+ headers: {
833
+ 'content-type': 'application/json',
834
+ 'authorization': `Bearer ${runtimeUser?.accessToken}`
835
+ },
836
+ body: JSON.stringify(body)
837
+ });
838
+ if (result.status !== 200) {
839
+ const message = `error: ${result.status}, ${result.statusText}`;
840
+ throw new Error(message);
841
+ }
842
+ const res = await result.json();
843
+ if (res.code !== 0) throw new Error(res.message);
844
+ if (res.data !== undefined) {
845
+ // eslint-disable-next-line no-console
846
+ console.log(res.data);
847
+ }
848
+ }
849
+ async _runIsolate(projectPath) {
850
+ // testFile
851
+ let testFile = path.join(import.meta.dirname, './toolsIsolate/play.ts');
852
+ if (!fse.existsSync(testFile)) {
853
+ testFile = path.join(import.meta.dirname, './toolsIsolate/play.js');
854
+ }
855
+ // run
856
+ let args = [];
857
+ args = args.concat([getImportEsm(), testFile, projectPath]);
858
+ // args = args.concat(['--experimental-transform-types', getImportEsm(), testFile, projectPath]);
859
+ const pos = process.argv.indexOf(':bin:play');
860
+ if (pos > -1) {
861
+ args = args.concat(process.argv.slice(pos + 1));
862
+ }
863
+ await this.helper.spawnExe({
864
+ cmd: 'node',
865
+ args,
866
+ options: {
867
+ cwd: projectPath
868
+ }
869
+ });
870
+ }
871
+ }
872
+
873
+ class CliBinTest extends BeanCliBase {
874
+ async execute() {
875
+ const {
876
+ argv
877
+ } = this.context;
878
+ // super
879
+ await super.execute();
880
+ const projectPath = argv.projectPath;
881
+ // test
882
+ await this._test(projectPath);
883
+ }
884
+ async _test(projectPath) {
885
+ const {
886
+ argv
887
+ } = this.context;
888
+ const mode = 'test';
889
+ const flavor = argv.flavor || 'normal';
890
+ const configMeta = {
891
+ flavor,
892
+ mode
893
+ };
894
+ const configOptions = {
895
+ appDir: projectPath,
896
+ runtimeDir: '.vona',
897
+ workers: 1
898
+ };
899
+ const {
900
+ modulesMeta
901
+ } = await generateVonaMeta(configMeta, configOptions);
902
+ await this._run(projectPath, modulesMeta);
903
+ if (argv.coverage && !argv.ci) {
904
+ await this._outputCoverageReportViewer(projectPath);
905
+ }
906
+ await rimraf(path.join(projectPath, '.vona'));
907
+ }
908
+ async _run(projectPath, modulesMeta) {
909
+ const {
910
+ argv
911
+ } = this.context;
912
+ // globs
913
+ const patterns = this._combineTestPatterns(projectPath, modulesMeta);
914
+ // testFile
915
+ let testFile = path.join(import.meta.dirname, './toolsIsolate/test.ts');
916
+ if (!fse.existsSync(testFile)) {
917
+ testFile = path.join(import.meta.dirname, './toolsIsolate/test.js');
918
+ }
919
+ // run
920
+ let args = [];
921
+ if (argv.coverage) {
922
+ args.push('--experimental-test-coverage');
923
+ }
924
+ if (process.env.TEST_WHYISNODERUNNING === 'true') {
925
+ args.push('--import=why-is-node-running/include');
926
+ }
927
+ args = args.concat([getImportEsm(), testFile, projectPath, (!!argv.coverage).toString(), patterns.join(',')]);
928
+ // args = args.concat(['--experimental-transform-types', getImportEsm(), testFile, projectPath, (!!argv.coverage).toString(), patterns.join(',')]);
929
+ // ignore error special in windows
930
+ await catchError(() => {
931
+ return this.helper.spawnExe({
932
+ cmd: 'node',
933
+ args,
934
+ options: {
935
+ cwd: projectPath
936
+ }
937
+ });
938
+ });
939
+ }
940
+ async _outputCoverageReportViewer(projectPath) {
941
+ // lcovCliFile
942
+ const lcovCliFile = getAbsolutePathOfModule('@lcov-viewer/cli/lib/index.js', '');
943
+ // run
944
+ const args = [lcovCliFile, 'lcov', '-o', './coverage/report', './coverage/lcov.info'];
945
+ await catchError(() => {
946
+ return this.helper.spawnExe({
947
+ cmd: 'node',
948
+ args,
949
+ options: {
950
+ cwd: projectPath
951
+ }
952
+ });
953
+ });
954
+ }
955
+ _combineTestPatterns(projectPath, modulesMeta) {
956
+ const patterns = [];
957
+ for (const moduleName in modulesMeta.modules) {
958
+ const module = modulesMeta.modules[moduleName];
959
+ if (module.info.node_modules) continue;
960
+ const testDir = path.join(module.root, 'test');
961
+ if (fse.existsSync(testDir)) {
962
+ const relativePath = path.relative(projectPath, module.root).replaceAll('\\', '/');
963
+ patterns.push(`${relativePath}/test/**/*.ts`);
964
+ }
965
+ }
966
+ return patterns;
967
+ }
968
+ }
969
+
970
+ class CliBinTsc extends BeanCliBase {
971
+ async execute() {
972
+ const {
973
+ argv
974
+ } = this.context;
975
+ // super
976
+ await super.execute();
977
+ const projectPath = argv.projectPath;
978
+ const force = argv.force;
979
+ await this._tsc(projectPath, force);
980
+ }
981
+ async _tsc(projectPath, force) {
982
+ const suiteNames = Object.keys(this.modulesMeta.suites).filter(suiteName => !this.modulesMeta.suites[suiteName].info.node_modules);
983
+ const modulesArray = this.modulesMeta.modulesArray.filter(item => !item.suite && !item.info.node_modules);
984
+ // count
985
+ const count = 1 + suiteNames.length + modulesArray.length;
986
+ // begin
987
+ let counter = 0;
988
+ const timeBegin = new Date();
989
+ // eslint-disable-next-line
990
+ console.log('===> build begin');
991
+ // args
992
+ const tscArgs = ['-b'];
993
+ if (force) {
994
+ tscArgs.push('--force');
995
+ }
996
+ // tsc: project
997
+ // eslint-disable-next-line
998
+ console.log(`===> ${++counter}/${count} project`);
999
+ await this.helper.processHelper.tsc(tscArgs, {
1000
+ cwd: projectPath
1001
+ });
1002
+ // suites
1003
+ for (const key of suiteNames) {
1004
+ const suite = this.modulesMeta.suites[key];
1005
+ // eslint-disable-next-line
1006
+ console.log(`===> ${++counter}/${count} suite: ${suite.info.originalName}`);
1007
+ await this.helper.processHelper.tsc(tscArgs, {
1008
+ cwd: suite.root
1009
+ });
1010
+ }
1011
+ // modules
1012
+ for (const module of modulesArray) {
1013
+ // eslint-disable-next-line
1014
+ console.log(`===> ${++counter}/${count} module: ${module.info.originalName}`);
1015
+ await this.helper.processHelper.tsc(tscArgs, {
1016
+ cwd: module.root
1017
+ });
1018
+ }
1019
+ // end
1020
+ const timeEnd = new Date();
1021
+ // eslint-disable-next-line
1022
+ console.log(`===> build end: ${(timeEnd.valueOf() - timeBegin.valueOf()) / 1000}s`);
1023
+ }
1024
+ }
1025
+
1026
+ const __ThisSetName__ = 'api';
1027
+
1028
+ class CliCreateBean extends BeanCliBase {
1029
+ async execute() {
1030
+ const {
1031
+ argv
1032
+ } = this.context;
1033
+ // super
1034
+ await super.execute();
1035
+ // noformat
1036
+ argv.noformat = true;
1037
+ // module name/info
1038
+ const moduleName = argv.module;
1039
+ argv.moduleInfo = this.helper.parseModuleInfo(moduleName);
1040
+ // check if exists
1041
+ const _module = this.helper.findModule(moduleName);
1042
+ if (!_module) {
1043
+ throw new Error(`module does not exist: ${moduleName}`);
1044
+ }
1045
+ // target dir
1046
+ const targetDir = await this.helper.ensureDir(_module.root);
1047
+ // scene name
1048
+ const sceneName = argv.sceneName;
1049
+ argv.sceneNameCapitalize = this.helper.firstCharToUpperCase(sceneName);
1050
+ // scene meta
1051
+ // onionScenesMeta
1052
+ const onionScenesMeta = getOnionScenesMeta(this.modulesMeta.modules);
1053
+ const onionSceneMeta = onionScenesMeta[sceneName];
1054
+ // bean name
1055
+ const beanName = argv.beanName;
1056
+ argv.beanNameCapitalize = this.helper.firstCharToUpperCase(beanName);
1057
+ // moduleResourceName
1058
+ argv.moduleResourceName = this.helper.combineModuleNameAndResource(argv.moduleInfo.relativeName, argv.beanName);
1059
+ // directory
1060
+ const beanDir = path.join(targetDir, onionSceneMeta.sceneIsolate ? `src/${sceneName}` : 'src/bean');
1061
+ const beanFile = path.join(beanDir, onionSceneMeta.sceneIsolate ? `${beanName}.ts` : `${sceneName}.${beanName}.ts`);
1062
+ if (fs.existsSync(beanFile)) {
1063
+ throw new Error(`${sceneName} bean exists: ${beanName}`);
1064
+ }
1065
+ await this.helper.ensureDir(beanDir);
1066
+ // snippets/boilerplate
1067
+ const snippets = this._getBoilerplatesOrSnippets('snippets');
1068
+ const boilerplates = this._getBoilerplatesOrSnippets('boilerplate', argv.boilerplate);
1069
+ const snippetsName = snippets[`${sceneName}:${argv.beanName}`] || snippets[sceneName];
1070
+ const boilerplateName = boilerplates[`${sceneName}:${argv.beanName}`] || boilerplates[sceneName];
1071
+ // render
1072
+ await this.template.renderBoilerplateAndSnippets({
1073
+ targetDir: beanDir,
1074
+ setName: __ThisSetName__,
1075
+ snippetsPath: snippetsName,
1076
+ boilerplatePath: boilerplateName
1077
+ });
1078
+ // tools.metadata
1079
+ if (!argv.nometadata) {
1080
+ await this.helper.invokeCli([':tools:metadata', moduleName], {
1081
+ cwd: argv.projectPath
1082
+ });
1083
+ }
1084
+ }
1085
+ _getBoilerplatesOrSnippets(type, custom) {
1086
+ const type2 = custom ? `${type}${toUpperCaseFirstChar(custom)}` : type;
1087
+ const result = {};
1088
+ // scenes
1089
+ const onionScenesMeta = getOnionScenesMeta(this.modulesMeta.modules);
1090
+ for (const sceneName in onionScenesMeta) {
1091
+ const onionSceneMeta = onionScenesMeta[sceneName];
1092
+ const scenePath = onionSceneMeta[type2];
1093
+ if (scenePath) {
1094
+ result[sceneName] = path.join(onionSceneMeta.module.root, scenePath);
1095
+ }
1096
+ }
1097
+ // metas
1098
+ const onionMetasMeta = getOnionMetasMeta(this.modulesMeta.modules);
1099
+ for (const sceneName in onionMetasMeta) {
1100
+ const onionMetaMeta = onionMetasMeta[sceneName];
1101
+ const scenePath = onionMetaMeta[type2];
1102
+ if (scenePath) {
1103
+ result[`meta:${sceneName}`] = path.join(onionMetaMeta.module.root, scenePath);
1104
+ }
1105
+ }
1106
+ return result;
1107
+ }
1108
+ }
1109
+
1110
+ class CliCreateModule extends BeanCliBase {
1111
+ async execute() {
1112
+ const {
1113
+ argv
1114
+ } = this.context;
1115
+ // super
1116
+ await super.execute();
1117
+ // noformat
1118
+ argv.noformat = true;
1119
+ // suite name/info
1120
+ const suiteName = argv.suite;
1121
+ if (suiteName) {
1122
+ argv.suiteInfo = this.helper.parseSuiteInfo(suiteName);
1123
+ // check if exists
1124
+ argv._suite = this.helper.findSuite(suiteName);
1125
+ if (!argv._suite) {
1126
+ throw new Error(`suite does not exist: ${suiteName}`);
1127
+ }
1128
+ }
1129
+ // nameMeta
1130
+ const nameMeta = this.helper.parseNameMeta(argv.name);
1131
+ const moduleDir = nameMeta.directory || 'module';
1132
+ argv.name = nameMeta.short;
1133
+ // module name/info
1134
+ const moduleName = argv.name;
1135
+ argv.moduleInfo = this.helper.parseModuleInfo(moduleName);
1136
+ argv.relativeNameCapitalize = this.helper.stringToCapitalize(argv.moduleInfo.relativeName, '-');
1137
+ // check if exists
1138
+ const _module = this.helper.findModule(moduleName);
1139
+ if (!argv.force && _module) {
1140
+ throw new Error(`module exists: ${moduleName}`);
1141
+ }
1142
+ // target dir
1143
+ let targetDir;
1144
+ if (suiteName) {
1145
+ targetDir = path.join(argv._suite.root, 'modules', moduleName);
1146
+ } else {
1147
+ targetDir = path.join(argv.projectPath, `src/${moduleDir}`, moduleName);
1148
+ }
1149
+ if (!argv.force && fs.existsSync(targetDir)) {
1150
+ throw new Error(`module exists: ${moduleName}`);
1151
+ }
1152
+ // render module snippets for suite
1153
+ if (suiteName) {
1154
+ await this.template.renderBoilerplateAndSnippets({
1155
+ targetDir: argv._suite.root,
1156
+ setName: __ThisSetName__,
1157
+ snippetsPath: 'create/module/snippets',
1158
+ boilerplatePath: null
1159
+ });
1160
+ await this.helper.removeGitkeep(path.join(argv._suite.root, 'modules'));
1161
+ }
1162
+ // render module boilerplate
1163
+ targetDir = await this.helper.ensureDir(targetDir);
1164
+ await this.template.renderBoilerplateAndSnippets({
1165
+ targetDir,
1166
+ setName: __ThisSetName__,
1167
+ snippetsPath: null,
1168
+ boilerplatePath: 'create/module/boilerplate'
1169
+ });
1170
+ // tools.deps
1171
+ if (!argv.vscode) {
1172
+ await this.helper.invokeCli([':tools:deps'], {
1173
+ cwd: argv.projectPath
1174
+ });
1175
+ }
1176
+ // pnpm install
1177
+ if (!argv.vscode && !argv.ci) {
1178
+ await this.helper.pnpmInstall();
1179
+ }
1180
+ }
1181
+ }
1182
+
1183
+ class CliCreateProject extends BeanCliBase {
1184
+ constructor(options) {
1185
+ super(options);
1186
+ this.httpClient = void 0;
1187
+ this.httpClient = urllib;
1188
+ }
1189
+ async execute() {
1190
+ const {
1191
+ argv
1192
+ } = this.context;
1193
+ // super
1194
+ await super.execute();
1195
+ // noformat
1196
+ argv.noformat = true;
1197
+ // project name
1198
+ const projectName = argv.name;
1199
+ // target dir
1200
+ const targetDir = path.join(argv.projectPath, projectName);
1201
+ if (!argv.force && fs.existsSync(targetDir)) {
1202
+ throw new Error(`project exists: ${projectName}`);
1203
+ }
1204
+ fse.ensureDirSync(targetDir);
1205
+ // vars
1206
+ argv.SERVER_KEYS = `vona_${uuid.v4()}_${Date.now()}_${random(100, 10000)}`;
1207
+ argv.SERVER_KEYS_PROD = `vona_${uuid.v4()}_${Date.now()}_${random(100, 10000)}`;
1208
+ argv.DATABASE_CLIENT_MYSQL_USER = 'web_user';
1209
+ argv.DATABASE_CLIENT_MYSQL_PASSWORD = randomize('*', 16, {
1210
+ exclude: '\\\'"$'
1211
+ });
1212
+ argv.DATABASE_CLIENT_MYSQL_PASSWORD_ROOT = randomize('*', 16, {
1213
+ exclude: '\\\'"$'
1214
+ });
1215
+ argv.DATABASE_CLIENT_PG_USER = 'postgres';
1216
+ argv.DATABASE_CLIENT_PG_PASSWORD = randomize('*', 16, {
1217
+ exclude: '\\\'"$'
1218
+ });
1219
+ argv.DATABASE_CLIENT_PG_PASSWORD_ROOT = randomize('*', 16, {
1220
+ exclude: '\\\'"$'
1221
+ });
1222
+ // template
1223
+ const template = argv.template;
1224
+ // render project boilerplate
1225
+ await this.template.renderBoilerplateAndSnippets({
1226
+ targetDir,
1227
+ setName: __ThisSetName__,
1228
+ snippetsPath: null,
1229
+ boilerplatePath: `create/project/${template}/boilerplate`
1230
+ });
1231
+ // create docker-compose/data/pg
1232
+ fse.ensureDirSync(path.join(targetDir, 'docker-compose/data/pg'));
1233
+ // copy package.json
1234
+ fse.copyFileSync(path.join(targetDir, 'package.original.json'), path.join(targetDir, 'package.json'));
1235
+ // npm run init
1236
+ await this.helper.spawnCmd({
1237
+ cmd: 'npm',
1238
+ args: ['run', 'init'],
1239
+ options: {
1240
+ cwd: targetDir
1241
+ }
1242
+ });
1243
+ // done
1244
+ await this.printUsage(targetDir);
1245
+ }
1246
+ async printUsage(targetDir) {
1247
+ await this.console.log(`usage:
1248
+ - cd ${targetDir}
1249
+ - pnpm install
1250
+ - npm run dev
1251
+ - npm run test
1252
+ - npm run build
1253
+ - npm run start
1254
+ `);
1255
+ }
1256
+ async downloadBoilerplate(packageName) {
1257
+ const result = await this.getPackageInfo(packageName, false);
1258
+ const tgzUrl = result.dist.tarball;
1259
+ await this.console.log(`downloading ${tgzUrl}`);
1260
+ const saveDir = path.join(os.tmpdir(), 'zova-project-boilerplate');
1261
+ await rimraf(saveDir);
1262
+ const response = await this.curl(tgzUrl, {
1263
+ streaming: true,
1264
+ followRedirect: true
1265
+ });
1266
+ await compressing.tgz.uncompress(response.res, saveDir);
1267
+ await this.console.log(`extract to ${saveDir}`);
1268
+ return path.join(saveDir, '/package');
1269
+ }
1270
+ async getPackageInfo(packageName, withFallback) {
1271
+ await this.console.log(`fetching npm info of ${packageName}`);
1272
+ try {
1273
+ const registry = await this.helper.getRegistry();
1274
+ const result = await this.curl(`${registry}${packageName}/latest`, {
1275
+ dataType: 'json',
1276
+ followRedirect: true,
1277
+ maxRedirects: 5
1278
+ });
1279
+ if (result.status !== 200) {
1280
+ const message = `npm info ${packageName} got error: ${result.status}, ${result.data.reason}`;
1281
+ throw new Error(message);
1282
+ }
1283
+ return result.data;
1284
+ } catch (err) {
1285
+ if (withFallback) {
1286
+ await this.console.log(`use fallback from ${packageName}`);
1287
+ const require = createRequire(import.meta.url);
1288
+ return require(`${packageName}/package.json`);
1289
+ }
1290
+ throw err;
1291
+ }
1292
+ }
1293
+ async curl(url, options) {
1294
+ options = options || {};
1295
+ if (!options.timeout) {
1296
+ options.timeout = 30000;
1297
+ }
1298
+ return await this.httpClient.request(url, options);
1299
+ }
1300
+ }
1301
+ function random(start, end) {
1302
+ return Math.floor(Math.random() * (end - start) + start);
1303
+ }
1304
+
1305
+ class CliCreateSuite extends BeanCliBase {
1306
+ async execute() {
1307
+ const {
1308
+ argv
1309
+ } = this.context;
1310
+ // super
1311
+ await super.execute();
1312
+ // noformat
1313
+ argv.noformat = true;
1314
+ // nameMeta
1315
+ const nameMeta = this.helper.parseNameMeta(argv.name);
1316
+ const suiteDir = nameMeta.directory || 'suite';
1317
+ argv.name = nameMeta.short;
1318
+ // suite name/info
1319
+ const suiteName = argv.name;
1320
+ argv.suiteInfo = this.helper.parseSuiteInfo(suiteName);
1321
+ // check if exists
1322
+ const _suite = this.helper.findSuite(suiteName);
1323
+ if (_suite) {
1324
+ throw new Error(`suite exists: ${suiteName}`);
1325
+ }
1326
+ // target dir
1327
+ let targetDir = path.join(argv.projectPath, `src/${suiteDir}`, suiteName);
1328
+ if (fs.existsSync(targetDir)) {
1329
+ throw new Error(`suite exists: ${suiteName}`);
1330
+ }
1331
+ targetDir = await this.helper.ensureDir(targetDir);
1332
+ // templateDir
1333
+ const templateDir = this.template.resolveTemplatePath(__ThisSetName__, 'create/suite');
1334
+ // render
1335
+ await this.template.renderDir(targetDir, templateDir);
1336
+ }
1337
+ }
1338
+
1339
+ class CliCreateTest extends BeanCliBase {
1340
+ async execute() {
1341
+ const {
1342
+ argv
1343
+ } = this.context;
1344
+ // super
1345
+ await super.execute();
1346
+ // noformat
1347
+ argv.noformat = true;
1348
+ // module name/info
1349
+ const moduleName = argv.module;
1350
+ argv.moduleInfo = this.helper.parseModuleInfo(moduleName);
1351
+ // check if exists
1352
+ const _module = this.helper.findModule(moduleName);
1353
+ if (!_module) {
1354
+ throw new Error(`module does not exist: ${moduleName}`);
1355
+ }
1356
+ // target dir
1357
+ const targetDir = await this.helper.ensureDir(_module.root);
1358
+ // name
1359
+ argv.nameCapitalize = this.helper.firstCharToUpperCase(argv.name);
1360
+ // nameMeta
1361
+ argv.nameMeta = this.helper.parseNameMeta(argv.name, ['test']);
1362
+ // directory
1363
+ const testDir = path.join(targetDir, 'test');
1364
+ const testFile = path.join(testDir, `${argv.name}.test.ts`);
1365
+ if (fs.existsSync(testFile)) {
1366
+ throw new Error(`test exists: ${testFile}`);
1367
+ }
1368
+ await this.helper.ensureDir(testDir);
1369
+ // render boilerplate
1370
+ await this.template.renderBoilerplateAndSnippets({
1371
+ targetDir: testDir,
1372
+ setName: __ThisSetName__,
1373
+ snippetsPath: null,
1374
+ boilerplatePath: 'create/test/boilerplate'
1375
+ });
1376
+ }
1377
+ }
1378
+
1379
+ class CliDefaultList extends BeanCliBase {
1380
+ async execute() {
1381
+ const {
1382
+ argv
1383
+ } = this.context;
1384
+ // super
1385
+ await super.execute();
1386
+ // set/group
1387
+ const setWant = argv.set;
1388
+ let groupWant = argv.group;
1389
+ if (!setWant) groupWant = undefined;
1390
+ // commandsAll
1391
+ const commandsAll = (await getCommandsMeta()).all;
1392
+ // setsShow
1393
+ let setsShow;
1394
+ if (setWant) {
1395
+ if (!commandsAll[setWant]) throw new Error(`cli set not found: ${setWant}`);
1396
+ setsShow = [setWant];
1397
+ } else {
1398
+ setsShow = Object.keys(commandsAll);
1399
+ }
1400
+ // loop
1401
+ const total = setsShow.length;
1402
+ for (let index = 0; index < total; index++) {
1403
+ const setShow = setsShow[index];
1404
+ // log
1405
+ await this.console.log({
1406
+ total,
1407
+ progress: index,
1408
+ text: setShow
1409
+ });
1410
+ // show
1411
+ await this._setShow({
1412
+ setShow,
1413
+ groupWant,
1414
+ commandsAll
1415
+ });
1416
+ }
1417
+ // await this.console.log({ text: JSON.stringify(modulesWant) });
1418
+ }
1419
+ async _setShow({
1420
+ setShow,
1421
+ groupWant,
1422
+ commandsAll
1423
+ }) {
1424
+ // _set
1425
+ const _set = commandsAll[setShow];
1426
+ // groupsShow
1427
+ let groupsShow;
1428
+ if (groupWant) {
1429
+ if (!_set[groupWant]) throw new Error(`cli set group not found: ${setShow}:${groupWant}`);
1430
+ groupsShow = [groupWant];
1431
+ } else {
1432
+ groupsShow = Object.keys(_set);
1433
+ }
1434
+ // table
1435
+ const table = this.helper.newTable({
1436
+ head: ['Command', 'Version', 'Description'],
1437
+ colWidths: [30, 10, 40]
1438
+ });
1439
+ // group
1440
+ const groupCount = groupsShow.length;
1441
+ for (let index = 0; index < groupCount; index++) {
1442
+ const groupShow = groupsShow[index];
1443
+ const _group = _set[groupShow];
1444
+ for (const commandName in _group) {
1445
+ const _command = _group[commandName].command;
1446
+ const cliFullName = this._combineCliFullName({
1447
+ setShow,
1448
+ groupShow,
1449
+ commandName
1450
+ });
1451
+ const version = _command.info.version;
1452
+ const description = _command.info.description || _command.info.title;
1453
+ table.push([cliFullName, version, description]);
1454
+ }
1455
+ if (index < groupCount - 1) {
1456
+ table.push([]);
1457
+ }
1458
+ }
1459
+ // log
1460
+ await this.console.log({
1461
+ text: table.toString()
1462
+ });
1463
+ }
1464
+ _combineCliFullName({
1465
+ setShow,
1466
+ groupShow,
1467
+ commandName
1468
+ }) {
1469
+ const parts = [];
1470
+ if (setShow === 'api') {
1471
+ parts.push('');
1472
+ } else {
1473
+ parts.push(setShow);
1474
+ }
1475
+ if (groupShow === 'default') {
1476
+ parts.push('');
1477
+ } else {
1478
+ parts.push(groupShow);
1479
+ }
1480
+ parts.push(commandName);
1481
+ return parts.join(':');
1482
+ }
1483
+ }
1484
+
1485
+ class CliInitAppMonkey extends BeanCliBase {
1486
+ async execute() {
1487
+ const {
1488
+ argv
1489
+ } = this.context;
1490
+ // super
1491
+ await super.execute();
1492
+ // noformat
1493
+ argv.noformat = true;
1494
+ // target dir
1495
+ const targetDir = path.join(argv.projectPath, 'src/backend/config');
1496
+ const monkeyFile = path.join(targetDir, 'monkey.ts');
1497
+ if (fse.existsSync(monkeyFile)) {
1498
+ throw new Error('app monkey exists');
1499
+ }
1500
+ // render boilerplate
1501
+ await this.template.renderBoilerplateAndSnippets({
1502
+ targetDir,
1503
+ setName: __ThisSetName__,
1504
+ snippetsPath: null,
1505
+ boilerplatePath: 'init/appMonkey/boilerplate'
1506
+ });
1507
+ }
1508
+ }
1509
+
1510
+ class CliInitAsset extends BeanCliBase {
1511
+ async execute() {
1512
+ const {
1513
+ argv
1514
+ } = this.context;
1515
+ // super
1516
+ await super.execute();
1517
+ // noformat
1518
+ argv.noformat = true;
1519
+ // module name/info
1520
+ const moduleName = argv.module;
1521
+ argv.moduleInfo = this.helper.parseModuleInfo(moduleName);
1522
+ // check if exists
1523
+ const _module = this.helper.findModule(moduleName);
1524
+ if (!_module) {
1525
+ throw new Error(`module does not exist: ${moduleName}`);
1526
+ }
1527
+ // target dir
1528
+ const targetDir = await this.helper.ensureDir(_module.root);
1529
+ // scene
1530
+ const scene = argv.scene;
1531
+ // directory
1532
+ const assetDir = path.join(targetDir, 'assets', scene);
1533
+ if (fse.existsSync(assetDir)) {
1534
+ throw new Error(`asset exists: ${moduleName}/assets/${scene}`);
1535
+ }
1536
+ await this.helper.ensureDir(assetDir);
1537
+ }
1538
+ }
1539
+
1540
+ class CliInitConfig extends BeanCliBase {
1541
+ async execute() {
1542
+ const {
1543
+ argv
1544
+ } = this.context;
1545
+ // super
1546
+ await super.execute();
1547
+ // noformat
1548
+ argv.noformat = true;
1549
+ // module name/info
1550
+ const moduleName = argv._[0];
1551
+ if (!moduleName) return;
1552
+ argv.moduleInfo = this.helper.parseModuleInfo(moduleName);
1553
+ // check if exists
1554
+ const _module = this.helper.findModule(moduleName);
1555
+ if (!_module) {
1556
+ throw new Error(`module does not exist: ${moduleName}`);
1557
+ }
1558
+ // target dir
1559
+ const targetDir = await this.helper.ensureDir(_module.root);
1560
+ const configFile = path.join(targetDir, 'src/config/config.ts');
1561
+ if (fse.existsSync(configFile)) {
1562
+ throw new Error(`config exists: ${moduleName}`);
1563
+ }
1564
+ // render boilerplate
1565
+ await this.template.renderBoilerplateAndSnippets({
1566
+ targetDir: path.join(targetDir, 'src'),
1567
+ setName: __ThisSetName__,
1568
+ snippetsPath: null,
1569
+ boilerplatePath: 'init/config/boilerplate'
1570
+ });
1571
+ // tools.metadata
1572
+ if (!argv.nometadata) {
1573
+ await this.helper.invokeCli([':tools:metadata', moduleName], {
1574
+ cwd: argv.projectPath
1575
+ });
1576
+ }
1577
+ }
1578
+ }
1579
+
1580
+ class CliInitConstant extends BeanCliBase {
1581
+ async execute() {
1582
+ const {
1583
+ argv
1584
+ } = this.context;
1585
+ // super
1586
+ await super.execute();
1587
+ // noformat
1588
+ argv.noformat = true;
1589
+ // module name/info
1590
+ const moduleName = argv._[0];
1591
+ if (!moduleName) return;
1592
+ argv.moduleInfo = this.helper.parseModuleInfo(moduleName);
1593
+ // check if exists
1594
+ const _module = this.helper.findModule(moduleName);
1595
+ if (!_module) {
1596
+ throw new Error(`module does not exist: ${moduleName}`);
1597
+ }
1598
+ // target dir
1599
+ const targetDir = await this.helper.ensureDir(_module.root);
1600
+ const constantFile = path.join(targetDir, 'src/config/constants.ts');
1601
+ if (fse.existsSync(constantFile)) {
1602
+ throw new Error(`constant exists: ${moduleName}`);
1603
+ }
1604
+ // render boilerplate
1605
+ await this.template.renderBoilerplateAndSnippets({
1606
+ targetDir: path.join(targetDir, 'src'),
1607
+ setName: __ThisSetName__,
1608
+ snippetsPath: null,
1609
+ boilerplatePath: 'init/constant/boilerplate'
1610
+ });
1611
+ // tools.metadata
1612
+ if (!argv.nometadata) {
1613
+ await this.helper.invokeCli([':tools:metadata', moduleName], {
1614
+ cwd: argv.projectPath
1615
+ });
1616
+ }
1617
+ }
1618
+ }
1619
+
1620
+ class CliInitError extends BeanCliBase {
1621
+ async execute() {
1622
+ const {
1623
+ argv
1624
+ } = this.context;
1625
+ // super
1626
+ await super.execute();
1627
+ // noformat
1628
+ argv.noformat = true;
1629
+ // module name/info
1630
+ const moduleName = argv._[0];
1631
+ if (!moduleName) return;
1632
+ argv.moduleInfo = this.helper.parseModuleInfo(moduleName);
1633
+ // check if exists
1634
+ const _module = this.helper.findModule(moduleName);
1635
+ if (!_module) {
1636
+ throw new Error(`module does not exist: ${moduleName}`);
1637
+ }
1638
+ // target dir
1639
+ const targetDir = await this.helper.ensureDir(_module.root);
1640
+ const errorFile = path.join(targetDir, 'src/config/errors.ts');
1641
+ if (fse.existsSync(errorFile)) {
1642
+ throw new Error(`error exists: ${moduleName}`);
1643
+ }
1644
+ // render boilerplate
1645
+ await this.template.renderBoilerplateAndSnippets({
1646
+ targetDir: path.join(targetDir, 'src'),
1647
+ setName: __ThisSetName__,
1648
+ snippetsPath: null,
1649
+ boilerplatePath: 'init/error/boilerplate'
1650
+ });
1651
+ // special for locale
1652
+ const localeFile = path.join(targetDir, 'src/config/locale');
1653
+ if (!fse.existsSync(localeFile)) {
1654
+ // render boilerplate
1655
+ await this.template.renderBoilerplateAndSnippets({
1656
+ targetDir: path.join(targetDir, 'src'),
1657
+ setName: __ThisSetName__,
1658
+ snippetsPath: null,
1659
+ boilerplatePath: 'init/locale/boilerplate'
1660
+ });
1661
+ }
1662
+ // tools.metadata
1663
+ if (!argv.nometadata) {
1664
+ await this.helper.invokeCli([':tools:metadata', moduleName], {
1665
+ cwd: argv.projectPath
1666
+ });
1667
+ }
1668
+ }
1669
+ }
1670
+
1671
+ class CliInitLib extends BeanCliBase {
1672
+ async execute() {
1673
+ const {
1674
+ argv
1675
+ } = this.context;
1676
+ // super
1677
+ await super.execute();
1678
+ // noformat
1679
+ argv.noformat = true;
1680
+ // module name/info
1681
+ const moduleName = argv._[0];
1682
+ if (!moduleName) return;
1683
+ argv.moduleInfo = this.helper.parseModuleInfo(moduleName);
1684
+ // check if exists
1685
+ const _module = this.helper.findModule(moduleName);
1686
+ if (!_module) {
1687
+ throw new Error(`module does not exist: ${moduleName}`);
1688
+ }
1689
+ // target dir
1690
+ const targetDir = await this.helper.ensureDir(_module.root);
1691
+ const mainFile = path.join(targetDir, 'src/lib/index.ts');
1692
+ if (fse.existsSync(mainFile)) {
1693
+ throw new Error(`lib exists: ${moduleName}`);
1694
+ }
1695
+ // render boilerplate
1696
+ await this.template.renderBoilerplateAndSnippets({
1697
+ targetDir: path.join(targetDir, 'src'),
1698
+ setName: __ThisSetName__,
1699
+ snippetsPath: null,
1700
+ boilerplatePath: 'init/lib/boilerplate'
1701
+ });
1702
+ // tools.metadata
1703
+ if (!argv.nometadata) {
1704
+ await this.helper.invokeCli([':tools:metadata', moduleName], {
1705
+ cwd: argv.projectPath
1706
+ });
1707
+ }
1708
+ }
1709
+ }
1710
+
1711
+ class CliInitLocale extends BeanCliBase {
1712
+ async execute() {
1713
+ const {
1714
+ argv
1715
+ } = this.context;
1716
+ // super
1717
+ await super.execute();
1718
+ // noformat
1719
+ argv.noformat = true;
1720
+ // module name/info
1721
+ const moduleName = argv._[0];
1722
+ if (!moduleName) return;
1723
+ argv.moduleInfo = this.helper.parseModuleInfo(moduleName);
1724
+ // check if exists
1725
+ const _module = this.helper.findModule(moduleName);
1726
+ if (!_module) {
1727
+ throw new Error(`module does not exist: ${moduleName}`);
1728
+ }
1729
+ // target dir
1730
+ const targetDir = await this.helper.ensureDir(_module.root);
1731
+ const localeFile = path.join(targetDir, 'src/config/locale');
1732
+ if (fse.existsSync(localeFile)) {
1733
+ throw new Error(`locale exists: ${moduleName}`);
1734
+ }
1735
+ // render boilerplate
1736
+ await this.template.renderBoilerplateAndSnippets({
1737
+ targetDir: path.join(targetDir, 'src'),
1738
+ setName: __ThisSetName__,
1739
+ snippetsPath: null,
1740
+ boilerplatePath: 'init/locale/boilerplate'
1741
+ });
1742
+ // tools.metadata
1743
+ if (!argv.nometadata) {
1744
+ await this.helper.invokeCli([':tools:metadata', moduleName], {
1745
+ cwd: argv.projectPath
1746
+ });
1747
+ }
1748
+ }
1749
+ }
1750
+
1751
+ class CliInitMain extends BeanCliBase {
1752
+ async execute() {
1753
+ const {
1754
+ argv
1755
+ } = this.context;
1756
+ // super
1757
+ await super.execute();
1758
+ // noformat
1759
+ argv.noformat = true;
1760
+ // module name/info
1761
+ const moduleName = argv._[0];
1762
+ if (!moduleName) return;
1763
+ argv.moduleInfo = this.helper.parseModuleInfo(moduleName);
1764
+ // check if exists
1765
+ const _module = this.helper.findModule(moduleName);
1766
+ if (!_module) {
1767
+ throw new Error(`module does not exist: ${moduleName}`);
1768
+ }
1769
+ // target dir
1770
+ const targetDir = await this.helper.ensureDir(_module.root);
1771
+ const mainFile = path.join(targetDir, 'src/main.ts');
1772
+ if (fse.existsSync(mainFile)) {
1773
+ throw new Error(`main exists: ${moduleName}`);
1774
+ }
1775
+ // render boilerplate
1776
+ await this.template.renderBoilerplateAndSnippets({
1777
+ targetDir: path.join(targetDir, 'src'),
1778
+ setName: __ThisSetName__,
1779
+ snippetsPath: null,
1780
+ boilerplatePath: 'init/main/boilerplate'
1781
+ });
1782
+ // tools.metadata
1783
+ if (!argv.nometadata) {
1784
+ await this.helper.invokeCli([':tools:metadata', moduleName], {
1785
+ cwd: argv.projectPath
1786
+ });
1787
+ }
1788
+ }
1789
+ }
1790
+
1791
+ class CliInitMonkey extends BeanCliBase {
1792
+ async execute() {
1793
+ const {
1794
+ argv
1795
+ } = this.context;
1796
+ // super
1797
+ await super.execute();
1798
+ // noformat
1799
+ argv.noformat = true;
1800
+ // module name/info
1801
+ const moduleName = argv._[0];
1802
+ if (!moduleName) return;
1803
+ argv.moduleInfo = this.helper.parseModuleInfo(moduleName);
1804
+ // check if exists
1805
+ const _module = this.helper.findModule(moduleName);
1806
+ if (!_module) {
1807
+ throw new Error(`module does not exist: ${moduleName}`);
1808
+ }
1809
+ // target dir
1810
+ const targetDir = await this.helper.ensureDir(_module.root);
1811
+ const monkeyFile = path.join(targetDir, 'src/monkey.ts');
1812
+ if (fse.existsSync(monkeyFile)) {
1813
+ throw new Error(`monkey exists: ${moduleName}`);
1814
+ }
1815
+ // render boilerplate
1816
+ await this.template.renderBoilerplateAndSnippets({
1817
+ targetDir: path.join(targetDir, 'src'),
1818
+ setName: __ThisSetName__,
1819
+ snippetsPath: null,
1820
+ boilerplatePath: 'init/monkey/boilerplate'
1821
+ });
1822
+ // set vonaModule.capabilities.monkey: true
1823
+ await this._setPackageInfo(targetDir);
1824
+ // tools.metadata
1825
+ if (!argv.nometadata) {
1826
+ await this.helper.invokeCli([':tools:metadata', moduleName], {
1827
+ cwd: argv.projectPath
1828
+ });
1829
+ }
1830
+ }
1831
+ async _setPackageInfo(modulePath) {
1832
+ const pkgFile = path.join(modulePath, 'package.json');
1833
+ const pkg = await this.helper.loadJSONFile(pkgFile);
1834
+ if (!pkg.vonaModule) pkg.vonaModule = {};
1835
+ if (!pkg.vonaModule.capabilities) pkg.vonaModule.capabilities = {};
1836
+ let changed;
1837
+ // monkey
1838
+ if (!pkg.vonaModule.capabilities.monkey) {
1839
+ pkg.vonaModule.capabilities.monkey = true;
1840
+ changed = true;
1841
+ }
1842
+ // // dependencies
1843
+ // if (!pkg.vonaModule.dependencies) pkg.vonaModule.dependencies = {};
1844
+ // if (!pkg.vonaModule.dependencies['a-vona']) {
1845
+ // pkg.vonaModule.dependencies['a-vona'] = '5.0.0';
1846
+ // changed = true;
1847
+ // }
1848
+ // save
1849
+ if (changed) {
1850
+ await this.helper.saveJSONFile(pkgFile, pkg);
1851
+ }
1852
+ }
1853
+ }
1854
+
1855
+ class CliInitStatic extends BeanCliBase {
1856
+ async execute() {
1857
+ const {
1858
+ argv
1859
+ } = this.context;
1860
+ // super
1861
+ await super.execute();
1862
+ // noformat
1863
+ argv.noformat = true;
1864
+ // module name/info
1865
+ const moduleName = argv._[0];
1866
+ if (!moduleName) return;
1867
+ argv.moduleInfo = this.helper.parseModuleInfo(moduleName);
1868
+ // check if exists
1869
+ const _module = this.helper.findModule(moduleName);
1870
+ if (!_module) {
1871
+ throw new Error(`module does not exist: ${moduleName}`);
1872
+ }
1873
+ // target dir
1874
+ const targetDir = await this.helper.ensureDir(_module.root);
1875
+ const staticDir = path.join(targetDir, 'assets/static');
1876
+ if (fse.existsSync(staticDir)) {
1877
+ throw new Error(`static exists: ${moduleName}`);
1878
+ }
1879
+ // render boilerplate
1880
+ await this.template.renderBoilerplateAndSnippets({
1881
+ targetDir,
1882
+ setName: __ThisSetName__,
1883
+ snippetsPath: null,
1884
+ boilerplatePath: 'init/static/boilerplate'
1885
+ });
1886
+ // // tools.metadata
1887
+ // if (!argv.nometadata) {
1888
+ // await this.helper.invokeCli([':tools:metadata', moduleName], { cwd: argv.projectPath });
1889
+ // }
1890
+ }
1891
+ }
1892
+
1893
+ class CliInitTypes extends BeanCliBase {
1894
+ async execute() {
1895
+ const {
1896
+ argv
1897
+ } = this.context;
1898
+ // super
1899
+ await super.execute();
1900
+ // noformat
1901
+ argv.noformat = true;
1902
+ // module name/info
1903
+ const moduleName = argv._[0];
1904
+ if (!moduleName) return;
1905
+ argv.moduleInfo = this.helper.parseModuleInfo(moduleName);
1906
+ // check if exists
1907
+ const _module = this.helper.findModule(moduleName);
1908
+ if (!_module) {
1909
+ throw new Error(`module does not exist: ${moduleName}`);
1910
+ }
1911
+ // target dir
1912
+ const targetDir = await this.helper.ensureDir(_module.root);
1913
+ const mainFile = path.join(targetDir, 'src/types/index.ts');
1914
+ if (fse.existsSync(mainFile)) {
1915
+ throw new Error(`types exists: ${moduleName}`);
1916
+ }
1917
+ // render boilerplate
1918
+ await this.template.renderBoilerplateAndSnippets({
1919
+ targetDir: path.join(targetDir, 'src'),
1920
+ setName: __ThisSetName__,
1921
+ snippetsPath: null,
1922
+ boilerplatePath: 'init/types/boilerplate'
1923
+ });
1924
+ // tools.metadata
1925
+ if (!argv.nometadata) {
1926
+ await this.helper.invokeCli([':tools:metadata', moduleName], {
1927
+ cwd: argv.projectPath
1928
+ });
1929
+ }
1930
+ }
1931
+ }
1932
+
1933
+ class CliToolsCrud extends BeanCliBase {
1934
+ async execute() {
1935
+ const {
1936
+ argv
1937
+ } = this.context;
1938
+ // super
1939
+ await super.execute();
1940
+ // noformat
1941
+ argv.noformat = true;
1942
+ // module name/info
1943
+ const moduleName = argv.module;
1944
+ argv.moduleInfo = this.helper.parseModuleInfo(moduleName);
1945
+ // check if exists
1946
+ const _module = this.helper.findModule(moduleName);
1947
+ if (!_module) {
1948
+ throw new Error(`module does not exist: ${moduleName}`);
1949
+ }
1950
+ // target dir
1951
+ const targetDir = await this.helper.ensureDir(_module.root);
1952
+ // resourceName
1953
+ const resourceName = argv.resourceName;
1954
+ argv.resourceNameCapitalize = this.helper.firstCharToUpperCase(resourceName);
1955
+ // moduleResourceName
1956
+ argv.moduleResourceName = this.helper.combineModuleNameAndResource(argv.moduleInfo.relativeName, argv.resourceName);
1957
+ argv.moduleActionPathRaw = combineApiPathControllerAndActionRaw(moduleName, resourceName, '', true);
1958
+ // controller
1959
+ const controllerFile = path.join(targetDir, 'src/controller', `${resourceName}.ts`);
1960
+ if (fs.existsSync(controllerFile)) {
1961
+ throw new Error(`resource exists: ${resourceName}`);
1962
+ }
1963
+ // render
1964
+ await this.template.renderBoilerplateAndSnippets({
1965
+ targetDir,
1966
+ setName: __ThisSetName__,
1967
+ snippetsPath: 'tools/crud/snippets',
1968
+ boilerplatePath: 'tools/crud/boilerplate'
1969
+ });
1970
+ // tools.metadata
1971
+ if (!argv.nometadata) {
1972
+ await this.helper.invokeCli([':tools:metadata', moduleName], {
1973
+ cwd: argv.projectPath
1974
+ });
1975
+ }
1976
+ }
1977
+ }
1978
+
1979
+ class CliToolsDeps extends BeanCliBase {
1980
+ async execute() {
1981
+ const {
1982
+ argv
1983
+ } = this.context;
1984
+ // super
1985
+ await super.execute();
1986
+ const projectPath = argv.projectPath;
1987
+ // generate
1988
+ await this._generate(projectPath);
1989
+ }
1990
+ async _generate(projectPath) {
1991
+ // generate package.json
1992
+ await this.common._generatePackageJson(projectPath);
1993
+ // generate type modules file
1994
+ await this.common._generateTypeModulesFile(projectPath);
1995
+ // generate type project file
1996
+ await this._generateTypeProjectFile(projectPath);
1997
+ }
1998
+ _getProjectMode(projectPath) {
1999
+ const vonaPath = this._getVonaPath(projectPath);
2000
+ return vonaPath.includes('packages-vona') ? 'source' : 'project';
2001
+ }
2002
+ _getVonaPath(projectPath) {
2003
+ let vonaPath = path.join(projectPath, 'packages-vona/vona');
2004
+ if (fse.existsSync(vonaPath)) return vonaPath;
2005
+ vonaPath = path.join(projectPath, 'node_modules/vona');
2006
+ if (fse.existsSync(vonaPath)) return vonaPath;
2007
+ }
2008
+ async _generateTypeProjectFile(projectPath) {
2009
+ const projectMode = this._getProjectMode(projectPath);
2010
+ const fileTemplate = resolveTemplatePath(`config/_tsconfig_${projectMode}.json`);
2011
+ const fileConfig = path.join(projectPath, 'tsconfig.json');
2012
+ if (!fse.existsSync(fileConfig)) {
2013
+ await fse.copyFile(fileTemplate, fileConfig);
2014
+ }
2015
+ }
2016
+ }
2017
+
2018
+ function checkIgnoreOfParts(parts) {
2019
+ const indexLast = parts.length - 1;
2020
+ if (parts[indexLast].endsWith('_')) {
2021
+ parts[indexLast] = parts[indexLast].substring(0, parts[indexLast].length - 1);
2022
+ return true;
2023
+ }
2024
+ return false;
2025
+ }
2026
+ function getScopeModuleName(moduleName) {
2027
+ return `ScopeModule${stringToCapitalize(moduleName, '-')}`;
2028
+ }
2029
+ async function globBeanFiles(sceneName, sceneMeta, moduleName, modulePath) {
2030
+ const result = [];
2031
+ const sceneNameCapitalize = toUpperCaseFirstChar(sceneName);
2032
+ const pattern = sceneMeta.sceneIsolate ? `src/${sceneName}/*.ts` : `src/bean/${sceneName}.*.ts`;
2033
+ const files = await globby(pattern, {
2034
+ cwd: modulePath
2035
+ });
2036
+ if (files.length === 0) return result;
2037
+ files.sort();
2038
+ for (const file of files) {
2039
+ const filePath = path.join(modulePath, file);
2040
+ const fileName = path.basename(file);
2041
+ if (fileName.startsWith('_')) continue;
2042
+ const parts = fileName.split('.').slice(0, -1);
2043
+ if (sceneMeta.sceneIsolate && parts.length !== 1) continue;
2044
+ if (!sceneMeta.sceneIsolate && parts.length < 2) continue;
2045
+ const isIgnore = checkIgnoreOfParts(parts);
2046
+ const fileNameJS = fileName; // fileName.replace('.ts', '.js');
2047
+ const fileNameJSRelative = sceneMeta.sceneIsolate ? `../${sceneName}/${fileNameJS}` : `../bean/${fileNameJS}`;
2048
+ const className = (sceneMeta.sceneIsolate ? sceneNameCapitalize : '') + parts.map(item => toUpperCaseFirstChar(item)).join('');
2049
+ const beanName = parts[parts.length - 1];
2050
+ const beanNameFull = `${moduleName}:${beanName}`;
2051
+ const beanNameCapitalize = toUpperCaseFirstChar(beanName);
2052
+ const fileContent = isIgnore ? '' : fse.readFileSync(filePath).toString();
2053
+ const isVirtual = fileContent.includes('@Virtual()');
2054
+ result.push({
2055
+ sceneName,
2056
+ sceneNameCapitalize,
2057
+ file: filePath,
2058
+ fileContent,
2059
+ fileName,
2060
+ fileNameJS,
2061
+ fileNameJSRelative,
2062
+ className,
2063
+ beanName,
2064
+ beanNameFull,
2065
+ beanNameCapitalize,
2066
+ isIgnore,
2067
+ isVirtual
2068
+ });
2069
+ }
2070
+ return result;
2071
+ }
2072
+ function extractBeanInfo(sceneName, fileContent, sceneMeta) {
2073
+ const sceneNameCapitalize = toUpperCaseFirstChar(sceneName);
2074
+ // optionsCustomInterface
2075
+ let optionsCustomInterface;
2076
+ let optionsCustomInterfaceFrom;
2077
+ let reg = new RegExp(`@${sceneNameCapitalize}<(I${sceneNameCapitalize}Options[^>]*)>`);
2078
+ let matches = fileContent.match(reg);
2079
+ if (matches) {
2080
+ optionsCustomInterface = matches[1];
2081
+ // optionsCustomInterfaceFrom
2082
+ reg = new RegExp(`import type {[\\s\\S]*?${optionsCustomInterface}[, ][\\s\\S]*?} from '([^']*)'`);
2083
+ matches = fileContent.match(reg);
2084
+ if (matches) {
2085
+ optionsCustomInterfaceFrom = matches[1];
2086
+ }
2087
+ }
2088
+ // isGlobal
2089
+ const isGlobal = sceneMeta.hasLocal ? fileContent.match(/@.*?\(\{([\s\S]*?)global: true([\s\S]*?)\}([\s\S]*?)\)\s*export class/) : true;
2090
+ return {
2091
+ optionsCustomInterface,
2092
+ optionsCustomInterfaceFrom,
2093
+ isGlobal
2094
+ };
2095
+ }
2096
+
2097
+ async function generateBeanGenerals(sceneName, sceneMeta, moduleName, modulePath) {
2098
+ const globFiles = await globBeanFiles(sceneName, sceneMeta, moduleName, modulePath);
2099
+ if (globFiles.length === 0) return '';
2100
+ //
2101
+ const contentImports = [];
2102
+ const contentRecords = [];
2103
+ for (const globFile of globFiles) {
2104
+ const {
2105
+ fileNameJSRelative,
2106
+ className,
2107
+ beanName,
2108
+ isIgnore
2109
+ } = globFile;
2110
+ const beanFullName = `${moduleName}.${sceneName}.${beanName}`;
2111
+ if (isIgnore) continue;
2112
+ if (!sceneMeta.scopeResource) {
2113
+ contentImports.push(`import type { ${className} } from '${fileNameJSRelative}';`);
2114
+ }
2115
+ contentRecords.push(`'${beanFullName}': ${className};`);
2116
+ }
2117
+ if (contentRecords.length === 0) return '';
2118
+ // combine
2119
+ const content = `/** ${sceneName}: begin */
2120
+ ${contentImports.join('\n')}
2121
+ import 'vona';
2122
+ declare module 'vona' {
2123
+ export interface IBeanRecordGeneral {
2124
+ ${contentRecords.join('\n')}
2125
+ }
2126
+ }
2127
+ /** ${sceneName}: end */
2128
+ `;
2129
+ return content;
2130
+ }
2131
+
2132
+ async function generateConfig(modulePath) {
2133
+ const configFile = path.join(modulePath, 'src/config/config.ts');
2134
+ if (!fse.existsSync(configFile)) return '';
2135
+ // combine
2136
+ const content = `/** config: begin */
2137
+ export * from '../config/config.ts';
2138
+ import type { config } from '../config/config.ts';
2139
+ /** config: end */
2140
+ `;
2141
+ return content;
2142
+ }
2143
+ async function generateConstant(modulePath) {
2144
+ const constantFile = path.join(modulePath, 'src/config/constants.ts');
2145
+ if (!fse.existsSync(constantFile)) return '';
2146
+ // combine
2147
+ const content = `/** constant: begin */
2148
+ export * from '../config/constants.ts';
2149
+ import { constants } from '../config/constants.ts';
2150
+ /** constant: end */
2151
+ `;
2152
+ return content;
2153
+ }
2154
+ async function generateLocale(modulePath) {
2155
+ const files = await globby('src/config/locale/*.ts', {
2156
+ cwd: modulePath
2157
+ });
2158
+ if (files.length === 0) return '';
2159
+ files.sort();
2160
+ const contentImports = [];
2161
+ const contentLocales = [];
2162
+ for (const file of files) {
2163
+ const localeName = path.basename(file, '.ts');
2164
+ const className = `locale_${localeName.replace('-', '_')}`;
2165
+ contentImports.push(`import ${className} from '../config/locale/${localeName}.ts';`);
2166
+ contentLocales.push(`'${localeName}': ${className},`);
2167
+ }
2168
+ // combine
2169
+ const content = `/** locale: begin */
2170
+ ${contentImports.join('\n')}
2171
+ export const locales = {
2172
+ ${contentLocales.join('\n')}
2173
+ };
2174
+ /** locale: end */
2175
+ `;
2176
+ return content;
2177
+ }
2178
+ async function generateError(modulePath) {
2179
+ const errorFile = path.join(modulePath, 'src/config/errors.ts');
2180
+ if (!fse.existsSync(errorFile)) return '';
2181
+ // combine
2182
+ const content = `/** error: begin */
2183
+ export * from '../config/errors.ts';
2184
+ import type { errors } from '../config/errors.ts';
2185
+ /** error: end */
2186
+ `;
2187
+ return content;
2188
+ }
2189
+
2190
+ async function generateMetadataCustom(cli, sceneName, sceneMeta, moduleName, modulePath) {
2191
+ const sceneNameCapitalize = toUpperCaseFirstChar(sceneName);
2192
+ const globFiles = await globBeanFiles(sceneName, sceneMeta, moduleName, modulePath);
2193
+ if (globFiles.length === 0) return '';
2194
+ // custom
2195
+ const jsFile = path.join(sceneMeta.module.root, sceneMeta.metadataCustom);
2196
+ return await cli.helper.importDynamic(jsFile, async instance => {
2197
+ const options = {
2198
+ cli,
2199
+ sceneName,
2200
+ sceneNameCapitalize,
2201
+ sceneMeta,
2202
+ moduleName,
2203
+ modulePath,
2204
+ globFiles
2205
+ };
2206
+ return await instance.default(options);
2207
+ });
2208
+ }
2209
+
2210
+ async function generateMonkey(modulePath) {
2211
+ const monkeyFile = path.join(modulePath, 'src/monkey.ts');
2212
+ if (!fse.existsSync(monkeyFile)) return '';
2213
+ // combine
2214
+ const content = `/** monkey: begin */
2215
+ export * from '../monkey.ts';
2216
+ /** monkey: end */
2217
+ `;
2218
+ return content;
2219
+ }
2220
+ async function generateMain(modulePath) {
2221
+ const monkeyFile = path.join(modulePath, 'src/main.ts');
2222
+ if (!fse.existsSync(monkeyFile)) return '';
2223
+ // combine
2224
+ const content = `/** main: begin */
2225
+ export * from '../main.ts';
2226
+ /** main: end */
2227
+ `;
2228
+ return content;
2229
+ }
2230
+
2231
+ async function generateOnions(sceneName, sceneMeta, moduleName, modulePath) {
2232
+ const scopeModuleName = getScopeModuleName(moduleName);
2233
+ const sceneNameCapitalize = toUpperCaseFirstChar(sceneName);
2234
+ const globFiles = await globBeanFiles(sceneName, sceneMeta, moduleName, modulePath);
2235
+ if (globFiles.length === 0) return '';
2236
+ //
2237
+ const contentExports = [];
2238
+ const contentScopes = [];
2239
+ const contentImports = [];
2240
+ const contentRecordsGlobal = [];
2241
+ const contentRecordsLocal = [];
2242
+ let needImportOptionsGlobalInterface;
2243
+ for (const globFile of globFiles) {
2244
+ const {
2245
+ fileContent,
2246
+ fileNameJSRelative,
2247
+ sceneName,
2248
+ className,
2249
+ beanNameFull,
2250
+ isIgnore,
2251
+ isVirtual
2252
+ } = globFile;
2253
+ const isBeanGlobal = fileNameJSRelative.includes('../bean/bean.');
2254
+ contentExports.push(`export * from '${fileNameJSRelative}';`);
2255
+ if (isIgnore) continue; // get scope() also can be ignored
2256
+ // options
2257
+ let onionOptions;
2258
+ if (!sceneMeta.optionsNone) {
2259
+ // fileInfo
2260
+ const fileInfo = extractBeanInfo(sceneName, fileContent, sceneMeta);
2261
+ // import options
2262
+ if (fileInfo.optionsCustomInterface) {
2263
+ contentImports.push(`import type { ${fileInfo.optionsCustomInterface} } from '${fileInfo.optionsCustomInterfaceFrom || fileNameJSRelative}';`);
2264
+ }
2265
+ // valueOptionsCustomInterface
2266
+ let valueOptionsCustomInterface = fileInfo.optionsCustomInterface;
2267
+ if (valueOptionsCustomInterface && sceneMeta.optionsCustomInterfaceTemplate) {
2268
+ valueOptionsCustomInterface = replaceTemplate(sceneMeta.optionsCustomInterfaceTemplate, {
2269
+ optionsCustomInterface: valueOptionsCustomInterface
2270
+ });
2271
+ }
2272
+ // record
2273
+ if (fileInfo.isGlobal) {
2274
+ if (valueOptionsCustomInterface) {
2275
+ onionOptions = valueOptionsCustomInterface;
2276
+ contentRecordsGlobal.push(`'${beanNameFull}': ${valueOptionsCustomInterface};`);
2277
+ } else {
2278
+ if (sceneMeta.optionsGlobalInterfaceName) {
2279
+ onionOptions = sceneMeta.optionsGlobalInterfaceName;
2280
+ contentRecordsGlobal.push(`'${beanNameFull}': ${sceneMeta.optionsGlobalInterfaceName};`);
2281
+ needImportOptionsGlobalInterface = true;
2282
+ } else {
2283
+ contentRecordsGlobal.push(`'${beanNameFull}': never;`);
2284
+ }
2285
+ }
2286
+ } else {
2287
+ if (valueOptionsCustomInterface) {
2288
+ onionOptions = valueOptionsCustomInterface;
2289
+ contentRecordsLocal.push(`'${beanNameFull}': ${valueOptionsCustomInterface};`);
2290
+ } else {
2291
+ contentRecordsLocal.push(`'${beanNameFull}': never;`);
2292
+ }
2293
+ }
2294
+ }
2295
+ // get scope() also can be ignored
2296
+ if (!['entity', 'dto'].includes(sceneName) && !isVirtual) {
2297
+ contentScopes.push(`
2298
+ export interface ${className} {
2299
+ /** @internal */
2300
+ get scope(): ${scopeModuleName};
2301
+ }`);
2302
+ if (!isBeanGlobal) {
2303
+ const contentOnionOptions = onionOptions ? `get $onionOptions(): ${onionOptions};` : '';
2304
+ contentScopes.push(`
2305
+ export interface ${className} {
2306
+ get $beanFullName(): '${beanFullNameFromOnionName(beanNameFull, sceneName)}';
2307
+ get $onionName(): '${beanNameFull}';
2308
+ ${contentOnionOptions}
2309
+ }`);
2310
+ }
2311
+ }
2312
+ }
2313
+ // middlewareGlobal
2314
+ const exportRecordsMiddlewareGlobal = `
2315
+ export interface I${sceneNameCapitalize}Record${sceneMeta.hasLocal ? 'Global' : ''} {
2316
+ ${contentRecordsGlobal.join('\n')}
2317
+ }
2318
+ `;
2319
+ // middlewareLocal
2320
+ const exportRecordsMiddlewareLocal = `
2321
+ export interface I${sceneNameCapitalize}RecordLocal {
2322
+ ${contentRecordsLocal.join('\n')}
2323
+ }
2324
+ `;
2325
+ // combine
2326
+ const content = `/** ${sceneName}: begin */
2327
+ ${contentExports.join('\n')}
2328
+ ${contentImports.join('\n')}
2329
+ ${needImportOptionsGlobalInterface ? `import { type ${sceneMeta.optionsGlobalInterfaceName} } from '${sceneMeta.optionsGlobalInterfaceFrom || 'vona'}';` : `import '${sceneMeta.optionsGlobalInterfaceFrom || 'vona'}';`}
2330
+ declare module '${sceneMeta.optionsGlobalInterfaceFrom || 'vona'}' {
2331
+ ${contentRecordsGlobal.length > 0 ? exportRecordsMiddlewareGlobal : ''}
2332
+ ${contentRecordsLocal.length > 0 ? exportRecordsMiddlewareLocal : ''}
2333
+ }
2334
+ declare module 'vona-module-${moduleName}' {
2335
+ ${contentScopes.join('\n')}
2336
+ }
2337
+ /** ${sceneName}: end */
2338
+ `;
2339
+ return content;
2340
+ }
2341
+
2342
+ async function generateScope(moduleName, relativeNameCapitalize, scopeResources, options) {
2343
+ // scopeVariable
2344
+ const parts = moduleName.split('-');
2345
+ const scopeVariable = parts[0] === 'a' ? parts[1] : relativeNameToCapitalize(moduleName, false);
2346
+ const contentImports = [];
2347
+ const contentRecords = [];
2348
+ // basic
2349
+ contentImports.push('BeanScopeBase');
2350
+ // util
2351
+ contentImports.push('type BeanScopeUtil');
2352
+ contentRecords.push('util: BeanScopeUtil;');
2353
+ //
2354
+ if (options.config) {
2355
+ contentImports.push('type TypeModuleConfig');
2356
+ contentRecords.push('config: TypeModuleConfig<typeof config>;');
2357
+ }
2358
+ if (options.errors) {
2359
+ contentImports.push('type TypeModuleErrors');
2360
+ contentRecords.push('error: TypeModuleErrors<typeof errors>;');
2361
+ }
2362
+ if (options.locales) {
2363
+ contentImports.push('type TypeModuleLocales');
2364
+ contentImports.push('type TypeLocaleBase');
2365
+ contentRecords.push('locale: TypeModuleLocales<(typeof locales)[TypeLocaleBase]>;');
2366
+ }
2367
+ if (options.constants) {
2368
+ contentImports.push('type TypeModuleConstants');
2369
+ contentRecords.push('constant: TypeModuleConstants<typeof constants>;');
2370
+ }
2371
+ // loop
2372
+ for (const sceneName in scopeResources) {
2373
+ contentRecords.push(`${sceneName}: ${scopeResources[sceneName]};`);
2374
+ }
2375
+ // combine
2376
+ const content = `/** scope: begin */
2377
+ import { ${contentImports.join(', ')} } from 'vona';
2378
+ import { Scope } from '${moduleName === 'a-bean' ? '../lib/scope.ts' : 'vona-module-a-bean'}';
2379
+
2380
+ @Scope()
2381
+ export class ScopeModule${relativeNameCapitalize} extends BeanScopeBase {}
2382
+
2383
+ export interface ScopeModule${relativeNameCapitalize} {
2384
+ ${contentRecords.join('\n')}
2385
+ }
2386
+
2387
+ import 'vona';
2388
+ declare module 'vona' {
2389
+ export interface IBeanScopeRecord {
2390
+ '${moduleName}': ScopeModule${relativeNameCapitalize};
2391
+ }
2392
+
2393
+ export interface IBeanScopeContainer {
2394
+ ${scopeVariable}: ScopeModule${relativeNameCapitalize};
2395
+ }
2396
+
2397
+ ${options.config ? `export interface IBeanScopeConfig {
2398
+ '${moduleName}': ReturnType<typeof config>;
2399
+ }` : ''}
2400
+
2401
+ ${options.locales ? `export interface IBeanScopeLocale {
2402
+ '${moduleName}': (typeof locales)[TypeLocaleBase];
2403
+ }` : ''}
2404
+
2405
+ ${options.errors ? `export interface IBeanScopeErrors {
2406
+ '${moduleName}': typeof errors;
2407
+ }` : ''}
2408
+ }
2409
+ ${options.locales ? `\nexport function $locale<K extends keyof (typeof locales)[TypeLocaleBase]>(key: K): \`${moduleName}::\${K}\` {
2410
+ return \`${moduleName}::\${key}\`;
2411
+ }` : ''}
2412
+ /** scope: end */
2413
+ `;
2414
+ return content;
2415
+ }
2416
+
2417
+ async function generateScopeResources(sceneName, sceneMeta, moduleName, modulePath) {
2418
+ const sceneNameCapitalize = toUpperCaseFirstChar(sceneName);
2419
+ const globFiles = await globBeanFiles(sceneName, sceneMeta, moduleName, modulePath);
2420
+ if (globFiles.length === 0) return '';
2421
+ //
2422
+ const contentImports = [];
2423
+ const contentRecords = [];
2424
+ for (const globFile of globFiles) {
2425
+ const {
2426
+ fileNameJSRelative,
2427
+ className,
2428
+ beanName,
2429
+ isIgnore
2430
+ } = globFile;
2431
+ if (isIgnore) continue;
2432
+ contentImports.push(`import type { ${className} } from '${fileNameJSRelative}';`);
2433
+ let typeClassName = className;
2434
+ if (sceneMeta.scopeResourceTypeTemplate) {
2435
+ typeClassName = replaceTemplate$1(sceneMeta.scopeResourceTypeTemplate, {
2436
+ className
2437
+ });
2438
+ }
2439
+ contentRecords.push(`'${beanName}': ${typeClassName};`);
2440
+ }
2441
+ if (contentImports.length === 0) return '';
2442
+ // combine
2443
+ const content = `/** ${sceneName}: begin */
2444
+ ${contentImports.join('\n')}
2445
+ export interface IModule${sceneNameCapitalize} {
2446
+ ${contentRecords.join('\n')}
2447
+ }
2448
+ /** ${sceneName}: end */
2449
+ `;
2450
+ return content;
2451
+ }
2452
+
2453
+ async function generateScopeResourcesMeta(metaName, _metaMeta, _sceneName, _sceneMeta, _moduleName, modulePath) {
2454
+ const files = await globby(`src/bean/meta.${metaName}.ts`, {
2455
+ cwd: modulePath
2456
+ });
2457
+ if (files.length === 0) return '';
2458
+ // combine
2459
+ const content = `/** meta ${metaName}: begin */
2460
+ import type { Meta${toUpperCaseFirstChar(metaName)} } from '../bean/meta.${metaName}.ts';
2461
+ /** meta ${metaName}: end */
2462
+ `;
2463
+ return content;
2464
+ }
2465
+
2466
+ class CliToolsMetadata extends BeanCliBase {
2467
+ async execute() {
2468
+ const {
2469
+ argv
2470
+ } = this.context;
2471
+ // super
2472
+ await super.execute();
2473
+ // noformat: src/index.ts need format
2474
+ // argv.noformat = true;
2475
+ // moduleNames
2476
+ let moduleNames = argv._;
2477
+ const force = argv.force ?? moduleNames.length > 0;
2478
+ if (moduleNames.length === 0) {
2479
+ moduleNames = this.modulesMeta.modulesArray.filter(item => !item.info.node_modules).map(item => item.info.relativeName);
2480
+ }
2481
+ const total = moduleNames.length;
2482
+ for (let index = 0; index < total; index++) {
2483
+ const moduleName = moduleNames[index];
2484
+ // log
2485
+ await this.console.log({
2486
+ total,
2487
+ progress: index,
2488
+ text: moduleName
2489
+ });
2490
+ // generate res
2491
+ await this._generateMetadata(moduleName, force);
2492
+ }
2493
+ }
2494
+ async _generateMetadata(moduleName, force) {
2495
+ const module = this.helper.findModule(moduleName);
2496
+ if (!module) throw new Error(`module not found: ${moduleName}`);
2497
+ const modulePath = module.root;
2498
+ const metaDir = path.join(modulePath, 'src/.metadata');
2499
+ const metaIndexFile = path.join(metaDir, 'index.ts');
2500
+ if (fse.existsSync(metaIndexFile) && !force) {
2501
+ // do nothing
2502
+ return;
2503
+ }
2504
+ await this.helper.ensureDir(metaDir);
2505
+ // relativeNameCapitalize
2506
+ const relativeNameCapitalize = this.helper.stringToCapitalize(moduleName, '-');
2507
+ // onionScenesMeta
2508
+ const onionScenesMeta = getOnionScenesMeta(this.modulesMeta.modules);
2509
+ // content
2510
+ let content = '';
2511
+ // onions
2512
+ const scopeResources = {};
2513
+ for (const sceneName in onionScenesMeta) {
2514
+ const sceneMeta = onionScenesMeta[sceneName];
2515
+ // general
2516
+ content += await generateOnions(sceneName, sceneMeta, moduleName, modulePath);
2517
+ // scope resources
2518
+ if (sceneMeta.scopeResource) {
2519
+ const contentScopeResource = await generateScopeResources(sceneName, sceneMeta, moduleName, modulePath);
2520
+ if (contentScopeResource) {
2521
+ content += contentScopeResource;
2522
+ scopeResources[sceneName] = `IModule${toUpperCaseFirstChar(sceneName)}`;
2523
+ }
2524
+ }
2525
+ // bean generals
2526
+ if (sceneMeta.beanGeneral) {
2527
+ content += await generateBeanGenerals(sceneName, sceneMeta, moduleName, modulePath);
2528
+ }
2529
+ // metas
2530
+ if (sceneName === 'meta') {
2531
+ const onionMetasMeta = getOnionMetasMeta(this.modulesMeta.modules);
2532
+ for (const metaName in onionMetasMeta) {
2533
+ const metaMeta = onionMetasMeta[metaName];
2534
+ if (metaMeta.scopeResource) {
2535
+ const contentScopeResourceMeta = await generateScopeResourcesMeta(metaName, metaMeta, sceneName, sceneMeta, moduleName, modulePath);
2536
+ if (contentScopeResourceMeta) {
2537
+ content += contentScopeResourceMeta;
2538
+ scopeResources[metaName] = `Meta${toUpperCaseFirstChar(metaName)}`;
2539
+ }
2540
+ }
2541
+ }
2542
+ }
2543
+ // metadata custom
2544
+ if (sceneMeta.metadataCustom) {
2545
+ content += await generateMetadataCustom(this, sceneName, sceneMeta, moduleName, modulePath);
2546
+ }
2547
+ }
2548
+ // config
2549
+ const contentConfig = await generateConfig(modulePath);
2550
+ content += contentConfig;
2551
+ // constant
2552
+ const contentConstants = await generateConstant(modulePath);
2553
+ content += contentConstants;
2554
+ // locale
2555
+ const contentLocales = await generateLocale(modulePath);
2556
+ content += contentLocales;
2557
+ // error
2558
+ const contentErrors = await generateError(modulePath);
2559
+ content += contentErrors;
2560
+ // monkey
2561
+ content += await generateMonkey(modulePath);
2562
+ // main
2563
+ content += await generateMain(modulePath);
2564
+ // scope
2565
+ content += await generateScope(moduleName, relativeNameCapitalize, scopeResources, {
2566
+ config: contentConfig,
2567
+ errors: contentErrors,
2568
+ locales: contentLocales,
2569
+ constants: contentConstants
2570
+ });
2571
+ // patch
2572
+ content = this._generatePatch(content);
2573
+ // empty
2574
+ if (!content.trim()) {
2575
+ content = 'export {};';
2576
+ } else {
2577
+ content = `/* eslint-disable */\n${content}`;
2578
+ }
2579
+ // save
2580
+ await fse.writeFile(metaIndexFile, content);
2581
+ // await this.helper.formatFile({ fileName: metaIndexFile, logPrefix: 'format: ' });
2582
+ // generate this
2583
+ await this._generateThis(moduleName, relativeNameCapitalize, modulePath);
2584
+ // index
2585
+ await this._generateIndex(modulePath);
2586
+ // package
2587
+ await this._generatePackage(modulePath);
2588
+ }
2589
+ _generatePatch(content) {
2590
+ if (!content) return content;
2591
+ content = this._generatePatch_resources(content, 'table-identity', ['TableIdentity'], true);
2592
+ content = this._generatePatch_resources(content, 'vona-module-a-openapi', ['TypeEntityOptionsFields', 'TypeControllerOptionsActions'], true);
2593
+ content = this._generatePatch_resources(content, 'vona-module-a-orm', ['TypeEntityMeta', 'TypeModelsClassLikeGeneral', 'TypeSymbolKeyFieldsMore', 'IModelRelationHasOne', 'IModelRelationBelongsTo', 'IModelRelationHasMany', 'IModelRelationBelongsToMany'], true);
2594
+ content = this._generatePatch_resources(content, 'vona', ['PowerPartial'], true);
2595
+ return content;
2596
+ }
2597
+ _generatePatch_resources(content, packageName, resources, type) {
2598
+ const items = resources.filter(item => {
2599
+ const regexp = new RegExp(`${item}[\\[\\]<,;?:\\s]`);
2600
+ return !!regexp.exec(content);
2601
+ });
2602
+ if (items.length === 0) return content;
2603
+ const importContent = `import ${type ? 'type ' : ''}{ ${items.join(',')} } from '${packageName}';`;
2604
+ return `${importContent}\n${content}`;
2605
+ }
2606
+ async _generateThis(moduleName, relativeNameCapitalize, modulePath) {
2607
+ const thisDest = path.join(modulePath, 'src/.metadata/this.ts');
2608
+ if (fse.existsSync(thisDest)) return;
2609
+ const content = `export const __ThisModule__ = '${moduleName}';
2610
+ export { ScopeModule${relativeNameCapitalize} as ScopeModule } from './index.ts';
2611
+ `;
2612
+ // save
2613
+ await fse.writeFile(thisDest, content);
2614
+ }
2615
+ async _generateIndex(modulePath) {
2616
+ let jsContent = '';
2617
+ const jsFile = path.join(modulePath, 'src/index.ts');
2618
+ if (fse.existsSync(jsFile)) {
2619
+ jsContent = (await fse.readFile(jsFile)).toString();
2620
+ }
2621
+ // jsTypes
2622
+ const jsTypes = "export * from './types/index.ts';";
2623
+ const jsTypesFile = path.join(modulePath, 'src/types/index.ts');
2624
+ if (fse.existsSync(jsTypesFile) && !jsContent.includes(jsTypes)) {
2625
+ jsContent = `${jsTypes}\n${jsContent}`;
2626
+ }
2627
+ // jsLib
2628
+ const jsLib = "export * from './lib/index.ts';";
2629
+ const jsLibFile = path.join(modulePath, 'src/lib/index.ts');
2630
+ if (fse.existsSync(jsLibFile) && !jsContent.includes(jsLib)) {
2631
+ jsContent = `${jsLib}\n${jsContent}`;
2632
+ }
2633
+ // jsMetadata
2634
+ const jsMetadata = "export * from './.metadata/index.ts';";
2635
+ const jsMetadataFile = path.join(modulePath, 'src/.metadata/index.ts');
2636
+ if (fse.existsSync(jsMetadataFile) && !jsContent.includes(jsMetadata)) {
2637
+ jsContent = `${jsMetadata}\n${jsContent}`;
2638
+ }
2639
+ // trim empty
2640
+ jsContent = jsContent.replace('export {};\n', '');
2641
+ // write
2642
+ await fse.writeFile(jsFile, jsContent);
2643
+ await this.helper.formatFile({
2644
+ fileName: jsFile,
2645
+ logPrefix: 'format: '
2646
+ });
2647
+ }
2648
+ async _generatePackage(modulePath) {
2649
+ let pkgFile;
2650
+ let pkg;
2651
+ let changed;
2652
+ async function _loadPkg() {
2653
+ if (!pkg) {
2654
+ pkgFile = path.join(modulePath, 'package.json');
2655
+ pkg = await loadJSONFile(pkgFile);
2656
+ }
2657
+ return pkg;
2658
+ }
2659
+ // cli
2660
+ const cli = path.join(modulePath, 'cli');
2661
+ if (fse.existsSync(cli)) {
2662
+ pkg = await _loadPkg();
2663
+ const index = pkg.files.indexOf('cli');
2664
+ if (index === -1) {
2665
+ changed = true;
2666
+ pkg.files.push('cli');
2667
+ }
2668
+ }
2669
+ // save
2670
+ if (changed) {
2671
+ await saveJSONFile(pkgFile, pkg);
2672
+ await this.helper.formatFile({
2673
+ fileName: pkgFile
2674
+ });
2675
+ }
2676
+ }
2677
+ }
2678
+
2679
+ const beans = {
2680
+ 'default.list': CliDefaultList,
2681
+ 'bin.build': CliBinBuild,
2682
+ 'bin.buildModule': CliBinBuildModule,
2683
+ 'bin.buildGeneral': CliBinBuildGeneral,
2684
+ 'bin.dbReset': CliBinDbReset,
2685
+ 'bin.play': CliBinPlay,
2686
+ 'bin.dev': CliBinDev,
2687
+ 'bin.test': CliBinTest,
2688
+ 'bin.tsc': CliBinTsc,
2689
+ 'create.suite': CliCreateSuite,
2690
+ 'create.bean': CliCreateBean,
2691
+ 'create.module': CliCreateModule,
2692
+ 'create.project': CliCreateProject,
2693
+ 'create.test': CliCreateTest,
2694
+ 'init.config': CliInitConfig,
2695
+ 'init.constant': CliInitConstant,
2696
+ 'init.error': CliInitError,
2697
+ 'init.locale': CliInitLocale,
2698
+ 'init.monkey': CliInitMonkey,
2699
+ 'init.main': CliInitMain,
2700
+ 'init.static': CliInitStatic,
2701
+ 'init.asset': CliInitAsset,
2702
+ 'init.lib': CliInitLib,
2703
+ 'init.types': CliInitTypes,
2704
+ 'init.appMonkey': CliInitAppMonkey,
2705
+ 'tools.deps': CliToolsDeps,
2706
+ 'tools.metadata': CliToolsMetadata,
2707
+ 'tools.crud': CliToolsCrud
2708
+ };
2709
+
2710
+ var binBuild = {
2711
+ bean: 'bin.build',
2712
+ info: {
2713
+ version: '5.0.0',
2714
+ title: 'Cli: Tools: Bin',
2715
+ usage: 'vona :bin:build [--workers=] [--flavor=] [--sourcemap=]'
2716
+ },
2717
+ options: {
2718
+ workers: {
2719
+ description: 'workers',
2720
+ type: 'number'
2721
+ },
2722
+ flavor: {
2723
+ description: 'flavor',
2724
+ type: 'string'
2725
+ }
2726
+ }
2727
+ };
2728
+
2729
+ var binBuildGeneral = {
2730
+ bean: 'bin.buildGeneral',
2731
+ info: {
2732
+ version: '5.0.0',
2733
+ title: 'Cli: Tools: Bin',
2734
+ usage: 'vona :bin:buildGeneral [--minify] [--sourcemap]'
2735
+ },
2736
+ options: {
2737
+ minify: {
2738
+ description: 'minify',
2739
+ type: 'boolean'
2740
+ },
2741
+ sourcemap: {
2742
+ description: 'sourcemap',
2743
+ type: 'boolean'
2744
+ }
2745
+ }
2746
+ };
2747
+
2748
+ var binBuildModule = {
2749
+ bean: 'bin.buildModule',
2750
+ info: {
2751
+ version: '5.0.0',
2752
+ title: 'Cli: Tools: Bin',
2753
+ usage: 'vona :bin:buildModule [--minify] [--sourcemap]'
2754
+ },
2755
+ options: {
2756
+ minify: {
2757
+ description: 'minify',
2758
+ type: 'boolean'
2759
+ },
2760
+ sourcemap: {
2761
+ description: 'sourcemap',
2762
+ type: 'boolean'
2763
+ }
2764
+ }
2765
+ };
2766
+
2767
+ var binDbReset = {
2768
+ bean: 'bin.dbReset',
2769
+ info: {
2770
+ version: '5.0.0',
2771
+ title: 'Cli: Bin: DbReset',
2772
+ usage: 'vona :bin:dbReset [--flavor=]'
2773
+ },
2774
+ options: {
2775
+ flavor: {
2776
+ description: 'flavor',
2777
+ type: 'string'
2778
+ }
2779
+ }
2780
+ };
2781
+
2782
+ var binDev = {
2783
+ bean: 'bin.dev',
2784
+ info: {
2785
+ version: '5.0.0',
2786
+ title: 'Cli: Bin: Dev',
2787
+ usage: 'vona :bin:dev [--workers=] [--flavor=]'
2788
+ },
2789
+ options: {
2790
+ workers: {
2791
+ description: 'workers',
2792
+ type: 'number'
2793
+ },
2794
+ flavor: {
2795
+ description: 'flavor',
2796
+ type: 'string'
2797
+ }
2798
+ }
2799
+ };
2800
+
2801
+ var binPlay = {
2802
+ bean: 'bin.play',
2803
+ info: {
2804
+ version: '5.0.0',
2805
+ title: 'Cli: Bin: Play',
2806
+ usage: 'vona :bin:play [index.ts] [--flavor=] [--retainRuntime=] [--attach]'
2807
+ },
2808
+ options: {
2809
+ mode: {
2810
+ description: 'mode',
2811
+ type: 'string'
2812
+ },
2813
+ flavor: {
2814
+ description: 'flavor',
2815
+ type: 'string'
2816
+ },
2817
+ retainRuntime: {
2818
+ description: 'retainRuntime',
2819
+ type: 'boolean'
2820
+ },
2821
+ attach: {
2822
+ alias: 'a',
2823
+ description: 'attach',
2824
+ type: 'boolean'
2825
+ }
2826
+ }
2827
+ };
2828
+
2829
+ var binTest = {
2830
+ bean: 'bin.test',
2831
+ info: {
2832
+ version: '5.0.0',
2833
+ title: 'Cli: Bin: Test',
2834
+ usage: 'vona :bin:test [--coverage=] [--flavor=]'
2835
+ },
2836
+ options: {
2837
+ coverage: {
2838
+ description: 'coverage',
2839
+ type: 'boolean'
2840
+ },
2841
+ flavor: {
2842
+ description: 'flavor',
2843
+ type: 'string'
2844
+ }
2845
+ }
2846
+ };
2847
+
2848
+ var binTsc = {
2849
+ bean: 'bin.tsc',
2850
+ info: {
2851
+ version: '5.0.0',
2852
+ title: 'Cli: Bin: Tsc',
2853
+ usage: 'vona :bin:tsc [--force]'
2854
+ },
2855
+ options: {
2856
+ force: {
2857
+ description: 'force',
2858
+ type: 'boolean'
2859
+ }
2860
+ }
2861
+ };
2862
+
2863
+ var createBean = {
2864
+ bean: 'create.bean',
2865
+ info: {
2866
+ version: '5.0.0',
2867
+ title: 'Cli: Create Bean',
2868
+ usage: 'vona :create:bean sceneName beanName [--module=] [--boilerplate=]'
2869
+ },
2870
+ options: {
2871
+ module: {
2872
+ alias: 'm',
2873
+ description: 'module name',
2874
+ type: 'string'
2875
+ },
2876
+ boilerplate: {
2877
+ description: 'boilerplate',
2878
+ type: 'string'
2879
+ }
2880
+ },
2881
+ groups: {
2882
+ default: {
2883
+ questions: {
2884
+ sceneName: {
2885
+ type: 'input',
2886
+ message: 'sceneName',
2887
+ initial: {
2888
+ expression: 'context.argv._[0]'
2889
+ },
2890
+ required: true
2891
+ },
2892
+ beanName: {
2893
+ type: 'input',
2894
+ message: 'beanName',
2895
+ initial: {
2896
+ expression: 'context.argv._[1]'
2897
+ },
2898
+ required: true
2899
+ },
2900
+ module: {
2901
+ type: 'input',
2902
+ message: 'module name',
2903
+ required: true
2904
+ }
2905
+ }
2906
+ }
2907
+ }
2908
+ };
2909
+
2910
+ var createModule = {
2911
+ bean: 'create.module',
2912
+ info: {
2913
+ version: '5.0.0',
2914
+ title: 'Cli: Create Module',
2915
+ usage: 'vona :create:module moduleName [--suite=] [--force]'
2916
+ },
2917
+ options: {
2918
+ suite: {
2919
+ description: 'suite name',
2920
+ type: 'string'
2921
+ },
2922
+ force: {
2923
+ description: 'force',
2924
+ type: 'boolean'
2925
+ }
2926
+ },
2927
+ groups: {
2928
+ default: {
2929
+ questions: {
2930
+ name: {
2931
+ type: 'input',
2932
+ message: 'module name',
2933
+ initial: {
2934
+ expression: 'context.argv._[0]'
2935
+ },
2936
+ required: true
2937
+ },
2938
+ suite: {
2939
+ type: 'input',
2940
+ message: 'suite name'
2941
+ }
2942
+ }
2943
+ }
2944
+ }
2945
+ };
2946
+
2947
+ var createProject = {
2948
+ bean: 'create.project',
2949
+ info: {
2950
+ version: '5.0.0',
2951
+ title: 'Cli: Create Project',
2952
+ usage: 'vona :create:project projectName [--template=] [--force]'
2953
+ },
2954
+ options: {
2955
+ template: {
2956
+ description: 'template',
2957
+ type: 'string'
2958
+ },
2959
+ force: {
2960
+ description: 'force',
2961
+ type: 'boolean'
2962
+ }
2963
+ },
2964
+ groups: {
2965
+ default: {
2966
+ questions: {
2967
+ template: {
2968
+ type: 'select',
2969
+ message: 'Specify the project template',
2970
+ choices: [{
2971
+ name: 'basic',
2972
+ message: 'basic'
2973
+ }]
2974
+ }
2975
+ }
2976
+ },
2977
+ moduleInfo: {
2978
+ questions: {
2979
+ name: {
2980
+ type: 'input',
2981
+ message: 'project name',
2982
+ initial: {
2983
+ expression: 'context.argv._[0]'
2984
+ },
2985
+ required: true
2986
+ }
2987
+ }
2988
+ }
2989
+ }
2990
+ };
2991
+
2992
+ var createSuite = {
2993
+ bean: 'create.suite',
2994
+ info: {
2995
+ version: '5.0.0',
2996
+ title: 'Cli: Create Suite',
2997
+ usage: 'vona :create:suite suiteName'
2998
+ },
2999
+ options: {},
3000
+ groups: {
3001
+ suiteInfo: {
3002
+ questions: {
3003
+ name: {
3004
+ type: 'input',
3005
+ message: 'suite name',
3006
+ initial: {
3007
+ expression: 'context.argv._[0]'
3008
+ },
3009
+ required: true
3010
+ }
3011
+ }
3012
+ }
3013
+ }
3014
+ };
3015
+
3016
+ var createTest = {
3017
+ bean: 'create.test',
3018
+ info: {
3019
+ version: '5.0.0',
3020
+ title: 'Cli: Create Test',
3021
+ usage: 'vona :create:test name [--module=]'
3022
+ },
3023
+ options: {
3024
+ module: {
3025
+ description: 'module name',
3026
+ type: 'string'
3027
+ }
3028
+ },
3029
+ groups: {
3030
+ default: {
3031
+ questions: {
3032
+ name: {
3033
+ type: 'input',
3034
+ message: 'name',
3035
+ initial: {
3036
+ expression: 'context.argv._[0]'
3037
+ },
3038
+ required: true
3039
+ },
3040
+ module: {
3041
+ type: 'input',
3042
+ message: 'module name',
3043
+ required: true
3044
+ }
3045
+ }
3046
+ }
3047
+ }
3048
+ };
3049
+
3050
+ var defaultList = {
3051
+ bean: 'default.list',
3052
+ info: {
3053
+ version: '5.0.0',
3054
+ title: 'Cli: Command List'
3055
+ },
3056
+ options: {
3057
+ module: {
3058
+ description: 'module',
3059
+ type: 'string'
3060
+ },
3061
+ group: {
3062
+ description: 'group',
3063
+ type: 'string'
3064
+ }
3065
+ },
3066
+ groups: null
3067
+ };
3068
+
3069
+ var initAppMonkey = {
3070
+ bean: 'init.appMonkey',
3071
+ info: {
3072
+ version: '5.0.0',
3073
+ title: 'Cli: Init: App Monkey',
3074
+ usage: 'vona :init:appMonkey'
3075
+ }
3076
+ // options: null,
3077
+ // groups: null,
3078
+ };
3079
+
3080
+ var initAsset = {
3081
+ bean: 'init.asset',
3082
+ info: {
3083
+ version: '5.0.0',
3084
+ title: 'Cli: Init: Asset Resources',
3085
+ usage: 'vona :init:asset scene [--module=]'
3086
+ },
3087
+ options: {
3088
+ module: {
3089
+ description: 'module name',
3090
+ type: 'string'
3091
+ }
3092
+ },
3093
+ groups: {
3094
+ default: {
3095
+ questions: {
3096
+ scene: {
3097
+ type: 'input',
3098
+ message: 'scene',
3099
+ initial: {
3100
+ expression: 'context.argv._[0]'
3101
+ },
3102
+ required: true
3103
+ },
3104
+ module: {
3105
+ type: 'input',
3106
+ message: 'module name',
3107
+ required: true
3108
+ }
3109
+ }
3110
+ }
3111
+ }
3112
+ };
3113
+
3114
+ var initConfig = {
3115
+ bean: 'init.config',
3116
+ info: {
3117
+ version: '5.0.0',
3118
+ title: 'Cli: Init: Config',
3119
+ usage: 'vona :init:config module'
3120
+ }
3121
+ // options: null,
3122
+ // groups: null,
3123
+ };
3124
+
3125
+ var initConstant = {
3126
+ bean: 'init.constant',
3127
+ info: {
3128
+ version: '5.0.0',
3129
+ title: 'Cli: Init: Constant',
3130
+ usage: 'vona :init:constant module'
3131
+ }
3132
+ // options: null,
3133
+ // groups: null,
3134
+ };
3135
+
3136
+ var initError = {
3137
+ bean: 'init.error',
3138
+ info: {
3139
+ version: '5.0.0',
3140
+ title: 'Cli: Init: Error',
3141
+ usage: 'vona :init:error module'
3142
+ }
3143
+ // options: null,
3144
+ // groups: null,
3145
+ };
3146
+
3147
+ var initLib = {
3148
+ bean: 'init.lib',
3149
+ info: {
3150
+ version: '5.0.0',
3151
+ title: 'Cli: Init: Lib',
3152
+ usage: 'vona :init:lib module'
3153
+ }
3154
+ // options: null,
3155
+ // groups: null,
3156
+ };
3157
+
3158
+ var initLocale = {
3159
+ bean: 'init.locale',
3160
+ info: {
3161
+ version: '5.0.0',
3162
+ title: 'Cli: Init: Locale',
3163
+ usage: 'vona :init:locale module'
3164
+ }
3165
+ // options: null,
3166
+ // groups: null,
3167
+ };
3168
+
3169
+ var initMain = {
3170
+ bean: 'init.main',
3171
+ info: {
3172
+ version: '5.0.0',
3173
+ title: 'Cli: Init: Main',
3174
+ usage: 'vona :init:main module'
3175
+ }
3176
+ // options: null,
3177
+ // groups: null,
3178
+ };
3179
+
3180
+ var initMonkey = {
3181
+ bean: 'init.monkey',
3182
+ info: {
3183
+ version: '5.0.0',
3184
+ title: 'Cli: Init: Monkey',
3185
+ usage: 'vona :init:monkey module'
3186
+ }
3187
+ // options: null,
3188
+ // groups: null,
3189
+ };
3190
+
3191
+ var initStatic = {
3192
+ bean: 'init.static',
3193
+ info: {
3194
+ version: '5.0.0',
3195
+ title: 'Cli: Init: Static Resources',
3196
+ usage: 'vona :init:static module'
3197
+ }
3198
+ // options: null,
3199
+ // groups: null,
3200
+ };
3201
+
3202
+ var initTypes = {
3203
+ bean: 'init.types',
3204
+ info: {
3205
+ version: '5.0.0',
3206
+ title: 'Cli: Init: Types',
3207
+ usage: 'vona :init:types module'
3208
+ }
3209
+ // options: null,
3210
+ // groups: null,
3211
+ };
3212
+
3213
+ var toolsCrud = {
3214
+ bean: 'tools.crud',
3215
+ info: {
3216
+ version: '5.0.0',
3217
+ title: 'Cli: Tools: Crud',
3218
+ usage: 'vona :tools:crud resourceName [--module=]'
3219
+ },
3220
+ options: {
3221
+ module: {
3222
+ description: 'module name',
3223
+ type: 'string'
3224
+ }
3225
+ },
3226
+ groups: {
3227
+ default: {
3228
+ questions: {
3229
+ resourceName: {
3230
+ type: 'input',
3231
+ message: 'resourceName',
3232
+ initial: {
3233
+ expression: 'context.argv._[0]'
3234
+ },
3235
+ required: true
3236
+ },
3237
+ module: {
3238
+ type: 'input',
3239
+ message: 'module name',
3240
+ required: true
3241
+ }
3242
+ }
3243
+ }
3244
+ }
3245
+ };
3246
+
3247
+ var toolsDeps = {
3248
+ bean: 'tools.deps',
3249
+ info: {
3250
+ version: '5.0.0',
3251
+ title: 'Cli: Tools: Deps',
3252
+ usage: 'vona :tools:deps'
3253
+ },
3254
+ options: {}
3255
+ };
3256
+
3257
+ var toolsMetadata = {
3258
+ bean: 'tools.metadata',
3259
+ info: {
3260
+ version: '5.0.0',
3261
+ title: 'Cli: Tools: Metadata',
3262
+ usage: 'vona :tools:metadata module1 [module2] [--force]'
3263
+ },
3264
+ options: {
3265
+ force: {
3266
+ description: 'force',
3267
+ type: 'boolean'
3268
+ }
3269
+ }
3270
+ };
3271
+
3272
+ const commands = {
3273
+ default: {
3274
+ list: defaultList
3275
+ },
3276
+ bin: {
3277
+ build: binBuild,
3278
+ buildModule: binBuildModule,
3279
+ buildGeneral: binBuildGeneral,
3280
+ dbReset: binDbReset,
3281
+ dev: binDev,
3282
+ play: binPlay,
3283
+ test: binTest,
3284
+ tsc: binTsc
3285
+ },
3286
+ create: {
3287
+ suite: createSuite,
3288
+ module: createModule,
3289
+ project: createProject,
3290
+ bean: createBean,
3291
+ test: createTest
3292
+ },
3293
+ init: {
3294
+ config: initConfig,
3295
+ locale: initLocale,
3296
+ constant: initConstant,
3297
+ error: initError,
3298
+ monkey: initMonkey,
3299
+ main: initMain,
3300
+ static: initStatic,
3301
+ asset: initAsset,
3302
+ lib: initLib,
3303
+ types: initTypes,
3304
+ appMonkey: initAppMonkey
3305
+ },
3306
+ refactor: {},
3307
+ tools: {
3308
+ deps: toolsDeps,
3309
+ metadata: toolsMetadata,
3310
+ crud: toolsCrud
3311
+ }
3312
+ };
3313
+
3314
+ export { beans, commands, copyTemplateFile, copyTemplateIfNeed, generateConfigDefine, getAbsolutePathOfModule, getEnvMeta, getImportEsm, getNodeEnv, getOutDir, getOutReleasesDir, loadJSONFile, pathToHref, requireModule, saveJSONFile };