2016-03-18 11:12:50 +01:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Module dependencies
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Node.js core.
|
|
|
|
|
const path = require('path');
|
|
|
|
|
|
2018-02-05 22:21:47 +01:00
|
|
|
// Public node modules.
|
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
2016-03-18 11:12:50 +01:00
|
|
|
// Master of ceremonies for generators.
|
|
|
|
|
const generate = require('strapi-generate');
|
|
|
|
|
|
2018-05-04 17:02:27 +02:00
|
|
|
// Local Strapi dependencies.
|
|
|
|
|
const packageJSON = require('../package.json');
|
|
|
|
|
|
2016-03-18 11:12:50 +01:00
|
|
|
/**
|
|
|
|
|
* `$ strapi new`
|
|
|
|
|
*
|
|
|
|
|
* Generate a new Strapi application.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-27 17:55:51 +02:00
|
|
|
module.exports = function (name, cliArguments) {
|
2018-06-22 15:25:15 +02:00
|
|
|
console.log('🚀 Start creating your Strapi application. It might take a minute, please take a coffee ☕️');
|
2016-03-18 11:12:50 +01:00
|
|
|
|
2017-09-27 17:55:51 +02:00
|
|
|
const developerMode = cliArguments.dev !== undefined;
|
2016-03-18 11:12:50 +01:00
|
|
|
|
2018-06-22 15:25:15 +02:00
|
|
|
if (developerMode) {
|
|
|
|
|
console.log('🦄 Dev mode is activated!');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log();
|
|
|
|
|
|
2016-03-18 11:12:50 +01:00
|
|
|
// Build initial scope.
|
|
|
|
|
const scope = {
|
|
|
|
|
rootPath: process.cwd(),
|
|
|
|
|
strapiRoot: path.resolve(__dirname, '..'),
|
|
|
|
|
generatorType: 'new',
|
2017-09-27 17:55:51 +02:00
|
|
|
name,
|
|
|
|
|
strapiPackageJSON: packageJSON,
|
2018-12-28 16:51:02 +01:00
|
|
|
developerMode,
|
|
|
|
|
debug: cliArguments.debug !== undefined
|
2016-03-18 11:12:50 +01:00
|
|
|
};
|
|
|
|
|
|
2018-07-12 14:36:44 +01:00
|
|
|
const dbArguments = ['dbclient', 'dbhost', 'dbport', 'dbname', 'dbusername', 'dbpassword'];
|
2018-02-08 11:53:45 +01:00
|
|
|
const matchingDbArguments = _.intersection(_.keys(cliArguments), dbArguments);
|
|
|
|
|
|
|
|
|
|
if (matchingDbArguments.length) {
|
|
|
|
|
if (matchingDbArguments.length !== dbArguments.length) {
|
2018-06-22 15:25:15 +02:00
|
|
|
console.log(`⛔️ Some database arguments are missing. Required arguments list: ${dbArguments}`);
|
2018-02-08 11:53:45 +01:00
|
|
|
return process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 13:50:53 +05:30
|
|
|
scope.dbforce = cliArguments.dbforce !== undefined;
|
2018-12-24 15:39:51 +05:30
|
|
|
|
2018-02-05 22:21:47 +01:00
|
|
|
scope.database = {
|
|
|
|
|
settings: {
|
2018-02-06 19:34:23 +01:00
|
|
|
client: cliArguments.dbclient,
|
2018-02-05 22:21:47 +01:00
|
|
|
host: cliArguments.dbhost,
|
|
|
|
|
port: cliArguments.dbport,
|
|
|
|
|
database: cliArguments.dbname,
|
|
|
|
|
username: cliArguments.dbusername,
|
|
|
|
|
password: cliArguments.dbpassword
|
|
|
|
|
},
|
2018-07-11 16:42:12 +01:00
|
|
|
options: {
|
|
|
|
|
authenticationDatabase: cliArguments.dbauth,
|
2018-12-26 13:50:53 +05:30
|
|
|
ssl: cliArguments.dbssl
|
2018-07-11 16:42:12 +01:00
|
|
|
}
|
2018-05-04 17:02:27 +02:00
|
|
|
};
|
2018-02-05 22:21:47 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-18 11:12:50 +01:00
|
|
|
// Return the scope and the response (`error` or `success`).
|
|
|
|
|
return generate(scope, {
|
|
|
|
|
|
|
|
|
|
// Log and exit the REPL in case there is an error
|
|
|
|
|
// while we were trying to generate the new app.
|
|
|
|
|
error: function returnError(err) {
|
2018-06-22 15:25:15 +02:00
|
|
|
console.log(err);
|
2016-03-18 11:12:50 +01:00
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|