@strapi/generators 4.0.0-beta.2 → 4.0.0-beta.20
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/controllers/my-controller.js.hbs +1 -1
- package/lib/plopfile.js +2 -0
- package/lib/plops/api.js +2 -33
- package/lib/plops/content-type.js +99 -128
- package/lib/plops/controller.js +2 -2
- package/lib/plops/middleware.js +36 -0
- package/lib/plops/policy.js +2 -2
- 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 +2 -2
- package/lib/plops/prompts/kind-prompts.js +17 -0
- package/lib/plops/service.js +2 -2
- package/lib/plops/utils/get-file-path.js +3 -3
- package/lib/plops/utils/validate-input.js +1 -1
- package/lib/templates/collection-type-routes.js.hbs +5 -0
- package/lib/templates/content-type.schema.json.hbs +4 -5
- 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 +0 -1
- package/lib/templates/policy.js.hbs +10 -8
- package/lib/templates/single-route.js.hbs +13 -0
- package/lib/templates/single-type-routes.js.hbs +3 -0
- package/package.json +8 -6
|
@@ -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
|
},
|
package/lib/plopfile.js
CHANGED
|
@@ -7,6 +7,7 @@ const generateController = require('./plops/controller');
|
|
|
7
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 => {
|
|
@@ -20,5 +21,6 @@ module.exports = 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
|
@@ -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
47
|
actions(answers) {
|
|
64
|
-
|
|
65
|
-
if (answers.isPluginApi && answers.plugin) {
|
|
66
|
-
filePath = `plugins/{{plugin}}`;
|
|
67
|
-
} else {
|
|
68
|
-
filePath = `api/{{id}}`;
|
|
69
|
-
}
|
|
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/content-type.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
|
];
|
|
@@ -1,137 +1,66 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const DEFAULT_TYPES = [
|
|
8
|
-
// advanced types
|
|
9
|
-
'media',
|
|
10
|
-
|
|
11
|
-
// scalar types
|
|
12
|
-
'string',
|
|
13
|
-
'text',
|
|
14
|
-
'richtext',
|
|
15
|
-
'json',
|
|
16
|
-
'enumeration',
|
|
17
|
-
'password',
|
|
18
|
-
'email',
|
|
19
|
-
'integer',
|
|
20
|
-
'biginteger',
|
|
21
|
-
'float',
|
|
22
|
-
'decimal',
|
|
23
|
-
'date',
|
|
24
|
-
'time',
|
|
25
|
-
'datetime',
|
|
26
|
-
'timestamp',
|
|
27
|
-
'boolean',
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
const promptConfigQuestions = (plop, inquirer) => {
|
|
31
|
-
return inquirer.prompt([
|
|
32
|
-
{
|
|
33
|
-
type: 'input',
|
|
34
|
-
name: 'id',
|
|
35
|
-
message: 'Content type name',
|
|
36
|
-
validate: input => validateInput(input),
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
type: 'list',
|
|
40
|
-
name: 'kind',
|
|
41
|
-
message: 'Please choose the model type',
|
|
42
|
-
default: 'collectionType',
|
|
43
|
-
choices: [
|
|
44
|
-
{ name: 'Collection Type', value: 'collectionType' },
|
|
45
|
-
{ name: 'Singe Type', value: 'singleType' },
|
|
46
|
-
],
|
|
47
|
-
validate: input => validateInput(input),
|
|
48
|
-
},
|
|
49
|
-
...getDestinationPrompts('model', plop.getDestBasePath()),
|
|
50
|
-
{
|
|
51
|
-
type: 'confirm',
|
|
52
|
-
name: 'useDraftAndPublish',
|
|
53
|
-
default: false,
|
|
54
|
-
message: 'Use draft and publish?',
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
type: 'confirm',
|
|
58
|
-
name: 'addAttributes',
|
|
59
|
-
message: 'Do you want to add attributes?',
|
|
60
|
-
},
|
|
61
|
-
]);
|
|
62
|
-
};
|
|
3
|
+
const { join } = require('path');
|
|
4
|
+
const slugify = require('@sindresorhus/slugify');
|
|
5
|
+
const fs = require('fs-extra');
|
|
6
|
+
const { isKebabCase } = require('@strapi/utils');
|
|
63
7
|
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
type: 'list',
|
|
74
|
-
name: 'attributeType',
|
|
75
|
-
message: 'What type of attribute',
|
|
76
|
-
pageSize: DEFAULT_TYPES.length,
|
|
77
|
-
choices: DEFAULT_TYPES.map(type => {
|
|
78
|
-
return { name: type, value: type };
|
|
79
|
-
}),
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
when: answers => answers.attributeType === 'enumeration',
|
|
83
|
-
type: 'input',
|
|
84
|
-
name: 'enum',
|
|
85
|
-
message: 'Add values separated by a comma',
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
when: answers => answers.attributeType === 'media',
|
|
89
|
-
type: 'list',
|
|
90
|
-
name: 'multiple',
|
|
91
|
-
message: 'Choose media type',
|
|
92
|
-
choices: [
|
|
93
|
-
{ name: 'Multiple', value: true },
|
|
94
|
-
{ name: 'Single', value: false },
|
|
95
|
-
],
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
type: 'confirm',
|
|
99
|
-
name: 'addAttributes',
|
|
100
|
-
message: 'Do you want to add another attribute?',
|
|
101
|
-
},
|
|
102
|
-
]);
|
|
103
|
-
};
|
|
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');
|
|
104
15
|
|
|
105
16
|
module.exports = plop => {
|
|
106
17
|
// Model generator
|
|
107
18
|
plop.setGenerator('content-type', {
|
|
108
19
|
description: 'Generate a content type for an API',
|
|
109
20
|
async prompts(inquirer) {
|
|
110
|
-
const config = await
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
+
]);
|
|
132
60
|
|
|
133
61
|
return {
|
|
134
62
|
...config,
|
|
63
|
+
...api,
|
|
135
64
|
attributes,
|
|
136
65
|
};
|
|
137
66
|
},
|
|
@@ -153,22 +82,64 @@ module.exports = plop => {
|
|
|
153
82
|
|
|
154
83
|
const filePath = getFilePath(answers.destination);
|
|
155
84
|
|
|
156
|
-
|
|
85
|
+
const baseActions = [
|
|
157
86
|
{
|
|
158
87
|
type: 'add',
|
|
159
|
-
path: `${filePath}/content-types/{{
|
|
88
|
+
path: `${filePath}/content-types/{{ singularName }}/schema.json`,
|
|
160
89
|
templateFile: 'templates/content-type.schema.json.hbs',
|
|
90
|
+
data: {
|
|
91
|
+
collectionName: slugify(answers.pluralName, { separator: '_' }),
|
|
92
|
+
},
|
|
161
93
|
},
|
|
162
|
-
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
if (attributes.lenght > 0) {
|
|
97
|
+
baseActions.push({
|
|
163
98
|
type: 'modify',
|
|
164
|
-
path: `${filePath}/content-types/{{
|
|
99
|
+
path: `${filePath}/content-types/{{ singularName }}/schema.json`,
|
|
165
100
|
transform(template) {
|
|
166
101
|
const parsedTemplate = JSON.parse(template);
|
|
167
102
|
parsedTemplate.attributes = attributes;
|
|
168
103
|
return JSON.stringify(parsedTemplate, null, 2);
|
|
169
104
|
},
|
|
170
|
-
}
|
|
171
|
-
|
|
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;
|
|
172
143
|
},
|
|
173
144
|
});
|
|
174
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
|
|
|
@@ -23,7 +23,7 @@ module.exports = plop => {
|
|
|
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/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,7 +12,7 @@ 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
17
|
actions(answers) {
|
|
18
18
|
let filePath;
|
|
@@ -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
|
+
];
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const validateInput = require('../utils/validate-input');
|
|
4
|
+
|
|
5
|
+
const DEFAULT_TYPES = [
|
|
6
|
+
// advanced types
|
|
7
|
+
'media',
|
|
8
|
+
|
|
9
|
+
// scalar types
|
|
10
|
+
'string',
|
|
11
|
+
'text',
|
|
12
|
+
'richtext',
|
|
13
|
+
'json',
|
|
14
|
+
'enumeration',
|
|
15
|
+
'password',
|
|
16
|
+
'email',
|
|
17
|
+
'integer',
|
|
18
|
+
'biginteger',
|
|
19
|
+
'float',
|
|
20
|
+
'decimal',
|
|
21
|
+
'date',
|
|
22
|
+
'time',
|
|
23
|
+
'datetime',
|
|
24
|
+
'timestamp',
|
|
25
|
+
'boolean',
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {import('inquirer').Inquirer} inquirer
|
|
30
|
+
* @returns {Promise<Record<string, string>[]>}
|
|
31
|
+
*/
|
|
32
|
+
module.exports = async inquirer => {
|
|
33
|
+
const { addAttributes } = await inquirer.prompt([
|
|
34
|
+
{
|
|
35
|
+
type: 'confirm',
|
|
36
|
+
name: 'addAttributes',
|
|
37
|
+
message: 'Do you want to add attributes?',
|
|
38
|
+
},
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
const attributes = [];
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {import('inquirer').Inquirer} inquirer
|
|
45
|
+
* @returns {Promise<void>}
|
|
46
|
+
*/
|
|
47
|
+
const createNewAttributes = async inquirer => {
|
|
48
|
+
const answers = await inquirer.prompt([
|
|
49
|
+
{
|
|
50
|
+
type: 'input',
|
|
51
|
+
name: 'attributeName',
|
|
52
|
+
message: 'Name of attribute',
|
|
53
|
+
validate: input => validateInput(input),
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
type: 'list',
|
|
57
|
+
name: 'attributeType',
|
|
58
|
+
message: 'What type of attribute',
|
|
59
|
+
pageSize: DEFAULT_TYPES.length,
|
|
60
|
+
choices: DEFAULT_TYPES.map(type => {
|
|
61
|
+
return { name: type, value: type };
|
|
62
|
+
}),
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
when: answers => answers.attributeType === 'enumeration',
|
|
66
|
+
type: 'input',
|
|
67
|
+
name: 'enum',
|
|
68
|
+
message: 'Add values separated by a comma',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
when: answers => answers.attributeType === 'media',
|
|
72
|
+
type: 'list',
|
|
73
|
+
name: 'multiple',
|
|
74
|
+
message: 'Choose media type',
|
|
75
|
+
choices: [{ name: 'Multiple', value: true }, { name: 'Single', value: false }],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
type: 'confirm',
|
|
79
|
+
name: 'addAttributes',
|
|
80
|
+
message: 'Do you want to add another attribute?',
|
|
81
|
+
},
|
|
82
|
+
]);
|
|
83
|
+
|
|
84
|
+
attributes.push(answers);
|
|
85
|
+
|
|
86
|
+
if (!answers.addAttributes) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
await createNewAttributes(inquirer);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
if (addAttributes) {
|
|
94
|
+
await createNewAttributes(inquirer);
|
|
95
|
+
} else {
|
|
96
|
+
console.warn(
|
|
97
|
+
`You won't be able to manage entries from the admin, you can still add attributes later from the content type builder.`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return attributes;
|
|
102
|
+
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const { join } = require('path');
|
|
3
3
|
const fs = require('fs-extra');
|
|
4
4
|
|
|
5
|
-
module.exports = (action, basePath) => {
|
|
5
|
+
module.exports = (action, basePath, { rootFolder = false } = {}) => {
|
|
6
6
|
return [
|
|
7
7
|
{
|
|
8
8
|
type: 'list',
|
|
@@ -10,7 +10,7 @@ module.exports = (action, basePath) => {
|
|
|
10
10
|
message: `Where do you want to add this ${action}?`,
|
|
11
11
|
choices: [
|
|
12
12
|
{
|
|
13
|
-
name: `Add ${action} to ${
|
|
13
|
+
name: `Add ${action} to ${rootFolder ? 'root of project' : 'new API'}`,
|
|
14
14
|
value: 'new',
|
|
15
15
|
},
|
|
16
16
|
{ name: `Add ${action} to an existing API`, value: 'api' },
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const validateInput = require('../utils/validate-input');
|
|
4
|
+
|
|
5
|
+
module.exports = [
|
|
6
|
+
{
|
|
7
|
+
type: 'list',
|
|
8
|
+
name: 'kind',
|
|
9
|
+
message: 'Please choose the model type',
|
|
10
|
+
default: 'collectionType',
|
|
11
|
+
choices: [
|
|
12
|
+
{ name: 'Collection Type', value: 'collectionType' },
|
|
13
|
+
{ name: 'Single Type', value: 'singleType' },
|
|
14
|
+
],
|
|
15
|
+
validate: input => validateInput(input),
|
|
16
|
+
},
|
|
17
|
+
];
|
package/lib/plops/service.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
|
|
|
6
6
|
module.exports = plop => {
|
|
@@ -20,7 +20,7 @@ module.exports = plop => {
|
|
|
20
20
|
return [
|
|
21
21
|
{
|
|
22
22
|
type: 'add',
|
|
23
|
-
path: `${filePath}/services/{{id}}.js`,
|
|
23
|
+
path: `${filePath}/services/{{ id }}.js`,
|
|
24
24
|
templateFile: 'templates/service.js.hbs',
|
|
25
25
|
},
|
|
26
26
|
];
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
module.exports = destination => {
|
|
4
4
|
if (destination === 'api') {
|
|
5
|
-
return `api/{{api}}`;
|
|
5
|
+
return `api/{{ api }}`;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
if (destination === 'plugin') {
|
|
9
|
-
return `plugins/{{plugin}}`;
|
|
9
|
+
return `plugins/{{ plugin }}`;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
return `api/{{id}}`;
|
|
12
|
+
return `api/{{ id }}`;
|
|
13
13
|
};
|
|
@@ -6,6 +6,7 @@ module.exports = {
|
|
|
6
6
|
handler: '{{id}}.find',
|
|
7
7
|
config: {
|
|
8
8
|
policies: [],
|
|
9
|
+
middlewares: [],
|
|
9
10
|
},
|
|
10
11
|
},
|
|
11
12
|
{
|
|
@@ -14,6 +15,7 @@ module.exports = {
|
|
|
14
15
|
handler: '{{id}}.findOne',
|
|
15
16
|
config: {
|
|
16
17
|
policies: [],
|
|
18
|
+
middlewares: [],
|
|
17
19
|
},
|
|
18
20
|
},
|
|
19
21
|
{
|
|
@@ -22,6 +24,7 @@ module.exports = {
|
|
|
22
24
|
handler: '{{id}}.create',
|
|
23
25
|
config: {
|
|
24
26
|
policies: [],
|
|
27
|
+
middlewares: [],
|
|
25
28
|
},
|
|
26
29
|
},
|
|
27
30
|
{
|
|
@@ -30,6 +33,7 @@ module.exports = {
|
|
|
30
33
|
handler: '{{id}}.update',
|
|
31
34
|
config: {
|
|
32
35
|
policies: [],
|
|
36
|
+
middlewares: [],
|
|
33
37
|
},
|
|
34
38
|
},
|
|
35
39
|
{
|
|
@@ -38,6 +42,7 @@ module.exports = {
|
|
|
38
42
|
handler: '{{id}}.delete',
|
|
39
43
|
config: {
|
|
40
44
|
policies: [],
|
|
45
|
+
middlewares: [],
|
|
41
46
|
},
|
|
42
47
|
},
|
|
43
48
|
],
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
{
|
|
3
3
|
"kind": "{{kind}}",
|
|
4
|
-
"collectionName": "{{
|
|
4
|
+
"collectionName": "{{ collectionName }}",
|
|
5
5
|
"info": {
|
|
6
|
-
"singularName": "{{
|
|
7
|
-
"pluralName": "{{
|
|
8
|
-
"displayName": "{{
|
|
9
|
-
"name": "{{id}}"
|
|
6
|
+
"singularName": "{{ singularName }}",
|
|
7
|
+
"pluralName": "{{ pluralName }}",
|
|
8
|
+
"displayName": "{{ displayName }}"
|
|
10
9
|
},
|
|
11
10
|
"options": {
|
|
12
11
|
"draftAndPublish": {{ useDraftAndPublish }},
|
|
@@ -4,15 +4,17 @@
|
|
|
4
4
|
* `{{id}}` policy.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
module.exports =
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
module.exports = (config, { strapi }) => {
|
|
8
|
+
return policyCtx => {
|
|
9
|
+
// Add your own logic here.
|
|
10
|
+
strapi.log.info('In {{id}} policy.');
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
const canDoSomething = true;
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
if (canDoSomething) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
return false;
|
|
19
|
+
};
|
|
18
20
|
};
|
|
@@ -6,6 +6,7 @@ module.exports = {
|
|
|
6
6
|
handler: '{{id}}.find',
|
|
7
7
|
config: {
|
|
8
8
|
policies: [],
|
|
9
|
+
middlewares: [],
|
|
9
10
|
},
|
|
10
11
|
},
|
|
11
12
|
{
|
|
@@ -14,6 +15,7 @@ module.exports = {
|
|
|
14
15
|
handler: '{{id}}.update',
|
|
15
16
|
config: {
|
|
16
17
|
policies: [],
|
|
18
|
+
middlewares: [],
|
|
17
19
|
},
|
|
18
20
|
},
|
|
19
21
|
{
|
|
@@ -22,6 +24,7 @@ module.exports = {
|
|
|
22
24
|
handler: '{{id}}.delete',
|
|
23
25
|
config: {
|
|
24
26
|
policies: [],
|
|
27
|
+
middlewares: [],
|
|
25
28
|
},
|
|
26
29
|
},
|
|
27
30
|
],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/generators",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.20",
|
|
4
4
|
"description": "Interactive API generator.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -16,28 +16,30 @@
|
|
|
16
16
|
},
|
|
17
17
|
"license": "SEE LICENSE IN LICENSE",
|
|
18
18
|
"author": {
|
|
19
|
-
"name": "Strapi
|
|
19
|
+
"name": "Strapi Solutions SAS",
|
|
20
20
|
"email": "hi@strapi.io",
|
|
21
21
|
"url": "https://strapi.io"
|
|
22
22
|
},
|
|
23
23
|
"maintainers": [
|
|
24
24
|
{
|
|
25
|
-
"name": "Strapi
|
|
25
|
+
"name": "Strapi Solutions SAS",
|
|
26
26
|
"email": "hi@strapi.io",
|
|
27
27
|
"url": "https://strapi.io"
|
|
28
28
|
}
|
|
29
29
|
],
|
|
30
30
|
"main": "lib/index.js",
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"@sindresorhus/slugify": "1.1.0",
|
|
33
|
+
"@strapi/utils": "4.0.0-beta.20",
|
|
32
34
|
"chalk": "4.1.2",
|
|
33
35
|
"fs-extra": "10.0.0",
|
|
34
|
-
"node-plop": "0.26.
|
|
35
|
-
"plop": "2.7.
|
|
36
|
+
"node-plop": "0.26.3",
|
|
37
|
+
"plop": "2.7.6",
|
|
36
38
|
"pluralize": "8.0.0"
|
|
37
39
|
},
|
|
38
40
|
"engines": {
|
|
39
41
|
"node": ">=12.x.x <=16.x.x",
|
|
40
42
|
"npm": ">=6.0.0"
|
|
41
43
|
},
|
|
42
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "b4993dab9f6dbc583709167f459b6f00e0b4baa6"
|
|
43
45
|
}
|