1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | const chalk = require('chalk');
|
9 | const inquirer = require('inquirer');
|
10 | const fse = require('fs-extra');
|
11 |
|
12 | const { trackUsage } = require('./utils/usage');
|
13 | const stopProcess = require('./utils/stop-process');
|
14 | const createCLIDatabaseProject = require('./create-cli-db-project');
|
15 | const createCustomizeProject = require('./create-customized-project');
|
16 | const createQuickStartProject = require('./create-quickstart-project');
|
17 |
|
18 | module.exports = async scope => {
|
19 | const hasDatabaseConfig = Boolean(scope.database);
|
20 |
|
21 |
|
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 |
|
46 | if (hasDatabaseConfig) {
|
47 | return createCLIDatabaseProject(scope);
|
48 | }
|
49 |
|
50 |
|
51 | if (scope.quick === true) {
|
52 | return createQuickStartProject(scope);
|
53 | }
|
54 |
|
55 | const useQuickStart = await askShouldUseQuickstart();
|
56 |
|
57 | if (useQuickStart) {
|
58 | return createQuickStartProject(scope);
|
59 | }
|
60 |
|
61 |
|
62 | return createCustomizeProject(scope);
|
63 | };
|
64 |
|
65 | async 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 | }
|