11import { colors , ensureDir , gzipDecode , path , Untar } from '../deps.ts'
22import { ensureTextFile } from '../shared/fs.ts'
3- import log from '../shared/log.ts'
43import util from '../shared/util.ts'
54import { VERSION } from '../version.ts'
65
@@ -17,21 +16,18 @@ Options:
1716
1817export default async function ( appDir : string , options : Record < string , string | boolean > ) {
1918 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...' )
2123 const resp = await fetch ( 'https://codeload.github.com/alephjs/alephjs-templates/tar.gz/' + rev )
2224 const gzData = await Deno . readAll ( new Deno . Buffer ( await resp . arrayBuffer ( ) ) )
23- log . info ( 'Saving template...' )
25+
26+ console . log ( 'Saving template...' )
2427 const tarData = gzipDecode ( gzData )
2528 const entryList = new Untar ( new Deno . Buffer ( tarData ) )
26- const gitignore = [
27- '.DS_Store' ,
28- 'Thumbs.db' ,
29- '.aleph/' ,
30- 'dist/' ,
31- ]
3229
3330 // todo: add template select ui
34- let template = 'hello-world'
3531 for await ( const entry of entryList ) {
3632 if ( entry . fileName . startsWith ( `alephjs-templates-${ rev } /${ template } /` ) ) {
3733 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 |
4440 await Deno . copy ( entry , file )
4541 }
4642 }
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 = {
4951 imports : {
5052 'aleph' : `https://deno.land/x/aleph@v${ VERSION } /mod.ts` ,
5153 'aleph/' : `https://deno.land/x/aleph@v${ VERSION } /` ,
5254 'react' : 'https://esm.sh/react@17.0.1' ,
5355 'react-dom' : 'https://esm.sh/react-dom@17.0.1' ,
5456 } ,
5557 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+ ] )
5763
58- if ( await confirm ( `Add VS Code workspace settings?` ) ) {
64+ if ( vscode ) {
5965 const extensions = {
6066 'recommendations' : [
6167 'denoland.vscode-deno'
@@ -67,18 +73,20 @@ export default async function (appDir: string, options: Record<string, string |
6773 'deno.import_map' : './import_map.json'
6874 }
6975 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+ ] )
7280 }
7381
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 ( '---' )
8290 Deno . exit ( 0 )
8391}
8492
0 commit comments