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'
3
5
4
6
export const helpMessage = `
5
7
Usage:
6
8
aleph upgrade
7
9
8
10
Options:
9
- -v, --version <version> The upgrading version
11
+ --version <version> The version to upgrade to
10
12
-h, --help Prints help message
11
13
`
12
14
13
- export default async function ( version : string ) {
15
+ export default async function ( version = 'latest' ) {
14
16
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 ( )
17
18
if ( version === 'latest' ) {
18
19
version = latest
19
20
} else if ( ! versions . includes ( version ) ) {
@@ -23,17 +24,29 @@ export default async function (version: string) {
23
24
Deno . exit ( 1 )
24
25
}
25
26
}
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' ) )
30
30
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
+ ] ,
32
39
stdout : 'null' ,
33
- stderr : 'piped '
40
+ stderr : 'inherit '
34
41
} )
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 )
39
52
}
0 commit comments