@strapi/generators 0.0.0-next.f45143c5e2a8a9d85691d0abf79a3f42024a0c71 → 0.0.0-next.f7babb775ed9a7e18d8351cb7f74c63e016323c4

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 (172) hide show
  1. package/dist/files/js/plugin/.editorconfig +7 -0
  2. package/dist/files/js/plugin/.gitattributes +103 -0
  3. package/dist/files/ts/plugin/.editorconfig +7 -0
  4. package/dist/files/ts/plugin/.gitattributes +103 -0
  5. package/dist/index.d.ts +5 -0
  6. package/dist/index.js +32 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/plopfile.d.ts +3 -0
  9. package/dist/plopfile.js +29 -0
  10. package/dist/plopfile.js.map +1 -0
  11. package/dist/plops/api.d.ts +3 -0
  12. package/dist/plops/api.js +79 -0
  13. package/dist/plops/api.js.map +1 -0
  14. package/dist/plops/content-type.d.ts +3 -0
  15. package/dist/plops/content-type.js +158 -0
  16. package/dist/plops/content-type.js.map +1 -0
  17. package/dist/plops/controller.d.ts +3 -0
  18. package/dist/plops/controller.js +40 -0
  19. package/dist/plops/controller.js.map +1 -0
  20. package/dist/plops/middleware.d.ts +3 -0
  21. package/dist/plops/middleware.js +40 -0
  22. package/dist/plops/middleware.js.map +1 -0
  23. package/dist/plops/migration.d.ts +3 -0
  24. package/dist/plops/migration.js +35 -0
  25. package/dist/plops/migration.js.map +1 -0
  26. package/dist/plops/plugin.d.ts +3 -0
  27. package/dist/plops/plugin.js +107 -0
  28. package/dist/plops/plugin.js.map +1 -0
  29. package/dist/plops/policy.d.ts +3 -0
  30. package/dist/plops/policy.js +40 -0
  31. package/dist/plops/policy.js.map +1 -0
  32. package/dist/plops/prompts/bootstrap-api-prompts.d.ts +3 -0
  33. package/dist/plops/prompts/bootstrap-api-prompts.js +12 -0
  34. package/dist/plops/prompts/bootstrap-api-prompts.js.map +1 -0
  35. package/dist/plops/prompts/ct-names-prompts.d.ts +3 -0
  36. package/dist/plops/prompts/ct-names-prompts.js +68 -0
  37. package/dist/plops/prompts/ct-names-prompts.js.map +1 -0
  38. package/dist/plops/prompts/draft-and-publish-prompts.d.ts +3 -0
  39. package/dist/plops/prompts/draft-and-publish-prompts.js +12 -0
  40. package/dist/plops/prompts/draft-and-publish-prompts.js.map +1 -0
  41. package/dist/plops/prompts/get-attributes-prompts.d.ts +3 -0
  42. package/dist/plops/prompts/get-attributes-prompts.js +95 -0
  43. package/dist/plops/prompts/get-attributes-prompts.js.map +1 -0
  44. package/dist/plops/prompts/get-destination-prompts.d.ts +5 -0
  45. package/dist/plops/prompts/get-destination-prompts.js +72 -0
  46. package/dist/plops/prompts/get-destination-prompts.js.map +1 -0
  47. package/dist/plops/prompts/kind-prompts.d.ts +3 -0
  48. package/dist/plops/prompts/kind-prompts.js +21 -0
  49. package/dist/plops/prompts/kind-prompts.js.map +1 -0
  50. package/dist/plops/service.d.ts +3 -0
  51. package/dist/plops/service.js +38 -0
  52. package/dist/plops/service.js.map +1 -0
  53. package/dist/plops/utils/get-file-path.d.ts +2 -0
  54. package/dist/plops/utils/get-file-path.js +15 -0
  55. package/dist/plops/utils/get-file-path.js.map +1 -0
  56. package/dist/plops/utils/get-formatted-date.d.ts +2 -0
  57. package/dist/plops/utils/get-formatted-date.js +9 -0
  58. package/dist/plops/utils/get-formatted-date.js.map +1 -0
  59. package/dist/plops/utils/validate-attribute-input.d.ts +2 -0
  60. package/dist/plops/utils/validate-attribute-input.js +10 -0
  61. package/dist/plops/utils/validate-attribute-input.js.map +1 -0
  62. package/dist/plops/utils/validate-file-name-input.d.ts +2 -0
  63. package/dist/plops/utils/validate-file-name-input.js +10 -0
  64. package/dist/plops/utils/validate-file-name-input.js.map +1 -0
  65. package/dist/plops/utils/validate-input.d.ts +2 -0
  66. package/dist/plops/utils/validate-input.js +10 -0
  67. package/dist/plops/utils/validate-input.js.map +1 -0
  68. package/{lib → dist}/templates/js/plugin-package.json.hbs +5 -5
  69. package/{lib → dist}/templates/ts/plugin-package.json.hbs +7 -7
  70. package/package.json +23 -6
  71. package/.eslintignore +0 -3
  72. package/.eslintrc.js +0 -4
  73. package/lib/index.js +0 -37
  74. package/lib/plopfile.js +0 -28
  75. package/lib/plops/__tests__/content-type.test.js +0 -179
  76. package/lib/plops/api.js +0 -82
  77. package/lib/plops/content-type.js +0 -148
  78. package/lib/plops/controller.js +0 -36
  79. package/lib/plops/middleware.js +0 -36
  80. package/lib/plops/migration.js +0 -33
  81. package/lib/plops/plugin.js +0 -91
  82. package/lib/plops/policy.js +0 -36
  83. package/lib/plops/prompts/bootstrap-api-prompts.js +0 -10
  84. package/lib/plops/prompts/ct-names-prompts.js +0 -44
  85. package/lib/plops/prompts/draft-and-publish-prompts.js +0 -10
  86. package/lib/plops/prompts/get-attributes-prompts.js +0 -105
  87. package/lib/plops/prompts/get-destination-prompts.js +0 -79
  88. package/lib/plops/prompts/kind-prompts.js +0 -17
  89. package/lib/plops/service.js +0 -34
  90. package/lib/plops/utils/__tests__/get-file-path.test.js +0 -25
  91. package/lib/plops/utils/get-file-path.js +0 -17
  92. package/lib/plops/utils/get-formatted-date.js +0 -8
  93. package/lib/plops/utils/validate-attribute-input.js +0 -11
  94. package/lib/plops/utils/validate-file-name-input.js +0 -11
  95. package/lib/plops/utils/validate-input.js +0 -11
  96. /package/{lib → dist}/files/js/plugin/admin/src/components/Initializer/index.js +0 -0
  97. /package/{lib → dist}/files/js/plugin/admin/src/components/PluginIcon/index.js +0 -0
  98. /package/{lib → dist}/files/js/plugin/admin/src/index.js +0 -0
  99. /package/{lib → dist}/files/js/plugin/admin/src/pages/App/index.js +0 -0
  100. /package/{lib → dist}/files/js/plugin/admin/src/pages/HomePage/index.js +0 -0
  101. /package/{lib → dist}/files/js/plugin/admin/src/pluginId.js +0 -0
  102. /package/{lib → dist}/files/js/plugin/admin/src/translations/en.json +0 -0
  103. /package/{lib → dist}/files/js/plugin/admin/src/translations/fr.json +0 -0
  104. /package/{lib → dist}/files/js/plugin/admin/src/utils/getTrad.js +0 -0
  105. /package/{lib → dist}/files/js/plugin/server/bootstrap.js +0 -0
  106. /package/{lib → dist}/files/js/plugin/server/config/index.js +0 -0
  107. /package/{lib → dist}/files/js/plugin/server/content-types/index.js +0 -0
  108. /package/{lib → dist}/files/js/plugin/server/controllers/index.js +0 -0
  109. /package/{lib → dist}/files/js/plugin/server/controllers/my-controller.js.hbs +0 -0
  110. /package/{lib → dist}/files/js/plugin/server/destroy.js +0 -0
  111. /package/{lib → dist}/files/js/plugin/server/index.js +0 -0
  112. /package/{lib → dist}/files/js/plugin/server/middlewares/index.js +0 -0
  113. /package/{lib → dist}/files/js/plugin/server/policies/index.js +0 -0
  114. /package/{lib → dist}/files/js/plugin/server/register.js +0 -0
  115. /package/{lib → dist}/files/js/plugin/server/routes/index.js +0 -0
  116. /package/{lib → dist}/files/js/plugin/server/services/index.js +0 -0
  117. /package/{lib → dist}/files/js/plugin/server/services/my-service.js +0 -0
  118. /package/{lib → dist}/files/js/plugin/strapi-admin.js +0 -0
  119. /package/{lib → dist}/files/js/plugin/strapi-server.js +0 -0
  120. /package/{lib → dist}/files/ts/plugin/admin/src/components/Initializer/index.tsx +0 -0
  121. /package/{lib → dist}/files/ts/plugin/admin/src/components/PluginIcon/index.tsx +0 -0
  122. /package/{lib → dist}/files/ts/plugin/admin/src/index.tsx +0 -0
  123. /package/{lib → dist}/files/ts/plugin/admin/src/pages/App/index.tsx +0 -0
  124. /package/{lib → dist}/files/ts/plugin/admin/src/pages/HomePage/index.tsx +0 -0
  125. /package/{lib → dist}/files/ts/plugin/admin/src/pluginId.ts +0 -0
  126. /package/{lib → dist}/files/ts/plugin/admin/src/translations/en.json +0 -0
  127. /package/{lib → dist}/files/ts/plugin/admin/src/translations/fr.json +0 -0
  128. /package/{lib → dist}/files/ts/plugin/admin/src/utils/getTrad.ts +0 -0
  129. /package/{lib → dist}/files/ts/plugin/custom.d.ts +0 -0
  130. /package/{lib → dist}/files/ts/plugin/server/bootstrap.ts +0 -0
  131. /package/{lib → dist}/files/ts/plugin/server/config/index.ts +0 -0
  132. /package/{lib → dist}/files/ts/plugin/server/content-types/index.ts +0 -0
  133. /package/{lib → dist}/files/ts/plugin/server/controllers/index.ts +0 -0
  134. /package/{lib → dist}/files/ts/plugin/server/controllers/my-controller.ts.hbs +0 -0
  135. /package/{lib → dist}/files/ts/plugin/server/destroy.ts +0 -0
  136. /package/{lib → dist}/files/ts/plugin/server/index.ts +0 -0
  137. /package/{lib → dist}/files/ts/plugin/server/middlewares/index.ts +0 -0
  138. /package/{lib → dist}/files/ts/plugin/server/policies/index.ts +0 -0
  139. /package/{lib → dist}/files/ts/plugin/server/register.ts +0 -0
  140. /package/{lib → dist}/files/ts/plugin/server/routes/index.ts +0 -0
  141. /package/{lib → dist}/files/ts/plugin/server/services/index.ts +0 -0
  142. /package/{lib → dist}/files/ts/plugin/server/services/my-service.ts +0 -0
  143. /package/{lib → dist}/files/ts/plugin/strapi-admin.js +0 -0
  144. /package/{lib → dist}/files/ts/plugin/strapi-server.js +0 -0
  145. /package/{lib → dist}/files/ts/plugin/tsconfig.json +0 -0
  146. /package/{lib → dist}/files/ts/plugin/tsconfig.server.json +0 -0
  147. /package/{lib → dist}/templates/js/README.md.hbs +0 -0
  148. /package/{lib → dist}/templates/js/collection-type-routes.js.hbs +0 -0
  149. /package/{lib → dist}/templates/js/content-type.schema.json.hbs +0 -0
  150. /package/{lib → dist}/templates/js/controller.js.hbs +0 -0
  151. /package/{lib → dist}/templates/js/core-controller.js.hbs +0 -0
  152. /package/{lib → dist}/templates/js/core-router.js.hbs +0 -0
  153. /package/{lib → dist}/templates/js/core-service.js.hbs +0 -0
  154. /package/{lib → dist}/templates/js/middleware.js.hbs +0 -0
  155. /package/{lib → dist}/templates/js/migration.js.hbs +0 -0
  156. /package/{lib → dist}/templates/js/policy.js.hbs +0 -0
  157. /package/{lib → dist}/templates/js/service.js.hbs +0 -0
  158. /package/{lib → dist}/templates/js/single-route.js.hbs +0 -0
  159. /package/{lib → dist}/templates/js/single-type-routes.js.hbs +0 -0
  160. /package/{lib → dist}/templates/ts/README.md.hbs +0 -0
  161. /package/{lib → dist}/templates/ts/collection-type-routes.ts.hbs +0 -0
  162. /package/{lib → dist}/templates/ts/content-type.schema.json.hbs +0 -0
  163. /package/{lib → dist}/templates/ts/controller.ts.hbs +0 -0
  164. /package/{lib → dist}/templates/ts/core-controller.ts.hbs +0 -0
  165. /package/{lib → dist}/templates/ts/core-router.ts.hbs +0 -0
  166. /package/{lib → dist}/templates/ts/core-service.ts.hbs +0 -0
  167. /package/{lib → dist}/templates/ts/middleware.ts.hbs +0 -0
  168. /package/{lib → dist}/templates/ts/migration.ts.hbs +0 -0
  169. /package/{lib → dist}/templates/ts/policy.ts.hbs +0 -0
  170. /package/{lib → dist}/templates/ts/service.ts.hbs +0 -0
  171. /package/{lib → dist}/templates/ts/single-route.ts.hbs +0 -0
  172. /package/{lib → dist}/templates/ts/single-type-routes.ts.hbs +0 -0
