2021-06-02 14:55:33 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const inquirer = require('inquirer');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string|null} projectName - The name/path of project
|
|
|
|
* @param {string|null} starterUrl - The GitHub repo of the starter
|
|
|
|
* @returns Object containting prompt answers
|
|
|
|
*/
|
2021-11-10 17:55:31 +01:00
|
|
|
module.exports = async function promptUser(projectName, starter, program) {
|
2021-06-02 14:55:33 +02:00
|
|
|
const mainQuestions = [
|
|
|
|
{
|
|
|
|
type: 'input',
|
|
|
|
default: 'my-strapi-project',
|
|
|
|
name: 'directory',
|
|
|
|
message: 'What would you like to name your project?',
|
|
|
|
when: !projectName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'list',
|
|
|
|
name: 'quick',
|
|
|
|
message: 'Choose your installation type',
|
2021-11-16 15:36:38 +01:00
|
|
|
when: !program.quickstart,
|
2021-06-02 14:55:33 +02:00
|
|
|
choices: [
|
|
|
|
{
|
|
|
|
name: 'Quickstart (recommended)',
|
|
|
|
value: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Custom (manual settings)',
|
|
|
|
value: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const [mainResponse, starterQuestion] = await Promise.all([
|
|
|
|
inquirer.prompt(mainQuestions),
|
|
|
|
getStarterQuestion(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
const starterResponse = await inquirer.prompt({
|
|
|
|
name: 'starter',
|
|
|
|
when: !starter,
|
|
|
|
...starterQuestion,
|
|
|
|
});
|
|
|
|
|
|
|
|
return { ...mainResponse, ...starterResponse };
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns Prompt question object
|
|
|
|
*/
|
|
|
|
async function getStarterQuestion() {
|
2021-11-22 10:37:00 +01:00
|
|
|
// Ask user to manually input his starter
|
|
|
|
// TODO: find way to suggest the possible v4 starters
|
2021-06-02 14:55:33 +02:00
|
|
|
return {
|
2021-11-22 10:37:00 +01:00
|
|
|
type: 'input',
|
|
|
|
message: 'Please provide the npm package name of the starter you want to use:',
|
2021-06-02 14:55:33 +02:00
|
|
|
};
|
|
|
|
}
|