2019-06-20 15:45:14 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Node.js core.
|
|
|
|
const chalk = require('chalk');
|
|
|
|
const inquirer = require('inquirer');
|
2019-06-20 16:38:15 +02:00
|
|
|
const fse = require('fs-extra');
|
2019-06-20 15:45:14 +02:00
|
|
|
|
|
|
|
const { trackError, trackUsage } = require('./utils/usage');
|
|
|
|
const stopProcess = require('./utils/stop-process');
|
2019-06-20 16:38:15 +02:00
|
|
|
const createCLIDatabaseProject = require('./create-cli-db-project');
|
|
|
|
const createCustomizeProject = require('./create-customized-project');
|
|
|
|
const createQuickStartProject = require('./create-quickstart-project');
|
2019-06-20 15:45:14 +02:00
|
|
|
|
|
|
|
module.exports = async scope => {
|
|
|
|
await trackUsage({ event: 'willCreateProject', scope });
|
|
|
|
|
|
|
|
const hasDatabaseConfig = Boolean(scope.database);
|
|
|
|
|
|
|
|
// check rootPath is empty
|
|
|
|
if (await fse.exists(scope.rootPath)) {
|
|
|
|
const stat = await fse.stat(scope.rootPath);
|
|
|
|
|
|
|
|
if (!stat.isDirectory()) {
|
|
|
|
await trackError({ scope, error: 'Path is not a directory' });
|
|
|
|
|
|
|
|
stopProcess(
|
|
|
|
`⛔️ ${chalk.green(
|
|
|
|
scope.rootPath
|
|
|
|
)} is not a directory. Make sure to create a Strapi application in an empty directory.`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const files = await fse.readdir(scope.rootPath);
|
|
|
|
if (files.length > 1) {
|
|
|
|
await trackError({ scope, error: 'Directory is not empty' });
|
|
|
|
stopProcess(
|
2019-07-08 15:39:08 +02:00
|
|
|
`⛔️ You can only create a Strapi app in an empty directory.\nMake sure ${chalk.green(
|
2019-06-20 15:45:14 +02:00
|
|
|
scope.rootPath
|
|
|
|
)} is empty.`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if database config is provided don't test the connection and create the project directly
|
|
|
|
if (hasDatabaseConfig) {
|
2019-06-20 16:38:15 +02:00
|
|
|
return createCLIDatabaseProject(scope);
|
2019-06-20 15:45:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// if cli quickstart create project with default sqlite options
|
|
|
|
if (scope.quick === true) {
|
|
|
|
return createQuickStartProject(scope);
|
|
|
|
}
|
|
|
|
|
|
|
|
const useQuickStart = await askShouldUseQuickstart();
|
|
|
|
// else if question response is quickstart create project
|
|
|
|
if (useQuickStart) {
|
|
|
|
return createQuickStartProject(scope);
|
|
|
|
}
|
|
|
|
|
2019-06-20 16:38:15 +02:00
|
|
|
// create a project with full list of questions
|
|
|
|
return createCustomizeProject(scope);
|
2019-06-20 15:45:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
async function askShouldUseQuickstart() {
|
|
|
|
const answer = await inquirer.prompt([
|
|
|
|
{
|
|
|
|
type: 'list',
|
|
|
|
name: 'type',
|
|
|
|
message: 'Choose your installation type',
|
|
|
|
choices: [
|
|
|
|
{
|
|
|
|
name: 'Quickstart (recommended)',
|
|
|
|
value: 'quick',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Custom (manual settings)',
|
|
|
|
value: 'custom',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
return answer.type === 'quick';
|
|
|
|
}
|