1
1
import { colors , ensureDir , gzipDecode , path , Untar } from '../deps.ts'
2
2
import { ensureTextFile } from '../shared/fs.ts'
3
- import log from '../shared/log.ts'
4
3
import util from '../shared/util.ts'
5
4
import { VERSION } from '../version.ts'
6
5
@@ -17,21 +16,18 @@ Options:
17
16
18
17
export default async function ( appDir : string , options : Record < string , string | boolean > ) {
19
18
const rev = 'master'
20
- log . info ( 'Downloading template...' )
19
+ const template = 'hello-world'
20
+ const vscode = await confirm ( `Add recommended VS Code workspace settings?` )
21
+
22
+ console . log ( 'Downloading template...' )
21
23
const resp = await fetch ( 'https://codeload.github.com/alephjs/alephjs-templates/tar.gz/' + rev )
22
24
const gzData = await Deno . readAll ( new Deno . Buffer ( await resp . arrayBuffer ( ) ) )
23
- log . info ( 'Saving template...' )
25
+
26
+ console . log ( 'Saving template...' )
24
27
const tarData = gzipDecode ( gzData )
25
28
const entryList = new Untar ( new Deno . Buffer ( tarData ) )
26
- const gitignore = [
27
- '.DS_Store' ,
28
- 'Thumbs.db' ,
29
- '.aleph/' ,
30
- 'dist/' ,
31
- ]
32
29
33
30
// todo: add template select ui
34
- let template = 'hello-world'
35
31
for await ( const entry of entryList ) {
36
32
if ( entry . fileName . startsWith ( `alephjs-templates-${ rev } /${ template } /` ) ) {
37
33
const fp = path . join ( appDir , util . trimPrefix ( entry . fileName , `alephjs-templates-${ rev } /${ template } /` ) )
@@ -44,18 +40,28 @@ export default async function (appDir: string, options: Record<string, string |
44
40
await Deno . copy ( entry , file )
45
41
}
46
42
}
47
- await Deno . writeTextFile ( path . join ( appDir , '.gitignore' ) , gitignore . join ( '\n' ) )
48
- await Deno . writeTextFile ( path . join ( appDir , 'import_map.json' ) , JSON . stringify ( {
43
+
44
+ const gitignore = [
45
+ '.DS_Store' ,
46
+ 'Thumbs.db' ,
47
+ '.aleph/' ,
48
+ 'dist/' ,
49
+ ]
50
+ const importMap = {
49
51
imports : {
50
52
'aleph' : `https://deno.land/x/aleph@v${ VERSION } /mod.ts` ,
51
53
'aleph/' : `https://deno.land/x/aleph@v${ VERSION } /` ,
52
54
'react' :
'https://esm.sh/[email protected] ' ,
53
55
'react-dom' :
'https://esm.sh/[email protected] ' ,
54
56
} ,
55
57
scopes : { }
56
- } , undefined , 4 ) )
58
+ }
59
+ await Promise . all ( [
60
+ Deno . writeTextFile ( path . join ( appDir , '.gitignore' ) , gitignore . join ( '\n' ) ) ,
61
+ Deno . writeTextFile ( path . join ( appDir , 'import_map.json' ) , JSON . stringify ( importMap , undefined , 4 ) )
62
+ ] )
57
63
58
- if ( await confirm ( `Add VS Code workspace settings?` ) ) {
64
+ if ( vscode ) {
59
65
const extensions = {
60
66
'recommendations' : [
61
67
'denoland.vscode-deno'
@@ -67,18 +73,20 @@ export default async function (appDir: string, options: Record<string, string |
67
73
'deno.import_map' : './import_map.json'
68
74
}
69
75
await ensureDir ( path . join ( appDir , '.vscode' ) )
70
- await Deno . writeTextFile ( path . join ( appDir , '.vscode' , 'extensions.json' ) , JSON . stringify ( extensions , undefined , 4 ) )
71
- await Deno . writeTextFile ( path . join ( appDir , '.vscode' , 'settings.json' ) , JSON . stringify ( settigns , undefined , 4 ) )
76
+ await Promise . all ( [
77
+ Deno . writeTextFile ( path . join ( appDir , '.vscode' , 'extensions.json' ) , JSON . stringify ( extensions , undefined , 4 ) ) ,
78
+ Deno . writeTextFile ( path . join ( appDir , '.vscode' , 'settings.json' ) , JSON . stringify ( settigns , undefined , 4 ) )
79
+ ] )
72
80
}
73
81
74
- log . info ( 'Done' )
75
- log . info ( '---' )
76
- log . info ( colors . dim ( 'Aleph.js is ready to Go.' ) )
77
- log . info ( `${ colors . dim ( '$' ) } cd ` + path . basename ( appDir ) )
78
- log . info ( `${ colors . dim ( '$' ) } aleph ${ colors . bold ( 'dev' ) } ${ colors . dim ( '# start the app in `development` mode' ) } ` )
79
- log . info ( `${ colors . dim ( '$' ) } aleph ${ colors . bold ( 'start' ) } ${ colors . dim ( '# start the app in `production` mode' ) } ` )
80
- log . info ( `${ colors . dim ( '$' ) } aleph ${ colors . bold ( 'build' ) } ${ colors . dim ( '# build the app to a static site (SSG)' ) } ` )
81
- log . info ( '---' )
82
+ console . log ( 'Done' )
83
+ console . log ( '---' )
84
+ console . log ( colors . green ( 'Aleph.js is ready to Go.' ) )
85
+ console . log ( `${ colors . dim ( '$' ) } cd ` + path . basename ( appDir ) )
86
+ console . log ( `${ colors . dim ( '$' ) } aleph ${ colors . bold ( 'dev' ) } ${ colors . dim ( '# start the app in `development` mode' ) } ` )
87
+ console . log ( `${ colors . dim ( '$' ) } aleph ${ colors . bold ( 'start' ) } ${ colors . dim ( '# start the app in `production` mode' ) } ` )
88
+ console . log ( `${ colors . dim ( '$' ) } aleph ${ colors . bold ( 'build' ) } ${ colors . dim ( '# build the app to a static site (SSG)' ) } ` )
89
+ console . log ( '---' )
82
90
Deno . exit ( 0 )
83
91
}
84
92
0 commit comments