@@ -5,6 +5,7 @@ const ora = require(`ora`);
55const spinner = ora ( { text : `` } ) ;
66const chalk = require ( `chalk` ) ;
77const goodbye = require ( `./goodbye` ) ;
8+ const path = require ( `path` ) ;
89const createStrapiProject = async ( ) => {
910 const newProject = await prompts ( {
1011 name : `strapiProject` ,
@@ -27,12 +28,46 @@ const createStrapiProject = async () => {
2728 active : `Yes` ,
2829 inactive : `No` ,
2930 type : `toggle`
31+ } ,
32+ {
33+ name : `projectPath` ,
34+ message : `Do you want to assign a path for new project ?`
35+ + ` (leave blank for current directory )` ,
36+ type : `text` ,
37+ initial : process . cwd ( )
3038 }
3139 ] ) ;
40+
41+ async function checkPathAccessibility ( targetPath ) {
42+ if ( ! path . isAbsolute ( targetPath ) ) {
43+ console . error ( `${ chalk . bold . red (
44+ ` \n 🛑 Path is not valid. Please use a valid path for creating project, exiting...`
45+ ) } \n`) ;
46+ await goodbye ( ) ;
47+ process . exit ( 1 ) ;
48+ } else {
49+ console . log ( `${ chalk . bold . green ( `\n 📝 Path is valid, proceeding! \n` ) } ` ) ;
50+ }
51+ }
52+
53+ const checkIfPathExists = extraQuestions . projectPath ;
54+
55+ if ( checkIfPathExists === `` || checkIfPathExists === `undefined` || checkIfPathExists === null ) {
56+ extraQuestions . projectPath = `.` ;
57+ } else {
58+ await checkPathAccessibility ( checkIfPathExists ) ;
59+ }
60+
61+ if ( extraQuestions . projectPath !== process . cwd ( ) ) {
62+ extraQuestions . initial = `` ;
63+ }
64+
65+ const projectPath = `${ extraQuestions . projectPath } /${ extraQuestions . projectName } ` ;
66+
3267 const command = `npx` ;
3368 const args = [
3469 `create-strapi-app@latest` ,
35- extraQuestions . projectName ,
70+ projectPath ,
3671 `--quickstart` ,
3772 extraQuestions . typescript ? `--typescript` : `` ,
3873 `--no-run`
@@ -59,11 +94,10 @@ const createStrapiProject = async () => {
5994 spinner . stopAndPersist ( {
6095 symbol : `🚀` ,
6196 text : ` ${ chalk . bold . yellow (
62- `Strapi Project created! please CD into ${ extraQuestions . projectName } and run the tool again `
97+ `Strapi Project created! at path ${ projectPath } `
6398 ) } \n`
6499 } ) ;
65- await goodbye ( ) ;
66- process . exit ( 1 ) ;
100+ return projectPath ;
67101 } else {
68102 process . exit ( 1 ) ;
69103 }
0 commit comments