create-strapi-app 4.0.0-next.7 → 4.0.1

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.
@@ -1,14 +1,24 @@
1
1
  'use strict';
2
2
 
3
- // FIXME
4
- /* eslint-disable import/extensions */
3
+ const { resolve } = require('path');
5
4
  const commander = require('commander');
6
- const generateNewApp = require('@strapi/generate-new');
5
+ const { checkInstallPath, generateNewApp } = require('@strapi/generate-new');
7
6
  const promptUser = require('./utils/prompt-user');
8
7
  const packageJson = require('./package.json');
9
8
 
10
9
  const program = new commander.Command(packageJson.name);
11
10
 
11
+ const databaseOptions = [
12
+ 'dbclient',
13
+ 'dbhost',
14
+ 'dbport',
15
+ 'dbname',
16
+ 'dbusername',
17
+ 'dbpassword',
18
+ 'dbssl',
19
+ 'dbfile',
20
+ ];
21
+
12
22
  program
13
23
  .version(packageJson.version)
14
24
  .arguments('[directory]')
@@ -35,7 +45,6 @@ program
35
45
  function generateApp(projectName, options) {
36
46
  if (!projectName) {
37
47
  console.error('Please specify the <directory> of your project when using --quickstart');
38
- // eslint-disable-next-line no-process-exit
39
48
  process.exit(1);
40
49
  }
41
50
 
@@ -47,16 +56,37 @@ function generateApp(projectName, options) {
47
56
  }
48
57
 
49
58
  async function initProject(projectName, program) {
59
+ if (projectName) {
60
+ await checkInstallPath(resolve(projectName));
61
+ }
62
+
63
+ const hasDatabaseOptions = databaseOptions.some(opt => program[opt]);
64
+
65
+ if (program.quickstart && hasDatabaseOptions) {
66
+ console.error(
67
+ `The quickstart option is incompatible with the following options: ${databaseOptions.join(
68
+ ', '
69
+ )}`
70
+ );
71
+ process.exit(1);
72
+ }
73
+
74
+ if (hasDatabaseOptions) {
75
+ program.quickstart = false; // Will disable the quickstart question because != 'undefined'
76
+ }
77
+
50
78
  if (program.quickstart) {
51
79
  return generateApp(projectName, program);
52
80
  }
53
81
 
54
- const prompt = await promptUser(projectName, program.template);
82
+ const prompt = await promptUser(projectName, program);
55
83
 
56
84
  const directory = prompt.directory || projectName;
85
+ await checkInstallPath(resolve(directory));
86
+
57
87
  const options = {
58
- template: prompt.template || program.template,
59
- quickstart: prompt.quick,
88
+ template: program.template,
89
+ quickstart: prompt.quick || program.quickstart,
60
90
  };
61
91
 
62
92
  const generateStrapiAppOptions = {
package/package.json CHANGED
@@ -1,9 +1,7 @@
1
1
  {
2
2
  "name": "create-strapi-app",
3
- "version": "4.0.0-next.7",
3
+ "version": "4.0.1",
4
4
  "description": "Generate a new Strapi application.",
5
- "license": "SEE LICENSE IN LICENSE",
6
- "homepage": "https://strapi.io",
7
5
  "keywords": [
8
6
  "create-strapi-app",
9
7
  "create",
@@ -11,36 +9,42 @@
11
9
  "generate",
12
10
  "strapi"
13
11
  ],
14
- "main": "./index.js",
15
- "bin": {
16
- "create-strapi-app": "./index.js"
17
- },
18
- "dependencies": {
19
- "@strapi/generate-new": "4.0.0-next.7",
20
- "chalk": "4.1.1",
21
- "commander": "6.1.0",
22
- "inquirer": "8.1.0",
23
- "js-yaml": "4.1.0",
24
- "node-fetch": "^2.6.1"
12
+ "homepage": "https://strapi.io",
13
+ "bugs": {
14
+ "url": "https://github.com/strapi/strapi/issues"
25
15
  },
26
- "scripts": {
27
- "test": "echo \"no tests yet\""
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git://github.com/strapi/strapi.git"
28
19
  },
20
+ "license": "SEE LICENSE IN LICENSE",
29
21
  "author": {
22
+ "name": "Strapi Solutions SAS",
30
23
  "email": "hi@strapi.io",
31
- "name": "Strapi team",
32
24
  "url": "https://strapi.io"
33
25
  },
34
- "repository": {
35
- "type": "git",
36
- "url": "git://github.com/strapi/strapi.git"
26
+ "maintainers": [
27
+ {
28
+ "name": "Strapi Solutions SAS",
29
+ "email": "hi@strapi.io",
30
+ "url": "https://strapi.io"
31
+ }
32
+ ],
33
+ "main": "./index.js",
34
+ "bin": {
35
+ "create-strapi-app": "./index.js"
37
36
  },
38
- "bugs": {
39
- "url": "https://github.com/strapi/strapi/issues"
37
+ "scripts": {
38
+ "test": "echo \"no tests yet\""
39
+ },
40
+ "dependencies": {
41
+ "@strapi/generate-new": "4.0.1",
42
+ "commander": "6.1.0",
43
+ "inquirer": "8.2.0"
40
44
  },
41
45
  "engines": {
42
46
  "node": ">=12.x.x <=16.x.x",
43
47
  "npm": ">=6.0.0"
44
48
  },
45
- "gitHead": "522d6afd54b68ed3376dd0c807fab6c1315f1931"
49
+ "gitHead": "e2cd01e8c6cbfeba15ad7787e38b6eebcbb92221"
46
50
  }
@@ -1,66 +1,23 @@
1
1
  'use strict';
2
2
 
3
3
  const inquirer = require('inquirer');
4
- const fetch = require('node-fetch');
5
- const yaml = require('js-yaml');
6
4
 
7
5
  /**
8
6
  * @param {string|null} projectName - The name/path of project
9
7
  * @param {string|null} template - The Github repo of the template
10
8
  * @returns Object containting prompt answers
11
9
  */
12
- module.exports = async function promptUser(projectName, template) {
13
- const questions = await getPromptQuestions(projectName, template);
14
- const [initialResponse, templateQuestion] = await Promise.all([
15
- inquirer.prompt(questions),
16
- getTemplateQuestion(),
17
- ]);
18
-
19
- if (initialResponse.useTemplate) {
20
- const updatedResponse = await inquirer.prompt(templateQuestion);
21
- return { ...initialResponse, ...updatedResponse };
22
- }
23
-
24
- return initialResponse;
10
+ module.exports = async function promptUser(projectName, program) {
11
+ const questions = await getPromptQuestions(projectName, program);
12
+ return inquirer.prompt(questions);
25
13
  };
26
14
 
27
15
  /**
28
- *
29
- * @returns Prompt question object
30
- */
31
- async function getTemplateQuestion() {
32
- const content = await getTemplateData();
33
- // Fallback to manual input when fetch fails
34
- if (!content) {
35
- return {
36
- name: 'template',
37
- type: 'input',
38
- message: 'Please provide the GitHub URL for your template:',
39
- };
40
- }
41
-
42
- const choices = content.map(option => {
43
- const name = option.title.replace('Template', '');
44
- return {
45
- name,
46
- value: `https://github.com/${option.repo}`,
47
- };
48
- });
49
-
50
- return {
51
- name: 'template',
52
- type: 'list',
53
- message: `Select a template`,
54
- pageSize: choices.length,
55
- choices,
56
- };
57
- }
58
-
59
- /**
60
- *
16
+ * @param {string|null} projectName - The name of the project
17
+ * @param {string|null} template - The template the project should use
61
18
  * @returns Array of prompt question objects
62
19
  */
63
- async function getPromptQuestions(projectName, template) {
20
+ async function getPromptQuestions(projectName, program) {
64
21
  return [
65
22
  {
66
23
  type: 'input',
@@ -73,6 +30,7 @@ async function getPromptQuestions(projectName, template) {
73
30
  type: 'list',
74
31
  name: 'quick',
75
32
  message: 'Choose your installation type',
33
+ when: !program.quickstart,
76
34
  choices: [
77
35
  {
78
36
  name: 'Quickstart (recommended)',
@@ -84,31 +42,5 @@ async function getPromptQuestions(projectName, template) {
84
42
  },
85
43
  ],
86
44
  },
87
- {
88
- type: 'confirm',
89
- name: 'useTemplate',
90
- when: !template,
91
- message:
92
- 'Would you like to use a template? (Templates are Strapi configurations designed for a specific use case)',
93
- },
94
45
  ];
95
46
  }
96
-
97
- /**
98
- *
99
- * @returns JSON template data
100
- */
101
- async function getTemplateData() {
102
- const response = await fetch(
103
- `https://api.github.com/repos/strapi/community-content/contents/templates/templates.yml`
104
- );
105
- if (!response.ok) {
106
- return null;
107
- }
108
-
109
- const { content } = await response.json();
110
- const buff = Buffer.from(content, 'base64');
111
- const stringified = buff.toString('utf-8');
112
-
113
- return yaml.load(stringified);
114
- }