@@ -40,6 +40,7 @@ async function gatherConfig(
4040 const result = await group (
4141 {
4242 projectName : async ( ) => {
43+ if ( flags . projectName ) return flags . projectName ;
4344 let isValid = false ;
4445 let projectName : string | symbol = "" ;
4546 let defaultName = DEFAULT_CONFIG . projectName ;
@@ -83,8 +84,9 @@ async function gatherConfig(
8384 return projectName as string ;
8485 } ,
8586 database : ( ) =>
86- ! flags . database
87- ? select < ProjectDatabase > ( {
87+ flags . database !== undefined
88+ ? Promise . resolve ( flags . database )
89+ : select < ProjectDatabase > ( {
8890 message : "💾 Which database would you like to use?" ,
8991 options : [
9092 {
@@ -98,18 +100,19 @@ async function gatherConfig(
98100 hint : "Traditional relational database" ,
99101 } ,
100102 ] ,
101- } )
102- : Promise . resolve ( flags . database ) ,
103+ } ) ,
103104 auth : ( ) =>
104- flags . auth === undefined
105- ? confirm ( {
105+ flags . auth !== undefined
106+ ? Promise . resolve ( flags . auth )
107+ : confirm ( {
106108 message :
107109 "🔐 Would you like to add authentication with Better-Auth?" ,
108- } )
109- : Promise . resolve ( flags . auth ) ,
110+ initialValue : DEFAULT_CONFIG . auth ,
111+ } ) ,
110112 features : ( ) =>
111- ! flags . features
112- ? multiselect < ProjectFeature > ( {
113+ flags . features !== undefined
114+ ? Promise . resolve ( flags . features )
115+ : multiselect < ProjectFeature > ( {
113116 message : "✨ Which features would you like to add?" ,
114117 options : [
115118 {
@@ -128,16 +131,18 @@ async function gatherConfig(
128131 hint : "Search engine optimization configuration" ,
129132 } ,
130133 ] ,
131- } )
132- : Promise . resolve ( flags . features ) ,
134+ } ) ,
133135 git : ( ) =>
134- flags . git !== false
135- ? confirm ( {
136+ flags . git !== undefined
137+ ? Promise . resolve ( flags . git )
138+ : confirm ( {
136139 message : "🗃️ Initialize a new git repository?" ,
137- initialValue : true ,
138- } )
139- : Promise . resolve ( false ) ,
140+ initialValue : DEFAULT_CONFIG . git ,
141+ } ) ,
140142 packageManager : async ( ) => {
143+ if ( flags . packageManager !== undefined ) {
144+ return flags . packageManager ;
145+ }
141146 const detectedPackageManager = getUserPkgManager ( ) ;
142147
143148 const useDetected = await confirm ( {
@@ -179,15 +184,52 @@ async function gatherConfig(
179184 ) ;
180185
181186 return {
182- projectName : result . projectName ?? "" ,
183- database : result . database ?? "libsql" ,
184- auth : result . auth ?? true ,
185- features : result . features ?? [ ] ,
186- git : result . git ?? true ,
187- packageManager : result . packageManager ?? "npm" ,
187+ projectName : result . projectName ?? DEFAULT_CONFIG . projectName ,
188+ database : result . database ?? DEFAULT_CONFIG . database ,
189+ auth : result . auth ?? DEFAULT_CONFIG . auth ,
190+ features : result . features ?? DEFAULT_CONFIG . features ,
191+ git : result . git ?? DEFAULT_CONFIG . git ,
192+ packageManager : result . packageManager ?? DEFAULT_CONFIG . packageManager ,
188193 } ;
189194}
190195
196+ function displayConfig ( config : Partial < ProjectConfig > ) {
197+ const configDisplay = [ ] ;
198+
199+ if ( config . projectName ) {
200+ configDisplay . push (
201+ `${ chalk . blue ( "📝 Project Name: " ) } ${ chalk . green ( config . projectName ) } ` ,
202+ ) ;
203+ }
204+ if ( config . database ) {
205+ configDisplay . push (
206+ `${ chalk . blue ( "💾 Database: " ) } ${ chalk . yellow ( config . database ) } ` ,
207+ ) ;
208+ }
209+ if ( config . auth !== undefined ) {
210+ configDisplay . push (
211+ `${ chalk . blue ( "🔐 Authentication: " ) } ${ chalk . cyan ( config . auth ) } ` ,
212+ ) ;
213+ }
214+ if ( config . features ?. length ) {
215+ configDisplay . push (
216+ `${ chalk . blue ( "✨ Features: " ) } ${ config . features . map ( ( f ) => chalk . magenta ( f ) ) . join ( ", " ) } ` ,
217+ ) ;
218+ }
219+ if ( config . git !== undefined ) {
220+ configDisplay . push (
221+ `${ chalk . blue ( "🗃️ Git Init: " ) } ${ chalk . cyan ( config . git ) } ` ,
222+ ) ;
223+ }
224+ if ( config . packageManager ) {
225+ configDisplay . push (
226+ `${ chalk . blue ( "📦 Package Manager: " ) } ${ chalk . yellow ( config . packageManager ) } ` ,
227+ ) ;
228+ }
229+
230+ return configDisplay . join ( "\n" ) ;
231+ }
232+
191233async function main ( ) {
192234 const s = spinner ( ) ;
193235 try {
@@ -217,18 +259,30 @@ async function main() {
217259 const projectDirectory = program . args [ 0 ] ;
218260
219261 const flagConfig : Partial < ProjectConfig > = {
220- projectName : projectDirectory ,
221- database : options . database as ProjectDatabase ,
222- auth : options . auth ,
223- packageManager : options . packageManager as PackageManager ,
224- git : options . git ?? true ,
225- features : [
226- ...( options . docker ? [ "docker" ] : [ ] ) ,
227- ...( options . githubActions ? [ "github-actions" ] : [ ] ) ,
228- ...( options . seo ? [ "SEO" ] : [ ] ) ,
229- ] as ProjectFeature [ ] ,
262+ projectName : projectDirectory || undefined ,
263+ database : options . database as ProjectDatabase | undefined ,
264+ auth : "auth" in options ? options . auth : undefined ,
265+ packageManager : options . packageManager as PackageManager | undefined ,
266+ git : "git" in options ? options . git : undefined ,
267+ features :
268+ options . docker || options . githubActions || options . seo
269+ ? ( [
270+ ...( options . docker ? [ "docker" ] : [ ] ) ,
271+ ...( options . githubActions ? [ "github-actions" ] : [ ] ) ,
272+ ...( options . seo ? [ "SEO" ] : [ ] ) ,
273+ ] as ProjectFeature [ ] )
274+ : undefined ,
230275 } ;
231276
277+ if (
278+ ! options . yes &&
279+ Object . values ( flagConfig ) . some ( ( v ) => v !== undefined )
280+ ) {
281+ log . message ( chalk . bold ( "\n🎯 Using these pre-selected options:" ) ) ;
282+ log . message ( displayConfig ( flagConfig ) ) ;
283+ log . message ( "" ) ;
284+ }
285+
232286 const config = options . yes
233287 ? {
234288 ...DEFAULT_CONFIG ,
@@ -248,28 +302,9 @@ async function main() {
248302 : await gatherConfig ( flagConfig ) ;
249303
250304 if ( options . yes ) {
251- s . start ( "Using default configuration" ) ;
252- const colorizedConfig = {
253- projectName : chalk . green ( config . projectName ) ,
254- database : chalk . yellow ( config . database ) ,
255- auth : chalk . cyan ( config . auth ) ,
256- features : config . features . map ( ( feature ) => chalk . magenta ( feature ) ) ,
257- git : chalk . cyan ( config . git ) ,
258- } ;
259-
260- log . message (
261- `${ chalk . blue ( "📝 Project Name: " ) } ${
262- colorizedConfig . projectName
263- } \n${ chalk . blue ( "💾 Database: " ) } ${ colorizedConfig . database } \n${ chalk . blue (
264- "🔐 Authentication: " ,
265- ) } ${ colorizedConfig . auth } \n${ chalk . blue ( "✨ Features: " ) } ${
266- colorizedConfig . features . length
267- ? colorizedConfig . features . join ( ", " )
268- : chalk . gray ( "none" )
269- } \n${ chalk . blue ( "🗃️ Git Init: " ) } ${ colorizedConfig . git } \n`,
270- ) ;
271-
272- s . stop ( "Configuration loaded" ) ;
305+ log . message ( chalk . bold ( "\n🎯 Using these default options:" ) ) ;
306+ log . message ( displayConfig ( config ) ) ;
307+ log . message ( "" ) ;
273308 }
274309
275310 await createProject ( config ) ;
0 commit comments