@strapi/generators 0.0.0-next.ff946d2c25a3e577b47132a357cac2932eb8e635 → 0.0.0-next.ffc36acb308febe288f1a31b62cbbb75b286585c

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 (184) hide show
  1. package/LICENSE +18 -3
  2. package/dist/index.d.ts +10 -5
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +93 -27
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +95 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/dist/plopfile.d.ts +2 -1
  9. package/dist/plopfile.d.ts.map +1 -0
  10. package/dist/plopfile.js +24 -26
  11. package/dist/plopfile.js.map +1 -1
  12. package/dist/plopfile.mjs +25 -0
  13. package/dist/plopfile.mjs.map +1 -0
  14. package/dist/plops/api.d.ts +2 -1
  15. package/dist/plops/api.d.ts.map +1 -0
  16. package/dist/plops/api.js +33 -31
  17. package/dist/plops/api.js.map +1 -1
  18. package/dist/plops/api.mjs +79 -0
  19. package/dist/plops/api.mjs.map +1 -0
  20. package/dist/plops/content-type.d.ts +2 -1
  21. package/dist/plops/content-type.d.ts.map +1 -0
  22. package/dist/plops/content-type.js +73 -59
  23. package/dist/plops/content-type.js.map +1 -1
  24. package/dist/plops/content-type.mjs +147 -0
  25. package/dist/plops/content-type.mjs.map +1 -0
  26. package/dist/plops/controller.d.ts +2 -1
  27. package/dist/plops/controller.d.ts.map +1 -0
  28. package/dist/plops/controller.js +20 -20
  29. package/dist/plops/controller.js.map +1 -1
  30. package/dist/plops/controller.mjs +38 -0
  31. package/dist/plops/controller.mjs.map +1 -0
  32. package/dist/plops/middleware.d.ts +2 -1
  33. package/dist/plops/middleware.d.ts.map +1 -0
  34. package/dist/plops/middleware.js +22 -20
  35. package/dist/plops/middleware.js.map +1 -1
  36. package/dist/plops/middleware.mjs +40 -0
  37. package/dist/plops/middleware.mjs.map +1 -0
  38. package/dist/plops/migration.d.ts +2 -1
  39. package/dist/plops/migration.d.ts.map +1 -0
  40. package/dist/plops/migration.js +19 -19
  41. package/dist/plops/migration.js.map +1 -1
  42. package/dist/plops/migration.mjs +33 -0
  43. package/dist/plops/migration.mjs.map +1 -0
  44. package/dist/plops/policy.d.ts +2 -1
  45. package/dist/plops/policy.d.ts.map +1 -0
  46. package/dist/plops/policy.js +22 -20
  47. package/dist/plops/policy.js.map +1 -1
  48. package/dist/plops/policy.mjs +40 -0
  49. package/dist/plops/policy.mjs.map +1 -0
  50. package/dist/plops/prompts/bootstrap-api-prompts.d.ts +7 -2
  51. package/dist/plops/prompts/bootstrap-api-prompts.d.ts.map +1 -0
  52. package/dist/plops/prompts/bootstrap-api-prompts.js +7 -6
  53. package/dist/plops/prompts/bootstrap-api-prompts.js.map +1 -1
  54. package/dist/plops/prompts/bootstrap-api-prompts.mjs +11 -0
  55. package/dist/plops/prompts/bootstrap-api-prompts.mjs.map +1 -0
  56. package/dist/plops/prompts/ct-names-prompts.d.ts +19 -2
  57. package/dist/plops/prompts/ct-names-prompts.d.ts.map +1 -0
  58. package/dist/plops/prompts/ct-names-prompts.js +19 -20
  59. package/dist/plops/prompts/ct-names-prompts.js.map +1 -1
  60. package/dist/plops/prompts/ct-names-prompts.mjs +42 -0
  61. package/dist/plops/prompts/ct-names-prompts.mjs.map +1 -0
  62. package/dist/plops/prompts/get-attributes-prompts.d.ts +9 -2
  63. package/dist/plops/prompts/get-attributes-prompts.d.ts.map +1 -0
  64. package/dist/plops/prompts/get-attributes-prompts.js +36 -30
  65. package/dist/plops/prompts/get-attributes-prompts.js.map +1 -1
  66. package/dist/plops/prompts/get-attributes-prompts.mjs +99 -0
  67. package/dist/plops/prompts/get-attributes-prompts.mjs.map +1 -0
  68. package/dist/plops/prompts/get-destination-prompts.d.ts +25 -2
  69. package/dist/plops/prompts/get-destination-prompts.d.ts.map +1 -0
  70. package/dist/plops/prompts/get-destination-prompts.js +47 -41
  71. package/dist/plops/prompts/get-destination-prompts.js.map +1 -1
  72. package/dist/plops/prompts/get-destination-prompts.mjs +76 -0
  73. package/dist/plops/prompts/get-destination-prompts.mjs.map +1 -0
  74. package/dist/plops/prompts/kind-prompts.d.ts +12 -2
  75. package/dist/plops/prompts/kind-prompts.d.ts.map +1 -0
  76. package/dist/plops/prompts/kind-prompts.js +17 -12
  77. package/dist/plops/prompts/kind-prompts.js.map +1 -1
  78. package/dist/plops/prompts/kind-prompts.mjs +24 -0
  79. package/dist/plops/prompts/kind-prompts.mjs.map +1 -0
  80. package/dist/plops/service.d.ts +2 -1
  81. package/dist/plops/service.d.ts.map +1 -0
  82. package/dist/plops/service.js +19 -19
  83. package/dist/plops/service.js.map +1 -1
  84. package/dist/plops/service.mjs +36 -0
  85. package/dist/plops/service.mjs.map +1 -0
  86. package/dist/plops/utils/get-file-path.d.ts +2 -1
  87. package/dist/plops/utils/get-file-path.d.ts.map +1 -0
  88. package/dist/plops/utils/get-file-path.js +7 -5
  89. package/dist/plops/utils/get-file-path.js.map +1 -1
  90. package/dist/plops/utils/get-file-path.mjs +15 -0
  91. package/dist/plops/utils/get-file-path.mjs.map +1 -0
  92. package/dist/plops/utils/get-formatted-date.d.ts +1 -0
  93. package/dist/plops/utils/get-formatted-date.d.ts.map +1 -0
  94. package/dist/plops/utils/get-formatted-date.js +8 -9
  95. package/dist/plops/utils/get-formatted-date.js.map +1 -1
  96. package/dist/plops/utils/get-formatted-date.mjs +6 -0
  97. package/dist/plops/utils/get-formatted-date.mjs.map +1 -0
  98. package/dist/plops/utils/validate-attribute-input.d.ts +1 -0
  99. package/dist/plops/utils/validate-attribute-input.d.ts.map +1 -0
  100. package/dist/plops/utils/validate-attribute-input.js +7 -5
  101. package/dist/plops/utils/validate-attribute-input.js.map +1 -1
  102. package/dist/plops/utils/validate-attribute-input.mjs +10 -0
  103. package/dist/plops/utils/validate-attribute-input.mjs.map +1 -0
  104. package/dist/plops/utils/validate-file-name-input.d.ts +1 -0
  105. package/dist/plops/utils/validate-file-name-input.d.ts.map +1 -0
  106. package/dist/plops/utils/validate-file-name-input.js +7 -5
  107. package/dist/plops/utils/validate-file-name-input.js.map +1 -1
  108. package/dist/plops/utils/validate-file-name-input.mjs +10 -0
  109. package/dist/plops/utils/validate-file-name-input.mjs.map +1 -0
  110. package/dist/plops/utils/validate-input.d.ts +1 -0
  111. package/dist/plops/utils/validate-input.d.ts.map +1 -0
  112. package/dist/plops/utils/validate-input.js +7 -5
  113. package/dist/plops/utils/validate-input.js.map +1 -1
  114. package/dist/plops/utils/validate-input.mjs +10 -0
  115. package/dist/plops/utils/validate-input.mjs.map +1 -0
  116. package/dist/templates/js/content-type.schema.json.hbs +0 -1
  117. package/dist/templates/ts/content-type.schema.json.hbs +0 -1
  118. package/dist/templates/ts/middleware.ts.hbs +2 -2
  119. package/package.json +21 -17
  120. package/dist/files/js/plugin/.editorconfig +0 -7
  121. package/dist/files/js/plugin/.gitattributes +0 -103
  122. package/dist/files/js/plugin/admin/src/components/Initializer/index.js +0 -26
  123. package/dist/files/js/plugin/admin/src/components/PluginIcon/index.js +0 -12
  124. package/dist/files/js/plugin/admin/src/index.js +0 -63
  125. package/dist/files/js/plugin/admin/src/pages/App/index.js +0 -25
  126. package/dist/files/js/plugin/admin/src/pages/HomePage/index.js +0 -20
  127. package/dist/files/js/plugin/admin/src/pluginId.js +0 -5
  128. package/dist/files/js/plugin/admin/src/translations/en.json +0 -1
  129. package/dist/files/js/plugin/admin/src/translations/fr.json +0 -1
  130. package/dist/files/js/plugin/admin/src/utils/getTrad.js +0 -5
  131. package/dist/files/js/plugin/server/bootstrap.js +0 -5
  132. package/dist/files/js/plugin/server/config/index.js +0 -6
  133. package/dist/files/js/plugin/server/content-types/index.js +0 -3
  134. package/dist/files/js/plugin/server/controllers/index.js +0 -7
  135. package/dist/files/js/plugin/server/controllers/my-controller.js.hbs +0 -10
  136. package/dist/files/js/plugin/server/destroy.js +0 -5
  137. package/dist/files/js/plugin/server/index.js +0 -25
  138. package/dist/files/js/plugin/server/middlewares/index.js +0 -3
  139. package/dist/files/js/plugin/server/policies/index.js +0 -3
  140. package/dist/files/js/plugin/server/register.js +0 -5
  141. package/dist/files/js/plugin/server/routes/index.js +0 -10
  142. package/dist/files/js/plugin/server/services/index.js +0 -7
  143. package/dist/files/js/plugin/server/services/my-service.js +0 -7
  144. package/dist/files/js/plugin/strapi-admin.js +0 -3
  145. package/dist/files/js/plugin/strapi-server.js +0 -3
  146. package/dist/files/ts/plugin/.editorconfig +0 -7
  147. package/dist/files/ts/plugin/.gitattributes +0 -103
  148. package/dist/files/ts/plugin/admin/src/components/Initializer/index.tsx +0 -24
  149. package/dist/files/ts/plugin/admin/src/components/PluginIcon/index.tsx +0 -12
  150. package/dist/files/ts/plugin/admin/src/index.tsx +0 -67
  151. package/dist/files/ts/plugin/admin/src/pages/App/index.tsx +0 -25
  152. package/dist/files/ts/plugin/admin/src/pages/HomePage/index.tsx +0 -19
  153. package/dist/files/ts/plugin/admin/src/pluginId.ts +0 -5
  154. package/dist/files/ts/plugin/admin/src/translations/en.json +0 -1
  155. package/dist/files/ts/plugin/admin/src/translations/fr.json +0 -1
  156. package/dist/files/ts/plugin/admin/src/utils/getTrad.ts +0 -5
  157. package/dist/files/ts/plugin/custom.d.ts +0 -5
  158. package/dist/files/ts/plugin/server/bootstrap.ts +0 -5
  159. package/dist/files/ts/plugin/server/config/index.ts +0 -4
  160. package/dist/files/ts/plugin/server/content-types/index.ts +0 -1
  161. package/dist/files/ts/plugin/server/controllers/index.ts +0 -5
  162. package/dist/files/ts/plugin/server/controllers/my-controller.ts.hbs +0 -10
  163. package/dist/files/ts/plugin/server/destroy.ts +0 -5
  164. package/dist/files/ts/plugin/server/index.ts +0 -23
  165. package/dist/files/ts/plugin/server/middlewares/index.ts +0 -1
  166. package/dist/files/ts/plugin/server/policies/index.ts +0 -1
  167. package/dist/files/ts/plugin/server/register.ts +0 -5
  168. package/dist/files/ts/plugin/server/routes/index.ts +0 -10
  169. package/dist/files/ts/plugin/server/services/index.ts +0 -5
  170. package/dist/files/ts/plugin/server/services/my-service.ts +0 -7
  171. package/dist/files/ts/plugin/strapi-admin.js +0 -3
  172. package/dist/files/ts/plugin/strapi-server.js +0 -3
  173. package/dist/files/ts/plugin/tsconfig.json +0 -20
  174. package/dist/files/ts/plugin/tsconfig.server.json +0 -25
  175. package/dist/plops/plugin.d.ts +0 -3
  176. package/dist/plops/plugin.js +0 -84
  177. package/dist/plops/plugin.js.map +0 -1
  178. package/dist/plops/prompts/draft-and-publish-prompts.d.ts +0 -3
  179. package/dist/plops/prompts/draft-and-publish-prompts.js +0 -12
  180. package/dist/plops/prompts/draft-and-publish-prompts.js.map +0 -1
  181. package/dist/templates/js/README.md.hbs +0 -3
  182. package/dist/templates/js/plugin-package.json.hbs +0 -42
  183. package/dist/templates/ts/README.md.hbs +0 -3
  184. package/dist/templates/ts/plugin-package.json.hbs +0 -51
