@@ -11,6 +11,13 @@ import { trackSelectedKit } from './metrics';
1111const STARTER_KITS_JSON_URL = 'https://raw.githubusercontent.com/thisdot/starter.dev/main/starter-kits.json' ;
1212const EXCLUDED_PACKAGE_JSON_FIELDS = [ 'hasShowcase' ] ;
1313
14+ type Package = {
15+ scripts : {
16+ dev : string ;
17+ start : string ;
18+ } ;
19+ } ;
20+
1421export async function main ( ) {
1522 console . log ( `\n${ bold ( 'Welcome to starter.dev!' ) } ${ gray ( '(create-starter)' ) } ` ) ;
1623
@@ -55,11 +62,21 @@ export async function main() {
5562 } ,
5663 ] ) ;
5764
58- if ( ! options . kit || ! options . name ) {
65+ const packageOptions = await prompts ( [
66+ {
67+ type : 'autocomplete' ,
68+ name : 'packageManager' ,
69+ message : 'Which package manager would you like to use?' ,
70+ choices : packageSelection ( options . kit ) . map ( ( pm ) => ( { title : pm , value : pm } ) ) ,
71+ suggest : ( input , choices ) => Promise . resolve ( choices . filter ( ( c ) => c . title . includes ( input ) ) ) ,
72+ } ,
73+ ] ) ;
74+
75+ if ( ! options . kit || ! options . name || ! packageOptions ) {
5976 process . exit ( 1 ) ;
6077 }
6178
62- const [ createSelectedKitResult ] = await Promise . allSettled ( [ createStarter ( options ) , trackSelectedKit ( options . kit ) ] ) ;
79+ const [ createSelectedKitResult ] = await Promise . allSettled ( [ createStarter ( options , packageOptions ) , trackSelectedKit ( options . kit ) ] ) ;
6380
6481 if ( createSelectedKitResult . status === 'rejected' ) {
6582 const err = createSelectedKitResult . reason ;
@@ -68,9 +85,23 @@ export async function main() {
6885 }
6986}
7087
71- async function createStarter ( options : prompts . Answers < 'name' | 'kit' > ) : Promise < void > {
88+ function packageSelection ( selection : string ) : Array < string > {
89+ let packageOptions ;
90+ switch ( selection ) {
91+ case 'deno-oak-denodb' :
92+ packageOptions = [ 'deno' ] ;
93+ break ;
94+ default :
95+ packageOptions = [ 'npm' , 'pnpm' , 'yarn' ] ;
96+ }
97+ return packageOptions ;
98+ }
99+
100+ async function createStarter ( options : prompts . Answers < 'name' | 'kit' > , packageOptions : prompts . Answers < 'packageManager' > ) : Promise < void > {
72101 const repoPath = `thisdot/starter.dev/starters/${ options . kit } ` ;
73102 const destPath = path . join ( process . cwd ( ) , options . name ) ;
103+ const packageManager = packageOptions . packageManager ;
104+ const kit = options . kit ;
74105
75106 const emitter = degit ( repoPath , {
76107 cache : false ,
@@ -98,13 +129,32 @@ async function createStarter(options: prompts.Answers<'name' | 'kit'>): Promise<
98129 await initNodeProject ( packageJsonPath , destPath , options ) ;
99130 }
100131
101- await initGitRepo ( destPath ) ;
132+ const packageCommand = `https://raw.githubusercontent.com/thisdot/starter.dev/main/starters/${ kit } /${ packageManager === 'deno' ? 'deno' : 'package' } .json` ;
133+ const res = await fetch ( packageCommand ) ;
134+ let packageJSON : Package ;
135+
136+ if ( res . ok ) {
137+ packageJSON = ( await res . json ( ) ) as Package ;
138+ } else {
139+ throw new Error ( ) ;
140+ }
141+
142+ const startAction = packageJSON ?. scripts ?. dev !== undefined ? 'dev' : 'start' ;
143+
144+ await initGitRepo ( destPath , packageManager ) ;
102145 console . log ( bold ( green ( '✔' ) + ' Done!' ) ) ;
103146 console . log ( '\nNext steps:' ) ;
104147 console . log ( ` ${ bold ( cyan ( `cd ${ options . name } ` ) ) } ` ) ;
105148
106149 if ( packageJsonExists ) {
107- console . log ( ` ${ bold ( cyan ( 'npm install' ) ) } (or pnpm install, yarn, etc)` ) ;
150+ console . log ( ` ${ bold ( cyan ( `${ packageManager } ${ startAction } ` ) ) } ` ) ;
151+ } else if ( packageManager === 'deno' ) {
152+ console . log ( ` ${ bold ( cyan ( 'Make sure you have Docker & docker-compose installed on your machine' ) ) } ` ) ;
153+ console . log ( ` ${ bold ( cyan ( 'Create a .env file and copy the contents of .env.example into it' ) ) } ` ) ;
154+ console . log ( ` ${ bold ( cyan ( 'Run deno task start-db to start the local PostgreSQL and Redis' ) ) } ` ) ;
155+ console . log ( ` ${ bold ( cyan ( 'Run deno task start-web to start the development server' ) ) } ` ) ;
156+ console . log ( ` ${ bold ( cyan ( 'Open your browser to http://localhost:3333/health to see the API running' ) ) } ` ) ;
157+ console . log ( ` ${ bold ( cyan ( 'Proceed to the Seeding chapter to seed the database with some sample data' ) ) } ` ) ;
108158 }
109159 } catch ( err : unknown ) {
110160 throw new Error ( 'Failed to initialize the starter kit. This probably means that you provided an invalid kit name.' ) ;
0 commit comments