vona-cli-set-api 1.0.402 → 1.0.406
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +3314 -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/dist/lib/utils.d.ts +0 -1
- package/dist/utils.d.ts +1 -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/lib/bean/{toolsBin → toolsIsolate}/dbReset.d.ts +0 -0
- /package/dist/lib/bean/{toolsBin → toolsIsolate}/play.d.ts +0 -0
- /package/dist/lib/bean/{toolsBin → toolsIsolate}/test.d.ts +0 -0
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import os from 'node:os';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import * as dotenv from '@cabloy/dotenv';
|
|
4
|
-
import { glob } from '@cabloy/module-glob';
|
|
5
|
-
import { getEnvMeta, getNodeEnv } from "../../utils.js";
|
|
6
|
-
export function createConfigUtils(configMeta, configOptions) {
|
|
7
|
-
let __modulesMeta;
|
|
8
|
-
return {
|
|
9
|
-
loadEnvs: __loadEnvs,
|
|
10
|
-
loadModulesMeta: __loadModulesMeta,
|
|
11
|
-
};
|
|
12
|
-
//////////////////////////////
|
|
13
|
-
function __loadEnvs() {
|
|
14
|
-
const meta = getEnvMeta(configMeta);
|
|
15
|
-
const envDir = path.join(configOptions.appDir, 'env');
|
|
16
|
-
const envs = dotenv.loadEnvs(meta, envDir, '.env');
|
|
17
|
-
const res = Object.assign({
|
|
18
|
-
NODE_ENV: getNodeEnv(meta.mode),
|
|
19
|
-
}, envs, {
|
|
20
|
-
META_FLAVOR: meta.flavor,
|
|
21
|
-
META_MODE: meta.mode,
|
|
22
|
-
});
|
|
23
|
-
if (configOptions.workers !== undefined) {
|
|
24
|
-
res.SERVER_WORKERS = configOptions.workers.toString();
|
|
25
|
-
}
|
|
26
|
-
// maybe empty string
|
|
27
|
-
if (!res.SERVER_WORKERS) {
|
|
28
|
-
if (meta.mode === 'prod') {
|
|
29
|
-
res.SERVER_WORKERS = os.cpus().length.toString();
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
res.SERVER_WORKERS = '1';
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
for (const key of ['NODE_ENV', 'SERVER_WORKERS', 'META_FLAVOR', 'META_MODE']) {
|
|
36
|
-
if (res[key] !== false) {
|
|
37
|
-
process.env[key] = res[key];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
// ok
|
|
41
|
-
return res;
|
|
42
|
-
}
|
|
43
|
-
async function __loadModulesMeta() {
|
|
44
|
-
const meta = getEnvMeta(configMeta);
|
|
45
|
-
// modules
|
|
46
|
-
__modulesMeta = await glob({
|
|
47
|
-
projectMode: 'vona',
|
|
48
|
-
projectPath: configOptions.appDir,
|
|
49
|
-
disabledModules: process.env.PROJECT_DISABLED_MODULES,
|
|
50
|
-
disabledSuites: process.env.PROJECT_DISABLED_SUITES,
|
|
51
|
-
log: false,
|
|
52
|
-
meta,
|
|
53
|
-
});
|
|
54
|
-
return __modulesMeta;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { getEnvFiles } from '@cabloy/dotenv';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import fse from 'fs-extra';
|
|
5
|
-
import { copyTemplateFile, getEnvMeta, resolveTemplatePath } from "../../utils.js";
|
|
6
|
-
import { generateZod } from "./generateZod.js";
|
|
7
|
-
export async function generateEntryFiles(configMeta, configOptions, modulesMeta, env) {
|
|
8
|
-
// config
|
|
9
|
-
await __generateConfig();
|
|
10
|
-
// modules meta
|
|
11
|
-
await __generateModulesMeta();
|
|
12
|
-
// env
|
|
13
|
-
await __generateEnvJson();
|
|
14
|
-
// app
|
|
15
|
-
await __generateApp();
|
|
16
|
-
// others
|
|
17
|
-
await __generateOthers();
|
|
18
|
-
// zod
|
|
19
|
-
await generateZod(configOptions);
|
|
20
|
-
//////////////////////////////
|
|
21
|
-
async function __generateConfig() {
|
|
22
|
-
// check config
|
|
23
|
-
let configDir = path.join(configOptions.appDir, 'src/backend/config');
|
|
24
|
-
if (!fse.existsSync(configDir)) {
|
|
25
|
-
// eslint-disable-next-line
|
|
26
|
-
console.log(chalk.red('path not found: src/backend/config\n'));
|
|
27
|
-
process.exit(0);
|
|
28
|
-
}
|
|
29
|
-
// meta
|
|
30
|
-
const meta = getEnvMeta(configMeta);
|
|
31
|
-
configDir = path.join(configOptions.appDir, 'src/backend/config/config');
|
|
32
|
-
const files = getEnvFiles(meta, configDir, 'config', '.ts');
|
|
33
|
-
const filenames = files.map(item => path.basename(item));
|
|
34
|
-
const imports = [];
|
|
35
|
-
const constNames = [];
|
|
36
|
-
for (const filename of filenames) {
|
|
37
|
-
const parts = filename.split('.');
|
|
38
|
-
let constName = parts[0];
|
|
39
|
-
for (let index = 1; index < parts.length - 1; index++) {
|
|
40
|
-
constName += parts[index].charAt(0).toUpperCase() + parts[index].substring(1);
|
|
41
|
-
}
|
|
42
|
-
imports.push(`import ${constName} from '../src/backend/config/config/${filename}';`);
|
|
43
|
-
constNames.push(constName);
|
|
44
|
-
}
|
|
45
|
-
const contentDest = `${imports.join('\n')}\nexport default [${constNames.join(', ')}];`;
|
|
46
|
-
// output
|
|
47
|
-
const fileDest = path.join(configOptions.appDir, configOptions.runtimeDir, 'config.ts');
|
|
48
|
-
fse.ensureFileSync(fileDest);
|
|
49
|
-
fse.writeFileSync(fileDest, contentDest, 'utf-8');
|
|
50
|
-
}
|
|
51
|
-
async function __generateApp() {
|
|
52
|
-
const templates = [['app/bootstrap.ejs', 'bootstrap.ts'], ['app/app.ejs', 'app.ts']];
|
|
53
|
-
for (const [templateSrc, templateDest] of templates) {
|
|
54
|
-
const fileSrc = resolveTemplatePath(templateSrc);
|
|
55
|
-
const fileDest = path.join(configOptions.appDir, configOptions.runtimeDir, templateDest);
|
|
56
|
-
await fse.ensureDir(path.join(configOptions.appDir, configOptions.runtimeDir));
|
|
57
|
-
const vars = {
|
|
58
|
-
appMonkey: fse.existsSync(path.join(configOptions.appDir, 'src/backend/config/monkey.ts')),
|
|
59
|
-
};
|
|
60
|
-
await copyTemplateFile(fileSrc, fileDest, vars);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
async function __generateOthers() {
|
|
64
|
-
const templates = [['app/register.js', 'register.js']];
|
|
65
|
-
for (const [templateSrc, templateDest] of templates) {
|
|
66
|
-
const fileSrc = resolveTemplatePath(templateSrc);
|
|
67
|
-
const fileDest = path.join(configOptions.appDir, configOptions.runtimeDir, templateDest);
|
|
68
|
-
await fse.ensureDir(path.join(configOptions.appDir, configOptions.runtimeDir));
|
|
69
|
-
const vars = {};
|
|
70
|
-
await copyTemplateFile(fileSrc, fileDest, vars);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
async function __generateModulesMeta() {
|
|
74
|
-
// modules
|
|
75
|
-
const { modules, modulesArray } = modulesMeta;
|
|
76
|
-
const moduleNames = modulesArray.map(item => item.info.relativeName);
|
|
77
|
-
// src
|
|
78
|
-
const fileSrc = resolveTemplatePath('app/vona-modules-meta.ejs');
|
|
79
|
-
const fileDest = path.join(configOptions.appDir, configOptions.runtimeDir, 'modules-meta.ts');
|
|
80
|
-
await fse.ensureDir(path.join(configOptions.appDir, configOptions.runtimeDir));
|
|
81
|
-
await copyTemplateFile(fileSrc, fileDest, { modules, moduleNames });
|
|
82
|
-
}
|
|
83
|
-
async function __generateEnvJson() {
|
|
84
|
-
const contentDest = `export default ${JSON.stringify(env, null, 2)} as unknown as NodeJS.ProcessEnv;\n`;
|
|
85
|
-
// output
|
|
86
|
-
const fileDest = path.join(configOptions.appDir, configOptions.runtimeDir, 'env.ts');
|
|
87
|
-
fse.ensureFileSync(fileDest);
|
|
88
|
-
fse.writeFileSync(fileDest, contentDest, 'utf-8');
|
|
89
|
-
}
|
|
90
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { createConfigUtils } from "./configUtils.js";
|
|
2
|
-
import { generateEntryFiles } from "./generateEntryFiles.js";
|
|
3
|
-
export async function generateVonaMeta(configMeta, configOptions) {
|
|
4
|
-
// config utils
|
|
5
|
-
const configUtils = createConfigUtils(configMeta, configOptions);
|
|
6
|
-
// env
|
|
7
|
-
const env = configUtils.loadEnvs();
|
|
8
|
-
// modulesMeta
|
|
9
|
-
const modulesMeta = await configUtils.loadModulesMeta();
|
|
10
|
-
// generateEntryFiles
|
|
11
|
-
await generateEntryFiles(configMeta, configOptions, modulesMeta, env);
|
|
12
|
-
// ok
|
|
13
|
-
return {
|
|
14
|
-
env,
|
|
15
|
-
modulesMeta,
|
|
16
|
-
};
|
|
17
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import fse from 'fs-extra';
|
|
4
|
-
import { copyTemplateIfNeed, pathToHref } from "../../utils.js";
|
|
5
|
-
const __ImportZodCore = 'zod/v4/core';
|
|
6
|
-
export async function generateZod(configOptions) {
|
|
7
|
-
await __generateZodCoreUtil(configOptions);
|
|
8
|
-
await __generateZodCoreSchemas(configOptions);
|
|
9
|
-
}
|
|
10
|
-
async function __generateZodCoreUtil(configOptions) {
|
|
11
|
-
const pathZodCore = parseZodCorePath(configOptions.appDir);
|
|
12
|
-
const fileSrc = path.join(pathZodCore, 'util.js');
|
|
13
|
-
const fileSrcBak = path.join(pathZodCore, 'util-origin.js');
|
|
14
|
-
copyTemplateIfNeed(fileSrc, fileSrcBak);
|
|
15
|
-
const content = fse.readFileSync(fileSrcBak).toString();
|
|
16
|
-
const contentNew = content
|
|
17
|
-
.replace('export function finalizeIssue', `let __localeAdapterFn;
|
|
18
|
-
export function setLocaleAdapter(localeAdapterFn) {
|
|
19
|
-
__localeAdapterFn=localeAdapterFn;
|
|
20
|
-
}
|
|
21
|
-
export function finalizeIssue`)
|
|
22
|
-
.replace('const message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ??', `const msg = unwrapMessage(iss.inst?._zod.def?.error?.(iss));
|
|
23
|
-
const message = (__localeAdapterFn?__localeAdapterFn(msg, iss):msg) ??`);
|
|
24
|
-
fse.writeFileSync(fileSrc, contentNew);
|
|
25
|
-
}
|
|
26
|
-
async function __generateZodCoreSchemas(configOptions) {
|
|
27
|
-
const pathZodCore = parseZodCorePath(configOptions.appDir);
|
|
28
|
-
const fileSrc = path.join(pathZodCore, 'schemas.js');
|
|
29
|
-
const fileSrcBak = path.join(pathZodCore, 'schemas-origin.js');
|
|
30
|
-
copyTemplateIfNeed(fileSrc, fileSrcBak);
|
|
31
|
-
const content = fse.readFileSync(fileSrcBak).toString();
|
|
32
|
-
const contentNew = content
|
|
33
|
-
.replace('export const $ZodType =', `let __parseAdapterFn;
|
|
34
|
-
export function setParseAdapter(parseAdapterFn) {
|
|
35
|
-
__parseAdapterFn = parseAdapterFn;
|
|
36
|
-
}
|
|
37
|
-
export const $ZodType =`)
|
|
38
|
-
.replace('inst._zod.run = inst._zod.parse;', 'inst._zod.run = __parseAdapterFn ? __parseAdapterFn(inst, inst._zod.parse) : inst._zod.parse;')
|
|
39
|
-
.replace(/inst._zod.run = (\(payload, ctx\) => \{[\s\S]*?return runChecks\(result, checks, ctx\);\s*\};)/, (_, $0) => {
|
|
40
|
-
return `const __run = ${$0}\ninst._zod.run = __parseAdapterFn ? __parseAdapterFn(inst, __run) : __run;`;
|
|
41
|
-
});
|
|
42
|
-
fse.writeFileSync(fileSrc, contentNew);
|
|
43
|
-
}
|
|
44
|
-
function parseZodCorePath(appDir) {
|
|
45
|
-
const require = createRequire(pathToHref(path.join(appDir, '/')));
|
|
46
|
-
const fileCoreIndex = require.resolve(__ImportZodCore);
|
|
47
|
-
return path.dirname(fileCoreIndex);
|
|
48
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
-
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
-
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
-
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
return path;
|
|
8
|
-
};
|
|
9
|
-
import path from 'node:path';
|
|
10
|
-
import { sleep } from '@cabloy/utils';
|
|
11
|
-
import fse from 'fs-extra';
|
|
12
|
-
import { createGeneralApp, pathToHref } from 'vona-core';
|
|
13
|
-
import whyIsNodeRunning from 'why-is-node-running';
|
|
14
|
-
import parser from 'yargs-parser';
|
|
15
|
-
const __template = `import type { IArgv, VonaApplication } from 'vona';
|
|
16
|
-
|
|
17
|
-
export async function main(app: VonaApplication, _argv: IArgv) {
|
|
18
|
-
console.log(import.meta.filename);
|
|
19
|
-
console.log(app.config.meta);
|
|
20
|
-
return 'Hello VonaJS';
|
|
21
|
-
}
|
|
22
|
-
`;
|
|
23
|
-
const projectPath = process.argv[2];
|
|
24
|
-
const argv = parser(process.argv.slice(3));
|
|
25
|
-
let mainFile;
|
|
26
|
-
if (argv._[0]?.endsWith('.ts')) {
|
|
27
|
-
mainFile = argv._[0];
|
|
28
|
-
argv._ = argv._.slice(1);
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
mainFile = 'index.ts';
|
|
32
|
-
}
|
|
33
|
-
await playRun(projectPath);
|
|
34
|
-
async function playRun(projectPath) {
|
|
35
|
-
// create
|
|
36
|
-
const app = await createGeneralApp(projectPath);
|
|
37
|
-
// play
|
|
38
|
-
const playFile = path.join(projectPath, `src/backend/play/${mainFile}`);
|
|
39
|
-
if (!fse.existsSync(playFile)) {
|
|
40
|
-
await fse.outputFile(playFile, __template);
|
|
41
|
-
}
|
|
42
|
-
// run
|
|
43
|
-
const playInstance = await import(__rewriteRelativeImportExtension(pathToHref(playFile)));
|
|
44
|
-
const res = await playInstance.main(app, argv);
|
|
45
|
-
if (res !== undefined) {
|
|
46
|
-
// eslint-disable-next-line no-console
|
|
47
|
-
console.log(res);
|
|
48
|
-
}
|
|
49
|
-
// close
|
|
50
|
-
await app.close();
|
|
51
|
-
// handles
|
|
52
|
-
if (process.env.TEST_WHYISNODERUNNING === 'true') {
|
|
53
|
-
await sleep(2000);
|
|
54
|
-
const handles = process._getActiveHandles();
|
|
55
|
-
if (handles.length > 3) {
|
|
56
|
-
whyIsNodeRunning();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { createWriteStream } from 'node:fs';
|
|
2
|
-
import os from 'node:os';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { run } from 'node:test';
|
|
5
|
-
import { lcov, spec } from 'node:test/reporters';
|
|
6
|
-
import { catchError, sleep } from '@cabloy/utils';
|
|
7
|
-
import TableClass from 'cli-table3';
|
|
8
|
-
import fse from 'fs-extra';
|
|
9
|
-
import { globby } from 'globby';
|
|
10
|
-
import { cast, createGeneralApp } from 'vona-core';
|
|
11
|
-
import whyIsNodeRunning from 'why-is-node-running';
|
|
12
|
-
import { resolveTemplatePath } from "../../utils.js";
|
|
13
|
-
const argv = process.argv.slice(2);
|
|
14
|
-
const projectPath = argv[0];
|
|
15
|
-
const coverage = argv[1] === 'true';
|
|
16
|
-
const patterns = (argv[2] || '').split(',');
|
|
17
|
-
await testRun(projectPath, coverage, patterns);
|
|
18
|
-
async function testRun(projectPath, coverage, patterns) {
|
|
19
|
-
// patterns ignore
|
|
20
|
-
const patternsIgnore = (!coverage && process.env.TEST_PATTERNS_IGNORE) ? process.env.TEST_PATTERNS_IGNORE.split(',') : undefined;
|
|
21
|
-
// files
|
|
22
|
-
const files = await globby(patterns, {
|
|
23
|
-
cwd: projectPath,
|
|
24
|
-
ignore: patternsIgnore,
|
|
25
|
-
});
|
|
26
|
-
if (process.env.TEST_ONLY === 'true') {
|
|
27
|
-
files.push(resolveTemplatePath('test/done-only.test.js'));
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
files.push(resolveTemplatePath('test/done.test.js'));
|
|
31
|
-
}
|
|
32
|
-
// coverage
|
|
33
|
-
let coverageIncludeGlobs = [];
|
|
34
|
-
if (coverage) {
|
|
35
|
-
if (fse.existsSync(path.join(projectPath, 'packages-vona/vona-core'))) {
|
|
36
|
-
coverageIncludeGlobs = coverageIncludeGlobs.concat(['packages-vona/vona-core/**/*.ts', 'src/suite-vendor/a-vona/**/*.ts']);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
coverageIncludeGlobs = coverageIncludeGlobs.concat(['src/module/**/*.ts', 'src/suite/**/*.ts']);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const coverageExcludeGlobs = [
|
|
43
|
-
'src/module/*/cli/**/*.ts',
|
|
44
|
-
'src/module/*/templates/**/*.ts',
|
|
45
|
-
'src/suite/*/modules/*/cli/**/*.ts',
|
|
46
|
-
'src/suite/*/modules/*/templates/**/*.ts',
|
|
47
|
-
'src/module-vendor/*/cli/**/*.ts',
|
|
48
|
-
'src/module-vendor/*/templates/**/*.ts',
|
|
49
|
-
'src/suite-vendor/*/modules/*/cli/**/*.ts',
|
|
50
|
-
'src/suite-vendor/*/modules/*/templates/**/*.ts',
|
|
51
|
-
];
|
|
52
|
-
// app
|
|
53
|
-
const app = await createGeneralApp(projectPath);
|
|
54
|
-
// concurrency
|
|
55
|
-
const concurrency = await prepareConcurrency(app);
|
|
56
|
-
return new Promise(resolve => {
|
|
57
|
-
const testStream = run({
|
|
58
|
-
isolation: 'none',
|
|
59
|
-
concurrency,
|
|
60
|
-
only: process.env.TEST_ONLY === 'true',
|
|
61
|
-
coverage,
|
|
62
|
-
coverageIncludeGlobs,
|
|
63
|
-
coverageExcludeGlobs,
|
|
64
|
-
cwd: projectPath,
|
|
65
|
-
files,
|
|
66
|
-
setup: async () => { },
|
|
67
|
-
})
|
|
68
|
-
.on('test:coverage', data => {
|
|
69
|
-
outputCoverageReport(data.summary.totals);
|
|
70
|
-
})
|
|
71
|
-
.on('test:summary', async () => {
|
|
72
|
-
resolve(undefined);
|
|
73
|
-
})
|
|
74
|
-
.on('test:pass', async (t) => {
|
|
75
|
-
if (t.name === '---done---') {
|
|
76
|
-
const [_, err] = await catchError(() => {
|
|
77
|
-
return app.close();
|
|
78
|
-
});
|
|
79
|
-
if (err) {
|
|
80
|
-
console.error(err);
|
|
81
|
-
}
|
|
82
|
-
// handles
|
|
83
|
-
if (process.env.TEST_WHYISNODERUNNING === 'true') {
|
|
84
|
-
await sleep(2000);
|
|
85
|
-
const handles = process._getActiveHandles();
|
|
86
|
-
if (handles.length > 3) {
|
|
87
|
-
whyIsNodeRunning();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
if (coverage) {
|
|
93
|
-
const reporterDir = path.join(projectPath, 'coverage');
|
|
94
|
-
fse.ensureDirSync(reporterDir);
|
|
95
|
-
const reporterLcov = createWriteStream(path.join(reporterDir, 'lcov.info'));
|
|
96
|
-
testStream.compose(lcov)
|
|
97
|
-
.pipe(reporterLcov);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
testStream.compose(spec)
|
|
101
|
-
.pipe(process.stdout);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
async function prepareConcurrency(app) {
|
|
106
|
-
// check
|
|
107
|
-
let concurrency = 1;
|
|
108
|
-
if (process.env.TEST_CONCURRENCY === 'true') {
|
|
109
|
-
concurrency = os.cpus().length;
|
|
110
|
-
}
|
|
111
|
-
else if (process.env.TEST_CONCURRENCY === 'false') {
|
|
112
|
-
concurrency = 1;
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
concurrency = Number.parseInt(process.env.TEST_CONCURRENCY);
|
|
116
|
-
}
|
|
117
|
-
if (concurrency === 1)
|
|
118
|
-
return concurrency;
|
|
119
|
-
// check again
|
|
120
|
-
return await cast(app.bean).executor.mockCtx(async () => {
|
|
121
|
-
const db = cast(app.bean).database.getDb();
|
|
122
|
-
return db.dialect.capabilities.level ? concurrency : 1;
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
function outputCoverageReport(totals) {
|
|
126
|
-
// table
|
|
127
|
-
const table = new TableClass({
|
|
128
|
-
head: ['', 'Total', 'Covered', 'Percent'],
|
|
129
|
-
colWidths: [15, 15, 15, 25],
|
|
130
|
-
});
|
|
131
|
-
table.push(['Lines', totals.totalLineCount, totals.coveredLineCount, totals.coveredLinePercent]);
|
|
132
|
-
table.push(['Branches', totals.totalBranchCount, totals.coveredBranchCount, totals.coveredBranchPercent]);
|
|
133
|
-
table.push(['Functions', totals.totalFunctionCount, totals.coveredFunctionCount, totals.coveredFunctionPercent]);
|
|
134
|
-
// eslint-disable-next-line
|
|
135
|
-
console.log(table.toString());
|
|
136
|
-
}
|
|
137
|
-
;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { globBeanFiles } from "./utils.js";
|
|
2
|
-
export async function generateBeanGenerals(sceneName, sceneMeta, moduleName, modulePath) {
|
|
3
|
-
const globFiles = await globBeanFiles(sceneName, sceneMeta, moduleName, modulePath);
|
|
4
|
-
if (globFiles.length === 0)
|
|
5
|
-
return '';
|
|
6
|
-
//
|
|
7
|
-
const contentImports = [];
|
|
8
|
-
const contentRecords = [];
|
|
9
|
-
for (const globFile of globFiles) {
|
|
10
|
-
const { fileNameJSRelative, className, beanName, isIgnore } = globFile;
|
|
11
|
-
const beanFullName = `${moduleName}.${sceneName}.${beanName}`;
|
|
12
|
-
if (isIgnore)
|
|
13
|
-
continue;
|
|
14
|
-
if (!sceneMeta.scopeResource) {
|
|
15
|
-
contentImports.push(`import type { ${className} } from '${fileNameJSRelative}';`);
|
|
16
|
-
}
|
|
17
|
-
contentRecords.push(`'${beanFullName}': ${className};`);
|
|
18
|
-
}
|
|
19
|
-
if (contentRecords.length === 0)
|
|
20
|
-
return '';
|
|
21
|
-
// combine
|
|
22
|
-
const content = `/** ${sceneName}: begin */
|
|
23
|
-
${contentImports.join('\n')}
|
|
24
|
-
import 'vona';
|
|
25
|
-
declare module 'vona' {
|
|
26
|
-
export interface IBeanRecordGeneral {
|
|
27
|
-
${contentRecords.join('\n')}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/** ${sceneName}: end */
|
|
31
|
-
`;
|
|
32
|
-
return content;
|
|
33
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import fse from 'fs-extra';
|
|
3
|
-
import { globby } from 'globby';
|
|
4
|
-
export async function generateConfig(modulePath) {
|
|
5
|
-
const configFile = path.join(modulePath, 'src/config/config.ts');
|
|
6
|
-
if (!fse.existsSync(configFile))
|
|
7
|
-
return '';
|
|
8
|
-
// combine
|
|
9
|
-
const content = `/** config: begin */
|
|
10
|
-
export * from '../config/config.ts';
|
|
11
|
-
import type { config } from '../config/config.ts';
|
|
12
|
-
/** config: end */
|
|
13
|
-
`;
|
|
14
|
-
return content;
|
|
15
|
-
}
|
|
16
|
-
export async function generateConstant(modulePath) {
|
|
17
|
-
const constantFile = path.join(modulePath, 'src/config/constants.ts');
|
|
18
|
-
if (!fse.existsSync(constantFile))
|
|
19
|
-
return '';
|
|
20
|
-
// combine
|
|
21
|
-
const content = `/** constant: begin */
|
|
22
|
-
export * from '../config/constants.ts';
|
|
23
|
-
import { constants } from '../config/constants.ts';
|
|
24
|
-
/** constant: end */
|
|
25
|
-
`;
|
|
26
|
-
return content;
|
|
27
|
-
}
|
|
28
|
-
export async function generateLocale(modulePath) {
|
|
29
|
-
const files = await globby('src/config/locale/*.ts', { cwd: modulePath });
|
|
30
|
-
if (files.length === 0)
|
|
31
|
-
return '';
|
|
32
|
-
files.sort();
|
|
33
|
-
const contentImports = [];
|
|
34
|
-
const contentLocales = [];
|
|
35
|
-
for (const file of files) {
|
|
36
|
-
const localeName = path.basename(file, '.ts');
|
|
37
|
-
const className = `locale_${localeName.replace('-', '_')}`;
|
|
38
|
-
contentImports.push(`import ${className} from '../config/locale/${localeName}.ts';`);
|
|
39
|
-
contentLocales.push(`'${localeName}': ${className},`);
|
|
40
|
-
}
|
|
41
|
-
// combine
|
|
42
|
-
const content = `/** locale: begin */
|
|
43
|
-
${contentImports.join('\n')}
|
|
44
|
-
export const locales = {
|
|
45
|
-
${contentLocales.join('\n')}
|
|
46
|
-
};
|
|
47
|
-
/** locale: end */
|
|
48
|
-
`;
|
|
49
|
-
return content;
|
|
50
|
-
}
|
|
51
|
-
export async function generateError(modulePath) {
|
|
52
|
-
const errorFile = path.join(modulePath, 'src/config/errors.ts');
|
|
53
|
-
if (!fse.existsSync(errorFile))
|
|
54
|
-
return '';
|
|
55
|
-
// combine
|
|
56
|
-
const content = `/** error: begin */
|
|
57
|
-
export * from '../config/errors.ts';
|
|
58
|
-
import type { errors } from '../config/errors.ts';
|
|
59
|
-
/** error: end */
|
|
60
|
-
`;
|
|
61
|
-
return content;
|
|
62
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { toUpperCaseFirstChar } from '@cabloy/word-utils';
|
|
3
|
-
import { globBeanFiles } from "./utils.js";
|
|
4
|
-
export async function generateMetadataCustom(cli, sceneName, sceneMeta, moduleName, modulePath) {
|
|
5
|
-
const sceneNameCapitalize = toUpperCaseFirstChar(sceneName);
|
|
6
|
-
const globFiles = await globBeanFiles(sceneName, sceneMeta, moduleName, modulePath);
|
|
7
|
-
if (globFiles.length === 0)
|
|
8
|
-
return '';
|
|
9
|
-
// custom
|
|
10
|
-
const jsFile = path.join(sceneMeta.module.root, sceneMeta.metadataCustom);
|
|
11
|
-
return await cli.helper.importDynamic(jsFile, async (instance) => {
|
|
12
|
-
const options = {
|
|
13
|
-
cli,
|
|
14
|
-
sceneName,
|
|
15
|
-
sceneNameCapitalize,
|
|
16
|
-
sceneMeta,
|
|
17
|
-
moduleName,
|
|
18
|
-
modulePath,
|
|
19
|
-
globFiles,
|
|
20
|
-
};
|
|
21
|
-
return await instance.default(options);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import fse from 'fs-extra';
|
|
3
|
-
export async function generateMonkey(modulePath) {
|
|
4
|
-
const monkeyFile = path.join(modulePath, 'src/monkey.ts');
|
|
5
|
-
if (!fse.existsSync(monkeyFile))
|
|
6
|
-
return '';
|
|
7
|
-
// combine
|
|
8
|
-
const content = `/** monkey: begin */
|
|
9
|
-
export * from '../monkey.ts';
|
|
10
|
-
/** monkey: end */
|
|
11
|
-
`;
|
|
12
|
-
return content;
|
|
13
|
-
}
|
|
14
|
-
export async function generateMain(modulePath) {
|
|
15
|
-
const monkeyFile = path.join(modulePath, 'src/main.ts');
|
|
16
|
-
if (!fse.existsSync(monkeyFile))
|
|
17
|
-
return '';
|
|
18
|
-
// combine
|
|
19
|
-
const content = `/** main: begin */
|
|
20
|
-
export * from '../main.ts';
|
|
21
|
-
/** main: end */
|
|
22
|
-
`;
|
|
23
|
-
return content;
|
|
24
|
-
}
|