console command "update" accepts version as optional parameter
Massimo Melina committed
Oct 7, 2023 at 11:23 UTC
16fc92a8e5de8d7f705ddff7119428a5f98891ba
4 files changed
+17
-11
src/commands.ts
+2
-2
@@ -97,8 +97,8 @@ const commands = {
97
}
98
},
99
update: {
100
- params: '',
101
- cb: () => update()
100
+ params: '[<version>=latest]',
101
+ cb: update
102
},
103
'check-update': {
104
params: '',
src/index.ts
+1
-1
@@ -52,7 +52,7 @@ function errorHandler(err:Error & { code:string, path:string }) {
52
53
process.on('uncaughtException', err => {
54
if ((err as any).syscall !== 'watch')
55
- console.error(err)
55
+ console.error("uncaught:", err)
56
})
57
58
defineConfig('proxies', 0).sub(n => {
src/update.ts
+11
-6
@@ -68,15 +68,19 @@ export function updateSupported() {
68
return IS_BINARY
69
}
70
71
-export async function update(tag?: string) {
72
- if (!updateSupported())
73
- throw "only binary versions are supported for now"
71
+export async function update(tag: string='') {
72
+ if (!updateSupported()) throw "only binary versions supports automatic update for now"
73
let updateSource: Readable | false = await localUpdateAvailable() && createReadStream(LOCAL_UPDATE)
74
if (!updateSource) {
75
+ if (/^\d/.test(tag)) // work even if the tag is passed without the initial 'v' (useful for console commands)
76
+ tag = 'v' + tag
77
const update = !tag ? (await getUpdates())[0]
77
- : await getRepoInfo(HFS_REPO + '/releases/tags/' + tag) as Release
78
+ : await getRepoInfo(HFS_REPO + '/releases/tags/' + tag).catch(e => {
79
+ if (e.message === '404') console.error("version not found")
80
+ else throw e
81
+ }) as Release | undefined
82
if (!update)
79
- throw "no update found"
83
+ throw "update not found"
84
const assetSearch = ({ win32: 'windows', darwin: 'mac', linux: 'linux' } as any)[process.platform]
85
if (!assetSearch)
86
throw "this feature doesn't support your platform: " + process.platform
@@ -114,7 +118,8 @@ export async function update(tag?: string) {
118
console.log('quitting')
119
setTimeout(() => process.exit()) // give time to return (and caller to complete, eg: rest api to reply)
120
}
117
- catch {
121
+ catch (e: any) {
122
+ console.error(e?.message || String(e))
123
pluginsWatcher.unpause()
124
}
125
}
src/util-files.ts
+3
-2
@@ -107,9 +107,10 @@ export async function* dirStream(path: string, deep=0) {
107
108
export async function unzip(stream: Readable, cb: (path: string) => Promisable<false | string>) {
109
let pending: Promise<any> = Promise.resolve()
110
- return new Promise(resolve =>
110
+ return new Promise((resolve, reject) =>
111
stream.pipe(unzipper.Parse())
112
.on('end', () => pending.then(resolve))
113
+ .on('error', reject)
114
.on('entry', (entry: any) =>
115
pending = pending.then(async () => { // don't overlap writings
116
const { path, type } = entry
@@ -121,7 +122,7 @@ export async function unzip(stream: Readable, cb: (path: string) => Promisable<f
122
return entry.autodrain()
123
console.debug('unzip', dest)
124
await prepareFolder(dest)
124
- const thisFile = entry.pipe(createWriteStream(dest))
125
+ const thisFile = entry.pipe(createWriteStream(dest).on('error', reject))
126
await once(thisFile, 'finish')
127
}) )
128
)