@@ -0,0 +1,2 @@
1
+ declare const _default: (date?: Date) => string;
2
+ export default _default;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = (date = new Date()) => {
4
+ return new Date(date.getTime() - date.getTimezoneOffset() * 60000)
5
+ .toJSON()
6
+ .replace(/[-:]/g, '.')
7
+ .replace(/\....Z/, '');
8
+ };
9
+ //# sourceMappingURL=get-formatted-date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-formatted-date.js","sourceRoot":"","sources":["../../../src/plops/utils/get-formatted-date.ts"],"names":[],"mappings":";;AAAA,kBAAe,CAAC,OAAa,IAAI,IAAI,EAAE,EAAE,EAAE;IACzC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,iBAAiB,EAAE,GAAG,KAAK,CAAC;SAC/D,MAAM,EAAE;SACR,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;SACrB,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAC3B,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ declare const _default: (input: string) => true | "You must provide an input" | "Please use only letters, '-', '_', and no spaces";
2
+ export default _default;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = (input) => {
4
+ const regex = /^[A-Za-z-|_]+$/g;
5
+ if (!input) {
6
+ return 'You must provide an input';
7
+ }
8
+ return regex.test(input) || "Please use only letters, '-', '_', and no spaces";
9
+ };
10
+ //# sourceMappingURL=validate-attribute-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-attribute-input.js","sourceRoot":"","sources":["../../../src/plops/utils/validate-attribute-input.ts"],"names":[],"mappings":";;AAAA,kBAAe,CAAC,KAAa,EAAE,EAAE;IAC/B,MAAM,KAAK,GAAG,iBAAiB,CAAC;IAEhC,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,2BAA2B,CAAC;KACpC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,mDAAmD,CAAC;AAClF,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ declare const _default: (input: string) => true | "You must provide an input" | "Please use only letters and number, '-' or '_' and no spaces";
2
+ export default _default;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = (input) => {
4
+ const regex = /^[A-Za-z-_0-9]+$/g;
5
+ if (!input) {
6
+ return 'You must provide an input';
7
+ }
8
+ return regex.test(input) || "Please use only letters and number, '-' or '_' and no spaces";
9
+ };
10
+ //# sourceMappingURL=validate-file-name-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-file-name-input.js","sourceRoot":"","sources":["../../../src/plops/utils/validate-file-name-input.ts"],"names":[],"mappings":";;AAAA,kBAAe,CAAC,KAAa,EAAE,EAAE;IAC/B,MAAM,KAAK,GAAG,mBAAmB,CAAC;IAElC,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,2BAA2B,CAAC;KACpC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,8DAA8D,CAAC;AAC7F,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ declare const _default: (input: string) => true | "You must provide an input" | "Please use only letters, '-' and no spaces";
2
+ export default _default;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = (input) => {
4
+ const regex = /^[A-Za-z-]+$/g;
5
+ if (!input) {
6
+ return 'You must provide an input';
7
+ }
8
+ return regex.test(input) || "Please use only letters, '-' and no spaces";
9
+ };
10
+ //# sourceMappingURL=validate-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-input.js","sourceRoot":"","sources":["../../../src/plops/utils/validate-input.ts"],"names":[],"mappings":";;AAAA,kBAAe,CAAC,KAAa,EAAE,EAAE;IAC/B,MAAM,KAAK,GAAG,eAAe,CAAC;IAE9B,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,2BAA2B,CAAC;KACpC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,4CAA4C,CAAC;AAC3E,CAAC,CAAC"}
@@ -15,14 +15,14 @@
15
15
  "prop-types": "^15.7.2"
