2019-06-20 15:45:14 +02:00
|
|
|
'use strict';
|
|
|
|
|
2021-11-23 14:53:00 +01:00
|
|
|
const { resolve } = require('path');
|
2019-06-20 15:45:14 +02:00
|
|
|
const commander = require('commander');
|
2021-11-23 14:53:00 +01:00
|
|
|
const { checkInstallPath, generateNewApp } = require('@strapi/generate-new');
|
2021-06-02 14:55:33 +02:00
|
|
|
const promptUser = require('./utils/prompt-user');
|
2022-02-21 12:52:20 +01:00
|
|
|
// eslint-disable-next-line import/extensions
|
2020-10-27 11:27:17 +01:00
|
|
|
const packageJson = require('./package.json');
|
2019-06-20 15:45:14 +02:00
|
|
|
|
|
|
|
const program = new commander.Command(packageJson.name);
|
|
|
|
|
2021-11-16 15:36:38 +01:00
|
|
|
const databaseOptions = [
|
2021-11-10 17:55:31 +01:00
|
|
|
'dbclient',
|
|
|
|
'dbhost',
|
|
|
|
'dbport',
|
|
|
|
'dbname',
|
|
|
|
'dbusername',
|
|
|
|
'dbpassword',
|
|
|
|
'dbssl',
|
|
|
|
'dbfile',
|
|
|
|
];
|
|
|
|
|
2019-06-20 15:45:14 +02:00
|
|
|
program
|
|
|
|
.version(packageJson.version)
|
2021-06-02 14:55:33 +02:00
|
|
|
.arguments('[directory]')
|
2019-07-08 09:20:34 +02:00
|
|
|
.option('--no-run', 'Do not start the application after it is created')
|
2020-08-27 10:53:38 +02:00
|
|
|
.option('--use-npm', 'Force usage of npm instead of yarn to create the project')
|
2019-06-20 15:45:14 +02:00
|
|
|
.option('--debug', 'Display database connection error')
|
|
|
|
.option('--quickstart', 'Quickstart app creation')
|
|
|
|
.option('--dbclient <dbclient>', 'Database client')
|
|
|
|
.option('--dbhost <dbhost>', 'Database host')
|
|
|
|
.option('--dbport <dbport>', 'Database port')
|
|
|
|
.option('--dbname <dbname>', 'Database name')
|
|
|
|
.option('--dbusername <dbusername>', 'Database username')
|
|
|
|
.option('--dbpassword <dbpassword>', 'Database password')
|
|
|
|
.option('--dbssl <dbssl>', 'Database SSL')
|
|
|
|
.option('--dbfile <dbfile>', 'Database file path for sqlite')
|
|
|
|
.option('--dbforce', 'Overwrite database content if any')
|
2020-08-27 10:53:38 +02:00
|
|
|
.option('--template <templateurl>', 'Specify a Strapi template')
|
2022-03-07 11:09:26 +01:00
|
|
|
.option('--ts, --typescript', 'Use TypeScript to generate the project')
|
2019-06-20 15:45:14 +02:00
|
|
|
.description('create a new application')
|
|
|
|
.action(directory => {
|
2021-06-02 14:55:33 +02:00
|
|
|
initProject(directory, program);
|
2019-06-20 15:45:14 +02:00
|
|
|
})
|
|
|
|
.parse(process.argv);
|
|
|
|
|
2021-06-02 14:55:33 +02:00
|
|
|
function generateApp(projectName, options) {
|
|
|
|
if (!projectName) {
|
|
|
|
console.error('Please specify the <directory> of your project when using --quickstart');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2020-01-24 15:39:14 +01:00
|
|
|
|
2021-06-02 14:55:33 +02:00
|
|
|
return generateNewApp(projectName, options).then(() => {
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
});
|
2019-06-20 15:45:14 +02:00
|
|
|
}
|
|
|
|
|
2021-06-02 14:55:33 +02:00
|
|
|
async function initProject(projectName, program) {
|
2021-11-29 10:11:51 +01:00
|
|
|
if (projectName) {
|
|
|
|
await checkInstallPath(resolve(projectName));
|
|
|
|
}
|
2021-11-23 14:53:00 +01:00
|
|
|
|
2021-11-16 15:36:38 +01:00
|
|
|
const hasDatabaseOptions = databaseOptions.some(opt => program[opt]);
|
2021-11-10 17:55:31 +01:00
|
|
|
|
2021-11-16 15:36:38 +01:00
|
|
|
if (program.quickstart && hasDatabaseOptions) {
|
2021-11-10 17:55:31 +01:00
|
|
|
console.error(
|
2021-11-16 15:36:38 +01:00
|
|
|
`The quickstart option is incompatible with the following options: ${databaseOptions.join(
|
2021-11-10 17:55:31 +01:00
|
|
|
', '
|
|
|
|
)}`
|
|
|
|
);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2021-11-16 15:36:38 +01:00
|
|
|
if (hasDatabaseOptions) {
|
2021-11-10 17:55:31 +01:00
|
|
|
program.quickstart = false; // Will disable the quickstart question because != 'undefined'
|
|
|
|
}
|
|
|
|
|
2021-06-02 14:55:33 +02:00
|
|
|
if (program.quickstart) {
|
|
|
|
return generateApp(projectName, program);
|
2021-04-27 08:54:11 +02:00
|
|
|
}
|
2021-06-02 14:55:33 +02:00
|
|
|
|
2022-02-28 13:40:13 -05:00
|
|
|
const prompt = await promptUser(projectName, program, hasDatabaseOptions);
|
2021-06-02 14:55:33 +02:00
|
|
|
const directory = prompt.directory || projectName;
|
2021-11-29 10:11:51 +01:00
|
|
|
await checkInstallPath(resolve(directory));
|
2021-11-29 10:05:33 +01:00
|
|
|
|
2021-06-02 14:55:33 +02:00
|
|
|
const options = {
|
2021-11-16 15:36:38 +01:00
|
|
|
template: program.template,
|
2021-11-10 17:55:31 +01:00
|
|
|
quickstart: prompt.quick || program.quickstart,
|
2021-06-02 14:55:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const generateStrapiAppOptions = {
|
|
|
|
...program,
|
|
|
|
...options,
|
|
|
|
};
|
|
|
|
|
|
|
|
return generateApp(directory, generateStrapiAppOptions);
|
|
|
|
}
|