@strapi/generators 4.0.0-next.9 → 4.0.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.
Files changed (52) hide show
  1. package/lib/files/plugin/admin/src/components/PluginIcon/index.js +12 -0
  2. package/lib/files/plugin/admin/src/index.js +2 -6
  3. package/lib/files/plugin/admin/src/utils/axiosInstance.js +40 -0
  4. package/lib/files/plugin/server/bootstrap.js +5 -0
  5. package/lib/files/plugin/server/config/index.js +6 -0
  6. package/lib/files/plugin/server/controllers/index.js +7 -0
  7. package/lib/files/plugin/server/controllers/my-controller.js.hbs +10 -0
  8. package/lib/files/plugin/server/destroy.js +5 -0
  9. package/lib/files/plugin/server/index.js +22 -0
  10. package/lib/files/plugin/server/register.js +5 -0
  11. package/lib/files/plugin/server/routes/index.js +10 -0
  12. package/lib/files/plugin/server/services/index.js +7 -0
  13. package/lib/files/plugin/server/services/my-service.js +7 -0
  14. package/lib/files/plugin/strapi-admin.js +3 -0
  15. package/lib/files/plugin/strapi-server.js +3 -0
  16. package/lib/index.js +5 -5
  17. package/lib/plopfile.js +4 -2
  18. package/lib/plops/__tests__/content-type.test.js +179 -0
  19. package/lib/plops/api.js +4 -35
  20. package/lib/plops/content-type.js +145 -0
  21. package/lib/plops/controller.js +3 -3
  22. package/lib/plops/middleware.js +36 -0
  23. package/lib/plops/plugin.js +31 -22
  24. package/lib/plops/policy.js +4 -4
  25. package/lib/plops/prompts/bootstrap-api-prompts.js +10 -0
  26. package/lib/plops/prompts/ct-names-prompts.js +44 -0
  27. package/lib/plops/prompts/draft-and-publish-prompts.js +10 -0
  28. package/lib/plops/prompts/get-attributes-prompts.js +102 -0
  29. package/lib/plops/{utils → prompts}/get-destination-prompts.js +4 -4
  30. package/lib/plops/prompts/kind-prompts.js +17 -0
  31. package/lib/plops/service.js +3 -3
  32. package/lib/plops/utils/get-file-path.js +3 -3
  33. package/lib/plops/utils/validate-input.js +1 -1
  34. package/lib/templates/README.md.hbs +2 -2
  35. package/lib/templates/collection-type-routes.js.hbs +5 -0
  36. package/lib/templates/content-type.schema.json.hbs +15 -0
  37. package/lib/templates/core-controller.js.hbs +9 -0
  38. package/lib/templates/core-router.js.hbs +9 -0
  39. package/lib/templates/core-service.js.hbs +9 -0
  40. package/lib/templates/middleware.js.hbs +14 -0
  41. package/lib/templates/plugin-package.json.hbs +6 -10
  42. package/lib/templates/policy.js.hbs +10 -4
  43. package/lib/templates/service.js.hbs +1 -1
  44. package/lib/templates/single-route.js.hbs +13 -0
  45. package/lib/templates/single-type-routes.js.hbs +4 -1
  46. package/package.json +11 -7
  47. package/lib/files/plugin/admin/src/containers/App/index.js +0 -25
  48. package/lib/files/plugin/admin/src/containers/HomePage/index.js +0 -20
  49. package/lib/files/plugin/admin/src/containers/Initializer/index.js +0 -26
  50. package/lib/plops/model.js +0 -174
  51. package/lib/templates/model.schema.json.hbs +0 -16
  52. package/lib/templates/plugin-routes.json.hbs +0 -12