16
16
  },
17
17
  "devDependencies": {
18
- "react": "^17.0.2",
19
- "react-dom": "^17.0.2",
18
+ "react": "^18.2.0",
19
+ "react-dom": "^18.2.0",
20
20
  "react-router-dom": "^5.3.4",
21
21
  "styled-components": "^5.3.6"
22
22
  },
23
23
  "peerDependencies": {
24
- "react": "^17.0.2",
25
- "react-dom": "^17.0.2",
24
+ "react": "^17.0.0 || ^18.0.0",
25
+ "react-dom": "^17.0.0 || ^18.0.0",
26
26
  "react-router-dom": "^5.3.4",
27
27
  "styled-components": "^5.3.6"
28
28
  },
@@ -35,7 +35,7 @@
35
35
  }
36
36
  ],
37
37
  "engines": {
38
- "node": ">=14.19.1 <=18.x.x",
38
+ "node": ">=16.0.0 <=20.x.x",
39
39
  "npm": ">=6.0.0"
40
40
  },
41
41
  "license": "MIT"
@@ -16,18 +16,18 @@
16
16
  "devDependencies": {
17
17
  "@strapi/typescript-utils": "^4.6.0",
18
18
  "@types/react": "^17.0.53",
19
- "@types/react-dom": "^17.0.18",
19
+ "@types/react-dom": "^18.0.28",
20
20
  "@types/react-router-dom": "^5.3.3",
21
21
  "@types/styled-components": "^5.1.26",
22
- "react": "^17.0.2",
23
- "react-dom": "^17.0.2",
22
+ "react": "^18.2.0",
23
+ "react-dom": "^18.2.0",
24
24
  "react-router-dom": "^5.3.4",
25
25
  "styled-components": "^5.3.6",
26
- "typescript": "4.6.3"
26
+ "typescript": "5.0.4"
27
27
  },
