vona-cli-set-api 1.0.406 → 1.0.407
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +6 -6
- 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
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 = [];
|
|
@@ -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.407",
|
|
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
|