UNPKG

3.08 kBJavaScriptView Raw
1'use strict';
2
3const { join, resolve, basename } = require('path');
4const os = require('os');
5const crypto = require('crypto');
6const chalk = require('chalk');
7const { machineIdSync } = require('node-machine-id');
8const uuid = require('uuid/v4');
9const sentry = require('@sentry/node');
10
11const hasYarn = require('./utils/has-yarn');
12const checkRequirements = require('./utils/check-requirements');
13const { trackError, captureException } = require('./utils/usage');
14const parseDatabaseArguments = require('./utils/parse-db-arguments');
15const generateNew = require('./generate-new');
16
17sentry.init({
18 dsn: 'https://841d2b2c9b4d4b43a4cde92794cb705a@sentry.io/1762059',
19});
20
21module.exports = (projectDirectory, cliArguments) => {
22 checkRequirements();
23
24 const rootPath = resolve(projectDirectory);
25
26 const tmpPath = join(
27 os.tmpdir(),
28 `strapi${crypto.randomBytes(6).toString('hex')}`
29 );
30
31 const useNpm = cliArguments.useNpm !== undefined;
32
33 const scope = {
34 rootPath,
35 name: basename(rootPath),
36 // disable quickstart run app after creation
37 runQuickstartApp: cliArguments.run === false ? false : true,
38 // use pacakge version as strapiVersion (all packages have the same version);
39 strapiVersion: require('../package.json').version,
40 debug: cliArguments.debug !== undefined,
41 quick: cliArguments.quickstart !== undefined,
42 docker: process.env.DOCKER === 'true',
43 uuid: uuid(),
44 deviceId: machineIdSync(),
45 tmpPath,
46 // use yarn if available and --use-npm isn't true
47 useYarn: !useNpm && hasYarn(),
48 installDependencies: true,
49 strapiDependencies: [
50 'strapi',
51 'strapi-admin',
52 'strapi-utils',
53 'strapi-plugin-content-type-builder',
54 'strapi-plugin-content-manager',
55 'strapi-plugin-users-permissions',
56 'strapi-plugin-email',
57 'strapi-plugin-upload',
58 ],
59 additionalsDependencies: {},
60 };
61
62 sentry.configureScope(function(sentryScope) {
63 const tags = {
64 os_type: os.type(),
65 os_platform: os.platform(),
66 os_release: os.release(),
67 strapi_version: scope.strapiVersion,
68 node_version: process.version,
69 docker: scope.docker,
70 };
71
72 Object.keys(tags).forEach(tag => {
73 sentryScope.setTag(tag, tags[tag]);
74 });
75 });
76
77 parseDatabaseArguments({ scope, args: cliArguments });
78 initCancelCatcher(scope);
79
80 console.log(`Creating a new Strapi application at ${chalk.green(rootPath)}.`);
81 console.log();
82
83 return generateNew(scope).catch(error => {
84 console.error(error);
85 return captureException(error).then(() => {
86 return trackError({ scope, error }).then(() => {
87 process.exit(1);
88 });
89 });
90 });
91};
92
93function initCancelCatcher() {
94 // Create interface for windows user to let them quit the program.
95 if (process.platform === 'win32') {
96 const rl = require('readline').createInterface({
97 input: process.stdin,
98 output: process.stdout,
99 });
100
101 rl.on('SIGINT', function() {
102 process.emit('SIGINT');
103 });
104 }
105
106 process.on('SIGINT', () => {
107 process.exit(1);
108 });
109}