2016-03-18 11:12:50 +01:00
|
|
|
'use strict';
|
|
|
|
|
2019-06-19 19:02:36 +02:00
|
|
|
const { join, resolve, basename } = require('path');
|
|
|
|
const os = require('os');
|
|
|
|
const crypto = require('crypto');
|
2019-06-20 15:45:14 +02:00
|
|
|
const chalk = require('chalk');
|
2019-06-19 19:02:36 +02:00
|
|
|
const { machineIdSync } = require('node-machine-id');
|
|
|
|
const uuid = require('uuid/v4');
|
2019-09-26 12:33:36 +02:00
|
|
|
const sentry = require('@sentry/node');
|
2016-03-18 11:12:50 +01:00
|
|
|
|
2019-06-20 16:38:15 +02:00
|
|
|
const hasYarn = require('./utils/has-yarn');
|
2019-10-14 16:14:34 +02:00
|
|
|
const checkRequirements = require('./utils/check-requirements');
|
2019-10-15 16:21:59 +02:00
|
|
|
const { trackError, captureException } = require('./utils/usage');
|
2019-06-20 16:38:15 +02:00
|
|
|
const parseDatabaseArguments = require('./utils/parse-db-arguments');
|
|
|
|
const generateNew = require('./generate-new');
|
2016-03-18 11:12:50 +01:00
|
|
|
|
2019-09-26 12:33:36 +02:00
|
|
|
sentry.init({
|
|
|
|
dsn: 'https://841d2b2c9b4d4b43a4cde92794cb705a@sentry.io/1762059',
|
|
|
|
});
|
|
|
|
|
2019-06-20 15:45:14 +02:00
|
|
|
module.exports = (projectDirectory, cliArguments) => {
|
2019-10-14 16:14:34 +02:00
|
|
|
checkRequirements();
|
|
|
|
|
2019-06-20 15:45:14 +02:00
|
|
|
const rootPath = resolve(projectDirectory);
|
2019-01-27 16:55:55 +01:00
|
|
|
|
2019-06-19 19:02:36 +02:00
|
|
|
const tmpPath = join(
|
|
|
|
os.tmpdir(),
|
|
|
|
`strapi${crypto.randomBytes(6).toString('hex')}`
|
|
|
|
);
|
2016-03-18 11:12:50 +01:00
|
|
|
|
2019-07-02 17:38:06 +02:00
|
|
|
const useNpm = cliArguments.useNpm !== undefined;
|
|
|
|
|
2019-06-19 19:02:36 +02:00
|
|
|
const scope = {
|
|
|
|
rootPath,
|
|
|
|
name: basename(rootPath),
|
2019-06-20 16:38:15 +02:00
|
|
|
// disable quickstart run app after creation
|
|
|
|
runQuickstartApp: cliArguments.run === false ? false : true,
|
2019-06-19 19:02:36 +02:00
|
|
|
// use pacakge version as strapiVersion (all packages have the same version);
|
|
|
|
strapiVersion: require('../package.json').version,
|
2019-06-20 15:45:14 +02:00
|
|
|
debug: cliArguments.debug !== undefined,
|
|
|
|
quick: cliArguments.quickstart !== undefined,
|
2019-11-29 18:10:32 +01:00
|
|
|
docker: cliArguments.docker !== undefined,
|
2019-06-20 15:45:14 +02:00
|
|
|
uuid: uuid(),
|
2019-06-19 19:02:36 +02:00
|
|
|
deviceId: machineIdSync(),
|
|
|
|
tmpPath,
|
2019-07-02 17:38:06 +02:00
|
|
|
// use yarn if available and --use-npm isn't true
|
|
|
|
useYarn: !useNpm && hasYarn(),
|
2019-07-18 16:25:20 +02:00
|
|
|
installDependencies: true,
|
2019-06-19 19:02:36 +02:00
|
|
|
strapiDependencies: [
|
|
|
|
'strapi',
|
|
|
|
'strapi-admin',
|
|
|
|
'strapi-utils',
|
|
|
|
'strapi-plugin-content-type-builder',
|
|
|
|
'strapi-plugin-content-manager',
|
|
|
|
'strapi-plugin-users-permissions',
|
|
|
|
'strapi-plugin-email',
|
|
|
|
'strapi-plugin-upload',
|
|
|
|
],
|
|
|
|
additionalsDependencies: {},
|
|
|
|
};
|
2016-03-18 11:12:50 +01:00
|
|
|
|
2019-09-26 12:33:36 +02:00
|
|
|
sentry.configureScope(function(sentryScope) {
|
|
|
|
const tags = {
|
|
|
|
os_type: os.type(),
|
|
|
|
os_platform: os.platform(),
|
|
|
|
os_release: os.release(),
|
|
|
|
strapi_version: scope.strapiVersion,
|
|
|
|
node_version: process.version,
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.keys(tags).forEach(tag => {
|
|
|
|
sentryScope.setTag(tag, tags[tag]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-19 19:02:36 +02:00
|
|
|
parseDatabaseArguments({ scope, args: cliArguments });
|
2019-06-20 15:45:14 +02:00
|
|
|
initCancelCatcher(scope);
|
2019-06-19 19:02:36 +02:00
|
|
|
|
2019-07-08 16:13:36 +02:00
|
|
|
console.log(`Creating a new Strapi application at ${chalk.green(rootPath)}.`);
|
2019-06-20 15:45:14 +02:00
|
|
|
console.log();
|
2019-06-19 19:02:36 +02:00
|
|
|
|
2019-06-20 15:45:14 +02:00
|
|
|
return generateNew(scope).catch(error => {
|
|
|
|
console.error(error);
|
2019-10-15 16:21:59 +02:00
|
|
|
return captureException(error).then(() => {
|
2019-09-26 12:33:36 +02:00
|
|
|
return trackError({ scope, error }).then(() => {
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2019-06-19 19:02:36 +02:00
|
|
|
});
|
|
|
|
});
|
2019-06-20 15:45:14 +02:00
|
|
|
};
|
2019-06-19 19:02:36 +02:00
|
|
|
|
2019-06-20 18:04:09 +02:00
|
|
|
function initCancelCatcher() {
|
2019-06-19 19:02:36 +02:00
|
|
|
// Create interface for windows user to let them quit the program.
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
const rl = require('readline').createInterface({
|
|
|
|
input: process.stdin,
|
|
|
|
output: process.stdout,
|
|
|
|
});
|
|
|
|
|
|
|
|
rl.on('SIGINT', function() {
|
|
|
|
process.emit('SIGINT');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
process.on('SIGINT', () => {
|
2019-06-20 18:04:09 +02:00
|
|
|
process.exit(1);
|
2019-06-19 19:02:36 +02:00
|
|
|
});
|
|
|
|
}
|