@@ -14,10 +14,17 @@ Options:
14
14
-h, --help Prints help message
15
15
`
16
16
17
- export default async function ( appDir : string , options : Record < string , string | boolean > ) {
17
+ export default async function ( n ?: string ) {
18
+ const cwd = Deno . cwd ( )
18
19
const rev = 'master'
19
- const template = 'hello-world'
20
- const vscode = await confirm ( `Add recommended VS Code workspace settings?` )
20
+
21
+ const name = n || ( await ask ( 'Name:' ) ) . trim ( )
22
+ if ( name === '' ) {
23
+ return
24
+ }
25
+
26
+ const template = 'hello-world' // todo: add template select ui
27
+ const vscode = await confirm ( 'Add recommended workspace settings of VS Code?' )
21
28
22
29
console . log ( 'Downloading template...' )
23
30
const resp = await fetch ( 'https://codeload.github.com/alephjs/alephjs-templates/tar.gz/' + rev )
@@ -27,10 +34,9 @@ export default async function (appDir: string, options: Record<string, string |
27
34
const tarData = gzipDecode ( gzData )
28
35
const entryList = new Untar ( new Deno . Buffer ( tarData ) )
29
36
30
- // todo: add template select ui
31
37
for await ( const entry of entryList ) {
32
38
if ( entry . fileName . startsWith ( `alephjs-templates-${ rev } /${ template } /` ) ) {
33
- const fp = path . join ( appDir , util . trimPrefix ( entry . fileName , `alephjs-templates-${ rev } /${ template } /` ) )
39
+ const fp = path . join ( cwd , name , util . trimPrefix ( entry . fileName , `alephjs-templates-${ rev } /${ template } /` ) )
34
40
if ( entry . type === 'directory' ) {
35
41
await ensureDir ( fp )
36
42
continue
@@ -49,6 +55,7 @@ export default async function (appDir: string, options: Record<string, string |
49
55
]
50
56
const importMap = {
51
57
imports : {
58
+ '~/' : './' , '@/' : './' ,
52
59
'aleph' : `https://deno.land/x/aleph@v${ VERSION } /mod.ts` ,
53
60
'aleph/' : `https://deno.land/x/aleph@v${ VERSION } /` ,
54
61
'react' :
'https://esm.sh/[email protected] ' ,
@@ -57,8 +64,8 @@ export default async function (appDir: string, options: Record<string, string |
57
64
scopes : { }
58
65
}
59
66
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 ) )
67
+ Deno . writeTextFile ( path . join ( cwd , name , '.gitignore' ) , gitignore . join ( '\n' ) ) ,
68
+ Deno . writeTextFile ( path . join ( cwd , name , 'import_map.json' ) , JSON . stringify ( importMap , undefined , 4 ) )
62
69
] )
63
70
64
71
if ( vscode ) {
@@ -72,21 +79,21 @@ export default async function (appDir: string, options: Record<string, string |
72
79
'deno.unstable' : true ,
73
80
'deno.import_map' : './import_map.json'
74
81
}
75
- await ensureDir ( path . join ( appDir , '.vscode' ) )
82
+ await ensureDir ( path . join ( name , '.vscode' ) )
76
83
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 ) )
84
+ Deno . writeTextFile ( path . join ( name , '.vscode' , 'extensions.json' ) , JSON . stringify ( extensions , undefined , 4 ) ) ,
85
+ Deno . writeTextFile ( path . join ( name , '.vscode' , 'settings.json' ) , JSON . stringify ( settigns , undefined , 4 ) )
79
86
] )
80
87
}
81
88
82
89
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 ( '---' )
90
+ console . log ( colors . dim ( '---' ) )
91
+ console . log ( colors . green ( 'Aleph.js is ready to go! ' ) )
92
+ console . log ( `${ colors . dim ( '$' ) } cd ${ name } ` )
93
+ console . log ( `${ colors . dim ( '$' ) } aleph dev ${ colors . dim ( '# start the app in `development` mode' ) } ` )
94
+ console . log ( `${ colors . dim ( '$' ) } aleph start ${ colors . dim ( '# start the app in `production` mode' ) } ` )
95
+ console . log ( `${ colors . dim ( '$' ) } aleph build ${ colors . dim ( '# build the app to a static site (SSG)' ) } ` )
96
+ console . log ( colors . dim ( '---' ) )
90
97
Deno . exit ( 0 )
91
98
}
92
99
0 commit comments