@strapi/generators 4.2.0-beta.1 → 4.2.0-beta.4

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.
@@ -3,6 +3,7 @@
3
3
  const tsUtils = require('@strapi/typescript-utils');
4
4
 
5
5
  const getDestinationPrompts = require('./prompts/get-destination-prompts');
6
+ const validateInput = require('./utils/validate-input');
6
7
  const getFilePath = require('./utils/get-file-path');
7
8
 
8
9
  module.exports = plop => {
@@ -14,6 +15,7 @@ module.exports = plop => {
14
15
  type: 'input',
15
16
  name: 'name',
16
17
  message: 'Middleware name',
18
+ validate: input => validateInput(input),
17
19
  },
18
20
  ...getDestinationPrompts('middleware', plop.getDestBasePath(), { rootFolder: true }),
19
21
  ],
@@ -1,7 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  const chalk = require('chalk');
4
- const tsUtils = require('@strapi/typescript-utils');
4
+ const { isUsingTypeScriptSync } = require('@strapi/typescript-utils');
5
+ const { isKebabCase, toKebabCase } = require('@strapi/utils');
6
+
7
+ const validateInput = require('./utils/validate-input');
5
8
 
6
9
  const logInstructions = (pluginName, { language }) => {
7
10
  const maxLength = ` resolve: './src/plugins/${pluginName}'`.length;
@@ -37,13 +40,29 @@ module.exports = plop => {
37
40
  type: 'input',
38
41
  name: 'pluginName',
39
42
  message: 'Plugin name',
43
+ validate: input => validateInput(input),
44
+ },
45
+ {
46
+ type: 'list',
47
+ name: 'language',
48
+ message: 'Choose your preferred language',
49
+ choices: ['Javascript', 'Typescript'],
50
+ default: 'Javascript',
40
51
  },
41
52
  ],
42
53
  actions(answers) {
43
- const currentDir = process.cwd();
44
- const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
54
+ const isTypescript = answers.language === 'Typescript';
55
+ const language = isTypescript ? 'ts' : 'js';
56
+ const projectLanguage = isUsingTypeScriptSync(process.cwd()) ? 'ts' : 'js';
45
57
 
46
- // TODO: Adds tsconfig & build command for TS plugins?
58
+ if (!isKebabCase(answers.pluginName)) {
59
+ answers.pluginName = toKebabCase(answers.pluginName);
60
+ console.log(
61
+ chalk.yellow(
62
+ `Strapi only supports kebab-cased names for plugins.\nYour plugin has been automatically renamed to "${answers.pluginName}".`
63
+ )
64
+ );
65
+ }
47
66
 
48
67
  return [
49
68
  {
@@ -62,7 +81,7 @@ module.exports = plop => {
62
81
  path: 'plugins/{{ pluginName }}/package.json',
63
82
  templateFile: `templates/${language}/plugin-package.json.hbs`,
64
83
  },
65
- () => plop.renderString(logInstructions(answers.pluginName, { language })),
84
+ () => plop.renderString(logInstructions(answers.pluginName, { language: projectLanguage })),
66
85
  ];
67
86
  },
68
87
  });
@@ -3,6 +3,7 @@
3
3
  const tsUtils = require('@strapi/typescript-utils');
4
4
 
5
5
  const getDestinationPrompts = require('./prompts/get-destination-prompts');
6
+ const validateInput = require('./utils/validate-input');
6
7
  const getFilePath = require('./utils/get-file-path');
7
8
 
8
9
  module.exports = plop => {
@@ -14,6 +15,7 @@ module.exports = plop => {
14
15
  type: 'input',
15
16
  name: 'id',
16
17
  message: 'Policy name',
18
+ validate: input => validateInput(input),
17
19
  },
18
20
  ...getDestinationPrompts('policy', plop.getDestBasePath(), { rootFolder: true }),
19
21
  ],
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ const getFilePath = require('../get-file-path');
4
+
5
+ describe('Get-File-Path util', () => {
6
+ test('with destination set as api', () => {
7
+ const filePath = getFilePath('api');
8
+ expect(filePath).toBe(`api/{{ api }}`);
9
+ });
10
+
11
+ test('with destination set as plugin', () => {
12
+ const filePath = getFilePath('plugin');
13
+ expect(filePath).toBe(`plugins/{{ plugin }}/server`);
14
+ });
15
+
16
+ test('with destination set as root', () => {
17
+ const filePath = getFilePath('root');
18
+ expect(filePath).toBe(`./`);
19
+ });
20
+
21
+ test('with empty destination string', () => {
22
+ const filePath = getFilePath('');
23
+ expect(filePath).toBe(`api/{{ id }}`);
24
+ });
25
+ });
@@ -4,8 +4,9 @@
4
4
  "description": "This is the description of the plugin.",
5
5
  "strapi": {
6
6
  "name": "{{ pluginName }}",
7
- "description": "Description of {{ pluginName }} plugin",
8
- "kind": "plugin"
7
+ "description": "Description of {{titleCase pluginName }} plugin",
8
+ "kind": "plugin",
9
+ "displayName": "{{titleCase pluginName }}"
9
10
  },
10
11
  "dependencies": {},
11
12
  "author": {
@@ -17,7 +18,7 @@
17
18
  }
18
19
  ],
19
20
  "engines": {
20
- "node": ">=12.x.x <=16.x.x",
21
+ "node": ">=14.19.1 <=16.x.x",
21
22
  "npm": ">=6.0.0"
22
23
  },
23
24
  "license": "MIT"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/generators",
3
- "version": "4.2.0-beta.1",
3
+ "version": "4.2.0-beta.4",
4
4
  "description": "Interactive API generator.",
5
5
  "keywords": [
6
6
  "strapi",
@@ -30,8 +30,8 @@
30
30
  "main": "lib/index.js",
31
31
  "dependencies": {
32
32
  "@sindresorhus/slugify": "1.1.0",
33
- "@strapi/typescript-utils": "4.2.0-beta.1",
34
- "@strapi/utils": "4.2.0-beta.1",
33
+ "@strapi/typescript-utils": "4.2.0-beta.4",
34
+ "@strapi/utils": "4.2.0-beta.4",
35
35
  "chalk": "4.1.2",
36
36
  "fs-extra": "10.0.0",
37
37
  "node-plop": "0.26.3",
@@ -39,8 +39,8 @@
39
39
  "pluralize": "8.0.0"
40
40
  },
41
41
  "engines": {
42
- "node": ">=12.22.0 <=16.x.x",
42
+ "node": ">=14.19.1 <=16.x.x",
43
43
  "npm": ">=6.0.0"
44
44
  },
45
- "gitHead": "4fa2804f35e15ed72dfd309fb5bb1c4dba18932f"
45
+ "gitHead": "5caff35a30e33b7a660eb946299f9e3d2d35b2b8"
46
46
  }