@gaiaworks/gaia-cli 0.0.1 → 0.0.3

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
- 安装时会根据 npm 包版本,从 `gaiaworks/gaia-cli-releases` 的同版本 GitHub Release 下载当前平台对应的 `gaia-cli` 二进制。
20
+ 安装模式:
21
+
22
+ ```bash
23
+ npx @gaiaworks/gaia-cli@latest install
24
+ npx @gaiaworks/gaia-cli@latest install --mode saas
25
+ npx @gaiaworks/gaia-cli@latest install --mode work
26
+ ```
27
+
28
+ 未指定 `--mode` 时默认写入 `saas`。安装脚本会在全局安装完成后执行 `gaia-cli config set mode <saas|work>`,用于后续区分内部/外部登录流程和 shared skill 规则。
29
+
30
+ 安装时会根据 npm 包版本,从 OSS 的同版本目录下载当前平台对应的 `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.3",
4
4
  "description": "JavaScript launcher for gaia-cli.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -4,21 +4,90 @@
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 = 'saas';
15
+ let explicitMode = false;
16
+ const npmArgs = [];
14
17
 
15
- if (result.error) {
16
- console.error(`[gaia-cli] Failed to run npm install: ${result.error.message}`);
17
- process.exit(1);
18
+ for (let i = 0; i < args.length; i += 1) {
19
+ const arg = args[i];
20
+ if (arg === '--mode') {
21
+ const value = args[i + 1];
22
+ if (!value) {
23
+ throw new Error('--mode requires a value: work or saas');
24
+ }
25
+ mode = value;
26
+ explicitMode = true;
27
+ i += 1;
28
+ continue;
29
+ }
30
+ if (arg.startsWith('--mode=')) {
31
+ mode = arg.slice('--mode='.length);
32
+ explicitMode = true;
33
+ continue;
34
+ }
35
+ npmArgs.push(arg);
36
+ }
37
+
38
+ if (mode !== 'work' && mode !== 'saas') {
39
+ throw new Error(`Unsupported mode: ${mode}. Expected work or saas.`);
40
+ }
41
+
42
+ return { explicitMode, mode, npmArgs };
43
+ }
44
+
45
+ function run(command, args, options = {}) {
46
+ const result = spawnSync(command, args, {
47
+ stdio: options.stdio || 'inherit',
48
+ });
49
+
50
+ if (result.error) {
51
+ console.error(`[gaia-cli] Failed to run ${command}: ${result.error.message}`);
52
+ process.exit(1);
53
+ }
54
+
55
+ if (result.status !== 0) {
56
+ process.exit(typeof result.status === 'number' ? result.status : 1);
57
+ }
58
+ }
59
+
60
+ function ensureLocalBinary() {
61
+ if (fs.existsSync(binaryPath)) return;
62
+ install();
63
+ }
64
+
65
+ function installWizard(args) {
66
+ const { explicitMode, mode, npmArgs } = parseInstallArgs(args);
67
+ if (npmArgs.length > 0) {
68
+ throw new Error(`Unsupported install arguments: ${npmArgs.join(' ')}`);
69
+ }
70
+
71
+ ensureLocalBinary();
72
+ run('npm', ['install', '-g', packageSpec]);
73
+ run(binaryPath, ['config', 'set', 'mode', mode], { stdio: 'ignore' });
74
+ if (explicitMode) {
75
+ console.error(`[gaia-cli] 安装完成,当前模式: ${mode}。可以执行: gaia-cli version`);
76
+ } else {
77
+ console.error('[gaia-cli] 安装完成。可以执行: gaia-cli version');
78
+ }
18
79
  }
19
80
 
20
- if (result.status !== 0) {
21
- process.exit(typeof result.status === 'number' ? result.status : 1);
81
+ if (require.main === module) {
82
+ try {
83
+ installWizard(process.argv.slice(2));
84
+ } catch (error) {
85
+ console.error(`[gaia-cli] Install failed: ${error.message}`);
86
+ process.exit(1);
87
+ }
22
88
  }
23
89
 
24
- console.error('[gaia-cli] Global install completed. You can now run: gaia-cli version');
90
+ module.exports = {
91
+ installWizard,
92
+ parseInstallArgs,
93
+ };
@@ -9,11 +9,10 @@ const { spawnSync } = require('child_process');
9
9
  const PACKAGE_ROOT = path.resolve(__dirname, '..');
10
10
  const PACKAGE_JSON = path.join(PACKAGE_ROOT, 'package.json');
11
11
  const BIN_DIR = path.join(PACKAGE_ROOT, 'bin');
12
- const RELEASE_REPO = process.env.GAIA_CLI_RELEASE_REPO || 'gaiaworks/gaia-cli-releases';
13
- const DOWNLOAD_BASE = process.env.GAIA_CLI_DOWNLOAD_BASE || `https://github.com/${RELEASE_REPO}/releases/download`;
12
+ const DOWNLOAD_BASE = process.env.GAIA_CLI_DOWNLOAD_BASE || 'https://assets.gaiaworkforce.com/gaia-cli/releases';
14
13
  const ALLOWED_DOWNLOAD_HOSTS = new Set([
15
- 'github.com',
16
- 'objects.githubusercontent.com',
14
+ 'assets.gaiaworkforce.com',
15
+ 'gaiafe.oss-cn-shanghai.aliyuncs.com',
17
16
  ]);
18
17
 
19
18
  function readPackageVersion() {
@@ -158,7 +157,7 @@ if (require.main === module) {
158
157
  install();
159
158
  } catch (error) {
160
159
  console.error(`[gaia-cli] Failed to install binary: ${error.message}`);
161
- console.error('[gaia-cli] Please check network access to GitHub Releases or contact the administrator.');
160
+ console.error('[gaia-cli] Please check network access to OSS assets or contact the administrator.');
162
161
  process.exit(1);
163
162
  }
164
163
  }