28
28
  "peerDependencies": {
29
- "react": "^17.0.2",
30
- "react-dom": "^17.0.2",
29
+ "react": "^17.0.0 || ^18.0.0",
30
+ "react-dom": "^17.0.0 || ^18.0.0",
31
31
  "react-router-dom": "^5.3.4",
32
32
  "styled-components": "^5.3.6"
33
33
  },
@@ -40,7 +40,7 @@
40
40
  }
41
41
  ],
42
42
  "engines": {
43
- "node": ">=14.19.1 <=18.x.x",
43
+ "node": ">=16.0.0 <=20.x.x",
44
44
  "npm": ">=6.0.0"
45
45
  },
46
46
  "scripts": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/generators",
3
- "version": "0.0.0-next.f45143c5e2a8a9d85691d0abf79a3f42024a0c71",
3
+ "version": "0.0.0-next.f7babb775ed9a7e18d8351cb7f74c63e016323c4",
4
4
  "description": "Interactive API generator.",
5
5
  "keywords": [
6
6
  "strapi",
@@ -27,23 +27,40 @@
27
27
  "url": "https://strapi.io"
28
28
  }
29
29
  ],
30
- "main": "lib/index.js",
30
+ "main": "./dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
+ "files": [
33
+ "./dist"
34
+ ],
31
35
  "scripts": {
36
+ "build": "run -T tsc && run copy-files",
37
+ "build:ts": "run build",
38
+ "watch": "run -T tsc -w --preserveWatchOutput",
39
+ "clean": "run -T rimraf ./dist",
40
+ "copy-files": "copyfiles -u 1 -a 'src/templates/**/*' 'src/files/**/*' dist",
41
+ "prepublishOnly": "yarn clean && yarn build",
42
+ "test:unit": "run -T jest",
43
+ "test:unit:watch": "run -T jest --watch",
32
44
  "lint": "run -T eslint ."
33
45
  },
