@@ -4,8 +4,8 @@ const { spawn } = require(`child_process`);
44const ora = require ( `ora` ) ;
55const spinner = ora ( { text : `` } ) ;
66const chalk = require ( `chalk` ) ;
7- const fs = require ( `fs` ) ;
87const goodbye = require ( `./goodbye` ) ;
8+ const path = require ( `path` ) ;
99const createStrapiProject = async ( ) => {
1010 const newProject = await prompts ( {
1111 name : `strapiProject` ,
@@ -32,47 +32,34 @@ const createStrapiProject = async () => {
3232 {
3333 name : `projectPath` ,
3434 message : `Do you want to assign a path for new project ?`
35- + ` (leave blank for current directory )` ,
36- type : `text`
35+ + ` (leave blank for current directory )` ,
36+ type : `text` ,
37+ initial : process . cwd ( )
3738 }
3839 ] ) ;
3940
4041 async function checkPathAccessibility ( targetPath ) {
41- try {
42- await fs . access ( targetPath , fs . constants . F_OK | fs . constants . R_OK ) ;
43- const stats = await fs . stat ( targetPath ) ;
44-
45- if ( stats . isDirectory ( ) ) {
46- return true ;
47- }
48- } catch ( err ) {
49- if ( err . code === `ENOENT` ) {
50- console . error ( ` ${ chalk . bold . yellow (
51- `🟨 Path does not exist, continuing in current directory!`
52- ) } \n`) ;
53- } else {
54- console . error ( ` ${ chalk . bold . red (
55- `🛑 Path is not accessible please use accessible path for creating project, exiting...`
56- ) } \n`) ;
42+ if ( ! path . isAbsolute ( targetPath ) ) {
43+ console . error ( `${ chalk . bold . red (
44+ `🛑 Path is not accessible. Please use an accessible path for creating project, exiting...`
45+ ) } \n`) ;
5746 await goodbye ( ) ;
5847 process . exit ( 1 ) ;
59- }
60- throw err ;
48+ } else {
49+ console . log ( ` ${ chalk . bold . green ( `\n 📝 Path is accessible. Creating folder!\n` ) } ` ) ;
6150 }
62- }
51+ }
6352
6453 const checkIfPathExists = extraQuestions . projectPath ;
6554
6655 if ( checkIfPathExists === `` || checkIfPathExists === `undefined` || checkIfPathExists === null ) {
6756 extraQuestions . projectPath = `.` ;
6857 } else {
69- await checkPathAccessibility ( checkIfPathExists )
70- . then ( ( result ) => {
71- console . log ( result ) ;
72- } )
73- . catch ( ( error ) => {
74- console . error ( error . message ) ;
75- } ) ;
58+ await checkPathAccessibility ( checkIfPathExists ) ;
59+ }
60+
61+ if ( extraQuestions . projectPath !== process . cwd ( ) ) {
62+ extraQuestions . initial = `` ;
7663 }
7764
7865 const projectPath = `${ extraQuestions . projectPath } /${ extraQuestions . projectName } ` ;
0 commit comments