aweshare 0.3.0 → 0.3.1
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/README.md +1 -1
- package/apps/hub/package.json +1 -1
- package/bin/self-update.mjs +27 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
<a href="https://ko-fi.com/mugpeng"><img src="https://img.shields.io/badge/Ko--fi-Buy%20me%20a%20coffee-FF5E5B?style=flat-square&logo=ko-fi&logoColor=white" alt="Ko-fi"></a>
|
|
15
15
|
</p>
|
|
16
16
|
<p>
|
|
17
|
-
<a href="https://github.com/wehuman01/aweshare-source/releases"><img src="https://img.shields.io/badge/version-0.3.
|
|
17
|
+
<a href="https://github.com/wehuman01/aweshare-source/releases"><img src="https://img.shields.io/badge/version-0.3.1-7C3AED?style=flat-square" alt="Version"></a>
|
|
18
18
|
<a href="https://github.com/wehuman01/aweshare"><img src="https://img.shields.io/badge/node-%E2%89%A522-0EA5E9?style=flat-square" alt="Node"></a>
|
|
19
19
|
<a href="https://github.com/wehuman01/aweshare/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-proprietary-E34F26?style=flat-square" alt="License"></a>
|
|
20
20
|
<a href="https://www.npmjs.com/package/aweshare"><img src="https://img.shields.io/badge/npm-aweshare-7C3AED?style=flat-square" alt="npm package"></a>
|
package/apps/hub/package.json
CHANGED
package/bin/self-update.mjs
CHANGED
|
@@ -15,6 +15,22 @@ const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.u
|
|
|
15
15
|
|
|
16
16
|
const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000
|
|
17
17
|
const REMIND_INTERVAL_MS = 24 * 60 * 60 * 1000
|
|
18
|
+
const RETRY_INTERVAL_MS = 6 * 60 * 60 * 1000
|
|
19
|
+
|
|
20
|
+
/** Numeric comparison tolerant of prefixes/suffixes ("v1.2.3", prerelease tags). */
|
|
21
|
+
function parseVersion(value) {
|
|
22
|
+
const parts = String(value).match(/\d+/g)
|
|
23
|
+
return parts ? parts.slice(0, 3).map(Number) : [0]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function versionGte(current, latest) {
|
|
27
|
+
const a = parseVersion(current)
|
|
28
|
+
const b = parseVersion(latest)
|
|
29
|
+
for (let i = 0; i < 3; i++) {
|
|
30
|
+
if ((a[i] ?? 0) !== (b[i] ?? 0)) return (a[i] ?? 0) > (b[i] ?? 0)
|
|
31
|
+
}
|
|
32
|
+
return true
|
|
33
|
+
}
|
|
18
34
|
|
|
19
35
|
function runCommand(command, args, { cwd, timeout = 120_000 } = {}) {
|
|
20
36
|
return new Promise((resolve, reject) => {
|
|
@@ -67,7 +83,7 @@ export async function runSelfUpdate(args, { run = runCommand, confirmFn = confir
|
|
|
67
83
|
console.log(`current version: ${VERSION}`)
|
|
68
84
|
console.log(`latest version: ${latest}`)
|
|
69
85
|
|
|
70
|
-
if (VERSION
|
|
86
|
+
if (versionGte(VERSION, latest)) {
|
|
71
87
|
console.log('already up to date')
|
|
72
88
|
return
|
|
73
89
|
}
|
|
@@ -131,23 +147,26 @@ export async function maybeCheckForUpdate(argv, { run = runCommand, cacheFile, n
|
|
|
131
147
|
let cache = await readJson(cacheFile)
|
|
132
148
|
|
|
133
149
|
let latest = null
|
|
134
|
-
if (cache && now
|
|
150
|
+
if (cache && now < Date.parse(cache.nextCheckAt)) {
|
|
135
151
|
latest = cache.latestVersion
|
|
136
152
|
} else {
|
|
137
153
|
try {
|
|
138
154
|
latest = await getNpmLatestVersion(run)
|
|
155
|
+
cache = {
|
|
156
|
+
nextCheckAt: new Date(now + CHECK_INTERVAL_MS).toISOString(),
|
|
157
|
+
latestVersion: latest,
|
|
158
|
+
lastReminded: cache?.lastReminded ?? '',
|
|
159
|
+
}
|
|
139
160
|
} catch {
|
|
161
|
+
// back off for a few hours so an offline machine does not retry on every command
|
|
162
|
+
cache = { ...cache, nextCheckAt: new Date(now + RETRY_INTERVAL_MS).toISOString(), latestVersion: null }
|
|
163
|
+
await writeJson(cacheFile, cache)
|
|
140
164
|
return null
|
|
141
165
|
}
|
|
142
|
-
cache = {
|
|
143
|
-
lastChecked: new Date(now).toISOString(),
|
|
144
|
-
latestVersion: latest,
|
|
145
|
-
lastReminded: cache?.lastReminded ?? '',
|
|
146
|
-
}
|
|
147
166
|
await writeJson(cacheFile, cache)
|
|
148
167
|
}
|
|
149
168
|
|
|
150
|
-
if (!latest || latest
|
|
169
|
+
if (!latest || versionGte(VERSION, latest)) return null
|
|
151
170
|
|
|
152
171
|
const lastRemindedMs = cache.lastReminded ? Date.parse(cache.lastReminded) : 0
|
|
153
172
|
if (now - lastRemindedMs < REMIND_INTERVAL_MS) return null
|