@strapi/generators 0.0.0-next.e41415e8ff5f565ff959667d5c5ba4f20bee013c → 0.0.0-next.e5d4b412da0d932b61b2fa5012d16513fda6de04

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
package/LICENSE CHANGED
@@ -2,7 +2,21 @@ Copyright (c) 2015-present Strapi Solutions SAS
2
2
 
3
3
  Portions of the Strapi software are licensed as follows:
4
4
 
5
- * All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined in "ee/LICENSE".
5
+ * All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined below.
6
+
7
+ Enterprise License
8
+
9
+ If you or the company you represent has entered into a written agreement referencing the Enterprise Edition of the Strapi source code available at
10
+ https://github.com/strapi/strapi, then such agreement applies to your use of the Enterprise Edition of the Strapi Software. If you or the company you
11
+ represent is using the Enterprise Edition of the Strapi Software in connection with a subscription to our cloud offering, then the agreement you have
12
+ agreed to with respect to our cloud offering and the licenses included in such agreement apply to your use of the Enterprise Edition of the Strapi Software.
13
+ Otherwise, the Strapi Enterprise Software License Agreement (found here https://strapi.io/enterprise-terms) applies to your use of the Enterprise Edition of the Strapi Software.
14
+
15
+ BY ACCESSING OR USING THE ENTERPRISE EDITION OF THE STRAPI SOFTWARE, YOU ARE AGREEING TO BE BOUND BY THE RELEVANT REFERENCED AGREEMENT.
16
+ IF YOU ARE NOT AUTHORIZED TO ACCEPT THESE TERMS ON BEHALF OF THE COMPANY YOU REPRESENT OR IF YOU DO NOT AGREE TO ALL OF THE RELEVANT TERMS AND CONDITIONS REFERENCED AND YOU
17
+ HAVE NOT OTHERWISE EXECUTED A WRITTEN AGREEMENT WITH STRAPI, YOU ARE NOT AUTHORIZED TO ACCESS OR USE OR ALLOW ANY USER TO ACCESS OR USE ANY PART OF
18
+ THE ENTERPRISE EDITION OF THE STRAPI SOFTWARE. YOUR ACCESS RIGHTS ARE CONDITIONAL ON YOUR CONSENT TO THE RELEVANT REFERENCED TERMS TO THE EXCLUSION OF ALL OTHER TERMS;
19
+ IF THE RELEVANT REFERENCED TERMS ARE CONSIDERED AN OFFER BY YOU, ACCEPTANCE IS EXPRESSLY LIMITED TO THE RELEVANT REFERENCED TERMS.
6
20
 
7
21
  * All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below.
8
22
 
@@ -18,5 +32,6 @@ furnished to do so, subject to the following conditions:
18
32
  The above copyright notice and this permission notice shall be included in all
19
33
  copies or substantial portions of the Software.
20
34
 
21
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- SOFTWARE.
35
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
37
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,10 @@
1
- export declare const runCLI: () => void;
2
- export declare const generate: (generatorName: string, options: unknown, { dir, plopFile }?: {
3
- dir?: string | undefined;
4
- plopFile?: string | undefined;
5
- }) => Promise<void>;
1
+ export declare const runCLI: () => Promise<void>;
2
+ type GenerateOptions = {
3
+ dir?: string;
4
+ plopFile?: string;
5
+ };
6
+ export declare const generate: <T extends Record<string, any>>(generatorName: string, options: T, { dir, plopFile }?: GenerateOptions) => Promise<{
7
+ success: boolean;
8
+ }>;
9
+ export {};
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,MAAM,qBAkBlB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAUF,eAAO,MAAM,QAAQ,iDACJ,MAAM,WACZ,CAAC,sBACyC,eAAe;;EAkDnE,CAAC"}
package/dist/index.js CHANGED
@@ -1,32 +1,98 @@
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
- exports.generate = exports.runCLI = void 0;
7
- const node_path_1 = require("node:path");
8
- const plop_1 = require("plop");
9
- const node_plop_1 = __importDefault(require("node-plop"));
1
+ 'use strict';
2
+
3
+ var node_path = require('node:path');
4
+ var handlebars = require('handlebars');
5
+ var fs = require('fs-extra');
6
+
10
7
  // Starts the Plop CLI programmatically
11
- const runCLI = () => {
12
- plop_1.Plop.launch({ configPath: (0, node_path_1.join)(__dirname, 'plopfile.js') }, (env) => {
13
- const options = { ...env, dest: (0, node_path_1.join)(process.cwd(), 'src') };
14
- (0, plop_1.run)(options, undefined, true);
8
+ const runCLI = async ()=>{
9
+ const { Plop, run } = await import('plop');
10
+ Plop.prepare({
11
+ configPath: node_path.join(__dirname, 'plopfile.js')
12
+ }, (env)=>{
13
+ const argv = process.argv.slice(2); // Extract command-line arguments
14
+ Plop.execute(env, argv, (env, argv)=>{
15
+ const options = {
16
+ ...env,
17
+ dest: node_path.join(process.cwd(), 'src')
18
+ };
19
+ return run(options, argv, true); // Pass the third argument 'true' for passArgsBeforeDashes
20
+ });
15
21
  });
16
22
  };
17
- exports.runCLI = runCLI;
18
- // Runs a generator programmatically without prompts
19
- const generate = async (generatorName, options, { dir = process.cwd(), plopFile = 'plopfile.js' } = {}) => {
20
- const plop = (0, node_plop_1.default)((0, node_path_1.join)(__dirname, plopFile), {
21
- destBasePath: (0, node_path_1.join)(dir, 'src'),
22
- force: false,
23
- });
24
- const generator = plop.getGenerator(generatorName);
25
- await generator.runActions(options, {
26
- onSuccess() { },
27
- onFailure() { },
28
- onComment() { },
29
- });
23
+ const generate = async (generatorName, options, { dir = process.cwd(), plopFile = 'plopfile.js' } = {})=>{
24
+ // Resolve the absolute path to the plopfile (generator definitions)
25
+ const plopfilePath = node_path.join(__dirname, plopFile);
26
+ // Dynamically require the plopfile module.
27
+ // Note: This allows loading either CommonJS or transpiled ESM plopfiles.
28
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
29
+ const plopModule = require(plopfilePath);
30
+ // Internal objects to store registered generators and helpers.
31
+ // These will be populated by the plopfile when it is executed.
32
+ const generators = {};
33
+ const helpers = {};
34
+ // Minimal mock Plop API implementation, exposing only the methods needed by our plopfile.
35
+ // This allows the plopfile to register generators and helpers as it would in a real Plop environment.
36
+ const plopApi = {
37
+ setGenerator (name, config) {
38
+ generators[name] = config;
39
+ },
40
+ setHelper (name, fn) {
41
+ helpers[name] = fn;
42
+ },
43
+ getDestBasePath () {
44
+ return node_path.join(dir, 'src');
45
+ },
46
+ setWelcomeMessage () {}
47
+ };
48
+ // Execute the plopfile, passing in our API.
49
+ // This will populate the `generators` and `helpers` objects.
50
+ // Support both CommonJS and ESM default exports.
51
+ if (typeof plopModule.default === 'function') {
52
+ plopModule.default(plopApi);
53
+ } else {
54
+ plopModule(plopApi);
55
+ }
56
+ const generator = generators[generatorName];
57
+ if (!generator) {
58
+ throw new Error(`Generator "${generatorName}" not found`);
59
+ }
60
+ registerHandlebarsHelpers(helpers);
61
+ const actions = typeof generator.actions === 'function' ? generator.actions(options) : generator.actions || [];
62
+ await executeActions(actions, options, dir);
63
+ return {
64
+ success: true
65
+ };
30
66
  };
67
+ const registerHandlebarsHelpers = (helpers)=>{
68
+ Object.entries(helpers).forEach(([name, fn])=>handlebars.registerHelper(name, fn));
69
+ };
70
+ // Executes generator actions: add or modify files as specified
71
+ const executeActions = async (actions, options, dir)=>{
72
+ for (const action of actions){
73
+ const outputPath = handlebars.compile(action.path)(options);
74
+ const fullPath = node_path.join(dir, 'src', outputPath);
75
+ if (action.type === 'add' && action.templateFile) {
76
+ const templatePath = node_path.join(__dirname, action.templateFile);
77
+ const templateContent = await fs.readFile(templatePath, 'utf8');
78
+ const compiled = handlebars.compile(templateContent);
79
+ const output = compiled({
80
+ ...options,
81
+ ...action.data
82
+ });
83
+ await fs.ensureDir(node_path.dirname(fullPath));
84
+ await fs.writeFile(fullPath, output);
85
+ }
86
+ if (action.type === 'modify') {
87
+ if (await fs.pathExists(fullPath)) {
88
+ const content = await fs.readFile(fullPath, 'utf8');
89
+ const modified = action.transform ? action.transform(content) : content;
90
+ await fs.writeFile(fullPath, modified);
91
+ }
92
+ }
93
+ }
94
+ };
95
+
31
96
  exports.generate = generate;
32
- //# sourceMappingURL=index.js.map
97
+ exports.runCLI = runCLI;
98
+ //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAiC;AACjC,+BAAiC;AACjC,0DAAiC;AAEjC,uCAAuC;AAChC,MAAM,MAAM,GAAG,GAAG,EAAE;IACzB,WAAI,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,IAAA,gBAAI,EAAC,SAAS,EAAE,aAAa,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE;QAClE,MAAM,OAAO,GAAG,EAAE,GAAG,GAAG,EAAE,IAAI,EAAE,IAAA,gBAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,EAAE,CAAC;QAC7D,IAAA,UAAG,EAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AALW,QAAA,MAAM,UAKjB;AAEF,oDAAoD;AAC7C,MAAM,QAAQ,GAAG,KAAK,EAC3B,aAAqB,EACrB,OAAgB,EAChB,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,GAAG,aAAa,EAAE,GAAG,EAAE,EACtD,EAAE;IACF,MAAM,IAAI,GAAG,IAAA,mBAAQ,EAAC,IAAA,gBAAI,EAAC,SAAS,EAAE,QAAQ,CAAC,EAAE;QAC/C,YAAY,EAAE,IAAA,gBAAI,EAAC,GAAG,EAAE,KAAK,CAAC;QAC9B,KAAK,EAAE,KAAK;KACb,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;IACnD,MAAM,SAAS,CAAC,UAAU,CAAC,OAAO,EAAE;QAClC,SAAS,KAAI,CAAC;QACd,SAAS,KAAI,CAAC;QACd,SAAS,KAAI,CAAC;KACf,CAAC,CAAC;AACL,CAAC,CAAC;AAhBW,QAAA,QAAQ,YAgBnB"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { join, dirname } from 'node:path';\nimport handlebars from 'handlebars';\nimport fs from 'fs-extra';\n\n// Starts the Plop CLI programmatically\nexport const runCLI = async () => {\n const { Plop, run } = await import('plop');\n\n Plop.prepare(\n {\n configPath: join(__dirname, 'plopfile.js'),\n },\n (env) => {\n const argv = process.argv.slice(2); // Extract command-line arguments\n Plop.execute(env, argv, (env, argv) => {\n const options = {\n ...env,\n dest: join(process.cwd(), 'src'), // this will make the destination path to be based on the cwd when calling the wrapper\n };\n return run(options, argv, true); // Pass the third argument 'true' for passArgsBeforeDashes\n });\n }\n );\n};\n\ntype GenerateOptions = {\n dir?: string;\n plopFile?: string;\n};\n\ntype GeneratorAction = {\n type: 'add' | 'modify';\n path: string;\n templateFile?: string;\n data?: Record<string, any>;\n transform?: (content: string) => string;\n};\n\nexport const generate = async <T extends Record<string, any>>(\n generatorName: string,\n options: T,\n { dir = process.cwd(), plopFile = 'plopfile.js' }: GenerateOptions = {}\n) => {\n // Resolve the absolute path to the plopfile (generator definitions)\n const plopfilePath = join(__dirname, plopFile);\n // Dynamically require the plopfile module.\n // Note: This allows loading either CommonJS or transpiled ESM plopfiles.\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const plopModule = require(plopfilePath);\n\n // Internal objects to store registered generators and helpers.\n // These will be populated by the plopfile when it is executed.\n const generators: Record<string, any> = {};\n const helpers: Record<string, any> = {};\n\n // Minimal mock Plop API implementation, exposing only the methods needed by our plopfile.\n // This allows the plopfile to register generators and helpers as it would in a real Plop environment.\n const plopApi = {\n setGenerator(name: string, config: any) {\n generators[name] = config;\n },\n setHelper(name: string, fn: any) {\n helpers[name] = fn;\n },\n getDestBasePath() {\n return join(dir, 'src');\n },\n setWelcomeMessage() {}, // no-op\n };\n\n // Execute the plopfile, passing in our API.\n // This will populate the `generators` and `helpers` objects.\n // Support both CommonJS and ESM default exports.\n if (typeof plopModule.default === 'function') {\n plopModule.default(plopApi);\n } else {\n plopModule(plopApi);\n }\n\n const generator = generators[generatorName];\n if (!generator) {\n throw new Error(`Generator \"${generatorName}\" not found`);\n }\n\n registerHandlebarsHelpers(helpers);\n const actions: GeneratorAction[] =\n typeof generator.actions === 'function' ? generator.actions(options) : generator.actions || [];\n\n await executeActions(actions, options, dir);\n\n return { success: true };\n};\n\nconst registerHandlebarsHelpers = (helpers: Record<string, any>) => {\n Object.entries(helpers).forEach(([name, fn]) => handlebars.registerHelper(name, fn));\n};\n\n// Executes generator actions: add or modify files as specified\nconst executeActions = async (\n actions: GeneratorAction[],\n options: Record<string, any>,\n dir: string\n) => {\n for (const action of actions) {\n const outputPath = handlebars.compile(action.path)(options);\n const fullPath = join(dir, 'src', outputPath);\n\n if (action.type === 'add' && action.templateFile) {\n const templatePath = join(__dirname, action.templateFile);\n const templateContent = await fs.readFile(templatePath, 'utf8');\n const compiled = handlebars.compile(templateContent);\n const output = compiled({ ...options, ...action.data });\n\n await fs.ensureDir(dirname(fullPath));\n await fs.writeFile(fullPath, output);\n }\n\n if (action.type === 'modify') {\n if (await fs.pathExists(fullPath)) {\n const content = await fs.readFile(fullPath, 'utf8');\n const modified = action.transform ? action.transform(content) : content;\n await fs.writeFile(fullPath, modified);\n }\n }\n }\n};\n"],"names":["runCLI","Plop","run","prepare","configPath","join","__dirname","env","argv","process","slice","execute","options","dest","cwd","generate","generatorName","dir","plopFile","plopfilePath","plopModule","require","generators","helpers","plopApi","setGenerator","name","config","setHelper","fn","getDestBasePath","setWelcomeMessage","default","generator","Error","registerHandlebarsHelpers","actions","executeActions","success","Object","entries","forEach","handlebars","registerHelper","action","outputPath","compile","path","fullPath","type","templateFile","templatePath","templateContent","fs","readFile","compiled","output","data","ensureDir","dirname","writeFile","pathExists","content","modified","transform"],"mappings":";;;;;;AAIA;MACaA,MAAS,GAAA,UAAA;IACpB,MAAM,EAAEC,IAAI,EAAEC,GAAG,EAAE,GAAG,MAAM,OAAO,MAAA,C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AA,GAAW3C,cAAKY,CAAAA,GAAAA,EAAK,KAAO4B,EAAAA,UAAAA,CAAAA;AAElC,QAAA,IAAID,OAAOK,IAAI,KAAK,KAASL,IAAAA,MAAAA,CAAOM,YAAY,EAAE;AAChD,YAAA,MAAMC,YAAe9C,GAAAA,cAAAA,CAAKC,SAAWsC,EAAAA,MAAAA,CAAOM,YAAY,CAAA;AACxD,YAAA,MAAME,eAAkB,GAAA,MAAMC,EAAGC,CAAAA,QAAQ,CAACH,YAAc,EAAA,MAAA,CAAA;YACxD,MAAMI,QAAAA,GAAWb,UAAWI,CAAAA,OAAO,CAACM,eAAAA,CAAAA;AACpC,YAAA,MAAMI,SAASD,QAAS,CAAA;AAAE,gBAAA,GAAG3C,OAAO;AAAE,gBAAA,GAAGgC,OAAOa;AAAK,aAAA,CAAA;YAErD,MAAMJ,EAAAA,CAAGK,SAAS,CAACC,iBAAQX,CAAAA,QAAAA,CAAAA,CAAAA;YAC3B,MAAMK,EAAAA,CAAGO,SAAS,CAACZ,QAAUQ,EAAAA,MAAAA,CAAAA;AAC/B;QAEA,IAAIZ,MAAAA,CAAOK,IAAI,KAAK,QAAU,EAAA;AAC5B,YAAA,IAAI,MAAMI,EAAAA,CAAGQ,UAAU,CAACb,QAAW,CAAA,EAAA;AACjC,gBAAA,MAAMc,OAAU,GAAA,MAAMT,EAAGC,CAAAA,QAAQ,CAACN,QAAU,EAAA,MAAA,CAAA;AAC5C,gBAAA,MAAMe,WAAWnB,MAAOoB,CAAAA,SAAS,GAAGpB,MAAOoB,CAAAA,SAAS,CAACF,OAAWA,CAAAA,GAAAA,OAAAA;gBAChE,MAAMT,EAAAA,CAAGO,SAAS,CAACZ,QAAUe,EAAAA,QAAAA,CAAAA;AAC/B;AACF;AACF;AACF,CAAA;;;;;"}
package/dist/index.mjs ADDED
@@ -0,0 +1,95 @@
1
+ import { join, dirname } from 'node:path';
2
+ import handlebars from 'handlebars';
3
+ import fs from 'fs-extra';
4
+
5
+ // Starts the Plop CLI programmatically
6
+ const runCLI = async ()=>{
7
+ const { Plop, run } = await import('plop');
8
+ Plop.prepare({
9
+ configPath: join(__dirname, 'plopfile.js')
10
+ }, (env)=>{
11
+ const argv = process.argv.slice(2); // Extract command-line arguments
12
+ Plop.execute(env, argv, (env, argv)=>{
13
+ const options = {
14
+ ...env,
15
+ dest: join(process.cwd(), 'src')
16
+ };
17
+ return run(options, argv, true); // Pass the third argument 'true' for passArgsBeforeDashes
18
+ });
19
+ });
20
+ };
21
+ const generate = async (generatorName, options, { dir = process.cwd(), plopFile = 'plopfile.js' } = {})=>{
22
+ // Resolve the absolute path to the plopfile (generator definitions)
23
+ const plopfilePath = join(__dirname, plopFile);
24
+ // Dynamically require the plopfile module.
25
+ // Note: This allows loading either CommonJS or transpiled ESM plopfiles.
26
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
27
+ const plopModule = require(plopfilePath);
28
+ // Internal objects to store registered generators and helpers.
29
+ // These will be populated by the plopfile when it is executed.
30
+ const generators = {};
31
+ const helpers = {};
32
+ // Minimal mock Plop API implementation, exposing only the methods needed by our plopfile.
33
+ // This allows the plopfile to register generators and helpers as it would in a real Plop environment.
34
+ const plopApi = {
35
+ setGenerator (name, config) {
36
+ generators[name] = config;
37
+ },
38
+ setHelper (name, fn) {
39
+ helpers[name] = fn;
40
+ },
41
+ getDestBasePath () {
42
+ return join(dir, 'src');
43
+ },
44
+ setWelcomeMessage () {}
45
+ };
46
+ // Execute the plopfile, passing in our API.
47
+ // This will populate the `generators` and `helpers` objects.
48
+ // Support both CommonJS and ESM default exports.
49
+ if (typeof plopModule.default === 'function') {
50
+ plopModule.default(plopApi);
51
+ } else {
52
+ plopModule(plopApi);
53
+ }
54
+ const generator = generators[generatorName];
55
+ if (!generator) {
56
+ throw new Error(`Generator "${generatorName}" not found`);
57
+ }
58
+ registerHandlebarsHelpers(helpers);
59
+ const actions = typeof generator.actions === 'function' ? generator.actions(options) : generator.actions || [];
60
+ await executeActions(actions, options, dir);
61
+ return {
62
+ success: true
63
+ };
64
+ };
65
+ const registerHandlebarsHelpers = (helpers)=>{
66
+ Object.entries(helpers).forEach(([name, fn])=>handlebars.registerHelper(name, fn));
67
+ };
68
+ // Executes generator actions: add or modify files as specified
69
+ const executeActions = async (actions, options, dir)=>{
70
+ for (const action of actions){
71
+ const outputPath = handlebars.compile(action.path)(options);
72
+ const fullPath = join(dir, 'src', outputPath);
73
+ if (action.type === 'add' && action.templateFile) {
74
+ const templatePath = join(__dirname, action.templateFile);
75
+ const templateContent = await fs.readFile(templatePath, 'utf8');
76
+ const compiled = handlebars.compile(templateContent);
77
+ const output = compiled({
78
+ ...options,
79
+ ...action.data
80
+ });
81
+ await fs.ensureDir(dirname(fullPath));
82
+ await fs.writeFile(fullPath, output);
83
+ }
84
+ if (action.type === 'modify') {
85
+ if (await fs.pathExists(fullPath)) {
86
+ const content = await fs.readFile(fullPath, 'utf8');
87
+ const modified = action.transform ? action.transform(content) : content;
88
+ await fs.writeFile(fullPath, modified);
89
+ }
90
+ }
91
+ }
92
+ };
93
+
94
+ export { generate, runCLI };
95
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { join, dirname } from 'node:path';\nimport handlebars from 'handlebars';\nimport fs from 'fs-extra';\n\n// Starts the Plop CLI programmatically\nexport const runCLI = async () => {\n const { Plop, run } = await import('plop');\n\n Plop.prepare(\n {\n configPath: join(__dirname, 'plopfile.js'),\n },\n (env) => {\n const argv = process.argv.slice(2); // Extract command-line arguments\n Plop.execute(env, argv, (env, argv) => {\n const options = {\n ...env,\n dest: join(process.cwd(), 'src'), // this will make the destination path to be based on the cwd when calling the wrapper\n };\n return run(options, argv, true); // Pass the third argument 'true' for passArgsBeforeDashes\n });\n }\n );\n};\n\ntype GenerateOptions = {\n dir?: string;\n plopFile?: string;\n};\n\ntype GeneratorAction = {\n type: 'add' | 'modify';\n path: string;\n templateFile?: string;\n data?: Record<string, any>;\n transform?: (content: string) => string;\n};\n\nexport const generate = async <T extends Record<string, any>>(\n generatorName: string,\n options: T,\n { dir = process.cwd(), plopFile = 'plopfile.js' }: GenerateOptions = {}\n) => {\n // Resolve the absolute path to the plopfile (generator definitions)\n const plopfilePath = join(__dirname, plopFile);\n // Dynamically require the plopfile module.\n // Note: This allows loading either CommonJS or transpiled ESM plopfiles.\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const plopModule = require(plopfilePath);\n\n // Internal objects to store registered generators and helpers.\n // These will be populated by the plopfile when it is executed.\n const generators: Record<string, any> = {};\n const helpers: Record<string, any> = {};\n\n // Minimal mock Plop API implementation, exposing only the methods needed by our plopfile.\n // This allows the plopfile to register generators and helpers as it would in a real Plop environment.\n const plopApi = {\n setGenerator(name: string, config: any) {\n generators[name] = config;\n },\n setHelper(name: string, fn: any) {\n helpers[name] = fn;\n },\n getDestBasePath() {\n return join(dir, 'src');\n },\n setWelcomeMessage() {}, // no-op\n };\n\n // Execute the plopfile, passing in our API.\n // This will populate the `generators` and `helpers` objects.\n // Support both CommonJS and ESM default exports.\n if (typeof plopModule.default === 'function') {\n plopModule.default(plopApi);\n } else {\n plopModule(plopApi);\n }\n\n const generator = generators[generatorName];\n if (!generator) {\n throw new Error(`Generator \"${generatorName}\" not found`);\n }\n\n registerHandlebarsHelpers(helpers);\n const actions: GeneratorAction[] =\n typeof generator.actions === 'function' ? generator.actions(options) : generator.actions || [];\n\n await executeActions(actions, options, dir);\n\n return { success: true };\n};\n\nconst registerHandlebarsHelpers = (helpers: Record<string, any>) => {\n Object.entries(helpers).forEach(([name, fn]) => handlebars.registerHelper(name, fn));\n};\n\n// Executes generator actions: add or modify files as specified\nconst executeActions = async (\n actions: GeneratorAction[],\n options: Record<string, any>,\n dir: string\n) => {\n for (const action of actions) {\n const outputPath = handlebars.compile(action.path)(options);\n const fullPath = join(dir, 'src', outputPath);\n\n if (action.type === 'add' && action.templateFile) {\n const templatePath = join(__dirname, action.templateFile);\n const templateContent = await fs.readFile(templatePath, 'utf8');\n const compiled = handlebars.compile(templateContent);\n const output = compiled({ ...options, ...action.data });\n\n await fs.ensureDir(dirname(fullPath));\n await fs.writeFile(fullPath, output);\n }\n\n if (action.type === 'modify') {\n if (await fs.pathExists(fullPath)) {\n const content = await fs.readFile(fullPath, 'utf8');\n const modified = action.transform ? action.transform(content) : content;\n await fs.writeFile(fullPath, modified);\n }\n }\n }\n};\n"],"names":["runCLI","Plop","run","prepare","configPath","join","__dirname","env","argv","process","slice","execute","options","dest","cwd","generate","generatorName","dir","plopFile","plopfilePath","plopModule","require","generators","helpers","plopApi","setGenerator","name","config","setHelper","fn","getDestBasePath","setWelcomeMessage","default","generator","Error","registerHandlebarsHelpers","actions","executeActions","success","Object","entries","forEach","handlebars","registerHelper","action","outputPath","compile","path","fullPath","type","templateFile","templatePath","templateContent","fs","readFile","compiled","output","data","ensureDir","dirname","writeFile","pathExists","content","modified","transform"],"mappings":";;;;AAIA;MACaA,MAAS,GAAA,UAAA;IACpB,MAAM,EAAEC,IAAI,EAAEC,GAAG,EAAE,GAAG,MAAM,OAAO,MAAA,CAAA;AAEnCD,IAAAA,IAAAA,CAAKE,OAAO,CACV;AACEC,QAAAA,UAAAA,EAAYC,KAAKC,SAAW,EAAA,aAAA;AAC9B,KAAA,EACA,CAACC,GAAAA,GAAAA;AACC,QAAA,MAAMC,OAAOC,OAAQD,CAAAA,IAAI,CAACE,KAAK,CAAC;AAChCT,QAAAA,IAAAA,CAAKU,OAAO,CAACJ,GAAKC,EAAAA,IAAAA,EAAM,CAACD,GAAKC,EAAAA,IAAAA,GAAAA;AAC5B,YAAA,MAAMI,OAAU,GAAA;AACd,gBAAA,GAAGL,GAAG;gBACNM,IAAMR,EAAAA,IAAAA,CAAKI,OAAQK,CAAAA,GAAG,EAAI,EAAA,KAAA;AAC5B,aAAA;AACA,YAAA,OAAOZ,GAAIU,CAAAA,OAAAA,EAASJ,IAAM,EAAA,IAAA,CAAA,CAAA;AAC5B,SAAA,CAA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ACC,OAAQX,CAAAA,QAAAA,CAAAA,CAAAA;YAC3B,MAAMK,EAAAA,CAAGO,SAAS,CAACZ,QAAUQ,EAAAA,MAAAA,CAAAA;AAC/B;QAEA,IAAIZ,MAAAA,CAAOK,IAAI,KAAK,QAAU,EAAA;AAC5B,YAAA,IAAI,MAAMI,EAAAA,CAAGQ,UAAU,CAACb,QAAW,CAAA,EAAA;AACjC,gBAAA,MAAMc,OAAU,GAAA,MAAMT,EAAGC,CAAAA,QAAQ,CAACN,QAAU,EAAA,MAAA,CAAA;AAC5C,gBAAA,MAAMe,WAAWnB,MAAOoB,CAAAA,SAAS,GAAGpB,MAAOoB,CAAAA,SAAS,CAACF,OAAWA,CAAAA,GAAAA,OAAAA;gBAChE,MAAMT,EAAAA,CAAGO,SAAS,CAACZ,QAAUe,EAAAA,QAAAA,CAAAA;AAC/B;AACF;AACF;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=plopfile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plopfile.d.ts","sourceRoot":"","sources":["../src/plopfile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;+BAUlB,WAAW;AAAjC,wBAaE"}
package/dist/plopfile.js CHANGED
@@ -1,29 +1,27 @@
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 pluralize_1 = __importDefault(require("pluralize"));
7
- const api_1 = __importDefault(require("./plops/api"));
8
- const controller_1 = __importDefault(require("./plops/controller"));
9
- const content_type_1 = __importDefault(require("./plops/content-type"));
10
- const plugin_1 = __importDefault(require("./plops/plugin"));
11
- const policy_1 = __importDefault(require("./plops/policy"));
12
- const middleware_1 = __importDefault(require("./plops/middleware"));
13
- const migration_1 = __importDefault(require("./plops/migration"));
14
- const service_1 = __importDefault(require("./plops/service"));
15
- exports.default = (plop) => {
1
+ 'use strict';
2
+
3
+ var pluralize = require('pluralize');
4
+ var api = require('./plops/api.js');
5
+ var controller = require('./plops/controller.js');
6
+ var contentType = require('./plops/content-type.js');
7
+ var policy = require('./plops/policy.js');
8
+ var middleware = require('./plops/middleware.js');
9
+ var migration = require('./plops/migration.js');
10
+ var service = require('./plops/service.js');
11
+
12
+ var plopfile = ((plop)=>{
16
13
  // Plop config
17
14
  plop.setWelcomeMessage('Strapi Generators');
18
- plop.addHelper('pluralize', (text) => (0, pluralize_1.default)(text));
15
+ plop.setHelper('pluralize', (text)=>pluralize(text));
19
16
  // Generators
20
- (0, api_1.default)(plop);
21
- (0, controller_1.default)(plop);
22
- (0, content_type_1.default)(plop);
23
- (0, plugin_1.default)(plop);
24
- (0, policy_1.default)(plop);
25
- (0, middleware_1.default)(plop);
26
- (0, migration_1.default)(plop);
27
- (0, service_1.default)(plop);
28
- };
29
- //# sourceMappingURL=plopfile.js.map
17
+ api(plop);
18
+ controller(plop);
19
+ contentType(plop);
20
+ policy(plop);
21
+ middleware(plop);
22
+ migration(plop);
23
+ service(plop);
24
+ });
25
+
26
+ module.exports = plopfile;
27
+ //# sourceMappingURL=plopfile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plopfile.js","sourceRoot":"","sources":["../src/plopfile.ts"],"names":[],"mappings":";;;;;AAAA,0DAAkC;AAGlC,sDAAsC;AACtC,oEAAoD;AACpD,wEAAuD;AACvD,4DAA4C;AAC5C,4DAA4C;AAC5C,oEAAoD;AACpD,kEAAkD;AAClD,8DAA8C;AAE9C,kBAAe,CAAC,IAAiB,EAAE,EAAE;IACnC,cAAc;IACd,IAAI,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,CAAC;IAC5C,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAA,mBAAS,EAAC,IAAI,CAAC,CAAC,CAAC;IAE/D,aAAa;IACb,IAAA,aAAW,EAAC,IAAI,CAAC,CAAC;IAClB,IAAA,oBAAkB,EAAC,IAAI,CAAC,CAAC;IACzB,IAAA,sBAAmB,EAAC,IAAI,CAAC,CAAC;IAC1B,IAAA,gBAAc,EAAC,IAAI,CAAC,CAAC;IACrB,IAAA,gBAAc,EAAC,IAAI,CAAC,CAAC;IACrB,IAAA,oBAAkB,EAAC,IAAI,CAAC,CAAC;IACzB,IAAA,mBAAiB,EAAC,IAAI,CAAC,CAAC;IACxB,IAAA,iBAAe,EAAC,IAAI,CAAC,CAAC;AACxB,CAAC,CAAC"}
1
+ {"version":3,"file":"plopfile.js","sources":["../src/plopfile.ts"],"sourcesContent":["import pluralize from 'pluralize';\nimport type { NodePlopAPI } from 'plop';\n\nimport generateApi from './plops/api';\nimport generateController from './plops/controller';\nimport generateContentType from './plops/content-type';\nimport generatePolicy from './plops/policy';\nimport generateMiddleware from './plops/middleware';\nimport generateMigration from './plops/migration';\nimport generateService from './plops/service';\n\nexport default (plop: NodePlopAPI) => {\n // Plop config\n plop.setWelcomeMessage('Strapi Generators');\n plop.setHelper('pluralize', (text: string) => pluralize(text));\n\n // Generators\n generateApi(plop);\n generateController(plop);\n generateContentType(plop);\n generatePolicy(plop);\n generateMiddleware(plop);\n generateMigration(plop);\n generateService(plop);\n};\n"],"names":["plop","setWelcomeMessage","setHelper","text","pluralize","generateApi","generateController","generateContentType","generatePolicy","generateMiddleware","generateMigration","generateService"],"mappings":";;;;;;;;;;;AAWA,eAAe,CAAA,CAACA,IAAAA,GAAAA;;AAEdA,IAAAA,IAAAA,CAAKC,iBAAiB,CAAC,mBAAA,CAAA;AACvBD,IAAAA,IAAAA,CAAKE,SAAS,CAAC,WAAa,EAAA,CAACC,OAAiBC,SAAUD,CAAAA,IAAAA,CAAAA,CAAAA;;IAGxDE,GAAYL,CAAAA,IAAAA,CAAAA;IACZM,UAAmBN,CAAAA,IAAAA,CAAAA;IACnBO,WAAoBP,CAAAA,IAAAA,CAAAA;IACpBQ,MAAeR,CAAAA,IAAAA,CAAAA;IACfS,UAAmBT,CAAAA,IAAAA,CAAAA;IACnBU,SAAkBV,CAAAA,IAAAA,CAAAA;IAClBW,OAAgBX,CAAAA,IAAAA,CAAAA;AAClB,CAAA;;;;"}
@@ -0,0 +1,25 @@
1
+ import pluralize from 'pluralize';
2
+ import generateApi from './plops/api.mjs';
3
+ import generateController from './plops/controller.mjs';
4
+ import generateContentType from './plops/content-type.mjs';
5
+ import generatePolicy from './plops/policy.mjs';
6
+ import generateMiddleware from './plops/middleware.mjs';
7
+ import generateMigration from './plops/migration.mjs';
8
+ import generateService from './plops/service.mjs';
9
+
10
+ var plopfile = ((plop)=>{
11
+ // Plop config
12
+ plop.setWelcomeMessage('Strapi Generators');
13
+ plop.setHelper('pluralize', (text)=>pluralize(text));
14
+ // Generators
15
+ generateApi(plop);
16
+ generateController(plop);
17
+ generateContentType(plop);
18
+ generatePolicy(plop);
19
+ generateMiddleware(plop);
20
+ generateMigration(plop);
21
+ generateService(plop);
22
+ });
23
+
24
+ export { plopfile as default };
25
+ //# sourceMappingURL=plopfile.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plopfile.mjs","sources":["../src/plopfile.ts"],"sourcesContent":["import pluralize from 'pluralize';\nimport type { NodePlopAPI } from 'plop';\n\nimport generateApi from './plops/api';\nimport generateController from './plops/controller';\nimport generateContentType from './plops/content-type';\nimport generatePolicy from './plops/policy';\nimport generateMiddleware from './plops/middleware';\nimport generateMigration from './plops/migration';\nimport generateService from './plops/service';\n\nexport default (plop: NodePlopAPI) => {\n // Plop config\n plop.setWelcomeMessage('Strapi Generators');\n plop.setHelper('pluralize', (text: string) => pluralize(text));\n\n // Generators\n generateApi(plop);\n generateController(plop);\n generateContentType(plop);\n generatePolicy(plop);\n generateMiddleware(plop);\n generateMigration(plop);\n generateService(plop);\n};\n"],"names":["plop","setWelcomeMessage","setHelper","text","pluralize","generateApi","generateController","generateContentType","generatePolicy","generateMiddleware","generateMigration","generateService"],"mappings":";;;;;;;;;AAWA,eAAe,CAAA,CAACA,IAAAA,GAAAA;;AAEdA,IAAAA,IAAAA,CAAKC,iBAAiB,CAAC,mBAAA,CAAA;AACvBD,IAAAA,IAAAA,CAAKE,SAAS,CAAC,WAAa,EAAA,CAACC,OAAiBC,SAAUD,CAAAA,IAAAA,CAAAA,CAAAA;;IAGxDE,WAAYL,CAAAA,IAAAA,CAAAA;IACZM,kBAAmBN,CAAAA,IAAAA,CAAAA;IACnBO,mBAAoBP,CAAAA,IAAAA,CAAAA;IACpBQ,cAAeR,CAAAA,IAAAA,CAAAA;IACfS,kBAAmBT,CAAAA,IAAAA,CAAAA;IACnBU,iBAAkBV,CAAAA,IAAAA,CAAAA;IAClBW,eAAgBX,CAAAA,IAAAA,CAAAA;AAClB,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=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/plops/api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;+BAMlB,WAAW;AAAjC,wBA4EE"}
package/dist/plops/api.js CHANGED
@@ -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 path_1 = require("path");
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const typescript_utils_1 = __importDefault(require("@strapi/typescript-utils"));
9
- const validate_input_1 = __importDefault(require("./utils/validate-input"));
10
- exports.default = (plop) => {
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var fs = require('fs-extra');
5
+ var tsUtils = require('@strapi/typescript-utils');
6
+ var validateInput = require('./utils/validate-input.js');
7
+
8
+ var generateApi = ((plop)=>{
11
9
  // API generator
12
10
  plop.setGenerator('api', {
13
11
  description: 'Generate a basic API',
@@ -16,51 +14,53 @@ exports.default = (plop) => {
16
14
  type: 'input',
17
15
  name: 'id',
18
16
  message: 'API name',
19
- validate: (input) => (0, validate_input_1.default)(input),
17
+ validate: (input)=>validateInput(input)
20
18
  },
21
19
  {
22
20
  type: 'confirm',
23
21
  name: 'isPluginApi',
24
- message: 'Is this API for a plugin?',
22
+ message: 'Is this API for a plugin?'
25
23
  },
26
24
  {
27
- when: (answers) => answers.isPluginApi,
25
+ when: (answers)=>answers.isPluginApi,
28
26
  type: 'list',
29
27
  name: 'plugin',
30
28
  message: 'Plugin name',
31
- async choices() {
32
- const pluginsPath = (0, path_1.join)(plop.getDestBasePath(), 'plugins');
33
- const exists = await fs_extra_1.default.pathExists(pluginsPath);
29
+ async choices () {
30
+ const pluginsPath = path.join(plop.getDestBasePath(), 'plugins');
31
+ const exists = await fs.pathExists(pluginsPath);
34
32
  if (!exists) {
35
33
  throw Error('Couldn\'t find a "plugins" directory');
36
34
  }
37
- const pluginsDir = await fs_extra_1.default.readdir(pluginsPath, { withFileTypes: true });
38
- const pluginsDirContent = pluginsDir.filter((fd) => fd.isDirectory());
35
+ const pluginsDir = await fs.readdir(pluginsPath, {
36
+ withFileTypes: true
37
+ });
38
+ const pluginsDirContent = pluginsDir.filter((fd)=>fd.isDirectory());
39
39
  if (pluginsDirContent.length === 0) {
40
40
  throw Error('The "plugins" directory is empty');
41
41
  }
42
42
  return pluginsDirContent;
43
- },
44
- },
43
+ }
44
+ }
45
45
  ],
46
- actions(answers) {
46
+ actions (answers) {
47
47
  if (!answers) {
48
48
  return [];
49
49
  }
50
- const filePath = answers.isPluginApi && answers.plugin ? 'plugins/{{ plugin }}' : 'api/{{ id }}';
50
+ const filePath = answers.isPluginApi && answers.plugin ? 'plugins/{{ plugin }}/server' : 'api/{{ id }}';
51
51
  const currentDir = process.cwd();
52
- const language = typescript_utils_1.default.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
52
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
53
53
  const baseActions = [
54
54
  {
55
55
  type: 'add',
56
56
  path: `${filePath}/controllers/{{ id }}.${language}`,
57
- templateFile: `templates/${language}/controller.${language}.hbs`,
57
+ templateFile: `templates/${language}/controller.${language}.hbs`
58
58
  },
59
59
  {
60
60
  type: 'add',
61
61
  path: `${filePath}/services/{{ id }}.${language}`,
62
- templateFile: `templates/${language}/service.${language}.hbs`,
63
- },
62
+ templateFile: `templates/${language}/service.${language}.hbs`
63
+ }
64
64
  ];
65
65
  if (answers.isPluginApi) {
66
66
  return baseActions;
@@ -69,11 +69,13 @@ exports.default = (plop) => {
69
69
  {
70
70
  type: 'add',
71
71
  path: `${filePath}/routes/{{ id }}.${language}`,
72
- templateFile: `templates/${language}/single-route.${language}.hbs`,
72
+ templateFile: `templates/${language}/single-route.${language}.hbs`
73
73
  },
74
- ...baseActions,
74
+ ...baseActions
75
75
  ];
76
- },
76
+ }
77
77
  });
78
- };
79
- //# sourceMappingURL=api.js.map
78
+ });
79
+
80
+ module.exports = generateApi;
81
+ //# sourceMappingURL=api.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/plops/api.ts"],"names":[],"mappings":";;;;;AACA,+BAA4B;AAC5B,wDAA0B;AAC1B,gFAA+C;AAE/C,4EAAmD;AAEnD,kBAAe,CAAC,IAAiB,EAAE,EAAE;IACnC,gBAAgB;IAChB,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE;QACvB,WAAW,EAAE,sBAAsB;QACnC,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,IAAI;gBACV,OAAO,EAAE,UAAU;gBACnB,QAAQ,EAAE,CAAC,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,GAAG,0BAAO,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;YAEzE,MAAM,WAAW,GAAG;gBAClB;oBACE,IAAI,EAAE,KAAK;oBACX,IAAI,EAAE,GAAG,QAAQ,yBAAyB,QAAQ,EAAE;oBACpD,YAAY,EAAE,aAAa,QAAQ,eAAe,QAAQ,MAAM;iBACjE;gBACD;oBACE,IAAI,EAAE,KAAK;oBACX,IAAI,EAAE,GAAG,QAAQ,sBAAsB,QAAQ,EAAE;oBACjD,YAAY,EAAE,aAAa,QAAQ,YAAY,QAAQ,MAAM;iBAC9D;aACF,CAAC;YAEF,IAAI,OAAO,CAAC,WAAW,EAAE;gBACvB,OAAO,WAAW,CAAC;aACpB;YAED,OAAO;gBACL;oBACE,IAAI,EAAE,KAAK;oBACX,IAAI,EAAE,GAAG,QAAQ,oBAAoB,QAAQ,EAAE;oBAC/C,YAAY,EAAE,aAAa,QAAQ,iBAAiB,QAAQ,MAAM;iBACnE;gBACD,GAAG,WAAW;aACf,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
1
+ {"version":3,"file":"api.js","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;AACA,YAAA;gBACEJ,IAAM,EAAA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