@strapi/generators 4.2.0-beta.0 → 4.2.0-beta.3
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.
- package/lib/files/js/plugin/admin/src/pluginId.js +2 -2
- package/lib/files/ts/plugin/strapi-server.js +1 -1
- package/lib/files/ts/plugin/tsconfig.json +25 -0
- package/lib/plops/api.js +1 -1
- package/lib/plops/content-type.js +1 -1
- package/lib/plops/controller.js +1 -1
- package/lib/plops/middleware.js +3 -1
- package/lib/plops/plugin.js +27 -6
- package/lib/plops/policy.js +3 -1
- package/lib/plops/service.js +1 -1
- package/lib/plops/utils/__tests__/get-file-path.test.js +25 -0
- package/lib/templates/js/plugin-package.json.hbs +3 -2
- package/lib/templates/ts/plugin-package.json.hbs +8 -0
- package/package.json +4 -4
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@strapi/typescript-utils/lib/configs/server",
|
|
3
|
+
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"outDir": "dist",
|
|
6
|
+
"rootDir": "."
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
"include": [
|
|
10
|
+
// Include the root directory
|
|
11
|
+
"server",
|
|
12
|
+
// Force the JSON files in the src folder to be included
|
|
13
|
+
"server/**/*.json"
|
|
14
|
+
],
|
|
15
|
+
|
|
16
|
+
"exclude": [
|
|
17
|
+
"node_modules/",
|
|
18
|
+
"dist/",
|
|
19
|
+
|
|
20
|
+
// Do not include admin files in the server compilation
|
|
21
|
+
"admin/",
|
|
22
|
+
// Do not include test files
|
|
23
|
+
"**/*.test.ts"
|
|
24
|
+
]
|
|
25
|
+
}
|
package/lib/plops/api.js
CHANGED
|
@@ -49,7 +49,7 @@ module.exports = plop => {
|
|
|
49
49
|
actions(answers) {
|
|
50
50
|
const filePath = answers.isPluginApi && answers.plugin ? 'plugins/{{plugin}}' : 'api/{{id}}';
|
|
51
51
|
const currentDir = process.cwd();
|
|
52
|
-
const language = tsUtils.
|
|
52
|
+
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
53
53
|
|
|
54
54
|
const baseActions = [
|
|
55
55
|
{
|
|
@@ -83,7 +83,7 @@ module.exports = plop => {
|
|
|
83
83
|
|
|
84
84
|
const filePath = getFilePath(answers.destination);
|
|
85
85
|
const currentDir = process.cwd();
|
|
86
|
-
const language = tsUtils.
|
|
86
|
+
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
87
87
|
|
|
88
88
|
const baseActions = [
|
|
89
89
|
{
|
package/lib/plops/controller.js
CHANGED
|
@@ -22,7 +22,7 @@ module.exports = plop => {
|
|
|
22
22
|
actions(answers) {
|
|
23
23
|
const filePath = getFilePath(answers.destination);
|
|
24
24
|
const currentDir = process.cwd();
|
|
25
|
-
const language = tsUtils.
|
|
25
|
+
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
26
26
|
|
|
27
27
|
return [
|
|
28
28
|
{
|
package/lib/plops/middleware.js
CHANGED
|
@@ -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,13 +15,14 @@ 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
|
],
|
|
20
22
|
actions(answers) {
|
|
21
23
|
const filePath = getFilePath(answers.destination);
|
|
22
24
|
const currentDir = process.cwd();
|
|
23
|
-
const language = tsUtils.
|
|
25
|
+
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
24
26
|
|
|
25
27
|
return [
|
|
26
28
|
{
|
package/lib/plops/plugin.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const chalk = require('chalk');
|
|
4
|
-
const
|
|
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;
|
|
@@ -9,12 +12,14 @@ const logInstructions = (pluginName, { language }) => {
|
|
|
9
12
|
.fill('─')
|
|
10
13
|
.join('');
|
|
11
14
|
|
|
15
|
+
const exportInstruction = language === 'js' ? 'module.exports =' : 'export default';
|
|
16
|
+
|
|
12
17
|
return `
|
|
13
18
|
You can now enable your plugin by adding the following in ${chalk.yellow(
|
|
14
19
|
`./config/plugins.${language}`
|
|
15
20
|
)}
|
|
16
21
|
${separator}
|
|
17
|
-
|
|
22
|
+
${exportInstruction} {
|
|
18
23
|
${chalk.gray('// ...')}
|
|
19
24
|
${chalk.green(`'${pluginName}'`)}: {
|
|
20
25
|
enabled: ${chalk.yellow(true)},
|
|
@@ -35,13 +40,29 @@ module.exports = plop => {
|
|
|
35
40
|
type: 'input',
|
|
36
41
|
name: 'pluginName',
|
|
37
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',
|
|
38
51
|
},
|
|
39
52
|
],
|
|
40
53
|
actions(answers) {
|
|
41
|
-
const
|
|
42
|
-
const language =
|
|
54
|
+
const isTypescript = answers.language === 'Typescript';
|
|
55
|
+
const language = isTypescript ? 'ts' : 'js';
|
|
56
|
+
const projectLanguage = isUsingTypeScriptSync(process.cwd()) ? 'ts' : 'js';
|
|
43
57
|
|
|
44
|
-
|
|
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
|
+
}
|
|
45
66
|
|
|
46
67
|
return [
|
|
47
68
|
{
|
|
@@ -60,7 +81,7 @@ module.exports = plop => {
|
|
|
60
81
|
path: 'plugins/{{ pluginName }}/package.json',
|
|
61
82
|
templateFile: `templates/${language}/plugin-package.json.hbs`,
|
|
62
83
|
},
|
|
63
|
-
() => plop.renderString(logInstructions(answers.pluginName, { language })),
|
|
84
|
+
() => plop.renderString(logInstructions(answers.pluginName, { language: projectLanguage })),
|
|
64
85
|
];
|
|
65
86
|
},
|
|
66
87
|
});
|
package/lib/plops/policy.js
CHANGED
|
@@ -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,13 +15,14 @@ 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
|
],
|
|
20
22
|
actions(answers) {
|
|
21
23
|
const filePath = getFilePath(answers.destination);
|
|
22
24
|
const currentDir = process.cwd();
|
|
23
|
-
const language = tsUtils.
|
|
25
|
+
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
24
26
|
|
|
25
27
|
return [
|
|
26
28
|
{
|
package/lib/plops/service.js
CHANGED
|
@@ -20,7 +20,7 @@ module.exports = plop => {
|
|
|
20
20
|
actions(answers) {
|
|
21
21
|
const filePath = getFilePath(answers.destination);
|
|
22
22
|
const currentDir = process.cwd();
|
|
23
|
-
const language = tsUtils.
|
|
23
|
+
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
24
24
|
|
|
25
25
|
return [
|
|
26
26
|
{
|
|
@@ -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": {
|
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
"kind": "plugin"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"typescript": "4.6.3",
|
|
13
|
+
"@strapi/strapi": "4.1.8"
|
|
14
|
+
},
|
|
11
15
|
"author": {
|
|
12
16
|
"name": "A Strapi developer"
|
|
13
17
|
},
|
|
@@ -20,5 +24,9 @@
|
|
|
20
24
|
"node": ">=12.x.x <=16.x.x",
|
|
21
25
|
"npm": ">=6.0.0"
|
|
22
26
|
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"develop": "tsc -w",
|
|
29
|
+
"build": "tsc"
|
|
30
|
+
},
|
|
23
31
|
"license": "MIT"
|
|
24
32
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/generators",
|
|
3
|
-
"version": "4.2.0-beta.
|
|
3
|
+
"version": "4.2.0-beta.3",
|
|
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.
|
|
34
|
-
"@strapi/utils": "4.2.0-beta.
|
|
33
|
+
"@strapi/typescript-utils": "4.2.0-beta.3",
|
|
34
|
+
"@strapi/utils": "4.2.0-beta.3",
|
|
35
35
|
"chalk": "4.1.2",
|
|
36
36
|
"fs-extra": "10.0.0",
|
|
37
37
|
"node-plop": "0.26.3",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"node": ">=12.22.0 <=16.x.x",
|
|
43
43
|
"npm": ">=6.0.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "c4addbad6ecbc8ef7633bbba3806f3b0a2ae5f49"
|
|
46
46
|
}
|