@@ -0,0 +1,79 @@
1
+ import { join } from 'path';
2
+ import fs from 'fs-extra';
3
+ import tsUtils from '@strapi/typescript-utils';
4
+ import validateInput from './utils/validate-input.mjs';
5
+
6
+ var generateApi = ((plop)=>{
7
+ // API generator
8
+ plop.setGenerator('api', {
9
+ description: 'Generate a basic API',
10
+ prompts: [
11
+ {
12
+ type: 'input',
13
+ name: 'id',
14
+ message: 'API name',
15
+ validate: (input)=>validateInput(input)
16
+ },
17
+ {
18
+ type: 'confirm',
19
+ name: 'isPluginApi',
20
+ message: 'Is this API for a plugin?'
21
+ },
22
+ {
23
+ when: (answers)=>answers.isPluginApi,
24
+ type: 'list',
25
+ name: 'plugin',
26
+ message: 'Plugin name',
27
+ async choices () {
28
+ const pluginsPath = join(plop.getDestBasePath(), 'plugins');
29
+ const exists = await fs.pathExists(pluginsPath);
30
+ if (!exists) {
31
+ throw Error('Couldn\'t find a "plugins" directory');
32
+ }
33
+ const pluginsDir = await fs.readdir(pluginsPath, {
34
+ withFileTypes: true
35
+ });
36
+ const pluginsDirContent = pluginsDir.filter((fd)=>fd.isDirectory());
37
+ if (pluginsDirContent.length === 0) {
38
+ throw Error('The "plugins" directory is empty');
39
+ }
40
+ return pluginsDirContent;
41
+ }
42
+ }
43
+ ],
44
+ actions (answers) {
45
+ if (!answers) {
46
+ return [];
47
+ }
48
+ const filePath = answers.isPluginApi && answers.plugin ? 'plugins/{{ plugin }}/server' : 'api/{{ id }}';
49
+ const currentDir = process.cwd();
50
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
51
+ const baseActions = [
52
+ {
53
+ type: 'add',
54
+ path: `${filePath}/controllers/{{ id }}.${language}`,
55
+ templateFile: `templates/${language}/controller.${language}.hbs`
56
+ },
57
+ {
58
+ type: 'add',
59
+ path: `${filePath}/services/{{ id }}.${language}`,
60
+ templateFile: `templates/${language}/service.${language}.hbs`
61
+ }
62
+ ];
63
+ if (answers.isPluginApi) {
64
+ return baseActions;
65
+ }
66
+ return [
67
+ {
68
+ type: 'add',
69
+ path: `${filePath}/routes/{{ id }}.${language}`,
70
+ templateFile: `templates/${language}/single-route.${language}.hbs`
71
+ },
72
+ ...baseActions
73
+ ];
74
+ }
75
+ });
76
+ });
77
+
78
+ export { generateApi as default };
79
+ //# sourceMappingURL=api.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.mjs","sources":["../../src/plops/api.ts"],"sourcesContent":["import { join } from 'path';\nimport type { NodePlopAPI } from 'plop';\nimport fs from 'fs-extra';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport validateInput from './utils/validate-input';\n\nexport default (plop: NodePlopAPI) => {\n // API generator\n plop.setGenerator('api', {\n description: 'Generate a basic API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'API name',\n validate: (input) => validateInput(input),\n },\n {\n type: 'confirm',\n name: 'isPluginApi',\n message: 'Is this API for a plugin?',\n },\n {\n when: (answers) => answers.isPluginApi,\n type: 'list',\n name: 'plugin',\n message: 'Plugin name',\n async choices() {\n const pluginsPath = join(plop.getDestBasePath(), 'plugins');\n const exists = await fs.pathExists(pluginsPath);\n if (!exists) {\n throw Error('Couldn\\'t find a \"plugins\" directory');\n }\n\n const pluginsDir = await fs.readdir(pluginsPath, { withFileTypes: true });\n const pluginsDirContent = pluginsDir.filter((fd) => fd.isDirectory());\n\n if (pluginsDirContent.length === 0) {\n throw Error('The \"plugins\" directory is empty');\n }\n\n return pluginsDirContent;\n },\n },\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath =\n answers.isPluginApi && answers.plugin ? 'plugins/{{ plugin }}/server' : 'api/{{ id }}';\n const currentDir = process.cwd();\n const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n const baseActions = [\n {\n type: 'add',\n path: `${filePath}/controllers/{{ id }}.${language}`,\n templateFile: `templates/${language}/controller.${language}.hbs`,\n },\n {\n type: 'add',\n path: `${filePath}/services/{{ id }}.${language}`,\n templateFile: `templates/${language}/service.${language}.hbs`,\n },\n ];\n\n if (answers.isPluginApi) {\n return baseActions;\n }\n\n return [\n {\n type: 'add',\n path: `${filePath}/routes/{{ id }}.${language}`,\n templateFile: `templates/${language}/single-route.${language}.hbs`,\n },\n ...baseActions,\n ];\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","when","answers","isPluginApi","choices","pluginsPath","join","getDestBasePath","exists","fs","pathExists","Error","pluginsDir","readdir","withFileTypes","pluginsDirContent","filter","fd","isDirectory","length","actions","filePath","plugin","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","baseActions","path","templateFile"],"mappings":";;;;;AAOA,kBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,KAAO,EAAA;QACvBC,WAAa,EAAA,sBAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,IAAA;gBACNC,OAAS,EAAA,UAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,aAAcD,CAAAA,KAAAA;AACrC,aAAA;AAC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cAAc,IAAO,GAAA,IAAA;AAEpE,YAAA,MAAMM,WAAc,GAAA;AAClB,gBAAA;oBACElC,IAAM,EAAA,KAAA;AACNmC,oBAAAA,IAAAA,EAAM,CAAC,EAAET,QAAAA,CAAS,sBAAsB,EAAEK,SAAS,CAAC;oBACpDK,YAAc,EAAA,CAAC,UAAU,EAAEL,QAAAA,CAAS,YAAY,EAAEA,QAAAA,CAAS,IAAI;AACjE,iBAAA;AACA,gBAAA;oBACE/B,IAAM,EAAA,KAAA;AACNmC,oBAAAA,IAAAA,EAAM,CAAC,EAAET,QAAAA,CAAS,mBAAmB,EAAEK,SAAS,CAAC;oBACjDK,YAAc,EAAA,CAAC,UAAU,EAAEL,QAAAA,CAAS,SAAS,EAAEA,QAAAA,CAAS,IAAI;AAC9D;AACD,aAAA;YAED,IAAIxB,OAAAA,CAAQC,WAAW,EAAE;gBACvB,OAAO0B,WAAAA;AACT;YAEA,OAAO;AACL,gBAAA;oBACElC,IAAM,EAAA,KAAA;AACNmC,oBAAAA,IAAAA,EAAM,CAAC,EAAET,QAAAA,CAAS,iBAAiB,EAAEK,SAAS,CAAC;oBAC/CK,YAAc,EAAA,CAAC,UAAU,EAAEL,QAAAA,CAAS,cAAc,EAAEA,QAAAA,CAAS,IAAI;AACnE,iBAAA;AACGG,gBAAAA,GAAAA;AACJ,aAAA;AACH;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
@@ -1,3 +1,4 @@
1
- import { NodePlopAPI } from 'plop';
1
+ import type { NodePlopAPI } from 'plop';
2
2
  declare const _default: (plop: NodePlopAPI) => void;
