Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit e230d6c

Browse files
author
ije
committed
feat(cli): add install.ts
1 parent 306c639 commit e230d6c

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

cli/upgrade.ts

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import { colors } from '../deps.ts'
2-
import { VERSION } from '../version.ts'
1+
import { colors, path } from '../deps.ts'
2+
import { existsFileSync } from '../shared/fs.ts'
3+
4+
const versionMetaUrl = 'https://cdn.deno.land/aleph/meta/versions.json'
35

46
export const helpMessage = `
57
Usage:
68
aleph upgrade
79
810
Options:
9-
-v, --version <version> The upgrading version
11+
--version <version> The version to upgrade to
1012
-h, --help Prints help message
1113
`
1214

13-
export default async function (version: string) {
15+
export default async function (version = 'latest') {
1416
console.log('Looking up latest version...')
15-
const metaUrl = 'https://cdn.deno.land/aleph/meta/versions.json'
16-
const { latest, versions } = await (await fetch(metaUrl)).json()
17+
const { latest, versions } = await (await fetch(versionMetaUrl)).json()
1718
if (version === 'latest') {
1819
version = latest
1920
} else if (!versions.includes(version)) {
@@ -23,17 +24,29 @@ export default async function (version: string) {
2324
Deno.exit(1)
2425
}
2526
}
26-
if (version === 'v' + VERSION) {
27-
console.log('Already up-to-date!')
28-
Deno.exit(0)
29-
}
27+
28+
const denoExecPath = Deno.execPath()
29+
const cmdExists = existsFileSync(path.join(path.dirname(denoExecPath), 'aleph'))
3030
const p = Deno.run({
31-
cmd: [Deno.execPath(), 'install', '-A', '-f', '--location', 'http://localhost', '-n', 'aleph', `https://deno.land/x/aleph@${version}/cli.ts`],
31+
cmd: [
32+
denoExecPath, 'install',
33+
'--location', 'https://deno.land/x/aleph',
34+
'-n', 'aleph',
35+
'-A', '-f',
36+
'--unstable',
37+
`https://deno.land/x/aleph@${version}/cli.ts`
38+
],
3239
stdout: 'null',
33-
stderr: 'piped'
40+
stderr: 'inherit'
3441
})
35-
Deno.stderr.write(await p.stderrOutput())
36-
console.log(`Aleph.js is up to ${version}!`)
37-
p.close()
38-
Deno.exit(0)
42+
const status = await p.status()
43+
if (status.success) {
44+
if (cmdExists) {
45+
console.log(`Aleph.js is up to ${version}!`)
46+
} else {
47+
console.log('Aleph.js was installed successfully!')
48+
console.log(`Run 'aleph --help' to get started`)
49+
}
50+
}
51+
Deno.exit(status.code)
3952
}

install.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import upgrade from './cli/upgrade.ts'
2+
import { flags } from './deps.ts'
3+
4+
if (import.meta.main) {
5+
const { _: args, ...options } = flags.parse(Deno.args)
6+
await upgrade(options.v || options.version || args[0] || 'latest')
7+
}

0 commit comments

Comments
 (0)