vona-cli-set-api 1.1.155 → 1.1.156

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 CHANGED
@@ -20,6 +20,7 @@ import { getEnvFiles } from '@cabloy/dotenv';
20
20
  import { glob } from '@cabloy/module-glob';
21
21
  import os from 'node:os';
22
22
  import chalk from 'chalk';
23
+ import { spawn } from 'node:child_process';
23
24
  import nodemon from 'nodemon';
24
25
  import { catchError, combineApiPathControllerAndActionRaw, replaceTemplate } from '@cabloy/utils';
25
26
  import { getOnionScenesMeta, getOnionMetasMeta, relativeNameToCapitalize } from '@cabloy/module-info';
@@ -768,6 +769,16 @@ class CliBinDbReset extends BeanCliBase {
768
769
  }
769
770
  }
770
771
 
772
+ function resolveDevMode(mode) {
773
+ if (mode === undefined || mode === 'dev') return 'dev';
774
+ if (mode === 'test') return 'test';
775
+ throw new Error('Invalid --mode: expected dev or test');
776
+ }
777
+ function resolveTestWorkers(mode, workers) {
778
+ if (mode !== 'test') return workers;
779
+ if (workers === undefined || workers === 1) return 1;
780
+ throw new Error('--mode=test requires --workers=1');
781
+ }
771
782
  class CliBinDev extends BeanCliBase {
772
783
  async execute() {
773
784
  const {
@@ -783,7 +794,8 @@ class CliBinDev extends BeanCliBase {
783
794
  const {
784
795
  argv
785
796
  } = this.context;
786
- const mode = 'dev';
797
+ const mode = resolveDevMode(argv.mode);
798
+ const workers = resolveTestWorkers(mode, argv.workers);
787
799
  const flavor = argv.flavor || 'normal';
788
800
  const configMeta = {
789
801
  flavor,
@@ -792,13 +804,42 @@ class CliBinDev extends BeanCliBase {
792
804
  const configOptions = {
793
805
  appDir: projectPath,
794
806
  runtimeDir: '.vona',
795
- workers: argv.workers
807
+ workers
796
808
  };
797
- const {
798
- modulesMeta
799
- } = await generateVonaMeta(configMeta, configOptions);
800
- await this._run(projectPath, modulesMeta);
801
- await rimraf(path.join(projectPath, '.vona'));
809
+ try {
810
+ const {
811
+ modulesMeta
812
+ } = await generateVonaMeta(configMeta, configOptions);
813
+ if (mode === 'test') {
814
+ await this._runTest(projectPath);
815
+ } else {
816
+ await this._run(projectPath, modulesMeta);
817
+ }
818
+ } finally {
819
+ await rimraf(path.join(projectPath, '.vona'));
820
+ }
821
+ }
822
+ async _runTest(projectPath) {
823
+ const child = spawn(process.execPath, [getImportEsm(), '.vona/bootstrap.ts'], {
824
+ cwd: projectPath,
825
+ stdio: 'inherit'
826
+ });
827
+ const forwardSignal = signal => child.kill(signal);
828
+ const onInterrupt = () => forwardSignal('SIGINT');
829
+ const onTerminate = () => forwardSignal('SIGTERM');
830
+ process.on('SIGINT', onInterrupt);
831
+ process.on('SIGTERM', onTerminate);
832
+ try {
833
+ await new Promise((resolve, reject) => {
834
+ child.once('error', reject);
835
+ child.once('exit', (code, signal) => {
836
+ if (code === 0) resolve();else reject(new Error(`Test-mode dev server exited: ${signal ?? code}`));
837
+ });
838
+ });
839
+ } finally {
840
+ process.off('SIGINT', onInterrupt);
841
+ process.off('SIGTERM', onTerminate);
842
+ }
802
843
  }
803
844
  async _run(projectPath, _modulesMeta) {
804
845
  let closed = false;
@@ -3471,7 +3512,7 @@ var binDev = {
3471
3512
  info: {
3472
3513
  version: '5.0.0',
3473
3514
  title: 'Cli: Bin: Dev',
3474
- usage: 'npm run vona :bin:dev -- [--workers=] [--flavor=]'
3515
+ usage: 'npm run vona :bin:dev -- [--workers=] [--flavor=] [--mode=dev|test]'
3475
3516
  },
3476
3517
  options: {
3477
3518
  workers: {
@@ -3481,6 +3522,11 @@ var binDev = {
3481
3522
  flavor: {
3482
3523
  description: 'flavor',
3483
3524
  type: 'string'
3525
+ },
3526
+ mode: {
3527
+ description: 'dev or test',
3528
+ type: 'string',
3529
+ choices: ['dev', 'test']
3484
3530
  }
3485
3531
  }
3486
3532
  };
@@ -1,14 +1,18 @@
1
1
  import type { glob } from '@cabloy/module-glob';
2
- import type { VonaMetaFlavor } from '@cabloy/module-info';
2
+ import type { VonaMetaFlavor, VonaMetaMode } from '@cabloy/module-info';
3
3
  import { BeanCliBase } from '@cabloy/cli';
4
+ export declare function resolveDevMode(mode: unknown): 'dev' | 'test';
5
+ export declare function resolveTestWorkers(mode: 'dev' | 'test', workers: unknown): number | undefined;
4
6
  declare module '@cabloy/cli' {
5
7
  interface ICommandArgv {
6
8
  workers?: number;
7
9
  flavor?: VonaMetaFlavor;
10
+ mode?: VonaMetaMode;
8
11
  }
9
12
  }
10
13
  export declare class CliBinDev extends BeanCliBase {
11
14
  execute(): Promise<void>;
12
15
  _dev(projectPath: string): Promise<void>;
16
+ _runTest(projectPath: string): Promise<void>;
13
17
  _run(projectPath: string, _modulesMeta: Awaited<ReturnType<typeof glob>>): Promise<unknown>;
14
18
  }
@@ -14,6 +14,11 @@ declare const _default: {
14
14
  description: string;
15
15
  type: string;
16
16
  };
17
+ mode: {
18
+ description: string;
19
+ type: string;
20
+ choices: string[];
21
+ };
17
22
  };
18
23
  };
19
24
  export default _default;
@@ -104,6 +104,11 @@ export declare const commands: {
104
104
  description: string;
105
105
  type: string;
106
106
  };
107
+ mode: {
108
+ description: string;
109
+ type: string;
110
+ choices: string[];
111
+ };
107
112
  };
108
113
  };
109
114
  play: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-cli-set-api",
3
- "version": "1.1.155",
4
- "gitHead": "8d575dd958be6aa16daa249bdbdb024d20d0789d",
3
+ "version": "1.1.156",
4
+ "gitHead": "6933fa57c12a517fe3819ccf16f3d619e5a22471",
5
5
  "description": "vona cli-set-api",
6
6
  "keywords": [
7
7
  "framework",