vona-cli 1.0.375 → 1.0.377

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/bin/vona.js CHANGED
@@ -3,7 +3,7 @@ import path from 'node:path';
3
3
  import { ProcessHelper } from '@cabloy/process-helper';
4
4
  import fse from 'fs-extra';
5
5
  import semver from 'semver';
6
- import { VonaCommand } from "../start.js";
6
+ import { playAttach } from "../play.js";
7
7
  const pnpm_version = '10.19.0';
8
8
  const processHelper = new ProcessHelper(process.cwd());
9
9
  main();
@@ -24,22 +24,34 @@ async function checkPnpm() {
24
24
  }
25
25
  }
26
26
  async function main() {
27
- let args = [];
28
27
  // bootstrapFile
29
28
  let bootstrapFile = path.join(import.meta.dirname, '../bootstrap.ts');
30
29
  if (!fse.existsSync(bootstrapFile)) {
31
30
  bootstrapFile = path.join(import.meta.dirname, '../bootstrap.js');
32
31
  }
32
+ // args
33
+ let args = [];
33
34
  const rawArgv = process.argv.slice(2);
34
35
  const isPlay = rawArgv[0] === 'play';
36
+ const isPlayAttach = isPlay && (rawArgv.includes('-a') || rawArgv.includes('--attach'));
35
37
  if (isPlay) {
36
- args = args.concat([':bin:play']).concat(rawArgv.slice(1)).concat(['--dummy']);
37
- const command = new VonaCommand(args, true);
38
- await command.start();
39
- return;
38
+ if (!isPlayAttach) {
39
+ args = args.concat([bootstrapFile, ':bin:play']);
40
+ }
41
+ args = args.concat(rawArgv.slice(1)).concat(['--dummy']);
42
+ }
43
+ else {
44
+ args.push(bootstrapFile);
45
+ args = args.concat(rawArgv);
46
+ }
47
+ // run
48
+ if (isPlayAttach) {
49
+ await playAttach(process.cwd(), args);
50
+ }
51
+ else {
52
+ if (!isPlay) {
53
+ await checkPnpm();
54
+ }
55
+ processHelper.spawnCmd({ cmd: 'tsx', args });
40
56
  }
41
- args.push(bootstrapFile);
42
- args = args.concat(rawArgv);
43
- await checkPnpm();
44
- processHelper.spawnCmd({ cmd: 'tsx', args });
45
57
  }
package/dist/play.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function playAttach(projectPath: string, args: string[]): Promise<void>;
package/dist/play.js ADDED
@@ -0,0 +1,33 @@
1
+ import path from 'node:path';
2
+ import fse from 'fs-extra';
3
+ import { loadJSONFile } from "./utils.js";
4
+ export async function playAttach(projectPath, args) {
5
+ const runtimeFile = path.join(projectPath, '.app/runtime/-.json');
6
+ if (!fse.existsSync(runtimeFile))
7
+ throw new Error('dev server not running');
8
+ // body
9
+ const body = { args, projectPath };
10
+ //
11
+ const runtime = await loadJSONFile(runtimeFile);
12
+ const runtimeCore = runtime['a-core'];
13
+ const runtimeUser = runtime['a-user'];
14
+ const result = await fetch(`${runtimeCore?.protocol}://${runtimeCore?.host}/api/play`, {
15
+ method: 'post',
16
+ headers: {
17
+ 'content-type': 'application/json',
18
+ 'authorization': `Bearer ${runtimeUser?.accessToken}`,
19
+ },
20
+ body: JSON.stringify(body),
21
+ });
22
+ if (result.status !== 200) {
23
+ const message = `error: ${result.status}, ${result.statusText}`;
24
+ throw new Error(message);
25
+ }
26
+ const res = await result.json();
27
+ if (res.code !== 0)
28
+ throw new Error(res.message);
29
+ if (res.data !== undefined) {
30
+ // eslint-disable-next-line no-console
31
+ console.log(res.data);
32
+ }
33
+ }
@@ -0,0 +1 @@
1
+ export declare function loadJSONFile(fileName: string): Promise<any>;
package/dist/utils.js ADDED
@@ -0,0 +1,5 @@
1
+ import fse from 'fs-extra';
2
+ export async function loadJSONFile(fileName) {
3
+ const pkgContent = (await fse.readFile(fileName)).toString();
4
+ return JSON.parse(pkgContent);
5
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-cli",
3
3
  "type": "module",
4
- "version": "1.0.375",
4
+ "version": "1.0.377",
5
5
  "description": "vona cli",
6
6
  "publishConfig": {
7
7
  "access": "public"