ralph-review 0.1.10 → 0.1.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/package.json +1 -1
- package/src/commands/update.ts +28 -11
- package/src/lib/self-update.ts +20 -1
package/package.json
CHANGED
package/src/commands/update.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { type CommandDef, parseCommand } from "@/lib/cli-parser";
|
|
|
4
4
|
import {
|
|
5
5
|
getDefaultSelfUpdateDependencies,
|
|
6
6
|
isUpdateManager,
|
|
7
|
+
managerDisplay,
|
|
7
8
|
performSelfUpdate,
|
|
8
9
|
type SelfUpdateDependencies,
|
|
9
10
|
SelfUpdateError,
|
|
@@ -52,34 +53,30 @@ function createUpdateRuntime(overrides: UpdateRuntimeOverrides = {}): UpdateRunt
|
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
function managerLabel(manager: SelfUpdateResult["manager"]): string {
|
|
56
|
-
return manager === "brew" ? "Homebrew" : "npm";
|
|
57
|
-
}
|
|
58
|
-
|
|
59
56
|
function renderSelfUpdateResult(result: SelfUpdateResult, runtime: UpdateRuntime): void {
|
|
60
57
|
switch (result.status) {
|
|
61
58
|
case "up-to-date":
|
|
62
59
|
runtime.log.success(
|
|
63
|
-
`ralph-review is already up to date via ${
|
|
60
|
+
`ralph-review is already up to date via ${managerDisplay(result.manager)} (${result.currentVersion}).`
|
|
64
61
|
);
|
|
65
62
|
return;
|
|
66
63
|
|
|
67
64
|
case "update-available":
|
|
68
65
|
if (result.latestVersion) {
|
|
69
66
|
runtime.log.info(
|
|
70
|
-
`Update available via ${
|
|
67
|
+
`Update available via ${managerDisplay(result.manager)}: ${result.currentVersion} -> ${result.latestVersion}`
|
|
71
68
|
);
|
|
72
69
|
return;
|
|
73
70
|
}
|
|
74
71
|
|
|
75
72
|
runtime.log.info(
|
|
76
|
-
`Update available via ${
|
|
73
|
+
`Update available via ${managerDisplay(result.manager)}. Current version: ${result.currentVersion}`
|
|
77
74
|
);
|
|
78
75
|
return;
|
|
79
76
|
|
|
80
77
|
case "updated":
|
|
81
78
|
runtime.log.success(
|
|
82
|
-
`Updated ralph-review via ${
|
|
79
|
+
`Updated ralph-review via ${managerDisplay(result.manager)}: ${result.previousVersion} -> ${result.finalVersion}`
|
|
83
80
|
);
|
|
84
81
|
return;
|
|
85
82
|
}
|
|
@@ -112,13 +109,33 @@ export async function runUpdate(
|
|
|
112
109
|
};
|
|
113
110
|
|
|
114
111
|
const spinner = runtime.spinner();
|
|
112
|
+
let spinnerActive = false;
|
|
113
|
+
const stopSpinner = (message: string): void => {
|
|
114
|
+
if (!spinnerActive) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
spinner.stop(message);
|
|
119
|
+
spinnerActive = false;
|
|
120
|
+
};
|
|
121
|
+
|
|
115
122
|
spinner.start("Checking for updates...");
|
|
123
|
+
spinnerActive = true;
|
|
116
124
|
try {
|
|
117
|
-
const result = await runtime.performSelfUpdate(
|
|
118
|
-
|
|
125
|
+
const result = await runtime.performSelfUpdate(
|
|
126
|
+
{
|
|
127
|
+
...options,
|
|
128
|
+
onBeforeInstall: async ({ manager }) => {
|
|
129
|
+
stopSpinner("Update check complete.");
|
|
130
|
+
runtime.log.info(`Installing update via ${managerDisplay(manager)}...`);
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
runtime
|
|
134
|
+
);
|
|
135
|
+
stopSpinner("Done.");
|
|
119
136
|
renderSelfUpdateResult(result, runtime);
|
|
120
137
|
} catch (error) {
|
|
121
|
-
|
|
138
|
+
stopSpinner("Update failed.");
|
|
122
139
|
if (error instanceof SelfUpdateError) {
|
|
123
140
|
runtime.log.error(error.message);
|
|
124
141
|
for (const note of error.notes) {
|
package/src/lib/self-update.ts
CHANGED
|
@@ -16,9 +16,16 @@ export interface SelfUpdateDependencies {
|
|
|
16
16
|
runInteractive: (command: string[]) => Promise<number>;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
export interface BeforeInstallEvent {
|
|
20
|
+
manager: UpdateManager;
|
|
21
|
+
currentVersion: string;
|
|
22
|
+
latestVersion: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
19
25
|
export interface SelfUpdateOptions {
|
|
20
26
|
checkOnly: boolean;
|
|
21
27
|
manager?: UpdateManager;
|
|
28
|
+
onBeforeInstall?: (event: BeforeInstallEvent) => void | Promise<void>;
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
export type SelfUpdateResult =
|
|
@@ -100,7 +107,7 @@ function commandDisplay(command: readonly string[]): string {
|
|
|
100
107
|
return command.join(" ");
|
|
101
108
|
}
|
|
102
109
|
|
|
103
|
-
function managerDisplay(manager: UpdateManager): string {
|
|
110
|
+
export function managerDisplay(manager: UpdateManager): string {
|
|
104
111
|
switch (manager) {
|
|
105
112
|
case "brew":
|
|
106
113
|
return "Homebrew";
|
|
@@ -504,6 +511,12 @@ async function performNpmSelfUpdate(
|
|
|
504
511
|
};
|
|
505
512
|
}
|
|
506
513
|
|
|
514
|
+
await options.onBeforeInstall?.({
|
|
515
|
+
manager: "npm",
|
|
516
|
+
currentVersion,
|
|
517
|
+
latestVersion,
|
|
518
|
+
});
|
|
519
|
+
|
|
507
520
|
const exitCode = await deps.runInteractive([...NPM_INSTALL_COMMAND]);
|
|
508
521
|
if (exitCode !== 0) {
|
|
509
522
|
throw new SelfUpdateError(
|
|
@@ -547,6 +560,12 @@ async function performBrewSelfUpdate(
|
|
|
547
560
|
};
|
|
548
561
|
}
|
|
549
562
|
|
|
563
|
+
await options.onBeforeInstall?.({
|
|
564
|
+
manager: "brew",
|
|
565
|
+
currentVersion,
|
|
566
|
+
latestVersion,
|
|
567
|
+
});
|
|
568
|
+
|
|
550
569
|
const exitCode = await deps.runInteractive([...BREW_INSTALL_COMMAND]);
|
|
551
570
|
if (exitCode !== 0) {
|
|
552
571
|
throw new SelfUpdateError(
|