strapi/packages/generators/app/lib/generate-new.js

56 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-06-20 15:45:14 +02:00
'use strict';
/**
* Module dependencies
*/
// Node.js core.
const chalk = require('chalk');
2019-06-20 16:38:15 +02:00
const fse = require('fs-extra');
2019-06-20 15:45:14 +02:00
2019-10-14 16:14:34 +02:00
const { trackUsage } = require('./utils/usage');
2019-06-20 15:45:14 +02:00
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 => {
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()) {
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) {
stopProcess(
`⛔️ 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.`
);
}
}
2019-10-14 16:14:34 +02:00
await trackUsage({ event: 'willCreateProject', scope });
2019-06-20 15:45:14 +02:00
// 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);
}
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
};