@strapi/generators 0.0.0-next.e6eaa3d0563c85f80fd88b258df70a55c057096e → 0.0.0-next.e98ae27d8c69c68823eb7c46cf329385637ba393

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 (93) hide show
  1. package/LICENSE +18 -3
  2. package/dist/index.d.ts +2 -2
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +33 -26
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +32 -26
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/plopfile.d.ts +1 -1
  9. package/dist/plopfile.d.ts.map +1 -1
  10. package/dist/plopfile.js +621 -667
  11. package/dist/plopfile.js.map +1 -1
  12. package/dist/plopfile.mjs +621 -645
  13. package/dist/plopfile.mjs.map +1 -1
  14. package/dist/plops/api.d.ts +1 -1
  15. package/dist/plops/api.d.ts.map +1 -1
  16. package/dist/plops/content-type.d.ts +1 -1
  17. package/dist/plops/content-type.d.ts.map +1 -1
  18. package/dist/plops/controller.d.ts +1 -1
  19. package/dist/plops/controller.d.ts.map +1 -1
  20. package/dist/plops/middleware.d.ts +1 -1
  21. package/dist/plops/middleware.d.ts.map +1 -1
  22. package/dist/plops/migration.d.ts +1 -1
  23. package/dist/plops/migration.d.ts.map +1 -1
  24. package/dist/plops/policy.d.ts +1 -1
  25. package/dist/plops/policy.d.ts.map +1 -1
  26. package/dist/plops/service.d.ts +1 -1
  27. package/dist/plops/service.d.ts.map +1 -1
  28. package/dist/plops/utils/get-file-path.d.ts +1 -1
  29. package/dist/templates/js/content-type.schema.json.hbs +0 -1
  30. package/dist/templates/ts/content-type.schema.json.hbs +0 -1
  31. package/dist/templates/ts/middleware.ts.hbs +2 -2
  32. package/package.json +16 -14
  33. package/dist/files/js/plugin/.gitattributes +0 -103
  34. package/dist/files/js/plugin/admin/src/components/Initializer/index.js +0 -26
  35. package/dist/files/js/plugin/admin/src/components/PluginIcon/index.js +0 -12
  36. package/dist/files/js/plugin/admin/src/index.js +0 -61
  37. package/dist/files/js/plugin/admin/src/pages/App/index.js +0 -25
  38. package/dist/files/js/plugin/admin/src/pages/HomePage/index.js +0 -20
  39. package/dist/files/js/plugin/admin/src/pluginId.js +0 -5
  40. package/dist/files/js/plugin/admin/src/translations/en.json +0 -1
  41. package/dist/files/js/plugin/admin/src/translations/fr.json +0 -1
  42. package/dist/files/js/plugin/admin/src/utils/getTrad.js +0 -5
  43. package/dist/files/js/plugin/server/bootstrap.js +0 -5
  44. package/dist/files/js/plugin/server/config/index.js +0 -6
  45. package/dist/files/js/plugin/server/content-types/index.js +0 -3
  46. package/dist/files/js/plugin/server/controllers/index.js +0 -7
  47. package/dist/files/js/plugin/server/controllers/my-controller.js.hbs +0 -10
  48. package/dist/files/js/plugin/server/destroy.js +0 -5
  49. package/dist/files/js/plugin/server/index.js +0 -25
  50. package/dist/files/js/plugin/server/middlewares/index.js +0 -3
  51. package/dist/files/js/plugin/server/policies/index.js +0 -3
  52. package/dist/files/js/plugin/server/register.js +0 -5
  53. package/dist/files/js/plugin/server/routes/index.js +0 -10
  54. package/dist/files/js/plugin/server/services/index.js +0 -7
  55. package/dist/files/js/plugin/server/services/my-service.js +0 -7
  56. package/dist/files/js/plugin/strapi-admin.js +0 -3
  57. package/dist/files/js/plugin/strapi-server.js +0 -3
  58. package/dist/files/ts/plugin/.gitattributes +0 -103
  59. package/dist/files/ts/plugin/admin/src/components/Initializer/index.tsx +0 -24
  60. package/dist/files/ts/plugin/admin/src/components/PluginIcon/index.tsx +0 -12
  61. package/dist/files/ts/plugin/admin/src/index.tsx +0 -67
  62. package/dist/files/ts/plugin/admin/src/pages/App/index.tsx +0 -25
  63. package/dist/files/ts/plugin/admin/src/pages/HomePage/index.tsx +0 -19
  64. package/dist/files/ts/plugin/admin/src/pluginId.ts +0 -5
  65. package/dist/files/ts/plugin/admin/src/translations/en.json +0 -1
  66. package/dist/files/ts/plugin/admin/src/translations/fr.json +0 -1
  67. package/dist/files/ts/plugin/admin/src/utils/getTrad.ts +0 -5
  68. package/dist/files/ts/plugin/custom.d.ts +0 -5
  69. package/dist/files/ts/plugin/server/bootstrap.ts +0 -5
  70. package/dist/files/ts/plugin/server/config/index.ts +0 -4
  71. package/dist/files/ts/plugin/server/content-types/index.ts +0 -1
  72. package/dist/files/ts/plugin/server/controllers/index.ts +0 -5
  73. package/dist/files/ts/plugin/server/controllers/my-controller.ts.hbs +0 -10
  74. package/dist/files/ts/plugin/server/destroy.ts +0 -5
  75. package/dist/files/ts/plugin/server/index.ts +0 -23
  76. package/dist/files/ts/plugin/server/middlewares/index.ts +0 -1
  77. package/dist/files/ts/plugin/server/policies/index.ts +0 -1
  78. package/dist/files/ts/plugin/server/register.ts +0 -5
  79. package/dist/files/ts/plugin/server/routes/index.ts +0 -10
  80. package/dist/files/ts/plugin/server/services/index.ts +0 -5
  81. package/dist/files/ts/plugin/server/services/my-service.ts +0 -7
  82. package/dist/files/ts/plugin/strapi-admin.js +0 -3
  83. package/dist/files/ts/plugin/strapi-server.js +0 -3
  84. package/dist/files/ts/plugin/tsconfig.json +0 -20
  85. package/dist/files/ts/plugin/tsconfig.server.json +0 -25
  86. package/dist/plops/plugin.d.ts +0 -4
  87. package/dist/plops/plugin.d.ts.map +0 -1
  88. package/dist/plops/prompts/draft-and-publish-prompts.d.ts +0 -4
  89. package/dist/plops/prompts/draft-and-publish-prompts.d.ts.map +0 -1
  90. package/dist/templates/js/README.md.hbs +0 -3
  91. package/dist/templates/js/plugin-package.json.hbs +0 -42
  92. package/dist/templates/ts/README.md.hbs +0 -3
  93. package/dist/templates/ts/plugin-package.json.hbs +0 -51
