strapi/packages/strapi/bin/strapi-new.js

87 lines
2.1 KiB
JavaScript
Raw Normal View History

2016-03-18 11:12:50 +01:00
#!/usr/bin/env node
'use strict';
/**
* Module dependencies
*/
// Node.js core.
const path = require('path');
// 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.
*/
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
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',
name,
strapiPackageJSON: packageJSON,
2018-12-28 16:51:02 +01:00
developerMode,
debug: cliArguments.debug !== undefined
2016-03-18 11:12:50 +01:00
};
const dbArguments = ['dbclient', 'dbhost', 'dbport', 'dbname', 'dbusername', 'dbpassword'];
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}`);
return process.exit(1);
}
scope.dbforce = cliArguments.dbforce !== undefined;
scope.database = {
settings: {
2018-02-06 19:34:23 +01:00
client: cliArguments.dbclient,
host: cliArguments.dbhost,
port: cliArguments.dbport,
database: cliArguments.dbname,
username: cliArguments.dbusername,
password: cliArguments.dbpassword
},
options: {
authenticationDatabase: cliArguments.dbauth,
ssl: cliArguments.dbssl
}
2018-05-04 17:02:27 +02: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);
}
});
};