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