Skip to content

Commit

Permalink
Merge pull request #66 from SudeepPatel-0812/main
Browse files Browse the repository at this point in the history
Added ask path feature for creating new project
  • Loading branch information
Eventyret committed Apr 10, 2023
2 parents 7731579 + 12e90b0 commit 3ebef74
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ Feel free to buy [@Eventyret] a ☕️ if it was helpful. [Open Collective](http
- [@YEK-PLUS](https://github.com/YEK-PLUS)
- [@RobbieClarken](https://github.com/RobbieClarken)
- [@nevotheless](https://github.com/nevotheless)
- [@SudeepPatel-0812](https://github.com/SudeepPatel-0812)

## 🔖 License

Expand Down
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const {
const input = cli.input;
const flags = cli.flags;
const { clear, debug } = flags;
const path = require(`path`);
const { setConfig } = require(`./utils/config`);
const process = require(`process`);

(async () => {
init({ clear });
Expand All @@ -41,7 +44,9 @@ const { clear, debug } = flags;
await detectProjectType();
await detectPackageManager();
if (!(await detectStrapiProject())) {
await createStrapiProject();
const projectPath = await createStrapiProject();
process.chdir(projectPath);
setConfig({outDir: path.join(process.cwd())});
}

if (input.includes(`reset`)) {
Expand Down
42 changes: 38 additions & 4 deletions utils/createStrapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const ora = require(`ora`);
const spinner = ora({ text: `` });
const chalk = require(`chalk`);
const goodbye = require(`./goodbye`);
const path = require(`path`);
const createStrapiProject = async () => {
const newProject = await prompts({
name: `strapiProject`,
Expand All @@ -27,12 +28,46 @@ const createStrapiProject = async () => {
active: `Yes`,
inactive: `No`,
type: `toggle`
},
{
name: `projectPath`,
message: `Do you want to assign a path for new project ?`
+ ` (leave blank for current directory )`,
type: `text`,
initial: process.cwd()
}
]);

async function checkPathAccessibility(targetPath) {
if (!path.isAbsolute(targetPath)) {
console.error(`${chalk.bold.red(
` \n 🛑 Path is not valid. Please use a valid path for creating project, exiting...`
)}\n`);
await goodbye();
process.exit(1);
} else {
console.log(`${chalk.bold.green(`\n 📝 Path is valid, proceeding! \n`)}`);
}
}

const checkIfPathExists = extraQuestions.projectPath;

if (checkIfPathExists === `` || checkIfPathExists === `undefined` || checkIfPathExists === null) {
extraQuestions.projectPath = `.`;
} else {
await checkPathAccessibility(checkIfPathExists);
}

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

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

const command = `npx`;
const args = [
`create-strapi-app@latest`,
extraQuestions.projectName,
projectPath,
`--quickstart`,
extraQuestions.typescript ? `--typescript` : ``,
`--no-run`
Expand All @@ -59,11 +94,10 @@ const createStrapiProject = async () => {
spinner.stopAndPersist({
symbol: `🚀`,
text: ` ${chalk.bold.yellow(
`Strapi Project created! please CD into ${extraQuestions.projectName} and run the tool again`
`Strapi Project created! at path ${projectPath}`
)} \n`
});
await goodbye();
process.exit(1);
return projectPath;
} else {
process.exit(1);
}
Expand Down

0 comments on commit 3ebef74

Please sign in to comment.