Skip to content

Commit 22adb00

Browse files
Sudeep PatelSudeep Patel
authored andcommitted
fix(createstrapi.js, index.js): fixed path not getting detected issue, made feedback changes
1 parent 56a28e8 commit 22adb00

2 files changed

Lines changed: 19 additions & 34 deletions

File tree

index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,22 @@ const process = require(`process`);
3838
input.includes(`help`) && cli.showHelp(0);
3939
debug && log(flags);
4040

41-
let projectPath = ``;
42-
4341
const useQuickStart = input.includes(`new`) ? quickStart(flags) : false;
4442
try {
4543
await detectDownloadsAndStars();
4644
await detectProjectType();
4745
await detectPackageManager();
4846
if (!(await detectStrapiProject())) {
49-
projectPath = await createStrapiProject();
47+
const projectPath = await createStrapiProject();
48+
process.chdir(projectPath);
49+
setConfig({outDir: path.join(process.cwd())});
5050
}
5151

5252
if (input.includes(`reset`)) {
5353
await reset();
5454
goodbye();
5555
return;
5656
}
57-
process.chdir(projectPath);
58-
setConfig({outDir: path.join(process.cwd())});
5957
const askQuestions = useQuickStart ? false : await questions();
6058
if (askQuestions || config.dockerCompose) {
6159
await createDockerComposeFiles();

utils/createStrapi.js

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const { spawn } = require(`child_process`);
44
const ora = require(`ora`);
55
const spinner = ora({ text: `` });
66
const chalk = require(`chalk`);
7-
const fs = require(`fs`);
87
const goodbye = require(`./goodbye`);
8+
const path = require(`path`);
99
const 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

Comments
 (0)