-
Notifications
You must be signed in to change notification settings - Fork 170
/
upgrade.ts
61 lines (55 loc) · 1.72 KB
/
upgrade.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { red } from 'https://deno.land/std@0.90.0/fmt/colors.ts'
import { dirname, join } from 'https://deno.land/std@0.90.0/path/mod.ts'
import { existsSync } from 'https://deno.land/std@0.90.0/fs/exists.ts'
import { VERSION } from '../version.ts'
const versionMetaUrl = 'https://cdn.deno.land/aleph/meta/versions.json'
export const helpMessage = `
Usage:
aleph upgrade
Options:
--version <version> The version to upgrade to
-h, --help Prints help message
`
export default async function (version = 'latest', forceUpgrade = false) {
console.log('Looking up latest version...')
const { latest, versions } = await (await fetch(versionMetaUrl)).json()
if (version === 'latest') {
version = latest
} else if (!versions.includes(version)) {
version = 'v' + version
if (!versions.includes(version)) {
console.log(`${red('error')}: version(${version}) not found!`)
Deno.exit(1)
}
}
if (version === 'v' + VERSION && !forceUpgrade) {
console.log('Already up-to-date!')
Deno.exit(0)
}
const denoExecPath = Deno.execPath()
const cmdExists = existsSync(join(dirname(denoExecPath), 'aleph'))
const p = Deno.run({
cmd: [
denoExecPath,
'install',
'-A',
'-f',
'--unstable',
'-n', 'aleph',
'--location', 'https://deno.land/x/aleph',
`https://deno.land/x/aleph@${version}/cli.ts`
],
stdout: 'null',
stderr: 'inherit'
})
const status = await p.status()
if (status.success) {
if (cmdExists && !forceUpgrade) {
console.log(`Aleph.js is up to ${version}`)
} else {
console.log('Aleph.js was installed successfully')
console.log(`Run 'aleph -h' to get started`)
}
}
Deno.exit(status.code)
}