vona-cli-set-api 1.0.406 → 1.0.409
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/package.original.json +1 -1
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-base/package.json +1 -1
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-base/src/.metadata/index.ts +0 -1
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-index/package.json +1 -1
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-index/src/.metadata/index.ts +1 -10
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-index/src/.metadata/locales.ts +12 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-index/src/controller/home.ts +1 -1
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-index/src/index.ts +1 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/package.json +1 -1
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/.metadata/index.ts +1 -10
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/.metadata/locales.ts +12 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/entity/role.ts +1 -1
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/entity/user.ts +1 -1
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/index.ts +1 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/package.json +1 -1
- package/cli/templates/tools/crud/boilerplate/src/entity/{{resourceName}}.ts_ +1 -1
- package/dist/index.js +44 -18
- package/dist/lib/bean/cli.tools.metadata.d.ts +1 -0
- package/dist/lib/bean/toolsMetadata/generateConfig.d.ts +2 -1
- package/dist-toolsIsolate/dbReset.js +8 -0
- package/dist-toolsIsolate/play.js +59 -0
- package/dist-toolsIsolate/test.js +141 -0
- package/package.json +4 -3
- /package/{dist/lib/bean/toolsIsolate → dist-toolsIsolate}/dbReset.d.ts +0 -0
- /package/{dist/lib/bean/toolsIsolate → dist-toolsIsolate}/play.d.ts +0 -0
- /package/{dist/lib/bean/toolsIsolate → dist-toolsIsolate}/test.d.ts +0 -0
|
@@ -69,12 +69,7 @@ declare module 'vona-module-a-web' {
|
|
|
69
69
|
}
|
|
70
70
|
/** controller: end */
|
|
71
71
|
/** locale: begin */
|
|
72
|
-
import
|
|
73
|
-
import locale_zh_cn from '../config/locale/zh-cn.ts';
|
|
74
|
-
export const locales = {
|
|
75
|
-
'en-us': locale_en_us,
|
|
76
|
-
'zh-cn': locale_zh_cn,
|
|
77
|
-
};
|
|
72
|
+
import { locales } from './locales.ts'
|
|
78
73
|
/** locale: end */
|
|
79
74
|
/** scope: begin */
|
|
80
75
|
import { BeanScopeBase, type BeanScopeUtil, type TypeModuleLocales, type TypeLocaleBase } from 'vona';
|
|
@@ -106,8 +101,4 @@ declare module 'vona' {
|
|
|
106
101
|
|
|
107
102
|
|
|
108
103
|
}
|
|
109
|
-
|
|
110
|
-
export function $locale<K extends keyof (typeof locales)[TypeLocaleBase]>(key: K): `home-index::${K}` {
|
|
111
|
-
return `home-index::${key}`;
|
|
112
|
-
}
|
|
113
104
|
/** scope: end */
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TypeLocaleBase } from 'vona';
|
|
2
|
+
import locale_en_us from '../config/locale/en-us.ts';
|
|
3
|
+
import locale_zh_cn from '../config/locale/zh-cn.ts';
|
|
4
|
+
|
|
5
|
+
export const locales = {
|
|
6
|
+
'en-us': locale_en_us,
|
|
7
|
+
'zh-cn': locale_zh_cn,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function $locale<K extends keyof (typeof locales)[TypeLocaleBase]>(key: K): `home-index::${K}` {
|
|
11
|
+
return `home-index::${key}`;
|
|
12
|
+
}
|
|
@@ -3,7 +3,7 @@ import { BeanBase } from 'vona';
|
|
|
3
3
|
import { Api } from 'vona-module-a-openapiutils';
|
|
4
4
|
import { Passport } from 'vona-module-a-user';
|
|
5
5
|
import { Controller, Web } from 'vona-module-a-web';
|
|
6
|
-
import { $locale } from '../.metadata/
|
|
6
|
+
import { $locale } from '../.metadata/locales.ts';
|
|
7
7
|
|
|
8
8
|
export interface IControllerOptionsHome extends IDecoratorControllerOptions {}
|
|
9
9
|
|
|
@@ -571,12 +571,7 @@ export * from '../config/config.ts';
|
|
|
571
571
|
import type { config } from '../config/config.ts';
|
|
572
572
|
/** config: end */
|
|
573
573
|
/** locale: begin */
|
|
574
|
-
import
|
|
575
|
-
import locale_zh_cn from '../config/locale/zh-cn.ts';
|
|
576
|
-
export const locales = {
|
|
577
|
-
'en-us': locale_en_us,
|
|
578
|
-
'zh-cn': locale_zh_cn,
|
|
579
|
-
};
|
|
574
|
+
import { locales } from './locales.ts'
|
|
580
575
|
/** locale: end */
|
|
581
576
|
/** scope: begin */
|
|
582
577
|
import { BeanScopeBase, type BeanScopeUtil, type TypeModuleConfig, type TypeModuleLocales, type TypeLocaleBase } from 'vona';
|
|
@@ -614,8 +609,4 @@ declare module 'vona' {
|
|
|
614
609
|
|
|
615
610
|
|
|
616
611
|
}
|
|
617
|
-
|
|
618
|
-
export function $locale<K extends keyof (typeof locales)[TypeLocaleBase]>(key: K): `home-user::${K}` {
|
|
619
|
-
return `home-user::${key}`;
|
|
620
|
-
}
|
|
621
612
|
/** scope: end */
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TypeLocaleBase } from 'vona';
|
|
2
|
+
import locale_en_us from '../config/locale/en-us.ts';
|
|
3
|
+
import locale_zh_cn from '../config/locale/zh-cn.ts';
|
|
4
|
+
|
|
5
|
+
export const locales = {
|
|
6
|
+
'en-us': locale_en_us,
|
|
7
|
+
'zh-cn': locale_zh_cn,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function $locale<K extends keyof (typeof locales)[TypeLocaleBase]>(key: K): `home-user::${K}` {
|
|
11
|
+
return `home-user::${key}`;
|
|
12
|
+
}
|
|
@@ -2,7 +2,7 @@ import type { IDecoratorEntityOptions } from 'vona-module-a-orm';
|
|
|
2
2
|
import type { IRole } from 'vona-module-a-user';
|
|
3
3
|
import { Api, v } from 'vona-module-a-openapiutils';
|
|
4
4
|
import { Entity, EntityBase } from 'vona-module-a-orm';
|
|
5
|
-
import { $locale } from '../.metadata/
|
|
5
|
+
import { $locale } from '../.metadata/locales.ts';
|
|
6
6
|
|
|
7
7
|
export interface IEntityOptionsRole extends IDecoratorEntityOptions {}
|
|
8
8
|
|
|
@@ -4,7 +4,7 @@ import type { IUser } from 'vona-module-a-user';
|
|
|
4
4
|
import { Api, v } from 'vona-module-a-openapiutils';
|
|
5
5
|
import { Entity, EntityBase } from 'vona-module-a-orm';
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
-
import { $locale } from '../.metadata/
|
|
7
|
+
import { $locale } from '../.metadata/locales.ts';
|
|
8
8
|
|
|
9
9
|
export interface IEntityOptionsUser extends IDecoratorEntityOptions {}
|
|
10
10
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IDecoratorEntityOptions } from 'vona-module-a-orm';
|
|
2
2
|
import { Api, v } from 'vona-module-a-openapiutils';
|
|
3
3
|
import { Entity, EntityBase } from 'vona-module-a-orm';
|
|
4
|
-
import { $locale } from '../.metadata/
|
|
4
|
+
import { $locale } from '../.metadata/locales.ts';
|
|
5
5
|
|
|
6
6
|
export interface IEntityOptions<%=argv.resourceNameCapitalize%> extends IDecoratorEntityOptions {}
|
|
7
7
|
|
package/dist/index.js
CHANGED
|
@@ -690,9 +690,9 @@ class CliBinDbReset extends BeanCliBase {
|
|
|
690
690
|
}
|
|
691
691
|
async _run(projectPath, _modulesMeta) {
|
|
692
692
|
// testFile
|
|
693
|
-
let testFile = path.join(import.meta.dirname, '
|
|
693
|
+
let testFile = path.join(import.meta.dirname, '../../../toolsIsolate/dbReset.ts');
|
|
694
694
|
if (!fse.existsSync(testFile)) {
|
|
695
|
-
testFile = path.join(import.meta.dirname, '
|
|
695
|
+
testFile = path.join(import.meta.dirname, '../dist-toolsIsolate/dbReset.js');
|
|
696
696
|
}
|
|
697
697
|
// run
|
|
698
698
|
let args = [];
|
|
@@ -848,9 +848,9 @@ class CliBinPlay extends BeanCliBase {
|
|
|
848
848
|
}
|
|
849
849
|
async _runIsolate(projectPath) {
|
|
850
850
|
// testFile
|
|
851
|
-
let testFile = path.join(import.meta.dirname, '
|
|
851
|
+
let testFile = path.join(import.meta.dirname, '../../../toolsIsolate/play.ts');
|
|
852
852
|
if (!fse.existsSync(testFile)) {
|
|
853
|
-
testFile = path.join(import.meta.dirname, '
|
|
853
|
+
testFile = path.join(import.meta.dirname, '../dist-toolsIsolate/play.js');
|
|
854
854
|
}
|
|
855
855
|
// run
|
|
856
856
|
let args = [];
|
|
@@ -912,9 +912,9 @@ class CliBinTest extends BeanCliBase {
|
|
|
912
912
|
// globs
|
|
913
913
|
const patterns = this._combineTestPatterns(projectPath, modulesMeta);
|
|
914
914
|
// testFile
|
|
915
|
-
let testFile = path.join(import.meta.dirname, '
|
|
915
|
+
let testFile = path.join(import.meta.dirname, '../../../toolsIsolate/test.ts');
|
|
916
916
|
if (!fse.existsSync(testFile)) {
|
|
917
|
-
testFile = path.join(import.meta.dirname, '
|
|
917
|
+
testFile = path.join(import.meta.dirname, '../dist-toolsIsolate/test.js');
|
|
918
918
|
}
|
|
919
919
|
// run
|
|
920
920
|
let args = [];
|
|
@@ -2151,7 +2151,7 @@ import { constants } from '../config/constants.ts';
|
|
|
2151
2151
|
`;
|
|
2152
2152
|
return content;
|
|
2153
2153
|
}
|
|
2154
|
-
async function
|
|
2154
|
+
async function generateLocale1(modulePath, moduleName) {
|
|
2155
2155
|
const files = await globby('src/config/locale/*.ts', {
|
|
2156
2156
|
cwd: modulePath
|
|
2157
2157
|
});
|
|
@@ -2163,14 +2163,27 @@ async function generateLocale(modulePath) {
|
|
|
2163
2163
|
const localeName = path.basename(file, '.ts');
|
|
2164
2164
|
const className = `locale_${localeName.replace('-', '_')}`;
|
|
2165
2165
|
contentImports.push(`import ${className} from '../config/locale/${localeName}.ts';`);
|
|
2166
|
-
contentLocales.push(`'${localeName}': ${className},`);
|
|
2166
|
+
contentLocales.push(` '${localeName}': ${className},`);
|
|
2167
2167
|
}
|
|
2168
2168
|
// combine
|
|
2169
|
-
const content =
|
|
2169
|
+
const content = `import type { TypeLocaleBase } from 'vona';
|
|
2170
2170
|
${contentImports.join('\n')}
|
|
2171
|
+
|
|
2171
2172
|
export const locales = {
|
|
2172
|
-
|
|
2173
|
+
${contentLocales.join('\n')}
|
|
2173
2174
|
};
|
|
2175
|
+
|
|
2176
|
+
export function $locale<K extends keyof (typeof locales)[TypeLocaleBase]>(key: K): \`${moduleName}::\${K}\` {
|
|
2177
|
+
return \`${moduleName}::\${key}\`;
|
|
2178
|
+
}
|
|
2179
|
+
`;
|
|
2180
|
+
return content;
|
|
2181
|
+
}
|
|
2182
|
+
async function generateLocale2(contentLocales) {
|
|
2183
|
+
if (!contentLocales) return '';
|
|
2184
|
+
// combine
|
|
2185
|
+
const content = `/** locale: begin */
|
|
2186
|
+
import { locales } from './locales.ts'
|
|
2174
2187
|
/** locale: end */
|
|
2175
2188
|
`;
|
|
2176
2189
|
return content;
|
|
@@ -2406,9 +2419,6 @@ declare module 'vona' {
|
|
|
2406
2419
|
'${moduleName}': typeof errors;
|
|
2407
2420
|
}` : ''}
|
|
2408
2421
|
}
|
|
2409
|
-
${options.locales ? `\nexport function $locale<K extends keyof (typeof locales)[TypeLocaleBase]>(key: K): \`${moduleName}::\${K}\` {
|
|
2410
|
-
return \`${moduleName}::\${key}\`;
|
|
2411
|
-
}` : ''}
|
|
2412
2422
|
/** scope: end */
|
|
2413
2423
|
`;
|
|
2414
2424
|
return content;
|
|
@@ -2552,8 +2562,9 @@ class CliToolsMetadata extends BeanCliBase {
|
|
|
2552
2562
|
const contentConstants = await generateConstant(modulePath);
|
|
2553
2563
|
content += contentConstants;
|
|
2554
2564
|
// locale
|
|
2555
|
-
const
|
|
2556
|
-
|
|
2565
|
+
const contentLocales1 = await generateLocale1(modulePath, moduleName);
|
|
2566
|
+
const contentLocales2 = await generateLocale2(contentLocales1);
|
|
2567
|
+
content += contentLocales2;
|
|
2557
2568
|
// error
|
|
2558
2569
|
const contentErrors = await generateError(modulePath);
|
|
2559
2570
|
content += contentErrors;
|
|
@@ -2562,12 +2573,13 @@ class CliToolsMetadata extends BeanCliBase {
|
|
|
2562
2573
|
// main
|
|
2563
2574
|
content += await generateMain(modulePath);
|
|
2564
2575
|
// scope
|
|
2565
|
-
|
|
2576
|
+
const generateScopeOptions = {
|
|
2566
2577
|
config: contentConfig,
|
|
2567
2578
|
errors: contentErrors,
|
|
2568
|
-
locales:
|
|
2579
|
+
locales: contentLocales2,
|
|
2569
2580
|
constants: contentConstants
|
|
2570
|
-
}
|
|
2581
|
+
};
|
|
2582
|
+
content += await generateScope(moduleName, relativeNameCapitalize, scopeResources, generateScopeOptions);
|
|
2571
2583
|
// patch
|
|
2572
2584
|
content = this._generatePatch(content);
|
|
2573
2585
|
// empty
|
|
@@ -2579,6 +2591,8 @@ class CliToolsMetadata extends BeanCliBase {
|
|
|
2579
2591
|
// save
|
|
2580
2592
|
await fse.writeFile(metaIndexFile, content);
|
|
2581
2593
|
// await this.helper.formatFile({ fileName: metaIndexFile, logPrefix: 'format: ' });
|
|
2594
|
+
// locales
|
|
2595
|
+
await this._generateLocales(modulePath, contentLocales1);
|
|
2582
2596
|
// generate this
|
|
2583
2597
|
await this._generateThis(moduleName, relativeNameCapitalize, modulePath);
|
|
2584
2598
|
// index
|
|
@@ -2603,6 +2617,12 @@ class CliToolsMetadata extends BeanCliBase {
|
|
|
2603
2617
|
const importContent = `import ${type ? 'type ' : ''}{ ${items.join(',')} } from '${packageName}';`;
|
|
2604
2618
|
return `${importContent}\n${content}`;
|
|
2605
2619
|
}
|
|
2620
|
+
async _generateLocales(modulePath, contentLocales) {
|
|
2621
|
+
if (!contentLocales) return;
|
|
2622
|
+
const localesDest = path.join(modulePath, 'src/.metadata/locales.ts');
|
|
2623
|
+
// save
|
|
2624
|
+
await fse.writeFile(localesDest, contentLocales);
|
|
2625
|
+
}
|
|
2606
2626
|
async _generateThis(moduleName, relativeNameCapitalize, modulePath) {
|
|
2607
2627
|
const thisDest = path.join(modulePath, 'src/.metadata/this.ts');
|
|
2608
2628
|
if (fse.existsSync(thisDest)) return;
|
|
@@ -2630,6 +2650,12 @@ export { ScopeModule${relativeNameCapitalize} as ScopeModule } from './index.ts'
|
|
|
2630
2650
|
if (fse.existsSync(jsLibFile) && !jsContent.includes(jsLib)) {
|
|
2631
2651
|
jsContent = `${jsLib}\n${jsContent}`;
|
|
2632
2652
|
}
|
|
2653
|
+
// jsLocales
|
|
2654
|
+
const jsLocales = "export * from './.metadata/locales.ts';";
|
|
2655
|
+
const jsLocalesFile = path.join(modulePath, 'src/.metadata/locales.ts');
|
|
2656
|
+
if (fse.existsSync(jsLocalesFile) && !jsContent.includes(jsLocales)) {
|
|
2657
|
+
jsContent = `${jsLocales}\n${jsContent}`;
|
|
2658
|
+
}
|
|
2633
2659
|
// jsMetadata
|
|
2634
2660
|
const jsMetadata = "export * from './.metadata/index.ts';";
|
|
2635
2661
|
const jsMetadataFile = path.join(modulePath, 'src/.metadata/index.ts');
|
|
@@ -9,6 +9,7 @@ export declare class CliToolsMetadata extends BeanCliBase {
|
|
|
9
9
|
_generateMetadata(moduleName: string, force: boolean): Promise<void>;
|
|
10
10
|
_generatePatch(content: string): string;
|
|
11
11
|
_generatePatch_resources(content: string, packageName: string, resources: string[], type: boolean): string;
|
|
12
|
+
_generateLocales(modulePath: any, contentLocales: any): Promise<void>;
|
|
12
13
|
_generateThis(moduleName: string, relativeNameCapitalize: string, modulePath: string): Promise<void>;
|
|
13
14
|
_generateIndex(modulePath: string): Promise<void>;
|
|
14
15
|
_generatePackage(modulePath: string): Promise<void>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare function generateConfig(modulePath: string): Promise<"" | "/** config: begin */\nexport * from '../config/config.ts';\nimport type { config } from '../config/config.ts';\n/** config: end */\n">;
|
|
2
2
|
export declare function generateConstant(modulePath: string): Promise<"" | "/** constant: begin */\nexport * from '../config/constants.ts';\nimport { constants } from '../config/constants.ts';\n/** constant: end */\n">;
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function generateLocale1(modulePath: string, moduleName: string): Promise<string>;
|
|
4
|
+
export declare function generateLocale2(contentLocales: string): Promise<"" | "/** locale: begin */\nimport { locales } from './locales.ts'\n/** locale: end */\n">;
|
|
4
5
|
export declare function generateError(modulePath: string): Promise<"" | "/** error: begin */\nexport * from '../config/errors.ts';\nimport type { errors } from '../config/errors.ts';\n/** error: end */\n">;
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
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 { fileURLToPath } from 'node:url';
|
|
7
|
+
import { catchError, sleep } from '@cabloy/utils';
|
|
8
|
+
import TableClass from 'cli-table3';
|
|
9
|
+
import fse from 'fs-extra';
|
|
10
|
+
import { globby } from 'globby';
|
|
11
|
+
import { cast, createGeneralApp } from 'vona-core';
|
|
12
|
+
import whyIsNodeRunning from 'why-is-node-running';
|
|
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
|
+
;
|
|
138
|
+
function resolveTemplatePath(file) {
|
|
139
|
+
const url = (new URL(path.join('../templates', file), import.meta.url));
|
|
140
|
+
return fileURLToPath(url);
|
|
141
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vona-cli-set-api",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.409",
|
|
5
5
|
"description": "vona cli-set-api",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"files": [
|
|
26
26
|
"cli",
|
|
27
27
|
"dist",
|
|
28
|
+
"dist-toolsIsolate",
|
|
28
29
|
"templates"
|
|
29
30
|
],
|
|
30
31
|
"dependencies": {
|
|
@@ -68,7 +69,7 @@
|
|
|
68
69
|
},
|
|
69
70
|
"gitHead": "0eab9dc4a5622caffe89e7b1b3f02c08ccbc4c4b",
|
|
70
71
|
"scripts": {
|
|
71
|
-
"clean": "rimraf dist tsconfig.tsbuildinfo",
|
|
72
|
-
"tsc:publish": "npm run clean && vona :bin:buildGeneral && tsc && tsc -p tsconfig.isolate.json"
|
|
72
|
+
"clean": "rimraf dist dist-toolsIsolate tsconfig.build.tsbuildinfo tsconfig.isolate.tsbuildinfo",
|
|
73
|
+
"tsc:publish": "npm run clean && vona :bin:buildGeneral && tsc -p tsconfig.build.json && tsc -p tsconfig.isolate.json"
|
|
73
74
|
}
|
|
74
75
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|