create-strapi-app 5.12.1 → 5.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/cloud.js +65 -0
  2. package/dist/cloud.js.map +1 -0
  3. package/dist/cloud.mjs +63 -0
  4. package/dist/cloud.mjs.map +1 -0
  5. package/dist/create-strapi.js +251 -0
  6. package/dist/create-strapi.js.map +1 -0
  7. package/dist/create-strapi.mjs +249 -0
  8. package/dist/create-strapi.mjs.map +1 -0
  9. package/dist/index.js +35 -1330
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +15 -1291
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/prompts.js +66 -0
  14. package/dist/prompts.js.map +1 -0
  15. package/dist/prompts.mjs +60 -0
  16. package/dist/prompts.mjs.map +1 -0
  17. package/dist/types.js +8 -0
  18. package/dist/types.js.map +1 -0
  19. package/dist/types.mjs +6 -0
  20. package/dist/types.mjs.map +1 -0
  21. package/dist/utils/check-install-path.js +28 -0
  22. package/dist/utils/check-install-path.js.map +1 -0
  23. package/dist/utils/check-install-path.mjs +26 -0
  24. package/dist/utils/check-install-path.mjs.map +1 -0
  25. package/dist/utils/check-requirements.js +26 -0
  26. package/dist/utils/check-requirements.js.map +1 -0
  27. package/dist/utils/check-requirements.mjs +24 -0
  28. package/dist/utils/check-requirements.mjs.map +1 -0
  29. package/dist/utils/database.js +190 -0
  30. package/dist/utils/database.js.map +1 -0
  31. package/dist/utils/database.mjs +187 -0
  32. package/dist/utils/database.mjs.map +1 -0
  33. package/dist/utils/dot-env.js +46 -0
  34. package/dist/utils/dot-env.js.map +1 -0
  35. package/dist/utils/dot-env.mjs +44 -0
  36. package/dist/utils/dot-env.mjs.map +1 -0
  37. package/dist/utils/engines.js +9 -0
  38. package/dist/utils/engines.js.map +1 -0
  39. package/dist/utils/engines.mjs +7 -0
  40. package/dist/utils/engines.mjs.map +1 -0
  41. package/dist/utils/get-package-manager-args.js +135 -0
  42. package/dist/utils/get-package-manager-args.js.map +1 -0
  43. package/dist/utils/get-package-manager-args.mjs +132 -0
  44. package/dist/utils/get-package-manager-args.mjs.map +1 -0
  45. package/dist/utils/git.js +73 -0
  46. package/dist/utils/git.js.map +1 -0
  47. package/dist/utils/git.mjs +71 -0
  48. package/dist/utils/git.mjs.map +1 -0
  49. package/dist/utils/gitignore.js +139 -0
  50. package/dist/utils/gitignore.js.map +1 -0
  51. package/dist/utils/gitignore.mjs +137 -0
  52. package/dist/utils/gitignore.mjs.map +1 -0
  53. package/dist/utils/logger.js +54 -0
  54. package/dist/utils/logger.js.map +1 -0
  55. package/dist/utils/logger.mjs +52 -0
  56. package/dist/utils/logger.mjs.map +1 -0
  57. package/dist/utils/machine-id.js +17 -0
  58. package/dist/utils/machine-id.js.map +1 -0
  59. package/dist/utils/machine-id.mjs +15 -0
  60. package/dist/utils/machine-id.mjs.map +1 -0
  61. package/dist/utils/package-json.js +32 -0
  62. package/dist/utils/package-json.js.map +1 -0
  63. package/dist/utils/package-json.mjs +30 -0
  64. package/dist/utils/package-json.mjs.map +1 -0
  65. package/dist/utils/parse-to-chalk.js +25 -0
  66. package/dist/utils/parse-to-chalk.js.map +1 -0
  67. package/dist/utils/parse-to-chalk.mjs +23 -0
  68. package/dist/utils/parse-to-chalk.mjs.map +1 -0
  69. package/dist/utils/template.js +180 -0
  70. package/dist/utils/template.js.map +1 -0
  71. package/dist/utils/template.mjs +159 -0
  72. package/dist/utils/template.mjs.map +1 -0
  73. package/dist/utils/usage.js +90 -0
  74. package/dist/utils/usage.js.map +1 -0
  75. package/dist/utils/usage.mjs +87 -0
  76. package/dist/utils/usage.mjs.map +1 -0
  77. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -1,1315 +1,20 @@
1
1
  'use strict';
2
2
 
3
3
  var path = require('node:path');
4
- var os$1 = require('node:os');
4
+ var os = require('node:os');
5
5
  var chalk = require('chalk');
6
6
  var commander = require('commander');
7
7
  var crypto = require('crypto');
8
8
  var fse = require('fs-extra');
