Skip to content

Commit 3ebef74

Browse files
authored
Merge pull request #66 from SudeepPatel-0812/main
Added ask path feature for creating new project
2 parents 7731579 + 12e90b0 commit 3ebef74

3 files changed

Lines changed: 45 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ Feel free to buy [@Eventyret] a ☕️ if it was helpful. [Open Collective](http
139139
- [@YEK-PLUS](https://github.com/YEK-PLUS)
140140
- [@RobbieClarken](https://github.com/RobbieClarken)
141141
- [@nevotheless](https://github.com/nevotheless)
142+
- [@SudeepPatel-0812](https://github.com/SudeepPatel-0812)
142143

143144
## 🔖 License
144145

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ const {
2929
const input = cli.input;
3030
const flags = cli.flags;
3131
const { clear, debug } = flags;
32+
const path = require(`path`);
33+
const { setConfig } = require(`./utils/config`);
34+
const process = require(`process`);
3235

3336
(async () => {
3437
init({ clear });
@@ -41,7 +44,9 @@ const { clear, debug } = flags;
4144
await detectProjectType();
4245
await detectPackageManager();
4346
if (!(await detectStrapiProject())) {
44-
await createStrapiProject();
47+
const projectPath = await createStrapiProject();
48+
process.chdir(projectPath);
49+
setConfig({outDir: path.join(process.cwd())});
4550
}
4651

4752
if (input.includes(`reset`)) {

utils/createStrapi.js

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const ora = require(`ora`);
55
const spinner = ora({ text: `` });
66
const chalk = require(`chalk`);
77
const goodbye = require(`./goodbye`);
8+
const path = require(`path`);
89
const 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

Comments
 (0)