@agi-cli/install 0.1.33 → 0.1.34
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/start.js +48 -0
package/package.json
CHANGED
package/start.js
CHANGED
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
chmodSync,
|
|
7
7
|
mkdirSync,
|
|
8
8
|
statSync,
|
|
9
|
+
readFileSync,
|
|
10
|
+
appendFileSync,
|
|
9
11
|
} from 'fs';
|
|
10
12
|
import { resolve, dirname } from 'path';
|
|
11
13
|
import { fileURLToPath } from 'url';
|
|
@@ -119,6 +121,49 @@ function downloadWithProgress(url, dest) {
|
|
|
119
121
|
});
|
|
120
122
|
}
|
|
121
123
|
|
|
124
|
+
function updateShellProfile(userBin) {
|
|
125
|
+
// Skip on Windows
|
|
126
|
+
if (platform() === 'win32') return;
|
|
127
|
+
|
|
128
|
+
const shell = process.env.SHELL || '';
|
|
129
|
+
let configFile;
|
|
130
|
+
let shellType;
|
|
131
|
+
|
|
132
|
+
if (shell.includes('zsh')) {
|
|
133
|
+
configFile = resolve(homedir(), '.zshrc');
|
|
134
|
+
shellType = 'zsh';
|
|
135
|
+
} else if (shell.includes('bash')) {
|
|
136
|
+
configFile = resolve(homedir(), '.bashrc');
|
|
137
|
+
shellType = 'bash';
|
|
138
|
+
} else {
|
|
139
|
+
configFile = resolve(homedir(), '.profile');
|
|
140
|
+
shellType = 'shell';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const pathExport = 'export PATH="$HOME/.local/bin:$PATH"';
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
let fileContent = '';
|
|
147
|
+
if (existsSync(configFile)) {
|
|
148
|
+
fileContent = readFileSync(configFile, 'utf8');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Check if .local/bin is already in the config file
|
|
152
|
+
if (fileContent.includes('.local/bin')) {
|
|
153
|
+
console.log(`✓ PATH already configured in ${configFile}`);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Add the PATH export
|
|
158
|
+
appendFileSync(configFile, `\n${pathExport}\n`);
|
|
159
|
+
console.log(`✓ Added ${userBin} to PATH in ${configFile}`);
|
|
160
|
+
console.log(`✓ Restart your ${shellType} or run: source ${configFile}`);
|
|
161
|
+
} catch (error) {
|
|
162
|
+
// Silently fail if we can't update the profile
|
|
163
|
+
console.log(`⚠️ Could not automatically update ${configFile}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
122
167
|
async function install() {
|
|
123
168
|
try {
|
|
124
169
|
const { os, arch: architecture, ext } = getPlatformInfo();
|
|
@@ -143,6 +188,7 @@ async function install() {
|
|
|
143
188
|
|
|
144
189
|
const pathDirs = (process.env.PATH || '').split(':');
|
|
145
190
|
if (!pathDirs.includes(userBin)) {
|
|
191
|
+
updateShellProfile(userBin);
|
|
146
192
|
console.log(`\n⚠️ Add ${userBin} to your PATH:`);
|
|
147
193
|
console.log(
|
|
148
194
|
` echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc`,
|
|
@@ -150,6 +196,8 @@ async function install() {
|
|
|
150
196
|
console.log(
|
|
151
197
|
` Or for zsh: echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc`,
|
|
152
198
|
);
|
|
199
|
+
} else {
|
|
200
|
+
console.log(`✓ ${userBin} already in PATH`);
|
|
153
201
|
}
|
|
154
202
|
} else {
|
|
155
203
|
console.log(`\n✓ Installed to ${binPath}`);
|