@runloop/rl-cli 0.1.1 ā 0.1.2
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/dist/components/Breadcrumb.js +20 -24
- package/dist/utils/config.js +28 -9
- package/package.json +1 -1
|
@@ -10,30 +10,26 @@ const VersionCheck = () => {
|
|
|
10
10
|
React.useEffect(() => {
|
|
11
11
|
const checkForUpdates = async () => {
|
|
12
12
|
try {
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const isUpdateAvailable = compareVersions(latestVersion, currentVersion) > 0;
|
|
34
|
-
if (isUpdateAvailable) {
|
|
35
|
-
setUpdateAvailable(latestVersion);
|
|
36
|
-
}
|
|
13
|
+
// Import the utility functions from config
|
|
14
|
+
const { checkForUpdates: checkForUpdatesUtil } = await import("../utils/config.js");
|
|
15
|
+
// Use the same logic as the non-interactive version
|
|
16
|
+
// We'll call the utility function and capture its output
|
|
17
|
+
const originalConsoleError = console.error;
|
|
18
|
+
let updateMessage = "";
|
|
19
|
+
// Capture the console.error output
|
|
20
|
+
console.error = (...args) => {
|
|
21
|
+
updateMessage = args.join(' ');
|
|
22
|
+
originalConsoleError(...args);
|
|
23
|
+
};
|
|
24
|
+
// Call the update check utility
|
|
25
|
+
await checkForUpdatesUtil(false);
|
|
26
|
+
// Restore original console.error
|
|
27
|
+
console.error = originalConsoleError;
|
|
28
|
+
// Parse the update message to extract the latest version
|
|
29
|
+
if (updateMessage.includes("Update available:")) {
|
|
30
|
+
const match = updateMessage.match(/Update available: .+ ā (.+)/);
|
|
31
|
+
if (match && match[1]) {
|
|
32
|
+
setUpdateAvailable(match[1]);
|
|
37
33
|
}
|
|
38
34
|
}
|
|
39
35
|
}
|
package/dist/utils/config.js
CHANGED
|
@@ -33,7 +33,7 @@ export function sshUrl() {
|
|
|
33
33
|
export function getCacheDir() {
|
|
34
34
|
return join(homedir(), ".cache", "rl-cli");
|
|
35
35
|
}
|
|
36
|
-
function getCurrentVersion() {
|
|
36
|
+
export function getCurrentVersion() {
|
|
37
37
|
try {
|
|
38
38
|
// First try environment variable (when installed via npm)
|
|
39
39
|
if (process.env.npm_package_version) {
|
|
@@ -67,23 +67,42 @@ export function hasCachedUpdateInfo() {
|
|
|
67
67
|
const cacheFile = join(cacheDir, "last_update_check");
|
|
68
68
|
return existsSync(cacheFile);
|
|
69
69
|
}
|
|
70
|
-
export function updateCheckCache() {
|
|
70
|
+
export function updateCheckCache(latestVersion) {
|
|
71
71
|
const cacheDir = getCacheDir();
|
|
72
72
|
const cacheFile = join(cacheDir, "last_update_check");
|
|
73
73
|
// Create cache directory if it doesn't exist
|
|
74
74
|
if (!existsSync(cacheDir)) {
|
|
75
75
|
mkdirSync(cacheDir, { recursive: true });
|
|
76
76
|
}
|
|
77
|
-
//
|
|
78
|
-
writeFileSync(cacheFile,
|
|
77
|
+
// Store the latest version in the cache file
|
|
78
|
+
writeFileSync(cacheFile, latestVersion);
|
|
79
|
+
}
|
|
80
|
+
export function getCachedLatestVersion() {
|
|
81
|
+
const cacheDir = getCacheDir();
|
|
82
|
+
const cacheFile = join(cacheDir, "last_update_check");
|
|
83
|
+
if (!existsSync(cacheFile)) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
return readFileSync(cacheFile, 'utf-8').trim();
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
79
92
|
}
|
|
80
93
|
export async function checkForUpdates(force = false) {
|
|
81
94
|
const currentVersion = getCurrentVersion();
|
|
82
95
|
// Always show cached result if available and not forcing
|
|
83
96
|
if (!force && hasCachedUpdateInfo() && !shouldCheckForUpdates()) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
97
|
+
const cachedLatestVersion = getCachedLatestVersion();
|
|
98
|
+
if (cachedLatestVersion && cachedLatestVersion !== currentVersion) {
|
|
99
|
+
// Check if current version is older than cached latest
|
|
100
|
+
const isUpdateAvailable = compareVersions(cachedLatestVersion, currentVersion) > 0;
|
|
101
|
+
if (isUpdateAvailable) {
|
|
102
|
+
console.error(`\nš Update available: ${currentVersion} ā ${cachedLatestVersion}\n` +
|
|
103
|
+
` Run: npm install -g @runloop/rl-cli@latest\n\n`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
87
106
|
return;
|
|
88
107
|
}
|
|
89
108
|
// Only fetch from npm if cache is expired or forcing
|
|
@@ -118,8 +137,8 @@ export async function checkForUpdates(force = false) {
|
|
|
118
137
|
else if (force) {
|
|
119
138
|
console.error("ā
You're running the latest version!\n");
|
|
120
139
|
}
|
|
121
|
-
// Update the cache
|
|
122
|
-
updateCheckCache();
|
|
140
|
+
// Update the cache with the latest version
|
|
141
|
+
updateCheckCache(latestVersion);
|
|
123
142
|
}
|
|
124
143
|
catch (error) {
|
|
125
144
|
if (force) {
|