@preapexis/pi-kit 1.0.9 → 1.0.11
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/extensions/update.ts +57 -13
- package/package.json +1 -1
package/extensions/update.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// cSpell:words
|
|
1
|
+
// cSpell:words preapexis npm PowerShell
|
|
2
2
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
|
|
4
4
|
type EventContext = Parameters<Parameters<ExtensionAPI["on"]>[1]>[1];
|
|
@@ -16,6 +16,7 @@ type ShellCommand = {
|
|
|
16
16
|
|
|
17
17
|
const RUN_CHOICE = "▶ Run selected updates";
|
|
18
18
|
const CANCEL_CHOICE = "✕ Cancel";
|
|
19
|
+
const UPDATE_STATUS_KEY = "preapexis-update-status";
|
|
19
20
|
|
|
20
21
|
export default function (pi: ExtensionAPI): void {
|
|
21
22
|
const options: UpdateOption[] = [
|
|
@@ -26,19 +27,14 @@ export default function (pi: ExtensionAPI): void {
|
|
|
26
27
|
"npm install -g --ignore-scripts @earendil-works/pi-coding-agent@latest"
|
|
27
28
|
},
|
|
28
29
|
{
|
|
29
|
-
id: "
|
|
30
|
-
label: "
|
|
31
|
-
shell: "pi
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
id: "kit-github",
|
|
35
|
-
label: "Update PreApeXis Pi Kit from GitHub",
|
|
36
|
-
shell: "pi install git:github.com/VarunGaikwad/preapexis-pi-kit@master"
|
|
30
|
+
id: "pi-extensions",
|
|
31
|
+
label: "Update installed Pi packages/extensions",
|
|
32
|
+
shell: "pi update --extensions"
|
|
37
33
|
},
|
|
38
34
|
{
|
|
39
35
|
id: "kit-npm",
|
|
40
36
|
label: "Update PreApeXis Pi Kit from npm",
|
|
41
|
-
shell: "pi install npm
|
|
37
|
+
shell: "pi install npm:@preapexis/pi-kit"
|
|
42
38
|
},
|
|
43
39
|
{
|
|
44
40
|
id: "project-npm",
|
|
@@ -61,6 +57,29 @@ export default function (pi: ExtensionAPI): void {
|
|
|
61
57
|
};
|
|
62
58
|
}
|
|
63
59
|
|
|
60
|
+
function startUpdateStatus(ctx: EventContext, label: string): () => void {
|
|
61
|
+
const frames = ["◐", "◓", "◑", "◒"];
|
|
62
|
+
let seconds = 0;
|
|
63
|
+
let frame = 0;
|
|
64
|
+
|
|
65
|
+
ctx.ui.setStatus(UPDATE_STATUS_KEY, `updating: ${label} ${frames[0]} 0s`);
|
|
66
|
+
|
|
67
|
+
const timer = setInterval(() => {
|
|
68
|
+
seconds += 1;
|
|
69
|
+
frame = (frame + 1) % frames.length;
|
|
70
|
+
|
|
71
|
+
ctx.ui.setStatus(
|
|
72
|
+
UPDATE_STATUS_KEY,
|
|
73
|
+
`updating: ${label} ${frames[frame]} ${seconds}s`
|
|
74
|
+
);
|
|
75
|
+
}, 1000);
|
|
76
|
+
|
|
77
|
+
return () => {
|
|
78
|
+
clearInterval(timer);
|
|
79
|
+
ctx.ui.setStatus(UPDATE_STATUS_KEY, undefined);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
64
83
|
function optionLabel(
|
|
65
84
|
option: UpdateOption,
|
|
66
85
|
selected: Map<string, UpdateOption>
|
|
@@ -151,10 +170,35 @@ export default function (pi: ExtensionAPI): void {
|
|
|
151
170
|
ctx.ui.notify(`Running update:\n\n${option.shell}`, "info");
|
|
152
171
|
|
|
153
172
|
const shell = shellCommand(option.shell);
|
|
173
|
+
const stopStatus = startUpdateStatus(ctx, option.label);
|
|
154
174
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
175
|
+
let result: Awaited<ReturnType<typeof pi.exec>> | undefined;
|
|
176
|
+
|
|
177
|
+
try {
|
|
178
|
+
result = await pi.exec(shell.command, shell.args, {
|
|
179
|
+
cwd: ctx.cwd
|
|
180
|
+
});
|
|
181
|
+
} catch (error) {
|
|
182
|
+
ctx.ui.notify(
|
|
183
|
+
[
|
|
184
|
+
`Update failed: ${option.label}`,
|
|
185
|
+
"",
|
|
186
|
+
`Command: ${option.shell}`,
|
|
187
|
+
"",
|
|
188
|
+
error instanceof Error ? error.message : String(error)
|
|
189
|
+
].join("\n"),
|
|
190
|
+
"error"
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
return false;
|
|
194
|
+
} finally {
|
|
195
|
+
stopStatus();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (!result) {
|
|
199
|
+
ctx.ui.notify(`Update failed: ${option.label}`, "error");
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
158
202
|
|
|
159
203
|
const stdout = result.stdout?.trim() ?? "";
|
|
160
204
|
const stderr = result.stderr?.trim() ?? "";
|