@strapi/generators 4.0.0-next.9 → 4.0.0
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/plugin/admin/src/components/PluginIcon/index.js +12 -0
- package/lib/files/plugin/admin/src/index.js +2 -6
- package/lib/files/plugin/server/bootstrap.js +5 -0
- package/lib/files/plugin/server/config/index.js +6 -0
- package/lib/files/plugin/server/controllers/index.js +7 -0
- package/lib/files/plugin/server/controllers/my-controller.js.hbs +10 -0
- package/lib/files/plugin/server/destroy.js +5 -0
- package/lib/files/plugin/server/index.js +22 -0
- package/lib/files/plugin/server/register.js +5 -0
- package/lib/files/plugin/server/routes/index.js +10 -0
- package/lib/files/plugin/server/services/index.js +7 -0
- package/lib/files/plugin/server/services/my-service.js +7 -0
- package/lib/files/plugin/strapi-admin.js +3 -0
- package/lib/files/plugin/strapi-server.js +3 -0
- package/lib/index.js +5 -5
- package/lib/plopfile.js +4 -2
- package/lib/plops/api.js +4 -35
- package/lib/plops/content-type.js +145 -0
- package/lib/plops/controller.js +3 -3
- package/lib/plops/middleware.js +36 -0
- package/lib/plops/plugin.js +31 -22
- package/lib/plops/policy.js +4 -4
- package/lib/plops/prompts/bootstrap-api-prompts.js +10 -0
- package/lib/plops/prompts/ct-names-prompts.js +44 -0
- package/lib/plops/prompts/draft-and-publish-prompts.js +10 -0
- package/lib/plops/prompts/get-attributes-prompts.js +102 -0
- package/lib/plops/{utils → prompts}/get-destination-prompts.js +4 -4
- package/lib/plops/prompts/kind-prompts.js +17 -0
- package/lib/plops/service.js +3 -3
- package/lib/plops/utils/get-file-path.js +3 -3
- package/lib/plops/utils/validate-input.js +1 -1
- package/lib/templates/README.md.hbs +2 -2
- package/lib/templates/collection-type-routes.js.hbs +5 -0
- package/lib/templates/content-type.schema.json.hbs +15 -0
- package/lib/templates/core-controller.js.hbs +9 -0
- package/lib/templates/core-router.js.hbs +9 -0
- package/lib/templates/core-service.js.hbs +9 -0
- package/lib/templates/middleware.js.hbs +14 -0
- package/lib/templates/plugin-package.json.hbs +6 -10
- package/lib/templates/policy.js.hbs +12 -4
- package/lib/templates/service.js.hbs +1 -1
- package/lib/templates/single-route.js.hbs +13 -0
- package/lib/templates/single-type-routes.js.hbs +4 -1
- package/package.json +10 -6
- package/lib/plops/model.js +0 -174
- package/lib/templates/model.schema.json.hbs +0 -16
- package/lib/templates/plugin-routes.json.hbs +0 -12
|
@@ -2,16 +2,15 @@ import { prefixPluginTranslations } from '@strapi/helper-plugin';
|
|
|
2
2
|
import pluginPkg from '../../package.json';
|
|
3
3
|
import pluginId from './pluginId';
|
|
4
4
|
import Initializer from './components/Initializer';
|
|
5
|
+
import PluginIcon from './components/PluginIcon';
|
|
5
6
|
|
|
6
|
-
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
|
|
7
|
-
const icon = pluginPkg.strapi.icon;
|
|
8
7
|
const name = pluginPkg.strapi.name;
|
|
9
8
|
|
|
10
9
|
export default {
|
|
11
10
|
register(app) {
|
|
12
11
|
app.addMenuLink({
|
|
13
12
|
to: `/plugins/${pluginId}`,
|
|
14
|
-
icon,
|
|
13
|
+
icon: PluginIcon,
|
|
15
14
|
intlLabel: {
|
|
16
15
|
id: `${pluginId}.plugin.name`,
|
|
17
16
|
defaultMessage: name,
|
|
@@ -30,12 +29,9 @@ export default {
|
|
|
30
29
|
],
|
|
31
30
|
});
|
|
32
31
|
app.registerPlugin({
|
|
33
|
-
description: pluginDescription,
|
|
34
|
-
icon,
|
|
35
32
|
id: pluginId,
|
|
36
33
|
initializer: Initializer,
|
|
37
34
|
isReady: false,
|
|
38
|
-
isRequired: pluginPkg.strapi.required || false,
|
|
39
35
|
name,
|
|
40
36
|
});
|
|
41
37
|
},
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const register = require('./register');
|
|
4
|
+
const bootstrap = require('./bootstrap');
|
|
5
|
+
const destroy = require('./destroy');
|
|
6
|
+
const config = require('./config');
|
|
7
|
+
const controllers = require('./controllers');
|
|
8
|
+
const routes = require('./routes');
|
|
9
|
+
const services = require('./services');
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
register,
|
|
13
|
+
bootstrap,
|
|
14
|
+
destroy,
|
|
15
|
+
config,
|
|
16
|
+
controllers,
|
|
17
|
+
routes,
|
|
18
|
+
services,
|
|
19
|
+
contentTypes: {},
|
|
20
|
+
policies: {},
|
|
21
|
+
middlewares: {},
|
|
22
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -9,7 +9,7 @@ const nodePlop = require('node-plop');
|
|
|
9
9
|
*/
|
|
10
10
|
const runCLI = () => {
|
|
11
11
|
Plop.launch({ configPath: join(__dirname, 'plopfile.js') }, env =>
|
|
12
|
-
run({ ...env, dest: process.cwd() }, undefined, true)
|
|
12
|
+
run({ ...env, dest: join(process.cwd(), 'src') }, undefined, true)
|
|
13
13
|
);
|
|
14
14
|
};
|
|
15
15
|
|
|
@@ -21,13 +21,13 @@ const runCLI = () => {
|
|
|
21
21
|
* @param {string} plopOptions.dir base path for plop to generate the files from
|
|
22
22
|
*/
|
|
23
23
|
const generate = async (generatorName, options, { dir = process.cwd() } = {}) => {
|
|
24
|
-
const plop = nodePlop(join(__dirname, 'plopfile.js'), { destBasePath: dir });
|
|
24
|
+
const plop = nodePlop(join(__dirname, 'plopfile.js'), { destBasePath: join(dir, 'src') });
|
|
25
25
|
|
|
26
26
|
const generator = plop.getGenerator(generatorName);
|
|
27
27
|
await generator.runActions(options, {
|
|
28
|
-
onSuccess
|
|
29
|
-
onFailure
|
|
30
|
-
onComment
|
|
28
|
+
onSuccess() {},
|
|
29
|
+
onFailure() {},
|
|
30
|
+
onComment() {},
|
|
31
31
|
});
|
|
32
32
|
};
|
|
33
33
|
|
package/lib/plopfile.js
CHANGED
|
@@ -4,9 +4,10 @@ const pluralize = require('pluralize');
|
|
|
4
4
|
|
|
5
5
|
const generateApi = require('./plops/api');
|
|
6
6
|
const generateController = require('./plops/controller');
|
|
7
|
-
const
|
|
7
|
+
const generateContentType = require('./plops/content-type');
|
|
8
8
|
const generatePlugin = require('./plops/plugin');
|
|
9
9
|
const generatePolicy = require('./plops/policy');
|
|
10
|
+
const generateMiddleware = require('./plops/middleware');
|
|
10
11
|
const generateService = require('./plops/service');
|
|
11
12
|
|
|
12
13
|
module.exports = plop => {
|
|
@@ -17,8 +18,9 @@ module.exports = plop => {
|
|
|
17
18
|
// Generators
|
|
18
19
|
generateApi(plop);
|
|
19
20
|
generateController(plop);
|
|
20
|
-
|
|
21
|
+
generateContentType(plop);
|
|
21
22
|
generatePlugin(plop);
|
|
22
23
|
generatePolicy(plop);
|
|
24
|
+
generateMiddleware(plop);
|
|
23
25
|
generateService(plop);
|
|
24
26
|
};
|
package/lib/plops/api.js
CHANGED
|
@@ -25,7 +25,7 @@ module.exports = plop => {
|
|
|
25
25
|
type: 'list',
|
|
26
26
|
name: 'plugin',
|
|
27
27
|
message: 'Plugin name',
|
|
28
|
-
|
|
28
|
+
async choices() {
|
|
29
29
|
const pluginsPath = join(plop.getDestBasePath(), 'plugins');
|
|
30
30
|
const exists = await fs.pathExists(pluginsPath);
|
|
31
31
|
|
|
@@ -43,30 +43,9 @@ module.exports = plop => {
|
|
|
43
43
|
return pluginsDirContent;
|
|
44
44
|
},
|
|
45
45
|
},
|
|
46
|
-
{
|
|
47
|
-
type: 'list',
|
|
48
|
-
name: 'kind',
|
|
49
|
-
message: 'Please choose the model type',
|
|
50
|
-
default: 'collectionType',
|
|
51
|
-
choices: [
|
|
52
|
-
{ name: 'Collection Type', value: 'collectionType' },
|
|
53
|
-
{ name: 'Singe Type', value: 'singleType' },
|
|
54
|
-
],
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
type: 'confirm',
|
|
58
|
-
name: 'useDraftAndPublish',
|
|
59
|
-
default: false,
|
|
60
|
-
message: 'Use draft and publish?',
|
|
61
|
-
},
|
|
62
46
|
],
|
|
63
|
-
actions
|
|
64
|
-
|
|
65
|
-
if (answers.isPluginApi && answers.plugin) {
|
|
66
|
-
filePath = `plugins/{{plugin}}`;
|
|
67
|
-
} else {
|
|
68
|
-
filePath = `api/{{id}}`;
|
|
69
|
-
}
|
|
47
|
+
actions(answers) {
|
|
48
|
+
const filePath = answers.isPluginApi && answers.plugin ? 'plugins/{{plugin}}' : 'api/{{id}}';
|
|
70
49
|
|
|
71
50
|
const baseActions = [
|
|
72
51
|
{
|
|
@@ -74,11 +53,6 @@ module.exports = plop => {
|
|
|
74
53
|
path: `${filePath}/controllers/{{id}}.js`,
|
|
75
54
|
templateFile: 'templates/controller.js.hbs',
|
|
76
55
|
},
|
|
77
|
-
{
|
|
78
|
-
type: 'add',
|
|
79
|
-
path: `${filePath}/content-types/{{id}}/schema.json`,
|
|
80
|
-
templateFile: 'templates/model.schema.json.hbs',
|
|
81
|
-
},
|
|
82
56
|
{
|
|
83
57
|
type: 'add',
|
|
84
58
|
path: `${filePath}/services/{{id}}.js`,
|
|
@@ -90,16 +64,11 @@ module.exports = plop => {
|
|
|
90
64
|
return baseActions;
|
|
91
65
|
}
|
|
92
66
|
|
|
93
|
-
const routeType =
|
|
94
|
-
answers.kind === 'singleType'
|
|
95
|
-
? 'single-type-routes.js.hbs'
|
|
96
|
-
: 'collection-type-routes.js.hbs';
|
|
97
|
-
|
|
98
67
|
return [
|
|
99
68
|
{
|
|
100
69
|
type: 'add',
|
|
101
70
|
path: `${filePath}/routes/{{id}}.js`,
|
|
102
|
-
templateFile: `templates
|
|
71
|
+
templateFile: `templates/single-route.js.hbs`,
|
|
103
72
|
},
|
|
104
73
|
...baseActions,
|
|
105
74
|
];
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { join } = require('path');
|
|
4
|
+
const slugify = require('@sindresorhus/slugify');
|
|
5
|
+
const fs = require('fs-extra');
|
|
6
|
+
const { isKebabCase } = require('@strapi/utils');
|
|
7
|
+
|
|
8
|
+
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
|
9
|
+
const getFilePath = require('./utils/get-file-path');
|
|
10
|
+
const ctNamesPrompts = require('./prompts/ct-names-prompts');
|
|
11
|
+
const kindPrompts = require('./prompts/kind-prompts');
|
|
12
|
+
const draftAndPublishPrompts = require('./prompts/draft-and-publish-prompts');
|
|
13
|
+
const getAttributesPrompts = require('./prompts/get-attributes-prompts');
|
|
14
|
+
const bootstrapApiPrompts = require('./prompts/bootstrap-api-prompts');
|
|
15
|
+
|
|
16
|
+
module.exports = plop => {
|
|
17
|
+
// Model generator
|
|
18
|
+
plop.setGenerator('content-type', {
|
|
19
|
+
description: 'Generate a content type for an API',
|
|
20
|
+
async prompts(inquirer) {
|
|
21
|
+
const config = await inquirer.prompt([
|
|
22
|
+
...ctNamesPrompts,
|
|
23
|
+
...kindPrompts,
|
|
24
|
+
...draftAndPublishPrompts,
|
|
25
|
+
]);
|
|
26
|
+
const attributes = await getAttributesPrompts(inquirer);
|
|
27
|
+
|
|
28
|
+
const api = await inquirer.prompt([
|
|
29
|
+
...getDestinationPrompts('model', plop.getDestBasePath()),
|
|
30
|
+
{
|
|
31
|
+
when: answers => answers.destination === 'new',
|
|
32
|
+
type: 'input',
|
|
33
|
+
name: 'id',
|
|
34
|
+
default: config.singularName,
|
|
35
|
+
message: 'Name of the new API?',
|
|
36
|
+
async validate(input) {
|
|
37
|
+
if (!isKebabCase(input)) {
|
|
38
|
+
return 'Value must be in kebab-case';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const apiPath = join(plop.getDestBasePath(), 'api');
|
|
42
|
+
const exists = await fs.pathExists(apiPath);
|
|
43
|
+
|
|
44
|
+
if (!exists) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const apiDir = await fs.readdir(apiPath, { withFileTypes: true });
|
|
49
|
+
const apiDirContent = apiDir.filter(fd => fd.isDirectory());
|
|
50
|
+
|
|
51
|
+
if (apiDirContent.findIndex(api => api.name === input) !== -1) {
|
|
52
|
+
throw new Error('This name is already taken.');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return true;
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
...bootstrapApiPrompts,
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
...config,
|
|
63
|
+
...api,
|
|
64
|
+
attributes,
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
actions(answers) {
|
|
68
|
+
const attributes = answers.attributes.reduce((object, answer) => {
|
|
69
|
+
const val = { type: answer.attributeType };
|
|
70
|
+
|
|
71
|
+
if (answer.attributeType === 'enumeration') {
|
|
72
|
+
val.enum = answer.enum.split(',').map(item => item.trim());
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (answer.attributeType === 'media') {
|
|
76
|
+
val.allowedTypes = ['images', 'files', 'videos'];
|
|
77
|
+
val.multiple = answer.multiple;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return Object.assign(object, { [answer.attributeName]: val }, {});
|
|
81
|
+
}, {});
|
|
82
|
+
|
|
83
|
+
const filePath = getFilePath(answers.destination);
|
|
84
|
+
|
|
85
|
+
const baseActions = [
|
|
86
|
+
{
|
|
87
|
+
type: 'add',
|
|
88
|
+
path: `${filePath}/content-types/{{ singularName }}/schema.json`,
|
|
89
|
+
templateFile: 'templates/content-type.schema.json.hbs',
|
|
90
|
+
data: {
|
|
91
|
+
collectionName: slugify(answers.pluralName, { separator: '_' }),
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
if (attributes.lenght > 0) {
|
|
97
|
+
baseActions.push({
|
|
98
|
+
type: 'modify',
|
|
99
|
+
path: `${filePath}/content-types/{{ singularName }}/schema.json`,
|
|
100
|
+
transform(template) {
|
|
101
|
+
const parsedTemplate = JSON.parse(template);
|
|
102
|
+
parsedTemplate.attributes = attributes;
|
|
103
|
+
return JSON.stringify(parsedTemplate, null, 2);
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (answers.bootstrapApi) {
|
|
109
|
+
const { singularName } = answers;
|
|
110
|
+
|
|
111
|
+
let uid;
|
|
112
|
+
if (answers.destination === 'new') {
|
|
113
|
+
uid = `api::${answers.id}.${singularName}`;
|
|
114
|
+
} else if (answers.api) {
|
|
115
|
+
uid = `api::${answers.api}.${singularName}`;
|
|
116
|
+
} else if (answers.plugin) {
|
|
117
|
+
uid = `plugin::${answers.plugin}.${singularName}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
baseActions.push(
|
|
121
|
+
{
|
|
122
|
+
type: 'add',
|
|
123
|
+
path: `${filePath}/controllers/{{singularName}}.js`,
|
|
124
|
+
templateFile: 'templates/core-controller.js.hbs',
|
|
125
|
+
data: { uid },
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
type: 'add',
|
|
129
|
+
path: `${filePath}/services/{{singularName}}.js`,
|
|
130
|
+
templateFile: 'templates/core-service.js.hbs',
|
|
131
|
+
data: { uid },
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
type: 'add',
|
|
135
|
+
path: `${filePath}/routes/{{singularName}}.js`,
|
|
136
|
+
templateFile: `templates/core-router.js.hbs`,
|
|
137
|
+
data: { uid },
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return baseActions;
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
};
|
package/lib/plops/controller.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const getDestinationPrompts = require('./
|
|
3
|
+
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
|
4
4
|
const getFilePath = require('./utils/get-file-path');
|
|
5
5
|
const validateInput = require('./utils/validate-input');
|
|
6
6
|
|
|
@@ -17,13 +17,13 @@ module.exports = plop => {
|
|
|
17
17
|
},
|
|
18
18
|
...getDestinationPrompts('controller', plop.getDestBasePath()),
|
|
19
19
|
],
|
|
20
|
-
actions
|
|
20
|
+
actions(answers) {
|
|
21
21
|
const filePath = getFilePath(answers.destination);
|
|
22
22
|
|
|
23
23
|
return [
|
|
24
24
|
{
|
|
25
25
|
type: 'add',
|
|
26
|
-
path: `${filePath}/controllers/{{id}}.js`,
|
|
26
|
+
path: `${filePath}/controllers/{{ id }}.js`,
|
|
27
27
|
templateFile: 'templates/controller.js.hbs',
|
|
28
28
|
},
|
|
29
29
|
];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
|
4
|
+
|
|
5
|
+
module.exports = plop => {
|
|
6
|
+
// middleware generator
|
|
7
|
+
plop.setGenerator('middleware', {
|
|
8
|
+
description: 'Generate a middleware for an API',
|
|
9
|
+
prompts: [
|
|
10
|
+
{
|
|
11
|
+
type: 'input',
|
|
12
|
+
name: 'name',
|
|
13
|
+
message: 'Middleware name',
|
|
14
|
+
},
|
|
15
|
+
...getDestinationPrompts('middleware', plop.getDestBasePath(), { rootFolder: true }),
|
|
16
|
+
],
|
|
17
|
+
actions(answers) {
|
|
18
|
+
let filePath;
|
|
19
|
+
if (answers.destination === 'api') {
|
|
20
|
+
filePath = `api/{{ api }}`;
|
|
21
|
+
} else if (answers.destination === 'plugin') {
|
|
22
|
+
filePath = `plugins/{{ plugin }}`;
|
|
23
|
+
} else {
|
|
24
|
+
filePath = `./`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return [
|
|
28
|
+
{
|
|
29
|
+
type: 'add',
|
|
30
|
+
path: `${filePath}/middlewares/{{ name }}.js`,
|
|
31
|
+
templateFile: 'templates/middleware.js.hbs',
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
};
|
package/lib/plops/plugin.js
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
|
|
5
|
+
const logInstructions = pluginName => {
|
|
6
|
+
const maxLength = ` resolve: './src/plugins/${pluginName}'`.length;
|
|
7
|
+
const separator = Array(maxLength)
|
|
8
|
+
.fill('─')
|
|
9
|
+
.join('');
|
|
10
|
+
|
|
11
|
+
return `
|
|
12
|
+
You can now enable your plugin by adding the following in ${chalk.yellow('./config/plugins.js')}.
|
|
13
|
+
${separator}
|
|
14
|
+
module.exports = {
|
|
15
|
+
${chalk.gray('// ...')}
|
|
16
|
+
${chalk.green(`'${pluginName}'`)}: {
|
|
17
|
+
enabled: ${chalk.yellow(true)},
|
|
18
|
+
resolve: ${chalk.yellow(`'./src/plugins/${pluginName}'`)}
|
|
19
|
+
},
|
|
20
|
+
${chalk.gray('// ...')}
|
|
21
|
+
}
|
|
22
|
+
${separator}
|
|
23
|
+
`;
|
|
24
|
+
};
|
|
25
|
+
|
|
3
26
|
module.exports = plop => {
|
|
4
27
|
// Plugin generator
|
|
5
28
|
plop.setGenerator('plugin', {
|
|
@@ -7,43 +30,29 @@ module.exports = plop => {
|
|
|
7
30
|
prompts: [
|
|
8
31
|
{
|
|
9
32
|
type: 'input',
|
|
10
|
-
name: '
|
|
33
|
+
name: 'pluginName',
|
|
11
34
|
message: 'Plugin name',
|
|
12
35
|
},
|
|
13
36
|
],
|
|
14
|
-
actions
|
|
37
|
+
actions(answers) {
|
|
15
38
|
return [
|
|
16
39
|
{
|
|
17
40
|
type: 'addMany',
|
|
18
|
-
destination: 'plugins/{{
|
|
19
|
-
base: 'files/plugin
|
|
20
|
-
templateFiles: 'files/plugin
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
type: 'add',
|
|
24
|
-
path: 'plugins/{{id}}/services/{{id}}.js',
|
|
25
|
-
templateFile: 'templates/service.js.hbs',
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
type: 'add',
|
|
29
|
-
path: 'plugins/{{id}}/controllers/{{id}}.js',
|
|
30
|
-
templateFile: 'templates/controller.js.hbs',
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
type: 'add',
|
|
34
|
-
path: 'plugins/{{id}}/config/routes.json',
|
|
35
|
-
templateFile: 'templates/plugin-routes.json.hbs',
|
|
41
|
+
destination: 'plugins/{{ pluginName }}',
|
|
42
|
+
base: 'files/plugin',
|
|
43
|
+
templateFiles: 'files/plugin/**',
|
|
36
44
|
},
|
|
37
45
|
{
|
|
38
46
|
type: 'add',
|
|
39
|
-
path: 'plugins/{{
|
|
47
|
+
path: 'plugins/{{ pluginName }}/README.md',
|
|
40
48
|
templateFile: 'templates/README.md.hbs',
|
|
41
49
|
},
|
|
42
50
|
{
|
|
43
51
|
type: 'add',
|
|
44
|
-
path: 'plugins/{{
|
|
52
|
+
path: 'plugins/{{ pluginName }}/package.json',
|
|
45
53
|
templateFile: 'templates/plugin-package.json.hbs',
|
|
46
54
|
},
|
|
55
|
+
() => plop.renderString(logInstructions(answers.pluginName)),
|
|
47
56
|
];
|
|
48
57
|
},
|
|
49
58
|
});
|
package/lib/plops/policy.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const getDestinationPrompts = require('./
|
|
3
|
+
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
|
4
4
|
|
|
5
5
|
module.exports = plop => {
|
|
6
6
|
// Policy generator
|
|
@@ -12,9 +12,9 @@ module.exports = plop => {
|
|
|
12
12
|
name: 'id',
|
|
13
13
|
message: 'Policy name',
|
|
14
14
|
},
|
|
15
|
-
...getDestinationPrompts('policy', plop.getDestBasePath()),
|
|
15
|
+
...getDestinationPrompts('policy', plop.getDestBasePath(), { rootFolder: true }),
|
|
16
16
|
],
|
|
17
|
-
actions
|
|
17
|
+
actions(answers) {
|
|
18
18
|
let filePath;
|
|
19
19
|
if (answers.destination === 'api') {
|
|
20
20
|
filePath = `api/{{api}}`;
|
|
@@ -27,7 +27,7 @@ module.exports = plop => {
|
|
|
27
27
|
return [
|
|
28
28
|
{
|
|
29
29
|
type: 'add',
|
|
30
|
-
path: `${filePath}/
|
|
30
|
+
path: `${filePath}/policies/{{id}}.js`,
|
|
31
31
|
templateFile: 'templates/policy.js.hbs',
|
|
32
32
|
},
|
|
33
33
|
];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const pluralize = require('pluralize');
|
|
4
|
+
const slugify = require('@sindresorhus/slugify');
|
|
5
|
+
const { isKebabCase } = require('@strapi/utils');
|
|
6
|
+
|
|
7
|
+
module.exports = [
|
|
8
|
+
{
|
|
9
|
+
type: 'input',
|
|
10
|
+
name: 'displayName',
|
|
11
|
+
message: 'Content type display name',
|
|
12
|
+
validate: input => !!input,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
type: 'input',
|
|
16
|
+
name: 'singularName',
|
|
17
|
+
message: 'Content type singular name',
|
|
18
|
+
default: answers => slugify(answers.displayName),
|
|
19
|
+
validate(input) {
|
|
20
|
+
if (!isKebabCase(input)) {
|
|
21
|
+
return 'Value must be in kebab-case';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return true;
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: 'input',
|
|
29
|
+
name: 'pluralName',
|
|
30
|
+
message: 'Content type plural name',
|
|
31
|
+
default: answers => pluralize(answers.singularName),
|
|
32
|
+
validate(input, answers) {
|
|
33
|
+
if (answers.singularName === input) {
|
|
34
|
+
return 'Singular and plural names cannot be the same';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!isKebabCase(input)) {
|
|
38
|
+
return 'Value must be in kebab-case';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return true;
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
];
|