UNPKG

2.27 kBJavaScriptView Raw
1'use strict';
2
3/**
4 * Module dependencies
5 */
6
7// Node.js core.
8const chalk = require('chalk');
9const inquirer = require('inquirer');
10const fse = require('fs-extra');
11
12const { trackUsage } = require('./utils/usage');
13const stopProcess = require('./utils/stop-process');
14const createCLIDatabaseProject = require('./create-cli-db-project');
15const createCustomizeProject = require('./create-customized-project');
16const createQuickStartProject = require('./create-quickstart-project');
17
18module.exports = async scope => {
19 const hasDatabaseConfig = Boolean(scope.database);
20
21 // check rootPath is empty
22 if (await fse.exists(scope.rootPath)) {
23 const stat = await fse.stat(scope.rootPath);
24
25 if (!stat.isDirectory()) {
26 stopProcess(
27 `⛔️ ${chalk.green(
28 scope.rootPath
29 )} is not a directory. Make sure to create a Strapi application in an empty directory.`
30 );
31 }
32
33 const files = await fse.readdir(scope.rootPath);
34 if (files.length > 1) {
35 stopProcess(
36 `⛔️ You can only create a Strapi app in an empty directory.\nMake sure ${chalk.green(
37 scope.rootPath
38 )} is empty.`
39 );
40 }
41 }
42
43 await trackUsage({ event: 'willCreateProject', scope });
44
45 // if database config is provided don't test the connection and create the project directly
46 if (hasDatabaseConfig) {
47 return createCLIDatabaseProject(scope);
48 }
49
50 // if cli quickstart create project with default sqlite options
51 if (scope.quick === true) {
52 return createQuickStartProject(scope);
53 }
54
55 const useQuickStart = await askShouldUseQuickstart();
56 // else if question response is quickstart create project
57 if (useQuickStart) {
58 return createQuickStartProject(scope);
59 }
60
61 // create a project with full list of questions
62 return createCustomizeProject(scope);
63};
64
65async function askShouldUseQuickstart() {
66 const answer = await inquirer.prompt([
67 {
68 type: 'list',
69 name: 'type',
70 message: 'Choose your installation type',
71 choices: [
72 {
73 name: 'Quickstart (recommended)',
74 value: 'quick',
75 },
76 {
77 name: 'Custom (manual settings)',
78 value: 'custom',
79 },
80 ],
81 },
82 ]);
83
84 return answer.type === 'quick';
85}