@@ -96,29 +96,33 @@ function generateDbUrlForPrisma(connectionString) {
96
96
return connectionString . toString ( ) ;
97
97
}
98
98
99
- function initialChecks ( ) {
99
+ function initialChecks ( options ) {
100
100
return [
101
101
{
102
102
title : '👀 Checking Node.js version...' ,
103
103
task : ( ) => checkNodeVersion ( 20 )
104
104
} ,
105
105
{
106
106
title : '👀 Validating current working directory...' ,
107
- task : ( ) => checkForExistingPackageJson ( )
107
+ task : ( ) => checkForExistingPackageJson ( options )
108
108
}
109
109
]
110
110
}
111
111
112
- function checkForExistingPackageJson ( ) {
113
- if ( fs . existsSync ( path . join ( process . cwd ( ) , 'package.json' ) ) ) {
112
+ function checkForExistingPackageJson ( options ) {
113
+ const projectDir = path . join ( process . cwd ( ) , options . appName ) ;
114
+ if ( fs . existsSync ( projectDir ) ) {
114
115
throw new Error (
115
- `A package.json already exists in this directory .\n` +
116
- `Please remove it or use an empty directory .`
116
+ `Directory " ${ options . appName } " already exists.\n` +
117
+ `Please remove it or use a different name .`
117
118
) ;
118
119
}
119
120
}
120
121
121
122
async function scaffoldProject ( ctx , options , cwd ) {
123
+ const projectDir = path . join ( cwd , options . appName ) ;
124
+ await fse . ensureDir ( projectDir ) ;
125
+
122
126
const connectionString = parseConnectionString ( options . db ) ;
123
127
const provider = detectDbProvider ( connectionString . protocol ) ;
124
128
const prismaDbUrl = generateDbUrlForPrisma ( connectionString ) ;
@@ -130,9 +134,9 @@ async function scaffoldProject(ctx, options, cwd) {
130
134
const dirname = path . dirname ( filename ) ;
131
135
132
136
// Prepare directories
133
- ctx . customDir = path . join ( cwd , 'custom' ) ;
137
+ ctx . customDir = path . join ( projectDir , 'custom' ) ;
134
138
await fse . ensureDir ( ctx . customDir ) ;
135
- await fse . ensureDir ( path . join ( cwd , 'resources' ) ) ;
139
+ await fse . ensureDir ( path . join ( projectDir , 'resources' ) ) ;
136
140
137
141
// Copy static assets to `custom/assets`
138
142
const sourceAssetsDir = path . join ( dirname , 'assets' ) ;
@@ -141,13 +145,14 @@ async function scaffoldProject(ctx, options, cwd) {
141
145
await fse . copy ( sourceAssetsDir , targetAssetsDir ) ;
142
146
143
147
// Write templated files
144
- writeTemplateFiles ( dirname , cwd , {
148
+ writeTemplateFiles ( dirname , projectDir , {
145
149
dbUrl : connectionString . toString ( ) ,
146
150
prismaDbUrl,
147
151
appName,
148
152
provider,
149
153
} ) ;
150
154
155
+ return projectDir ; // Return the new directory path
151
156
}
152
157
153
158
async function writeTemplateFiles ( dirname , cwd , options ) {
@@ -241,9 +246,13 @@ async function installDependencies(ctx, cwd) {
241
246
] ) ;
242
247
}
243
248
244
- function generateFinalInstructions ( skipPrismaSetup ) {
249
+ function generateFinalInstructions ( skipPrismaSetup , options ) {
245
250
let instruction = '⏭️ Run the following commands to get started:\n' ;
246
251
if ( ! skipPrismaSetup )
252
+ instruction += `
253
+ ${ chalk . dim ( '// Go to the project directory' ) }
254
+ ${ chalk . cyan ( `$ cd ${ options . appName } ` ) } \n` ;
255
+
247
256
instruction += `
248
257
${ chalk . dim ( '// Generate and apply initial migration' ) }
249
258
${ chalk . cyan ( '$ npm run makemigration -- --name init' ) } \n` ;
@@ -272,33 +281,35 @@ export function prepareWorkflow(options) {
272
281
title : '🔍 Initial checks...' ,
273
282
task : ( _ , task ) =>
274
283
task . newListr (
275
- initialChecks ( ) ,
284
+ initialChecks ( options ) ,
276
285
{ concurrent : true } ,
277
286
)
278
287
} ,
279
288
{
280
289
title : '🚀 Scaffolding your project...' ,
281
- task : async ( ctx ) => scaffoldProject ( ctx , options , cwd )
290
+ task : async ( ctx ) => {
291
+ ctx . projectDir = await scaffoldProject ( ctx , options , cwd ) ;
292
+ }
282
293
} ,
283
294
{
284
295
title : '📦 Installing dependencies...' ,
285
- task : async ( ctx ) => installDependencies ( ctx , cwd )
296
+ task : async ( ctx ) => installDependencies ( ctx , ctx . projectDir )
286
297
} ,
287
298
{
288
299
title : '📝 Preparing final instructions...' ,
289
300
task : ( ctx ) => {
290
- console . log ( chalk . green ( `✅ Successfully created your new Adminforth project!\n` ) ) ;
291
- console . log ( generateFinalInstructions ( ctx . skipPrismaSetup ) ) ;
301
+ console . log ( chalk . green ( `✅ Successfully created your new Adminforth project in ${ ctx . projectDir } !\n` ) ) ;
302
+ console . log ( generateFinalInstructions ( ctx . skipPrismaSetup , options ) ) ;
292
303
console . log ( '\n\n' ) ;
304
+ }
293
305
}
294
- } ] ,
306
+ ] ,
295
307
{
296
308
rendererOptions : { collapseSubtasks : false } ,
297
309
concurrent : false ,
298
310
exitOnError : true ,
299
311
collectErrors : true ,
300
- }
301
- ) ;
312
+ } ) ;
302
313
303
314
return tasks ;
304
315
}
0 commit comments