34
46
  "dependencies": {
35
47
  "@sindresorhus/slugify": "1.1.0",
36
- "@strapi/typescript-utils": "0.0.0-next.f45143c5e2a8a9d85691d0abf79a3f42024a0c71",
37
- "@strapi/utils": "0.0.0-next.f45143c5e2a8a9d85691d0abf79a3f42024a0c71",
48
+ "@strapi/typescript-utils": "0.0.0-next.f7babb775ed9a7e18d8351cb7f74c63e016323c4",
49
+ "@strapi/utils": "0.0.0-next.f7babb775ed9a7e18d8351cb7f74c63e016323c4",
38
50
  "chalk": "4.1.2",
51
+ "copyfiles": "2.4.1",
39
52
  "fs-extra": "10.0.0",
40
53
  "node-plop": "0.26.3",
41
54
  "plop": "2.7.6",
42
55
  "pluralize": "8.0.0"
43
56
  },
57
+ "devDependencies": {
58
+ "eslint-config-custom": "0.0.0-next.f7babb775ed9a7e18d8351cb7f74c63e016323c4",
59
+ "tsconfig": "0.0.0-next.f7babb775ed9a7e18d8351cb7f74c63e016323c4"
60
+ },
44
61
  "engines": {
45
- "node": ">=14.19.1 <=18.x.x",
62
+ "node": ">=16.0.0 <=20.x.x",
46
63
  "npm": ">=6.0.0"
47
64
  },