9
- var inquirer = require('inquirer');
10
- var cloudCli = require('@strapi/cloud-cli');
11
- var execa = require('execa');
12
- var url = require('node:url');
13
- var node_stream = require('node:stream');
14
- var promises = require('node:stream/promises');
15
- var tar = require('tar');
16
- var retry = require('async-retry');
17
- var os = require('os');
18
- var _ = require('lodash');
19
- var path$1 = require('path');
20
- var semver = require('semver');
21
- var nodeMachineId = require('node-machine-id');
22
-
23
- function _interopNamespaceDefault(e) {
24
- var n = Object.create(null);
25
- if (e) {
26
- Object.keys(e).forEach(function (k) {
27
- if (k !== 'default') {
28
- var d = Object.getOwnPropertyDescriptor(e, k);
29
- Object.defineProperty(n, k, d.get ? d : {
30
- enumerable: true,
31
- get: function () { return e[k]; }
32
- });
33
- }
34
- });
35
- }
36
- n.default = e;
37
- return Object.freeze(n);
38
- }
39
-
40
- var tar__namespace = /*#__PURE__*/_interopNamespaceDefault(tar);
41
-
42
- async function directory() {
43
- const { directory } = await inquirer.prompt([
44
- {
45
- type: 'input',
46
- default: 'my-strapi-project',
47
- name: 'directory',
48
- message: 'What is the name of your project?'
49
- }
50
- ]);
51
- return directory;
52
- }
53
- async function typescript() {
54
- const { useTypescript } = await inquirer.prompt([
55
- {
56
- type: 'confirm',
57
- name: 'useTypescript',
58
- message: 'Start with Typescript?',
59
- default: true
60
- }
61
- ]);
62
- return useTypescript;
63
- }
64
- async function example() {
65
- const { useExample } = await inquirer.prompt([
66
- {
67
- type: 'confirm',
68
- name: 'useExample',
69
- message: 'Start with an example structure & data?',
70
- default: false
71
- }
72
- ]);
73
- return useExample;
74
- }
75
- async function gitInit() {
76
- const { gitInit } = await inquirer.prompt([
77
- {
78
- type: 'confirm',
79
- name: 'gitInit',
80
- message: 'Initialize a git repository?',
81
- default: true
82
- }
83
- ]);
84
- return gitInit;
85
- }
86
- async function installDependencies(packageManager) {
87
- const { installDependencies } = await inquirer.prompt([
88
- {
89
- type: 'confirm',
90
- name: 'installDependencies',
91
- message: `Install dependencies with ${packageManager}?`,
92
- default: true
93
- }
94
- ]);
95
- return installDependencies;
96
- }
97
-
98
- // TODO: move styles to API
99
- const supportedStyles = {
100
- magentaBright: chalk.magentaBright,
101
- blueBright: chalk.blueBright,
102
- yellowBright: chalk.yellowBright,
103
- green: chalk.green,
104
- red: chalk.red,
105
- bold: chalk.bold,
106
- italic: chalk.italic
107
- };
108
- function parseToChalk(template) {
109
- let result = template;
110
- for (const [color, chalkFunction] of Object.entries(supportedStyles)){
111
- const regex = new RegExp(`{${color}}(.*?){/${color}}`, 'g');
112
- result = result.replace(regex, (_, p1)=>chalkFunction(p1.trim()));
113
- }
114
- return result;
115
- }
116
-
117
- function assertCloudError(e) {
118
- if (e.response === undefined) {
119
- throw Error('Expected CloudError');
120
- }
121
- }
122
- async function handleCloudLogin() {
123
- const logger = cloudCli.services.createLogger({
124
- silent: false,
125
- debug: process.argv.includes('--debug'),
126
- timestamp: false
127
- });
128
- const cloudApiService = await cloudCli.services.cloudApiFactory({
129
- logger
130
- });
131
- const defaultErrorMessage = 'An error occurred while trying to interact with Strapi Cloud. Use strapi deploy command once the project is generated.';
132
- try {
133
- const { data: config } = await cloudApiService.config();
134
- logger.log(parseToChalk(config.projectCreation.introText));
135
- } catch (e) {
136
- logger.debug(e);
137
- logger.error(defaultErrorMessage);
138
- return;
139
- }
140
- const { userChoice } = await inquirer.prompt([
141
- {
142
- type: 'list',
143
- name: 'userChoice',
144
- message: `Please log in or sign up.`,
145
- choices: [
146
- 'Login/Sign up',
147
- 'Skip'
148
- ]
149
- }
150
- ]);
151
- if (userChoice !== 'Skip') {
152
- const cliContext = {
153
- logger,
154
- cwd: process.cwd()
155
- };
156
- try {
157
- await cloudCli.cli.login.action(cliContext);
158
- } catch (e) {
159
- logger.debug(e);
160
- try {
161
- assertCloudError(e);
162
- if (e.response.status === 403) {
163
- const message = typeof e.response.data === 'string' ? e.response.data : 'We are sorry, but we are not able to log you into Strapi Cloud at the moment.';
164
- logger.warn(message);
165
- return;
166
- }
167
- } catch (e) {
168
- /* empty */ }
169
- logger.error(defaultErrorMessage);
170
- }
171
- }
172
- }
173
-
174
- const stripTrailingSlash = (str)=>{
175
- return str.endsWith('/') ? str.slice(0, -1) : str;
176
- };
177
- // Merge template with new project being created
178
- async function copyTemplate(scope, rootPath) {
179
- const { template } = scope;
180
- if (!template) {
181
- throw new Error('Missing template or example app option');
182
- }
183
- if (await isOfficialTemplate(template, scope.templateBranch)) {
184
- await retry(()=>downloadGithubRepo(rootPath, {
185
- owner: 'strapi',
186
- repo: 'strapi',
187
- branch: scope.templateBranch,
188
- subPath: `templates/${template}`
189
- }), {
190
- retries: 3,
191
- onRetry (err, attempt) {
192
- console.log(`Retrying to download the template. Attempt ${attempt}. Error: ${err}`);
193
- }
194
- });
195
- return;
196
- }
197
- if (isLocalTemplate(template)) {
198
- const filePath = template.startsWith('file://') ? url.fileURLToPath(template) : template;
199
- await fse.copy(filePath, rootPath);
200
- }
201
- if (isGithubShorthand(template)) {
202
- const [owner, repo, ...pathSegments] = template.split('/');
203
- const subPath = pathSegments.length ? pathSegments.join('/') : scope.templatePath;
204
- await retry(()=>downloadGithubRepo(rootPath, {
205
- owner,
206
- repo,
207
- branch: scope.templateBranch,
208
- subPath
209
- }), {
210
- retries: 3,
211
- onRetry (err, attempt) {
212
- console.log(`Retrying to download the template. Attempt ${attempt}. Error: ${err}`);
213
- }
214
- });
215
- return;
216
- }
217
- if (isGithubRepo(template)) {
218
- const url = new URL(template);
219
- const [owner, repo, t, branch, ...pathSegments] = stripTrailingSlash(url.pathname.slice(1)).split('/');
220
- if (t !== undefined && t !== 'tree') {
221
- throw new Error(`Invalid GitHub template URL: ${template}`);
222
- }
223
- if (scope.templateBranch) {
224
- await retry(()=>downloadGithubRepo(rootPath, {
225
- owner,
226
- repo,
227
- branch: scope.templateBranch,
228
- subPath: scope.templatePath
229
- }), {
230
- retries: 3,
231
- onRetry (err, attempt) {
232
- console.log(`Retrying to download the template. Attempt ${attempt}. Error: ${err}`);
233
- }
234
- });
235
- return;
236
- }
237
- await retry(()=>downloadGithubRepo(rootPath, {
238
- owner,
239
- repo,
240
- branch: decodeURIComponent(branch) ?? scope.templateBranch,
241
- subPath: pathSegments.length ? decodeURIComponent(pathSegments.join('/')) : scope.templatePath
242
- }), {
243
- retries: 3,
244
- onRetry (err, attempt) {
245
- console.log(`Retrying to download the template. Attempt ${attempt}. Error: ${err}`);
246
- }
247
- });
248
- throw new Error(`Invalid GitHub template URL: ${template}`);
249
- }
250
- }
251
- async function downloadGithubRepo(rootPath, { owner, repo, branch, subPath }) {
252
- const filePath = subPath ? subPath.split('/').join(path.posix.sep) : null;
253
- let checkContentUrl = `https://api.github.com/repos/${owner}/${repo}/contents`;
254
- if (filePath) {
255
- checkContentUrl = `${checkContentUrl}/${filePath}`;
256
- }
257
- if (branch) {
258
- checkContentUrl = `${checkContentUrl}?ref=${branch}`;
259
- }
260
- const checkRes = await fetch(checkContentUrl, {
261
- method: 'HEAD'
262
- });
263
- if (checkRes.status !== 200) {
264
- throw new Error(`Could not find a template at https://github.com/${owner}/${repo}${branch ? ` on branch ${branch}` : ''}${filePath ? ` at path ${filePath}` : ''}`);
265
- }
266
- let url = `https://api.github.com/repos/${owner}/${repo}/tarball`;
267
- if (branch) {
268
- url = `${url}/${branch}`;
269
- }
270
- const res = await fetch(url);
271
- if (!res.body) {
272
- throw new Error(`Failed to download ${url}`);
273
- }
274
- await promises.pipeline(// @ts-expect-error - Readable is not a valid source
275
- node_stream.Readable.fromWeb(res.body), tar__namespace.x({
276
- cwd: rootPath,
277
- strip: filePath ? filePath.split('/').length + 1 : 1,
278
- filter (path) {
279
- if (filePath) {
280
- return path.split('/').slice(1).join('/').startsWith(filePath);
281
- }
282
- return true;
283
- }
284
- }));
285
- }
286
- function isLocalTemplate(template) {
287
- return template.startsWith('file://') || fse.existsSync(path.isAbsolute(template) ? template : path.resolve(process.cwd(), template));
288
- }
289
- function isGithubShorthand(value) {
290
- if (isValidUrl(value)) {
291
- return false;
292
- }
293
- return /^[\w-]+\/[\w-.]+(\/[\w-.]+)*$/.test(value);
294
- }
295
- function isGithubRepo(value) {
296
- try {
297
- const url = new URL(value);
298
- return url.origin === 'https://github.com';
299
- } catch {
300
- return false;
301
- }
302
- }
303
- function isValidUrl(value) {
304
- try {
305
- // eslint-disable-next-line no-new
306
- new URL(value);
307
- return true;
308
- } catch {
309
- return false;
310
- }
311
- }
312
- const OFFICIAL_NAME_REGEX = /^[a-zA-Z]*$/;
313
- async function isOfficialTemplate(template, branch) {
314
- if (isValidUrl(template) || !OFFICIAL_NAME_REGEX.test(template)) {
315
- return false;
316
- }
317
- const res = await fetch(`https://api.github.com/repos/strapi/strapi/contents/templates/${template}?${branch ? `ref=${branch}` : ''}`, {
318
- method: 'HEAD'
319
- });
320
- return res.status === 200;
321
- }
322
-
323
- async function isInGitRepository(rootDir) {
324
- try {
325
- await execa('git', [
326
- 'rev-parse',
327
- '--is-inside-work-tree'
328
- ], {
329
- stdio: 'ignore',
330
- cwd: rootDir
331
- });
332
- return true;
333
- } catch (_) {
334
- return false;
335
- }
336
- }
337
- async function isInMercurialRepository(rootDir) {
338
- try {
339
- await execa('hg', [
340
- '-cwd',
341
- '.',
342
- 'root'
343
- ], {
344
- stdio: 'ignore',
345
- cwd: rootDir
346
- });
347
- return true;
348
- } catch (_) {
349
- return false;
350
- }
351
- }
352
- async function tryGitInit(rootDir) {
353
- try {
354
- await execa('git', [
355
- '--version'
356
- ], {
357
- stdio: 'ignore'
358
- });
359
- if (await isInGitRepository(rootDir) || await isInMercurialRepository(rootDir)) {
360
- return false;
361
- }
362
- await execa('git', [
363
- 'init'
364
- ], {
365
- stdio: 'ignore',
366
- cwd: rootDir
367
- });
368
- await execa('git', [
369
- 'add',
370
- '.'
371
- ], {
372
- stdio: 'ignore',
373
- cwd: rootDir
374
- });
375
- await execa('git', [
376
- 'commit',
377
- '-m',
378
- 'Initial commit from Strapi'
379
- ], {
380
- stdio: 'ignore',
381
- cwd: rootDir
382
- });
383
- return true;
384
- } catch (e) {
385
- console.error('Error while trying to initialize git:', e);
386
- return false;
387
- }
388
- }
389
-
390
- // Add properties from the package.json strapi key in the metadata
391
- function addPackageJsonStrapiMetadata(metadata, scope) {
392
- const { packageJsonStrapi = {} } = scope;
393
- return _.defaults(metadata, packageJsonStrapi);
394
- }
395
- const boolToString = (value)=>(value === true).toString();
396
- const getProperties = (scope, error)=>{
397
- const eventProperties = {
398
- error: typeof error === 'string' ? error : error && error.message
399
- };
400
- const userProperties = {
401
- os: os.type(),
402
- osPlatform: os.platform(),
403
- osArch: os.arch(),
404
- osRelease: os.release(),
405
- nodeVersion: process.versions.node
406
- };
407
- const groupProperties = {
408
- version: scope.strapiVersion,
409
- docker: scope.docker,
410
- useYarn: scope.packageManager === 'yarn',
411
- packageManager: scope.packageManager,
412
- /** @deprecated */ useTypescriptOnServer: boolToString(scope.useTypescript),
413
- /** @deprecated */ useTypescriptOnAdmin: boolToString(scope.useTypescript),
414
- useTypescript: boolToString(scope.useTypescript),
415
- isHostedOnStrapiCloud: process.env.STRAPI_HOSTING === 'strapi.cloud',
416
- noRun: boolToString(scope.runApp),
417
- projectId: scope.uuid,
418
- useExample: boolToString(scope.useExample),
419
- gitInit: boolToString(scope.gitInit),
420
- installDependencies: boolToString(scope.installDependencies)
421
- };
422
- return {
423
- eventProperties,
424
- userProperties,
425
- groupProperties: addPackageJsonStrapiMetadata(groupProperties, scope)
426
- };
427
- };
428
- function trackEvent(event, payload) {
429
- if (process.env.NODE_ENV === 'test') {
430
- return;
431
- }
432
- try {
433
- return fetch('https://analytics.strapi.io/api/v2/track', {
434
- method: 'POST',
435
- body: JSON.stringify({
436
- event,
437
- ...payload
438
- }),
439
- signal: AbortSignal.timeout(1000),
440
- headers: {
441
- 'Content-Type': 'application/json',
442
- 'X-Strapi-Event': event
443
- }
444
- }).catch(()=>{});
445
- } catch (err) {
446
- /** ignore errors */ return Promise.resolve();
447
- }
448
- }
449
- async function trackError({ scope, error }) {
450
- const properties = getProperties(scope, error);
451
- try {
452
- return await trackEvent('didNotCreateProject', {
453
- deviceId: scope.deviceId,
454
- ...properties
455
- });
456
- } catch (err) {
457
- /** ignore errors */ return Promise.resolve();
458
- }
459
- }
460
- async function trackUsage({ event, scope, error }) {
461
- const properties = getProperties(scope, error);
462
- try {
463
- return await trackEvent(event, {
464
- deviceId: scope.deviceId,
465
- ...properties
466
- });
467
- } catch (err) {
468
- /** ignore errors */ return Promise.resolve();
469
- }
470
- }
471
-
472
- const engines = {
473
- node: '>=18.0.0 <=22.x.x',
474
- npm: '>=6.0.0'
475
- };
476
-
477
- async function createPackageJSON(scope) {
478
- const { sortPackageJson } = await import('sort-package-json');
479
- const pkgJSONPath = path$1.join(scope.rootPath, 'package.json');
480
- const existingPkg = await fse.readJSON(pkgJSONPath).catch(()=>({}));
481
- const pkg = {
482
- name: _.kebabCase(scope.name),
483
- private: true,
484
- version: '0.1.0',
485
- description: 'A Strapi application',
486
- devDependencies: scope.devDependencies ?? {},
487
- dependencies: scope.dependencies ?? {},
488
- strapi: {
489
- ...scope.packageJsonStrapi ?? {},
490
- uuid: scope.uuid
491
- },
492
- engines
493
- };
494
- // copy templates
495
- await fse.writeJSON(pkgJSONPath, sortPackageJson(_.merge(existingPkg, pkg)), {
496
- spaces: 2
497
- });
498
- }
499
-
500
- const generateASecret = ()=>crypto.randomBytes(16).toString('base64');
501
- const envTmpl = `
502
- # Server
503
- HOST=0.0.0.0
504
- PORT=1337
505
-
506
- # Secrets
507
- APP_KEYS=<%= appKeys %>
508
- API_TOKEN_SALT=<%= apiTokenSalt %>
509
- ADMIN_JWT_SECRET=<%= adminJwtToken %>
510
- TRANSFER_TOKEN_SALT=<%= transferTokenSalt %>
511
-
512
- # Database
513
- DATABASE_CLIENT=<%= database.client %>
514
- DATABASE_HOST=<%= database.connection.host %>
515
- DATABASE_PORT=<%= database.connection.port %>
516
- DATABASE_NAME=<%= database.connection.database %>
517
- DATABASE_USERNAME=<%= database.connection.username %>
518
- DATABASE_PASSWORD=<%= database.connection.password %>
519
- DATABASE_SSL=<%= database.connection.ssl %>
520
- DATABASE_FILENAME=<%= database.connection.filename %>
521
- `;
522
- function generateDotEnv(scope) {
523
- const compile = _.template(envTmpl);
524
- return compile({
525
- appKeys: new Array(4).fill(null).map(generateASecret).join(','),
526
- apiTokenSalt: generateASecret(),
527
- transferTokenSalt: generateASecret(),
528
- adminJwtToken: generateASecret(),
529
- database: {
530
- client: scope.database.client,
531
- connection: {
532
- ...scope.database.connection,
533
- ssl: scope.database.connection?.ssl || false
534
- }
535
- }
536
- });
537
- }
538
-
539
- function isStderrError(error) {
540
- return typeof error === 'object' && error !== null && 'stderr' in error && typeof error.stderr === 'string';
541
- }
542
-
543
- const MAX_PREFIX_LENGTH = 8;
544
- const badge = (text, bgColor, textColor = chalk.black)=>{
545
- const wrappedText = ` ${text} `;
546
- const repeat = Math.max(0, MAX_PREFIX_LENGTH - wrappedText.length);
547
- return ' '.repeat(repeat) + bgColor(textColor(wrappedText));
548
- };
549
- const textIndent = (text, indentFirst = true, indent = MAX_PREFIX_LENGTH + 2)=>{
550
- const parts = Array.isArray(text) ? text : [
551
- text
552
- ];
553
- return parts.map((part, i)=>{
554
- if (i === 0 && !indentFirst) {
555
- return part;
556
- }
557
- return ' '.repeat(indent) + part;
558
- }).join('\n');
559
- };
560
- const logger = {
561
- log (message) {
562
- console.log(textIndent(message));
563
- },
564
- title (title, message) {
565
- const prefix = badge(title, chalk.bgBlueBright);
566
- console.log(`\n${prefix} ${message}`);
567
- },
568
- info (message) {
569
- console.log(`${' '.repeat(7)}${chalk.cyan('●')} ${message}`);
570
- },
571
- success (message) {
572
- console.log(`\n${' '.repeat(7)}${chalk.green('✓')} ${chalk.green(message)}`);
573
- },
574
- fatal (message) {
575
- const prefix = badge('Error', chalk.bgRed);
576
- if (message) {
577
- console.error(`\n${prefix} ${textIndent(message, false)}\n`);
578
- }
579
- process.exit(1);
580
- },
581
- error (message) {
582
- const prefix = badge('Error', chalk.bgRed);
583
- console.error(`\n${prefix} ${textIndent(message, false)}\n`);
584
- },
585
- warn (message) {
586
- const prefix = badge('Warn', chalk.bgYellow);
587
- console.warn(`\n${prefix} ${textIndent(message, false)}\n`);
588
- }
589
- };
590
-
591
- const baseGitIgnore = `
592
- ############################
593
- # OS X
594
- ############################
595
-
596
- .DS_Store
597
- .AppleDouble
598
- .LSOverride
599
- Icon
600
- .Spotlight-V100
601
- .Trashes
602
- ._*
603
-
604
-
605
- ############################
606
- # Linux
607
- ############################
608
-
609
- *~
610
-
611
-
612
- ############################
613
- # Windows
614
- ############################
615
-
616
- Thumbs.db
617
- ehthumbs.db
618
- Desktop.ini
619
- $RECYCLE.BIN/
620
- *.cab
621
- *.msi
622
- *.msm
623
- *.msp
624
-
625
-
626
- ############################
627
- # Packages
628
- ############################
629
-
630
- *.7z
631
- *.csv
632
- *.dat
633
- *.dmg
634
- *.gz
635
- *.iso
636
- *.jar
637
- *.rar
638
- *.tar
639
- *.zip
640
- *.com
641
- *.class
642
- *.dll
643
- *.exe
644
- *.o
645
- *.seed
646
- *.so
647
- *.swo
648
- *.swp
649
- *.swn
650
- *.swm
651
- *.out
652
- *.pid
653
-
654
-
655
- ############################
656
- # Logs and databases
657
- ############################
658
-
659
- .tmp
660
- *.log
661
- *.sql
662
- *.sqlite
663
- *.sqlite3
664
-
665
-
666
- ############################
667
- # Misc.
668
- ############################
669
-
670
- *#
671
- ssl
672
- .idea
673
- nbproject
674
- public/uploads/*
675
- !public/uploads/.gitkeep
676
- .tsbuildinfo
677
- .eslintcache
678
-
679
- ############################
680
- # Node.js
681
- ############################
682
-
683
- lib-cov
684
- lcov.info
685
- pids
686
- logs
687
- results
688
- node_modules
689
- .node_history
690
-
691
- ############################
692
- # Package managers
693
- ############################
694
-
695
- .yarn/*
696
- !.yarn/cache
697
- !.yarn/unplugged
698
- !.yarn/patches
699
- !.yarn/releases
700
- !.yarn/sdks
701
- !.yarn/versions
702
- .pnp.*
703
- yarn-error.log
704
-
705
- ############################
706
- # Tests
707
- ############################
708
-
709
- coverage
710
-
711
- ############################
712
- # Strapi
713
- ############################
714
-
715
- .env
716
- license.txt
717
- exports
718
- .strapi
719
- dist
720
- build
721
- .strapi-updater.json
722
- .strapi-cloud.json
723
- `;
724
- const gitIgnore = baseGitIgnore.trim();
725
-
726
- const installArguments = [
727
- 'install'
728
- ];
729
- // Set command line options for specific package managers, with full semver ranges
730
- const installArgumentsMap = {
731
- npm: {
732
- '*': [
733
- '--legacy-peer-deps'
734
- ]
735
- },
736
- yarn: {
737
- '<4': [
738
- '--network-timeout',
739
- '1000000'
740
- ],
741
- '*': []
742
- },
743
- pnpm: {
744
- '*': []
745
- }
746
- };
747
- // Set environment variables for specific package managers, with full semver ranges
748
- const installEnvMap = {
749
- yarn: {
750
- '>=4': {
751
- YARN_HTTP_TIMEOUT: '1000000'
752
- },
753
- '*': {}
754
- },
755
- npm: {
756
- '*': {}
757
- },
758
- pnpm: {
759
- '*': {}
760
- }
761
- };
762
- /**
763
- * Retrieves the version of the specified package manager.
764
- *
765
- * Executes the package manager's `--version` command to determine its version.
766
- *
767
- * @param packageManager - The name of the package manager (e.g., 'npm', 'yarn', 'pnpm').
768
- * @param options - Optional execution options to pass to `execa`.
769
- * @returns A promise that resolves to the trimmed version string of the package manager.
770
- *
771
- * @throws Will throw an error if the package manager's version cannot be determined.
772
- */ const getPackageManagerVersion = async (packageManager, options)=>{
773
- try {
774
- const { stdout } = await execa(packageManager, [
775
- '--version'
776
- ], options);
777
- return stdout.trim();
778
- } catch (err) {
779
- throw new Error(`Error detecting ${packageManager} version: ${err}`);
780
- }
781
- };
782
- /**
783
- * Merges all matching semver ranges using a custom merge function.
784
- *
785
- * Iterates over the `versionMap`, checking if the provided `version` satisfies each semver range.
786
- * If it does, the corresponding value is merged using the provided `mergeFn`.
787
- * The merging starts with the value associated with the wildcard '*' key.
788
- *
789
- * @param version - The package manager version to check against the ranges.
790
- * @param versionMap - A map of semver ranges to corresponding values (arguments or environment variables).
791
- * @param mergeFn - A function that defines how to merge two values (accumulated and current).
792
- * @returns The merged result of all matching ranges.
793
- */ function mergeMatchingVersionRanges(version, versionMap, mergeFn) {
794
- return Object.keys(versionMap).reduce((acc, range)=>{
795
- if (semver.satisfies(version, range) || range === '*') {
796
- return mergeFn(acc, versionMap[range]);
797
- }
798
- return acc;
799
- }, versionMap['*']); // Start with the wildcard entry
800
- }
801
- function mergeArguments(acc, curr) {
802
- return [
803
- ...acc,
804
- ...curr
805
- ];
806
- }
807
- function mergeEnvVars(acc, curr) {
808
- return {
809
- ...acc,
810
- ...curr
811
- };
812
- }
813
- /**
814
- * Retrieves the install arguments and environment variables for a given package manager.
815
- *
816
- * This function determines the correct command line arguments and environment variables
817
- * based on the package manager's version. It uses predefined semver ranges to match
818
- * the package manager's version and merges all applicable settings.
819
- *
820
- * The arguments and environment variables are sourced from:
821
- * - `installArgumentsMap` for command line arguments.
822
- * - `installEnvMap` for environment variables.
823
- *
824
- * The function ensures that all matching semver ranges are considered and merged appropriately.
825
- * It always includes the base `installArguments` (e.g., `['install']`) and applies any additional
826
- * arguments or environment variables as defined by the matched version ranges.
827
- *
828
- * @param packageManager - The name of the package manager (e.g., 'npm', 'yarn', 'pnpm').
829
- * @param options - Optional execution options to pass to `execa`.
830
- * @returns An object containing:
831
- * - `cmdArgs`: The full array of install arguments for the given package manager and version.
832
- * - `envArgs`: The merged environment variables applicable to the package manager and version.
833
- *
834
- * @throws Will throw an error if the package manager version cannot be determined.
835
- */ const getInstallArgs = async (packageManager, options)=>{
836
- const packageManagerVersion = await getPackageManagerVersion(packageManager, options);
837
- // Get environment variables
838
- const envMap = installEnvMap[packageManager];
839
- const envArgs = packageManagerVersion ? mergeMatchingVersionRanges(packageManagerVersion, envMap, mergeEnvVars) : envMap['*'];
840
- // Get install arguments
841
- const argsMap = installArgumentsMap[packageManager];
842
- const cmdArgs = packageManagerVersion ? mergeMatchingVersionRanges(packageManagerVersion, argsMap, mergeArguments) : argsMap['*'];
843
- return {
844
- envArgs,
845
- cmdArgs: [
846
- ...installArguments,
847
- ...cmdArgs
848
- ],
849
- version: packageManagerVersion
850
- };
851
- };
852
-
853
- async function createStrapi(scope) {
854
- const { rootPath } = scope;
855
- try {
856
- await fse.ensureDir(rootPath);
857
- await createApp(scope);
858
- } catch (error) {
859
- await fse.remove(rootPath);
860
- throw error;
861
- }
862
- }
863
- async function createApp(scope) {
864
- const { rootPath, useTypescript, useExample, installDependencies, isQuickstart, template, packageManager, gitInit, runApp } = scope;
865
- const shouldRunSeed = useExample && installDependencies;
866
- await trackUsage({
867
- event: 'willCreateProject',
868
- scope
869
- });
870
- logger.title('Strapi', `Creating a new application at ${chalk.green(rootPath)}`);
871
- if (!isQuickstart) {
872
- await trackUsage({
873
- event: 'didChooseCustomDatabase',
874
- scope
875
- });
876
- } else {
877
- await trackUsage({
878
- event: 'didChooseQuickstart',
879
- scope
880
- });
881
- }
882
- if (!template) {
883
- let templateName = useExample ? 'example' : 'vanilla';
884
- if (!useTypescript) {
885
- templateName = `${templateName}-js`;
886
- }
887
- const internalTemplatePath = path.join(__dirname, '../templates', templateName);
888
- if (await fse.exists(internalTemplatePath)) {
889
- await fse.copy(internalTemplatePath, rootPath);
890
- }
891
- } else {
892
- try {
893
- logger.info(`${chalk.cyan('Installing template')} ${template}`);
894
- await copyTemplate(scope, rootPath);
895
- logger.success('Template copied successfully.');
896
- } catch (error) {
897
- if (error instanceof Error) {
898
- logger.fatal(`Template installation failed: ${error.message}`);
899
- }
900
- throw error;
901
- }
902
- if (!fse.existsSync(path.join(rootPath, 'package.json'))) {
903
- logger.fatal(`Missing ${chalk.bold('package.json')} in template`);
904
- }
905
- }
906
- await trackUsage({
907
- event: 'didCopyProjectFiles',
908
- scope
909
- });
910
- try {
911
- await createPackageJSON(scope);
912
- await trackUsage({
913
- event: 'didWritePackageJSON',
914
- scope
915
- });
916
- // ensure node_modules is created
917
- await fse.ensureDir(path.join(rootPath, 'node_modules'));
918
- // create config/database
919
- await fse.writeFile(path.join(rootPath, '.env'), generateDotEnv(scope));
920
- await trackUsage({
921
- event: 'didCopyConfigurationFiles',
922
- scope
923
- });
924
- } catch (err) {
925
- await fse.remove(rootPath);
926
- throw err;
927
- }
928
- if (installDependencies) {
929
- try {
930
- logger.title('deps', `Installing dependencies with ${chalk.cyan(packageManager)}`);
931
- await trackUsage({
932
- event: 'willInstallProjectDependencies',
933
- scope
934
- });
935
- await runInstall(scope);
936
- await trackUsage({
937
- event: 'didInstallProjectDependencies',
938
- scope
939
- });
940
- logger.success(`Dependencies installed`);
941
- } catch (error) {
942
- const stderr = isStderrError(error) ? error.stderr : '';
943
- await trackUsage({
944
- event: 'didNotInstallProjectDependencies',
945
- scope,
946
- error: stderr.slice(-1024)
947
- });
948
- logger.fatal([
949
- chalk.bold('Oh, it seems that you encountered an error while installing dependencies in your project'),
950
- '',
951
- `Don't give up, your project was created correctly`,
952
- '',
953
- `Fix the issues mentioned in the installation errors and try to run the following command:`,
954
- '',
955
- `cd ${chalk.green(rootPath)} && ${chalk.cyan(packageManager)} install`
956
- ]);
957
- }
958
- }
959
- await trackUsage({
960
- event: 'didCreateProject',
961
- scope
962
- });
963
- // make sure a gitignore file is created regardless of the user using git or not
964
- if (!await fse.exists(path.join(rootPath, '.gitignore'))) {
965
- await fse.writeFile(path.join(rootPath, '.gitignore'), gitIgnore);
966
- }
967
- // Init git
968
- if (gitInit) {
969
- logger.title('git', 'Initializing git repository.');
970
- await tryGitInit(rootPath);
971
- logger.success('Initialized a git repository.');
972
- }
973
- if (shouldRunSeed) {
974
- if (await fse.exists(path.join(rootPath, 'scripts/seed.js'))) {
975
- logger.title('Seed', 'Seeding your database with sample data');
976
- try {
977
- await execa(packageManager, [
978
- 'run',
979
- 'seed:example'
980
- ], {
981
- stdio: 'inherit',
982
- cwd: rootPath
983
- });
984
- logger.success('Sample data added to your database');
985
- } catch (error) {
986
- logger.error('Failed to seed your database. Skipping');
987
- }
988
- }
989
- }
990
- const cmd = chalk.cyan(`${packageManager} run`);
991
- logger.title('Strapi', `Your application was created!`);
992
- logger.log([
993
- 'Available commands in your project:',
994
- '',
995
- 'Start Strapi in watch mode. (Changes in Strapi project files will trigger a server restart)',
996
- `${cmd} develop`,
997
- '',
998
- 'Start Strapi without watch mode.',
999
- `${cmd} start`,
1000
- '',
1001
- 'Build Strapi admin panel.',
1002
- `${cmd} build`,
1003
- '',
1004
- 'Deploy Strapi project.',
1005
- `${cmd} deploy`,
1006
- ''
1007
- ]);
1008
- if (useExample) {
1009
- logger.log([
1010
- 'Seed your database with sample data.',
1011
- `${cmd} seed:example`,
1012
- ''
1013
- ]);
1014
- }
1015
- logger.log([
1016
- 'Display all available commands.',
1017
- `${cmd} strapi\n`
1018
- ]);
1019
- if (installDependencies) {
1020
- logger.log([
1021
- 'To get started run',
1022
- '',
1023
- `${chalk.cyan('cd')} ${rootPath}`,
1024
- !shouldRunSeed && useExample ? `${cmd} seed:example && ${cmd} develop` : `${cmd} develop`
1025
- ]);
1026
- } else {
1027
- logger.log([
1028
- 'To get started run',
1029
- '',
1030
- `${chalk.cyan('cd')} ${rootPath}`,
1031
- `${chalk.cyan(packageManager)} install`,
1032
- !shouldRunSeed && useExample ? `${cmd} seed:example && ${cmd} develop` : `${cmd} develop`
1033
- ]);
1034
- }
1035
- if (runApp && installDependencies) {
1036
- logger.title('Run', 'Running your Strapi application');
1037
- try {
1038
- await trackUsage({
1039
- event: 'willStartServer',
1040
- scope
1041
- });
1042
- await execa(packageManager, [
1043
- 'run',
1044
- 'develop'
1045
- ], {
1046
- stdio: 'inherit',
1047
- cwd: rootPath,
1048
- env: {
1049
- FORCE_COLOR: '1'
1050
- }
1051
- });
1052
- } catch (error) {
1053
- if (typeof error === 'string' || error instanceof Error) {
1054
- await trackUsage({
1055
- event: 'didNotStartServer',
1056
- scope,
1057
- error
1058
- });
1059
- }
1060
- logger.fatal('Failed to start your Strapi application');
1061
- }
1062
- }
1063
- }
1064
- async function runInstall({ rootPath, packageManager }) {
1065
- // include same cwd and env to ensure version check returns same version we use below
1066
- const { envArgs, cmdArgs } = await getInstallArgs(packageManager, {
1067
- cwd: rootPath,
1068
- env: {
1069
- ...process.env,
1070
- NODE_ENV: 'development'
1071
- }
1072
- });
1073
- const options = {
1074
- cwd: rootPath,
1075
- stdio: 'inherit',
1076
- env: {
1077
- ...process.env,
1078
- ...envArgs,
1079
- NODE_ENV: 'development'
1080
- }
1081
- };
1082
- const proc = execa(packageManager, cmdArgs, options);
1083
- return proc;
1084
- }
1085
-
1086
- function checkNodeRequirements() {
1087
- const currentNodeVersion = process.versions.node;
1088
- // error if the node version isn't supported
1089
- if (!semver.satisfies(currentNodeVersion, engines.node)) {
1090
- logger.fatal([
1091
- chalk.red(`You are running ${chalk.bold(`Node.js ${currentNodeVersion}`)}`),
1092
- `Strapi requires ${chalk.bold(chalk.green(`Node.js ${engines.node}`))}`,
1093
- 'Please make sure to use the right version of Node.'
1094
- ]);
1095
- } else if (semver.major(currentNodeVersion) % 2 !== 0) {
1096
- logger.warn([
1097
- chalk.yellow(`You are running ${chalk.bold(`Node.js ${currentNodeVersion}`)}`),
1098
- `Strapi only supports ${chalk.bold(chalk.green('LTS versions of Node.js'))}, other versions may not be compatible.`
1099
- ]);
1100
- }
1101
- }
1102
-
1103
- // Checks if the an empty directory exists at rootPath
1104
- async function checkInstallPath(directory) {
1105
- const rootPath = path.resolve(directory);
1106
- if (await fse.pathExists(rootPath)) {
1107
- const stat = await fse.stat(rootPath);
1108
- if (!stat.isDirectory()) {
1109
- logger.fatal(`${chalk.green(rootPath)} is not a directory. Make sure to create a Strapi application in an empty directory.`);
1110
- }
1111
- const files = await fse.readdir(rootPath);
1112
- if (files.length > 1) {
1113
- logger.fatal([
1114
- 'You can only create a Strapi app in an empty directory',
1115
- `Make sure ${chalk.green(rootPath)} is empty.`
1116
- ]);
1117
- }
1118
- }
1119
- return rootPath;
1120
- }
1121
-
1122
- function machineID() {
1123
- try {
1124
- const deviceId = nodeMachineId.machineIdSync();
1125
- return deviceId;
1126
- } catch (error) {
1127
- const deviceId = crypto.randomUUID();
1128
- return deviceId;
1129
- }
1130
- }
1131
-
1132
- const DBOptions = [
1133
- 'dbclient',
1134
- 'dbhost',
1135
- 'dbport',
1136
- 'dbname',
1137
- 'dbusername',
1138
- 'dbpassword'
1139
- ];
1140
- const VALID_CLIENTS = [
1141
- 'sqlite',
1142
- 'mysql',
1143
- 'postgres'
1144
- ];
1145
- const DEFAULT_CONFIG = {
1146
- client: 'sqlite',
1147
- connection: {
1148
- filename: '.tmp/data.db'
1149
- }
1150
- };
1151
- async function dbPrompt() {
1152
- const { useDefault } = await inquirer.prompt([
1153
- {
1154
- type: 'confirm',
1155
- name: 'useDefault',
1156
- message: 'Do you want to use the default database (sqlite) ?',
1157
- default: true
1158
- }
1159
- ]);
1160
- if (useDefault) {
1161
- return DEFAULT_CONFIG;
1162
- }
1163
- const { client } = await inquirer.prompt([
1164
- {
1165
- type: 'list',
1166
- name: 'client',
1167
- message: 'Choose your default database client',
1168
- choices: [
1169
- 'sqlite',
1170
- 'postgres',
1171
- 'mysql'
1172
- ],
1173
- default: 'sqlite'
1174
- }
1175
- ]);
1176
- const questions = dbQuestions[client].map((q)=>q({
1177
- client
1178
- }));
1179
- const responses = await inquirer.prompt(questions);
1180
- return {
1181
- client,
1182
- connection: responses
1183
- };
1184
- }
1185
- async function getDatabaseInfos(options) {
1186
- if (options.skipDb) {
1187
- return DEFAULT_CONFIG;
1188
- }
1189
- if (options.dbclient && !VALID_CLIENTS.includes(options.dbclient)) {
1190
- logger.fatal(`Invalid --dbclient: ${options.dbclient}, expected one of ${VALID_CLIENTS.join(', ')}`);
1191
- }
1192
- const matchingArgs = DBOptions.filter((key)=>key in options);
1193
- const missingArgs = DBOptions.filter((key)=>!(key in options));
1194
- if (matchingArgs.length > 0 && matchingArgs.length !== DBOptions.length && options.dbclient !== 'sqlite') {
1195
- logger.fatal(`Required database arguments are missing: ${missingArgs.join(', ')}.`);
1196
- }
1197
- const hasDBOptions = DBOptions.some((key)=>key in options);
1198
- if (!hasDBOptions) {
1199
- if (options.quickstart) {
1200
- return DEFAULT_CONFIG;
1201
- }
1202
- return dbPrompt();
1203
- }
1204
- if (!options.dbclient) {
1205
- return logger.fatal('Please specify the database client');
1206
- }
1207
- const database = {
1208
- client: options.dbclient,
1209
- connection: {
1210
- host: options.dbhost,
1211
- port: options.dbport,
1212
- database: options.dbname,
1213
- username: options.dbusername,
1214
- password: options.dbpassword,
1215
- filename: options.dbfile
1216
- }
1217
- };
1218
- if (options.dbssl !== undefined) {
1219
- database.connection.ssl = options.dbssl === 'true';
1220
- }
1221
- return database;
1222
- }
1223
- const sqlClientModule = {
1224
- mysql: {
1225
- mysql2: '3.9.8'
1226
- },
1227
- postgres: {
1228
- pg: '8.8.0'
1229
- },
1230
- sqlite: {
1231
- 'better-sqlite3': '11.3.0'
1232
- }
1233
- };
1234
- function addDatabaseDependencies(scope) {
1235
- scope.dependencies = {
1236
- ...scope.dependencies,
1237
- ...sqlClientModule[scope.database.client]
1238
- };
1239
- }
1240
- const DEFAULT_PORTS = {
1241
- postgres: 5432,
1242
- mysql: 3306,
1243
- sqlite: undefined
1244
- };
1245
- const database = ()=>({
1246
- type: 'input',
1247
- name: 'database',
1248
- message: 'Database name:',
1249
- default: 'strapi',
1250
- validate (value) {
1251
- if (value.includes('.')) {
1252
- return `The database name can't contain a "."`;
1253
- }
1254
- return true;
1255
- }
1256
- });
1257
- const host = ()=>({
1258
- type: 'input',
1259
- name: 'host',
1260
- message: 'Host:',
1261
- default: '127.0.0.1'
1262
- });
1263
- const port = ({ client })=>({
1264
- type: 'input',
1265
- name: 'port',
1266
- message: 'Port:',
1267
- default: DEFAULT_PORTS[client]
1268
- });
1269
- const username = ()=>({
1270
- type: 'input',
1271
- name: 'username',
1272
- message: 'Username:'
1273
- });
1274
- const password = ()=>({
1275
- type: 'password',
1276
- name: 'password',
1277
- message: 'Password:',
1278
- mask: '*'
1279
- });
1280
- const ssl = ()=>({
1281
- type: 'confirm',
1282
- name: 'ssl',
1283
- message: 'Enable SSL connection:',
1284
- default: false
1285
- });
1286
- const filename = ()=>({
1287
- type: 'input',
1288
- name: 'filename',
1289
- message: 'Filename:',
1290
- default: '.tmp/data.db'
1291
- });
1292
- const dbQuestions = {
1293
- sqlite: [
1294
- filename
1295
- ],
1296
- postgres: [
1297
- database,
1298
- host,
1299
- port,
1300
- username,
1301
- password,
1302
- ssl
1303
- ],
1304
- mysql: [
1305
- database,
1306
- host,
1307
- port,
1308
- username,
1309
- password,
1310
- ssl
1311
- ]
1312
- };
9
+ var prompts = require('./prompts.js');
10
+ var cloud = require('./cloud.js');
11
+ var createStrapi = require('./create-strapi.js');
12
+ var checkRequirements = require('./utils/check-requirements.js');
13
+ var checkInstallPath = require('./utils/check-install-path.js');
14
+ var machineId = require('./utils/machine-id.js');
15
+ var usage = require('./utils/usage.js');
16
+ var database = require('./utils/database.js');
17
+ var logger = require('./utils/logger.js');
1313
18
 