3
3
  export default _default;
4
+ //# sourceMappingURL=content-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-type.d.ts","sourceRoot":"","sources":["../../src/plops/content-type.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAc,MAAM,MAAM,CAAC;+BAa9B,WAAW;AAAjC,wBAmIE"}
@@ -1,102 +1,110 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const path_1 = require("path");
7
- const slugify_1 = __importDefault(require("@sindresorhus/slugify"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const utils_1 = __importDefault(require("@strapi/utils"));
10
- const typescript_utils_1 = __importDefault(require("@strapi/typescript-utils"));
11
- const get_destination_prompts_1 = __importDefault(require("./prompts/get-destination-prompts"));
12
- const get_file_path_1 = __importDefault(require("./utils/get-file-path"));
13
- const ct_names_prompts_1 = __importDefault(require("./prompts/ct-names-prompts"));
14
- const kind_prompts_1 = __importDefault(require("./prompts/kind-prompts"));
15
- const draft_and_publish_prompts_1 = __importDefault(require("./prompts/draft-and-publish-prompts"));
16
- const get_attributes_prompts_1 = __importDefault(require("./prompts/get-attributes-prompts"));
17
- const bootstrap_api_prompts_1 = __importDefault(require("./prompts/bootstrap-api-prompts"));
18
- exports.default = (plop) => {
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var slugify = require('@sindresorhus/slugify');
5
+ var fs = require('fs-extra');
6
+ var utils = require('@strapi/utils');
7
+ var tsUtils = require('@strapi/typescript-utils');
8
+ var getDestinationPrompts = require('./prompts/get-destination-prompts.js');
9
+ var getFilePath = require('./utils/get-file-path.js');
10
+ var ctNamesPrompts = require('./prompts/ct-names-prompts.js');
11
+ var kindPrompts = require('./prompts/kind-prompts.js');
12
+ var getAttributesPrompts = require('./prompts/get-attributes-prompts.js');
13
+ var bootstrapApiPrompts = require('./prompts/bootstrap-api-prompts.js');
14
+
15
+ var generateContentType = ((plop)=>{
19
16
  // Model generator
20
17
  plop.setGenerator('content-type', {
21
18
  description: 'Generate a content type for an API',
22
- async prompts(inquirer) {
19
+ async prompts (inquirer) {
23
20
  const config = await inquirer.prompt([
24
- ...ct_names_prompts_1.default,
25
- ...kind_prompts_1.default,
26
- ...draft_and_publish_prompts_1.default,
21
+ ...ctNamesPrompts,
22
+ ...kindPrompts
27
23
  ]);
28
- const attributes = await (0, get_attributes_prompts_1.default)(inquirer);
24
+ const attributes = await getAttributesPrompts(inquirer);
29
25
  const api = await inquirer.prompt([
30
- ...(0, get_destination_prompts_1.default)('model', plop.getDestBasePath()),
26
+ ...getDestinationPrompts('model', plop.getDestBasePath()),
31
27
  {
32
- when: (answers) => answers.destination === 'new',
28
+ when: (answers)=>answers.destination === 'new',
33
29
  type: 'input',
34
30
  name: 'id',
35
31
  default: config.singularName,
36
32
  message: 'Name of the new API?',
37
- async validate(input) {
38
- if (!utils_1.default.isKebabCase(input)) {
33
+ async validate (input) {
34
+ if (!utils.strings.isKebabCase(input)) {
39
35
  return 'Value must be in kebab-case';
40
36
  }
41
- const apiPath = (0, path_1.join)(plop.getDestBasePath(), 'api');
42
- const exists = await fs_extra_1.default.pathExists(apiPath);
37
+ const apiPath = path.join(plop.getDestBasePath(), 'api');
38
+ const exists = await fs.pathExists(apiPath);
43
39
  if (!exists) {
44
40
  return true;
45
41
  }
46
- const apiDir = await fs_extra_1.default.readdir(apiPath, { withFileTypes: true });
47
- const apiDirContent = apiDir.filter((fd) => fd.isDirectory());
48
- if (apiDirContent.findIndex((dir) => dir.name === input) !== -1) {
42
+ const apiDir = await fs.readdir(apiPath, {
43
+ withFileTypes: true
44
+ });
45
+ const apiDirContent = apiDir.filter((fd)=>fd.isDirectory());
46
+ if (apiDirContent.findIndex((dir)=>dir.name === input) !== -1) {
49
47
  throw new Error('This name is already taken.');
50
48
  }
51
49
  return true;
52
- },
50
+ }
53
51
  },
54
- ...bootstrap_api_prompts_1.default,
52
+ ...bootstrapApiPrompts
55
53
  ]);
56
54
  return {
57
55
  ...config,
58
56
  ...api,
59
- attributes,
57
+ attributes
60
58
  };
61
59
  },
62
- actions(answers) {
60
+ actions (answers) {
63
61
  if (!answers) {
64
62
  return [];
65
63
  }
66
- const attributes = answers.attributes.reduce((object, answer) => {
67
- const val = { type: answer.attributeType };
64
+ const attributes = answers.attributes.reduce((object, answer)=>{
65
+ const val = {
66
+ type: answer.attributeType
67
+ };
68
68
  if (answer.attributeType === 'enumeration') {
69
- val.enum = answer.enum.split(',').map((item) => item.trim());
69
+ val.enum = answer.enum.split(',').map((item)=>item.trim());
70
70
  }
71
71
  if (answer.attributeType === 'media') {
72
- val.allowedTypes = ['images', 'files', 'videos', 'audios'];
72
+ val.allowedTypes = [
73
+ 'images',
74
+ 'files',
75
+ 'videos',
76
+ 'audios'
77
+ ];
73
78
  val.multiple = answer.multiple;
74
79
  }
75
- return Object.assign(object, { [answer.attributeName]: val }, {});
80
+ return Object.assign(object, {
81
+ [answer.attributeName]: val
82
+ }, {});
76
83
  }, {});
77
- const filePath = (0, get_file_path_1.default)(answers.destination);
78
- // TODO: use basePath instead
84
+ const filePath = getFilePath(answers.destination);
79
85
  const currentDir = process.cwd();
80
- const language = typescript_utils_1.default.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
86
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
81
87
  const baseActions = [
82
88
  {
83
89
  type: 'add',
84
90
  path: `${filePath}/content-types/{{ singularName }}/schema.json`,
85
91
  templateFile: `templates/${language}/content-type.schema.json.hbs`,
86
92
  data: {
87
- collectionName: (0, slugify_1.default)(answers.pluralName, { separator: '_' }),
88
- },
89
- },
93
+ collectionName: slugify(answers.pluralName, {
94
+ separator: '_'
95
+ })
96
+ }
97
+ }
90
98
  ];
91
99
  if (Object.entries(attributes).length > 0) {
92
100
  baseActions.push({
93
101
  type: 'modify',
94
102
  path: `${filePath}/content-types/{{ singularName }}/schema.json`,
95
- transform(template) {
103
+ transform (template) {
96
104
  const parsedTemplate = JSON.parse(template);
97
105
  parsedTemplate.attributes = attributes;
98
106
  return JSON.stringify(parsedTemplate, null, 2);
99
- },
107
+ }
100
108
  });
101
109
  }
102
110
  if (answers.bootstrapApi) {
@@ -104,32 +112,38 @@ exports.default = (plop) => {
104
112
  let uid;
105
113
  if (answers.destination === 'new') {
106
114
  uid = `api::${answers.id}.${singularName}`;
107
- }
108
- else if (answers.api) {
115
+ } else if (answers.api) {
109
116
  uid = `api::${answers.api}.${singularName}`;
110
- }
111
- else if (answers.plugin) {
117
+ } else if (answers.plugin) {
112
118
  uid = `plugin::${answers.plugin}.${singularName}`;
113
119
  }
114
120
  baseActions.push({
115
121
  type: 'add',
116
122
  path: `${filePath}/controllers/{{ singularName }}.${language}`,
117
123
  templateFile: `templates/${language}/core-controller.${language}.hbs`,
118
- data: { uid },
124
+ data: {
125
+ uid
126
+ }
119
127
  }, {
120
128
  type: 'add',
121
129
  path: `${filePath}/services/{{ singularName }}.${language}`,
122
130
  templateFile: `templates/${language}/core-service.${language}.hbs`,
123
- data: { uid },
131
+ data: {
132
+ uid
133
+ }
124
134
  }, {
125
135
  type: 'add',
126
136
  path: `${filePath}/routes/{{ singularName }}.${language}`,
127
137
  templateFile: `templates/${language}/core-router.${language}.hbs`,
128
- data: { uid },
138
+ data: {
139
+ uid
140
+ }
129
141
  });
130
142
  }
131
143
  return baseActions;
132
- },
144
+ }
133
145
  });
134
- };
135
- //# sourceMappingURL=content-type.js.map
146
+ });
147
+
148
+ module.exports = generateContentType;
149
+ //# sourceMappingURL=content-type.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"content-type.js","sourceRoot":"","sources":["../../src/plops/content-type.ts"],"names":[],"mappings":";;;;;AACA,+BAA4B;AAC5B,oEAA4C;AAC5C,wDAA0B;AAC1B,0DAAkC;AAClC,gFAA+C;AAE/C,gGAAsE;AACtE,0EAAgD;AAChD,kFAAwD;AACxD,0EAAiD;AACjD,oGAAyE;AACzE,8FAAoE;AACpE,4FAAkE;AAElE,kBAAe,CAAC,IAAiB,EAAE,EAAE;IACnC,kBAAkB;IAClB,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE;QAChC,WAAW,EAAE,oCAAoC;QACjD,KAAK,CAAC,OAAO,CAAC,QAAQ;YACpB,MAAM,MAAM,GAAG,MAAM,QAAQ,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,YAAY,EAAE,CAAC;iBACnD;gBAED,WAAW,CAAC,IAAI,CACd;oBACE,IAAI,EAAE,KAAK;oBACX,IAAI,EAAE,GAAG,QAAQ,mCAAmC,QAAQ,EAAE;oBAC9D,YAAY,EAAE,aAAa,QAAQ,oBAAoB,QAAQ,MAAM;oBACrE,IAAI,EAAE,EAAE,GAAG,EAAE;iBACd,EACD;oBACE,IAAI,EAAE,KAAK;oBACX,IAAI,EAAE,GAAG,QAAQ,gCAAgC,QAAQ,EAAE;oBAC3D,YAAY,EAAE,aAAa,QAAQ,iBAAiB,QAAQ,MAAM;oBAClE,IAAI,EAAE,EAAE,GAAG,EAAE;iBACd,EACD;oBACE,IAAI,EAAE,KAAK;oBACX,IAAI,EAAE,GAAG,QAAQ,8BAA8B,QAAQ,EAAE;oBACzD,YAAY,EAAE,aAAa,QAAQ,gBAAgB,QAAQ,MAAM;oBACjE,IAAI,EAAE,EAAE,GAAG,EAAE;iBACd,CACF,CAAC;aACH;YAED,OAAO,WAAW,CAAC;QACrB,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
1
+ {"version":3,"file":"content-type.js","sources":["../../src/plops/content-type.ts"],"sourcesContent":["import { join } from 'path';\nimport type { NodePlopAPI, ActionType } from 'plop';\nimport slugify from '@sindresorhus/slugify';\nimport fs from 'fs-extra';\nimport { strings } from '@strapi/utils';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport ctNamesPrompts from './prompts/ct-names-prompts';\nimport kindPrompts from './prompts/kind-prompts';\nimport getAttributesPrompts from './prompts/get-attributes-prompts';\nimport bootstrapApiPrompts from './prompts/bootstrap-api-prompts';\n\nexport default (plop: NodePlopAPI) => {\n // Model generator\n plop.setGenerator('content-type', {\n description: 'Generate a content type for an API',\n async prompts(inquirer) {\n const config = await inquirer.prompt([...ctNamesPrompts, ...kindPrompts]);\n const attributes = await getAttributesPrompts(inquirer);\n\n const api = await inquirer.prompt([\n ...getDestinationPrompts('model', plop.getDestBasePath()),\n {\n when: (answers) => answers.destination === 'new',\n type: 'input',\n name: 'id',\n default: config.singularName,\n message: 'Name of the new API?',\n async validate(input) {\n if (!strings.isKebabCase(input)) {\n return 'Value must be in kebab-case';\n }\n\n const apiPath = join(plop.getDestBasePath(), 'api');\n const exists = await fs.pathExists(apiPath);\n\n if (!exists) {\n return true;\n }\n\n const apiDir = await fs.readdir(apiPath, { withFileTypes: true });\n const apiDirContent = apiDir.filter((fd) => fd.isDirectory());\n\n if (apiDirContent.findIndex((dir) => dir.name === input) !== -1) {\n throw new Error('This name is already taken.');\n }\n\n return true;\n },\n },\n ...bootstrapApiPrompts,\n ]);\n\n return {\n ...config,\n ...api,\n attributes,\n };\n },\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const attributes = answers.attributes.reduce((object: any, answer: any) => {\n const val: any = { type: answer.attributeType };\n\n if (answer.attributeType === 'enumeration') {\n val.enum = answer.enum.split(',').map((item: string) => item.trim());\n }\n\n if (answer.attributeType === 'media') {\n val.allowedTypes = ['images', 'files', 'videos', 'audios'];\n val.multiple = answer.multiple;\n }\n\n return Object.assign(object, { [answer.attributeName]: val }, {});\n }, {});\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n templateFile: `templates/${language}/content-type.schema.json.hbs`,\n data: {\n collectionName: slugify(answers.pluralName, { separator: '_' }),\n },\n },\n ];\n\n if (Object.entries(attributes).length > 0) {\n baseActions.push({\n type: 'modify',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n transform(template: string) {\n const parsedTemplate = JSON.parse(template);\n parsedTemplate.attributes = attributes;\n return JSON.stringify(parsedTemplate, null, 2);\n },\n });\n }\n\n if (answers.bootstrapApi) {\n const { singularName } = answers;\n\n let uid;\n if (answers.destination === 'new') {\n uid = `api::${answers.id}.${singularName}`;\n } else if (answers.api) {\n uid = `api::${answers.api}.${singularName}`;\n } else if (answers.plugin) {\n uid = `plugin::${answers.plugin}.${singularName}`;\n }\n\n baseActions.push(\n {\n type: 'add',\n path: `${filePath}/controllers/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-controller.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/services/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-service.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/routes/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-router.${language}.hbs`,\n data: { uid },\n }\n );\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","inquirer","config","prompt","ctNamesPrompts","kindPrompts","attributes","getAttributesPrompts","api","getDestinationPrompts","getDestBasePath","when","answers","destination","type","name","default","singularName","message","validate","input","strings","isKebabCase","apiPath","join","exists","fs","pathExists","apiDir","readdir","withFileTypes","apiDirContent","filter","fd","isDirectory","findIndex","dir","Error","bootstrapApiPrompts","actions","reduce","object","answer","val","attributeType","enum","split","map","item","trim","allowedTypes","multiple","Object","assign","attributeName","filePath","getFilePath","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","baseActions","path","templateFile","data","collectionName","slugify","pluralName","separator","entries","length","push","transform","template","parsedTemplate","JSON","parse","stringify","bootstrapApi","uid","id","plugin"],"mappings":";;;;;;;;;;;;;;AAcA,0BAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,cAAgB,EAAA;QAChCC,WAAa,EAAA,oCAAA;AACb,QAAA,MAAMC,SAAQC,QAAQ,EAAA;AACpB,YAAA,MAAMC,MAAS,GAAA,MAAMD,QAASE,CAAAA,MAAM,CAAC;AAAIC,gBAAAA,GAAAA,cAAAA;AAAmBC,gBAAAA,GAAAA;AAAY,aAAA,CAAA;YACxE,M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GAAA,CAAC,KAAK,EAAErE,OAAAA,CAAQJ,GAAG,CAAC,CAAC,EAAES,YAAAA,CAAa,CAAC;iBACtC,MAAA,IAAIL,OAAQuE,CAAAA,MAAM,EAAE;oBACzBF,GAAM,GAAA,CAAC,QAAQ,EAAErE,OAAAA,CAAQuE,MAAM,CAAC,CAAC,EAAElE,YAAAA,CAAa,CAAC;AACnD;AAEA8C,gBAAAA,WAAAA,CAAYU,IAAI,CACd;oBACE3D,IAAM,EAAA,KAAA;AACNkD,oBAAAA,IAAAA,EAAM,CAAC,EAAET,QAAAA,CAAS,gCAAgC,EAAEK,SAAS,CAAC;oBAC9DK,YAAc,EAAA,CAAC,UAAU,EAAEL,QAAAA,CAAS,iBAAiB,EAAEA,QAAAA,CAAS,IAAI,CAAC;oBACrEM,IAAM,EAAA;AAAEe,wBAAAA;AAAI;iBAEd,EAAA;oBACEnE,IAAM,EAAA,KAAA;AACNkD,oBAAAA,IAAAA,EAAM,CAAC,EAAET,QAAAA,CAAS,6BAA6B,EAAEK,SAAS,CAAC;oBAC3DK,YAAc,EAAA,CAAC,UAAU,EAAEL,QAAAA,CAAS,cAAc,EAAEA,QAAAA,CAAS,IAAI,CAAC;oBAClEM,IAAM,EAAA;AAAEe,wBAAAA;AAAI;iBAEd,EAAA;oBACEnE,IAAM,EAAA,KAAA;AACNkD,oBAAAA,IAAAA,EAAM,CAAC,EAAET,QAAAA,CAAS,2BAA2B,EAAEK,SAAS,CAAC;oBACzDK,YAAc,EAAA,CAAC,UAAU,EAAEL,QAAAA,CAAS,aAAa,EAAEA,QAAAA,CAAS,IAAI,CAAC;oBACjEM,IAAM,EAAA;AAAEe,wBAAAA;AAAI;AACd,iBAAA,CAAA;AAEJ;YAEA,OAAOlB,WAAAA;AACT;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
@@ -0,0 +1,147 @@
1
+ import { join } from 'path';
2
+ import slugify from '@sindresorhus/slugify';
3
+ import fs from 'fs-extra';
4
+ import { strings } from '@strapi/utils';
5
+ import tsUtils from '@strapi/typescript-utils';
6
+ import getDestinationPrompts from './prompts/get-destination-prompts.mjs';
7
+ import getFilePath from './utils/get-file-path.mjs';
8
+ import questions from './prompts/ct-names-prompts.mjs';
9
+ import questions$1 from './prompts/kind-prompts.mjs';
10
+ import getAttributesPrompts from './prompts/get-attributes-prompts.mjs';
11
+ import questions$2 from './prompts/bootstrap-api-prompts.mjs';
12
+
13
+ var generateContentType = ((plop)=>{
14
+ // Model generator
15
+ plop.setGenerator('content-type', {
16
+ description: 'Generate a content type for an API',
17
+ async prompts (inquirer) {
18
+ const config = await inquirer.prompt([
19
+ ...questions,
20
+ ...questions$1
21
+ ]);
22
+ const attributes = await getAttributesPrompts(inquirer);
23
+ const api = await inquirer.prompt([
24
+ ...getDestinationPrompts('model', plop.getDestBasePath()),
25
+ {
26
+ when: (answers)=>answers.destination === 'new',
27
+ type: 'input',
28
+ name: 'id',
29
+ default: config.singularName,
30
+ message: 'Name of the new API?',
31
+ async validate (input) {
32
+ if (!strings.isKebabCase(input)) {
33
+ return 'Value must be in kebab-case';
34
+ }
35
+ const apiPath = join(plop.getDestBasePath(), 'api');
36
+ const exists = await fs.pathExists(apiPath);
37
+ if (!exists) {
38
+ return true;
39
+ }
40
+ const apiDir = await fs.readdir(apiPath, {
41
+ withFileTypes: true
42
+ });
43
+ const apiDirContent = apiDir.filter((fd)=>fd.isDirectory());
44
+ if (apiDirContent.findIndex((dir)=>dir.name === input) !== -1) {
45
+ throw new Error('This name is already taken.');
46
+ }
47
+ return true;
48
+ }
49
+ },
50
+ ...questions$2
51
+ ]);
52
+ return {
53
+ ...config,
54
+ ...api,
55
+ attributes
56
+ };
57
+ },
58
+ actions (answers) {
59
+ if (!answers) {
60
+ return [];
61
+ }
62
+ const attributes = answers.attributes.reduce((object, answer)=>{
63
+ const val = {
64
+ type: answer.attributeType
65
+ };
66
+ if (answer.attributeType === 'enumeration') {
67
+ val.enum = answer.enum.split(',').map((item)=>item.trim());
68
+ }
69
+ if (answer.attributeType === 'media') {
70
+ val.allowedTypes = [
71
+ 'images',
72
+ 'files',
73
+ 'videos',
74
+ 'audios'
75
+ ];
76
+ val.multiple = answer.multiple;
77
+ }
78
+ return Object.assign(object, {
79
+ [answer.attributeName]: val
80
+ }, {});
81
+ }, {});
82
+ const filePath = getFilePath(answers.destination);
83
+ const currentDir = process.cwd();
84
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
85
+ const baseActions = [
86
+ {
87
+ type: 'add',
88
+ path: `${filePath}/content-types/{{ singularName }}/schema.json`,
89
+ templateFile: `templates/${language}/content-type.schema.json.hbs`,
90
+ data: {
91
+ collectionName: slugify(answers.pluralName, {
92
+ separator: '_'
93
+ })
94
+ }
95
+ }
96
+ ];
97
+ if (Object.entries(attributes).length > 0) {
98
+ baseActions.push({
99
+ type: 'modify',
100
+ path: `${filePath}/content-types/{{ singularName }}/schema.json`,
101
+ transform (template) {
102
+ const parsedTemplate = JSON.parse(template);
103
+ parsedTemplate.attributes = attributes;
104
+ return JSON.stringify(parsedTemplate, null, 2);
105
+ }
106
+ });
107
+ }
108
+ if (answers.bootstrapApi) {
109
+ const { singularName } = answers;
110
+ let uid;
111
+ if (answers.destination === 'new') {
112
+ uid = `api::${answers.id}.${singularName}`;
113
+ } else if (answers.api) {
114
+ uid = `api::${answers.api}.${singularName}`;
115
+ } else if (answers.plugin) {
116
+ uid = `plugin::${answers.plugin}.${singularName}`;
117
+ }
118
+ baseActions.push({
119
+ type: 'add',
120
+ path: `${filePath}/controllers/{{ singularName }}.${language}`,
121
+ templateFile: `templates/${language}/core-controller.${language}.hbs`,
122
+ data: {
123
+ uid
124
+ }
125
+ }, {
126
+ type: 'add',
127
+ path: `${filePath}/services/{{ singularName }}.${language}`,
128
+ templateFile: `templates/${language}/core-service.${language}.hbs`,
129
+ data: {
130
+ uid
131
+ }
132
+ }, {
133
+ type: 'add',
134
+ path: `${filePath}/routes/{{ singularName }}.${language}`,
135
+ templateFile: `templates/${language}/core-router.${language}.hbs`,
136
+ data: {
137
+ uid
138
+ }
139
+ });
140
+ }
141
+ return baseActions;
142
+ }
143
+ });
144
+ });
145
+
146
+ export { generateContentType as default };
147
+ //# sourceMappingURL=content-type.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-type.mjs","sources":["../../src/plops/content-type.ts"],"sourcesContent":["import { join } from 'path';\nimport type { NodePlopAPI, ActionType } from 'plop';\nimport slugify from '@sindresorhus/slugify';\nimport fs from 'fs-extra';\nimport { strings } from '@strapi/utils';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport ctNamesPrompts from './prompts/ct-names-prompts';\nimport kindPrompts from './prompts/kind-prompts';\nimport getAttributesPrompts from './prompts/get-attributes-prompts';\nimport bootstrapApiPrompts from './prompts/bootstrap-api-prompts';\n\nexport default (plop: NodePlopAPI) => {\n // Model generator\n plop.setGenerator('content-type', {\n description: 'Generate a content type for an API',\n async prompts(inquirer) {\n const config = await inquirer.prompt([...ctNamesPrompts, ...kindPrompts]);\n const attributes = await getAttributesPrompts(inquirer);\n\n const api = await inquirer.prompt([\n ...getDestinationPrompts('model', plop.getDestBasePath()),\n {\n when: (answers) => answers.destination === 'new',\n type: 'input',\n name: 'id',\n default: config.singularName,\n message: 'Name of the new API?',\n async validate(input) {\n if (!strings.isKebabCase(input)) {\n return 'Value must be in kebab-case';\n }\n\n const apiPath = join(plop.getDestBasePath(), 'api');\n const exists = await fs.pathExists(apiPath);\n\n if (!exists) {\n return true;\n }\n\n const apiDir = await fs.readdir(apiPath, { withFileTypes: true });\n const apiDirContent = apiDir.filter((fd) => fd.isDirectory());\n\n if (apiDirContent.findIndex((dir) => dir.name === input) !== -1) {\n throw new Error('This name is already taken.');\n }\n\n return true;\n },\n },\n ...bootstrapApiPrompts,\n ]);\n\n return {\n ...config,\n ...api,\n attributes,\n };\n },\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const attributes = answers.attributes.reduce((object: any, answer: any) => {\n const val: any = { type: answer.attributeType };\n\n if (answer.attributeType === 'enumeration') {\n val.enum = answer.enum.split(',').map((item: string) => item.trim());\n }\n\n if (answer.attributeType === 'media') {\n val.allowedTypes = ['images', 'files', 'videos', 'audios'];\n val.multiple = answer.multiple;\n }\n\n return Object.assign(object, { [answer.attributeName]: val }, {});\n }, {});\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n templateFile: `templates/${language}/content-type.schema.json.hbs`,\n data: {\n collectionName: slugify(answers.pluralName, { separator: '_' }),\n },\n },\n ];\n\n if (Object.entries(attributes).length > 0) {\n baseActions.push({\n type: 'modify',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n transform(template: string) {\n const parsedTemplate = JSON.parse(template);\n parsedTemplate.attributes = attributes;\n return JSON.stringify(parsedTemplate, null, 2);\n },\n });\n }\n\n if (answers.bootstrapApi) {\n const { singularName } = answers;\n\n let uid;\n if (answers.destination === 'new') {\n uid = `api::${answers.id}.${singularName}`;\n } else if (answers.api) {\n uid = `api::${answers.api}.${singularName}`;\n } else if (answers.plugin) {\n uid = `plugin::${answers.plugin}.${singularName}`;\n }\n\n baseActions.push(\n {\n type: 'add',\n path: `${filePath}/controllers/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-controller.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/services/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-service.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/routes/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-router.${language}.hbs`,\n data: { uid },\n }\n );\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","inquirer","config","prompt","ctNamesPrompts","kindPrompts","attributes","getAttributesPrompts","api","getDestinationPrompts","getDestBasePath","when","answers","destination","type","name","default","singularName","message","validate","input","strings","isKebabCase","apiPath","join","exists","fs","pathExists","apiDir","readdir","withFileTypes","apiDirContent","filter","fd","isDirectory","findIndex","dir","Error","bootstrapApiPrompts","actions","reduce","object","answer","val","attributeType","enum","split","map","item","trim","allowedTypes","multiple","Object","assign","attributeName","filePath","getFilePath","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","baseActions","path","templateFile","data","collectionName","slugify","pluralName","separator","entries","length","push","transform","template","parsedTemplate","JSON","parse","stringify","bootstrapApi","uid","id","plugin"],"mappings":";;;;;;;;;;;;AAcA,0BAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,cAAgB,EAAA;QAChCC,WAAa,EAAA,oCAAA;AACb,QAAA,MAAMC,SAAQC,QAAQ,EAAA;AACpB,YAAA,MAAMC,MAAS,GAAA,MAAMD,QAASE,CAAAA,MAAM,CAAC;AAAIC,gBAAAA,GAAAA,SAAAA;AAAmBC,gBAAAA,GAAAA;AAAY,aAAA,CAAA;YACxE,MAAMC,UAAAA,GAAa,MAAMC,oBAAqBN,CAAAA,QAAAA,CAAAA;AAE9C,YAAA,MAAMO,GAAM,GAAA,MAAMP,QAASE,CAAAA,MAAM,CAAC;mBAC7BM,qBAAsB,CAAA,OAAA,EAASZ,KAAKa,eAAe,EAAA,CAAA;AACtD,gBAAA;AACEC,oBAAAA,IAAAA,EAAM,CAACC,OAAAA,GAAYA,OAAQC,CAAAA,WAAW,KAAK,KAAA;oBAC3CC,IAAM,EAAA,OAAA;oBACNC,IAAM,EAAA,IAAA;AACNC,oBAAAA,OAAAA,EAASd,OAAOe,YAAY;oBAC5BC,OAAS,EAAA,sBAAA;AACT,oBAAA,MAAMC,UAASC,KAAK,EAAA;AAClB,wBAAA,IAAI,CAACC,OAAAA,CAAQC,WAAW,CAACF,KAAQ,CAAA,EAAA;4BAC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AAAA;AAAI;iBAEd,EAAA;oBACEnE,IAAM,EAAA,KAAA;AACNkD,oBAAAA,IAAAA,EAAM,CAAC,EAAET,QAAAA,CAAS,6BAA6B,EAAEK,SAAS,CAAC;oBAC3DK,YAAc,EAAA,CAAC,UAAU,EAAEL,QAAAA,CAAS,cAAc,EAAEA,QAAAA,CAAS,IAAI,CAAC;oBAClEM,IAAM,EAAA;AAAEe,wBAAAA;AAAI;iBAEd,EAAA;oBACEnE,IAAM,EAAA,KAAA;AACNkD,oBAAAA,IAAAA,EAAM,CAAC,EAAET,QAAAA,CAAS,2BAA2B,EAAEK,SAAS,CAAC;oBACzDK,YAAc,EAAA,CAAC,UAAU,EAAEL,QAAAA,CAAS,aAAa,EAAEA,QAAAA,CAAS,IAAI,CAAC;oBACjEM,IAAM,EAAA;AAAEe,wBAAAA;AAAI;AACd,iBAAA,CAAA;AAEJ;YAEA,OAAOlB,WAAAA;AACT;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
@@ -1,3 +1,4 @@
1
- import { NodePlopAPI } from 'plop';
1
+ import type { NodePlopAPI } from 'plop';
2
2
  declare const _default: (plop: NodePlopAPI) => void;
3
3
  export default _default;
4
+ //# sourceMappingURL=controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/plops/controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;+BAOlB,WAAW;AAAjC,wBA+BE"}
@@ -1,13 +1,11 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const typescript_utils_1 = __importDefault(require("@strapi/typescript-utils"));
7
- const get_destination_prompts_1 = __importDefault(require("./prompts/get-destination-prompts"));
8
- const get_file_path_1 = __importDefault(require("./utils/get-file-path"));
9
- const validate_input_1 = __importDefault(require("./utils/validate-input"));
10
- exports.default = (plop) => {
1
+ 'use strict';
2
+
3
+ var tsUtils = require('@strapi/typescript-utils');
4
+ var getDestinationPrompts = require('./prompts/get-destination-prompts.js');
5
+ var getFilePath = require('./utils/get-file-path.js');
6
+ var validateInput = require('./utils/validate-input.js');
7
+
8
+ var generateController = ((plop)=>{
11
9
  // Controller generator
12
10
  plop.setGenerator('controller', {
13
11
  description: 'Generate a controller for an API',
@@ -16,25 +14,27 @@ exports.default = (plop) => {
16
14
  type: 'input',
17
15
  name: 'id',
18
16
  message: 'Controller name',
19
- validate: (input) => (0, validate_input_1.default)(input),
17
+ validate: (input)=>validateInput(input)
20
18
  },
21
- ...(0, get_destination_prompts_1.default)('controller', plop.getDestBasePath()),
19
+ ...getDestinationPrompts('controller', plop.getDestBasePath())
22
20
  ],
23
- actions(answers) {
21
+ actions (answers) {
24
22
  if (!answers) {
25
23
  return [];
26
24
  }
27
- const filePath = (0, get_file_path_1.default)(answers.destination);
25
+ const filePath = getFilePath(answers.destination);
28
26
  const currentDir = process.cwd();
29
- const language = typescript_utils_1.default.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
27
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
30
28
  return [
31
29
  {
32
30
  type: 'add',
33
31
  path: `${filePath}/controllers/{{ id }}.${language}`,
34
- templateFile: `templates/${language}/controller.${language}.hbs`,
35
- },
32
+ templateFile: `templates/${language}/controller.${language}.hbs`
33
+ }
36
34
  ];
37
- },
35
+ }
38
36
  });
39
- };
40
- //# sourceMappingURL=controller.js.map
37
+ });
38
+
39
+ module.exports = generateController;
40
+ //# sourceMappingURL=controller.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/plops/controller.ts"],"names":[],"mappings":";;;;;AACA,gFAA+C;AAE/C,gGAAsE;AACtE,0EAAgD;AAChD,4EAAmD;AAEnD,kBAAe,CAAC,IAAiB,EAAE,EAAE;IACnC,uBAAuB;IACvB,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE;QAC9B,WAAW,EAAE,kCAAkC;QAC/C,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,IAAI;gBACV,OAAO,EAAE,iBAAiB;gBAC1B,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,wBAAa,EAAC,KAAK,CAAC;aAC1C;YACD,GAAG,IAAA,iCAAqB,EAAC,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE,CAAC;SAC/D;QACD,OAAO,CAAC,OAAO;YACb,IAAI,CAAC,OAAO,EAAE;gBACZ,OAAO,EAAE,CAAC;aACX;YAED,MAAM,QAAQ,GAAG,IAAA,uBAAW,EAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YAClD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;YACjC,MAAM,QAAQ,GAAG,0BAAO,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;YAEzE,OAAO;gBACL;oBACE,IAAI,EAAE,KAAK;oBACX,IAAI,EAAE,GAAG,QAAQ,yBAAyB,QAAQ,EAAE;oBACpD,YAAY,EAAE,aAAa,QAAQ,eAAe,QAAQ,MAAM;iBACjE;aACF,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
1
+ {"version":3,"file":"controller.js","sources":["../../src/plops/controller.ts"],"sourcesContent":["import type { NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport validateInput from './utils/validate-input';\n\nexport default (plop: NodePlopAPI) => {\n // Controller generator\n plop.setGenerator('controller', {\n description: 'Generate a controller for an API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'Controller name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('controller', plop.getDestBasePath()),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n return [\n {\n type: 'add',\n path: `${filePath}/controllers/{{ id }}.${language}`,\n templateFile: `templates/${language}/controller.${language}.hbs`,\n },\n ];\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","getDestinationPrompts","getDestBasePath","actions","answers","filePath","getFilePath","destination","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","path","templateFile"],"mappings":";;;;;;;AAOA,yBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,YAAc,EAAA;QAC9BC,WAAa,EAAA,kCAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,IAAA;gBACNC,OAAS,EAAA,iBAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,aAAcD,CAAAA,KAAAA;AACrC,aAAA;eACGE,qBAAsB,CAAA,YAAA,EAAcV,KAAKW,eAAe,EAAA;AAC5D,SAAA;AACDC,QAAAA,OAAAA,CAAAA,CAAQC,OAAO,EAAA;AACb,YAAA,IAAI,CAACA,OAAS,EAAA;AACZ,gBAAA,OAAO,EAAE;AACX;YAEA,MAAMC,QAAAA,GAAWC,WAAYF,CAAAA,OAAAA,CAAQG,WAAW,CAAA;YAChD,MAAMC,UAAAA,GAAaC,QAAQC,GAAG,EAAA;AAC9B,YAAA,MAAMC,QAAWC,GAAAA,OAAAA,CAAQC,qBAAqB,CAACL,cAAc,IAAO,GAAA,IAAA;YAEpE,OAAO;AACL,gBAAA;oBACEb,IAAM,EAAA,KAAA;AACNmB,oBAAAA,IAAAA,EAAM,CAAC,EAAET,QAAAA,CAAS,sBAAsB,EAAEM,SAAS,CAAC;oBACpDI,YAAc,EAAA,CAAC,UAAU,EAAEJ,QAAAA,CAAS,YAAY,EAAEA,QAAAA,CAAS,IAAI;AACjE;AACD,aAAA;AACH;AACF,KAAA,CAAA;AACF,CAAA;;;;"}