48
- "gitHead": "f45143c5e2a8a9d85691d0abf79a3f42024a0c71"
65
+ "gitHead": "f7babb775ed9a7e18d8351cb7f74c63e016323c4"
49
66
  }
package/.eslintignore DELETED
@@ -1,3 +0,0 @@
1
- node_modules/
2
- .eslintrc.js
3
- lib/files/
package/.eslintrc.js DELETED
@@ -1,4 +0,0 @@
1
- module.exports = {
2
- root: true,
3
- extends: ['custom/back'],
4
- };
package/lib/index.js DELETED
@@ -1,37 +0,0 @@
1
- 'use strict';
2
-
3
- const { join } = require('path');
4
- const { Plop, run } = require('plop');
5
- const nodePlop = require('node-plop');
6
-
7
- /**
8
- * Starts the Plop CLI programmatically
9
- */
10
- const runCLI = () => {
11
- Plop.launch({ configPath: join(__dirname, 'plopfile.js') }, (env) =>
12
- run({ ...env, dest: join(process.cwd(), 'src') }, undefined, true)
13
- );
14
- };
15
-
16
- /**
17
- * Runs a generator programmatically without prompts
18
- * @param {string} generatorName
19
- * @param {Object} options generator options replacing the prompts answers
20
- * @param {Object} plopOptions
21
- * @param {string} plopOptions.dir base path for plop to generate the files from
22
- */
23
- const generate = async (generatorName, options, { dir = process.cwd() } = {}) => {
24
- const plop = nodePlop(join(__dirname, 'plopfile.js'), { destBasePath: join(dir, 'src') });
25
-
26
- const generator = plop.getGenerator(generatorName);
27
- await generator.runActions(options, {
28
- onSuccess() {},
29
- onFailure() {},
30
- onComment() {},
31
- });
32
- };
33
-
34
- module.exports = {
35
- generate,
36
- runCLI,
37
- };
package/lib/plopfile.js DELETED
@@ -1,28 +0,0 @@
1
- 'use strict';
2
-
3
- const pluralize = require('pluralize');
4
-
5
- const generateApi = require('./plops/api');
6
- const generateController = require('./plops/controller');
7
- const generateContentType = require('./plops/content-type');
8
- const generatePlugin = require('./plops/plugin');
9
- const generatePolicy = require('./plops/policy');
10
- const generateMiddleware = require('./plops/middleware');
11
- const generateMigration = require('./plops/migration');
12
- const generateService = require('./plops/service');
13
-
14
- module.exports = (plop) => {
15
- // Plop config
16
- plop.setWelcomeMessage('Strapi Generators');
17
- plop.addHelper('pluralize', (text) => pluralize(text));
18
-
19
- // Generators
20
- generateApi(plop);
21
- generateController(plop);
22
- generateContentType(plop);
23
- generatePlugin(plop);
24
- generatePolicy(plop);
25
- generateMiddleware(plop);
26
- generateMigration(plop);
27
- generateService(plop);
28
- };
@@ -1,179 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const { readFile, remove, stat } = require('fs-extra');
5
- const strapiGenerators = require('../../index');
6
-
7
- describe('Content Type Generator', () => {
8
- const outputDirectory = path.join(__dirname, 'output');
9
-
10
- afterEach(async () => {
11
- await remove(outputDirectory);
12
- });
13
-
14
- test('it generates the schema', async () => {
15
- await strapiGenerators.generate(
16
- 'content-type',
17
- {
18
- displayName: 'testContentType',
19
- singularName: 'testContentType',
20
- pluralName: 'testContentTypes',
21
- kind: 'singleType',
22
- id: 'testContentType',
23
- useDraftAndPublish: false,
24
- destination: 'new',
25
- bootstrapApi: false,
26
- attributes: [],
27
- },
28
- { dir: outputDirectory }
29
- );
30
-
31
- const generatedSchemaPath = path.join(
32
- outputDirectory,
33
- 'src/api/testContentType',
34
- 'content-types/testContentType/schema.json'
35
- );
36
-
37
- expect((await stat(generatedSchemaPath)).isFile()).toBeTruthy();
38
-
39
- const fileContent = await readFile(generatedSchemaPath, 'utf-8');
40
-
41
- expect(fileContent).not.toBeNull();
42
-
43
- const schema = JSON.parse(fileContent.toString());
44
-
45
- expect(schema).toStrictEqual({
46
- kind: 'singleType',
47
- collectionName: 'test_content_types',
48
- info: {
49
- singularName: 'testContentType',
50
- pluralName: 'testContentTypes',
51
- displayName: 'testContentType',
52
- },
53
- options: {
54
- draftAndPublish: false,
55
- comment: '',
56
- },
57
- attributes: {},
58
- });
59
- });
60
-
61
- test('it scaffolds a new API', async () => {
62
- await strapiGenerators.generate(
63
- 'content-type',
64
- {
65
- displayName: 'testContentType',
66
- singularName: 'testContentType',
67
- pluralName: 'testContentTypes',
68
- kind: 'singleType',
69
- id: 'testContentType',
70
- useDraftAndPublish: false,
71
- destination: 'new',
72
- bootstrapApi: true,
73
- attributes: [],
74
- },
75
- { dir: outputDirectory }
76
- );
77
- const generatedApiPath = path.join(outputDirectory, 'src/api/testContentType');
78
-
79
- expect((await stat(generatedApiPath)).isDirectory()).toBeTruthy();
80
- expect(
81
- (await stat(path.join(generatedApiPath, 'controllers/testContentType.js'))).isFile()
82
- ).toBeTruthy();
83
- expect(
84
- (await stat(path.join(generatedApiPath, 'services/testContentType.js'))).isFile()
85
- ).toBeTruthy();
86
- expect(
87
- (await stat(path.join(generatedApiPath, 'routes/testContentType.js'))).isFile()
88
- ).toBeTruthy();
89
-
90
- const controller = await readFile(
91
- path.join(generatedApiPath, 'controllers/testContentType.js')
92
- );
93
- const router = await readFile(path.join(generatedApiPath, 'routes/testContentType.js'));
94
- const service = await readFile(path.join(generatedApiPath, 'services/testContentType.js'));
95
-
96
- expect(controller.toString()).toMatchInlineSnapshot(`
97
- "'use strict';
98
-
99
- /**
100
- * testContentType controller
101
- */
102
-
103
- const { createCoreController } = require('@strapi/strapi').factories;
104
-
105
- module.exports = createCoreController('api::testContentType.testContentType');
106
- "
107
- `);
108
- expect(router.toString()).toMatchInlineSnapshot(`
109
- "'use strict';
110
-
111
- /**
112
- * testContentType router.
113
- */
114
-
115
- const { createCoreRouter } = require('@strapi/strapi').factories;
116
-
117
- module.exports = createCoreRouter('api::testContentType.testContentType');
118
- "
119
- `);
120
- expect(service.toString()).toMatchInlineSnapshot(`
121
- "'use strict';
122
-
123
- /**
124
- * testContentType service.
125
- */
126
-
127
- const { createCoreService } = require('@strapi/strapi').factories;
128
-
129
- module.exports = createCoreService('api::testContentType.testContentType');
130
- "
131
- `);
132
- });
133
-
134
- test('it generates the schema, then adds the attributes', async () => {
135
- await strapiGenerators.generate(
136
- 'content-type',
137
- {
138
- displayName: 'testContentType',
139
- singularName: 'testContentType',
140
- pluralName: 'testContentTypes',
141
- kind: 'singleType',
142
- id: 'testContentType',
143
- useDraftAndPublish: false,
144
- destination: 'new',
145
- bootstrapApi: false,
146
- attributes: [
147
- {
148
- attributeName: 'name',
149
- attributeType: 'string',
150
- },
151
- {
152
- attributeName: 'email',
153
- attributeType: 'string',
154
- },
155
- ],
156
- },
157
- { dir: outputDirectory }
158
- );
159
-
160
- const generatedSchemaPath = path.join(
161
- outputDirectory,
162
- 'src/api/testContentType',
163
- 'content-types/testContentType/schema.json'
164
- );
165
-
166
- expect((await stat(generatedSchemaPath)).isFile()).toBeTruthy();
167
-
168
- const fileContent = await readFile(generatedSchemaPath, 'utf-8');
169
-
170
- expect(fileContent).not.toBeNull();
171
-
172
- const schema = JSON.parse(fileContent.toString());
173
-
174
- expect(schema.attributes).toStrictEqual({
175
- email: { type: 'string' },
176
- name: { type: 'string' },
177
- });
178
- });
179
- });
package/lib/plops/api.js DELETED
@@ -1,82 +0,0 @@
1
- 'use strict';
2
-
3
- const { join } = require('path');
4
- const fs = require('fs-extra');
5
- const tsUtils = require('@strapi/typescript-utils');
6
-
7
- const validateInput = require('./utils/validate-input');
8
-
9
- module.exports = (plop) => {
10
- // API generator
11
- plop.setGenerator('api', {
12
- description: 'Generate a basic API',
13
- prompts: [
14
- {
15
- type: 'input',
16
- name: 'id',
17
- message: 'API name',
18
- validate: (input) => validateInput(input),
19
- },
20
- {
21
- type: 'confirm',
22
- name: 'isPluginApi',
23
- message: 'Is this API for a plugin?',
24
- },
25
- {
26
- when: (answers) => answers.isPluginApi,
27
- type: 'list',
28
- name: 'plugin',
29
- message: 'Plugin name',
30
- async choices() {
31
- const pluginsPath = join(plop.getDestBasePath(), 'plugins');
32
- const exists = await fs.pathExists(pluginsPath);
33
-
34
- if (!exists) {
35
- throw Error('Couldn\'t find a "plugins" directory');
36
- }
37
-
38
- const pluginsDir = await fs.readdir(pluginsPath, { withFileTypes: true });
39
- const pluginsDirContent = pluginsDir.filter((fd) => fd.isDirectory());
40
-
41
- if (pluginsDirContent.length === 0) {
42
- throw Error('The "plugins" directory is empty');
43
- }
44
-
45
- return pluginsDirContent;
46
- },
47
- },
48
- ],
49
- actions(answers) {
50
- const filePath =
51
- answers.isPluginApi && answers.plugin ? 'plugins/{{ plugin }}' : 'api/{{ id }}';
52
- const currentDir = process.cwd();
53
- const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
54
-
55
- const baseActions = [
56
- {
57
- type: 'add',
58
- path: `${filePath}/controllers/{{ id }}.${language}`,
59
- templateFile: `templates/${language}/controller.${language}.hbs`,
60
- },
61
- {
62
- type: 'add',
63
- path: `${filePath}/services/{{ id }}.${language}`,
64
- templateFile: `templates/${language}/service.${language}.hbs`,
65
- },
66
- ];
67
-
68
- if (answers.isPluginApi) {
69
- return baseActions;
70
- }
71
-
72
- return [
73
- {
74
- type: 'add',
75
- path: `${filePath}/routes/{{ id }}.${language}`,
76
- templateFile: `templates/${language}/single-route.${language}.hbs`,
77
- },
78
- ...baseActions,
79
- ];
80
- },
81
- });
82
- };