@gaiaworks/gaia-cli 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -17,4 +17,14 @@ npx @gaiaworks/gaia-cli@latest install
17
17
  gaia-cli version
18
18
  ```
19
19
 
20
+ 安装模式:
21
+
22
+ ```bash
23
+ npx @gaiaworks/gaia-cli@latest install
24
+ npx @gaiaworks/gaia-cli@latest install --mode external
25
+ npx @gaiaworks/gaia-cli@latest install --mode internal
26
+ ```
27
+
28
+ 未指定 `--mode` 时默认写入 `external`。安装脚本会在全局安装完成后执行 `gaia-cli config set mode <external|internal>`,用于后续区分内部/外部登录流程和 shared skill 规则。
29
+
20
30
  安装时会根据 npm 包版本,从 `gaiaworks/gaia-cli-releases` 的同版本 GitHub Release 下载当前平台对应的 `gaia-cli` 二进制。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gaiaworks/gaia-cli",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "JavaScript launcher for gaia-cli.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -4,21 +4,83 @@
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
6
  const { spawnSync } = require('child_process');
7
+ const { binaryName, install } = require('./install');
7
8
 
8
9
  const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
9
10
  const packageSpec = `${packageJson.name}@${packageJson.version}`;
11
+ const binaryPath = path.join(__dirname, '..', 'bin', binaryName());
10
12
 
11
- const result = spawnSync('npm', ['install', '-g', packageSpec], {
12
- stdio: 'inherit',
13
- });
13
+ function parseInstallArgs(args) {
14
+ let mode = 'external';
15
+ const npmArgs = [];
14
16
 
15
- if (result.error) {
16
- console.error(`[gaia-cli] Failed to run npm install: ${result.error.message}`);
17
- process.exit(1);
17
+ for (let i = 0; i < args.length; i += 1) {
18
+ const arg = args[i];
19
+ if (arg === '--mode') {
20
+ const value = args[i + 1];
21
+ if (!value) {
22
+ throw new Error('--mode requires a value: internal or external');
23
+ }
24
+ mode = value;
25
+ i += 1;
26
+ continue;
27
+ }
28
+ if (arg.startsWith('--mode=')) {
29
+ mode = arg.slice('--mode='.length);
30
+ continue;
31
+ }
32
+ npmArgs.push(arg);
33
+ }
34
+
35
+ if (mode !== 'internal' && mode !== 'external') {
36
+ throw new Error(`Unsupported mode: ${mode}. Expected internal or external.`);
37
+ }
38
+
39
+ return { mode, npmArgs };
40
+ }
41
+
42
+ function run(command, args) {
43
+ const result = spawnSync(command, args, {
44
+ stdio: 'inherit',
45
+ });
46
+
47
+ if (result.error) {
48
+ console.error(`[gaia-cli] Failed to run ${command}: ${result.error.message}`);
49
+ process.exit(1);
50
+ }
51
+
52
+ if (result.status !== 0) {
53
+ process.exit(typeof result.status === 'number' ? result.status : 1);
54
+ }
55
+ }
56
+
57
+ function ensureLocalBinary() {
58
+ if (fs.existsSync(binaryPath)) return;
59
+ install();
60
+ }
61
+
62
+ function installWizard(args) {
63
+ const { mode, npmArgs } = parseInstallArgs(args);
64
+ if (npmArgs.length > 0) {
65
+ throw new Error(`Unsupported install arguments: ${npmArgs.join(' ')}`);
66
+ }
67
+
68
+ ensureLocalBinary();
69
+ run('npm', ['install', '-g', packageSpec]);
70
+ run(binaryPath, ['config', 'set', 'mode', mode]);
71
+ console.error(`[gaia-cli] Global install completed with mode: ${mode}. You can now run: gaia-cli version`);
18
72
  }
19
73
 
20
- if (result.status !== 0) {
21
- process.exit(typeof result.status === 'number' ? result.status : 1);
74
+ if (require.main === module) {
75
+ try {
76
+ installWizard(process.argv.slice(2));
77
+ } catch (error) {
78
+ console.error(`[gaia-cli] Install failed: ${error.message}`);
79
+ process.exit(1);
80
+ }
22
81
  }
23
82
 
24
- console.error('[gaia-cli] Global install completed. You can now run: gaia-cli version');
83
+ module.exports = {
84
+ installWizard,
85
+ parseInstallArgs,
86
+ };