@gaiaworks/gaia-cli 0.3.9 → 0.4.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gaiaworks/gaia-cli",
3
- "version": "0.3.9",
3
+ "version": "0.4.0",
4
4
  "description": "JavaScript launcher for gaia-cli.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -8,22 +8,22 @@ const { binaryName, install } = require('./install');
8
8
 
9
9
  const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
10
10
  const packageSpec = `${packageJson.name}@${packageJson.version}`;
11
- const binaryPath = path.join(__dirname, '..', 'bin', binaryName());
12
- const shellPathMarker = '# Added by gaia-cli installer';
13
-
14
- function npmInvocation(args) {
15
- if (process.platform === 'win32') {
16
- const npmCli = process.env.npm_execpath || path.join(
17
- path.dirname(process.execPath),
18
- 'node_modules',
19
- 'npm',
20
- 'bin',
21
- 'npm-cli.js'
22
- );
23
- return { command: process.execPath, args: [npmCli, ...args] };
24
- }
25
- return { command: 'npm', args };
26
- }
11
+ const binaryPath = path.join(__dirname, '..', 'bin', binaryName());
12
+ const shellPathMarker = '# Added by gaia-cli installer';
13
+
14
+ function npmInvocation(args) {
15
+ if (process.platform === 'win32') {
16
+ const npmCli = process.env.npm_execpath || path.join(
17
+ path.dirname(process.execPath),
18
+ 'node_modules',
19
+ 'npm',
20
+ 'bin',
21
+ 'npm-cli.js'
22
+ );
23
+ return { command: process.execPath, args: [npmCli, ...args] };
24
+ }
25
+ return { command: 'npm', args };
26
+ }
27
27
 
28
28
  function parseInstallArgs(args) {
29
29
  let mode = 'external';
@@ -80,24 +80,24 @@ function runCapture(command, args) {
80
80
  });
81
81
  }
82
82
 
83
- function npmGlobalBinDir() {
84
- const npm = npmInvocation(['prefix', '-g']);
85
- const result = runCapture(npm.command, npm.args);
83
+ function npmGlobalBinDir() {
84
+ const npm = npmInvocation(['prefix', '-g']);
85
+ const result = runCapture(npm.command, npm.args);
86
86
  if (result.error || result.status !== 0) return null;
87
87
  const prefix = result.stdout.trim();
88
88
  if (!prefix) return null;
89
89
  return process.platform === 'win32' ? prefix : path.join(prefix, 'bin');
90
90
  }
91
91
 
92
- function npmGlobalCommandPath(binDir, platform = process.platform) {
92
+ function npmGlobalCommandPath(binDir, platform = process.platform) {
93
93
  if (!binDir) return null;
94
94
  if (platform === 'win32') return path.win32.join(binDir, 'gaia.cmd');
95
95
  return path.posix.join(binDir, 'gaia');
96
- }
97
-
98
- function setupCommandPath(packageBinary) {
99
- return packageBinary;
100
- }
96
+ }
97
+
98
+ function setupCommandPath(packageBinary) {
99
+ return packageBinary;
100
+ }
101
101
 
102
102
  function pathContains(dir) {
103
103
  if (!dir) return false;
@@ -142,10 +142,10 @@ function pathExportBlock(binDir) {
142
142
  return `${shellPathMarker}\nexport PATH="${binDir}:$PATH"\n`;
143
143
  }
144
144
 
145
- function ensurePathConfigured(binDir, profilePath = shellProfilePath(), platform = process.platform) {
146
- if (!binDir) return null;
147
- if (platform === 'win32') {
148
- return ensureWindowsPathConfigured(binDir);
145
+ function ensurePathConfigured(binDir, profilePath = shellProfilePath(), platform = process.platform) {
146
+ if (!binDir) return null;
147
+ if (platform === 'win32') {
148
+ return ensureWindowsPathConfigured(binDir);
149
149
  }
150
150
  if (!profilePath || pathContains(binDir)) return null;
151
151
  const existing = fs.existsSync(profilePath) ? fs.readFileSync(profilePath, 'utf8') : '';
@@ -164,14 +164,21 @@ function installWizard(args) {
164
164
  const { explicitMode, mode, npmArgs } = parseInstallArgs(args);
165
165
  if (npmArgs.length > 0) {
166
166
  throw new Error(`Unsupported install arguments: ${npmArgs.join(' ')}`);
167
- }
168
-
169
- ensureLocalBinary();
170
- const npm = npmInvocation(['install', '-g', packageSpec]);
171
- run(npm.command, npm.args);
172
- const globalBinDir = npmGlobalBinDir();
173
- const setupCommand = setupCommandPath(binaryPath);
174
- run(setupCommand, ['setup', '--mode', mode], { stdio: 'ignore' });
167
+ }
168
+
169
+ ensureLocalBinary();
170
+ const npm = npmInvocation(['install', '-g', packageSpec]);
171
+ run(npm.command, npm.args);
172
+ const globalBinDir = npmGlobalBinDir();
173
+ const setupCommand = setupCommandPath(binaryPath);
174
+ console.error('[gaia-cli] 正在安装 Gaia Skill: gaia-shared...');
175
+ try {
176
+ run(setupCommand, ['setup', '--mode', mode], { stdio: 'ignore' });
177
+ } catch (error) {
178
+ console.error('[gaia-cli] gaia-shared 安装失败。');
179
+ throw error;
180
+ }
181
+ console.error('[gaia-cli] ✓ Gaia Skill gaia-shared 安装完成。');
175
182
  const profilePath = ensurePathConfigured(globalBinDir);
176
183
  const suffix = explicitMode ? `当前模式: ${mode}。` : '';
177
184
  if (profilePath && globalBinDir && !pathContains(globalBinDir)) {
@@ -198,13 +205,13 @@ if (require.main === module) {
198
205
  module.exports = {
199
206
  ensurePathConfigured,
200
207
  ensureWindowsPathConfigured,
201
- npmGlobalBinDir,
202
- npmGlobalCommandPath,
203
- npmInvocation,
208
+ npmGlobalBinDir,
209
+ npmGlobalCommandPath,
210
+ npmInvocation,
204
211
  pathContains,
205
212
  pathExportBlock,
206
- shellProfilePath,
207
- setupCommandPath,
213
+ shellProfilePath,
214
+ setupCommandPath,
208
215
  installWizard,
209
216
  parseInstallArgs,
210
217
  };