1 | 'use strict';
|
2 |
|
3 | const { join, resolve, basename } = require('path');
|
4 | const os = require('os');
|
5 | const crypto = require('crypto');
|
6 | const chalk = require('chalk');
|
7 | const { machineIdSync } = require('node-machine-id');
|
8 | const uuid = require('uuid/v4');
|
9 | const sentry = require('@sentry/node');
|
10 |
|
11 | const hasYarn = require('./utils/has-yarn');
|
12 | const checkRequirements = require('./utils/check-requirements');
|
13 | const { trackError, captureException } = require('./utils/usage');
|
14 | const parseDatabaseArguments = require('./utils/parse-db-arguments');
|
15 | const generateNew = require('./generate-new');
|
16 |
|
17 | sentry.init({
|
18 | dsn: 'https://841d2b2c9b4d4b43a4cde92794cb705a@sentry.io/1762059',
|
19 | });
|
20 |
|
21 | module.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 |
|
37 | runQuickstartApp: cliArguments.run === false ? false : true,
|
38 |
|
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 |
|
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 |
|
93 | function initCancelCatcher() {
|
94 |
|
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 | }
|