package/dist/plopfile.js CHANGED
@@ -1,703 +1,657 @@
1
- "use strict";
2
- const pluralize = require("pluralize");
3
- const path = require("path");
4
- const fs = require("fs-extra");
5
- const tsUtils = require("@strapi/typescript-utils");
6
- const slugify = require("@sindresorhus/slugify");
7
- const utils = require("@strapi/utils");
8
- const chalk = require("chalk");
9
- const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
10
- function _interopNamespace(e) {
11
- if (e && e.__esModule)
12
- return e;
13
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
14
- if (e) {
15
- for (const k in e) {
16
- if (k !== "default") {
17
- const d = Object.getOwnPropertyDescriptor(e, k);
18
- Object.defineProperty(n, k, d.get ? d : {
19
- enumerable: true,
20
- get: () => e[k]
21
- });
22
- }
1
+ 'use strict';
2
+
3
+ var pluralize = require('pluralize');
4
+ var path = require('path');
5
+ var fs = require('fs-extra');
6
+ var tsUtils = require('@strapi/typescript-utils');
7
+ var slugify = require('@sindresorhus/slugify');
8
+ var utils = require('@strapi/utils');
9
+
10
+ var validateInput = ((input)=>{
11
+ const regex = /^[A-Za-z-]+$/g;
12
+ if (!input) {
13
+ return 'You must provide an input';
23
14
  }
24
- }
25
- n.default = e;
26
- return Object.freeze(n);
27
- }
28
- const pluralize__default = /* @__PURE__ */ _interopDefault(pluralize);
29
- const fs__default = /* @__PURE__ */ _interopDefault(fs);
30
- const tsUtils__default = /* @__PURE__ */ _interopDefault(tsUtils);
31
- const slugify__default = /* @__PURE__ */ _interopDefault(slugify);
32
- const utils__namespace = /* @__PURE__ */ _interopNamespace(utils);
33
- const chalk__default = /* @__PURE__ */ _interopDefault(chalk);
34
- const validateInput = (input) => {
35
- const regex = /^[A-Za-z-]+$/g;
36
- if (!input) {
37
- return "You must provide an input";
38
- }
39
- return regex.test(input) || "Please use only letters, '-' and no spaces";
40
- };
41
- const generateApi = (plop) => {
42
- plop.setGenerator("api", {
43
- description: "Generate a basic API",
44
- prompts: [
45
- {
46
- type: "input",
47
- name: "id",
48
- message: "API name",
49
- validate: (input) => validateInput(input)
50
- },
51
- {
52
- type: "confirm",
53
- name: "isPluginApi",
54
- message: "Is this API for a plugin?"
55
- },
56
- {
57
- when: (answers) => answers.isPluginApi,
58
- type: "list",
59
- name: "plugin",
60
- message: "Plugin name",
61
- async choices() {
62
- const pluginsPath = path.join(plop.getDestBasePath(), "plugins");
63
- const exists = await fs__default.default.pathExists(pluginsPath);
64
- if (!exists) {
65
- throw Error(`Couldn't find a "plugins" directory`);
66
- }
67
- const pluginsDir = await fs__default.default.readdir(pluginsPath, { withFileTypes: true });
68
- const pluginsDirContent = pluginsDir.filter((fd) => fd.isDirectory());
69
- if (pluginsDirContent.length === 0) {
70
- throw Error('The "plugins" directory is empty');
71
- }
72
- return pluginsDirContent;
15
+ return regex.test(input) || "Please use only letters, '-' and no spaces";
16
+ });
17
+
18
+ var generateApi = ((plop)=>{
19
+ // API generator
20
+ plop.setGenerator('api', {
21
+ description: 'Generate a basic API',
22
+ prompts: [
23
+ {
24
+ type: 'input',
25
+ name: 'id',
26
+ message: 'API name',
27
+ validate: (input)=>validateInput(input)
28
+ },
29
+ {
30
+ type: 'confirm',
31
+ name: 'isPluginApi',
32
+ message: 'Is this API for a plugin?'
33
+ },
34
+ {
35
+ when: (answers)=>answers.isPluginApi,
36
+ type: 'list',
37
+ name: 'plugin',
38
+ message: 'Plugin name',
39
+ async choices () {
40
+ const pluginsPath = path.join(plop.getDestBasePath(), 'plugins');
41
+ const exists = await fs.pathExists(pluginsPath);
42
+ if (!exists) {
43
+ throw Error('Couldn\'t find a "plugins" directory');
44
+ }
45
+ const pluginsDir = await fs.readdir(pluginsPath, {
46
+ withFileTypes: true
47
+ });
48
+ const pluginsDirContent = pluginsDir.filter((fd)=>fd.isDirectory());
49
+ if (pluginsDirContent.length === 0) {
50
+ throw Error('The "plugins" directory is empty');
51
+ }
52
+ return pluginsDirContent;
53
+ }
54
+ }
55
+ ],
56
+ actions (answers) {
57
+ if (!answers) {
58
+ return [];
59
+ }
60
+ const filePath = answers.isPluginApi && answers.plugin ? 'plugins/{{ plugin }}/server' : 'api/{{ id }}';
61
+ const currentDir = process.cwd();
62
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
63
+ const baseActions = [
64
+ {
65
+ type: 'add',
66
+ path: `${filePath}/controllers/{{ id }}.${language}`,
67
+ templateFile: `templates/${language}/controller.${language}.hbs`
68
+ },
69
+ {
70
+ type: 'add',
71
+ path: `${filePath}/services/{{ id }}.${language}`,
72
+ templateFile: `templates/${language}/service.${language}.hbs`
73
+ }
74
+ ];
75
+ if (answers.isPluginApi) {
76
+ return baseActions;
77
+ }
78
+ return [
79
+ {
80
+ type: 'add',
81
+ path: `${filePath}/routes/{{ id }}.${language}`,
82
+ templateFile: `templates/${language}/single-route.${language}.hbs`
83
+ },
84
+ ...baseActions
85
+ ];
73
86
  }
74
- }
75
- ],
76
- actions(answers) {
77
- if (!answers) {
78
- return [];
79
- }
80
- const filePath = answers.isPluginApi && answers.plugin ? "plugins/{{ plugin }}" : "api/{{ id }}";
81
- const currentDir = process.cwd();
82
- const language = tsUtils__default.default.isUsingTypeScriptSync(currentDir) ? "ts" : "js";
83
- const baseActions = [
87
+ });
88
+ });
89
+
90
+ var getDestinationPrompts = ((action, basePath, { rootFolder = false } = {})=>{
91
+ return [
84
92
  {
85
- type: "add",
86
- path: `${filePath}/controllers/{{ id }}.${language}`,
87
- templateFile: `templates/${language}/controller.${language}.hbs`
93
+ type: 'list',
94
+ name: 'destination',
95
+ message: `Where do you want to add this ${action}?`,
96
+ choices: [
97
+ ...rootFolder ? [
98
+ {
99
+ name: `Add ${action} to root of project`,
100
+ value: 'root'
101
+ }
102
+ ] : [
103
+ {
104
+ name: `Add ${action} to new API`,
105
+ value: 'new'
106
+ }
107
+ ],
108
+ {
109
+ name: `Add ${action} to an existing API`,
110
+ value: 'api'
111
+ },
112
+ {
113
+ name: `Add ${action} to an existing plugin`,
114
+ value: 'plugin'
115
+ }
116
+ ]
88
117
  },
89
118
  {
90
- type: "add",
91
- path: `${filePath}/services/{{ id }}.${language}`,
92
- templateFile: `templates/${language}/service.${language}.hbs`
93
- }
94
- ];
95
- if (answers.isPluginApi) {
96
- return baseActions;
97
- }
98
- return [
99
- {
100
- type: "add",
101
- path: `${filePath}/routes/{{ id }}.${language}`,
102
- templateFile: `templates/${language}/single-route.${language}.hbs`
119
+ when: (answers)=>answers.destination === 'api',
120
+ type: 'list',
121
+ message: 'Which API is this for?',
122
+ name: 'api',
123
+ async choices () {
124
+ const apiPath = path.join(basePath, 'api');
125
+ const exists = await fs.pathExists(apiPath);
126
+ if (!exists) {
127
+ throw Error('Couldn\'t find an "api" directory');
128
+ }
129
+ const apiDir = await fs.readdir(apiPath, {
130
+ withFileTypes: true
131
+ });
132
+ const apiDirContent = apiDir.filter((fd)=>fd.isDirectory());
133
+ if (apiDirContent.length === 0) {
134
+ throw Error('The "api" directory is empty');
135
+ }
136
+ return apiDirContent;
137
+ }
103
138
  },
104
- ...baseActions
105
- ];
139
+ {
140
+ when: (answers)=>answers.destination === 'plugin',
141
+ type: 'list',
142
+ message: 'Which plugin is this for?',
143
+ name: 'plugin',
144
+ async choices () {
145
+ const pluginsPath = path.join(basePath, 'plugins');
146
+ const exists = await fs.pathExists(pluginsPath);
147
+ if (!exists) {
148
+ throw Error('Couldn\'t find a "plugins" directory');
149
+ }
150
+ const pluginsDir = await fs.readdir(pluginsPath);
151
+ const pluginsDirContent = pluginsDir.filter((api)=>fs.lstatSync(path.join(pluginsPath, api)).isDirectory());
152
+ if (pluginsDirContent.length === 0) {
153
+ throw Error('The "plugins" directory is empty');
154
+ }
155
+ return pluginsDirContent;
156
+ }
157
+ }
158
+ ];
159
+ });
160
+
161
+ var getFilePath = ((destination)=>{
162
+ if (destination === 'api') {
163
+ return `api/{{ api }}`;
106
164
  }
107
- });
108
- };
109
- const getDestinationPrompts = (action, basePath, { rootFolder = false } = {}) => {
110
- return [
111
- {
112
- type: "list",
113
- name: "destination",
114
- message: `Where do you want to add this ${action}?`,
115
- choices: [
116
- ...rootFolder ? [
117
- {
118
- name: `Add ${action} to root of project`,
119
- value: "root"
120
- }
121
- ] : [
122
- {
123
- name: `Add ${action} to new API`,
124
- value: "new"
125
- }
165
+ if (destination === 'plugin') {
166
+ return `plugins/{{ plugin }}/server`;
167
+ }
168
+ if (destination === 'root') {
169
+ return './';
170
+ }
171
+ return `api/{{ id }}`;
172
+ });
173
+
174
+ var generateController = ((plop)=>{
175
+ // Controller generator
176
+ plop.setGenerator('controller', {
177
+ description: 'Generate a controller for an API',
178
+ prompts: [
179
+ {
180
+ type: 'input',
181
+ name: 'id',
182
+ message: 'Controller name',
183
+ validate: (input)=>validateInput(input)
184
+ },
185
+ ...getDestinationPrompts('controller', plop.getDestBasePath())
126
186
  ],
127
- { name: `Add ${action} to an existing API`, value: "api" },
128
- { name: `Add ${action} to an existing plugin`, value: "plugin" }
129
- ]
187
+ actions (answers) {
188
+ if (!answers) {
189
+ return [];
190
+ }
191
+ const filePath = getFilePath(answers.destination);
192
+ const currentDir = process.cwd();
193
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
194
+ return [
195
+ {
196
+ type: 'add',
197
+ path: `${filePath}/controllers/{{ id }}.${language}`,
198
+ templateFile: `templates/${language}/controller.${language}.hbs`
199
+ }
200
+ ];
201
+ }
202
+ });
203
+ });
204
+
205
+ const questions$2 = [
206
+ {
207
+ type: 'input',
208
+ name: 'displayName',
209
+ message: 'Content type display name',
210
+ validate: (input)=>!!input
130
211
  },
131
212
  {
132
- when: (answers) => answers.destination === "api",
133
- type: "list",
134
- message: "Which API is this for?",
135
- name: "api",
136
- async choices() {
137
- const apiPath = path.join(basePath, "api");
138
- const exists = await fs__default.default.pathExists(apiPath);
139
- if (!exists) {
140
- throw Error(`Couldn't find an "api" directory`);
141
- }
142
- const apiDir = await fs__default.default.readdir(apiPath, { withFileTypes: true });
143
- const apiDirContent = apiDir.filter((fd) => fd.isDirectory());
144
- if (apiDirContent.length === 0) {
145
- throw Error('The "api" directory is empty');
213
+ type: 'input',
214
+ name: 'singularName',
215
+ message: 'Content type singular name',
216
+ default: (answers)=>slugify(answers.displayName),
217
+ validate (input) {
218
+ if (!utils.strings.isKebabCase(input)) {
219
+ return 'Value must be in kebab-case';
220
+ }
221
+ return true;
146
222
  }
147
- return apiDirContent;
148
- }
149
223
  },
150
224
  {
151
- when: (answers) => answers.destination === "plugin",
152
- type: "list",
153
- message: "Which plugin is this for?",
154
- name: "plugin",
155
- async choices() {
156
- const pluginsPath = path.join(basePath, "plugins");
157
- const exists = await fs__default.default.pathExists(pluginsPath);
158
- if (!exists) {
159
- throw Error(`Couldn't find a "plugins" directory`);
160
- }
161
- const pluginsDir = await fs__default.default.readdir(pluginsPath);
162
- const pluginsDirContent = pluginsDir.filter(
163
- (api) => fs__default.default.lstatSync(path.join(pluginsPath, api)).isDirectory()
164
- );
165
- if (pluginsDirContent.length === 0) {
166
- throw Error('The "plugins" directory is empty');
167
- }
168
- return pluginsDirContent;
169
- }
170
- }
171
- ];
172
- };
173
- const getFilePath = (destination) => {
174
- if (destination === "api") {
175
- return `api/{{ api }}`;
176
- }
177
- if (destination === "plugin") {
178
- return `plugins/{{ plugin }}/server`;
179
- }
180
- if (destination === "root") {
181
- return "./";
182
- }
183
- return `api/{{ id }}`;
184
- };
185
- const generateController = (plop) => {
186
- plop.setGenerator("controller", {
187
- description: "Generate a controller for an API",
188
- prompts: [
189
- {
190
- type: "input",
191
- name: "id",
192
- message: "Controller name",
193
- validate: (input) => validateInput(input)
194
- },
195
- ...getDestinationPrompts("controller", plop.getDestBasePath())
196
- ],
197
- actions(answers) {
198
- if (!answers) {
199
- return [];
200
- }
201
- const filePath = getFilePath(answers.destination);
202
- const currentDir = process.cwd();
203
- const language = tsUtils__default.default.isUsingTypeScriptSync(currentDir) ? "ts" : "js";
204
- return [
205
- {
206
- type: "add",
207
- path: `${filePath}/controllers/{{ id }}.${language}`,
208
- templateFile: `templates/${language}/controller.${language}.hbs`
225
+ type: 'input',
226
+ name: 'pluralName',
227
+ message: 'Content type plural name',
228
+ default: (answers)=>pluralize(answers.singularName),
229
+ validate (input, answers) {
230
+ if (answers.singularName === input) {
231
+ return 'Singular and plural names cannot be the same';
232
+ }
233
+ if (!utils.strings.isKebabCase(input)) {
234
+ return 'Value must be in kebab-case';
235
+ }
236
+ return true;
209
237
  }
210
- ];
211
- }
212
- });
213
- };
214
- const questions$3 = [
215
- {
216
- type: "input",
217
- name: "displayName",
218
- message: "Content type display name",
219
- validate: (input) => !!input
220
- },
221
- {
222
- type: "input",
223
- name: "singularName",
224
- message: "Content type singular name",
225
- default: (answers) => slugify__default.default(answers.displayName),
226
- validate(input) {
227
- if (!utils__namespace.isKebabCase(input)) {
228
- return "Value must be in kebab-case";
229
- }
230
- return true;
231
238
  }
232
- },
233
- {
234
- type: "input",
235
- name: "pluralName",
236
- message: "Content type plural name",
237
- default: (answers) => pluralize__default.default(answers.singularName),
238
- validate(input, answers) {
239
- if (answers.singularName === input) {
240
- return "Singular and plural names cannot be the same";
241
- }
242
- if (!utils__namespace.isKebabCase(input)) {
243
- return "Value must be in kebab-case";
244
- }
245
- return true;
246
- }
247
- }
248
- ];
249
- const questions$2 = [
250
- {
251
- type: "list",
252
- name: "kind",
253
- message: "Please choose the model type",
254
- default: "collectionType",
255
- choices: [
256
- { name: "Collection Type", value: "collectionType" },
257
- { name: "Single Type", value: "singleType" }
258
- ],
259
- validate: (input) => validateInput(input)
260
- }
261
239
  ];
240
+
262
241
  const questions$1 = [
263
- {
264
- type: "confirm",
265
- name: "useDraftAndPublish",
266
- default: false,
267
- message: "Use draft and publish?"
268
- }
242
+ {
243
+ type: 'list',
244
+ name: 'kind',
245
+ message: 'Please choose the model type',
246
+ default: 'collectionType',
247
+ choices: [
248
+ {
249
+ name: 'Collection Type',
250
+ value: 'collectionType'
251
+ },
252
+ {
253
+ name: 'Single Type',
254
+ value: 'singleType'
255
+ }
256
+ ],
257
+ validate: (input)=>validateInput(input)
258
+ }
269
259
  ];
270
- const validateAttributeInput = (input) => {
271
- const regex = /^[A-Za-z-|_]+$/g;
272
- if (!input) {
273
- return "You must provide an input";
274
- }
275
- return regex.test(input) || "Please use only letters, '-', '_', and no spaces";
276
- };
260
+
261
+ var validateAttributeInput = ((input)=>{
262
+ const regex = /^[A-Za-z-|_]+$/g;
263
+ if (!input) {
264
+ return 'You must provide an input';
265
+ }
266
+ return regex.test(input) || "Please use only letters, '-', '_', and no spaces";
267
+ });
268
+
277
269
  const DEFAULT_TYPES = [
278
- // advanced types
279
- "media",
280
- // scalar types
281
- "string",
282
- "text",
283
- "richtext",
284
- "json",
285
- "enumeration",
286
- "password",
287
- "email",
288
- "integer",
289
- "biginteger",
290
- "float",
291
- "decimal",
292
- "date",
293
- "time",
294
- "datetime",
295
- "timestamp",
296
- "boolean"
270
+ // advanced types
271
+ 'media',
272
+ // scalar types
273
+ 'string',
274
+ 'text',
275
+ 'richtext',
276
+ 'json',
277
+ 'enumeration',
278
+ 'password',
279
+ 'email',
280
+ 'integer',
281
+ 'biginteger',
282
+ 'float',
283
+ 'decimal',
284
+ 'date',
285
+ 'time',
286
+ 'datetime',
287
+ 'timestamp',
288
+ 'boolean'
297
289
  ];
298
- const getAttributesPrompts = async (inquirer) => {
299
- const { addAttributes } = await inquirer.prompt([
300
- {
301
- type: "confirm",
302
- name: "addAttributes",
303
- message: "Do you want to add attributes?"
304
- }
305
- ]);
306
- const attributes = [];
307
- const createNewAttributes = async (inquirer2) => {
308
- const answers = await inquirer2.prompt([
309
- {
310
- type: "input",
311
- name: "attributeName",
312
- message: "Name of attribute",
313
- validate: (input) => validateAttributeInput(input)
314
- },
315
- {
316
- type: "list",
317
- name: "attributeType",
318
- message: "What type of attribute",
319
- pageSize: DEFAULT_TYPES.length,
320
- choices: DEFAULT_TYPES.map((type) => {
321
- return { name: type, value: type };
322
- })
323
- },
324
- {
325
- when: (answers2) => answers2.attributeType === "enumeration",
326
- type: "input",
327
- name: "enum",
328
- message: "Add values separated by a comma"
329
- },
330
- {
331
- when: (answers2) => answers2.attributeType === "media",
332
- type: "list",
333
- name: "multiple",
334
- message: "Choose media type",
335
- choices: [
336
- { name: "Multiple", value: true },
337
- { name: "Single", value: false }
338
- ]
339
- },
340
- {
341
- type: "confirm",
342
- name: "addAttributes",
343
- message: "Do you want to add another attribute?"
344
- }
290
+ const getAttributesPrompts = async (inquirer)=>{
291
+ const { addAttributes } = await inquirer.prompt([
292
+ {
293
+ type: 'confirm',
294
+ name: 'addAttributes',
295
+ message: 'Do you want to add attributes?'
296
+ }
345
297
  ]);
346
- attributes.push(answers);
347
- if (!answers.addAttributes) {
348
- return;
298
+ const attributes = [];
299
+ /**
300
+ * @param {import('inquirer').Inquirer} inquirer
301
+ * @returns {Promise<void>}
302
+ */ const createNewAttributes = async (inquirer)=>{
303
+ const answers = await inquirer.prompt([
304
+ {
305
+ type: 'input',
306
+ name: 'attributeName',
307
+ message: 'Name of attribute',
308
+ validate: (input)=>validateAttributeInput(input)
309
+ },
310
+ {
311
+ type: 'list',
312
+ name: 'attributeType',
313
+ message: 'What type of attribute',
314
+ pageSize: DEFAULT_TYPES.length,
315
+ choices: DEFAULT_TYPES.map((type)=>{
316
+ return {
317
+ name: type,
318
+ value: type
319
+ };
320
+ })
321
+ },
322
+ {
323
+ when: (answers)=>answers.attributeType === 'enumeration',
324
+ type: 'input',
325
+ name: 'enum',
326
+ message: 'Add values separated by a comma'
327
+ },
328
+ {
329
+ when: (answers)=>answers.attributeType === 'media',
330
+ type: 'list',
331
+ name: 'multiple',
332
+ message: 'Choose media type',
333
+ choices: [
334
+ {
335
+ name: 'Multiple',
336
+ value: true
337
+ },
338
+ {
339
+ name: 'Single',
340
+ value: false
341
+ }
342
+ ]
343
+ },
344
+ {
345
+ type: 'confirm',
346
+ name: 'addAttributes',
347
+ message: 'Do you want to add another attribute?'
348
+ }
349
+ ]);
350
+ attributes.push(answers);
351
+ if (!answers.addAttributes) {
352
+ return;
353
+ }
354
+ await createNewAttributes(inquirer);
355
+ };
356
+ if (addAttributes) {
357
+ await createNewAttributes(inquirer);
358
+ } else {
359
+ console.warn(`You won't be able to manage entries from the admin, you can still add attributes later from the content type builder.`);
349
360
  }
350
- await createNewAttributes(inquirer2);
351
- };
352
- if (addAttributes) {
353
- await createNewAttributes(inquirer);
354
- } else {
355
- console.warn(
356
- `You won't be able to manage entries from the admin, you can still add attributes later from the content type builder.`
357
- );
358
- }
359
- return attributes;
361
+ return attributes;
360
362
  };
363
+
361
364
  const questions = [
362
- {
363
- type: "confirm",
364
- name: "bootstrapApi",
365
- default: true,
366
- message: "Bootstrap API related files?"
367
- }
365
+ {
366
+ type: 'confirm',
367
+ name: 'bootstrapApi',
368
+ default: true,
369
+ message: 'Bootstrap API related files?'
370
+ }
368
371
  ];
369
- const generateContentType = (plop) => {
370
- plop.setGenerator("content-type", {
371
- description: "Generate a content type for an API",
372
- async prompts(inquirer) {
373
- const config = await inquirer.prompt([
374
- ...questions$3,
375
- ...questions$2,
376
- ...questions$1
377
- ]);
378
- const attributes = await getAttributesPrompts(inquirer);
379
- const api = await inquirer.prompt([
380
- ...getDestinationPrompts("model", plop.getDestBasePath()),
381
- {
382
- when: (answers) => answers.destination === "new",
383
- type: "input",
384
- name: "id",
385
- default: config.singularName,
386
- message: "Name of the new API?",
387
- async validate(input) {
388
- if (!utils__namespace.isKebabCase(input)) {
389
- return "Value must be in kebab-case";
372
+
373
+ var generateContentType = ((plop)=>{
374
+ // Model generator
375
+ plop.setGenerator('content-type', {
376
+ description: 'Generate a content type for an API',
377
+ async prompts (inquirer) {
378
+ const config = await inquirer.prompt([
379
+ ...questions$2,
380
+ ...questions$1
381
+ ]);
382
+ // @ts-expect-error issue with deprecated inquirer.prompts attribute to fix with ugprade to inquirer
383
+ const attributes = await getAttributesPrompts(inquirer);
384
+ const api = await inquirer.prompt([
385
+ ...getDestinationPrompts('model', plop.getDestBasePath()),
386
+ {
387
+ when: (answers)=>answers.destination === 'new',
388
+ type: 'input',
389
+ name: 'id',
390
+ default: config.singularName,
391
+ message: 'Name of the new API?',
392
+ async validate (input) {
393
+ if (!utils.strings.isKebabCase(input)) {
394
+ return 'Value must be in kebab-case';
395
+ }
396
+ const apiPath = path.join(plop.getDestBasePath(), 'api');
397
+ const exists = await fs.pathExists(apiPath);
398
+ if (!exists) {
399
+ return true;
400
+ }
401
+ const apiDir = await fs.readdir(apiPath, {
402
+ withFileTypes: true
403
+ });
404
+ const apiDirContent = apiDir.filter((fd)=>fd.isDirectory());
405
+ if (apiDirContent.findIndex((dir)=>dir.name === input) !== -1) {
406
+ throw new Error('This name is already taken.');
407
+ }
408
+ return true;
409
+ }
410
+ },
411
+ ...questions
412
+ ]);
413
+ return {
414
+ ...config,
415
+ ...api,
416
+ attributes
417
+ };
418
+ },
419
+ actions (answers) {
420
+ if (!answers) {
421
+ return [];
390
422
  }
391
- const apiPath = path.join(plop.getDestBasePath(), "api");
392
- const exists = await fs__default.default.pathExists(apiPath);
393
- if (!exists) {
394
- return true;
423
+ const attributes = answers.attributes.reduce((object, answer)=>{
424
+ const val = {
425
+ type: answer.attributeType
426
+ };
427
+ if (answer.attributeType === 'enumeration') {
428
+ val.enum = answer.enum.split(',').map((item)=>item.trim());
429
+ }
430
+ if (answer.attributeType === 'media') {
431
+ val.allowedTypes = [
432
+ 'images',
433
+ 'files',
434
+ 'videos',
435
+ 'audios'
436
+ ];
437
+ val.multiple = answer.multiple;
438
+ }
439
+ return Object.assign(object, {
440
+ [answer.attributeName]: val
441
+ }, {});
442
+ }, {});
443
+ const filePath = getFilePath(answers.destination);
444
+ const currentDir = process.cwd();
445
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
446
+ const baseActions = [
447
+ {
448
+ type: 'add',
449
+ path: `${filePath}/content-types/{{ singularName }}/schema.json`,
450
+ templateFile: `templates/${language}/content-type.schema.json.hbs`,
451
+ data: {
452
+ collectionName: slugify(answers.pluralName, {
453
+ separator: '_'
454
+ })
455
+ }
456
+ }
457
+ ];
458
+ if (Object.entries(attributes).length > 0) {
459
+ baseActions.push({
460
+ type: 'modify',
461
+ path: `${filePath}/content-types/{{ singularName }}/schema.json`,
462
+ transform (template) {
463
+ const parsedTemplate = JSON.parse(template);
464
+ parsedTemplate.attributes = attributes;
465
+ return JSON.stringify(parsedTemplate, null, 2);
466
+ }
467
+ });
395
468
  }
396
- const apiDir = await fs__default.default.readdir(apiPath, { withFileTypes: true });
397
- const apiDirContent = apiDir.filter((fd) => fd.isDirectory());
398
- if (apiDirContent.findIndex((dir) => dir.name === input) !== -1) {
399
- throw new Error("This name is already taken.");
469
+ if (answers.bootstrapApi) {
470
+ const { singularName } = answers;
471
+ let uid;
472
+ if (answers.destination === 'new') {
473
+ uid = `api::${answers.id}.${singularName}`;
474
+ } else if (answers.api) {
475
+ uid = `api::${answers.api}.${singularName}`;
476
+ } else if (answers.plugin) {
477
+ uid = `plugin::${answers.plugin}.${singularName}`;
478
+ }
479
+ baseActions.push({
480
+ type: 'add',
481
+ path: `${filePath}/controllers/{{ singularName }}.${language}`,
482
+ templateFile: `templates/${language}/core-controller.${language}.hbs`,
483
+ data: {
484
+ uid
485
+ }
486
+ }, {
487
+ type: 'add',
488
+ path: `${filePath}/services/{{ singularName }}.${language}`,
489
+ templateFile: `templates/${language}/core-service.${language}.hbs`,
490
+ data: {
491
+ uid
492
+ }
493
+ }, {
494
+ type: 'add',
495
+ path: `${filePath}/routes/{{ singularName }}.${language}`,
496
+ templateFile: `templates/${language}/core-router.${language}.hbs`,
497
+ data: {
498
+ uid
499
+ }
500
+ });
400
501
  }
401
- return true;
402
- }
403
- },
404
- ...questions
405
- ]);
406
- return {
407
- ...config,
408
- ...api,
409
- attributes
410
- };
411
- },
412
- actions(answers) {
413
- if (!answers) {
414
- return [];
415
- }
416
- const attributes = answers.attributes.reduce((object, answer) => {
417
- const val = { type: answer.attributeType };
418
- if (answer.attributeType === "enumeration") {
419
- val.enum = answer.enum.split(",").map((item) => item.trim());
420
- }
421
- if (answer.attributeType === "media") {
422
- val.allowedTypes = ["images", "files", "videos", "audios"];
423
- val.multiple = answer.multiple;
424
- }
425
- return Object.assign(object, { [answer.attributeName]: val }, {});
426
- }, {});
427
- const filePath = getFilePath(answers.destination);
428
- const currentDir = process.cwd();
429
- const language = tsUtils__default.default.isUsingTypeScriptSync(currentDir) ? "ts" : "js";
430
- const baseActions = [
431
- {
432
- type: "add",
433
- path: `${filePath}/content-types/{{ singularName }}/schema.json`,
434
- templateFile: `templates/${language}/content-type.schema.json.hbs`,
435
- data: {
436
- collectionName: slugify__default.default(answers.pluralName, { separator: "_" })
437
- }
502
+ return baseActions;
438
503
  }
439
- ];
440
- if (Object.entries(attributes).length > 0) {
441
- baseActions.push({
442
- type: "modify",
443
- path: `${filePath}/content-types/{{ singularName }}/schema.json`,
444
- transform(template) {
445
- const parsedTemplate = JSON.parse(template);
446
- parsedTemplate.attributes = attributes;
447
- return JSON.stringify(parsedTemplate, null, 2);
448
- }
449
- });
450
- }
451
- if (answers.bootstrapApi) {
452
- const { singularName } = answers;
453
- let uid;
454
- if (answers.destination === "new") {
455
- uid = `api::${answers.id}.${singularName}`;
456
- } else if (answers.api) {
457
- uid = `api::${answers.api}.${singularName}`;
458
- } else if (answers.plugin) {
459
- uid = `plugin::${answers.plugin}.${singularName}`;
460
- }
461
- baseActions.push(
462
- {
463
- type: "add",
464
- path: `${filePath}/controllers/{{ singularName }}.${language}`,
465
- templateFile: `templates/${language}/core-controller.${language}.hbs`,
466
- data: { uid }
467
- },
468
- {
469
- type: "add",
470
- path: `${filePath}/services/{{ singularName }}.${language}`,
471
- templateFile: `templates/${language}/core-service.${language}.hbs`,
472
- data: { uid }
473
- },
474
- {
475
- type: "add",
476
- path: `${filePath}/routes/{{ singularName }}.${language}`,
477
- templateFile: `templates/${language}/core-router.${language}.hbs`,
478
- data: { uid }
479
- }
480
- );
481
- }
482
- return baseActions;
483
- }
484
- });
485
- };
486
- const LANGUAGES = {
487
- javascript: "JavaScript",
488
- typescript: "TypeScript"
489
- };
490
- const logInstructions = (pluginName, { language }) => {
491
- const maxLength = ` resolve: './src/plugins/${pluginName}'`.length;
492
- const separator = Array(maxLength).fill("─").join("");
493
- const exportInstruction = language === "js" ? "module.exports =" : "export default";
494
- return `
495
- You can now enable your plugin by adding the following in ${chalk__default.default.yellow(
496
- `./config/plugins.${language}`
497
- )}
498
- ${separator}
499
- ${exportInstruction} {
500
- ${chalk__default.default.gray("// ...")}
501
- ${chalk__default.default.green(`'${pluginName}'`)}: {
502
- enabled: ${chalk__default.default.yellow(true)},
503
- resolve: ${chalk__default.default.yellow(`'./src/plugins/${pluginName}'`)}
504
- },
505
- ${chalk__default.default.gray("// ...")}
506
- }
507
- ${separator}
508
- `;
509
- };
510
- const generatePlugin = (plop) => {
511
- plop.setGenerator("plugin", {
512
- description: "Generate a basic plugin",
513
- prompts: [
514
- {
515
- type: "input",
516
- name: "pluginName",
517
- message: "Plugin name",
518
- validate: (input) => validateInput(input)
519
- },
520
- {
521
- type: "list",
522
- name: "language",
523
- message: "Choose your preferred language",
524
- choices: Object.values(LANGUAGES),
525
- default: LANGUAGES.javascript
526
- }
527
- ],
528
- actions(answers) {
529
- if (!answers) {
530
- return [];
531
- }
532
- const isTypescript = answers.language === LANGUAGES.typescript;
533
- const language = isTypescript ? "ts" : "js";
534
- const projectLanguage = tsUtils__default.default.isUsingTypeScriptSync(process.cwd()) ? "ts" : "js";
535
- if (!utils__namespace.isKebabCase(answers.pluginName)) {
536
- answers.pluginName = utils__namespace.toKebabCase(answers.pluginName);
537
- console.log(
538
- chalk__default.default.yellow(
539
- `Strapi only supports kebab-cased names for plugins.
540
- Your plugin has been automatically renamed to "${answers.pluginName}".`
541
- )
542
- );
543
- }
544
- return [
545
- {
546
- type: "addMany",
547
- destination: "plugins/{{ pluginName }}",
548
- base: `files/${language}/plugin`,
549
- templateFiles: `files/${language}/plugin/**`
550
- },
551
- {
552
- type: "add",
553
- path: "plugins/{{ pluginName }}/README.md",
554
- templateFile: `templates/${language}/README.md.hbs`
555
- },
556
- {
557
- type: "add",
558
- path: "plugins/{{ pluginName }}/package.json",
559
- templateFile: `templates/${language}/plugin-package.json.hbs`
560
- },
561
- () => plop.renderString(
562
- logInstructions(answers.pluginName, { language: projectLanguage }),
563
- null
564
- )
565
- ];
566
- }
567
- });
568
- };
569
- const generatePolicy = (plop) => {
570
- plop.setGenerator("policy", {
571
- description: "Generate a policy for an API",
572
- prompts: [
573
- {
574
- type: "input",
575
- name: "id",
576
- message: "Policy name",
577
- validate: (input) => validateInput(input)
578
- },
579
- ...getDestinationPrompts("policy", plop.getDestBasePath(), { rootFolder: true })
580
- ],
581
- actions(answers) {
582
- if (!answers) {
583
- return [];
584
- }
585
- const filePath = getFilePath(answers.destination);
586
- const currentDir = process.cwd();
587
- const language = tsUtils__default.default.isUsingTypeScriptSync(currentDir) ? "ts" : "js";
588
- return [
589
- {
590
- type: "add",
591
- path: `${filePath}/policies/{{ id }}.${language}`,
592
- templateFile: `templates/${language}/policy.${language}.hbs`
504
+ });
505
+ });
506
+
507
+ var generatePolicy = ((plop)=>{
508
+ // Policy generator
509
+ plop.setGenerator('policy', {
510
+ description: 'Generate a policy for an API',
511
+ prompts: [
512
+ {
513
+ type: 'input',
514
+ name: 'id',
515
+ message: 'Policy name',
516
+ validate: (input)=>validateInput(input)
517
+ },
518
+ ...getDestinationPrompts('policy', plop.getDestBasePath(), {
519
+ rootFolder: true
520
+ })
521
+ ],
522
+ actions (answers) {
523
+ if (!answers) {
524
+ return [];
525
+ }
526
+ const currentDir = process.cwd();
527
+ const filePath = getFilePath(answers.destination);
528
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
529
+ return [
530
+ {
531
+ type: 'add',
532
+ path: `${filePath}/policies/{{ id }}.${language}`,
533
+ templateFile: `templates/${language}/policy.${language}.hbs`
534
+ }
535
+ ];
593
536
  }
594
- ];
595
- }
596
- });
597
- };
598
- const generateMiddleware = (plop) => {
599
- plop.setGenerator("middleware", {
600
- description: "Generate a middleware for an API",
601
- prompts: [
602
- {
603
- type: "input",
604
- name: "name",
605
- message: "Middleware name",
606
- validate: (input) => validateInput(input)
607
- },
608
- ...getDestinationPrompts("middleware", plop.getDestBasePath(), { rootFolder: true })
609
- ],
610
- actions(answers) {
611
- if (!answers) {
612
- return [];
613
- }
614
- const filePath = getFilePath(answers.destination);
615
- const currentDir = process.cwd();
616
- const language = tsUtils__default.default.isUsingTypeScriptSync(currentDir) ? "ts" : "js";
617
- return [
618
- {
619
- type: "add",
620
- path: `${filePath}/middlewares/{{ name }}.${language}`,
621
- templateFile: `templates/${language}/middleware.${language}.hbs`
537
+ });
538
+ });
539
+
540
+ var generateMiddleware = ((plop)=>{
541
+ // middleware generator
542
+ plop.setGenerator('middleware', {
543
+ description: 'Generate a middleware for an API',
544
+ prompts: [
545
+ {
546
+ type: 'input',
547
+ name: 'name',
548
+ message: 'Middleware name',
549
+ validate: (input)=>validateInput(input)
550
+ },
551
+ ...getDestinationPrompts('middleware', plop.getDestBasePath(), {
552
+ rootFolder: true
553
+ })
554
+ ],
555
+ actions (answers) {
556
+ if (!answers) {
557
+ return [];
558
+ }
559
+ const filePath = getFilePath(answers.destination);
560
+ const currentDir = process.cwd();
561
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
562
+ return [
563
+ {
564
+ type: 'add',
565
+ path: `${filePath}/middlewares/{{ name }}.${language}`,
566
+ templateFile: `templates/${language}/middleware.${language}.hbs`
567
+ }
568
+ ];
622
569
  }
623
- ];
570
+ });
571
+ });
572
+
573
+ var validateFileNameInput = ((input)=>{
574
+ const regex = /^[A-Za-z-_0-9]+$/g;
575
+ if (!input) {
576
+ return 'You must provide an input';
624
577
  }
625
- });
626
- };
627
- const validateFileNameInput = (input) => {
628
- const regex = /^[A-Za-z-_0-9]+$/g;
629
- if (!input) {
630
- return "You must provide an input";
631
- }
632
- return regex.test(input) || "Please use only letters and number, '-' or '_' and no spaces";
633
- };
634
- const getFormattedDate = (date = /* @__PURE__ */ new Date()) => {
635
- return new Date(date.getTime() - date.getTimezoneOffset() * 6e4).toJSON().replace(/[-:]/g, ".").replace(/\....Z/, "");
636
- };
637
- const generateMigration = (plop) => {
638
- plop.setGenerator("migration", {
639
- description: "Generate a migration",
640
- prompts: [
641
- {
642
- type: "input",
643
- name: "name",
644
- message: "Migration name",
645
- validate: (input) => validateFileNameInput(input)
646
- }
647
- ],
648
- actions() {
649
- const currentDir = process.cwd();
650
- const language = tsUtils__default.default.isUsingTypeScriptSync(currentDir) ? "ts" : "js";
651
- const timestamp = getFormattedDate();
652
- return [
653
- {
654
- type: "add",
655
- path: `${currentDir}/database/migrations/${timestamp}.{{ name }}.${language}`,
656
- templateFile: `templates/${language}/migration.${language}.hbs`
578
+ return regex.test(input) || "Please use only letters and number, '-' or '_' and no spaces";
579
+ });
580
+
581
+ var getFormattedDate = ((date = new Date())=>{
582
+ return new Date(date.getTime() - date.getTimezoneOffset() * 60000).toJSON().replace(/[-:]/g, '.').replace(/\....Z/, '');
583
+ });
584
+
585
+ var generateMigration = ((plop)=>{
586
+ // Migration generator
587
+ plop.setGenerator('migration', {
588
+ description: 'Generate a migration',
589
+ prompts: [
590
+ {
591
+ type: 'input',
592
+ name: 'name',
593
+ message: 'Migration name',
594
+ validate: (input)=>validateFileNameInput(input)
595
+ }
596
+ ],
597
+ actions () {
598
+ const currentDir = process.cwd();
599
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
600
+ const timestamp = getFormattedDate();
601
+ return [
602
+ {
603
+ type: 'add',
604
+ path: `${currentDir}/database/migrations/${timestamp}.{{ name }}.${language}`,
605
+ templateFile: `templates/${language}/migration.${language}.hbs`
606
+ }
607
+ ];
657
608
  }
658
- ];
659
- }
660
- });
661
- };
662
- const generateService = (plop) => {
663
- plop.setGenerator("service", {
664
- description: "Generate a service for an API",
665
- prompts: [
666
- {
667
- type: "input",
668
- name: "id",
669
- message: "Service name"
670
- },
671
- ...getDestinationPrompts("service", plop.getDestBasePath())
672
- ],
673
- actions(answers) {
674
- if (!answers) {
675
- return [];
676
- }
677
- const filePath = getFilePath(answers?.destination);
678
- const currentDir = process.cwd();
679
- const language = tsUtils__default.default.isUsingTypeScriptSync(currentDir) ? "ts" : "js";
680
- return [
681
- {
682
- type: "add",
683
- path: `${filePath}/services/{{ id }}.${language}`,
684
- templateFile: `templates/${language}/service.${language}.hbs`
609
+ });
610
+ });
611
+
612
+ var generateService = ((plop)=>{
613
+ // Service generator
614
+ plop.setGenerator('service', {
615
+ description: 'Generate a service for an API',
616
+ prompts: [
617
+ {
618
+ type: 'input',
619
+ name: 'id',
620
+ message: 'Service name'
621
+ },
622
+ ...getDestinationPrompts('service', plop.getDestBasePath())
623
+ ],
624
+ actions (answers) {
625
+ if (!answers) {
626
+ return [];
627
+ }
628
+ const filePath = getFilePath(answers?.destination);
629
+ const currentDir = process.cwd();
630
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
631
+ return [
632
+ {
633
+ type: 'add',
634
+ path: `${filePath}/services/{{ id }}.${language}`,
635
+ templateFile: `templates/${language}/service.${language}.hbs`
636
+ }
637
+ ];
685
638
  }
686
- ];
687
- }
688
- });
689
- };
690
- const plopfile = (plop) => {
691
- plop.setWelcomeMessage("Strapi Generators");
692
- plop.addHelper("pluralize", (text) => pluralize__default.default(text));
693
- generateApi(plop);
694
- generateController(plop);
695
- generateContentType(plop);
696
- generatePlugin(plop);
697
- generatePolicy(plop);
698
- generateMiddleware(plop);
699
- generateMigration(plop);
700
- generateService(plop);
701
- };
639
+ });
640
+ });
641
+
642
+ var plopfile = ((plop)=>{
643
+ // Plop config
644
+ plop.setWelcomeMessage('Strapi Generators');
645
+ plop.setHelper('pluralize', (text)=>pluralize(text));
646
+ // Generators
647
+ generateApi(plop);
648
+ generateController(plop);
649
+ generateContentType(plop);
650
+ generatePolicy(plop);
651
+ generateMiddleware(plop);
652
+ generateMigration(plop);
653
+ generateService(plop);
654
+ });
655
+
702
656
  module.exports = plopfile;
703
657
  //# sourceMappingURL=plopfile.js.map