@@ -1,25 +0,0 @@
1
- /**
2
- *
3
- * This component is the skeleton around the actual pages, and should only
4
- * contain code that should be seen on all pages. (e.g. navigation bar)
5
- *
6
- */
7
-
8
- import React from 'react';
9
- import { Switch, Route } from 'react-router-dom';
10
- import { NotFound } from '@strapi/helper-plugin';
11
- import pluginId from '../../pluginId';
12
- import HomePage from '../HomePage';
13
-
14
- const App = () => {
15
- return (
16
- <div>
17
- <Switch>
18
- <Route path={`/plugins/${pluginId}`} component={HomePage} exact />
19
- <Route component={NotFound} />
20
- </Switch>
21
- </div>
22
- );
23
- };
24
-
25
- export default App;
@@ -1,20 +0,0 @@
1
- /*
2
- *
3
- * HomePage
4
- *
5
- */
6
-
7
- import React, { memo } from 'react';
8
- // import PropTypes from 'prop-types';
9
- import pluginId from '../../pluginId';
10
-
11
- const HomePage = () => {
12
- return (
13
- <div>
14
- <h1>{pluginId}&apos;s HomePage</h1>
15
- <p>Happy coding</p>
16
- </div>
17
- );
18
- };
19
-
20
- export default memo(HomePage);
@@ -1,26 +0,0 @@
1
- /**
2
- *
3
- * Initializer
4
- *
5
- */
6
-
7
- import { useEffect, useRef } from 'react';
8
- import PropTypes from 'prop-types';
9
- import pluginId from '../../pluginId';
10
-
11
- const Initializer = ({ setPlugin }) => {
12
- const ref = useRef();
13
- ref.current = setPlugin;
14
-
15
- useEffect(() => {
16
- ref.current(pluginId);
17
- }, []);
18
-
19
- return null;
20
- };
21
-
22
- Initializer.propTypes = {
23
- setPlugin: PropTypes.func.isRequired,
24
- };
25
-
26
- export default Initializer;
@@ -1,174 +0,0 @@
1
- 'use strict';
2
-
3
- const getDestinationPrompts = require('./utils/get-destination-prompts');
4
- const getFilePath = require('./utils/get-file-path');
5
- const validateInput = require('./utils/validate-input');
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: 'Model 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
- };
63
-
64
- const promptAttributeQuestions = inquirer => {
65
- return inquirer.prompt([
66
- {
67
- type: 'input',
68
- name: 'attributeName',
69
- message: 'Name of attribute',
70
- validate: input => validateInput(input),
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
- };
104
-
105
- module.exports = plop => {
106
- // Model generator
107
- plop.setGenerator('model', {
108
- description: 'Generate a model for an API',
109
- prompts: async inquirer => {
110
- const config = await promptConfigQuestions(plop, inquirer);
111
-
112
- if (!config.addAttributes) {
113
- return {
114
- ...config,
115
- attributes: [],
116
- };
117
- }
118
-
119
- const attributes = [];
120
-
121
- const genAttribute = async () => {
122
- const answers = await promptAttributeQuestions(inquirer);
123
-
124
- attributes.push(answers);
125
-
126
- if (answers.addAttributes) {
127
- return genAttribute();
128
- }
129
- };
130
-
131
- await genAttribute();
132
-
133
- return {
134
- ...config,
135
- attributes,
136
- };
137
- },
138
- actions: answers => {
139
- const attributes = answers.attributes.reduce((object, answer) => {
140
- const val = { type: answer.attributeType };
141
-
142
- if (answer.attributeType === 'enumeration') {
143
- val.enum = answer.enum.split(',').map(item => item.trim());
144
- }
145
-
146
- if (answer.attributeType === 'media') {
147
- val.allowedTypes = ['images', 'files', 'videos'];
148
- val.multiple = answer.multiple;
149
- }
150
-
151
- return Object.assign(object, { [answer.attributeName]: val }, {});
152
- }, {});
153
-
154
- const filePath = getFilePath(answers.destination);
155
-
156
- return [
157
- {
158
- type: 'add',
159
- path: `${filePath}/content-types/{{id}}/schema.json`,
160
- templateFile: 'templates/model.schema.json.hbs',
161
- },
162
- {
163
- type: 'modify',
164
- path: `${filePath}/content-types/{{id}}/schema.json`,
165
- transform: template => {
166
- const parsedTemplate = JSON.parse(template);
167
- parsedTemplate.attributes = attributes;
168
- return JSON.stringify(parsedTemplate, null, 2);
169
- },
170
- },
171
- ];
172
- },
173
- });
174
- };
@@ -1,16 +0,0 @@
1
-
2
- {
3
- "kind": "{{kind}}",
4
- "collectionName": "{{id}}",
5
- "info": {
6
- "singularName": "{{id}}",
7
- "pluralName": "{{pluralize id}}",
8
- "displayName": "{{id}}",
9
- "name": "{{id}}"
10
- },
11
- "options": {
12
- "draftAndPublish": {{useDraftAndPublish || false}},
13
- "comment": ""
14
- },
15
- "attributes": {}
16
- }
@@ -1,12 +0,0 @@
1
- {
2
- "routes": [
3
- {
4
- "method": "GET",
5
- "path": "/",
6
- "handler": "{{id}}.index",
7
- "config": {
8
- "policies": []
9
- }
10
- }
11
- ]
12
- }