1314
19
  const { version } = fse.readJSONSync(path.join(__dirname, '..', 'package.json'));
1315
20
  const command = new commander.Command('create-strapi-app').version(version).arguments('[directory]').usage('[directory] [options]').option('--quickstart', 'Quickstart app creation (deprecated)').option('--no-run', 'Do not start the application after it is created.')// setup options
@@ -1322,43 +27,43 @@ const command = new commander.Command('create-strapi-app').version(version).argu
1322
27
  .option('--dbclient <dbclient>', 'Database client').option('--dbhost <dbhost>', 'Database host').option('--dbport <dbport>', 'Database port').option('--dbname <dbname>', 'Database name').option('--dbusername <dbusername>', 'Database username').option('--dbpassword <dbpassword>', 'Database password').option('--dbssl <dbssl>', 'Database SSL').option('--dbfile <dbfile>', 'Database file path for sqlite').option('--skip-db', 'Skip database configuration').option('--template <template>', 'Specify a Strapi template').option('--template-branch <templateBranch>', 'Specify a branch for the template').option('--template-path <templatePath>', 'Specify a path to the template inside the repository').description('create a new application');
1323
28
  async function run(args) {
1324
29
  const options = command.parse(args).opts();
1325
- const directory$1 = command.args[0];
1326
- logger.title('Strapi', `${chalk.green(chalk.bold(`v${version}`))} ${chalk.bold("🚀 Let's create your new project")}\n`);
30
+ const directory = command.args[0];
31
+ logger.logger.title('Strapi', `${chalk.green(chalk.bold(`v${version}`))} ${chalk.bold("🚀 Let's create your new project")}\n`);
1327
32
  if ((options.javascript !== undefined || options.typescript !== undefined) && options.template !== undefined) {
1328
- logger.fatal(`You cannot use ${chalk.bold('--javascript')} or ${chalk.bold('--typescript')} with ${chalk.bold('--template')}`);
33
+ logger.logger.fatal(`You cannot use ${chalk.bold('--javascript')} or ${chalk.bold('--typescript')} with ${chalk.bold('--template')}`);
1329
34
  }
1330
35
  if (options.javascript === true && options.typescript === true) {
1331
- logger.fatal(`You cannot use both ${chalk.bold('--typescript')} (--ts) and ${chalk.bold('--javascript')} (--js) flags together`);
36
+ logger.logger.fatal(`You cannot use both ${chalk.bold('--typescript')} (--ts) and ${chalk.bold('--javascript')} (--js) flags together`);
1332
37
  }
1333
38
  // Only prompt the example app option if there is no template option
1334
39
  if (options.example === true && options.template !== undefined) {
1335
- logger.fatal(`You cannot use ${chalk.bold('--example')} with ${chalk.bold('--template')}`);
40
+ logger.logger.fatal(`You cannot use ${chalk.bold('--example')} with ${chalk.bold('--template')}`);
1336
41
  }
1337
42
  if (options.template !== undefined && options.template.startsWith('-')) {
1338
- logger.fatal(`Template name ${chalk.bold(`"${options.template}"`)} is invalid`);
43
+ logger.logger.fatal(`Template name ${chalk.bold(`"${options.template}"`)} is invalid`);
1339
44
  }
1340
45
  if ([
1341
46
  options.useNpm,
1342
47
  options.usePnpm,
1343
48
  options.useYarn
1344
49
  ].filter(Boolean).length > 1) {
1345
- logger.fatal(`You cannot specify multiple package managers at the same time ${chalk.bold('(--use-npm, --use-pnpm, --use-yarn)')}`);
50
+ logger.logger.fatal(`You cannot specify multiple package managers at the same time ${chalk.bold('(--use-npm, --use-pnpm, --use-yarn)')}`);
1346
51
  }
1347
- if (options.quickstart && !directory$1) {
1348
- logger.fatal(`Please specify the ${chalk.bold('<directory>')} of your project when using ${chalk.bold('--quickstart')}`);
52
+ if (options.quickstart && !directory) {
53
+ logger.logger.fatal(`Please specify the ${chalk.bold('<directory>')} of your project when using ${chalk.bold('--quickstart')}`);
1349
54
  }
1350
- checkNodeRequirements();
1351
- const appDirectory = directory$1 || await directory();
1352
- const rootPath = await checkInstallPath(appDirectory);
55
+ checkRequirements.checkNodeRequirements();
56
+ const appDirectory = directory || await prompts.directory();
57
+ const rootPath = await checkInstallPath.checkInstallPath(appDirectory);
1353
58
  if (!options.skipCloud) {
1354
- await handleCloudLogin();
59
+ await cloud.handleCloudLogin();
1355
60
  }
1356
- const tmpPath = path.join(os$1.tmpdir(), `strapi${crypto.randomBytes(6).toString('hex')}`);
61
+ const tmpPath = path.join(os.tmpdir(), `strapi${crypto.randomBytes(6).toString('hex')}`);
1357
62
  const scope = {
1358
63
  rootPath,
1359
64
  name: path.basename(rootPath),
1360
65
  packageManager: getPkgManager(options),
1361
- database: await getDatabaseInfos(options),
66
+ database: await database.getDatabaseInfos(options),
1362
67
  template: options.template,
1363
68
  templateBranch: options.templateBranch,
1364
69
  templatePath: options.templatePath,
@@ -1371,7 +76,7 @@ async function run(args) {
1371
76
  },
1372
77
  uuid: (process.env.STRAPI_UUID_PREFIX || '') + crypto.randomUUID(),
1373
78
  docker: process.env.DOCKER === 'true',
1374
- deviceId: machineID(),
79
+ deviceId: machineId.machineID(),
1375
80
  tmpPath,
1376
81
  gitInit: true,
1377
82
  devDependencies: {},
@@ -1393,21 +98,21 @@ async function run(args) {
1393
98
  } else if (options.example === false || options.quickstart === true) {
1394
99
  scope.useExample = false;
1395
100
  } else {
1396
- scope.useExample = await example();
101
+ scope.useExample = await prompts.example();
1397
102
  }
1398
103
  if (options.javascript === true) {
1399
104
  scope.useTypescript = false;
1400
105
  } else if (options.typescript === true || options.quickstart) {
1401
106
  scope.useTypescript = true;
1402
107
  } else if (!options.template) {
1403
- scope.useTypescript = await typescript();
108
+ scope.useTypescript = await prompts.typescript();
1404
109
  }
1405
110
  if (options.install === true || options.quickstart) {
1406
111
  scope.installDependencies = true;
1407
112
  } else if (options.install === false) {
1408
113
  scope.installDependencies = false;
1409
114
  } else {
1410
- scope.installDependencies = await installDependencies(scope.packageManager);
115
+ scope.installDependencies = await prompts.installDependencies(scope.packageManager);
1411
116
  }
1412
117
  if (scope.useTypescript) {
1413
118
  scope.devDependencies = {
@@ -1423,20 +128,20 @@ async function run(args) {
1423
128
  } else if (options.gitInit === false) {
1424
129
  scope.gitInit = false;
1425
130
  } else {
1426
- scope.gitInit = await gitInit();
131
+ scope.gitInit = await prompts.gitInit();
1427
132
  }
1428
- addDatabaseDependencies(scope);
133
+ database.addDatabaseDependencies(scope);
1429
134
  try {
1430
- await createStrapi(scope);
135
+ await createStrapi.createStrapi(scope);
1431
136
  } catch (error) {
1432
137
  if (!(error instanceof Error)) {
1433
138
  throw error;
1434
139
  }
1435
- await trackError({
140
+ await usage.trackError({
1436
141
  scope,
1437
142
  error
1438
143
  });
1439
- logger.fatal(error.message);
144
+ logger.logger.fatal(error.message);
1440
145
  }
1441
146
  }
1442
147
  function getPkgManager(options) {
@@ -1459,6 +164,6 @@ function getPkgManager(options) {
1459
164
  return 'npm';
1460
165
  }
1461
166
 
1462
- exports.createStrapi = createStrapi;
167
+ exports.createStrapi = createStrapi.createStrapi;
1463
168
  exports.run = run;
1464
169
  //# sourceMappingURL=index.js.map