@gaiaworks/gaia-cli 0.4.7 → 0.4.9
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 +1 -1
- package/scripts/install-wizard.js +42 -33
package/package.json
CHANGED
|
@@ -115,45 +115,54 @@ function shellProfilePath(env = process.env) {
|
|
|
115
115
|
return path.join(home, '.profile');
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
function ensureWindowsPathConfigured(binDir) {
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
"
|
|
124
|
-
"$
|
|
125
|
-
"if (
|
|
126
|
-
"
|
|
127
|
-
"
|
|
128
|
-
"
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
118
|
+
function ensureWindowsPathConfigured(binDir, options = {}) {
|
|
119
|
+
const platform = options.platform || process.platform;
|
|
120
|
+
const spawn = options.spawnSync || spawnSync;
|
|
121
|
+
if (!binDir || platform !== 'win32') return null;
|
|
122
|
+
const command = [
|
|
123
|
+
"$dir = $env:GAIA_CLI_PATH_DIR",
|
|
124
|
+
"$current = [Environment]::GetEnvironmentVariable('Path', 'User')",
|
|
125
|
+
"if (-not $current) { $current = '' }",
|
|
126
|
+
"$parts = $current -split ';' | Where-Object { $_ }",
|
|
127
|
+
"$normalize = { param($value) [Environment]::ExpandEnvironmentVariables($value.Trim().Trim([char]34).TrimEnd([char[]]'\\/')) }",
|
|
128
|
+
"$target = & $normalize $dir",
|
|
129
|
+
"$exists = @($parts | Where-Object { (& $normalize $_) -ieq $target }).Count -gt 0",
|
|
130
|
+
"if (-not $exists) {",
|
|
131
|
+
" $next = (@($dir) + $parts) -join ';'",
|
|
132
|
+
" [Environment]::SetEnvironmentVariable('Path', $next, 'User')",
|
|
133
|
+
" Write-Output '[gaia-cli:path-updated]'",
|
|
134
|
+
"} else {",
|
|
135
|
+
" Write-Output '[gaia-cli:path-unchanged]'",
|
|
136
|
+
"}",
|
|
137
|
+
].join("; ");
|
|
138
|
+
const result = spawn("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", command], {
|
|
139
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
140
|
+
encoding: "utf8",
|
|
141
|
+
env: { ...process.env, GAIA_CLI_PATH_DIR: binDir },
|
|
142
|
+
});
|
|
134
143
|
if (result.error || result.status !== 0) {
|
|
135
|
-
const detail = result.error ? result.error.message : `${result.stdout || ""}${result.stderr || ""}`.trim();
|
|
136
|
-
throw new Error(`Failed to update user PATH: ${detail}`);
|
|
137
|
-
}
|
|
138
|
-
return
|
|
144
|
+
const detail = result.error ? result.error.message : `${result.stdout || ""}${result.stderr || ""}`.trim();
|
|
145
|
+
throw new Error(`Failed to update user PATH: ${detail}`);
|
|
146
|
+
}
|
|
147
|
+
return (result.stdout || '').includes('[gaia-cli:path-updated]') ? 'Windows user PATH' : null;
|
|
139
148
|
}
|
|
140
149
|
|
|
141
150
|
function pathExportBlock(binDir) {
|
|
142
151
|
return `${shellPathMarker}\nexport PATH="${binDir}:$PATH"\n`;
|
|
143
152
|
}
|
|
144
153
|
|
|
145
|
-
function ensurePathConfigured(binDir, profilePath = shellProfilePath(), platform = process.platform) {
|
|
146
|
-
if (!binDir) return null;
|
|
147
|
-
if (platform === 'win32') {
|
|
148
|
-
return ensureWindowsPathConfigured(binDir);
|
|
149
|
-
}
|
|
150
|
-
if (!profilePath
|
|
151
|
-
const existing = fs.existsSync(profilePath) ? fs.readFileSync(profilePath, 'utf8') : '';
|
|
152
|
-
if (existing.includes(binDir)
|
|
153
|
-
const prefix = existing && !existing.endsWith('\n') ? '\n' : '';
|
|
154
|
-
fs.appendFileSync(profilePath, `${prefix}${pathExportBlock(binDir)}`);
|
|
155
|
-
return profilePath;
|
|
156
|
-
}
|
|
154
|
+
function ensurePathConfigured(binDir, profilePath = shellProfilePath(), platform = process.platform) {
|
|
155
|
+
if (!binDir) return null;
|
|
156
|
+
if (platform === 'win32') {
|
|
157
|
+
return ensureWindowsPathConfigured(binDir);
|
|
158
|
+
}
|
|
159
|
+
if (!profilePath) return null;
|
|
160
|
+
const existing = fs.existsSync(profilePath) ? fs.readFileSync(profilePath, 'utf8') : '';
|
|
161
|
+
if (existing.includes(binDir)) return null;
|
|
162
|
+
const prefix = existing && !existing.endsWith('\n') ? '\n' : '';
|
|
163
|
+
fs.appendFileSync(profilePath, `${prefix}${pathExportBlock(binDir)}`);
|
|
164
|
+
return profilePath;
|
|
165
|
+
}
|
|
157
166
|
|
|
158
167
|
function ensureLocalBinary() {
|
|
159
168
|
if (fs.existsSync(binaryPath)) return;
|
|
@@ -181,7 +190,7 @@ function installWizard(args) {
|
|
|
181
190
|
console.error('[gaia-cli] ✓ Gaia 内置 Skill 安装完成。');
|
|
182
191
|
const profilePath = ensurePathConfigured(globalBinDir);
|
|
183
192
|
const suffix = explicitMode ? `当前模式: ${mode}。` : '';
|
|
184
|
-
if (profilePath && globalBinDir
|
|
193
|
+
if (profilePath && globalBinDir) {
|
|
185
194
|
console.error(`[gaia-cli] 安装完成,${suffix}已更新 PATH 配置: ${profilePath}`);
|
|
186
195
|
console.error(`[gaia-cli] 重新打开终端后可以执行: gaia version`);
|
|
187
196
|
return;
|