Skip to content

Commit

Permalink
fix(createstrapi.js, index.js): fixed path not getting detected issue…
Browse files Browse the repository at this point in the history
…, made feedback changes
  • Loading branch information
Sudeep Patel authored and Sudeep Patel committed Apr 6, 2023
1 parent 56a28e8 commit 22adb00
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 34 deletions.
8 changes: 3 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,22 @@ const process = require(`process`);
input.includes(`help`) && cli.showHelp(0);
debug && log(flags);

let projectPath = ``;

const useQuickStart = input.includes(`new`) ? quickStart(flags) : false;
try {
await detectDownloadsAndStars();
await detectProjectType();
await detectPackageManager();
if (!(await detectStrapiProject())) {
projectPath = await createStrapiProject();
const projectPath = await createStrapiProject();
process.chdir(projectPath);
setConfig({outDir: path.join(process.cwd())});
}

if (input.includes(`reset`)) {
await reset();
goodbye();
return;
}
process.chdir(projectPath);
setConfig({outDir: path.join(process.cwd())});
const askQuestions = useQuickStart ? false : await questions();
if (askQuestions || config.dockerCompose) {
await createDockerComposeFiles();
Expand Down
45 changes: 16 additions & 29 deletions utils/createStrapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const { spawn } = require(`child_process`);
const ora = require(`ora`);
const spinner = ora({ text: `` });
const chalk = require(`chalk`);
const fs = require(`fs`);
const goodbye = require(`./goodbye`);
const path = require(`path`);
const createStrapiProject = async () => {
const newProject = await prompts({
name: `strapiProject`,
Expand All @@ -32,47 +32,34 @@ const createStrapiProject = async () => {
{
name: `projectPath`,
message: `Do you want to assign a path for new project ?`
+ ` (leave blank for current directory )`,
type: `text`
+ ` (leave blank for current directory )`,
type: `text`,
initial: process.cwd()
}
]);

async function checkPathAccessibility(targetPath) {
try {
await fs.access(targetPath, fs.constants.F_OK | fs.constants.R_OK);
const stats = await fs.stat(targetPath);

if (stats.isDirectory()) {
return true;
}
} catch (err) {
if (err.code === `ENOENT`) {
console.error(` ${chalk.bold.yellow(
`🟨 Path does not exist, continuing in current directory!`
)} \n`);
} else {
console.error(` ${chalk.bold.red(
`🛑 Path is not accessible please use accessible path for creating project, exiting...`
)} \n`);
if (!path.isAbsolute(targetPath)) {
console.error(`${chalk.bold.red(
`🛑 Path is not accessible. Please use an accessible path for creating project, exiting...`
)}\n`);
await goodbye();
process.exit(1);
}
throw err;
} else {
console.log(`${chalk.bold.green(`\n 📝 Path is accessible. Creating folder!\n`)}`);
}
}
}

const checkIfPathExists = extraQuestions.projectPath;

if (checkIfPathExists === `` || checkIfPathExists === `undefined` || checkIfPathExists === null) {
extraQuestions.projectPath = `.`;
} else {
await checkPathAccessibility(checkIfPathExists)
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error(error.message);
});
await checkPathAccessibility(checkIfPathExists);
}

if(extraQuestions.projectPath !== process.cwd()) {
extraQuestions.initial = ``;
}

const projectPath = `${extraQuestions.projectPath}/${extraQuestions.projectName}`;
Expand Down

0 comments on commit 22adb00

Please sign in to comment.