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

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 (195) 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 +92 -27
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +94 -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 +107 -37
  17. package/dist/plops/api.js.map +1 -1
  18. package/dist/plops/api.mjs +147 -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 +170 -83
  23. package/dist/plops/content-type.js.map +1 -1
  24. package/dist/plops/content-type.mjs +243 -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 +54 -21
  29. package/dist/plops/controller.js.map +1 -1
  30. package/dist/plops/controller.mjs +71 -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 +56 -21
  35. package/dist/plops/middleware.js.map +1 -1
  36. package/dist/plops/middleware.mjs +73 -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 +56 -21
  47. package/dist/plops/policy.js.map +1 -1
  48. package/dist/plops/policy.mjs +73 -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 -43
  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 +53 -20
  83. package/dist/plops/service.js.map +1 -1
  84. package/dist/plops/service.mjs +69 -0
  85. package/dist/plops/service.mjs.map +1 -0
  86. package/dist/plops/utils/extend-plugin-index-files.d.ts +8 -0
  87. package/dist/plops/utils/extend-plugin-index-files.d.ts.map +1 -0
  88. package/dist/plops/utils/extend-plugin-index-files.js +356 -0
  89. package/dist/plops/utils/extend-plugin-index-files.js.map +1 -0
  90. package/dist/plops/utils/extend-plugin-index-files.mjs +335 -0
  91. package/dist/plops/utils/extend-plugin-index-files.mjs.map +1 -0
  92. package/dist/plops/utils/get-file-path.d.ts +2 -1
  93. package/dist/plops/utils/get-file-path.d.ts.map +1 -0
  94. package/dist/plops/utils/get-file-path.js +9 -7
  95. package/dist/plops/utils/get-file-path.js.map +1 -1
  96. package/dist/plops/utils/get-file-path.mjs +15 -0
  97. package/dist/plops/utils/get-file-path.mjs.map +1 -0
  98. package/dist/plops/utils/get-formatted-date.d.ts +1 -0
  99. package/dist/plops/utils/get-formatted-date.d.ts.map +1 -0
  100. package/dist/plops/utils/get-formatted-date.js +8 -9
  101. package/dist/plops/utils/get-formatted-date.js.map +1 -1
  102. package/dist/plops/utils/get-formatted-date.mjs +6 -0
  103. package/dist/plops/utils/get-formatted-date.mjs.map +1 -0
  104. package/dist/plops/utils/validate-attribute-input.d.ts +1 -0
  105. package/dist/plops/utils/validate-attribute-input.d.ts.map +1 -0
  106. package/dist/plops/utils/validate-attribute-input.js +7 -5
  107. package/dist/plops/utils/validate-attribute-input.js.map +1 -1
  108. package/dist/plops/utils/validate-attribute-input.mjs +10 -0
  109. package/dist/plops/utils/validate-attribute-input.mjs.map +1 -0
  110. package/dist/plops/utils/validate-file-name-input.d.ts +1 -0
  111. package/dist/plops/utils/validate-file-name-input.d.ts.map +1 -0
  112. package/dist/plops/utils/validate-file-name-input.js +7 -5
  113. package/dist/plops/utils/validate-file-name-input.js.map +1 -1
  114. package/dist/plops/utils/validate-file-name-input.mjs +10 -0
  115. package/dist/plops/utils/validate-file-name-input.mjs.map +1 -0
  116. package/dist/plops/utils/validate-input.d.ts +1 -0
  117. package/dist/plops/utils/validate-input.d.ts.map +1 -0
  118. package/dist/plops/utils/validate-input.js +7 -5
  119. package/dist/plops/utils/validate-input.js.map +1 -1
  120. package/dist/plops/utils/validate-input.mjs +10 -0
  121. package/dist/plops/utils/validate-input.mjs.map +1 -0
  122. package/dist/templates/js/content-type.schema.json.hbs +0 -1
  123. package/dist/templates/js/plugin/plugin.routes.index.js.hbs +12 -0
  124. package/dist/templates/js/plugin/plugin.routes.type.index.js.hbs +6 -0
  125. package/dist/templates/ts/content-type.schema.json.hbs +0 -1
  126. package/dist/templates/ts/core-controller.ts.hbs +1 -1
  127. package/dist/templates/ts/middleware.ts.hbs +2 -2
  128. package/dist/templates/ts/plugin/plugin.routes.index.ts.hbs +9 -0
  129. package/dist/templates/ts/plugin/plugin.routes.type.index.ts.hbs +4 -0
  130. package/package.json +25 -17
  131. package/dist/files/js/plugin/.editorconfig +0 -7
  132. package/dist/files/js/plugin/.gitattributes +0 -103
  133. package/dist/files/js/plugin/admin/src/components/Initializer/index.js +0 -26
  134. package/dist/files/js/plugin/admin/src/components/PluginIcon/index.js +0 -12
  135. package/dist/files/js/plugin/admin/src/index.js +0 -63
  136. package/dist/files/js/plugin/admin/src/pages/App/index.js +0 -25
  137. package/dist/files/js/plugin/admin/src/pages/HomePage/index.js +0 -20
  138. package/dist/files/js/plugin/admin/src/pluginId.js +0 -5
  139. package/dist/files/js/plugin/admin/src/translations/en.json +0 -1
  140. package/dist/files/js/plugin/admin/src/translations/fr.json +0 -1
  141. package/dist/files/js/plugin/admin/src/utils/getTrad.js +0 -5
  142. package/dist/files/js/plugin/server/bootstrap.js +0 -5
  143. package/dist/files/js/plugin/server/config/index.js +0 -6
  144. package/dist/files/js/plugin/server/controllers/index.js +0 -7
  145. package/dist/files/js/plugin/server/controllers/my-controller.js.hbs +0 -10
  146. package/dist/files/js/plugin/server/destroy.js +0 -5
  147. package/dist/files/js/plugin/server/index.js +0 -25
  148. package/dist/files/js/plugin/server/middlewares/index.js +0 -3
  149. package/dist/files/js/plugin/server/policies/index.js +0 -3
  150. package/dist/files/js/plugin/server/register.js +0 -5
  151. package/dist/files/js/plugin/server/routes/index.js +0 -10
  152. package/dist/files/js/plugin/server/services/index.js +0 -7
  153. package/dist/files/js/plugin/server/services/my-service.js +0 -7
  154. package/dist/files/js/plugin/strapi-admin.js +0 -3
  155. package/dist/files/js/plugin/strapi-server.js +0 -3
  156. package/dist/files/ts/plugin/.editorconfig +0 -7
  157. package/dist/files/ts/plugin/.gitattributes +0 -103
  158. package/dist/files/ts/plugin/admin/src/components/Initializer/index.tsx +0 -24
  159. package/dist/files/ts/plugin/admin/src/components/PluginIcon/index.tsx +0 -12
  160. package/dist/files/ts/plugin/admin/src/index.tsx +0 -67
  161. package/dist/files/ts/plugin/admin/src/pages/App/index.tsx +0 -25
  162. package/dist/files/ts/plugin/admin/src/pages/HomePage/index.tsx +0 -19
  163. package/dist/files/ts/plugin/admin/src/pluginId.ts +0 -5
  164. package/dist/files/ts/plugin/admin/src/translations/en.json +0 -1
  165. package/dist/files/ts/plugin/admin/src/translations/fr.json +0 -1
  166. package/dist/files/ts/plugin/admin/src/utils/getTrad.ts +0 -5
  167. package/dist/files/ts/plugin/custom.d.ts +0 -5
  168. package/dist/files/ts/plugin/server/bootstrap.ts +0 -5
  169. package/dist/files/ts/plugin/server/config/index.ts +0 -4
  170. package/dist/files/ts/plugin/server/controllers/index.ts +0 -5
  171. package/dist/files/ts/plugin/server/controllers/my-controller.ts.hbs +0 -10
  172. package/dist/files/ts/plugin/server/destroy.ts +0 -5
  173. package/dist/files/ts/plugin/server/index.ts +0 -23
  174. package/dist/files/ts/plugin/server/middlewares/index.ts +0 -1
  175. package/dist/files/ts/plugin/server/policies/index.ts +0 -1
  176. package/dist/files/ts/plugin/server/register.ts +0 -5
  177. package/dist/files/ts/plugin/server/routes/index.ts +0 -10
  178. package/dist/files/ts/plugin/server/services/index.ts +0 -5
  179. package/dist/files/ts/plugin/server/services/my-service.ts +0 -7
  180. package/dist/files/ts/plugin/strapi-admin.js +0 -3
  181. package/dist/files/ts/plugin/strapi-server.js +0 -3
  182. package/dist/files/ts/plugin/tsconfig.json +0 -20
  183. package/dist/files/ts/plugin/tsconfig.server.json +0 -25
  184. package/dist/plops/plugin.d.ts +0 -3
  185. package/dist/plops/plugin.js +0 -107
  186. package/dist/plops/plugin.js.map +0 -1
  187. package/dist/plops/prompts/draft-and-publish-prompts.d.ts +0 -3
  188. package/dist/plops/prompts/draft-and-publish-prompts.js +0 -12
  189. package/dist/plops/prompts/draft-and-publish-prompts.js.map +0 -1
  190. package/dist/templates/js/README.md.hbs +0 -3
  191. package/dist/templates/js/plugin-package.json.hbs +0 -42
  192. package/dist/templates/ts/README.md.hbs +0 -3
  193. package/dist/templates/ts/plugin-package.json.hbs +0 -51
  194. /package/dist/{files/js/plugin/server/content-types/index.js → templates/js/plugin/plugin.index.js.hbs} +0 -0
  195. /package/dist/{files/ts/plugin/server/content-types/index.ts → templates/ts/plugin/plugin.index.ts.hbs} +0 -0
@@ -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';\nimport { appendToFile } from './utils/extend-plugin-index-files';\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 let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\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.plugin) {\n const indexPath = join(\n plop.getDestBasePath(),\n `${filePath}/content-types/index.${language}`\n );\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/content-types/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new content type to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/content-types/index.${language}`,\n transform(template: string) {\n return appendToFile(template, {\n type: 'content-type',\n singularName: answers.singularName,\n });\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/${answers.plugin ? 'content-api/' : ''}{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-router.${language}.hbs`,\n data: { uid },\n }\n );\n\n if (answers.plugin) {\n const indexFiles = ['controllers', 'services', 'routes'];\n\n indexFiles.forEach((type) => {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists && type !== 'routes') {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n if (type === 'routes') {\n const indexPath = join(\n plop.getDestBasePath(),\n `${filePath}/${type}/index.${language}`\n );\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.routes.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n const routeIndexFiles = ['content-api', 'admin'];\n\n routeIndexFiles.forEach((routeType) => {\n const routeTypeIndexPath = join(\n plop.getDestBasePath(),\n `${filePath}/${type}/${routeType}/index.${language}`\n );\n const routeTypeExists = fs.existsSync(routeTypeIndexPath);\n\n if (!routeTypeExists) {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/${routeType}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.routes.type.index.${language}.hbs`,\n data: { type: routeType },\n skipIfExists: true,\n });\n }\n });\n }\n\n baseActions.push({\n type: 'modify',\n path: `${filePath}/${type}/${type === 'routes' ? 'content-api/' : ''}index.${language}`,\n transform(template: string) {\n if (type === 'routes') {\n return appendToFile(template, {\n type: 'routes',\n singularName: answers.singularName,\n });\n }\n\n return appendToFile(template, {\n type: 'index',\n singularName: answers.singularName,\n });\n },\n });\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","plugin","pluginServerDir","replace","baseActions","path","templateFile","data","collectionName","slugify","pluralName","separator","entries","length","push","transform","template","parsedTemplate","JSON","parse","stringify","indexPath","existsSync","skipIfExists","appendToFile","bootstrapApi","uid","id","indexFiles","forEach","routeIndexFiles","routeType","routeTypeIndexPath","routeTypeExists"],"mappings":";;;;;;;;;;;;;AAeA,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,I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qE,aAAaR,QAAU,EAAA;oCAC5BhE,IAAM,EAAA,OAAA;AACNG,oCAAAA,YAAAA,EAAcL,QAAQK;AACxB,iCAAA,CAAA;AACF;AACF,yBAAA,CAAA;AACF,qBAAA,CAAA;AACF;AACF;YAEA,OAAOiD,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,EAAc,WAAW,EAAE,MAAM,MAAM,CAAC;+BAU9B,WAAW;AAAjC,wBAoEE"}
@@ -1,13 +1,14 @@
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 path = require('path');
5
+ var fs = require('fs');
6
+ var getDestinationPrompts = require('./prompts/get-destination-prompts.js');
7
+ var getFilePath = require('./utils/get-file-path.js');
8
+ var validateInput = require('./utils/validate-input.js');
9
+ var extendPluginIndexFiles = require('./utils/extend-plugin-index-files.js');
10
+
11
+ var generateController = ((plop)=>{
11
12
  // Controller generator
12
13
  plop.setGenerator('controller', {
13
14
  description: 'Generate a controller for an API',
@@ -16,25 +17,57 @@ exports.default = (plop) => {
16
17
  type: 'input',
17
18
  name: 'id',
18
19
  message: 'Controller name',
19
- validate: (input) => (0, validate_input_1.default)(input),
20
+ validate: (input)=>validateInput(input)
20
21
  },
21
- ...(0, get_destination_prompts_1.default)('controller', plop.getDestBasePath()),
22
+ ...getDestinationPrompts('controller', plop.getDestBasePath())
22
23
  ],
23
- actions(answers) {
24
+ actions (answers) {
24
25
  if (!answers) {
25
26
  return [];
26
27
  }
27
- const filePath = (0, get_file_path_1.default)(answers.destination);
28
+ const filePath = getFilePath(answers.destination);
28
29
  const currentDir = process.cwd();
29
- const language = typescript_utils_1.default.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
30
- return [
30
+ let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
31
+ if (answers.plugin) {
32
+ // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
33
+ const pluginServerDir = path.join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
34
+ language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
35
+ }
36
+ const baseActions = [
31
37
  {
32
38
  type: 'add',
33
39
  path: `${filePath}/controllers/{{ id }}.${language}`,
34
- templateFile: `templates/${language}/controller.${language}.hbs`,
35
- },
40
+ templateFile: `templates/${language}/controller.${language}.hbs`
41
+ }
36
42
  ];
37
- },
43
+ if (answers.plugin) {
44
+ const indexPath = path.join(plop.getDestBasePath(), `${filePath}/controllers/index.${language}`);
45
+ const exists = fs.existsSync(indexPath);
46
+ if (!exists) {
47
+ // Create index file if it doesn't exist
48
+ baseActions.push({
49
+ type: 'add',
50
+ path: `${filePath}/controllers/index.${language}`,
51
+ templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
52
+ skipIfExists: true
53
+ });
54
+ }
55
+ // Append the new controller to the index.ts file
56
+ baseActions.push({
57
+ type: 'modify',
58
+ path: `${filePath}/controllers/index.${language}`,
59
+ transform (template) {
60
+ return extendPluginIndexFiles.appendToFile(template, {
61
+ type: 'index',
62
+ singularName: answers.id
63
+ });
64
+ }
65
+ });
66
+ }
67
+ return baseActions;
68
+ }
38
69
  });
39
- };
40
- //# sourceMappingURL=controller.js.map
70
+ });
71
+
72
+ module.exports = generateController;
73
+ //# 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 { ActionType, NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport { join } from 'path';\nimport fs from 'fs';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport validateInput from './utils/validate-input';\nimport { appendToFile } from './utils/extend-plugin-index-files';\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 let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/controllers/{{ id }}.${language}`,\n templateFile: `templates/${language}/controller.${language}.hbs`,\n },\n ];\n\n if (answers.plugin) {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/controllers/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/controllers/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new controller to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/controllers/index.${language}`,\n transform(template: string) {\n return appendToFile(template, { type: 'index', singularName: answers.id });\n },\n });\n }\n\n return baseActions;\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","plugin","pluginServerDir","join","replace","baseActions","path","templateFile","indexPath","exists","fs","existsSync","push","skipIfExists","transform","template","appendToFile","singularName","id"],"mappings":";;;;;;;;;;AAUA,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,IAAIC,QAAWC,GAAAA,OAAAA,CAAQC,qBAAqB,CAACL,cAAc,IAAO,GAAA,IAAA;YAElE,IAAIJ,OAAAA,CAAQU,MAAM,EAAE;;gBAElB,MAAMC,eAAAA,GAAkBC,SACtBR,CAAAA,UAAAA,EACA,KACAH,EAAAA,QAAAA,CAASY,OAAO,CAAC,cAAA,EAAgBb,OAAQU,CAAAA,MAAM,CAC/C,EAAA,KAAA,CAAA;AAEFH,gBAAAA,QAAAA,GAAWC,OAAQC,CAAAA,qBAAqB,CAACE,eAAAA,CAAAA,GAAmB,IAAO,GAAA,IAAA;AACrE;AAEA,YAAA,MAAMG,WAAiC,GAAA;AACrC,g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@@ -0,0 +1,71 @@
1
+ import tsUtils from '@strapi/typescript-utils';
2
+ import { join } from 'path';
3
+ import fs from 'fs';
4
+ import getDestinationPrompts from './prompts/get-destination-prompts.mjs';
5
+ import getFilePath from './utils/get-file-path.mjs';
6
+ import validateInput from './utils/validate-input.mjs';
7
+ import { appendToFile } from './utils/extend-plugin-index-files.mjs';
8
+
9
+ var generateController = ((plop)=>{
10
+ // Controller generator
11
+ plop.setGenerator('controller', {
12
+ description: 'Generate a controller for an API',
13
+ prompts: [
14
+ {
15
+ type: 'input',
16
+ name: 'id',
17
+ message: 'Controller name',
18
+ validate: (input)=>validateInput(input)
19
+ },
20
+ ...getDestinationPrompts('controller', plop.getDestBasePath())
21
+ ],
22
+ actions (answers) {
23
+ if (!answers) {
24
+ return [];
25
+ }
26
+ const filePath = getFilePath(answers.destination);
27
+ const currentDir = process.cwd();
28
+ let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
29
+ if (answers.plugin) {
30
+ // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
31
+ const pluginServerDir = join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
32
+ language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
33
+ }
34
+ const baseActions = [
35
+ {
36
+ type: 'add',
37
+ path: `${filePath}/controllers/{{ id }}.${language}`,
38
+ templateFile: `templates/${language}/controller.${language}.hbs`
39
+ }
40
+ ];
41
+ if (answers.plugin) {
42
+ const indexPath = join(plop.getDestBasePath(), `${filePath}/controllers/index.${language}`);
43
+ const exists = fs.existsSync(indexPath);
44
+ if (!exists) {
45
+ // Create index file if it doesn't exist
46
+ baseActions.push({
47
+ type: 'add',
48
+ path: `${filePath}/controllers/index.${language}`,
49
+ templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
50
+ skipIfExists: true
51
+ });
52
+ }
53
+ // Append the new controller to the index.ts file
54
+ baseActions.push({
55
+ type: 'modify',
56
+ path: `${filePath}/controllers/index.${language}`,
57
+ transform (template) {
58
+ return appendToFile(template, {
59
+ type: 'index',
60
+ singularName: answers.id
61
+ });
62
+ }
63
+ });
64
+ }
65
+ return baseActions;
66
+ }
67
+ });
68
+ });
69
+
70
+ export { generateController as default };
71
+ //# sourceMappingURL=controller.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller.mjs","sources":["../../src/plops/controller.ts"],"sourcesContent":["import type { ActionType, NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport { join } from 'path';\nimport fs from 'fs';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport validateInput from './utils/validate-input';\nimport { appendToFile } from './utils/extend-plugin-index-files';\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 let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/controllers/{{ id }}.${language}`,\n templateFile: `templates/${language}/controller.${language}.hbs`,\n },\n ];\n\n if (answers.plugin) {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/controllers/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/controllers/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new controller to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/controllers/index.${language}`,\n transform(template: string) {\n return appendToFile(template, { type: 'index', singularName: answers.id });\n },\n });\n }\n\n return baseActions;\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","plugin","pluginServerDir","join","replace","baseActions","path","templateFile","indexPath","exists","fs","existsSync","push","skipIfExists","transform","template","appendToFile","singularName","id"],"mappings":";;;;;;;;AAUA,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,IAAIC,QAAWC,GAAAA,OAAAA,CAAQC,qBAAqB,CAACL,cAAc,IAAO,GAAA,IAAA;YAElE,IAAIJ,OAAAA,CAAQU,MAAM,EAAE;;gBAElB,MAAMC,eAAAA,GAAkBC,IACtBR,CAAAA,UAAAA,EACA,KACAH,EAAAA,QAAAA,CAASY,OAAO,CA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A,OAAOC,aAAaD,QAAU,EAAA;4BAAEjC,IAAM,EAAA,OAAA;AAASmC,4BAAAA,YAAAA,EAAc1B,QAAQ2B;AAAG,yBAAA,CAAA;AAC1E;AACF,iBAAA,CAAA;AACF;YAEA,OAAOb,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=middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/plops/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,MAAM,CAAC;+BAU9B,WAAW;AAAjC,wBAoEE"}
@@ -1,13 +1,14 @@
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 validate_input_1 = __importDefault(require("./utils/validate-input"));
9
- const get_file_path_1 = __importDefault(require("./utils/get-file-path"));
10
- exports.default = (plop) => {
1
+ 'use strict';
2
+
3
+ var tsUtils = require('@strapi/typescript-utils');
4
+ var path = require('path');
5
+ var fs = require('fs');
6
+ var getDestinationPrompts = require('./prompts/get-destination-prompts.js');
7
+ var validateInput = require('./utils/validate-input.js');
8
+ var getFilePath = require('./utils/get-file-path.js');
9
+ var extendPluginIndexFiles = require('./utils/extend-plugin-index-files.js');
10
+
11
+ var generateMiddleware = ((plop)=>{
11
12
  // middleware generator
12
13
  plop.setGenerator('middleware', {
13
14
  description: 'Generate a middleware for an API',
@@ -16,25 +17,59 @@ exports.default = (plop) => {
16
17
  type: 'input',
17
18
  name: 'name',
18
19
  message: 'Middleware name',
19
- validate: (input) => (0, validate_input_1.default)(input),
20
+ validate: (input)=>validateInput(input)
20
21
  },
21
- ...(0, get_destination_prompts_1.default)('middleware', plop.getDestBasePath(), { rootFolder: true }),
22
+ ...getDestinationPrompts('middleware', plop.getDestBasePath(), {
23
+ rootFolder: true
24
+ })
22
25
  ],
23
- actions(answers) {
26
+ actions (answers) {
24
27
  if (!answers) {
25
28
  return [];
26
29
  }
27
- const filePath = (0, get_file_path_1.default)(answers.destination);
30
+ const filePath = getFilePath(answers.destination);
28
31
  const currentDir = process.cwd();
29
- const language = typescript_utils_1.default.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
30
- return [
32
+ let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
33
+ if (answers.plugin) {
34
+ // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
35
+ const pluginServerDir = path.join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
36
+ language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
37
+ }
38
+ const baseActions = [
31
39
  {
32
40
  type: 'add',
33
41
  path: `${filePath}/middlewares/{{ name }}.${language}`,
34
- templateFile: `templates/${language}/middleware.${language}.hbs`,
35
- },
42
+ templateFile: `templates/${language}/middleware.${language}.hbs`
43
+ }
36
44
  ];
37
- },
45
+ if (answers.plugin) {
46
+ const indexPath = path.join(plop.getDestBasePath(), `${filePath}/middlewares/index.${language}`);
47
+ const exists = fs.existsSync(indexPath);
48
+ if (!exists) {
49
+ // Create index file if it doesn't exist
50
+ baseActions.push({
51
+ type: 'add',
52
+ path: `${filePath}/middlewares/index.${language}`,
53
+ templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
54
+ skipIfExists: true
55
+ });
56
+ }
57
+ // Append the new middleware to the index.ts file
58
+ baseActions.push({
59
+ type: 'modify',
60
+ path: `${filePath}/middlewares/index.${language}`,
61
+ transform (template) {
62
+ return extendPluginIndexFiles.appendToFile(template, {
63
+ type: 'index',
64
+ singularName: answers.name
65
+ });
66
+ }
67
+ });
68
+ }
69
+ return baseActions;
70
+ }
38
71
  });
39
- };
40
- //# sourceMappingURL=middleware.js.map
72
+ });
73
+
74
+ module.exports = generateMiddleware;
75
+ //# sourceMappingURL=middleware.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/plops/middleware.ts"],"names":[],"mappings":";;;;;AACA,gFAA+C;AAE/C,gGAAsE;AACtE,4EAAmD;AACnD,0EAAgD;AAEhD,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,MAAM;gBACZ,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,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;SACrF;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,2BAA2B,QAAQ,EAAE;oBACtD,YAAY,EAAE,aAAa,QAAQ,eAAe,QAAQ,MAAM;iBACjE;aACF,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
1
+ {"version":3,"file":"middleware.js","sources":["../../src/plops/middleware.ts"],"sourcesContent":["import type { ActionType, NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport { join } from 'path';\nimport fs from 'fs';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport validateInput from './utils/validate-input';\nimport getFilePath from './utils/get-file-path';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // middleware generator\n plop.setGenerator('middleware', {\n description: 'Generate a middleware for an API',\n prompts: [\n {\n type: 'input',\n name: 'name',\n message: 'Middleware name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('middleware', plop.getDestBasePath(), { rootFolder: true }),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/middlewares/{{ name }}.${language}`,\n templateFile: `templates/${language}/middleware.${language}.hbs`,\n },\n ];\n\n if (answers.plugin) {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/middlewares/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/middlewares/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new middleware to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/middlewares/index.${language}`,\n transform(template: string) {\n return appendToFile(template, { type: 'index', singularName: answers.name });\n },\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","getDestinationPrompts","getDestBasePath","rootFolder","actions","answers","filePath","getFilePath","destination","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","join","replace","baseActions","path","templateFile","indexPath","exists","fs","existsSync","push","skipIfExists","transform","template","appendToFile","singularName"],"mappings":";;;;;;;;;;AAUA,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,MAAA;gBACNC,OAAS,EAAA,iBAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,aAAcD,CAAAA,KAAAA;AACrC,aAAA;eACGE,qBAAsB,CAAA,YAAA,EAAcV,IAAKW,CAAAA,eAAe,EAAI,EAAA;gBAAEC,UAAY,EAAA;AAAK,aAAA;AACnF,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,IAAIC,QAAWC,GAAAA,OAAAA,CAAQC,qBAAqB,CAACL,cAAc,IAAO,GAAA,IAAA;YAElE,IAAIJ,OAAAA,CAAQU,MAAM,EAAE;;gBAElB,MAAMC,eAAAA,GAAkBC,SACtBR,CAAAA,UAAAA,EACA,KACAH,EAAAA,QAAAA,CAASY,OAAO,CAAC,cAAA,EAAgBb,OAAQU,CAAAA,MAAM,C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AM,EAAA,OAAA;AAASoC,4BAAAA,YAAAA,EAAc1B,QAAQT;AAAK,yBAAA,CAAA;AAC5E;AACF,iBAAA,CAAA;AACF;YAEA,OAAOuB,WAAAA;AACT;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
@@ -0,0 +1,73 @@
1
+ import tsUtils from '@strapi/typescript-utils';
2
+ import { join } from 'path';
3
+ import fs from 'fs';
4
+ import getDestinationPrompts from './prompts/get-destination-prompts.mjs';
5
+ import validateInput from './utils/validate-input.mjs';
6
+ import getFilePath from './utils/get-file-path.mjs';
7
+ import { appendToFile } from './utils/extend-plugin-index-files.mjs';
8
+
9
+ var generateMiddleware = ((plop)=>{
10
+ // middleware generator
11
+ plop.setGenerator('middleware', {
12
+ description: 'Generate a middleware for an API',
13
+ prompts: [
14
+ {
15
+ type: 'input',
16
+ name: 'name',
17
+ message: 'Middleware name',
18
+ validate: (input)=>validateInput(input)
19
+ },
20
+ ...getDestinationPrompts('middleware', plop.getDestBasePath(), {
21
+ rootFolder: true
22
+ })
23
+ ],
24
+ actions (answers) {
25
+ if (!answers) {
26
+ return [];
27
+ }
28
+ const filePath = getFilePath(answers.destination);
29
+ const currentDir = process.cwd();
30
+ let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
31
+ if (answers.plugin) {
32
+ // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
33
+ const pluginServerDir = join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
34
+ language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
35
+ }
36
+ const baseActions = [
37
+ {
38
+ type: 'add',
39
+ path: `${filePath}/middlewares/{{ name }}.${language}`,
40
+ templateFile: `templates/${language}/middleware.${language}.hbs`
41
+ }
42
+ ];
43
+ if (answers.plugin) {
44
+ const indexPath = join(plop.getDestBasePath(), `${filePath}/middlewares/index.${language}`);
45
+ const exists = fs.existsSync(indexPath);
46
+ if (!exists) {
47
+ // Create index file if it doesn't exist
48
+ baseActions.push({
49
+ type: 'add',
50
+ path: `${filePath}/middlewares/index.${language}`,
51
+ templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
52
+ skipIfExists: true
53
+ });
54
+ }
55
+ // Append the new middleware to the index.ts file
56
+ baseActions.push({
57
+ type: 'modify',
58
+ path: `${filePath}/middlewares/index.${language}`,
59
+ transform (template) {
60
+ return appendToFile(template, {
61
+ type: 'index',
62
+ singularName: answers.name
63
+ });
64
+ }
65
+ });
66
+ }
67
+ return baseActions;
68
+ }
69
+ });
70
+ });
71
+
72
+ export { generateMiddleware as default };
73
+ //# sourceMappingURL=middleware.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.mjs","sources":["../../src/plops/middleware.ts"],"sourcesContent":["import type { ActionType, NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport { join } from 'path';\nimport fs from 'fs';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport validateInput from './utils/validate-input';\nimport getFilePath from './utils/get-file-path';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // middleware generator\n plop.setGenerator('middleware', {\n description: 'Generate a middleware for an API',\n prompts: [\n {\n type: 'input',\n name: 'name',\n message: 'Middleware name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('middleware', plop.getDestBasePath(), { rootFolder: true }),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/middlewares/{{ name }}.${language}`,\n templateFile: `templates/${language}/middleware.${language}.hbs`,\n },\n ];\n\n if (answers.plugin) {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/middlewares/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/middlewares/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new middleware to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/middlewares/index.${language}`,\n transform(template: string) {\n return appendToFile(template, { type: 'index', singularName: answers.name });\n },\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","getDestinationPrompts","getDestBasePath","rootFolder","actions","answers","filePath","getFilePath","destination","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","join","replace","baseActions","path","templateFile","indexPath","exists","fs","existsSync","push","skipIfExists","transform","template","appendToFile","singularName"],"mappings":";;;;;;;;AAUA,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,MAAA;gBACNC,OAAS,EAAA,iBAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,aAAcD,CAAAA,KAAAA;AACrC,aAAA;eACGE,qBAAsB,CAAA,YAAA,EAAcV,IAAKW,CAAAA,eAAe,EAAI,EAAA;gBAAEC,UAAY,EAAA;AAAK,aAAA;AACnF,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,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,CAAS,IAAI,CAAC;wBACzEe,YAAc,EAAA;AAChB,qBAAA,CAAA;AACF;;AAGAR,gBAAAA,WAAAA,CAAYO,IAAI,CAAC;oBACf/B,IAAM,EAAA,QAAA;AACNyB,oBAAAA,IAAAA,EAAM,CAAGd,EAAAA,QAAAA,CAAS,mBAAmB,EAAEM,QAAU,CAAA,CAAA;AACjDgB,oBAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,wBAAA,OAAOC,aAAaD,QAAU,EAAA;4BAAElC,IAAM,EAAA,OAAA;AAASoC,4BAAAA,YAAAA,EAAc1B,QAAQT;AAAK,yBAAA,CAAA;AAC5E;AACF,iBAAA,CAAA;AACF;YAEA,OAAOuB,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=migration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../src/plops/migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;+BAKlB,WAAW;AAAjC,wBA0BE"}
@@ -1,12 +1,10 @@
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 validate_file_name_input_1 = __importDefault(require("./utils/validate-file-name-input"));
8
- const get_formatted_date_1 = __importDefault(require("./utils/get-formatted-date"));
9
- exports.default = (plop) => {
1
+ 'use strict';
2
+
3
+ var tsUtils = require('@strapi/typescript-utils');
4
+ var validateFileNameInput = require('./utils/validate-file-name-input.js');
5
+ var getFormattedDate = require('./utils/get-formatted-date.js');
6
+
7
+ var generateMigration = ((plop)=>{
10
8
  // Migration generator
11
9
  plop.setGenerator('migration', {
12
10
  description: 'Generate a migration',
@@ -15,21 +13,23 @@ exports.default = (plop) => {
15
13
  type: 'input',
16
14
  name: 'name',
17
15
  message: 'Migration name',
18
- validate: (input) => (0, validate_file_name_input_1.default)(input),
19
- },
16
+ validate: (input)=>validateFileNameInput(input)
17
+ }
20
18
  ],
21
- actions() {
19
+ actions () {
22
20
  const currentDir = process.cwd();
23
- const language = typescript_utils_1.default.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
24
- const timestamp = (0, get_formatted_date_1.default)();
21
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
22
+ const timestamp = getFormattedDate();
25
23
  return [
26
24
  {
27
25
  type: 'add',
28
26
  path: `${currentDir}/database/migrations/${timestamp}.{{ name }}.${language}`,
29
- templateFile: `templates/${language}/migration.${language}.hbs`,
30
- },
27
+ templateFile: `templates/${language}/migration.${language}.hbs`
28
+ }
31
29
  ];
32
- },
30
+ }
33
31
  });
34
- };
35
- //# sourceMappingURL=migration.js.map
32
+ });
33
+
34
+ module.exports = generateMigration;
35
+ //# sourceMappingURL=migration.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"migration.js","sourceRoot":"","sources":["../../src/plops/migration.ts"],"names":[],"mappings":";;;;;AACA,gFAA+C;AAC/C,gGAAqE;AACrE,oFAA0D;AAE1D,kBAAe,CAAC,IAAiB,EAAE,EAAE;IACnC,sBAAsB;IACtB,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE;QAC7B,WAAW,EAAE,sBAAsB;QACnC,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,gBAAgB;gBACzB,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,kCAAqB,EAAC,KAAK,CAAC;aAClD;SACF;QACD,OAAO;YACL,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;YACzE,MAAM,SAAS,GAAG,IAAA,4BAAgB,GAAE,CAAC;YAErC,OAAO;gBACL;oBACE,IAAI,EAAE,KAAK;oBACX,IAAI,EAAE,GAAG,UAAU,wBAAwB,SAAS,eAAe,QAAQ,EAAE;oBAC7E,YAAY,EAAE,aAAa,QAAQ,cAAc,QAAQ,MAAM;iBAChE;aACF,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
1
+ {"version":3,"file":"migration.js","sources":["../../src/plops/migration.ts"],"sourcesContent":["import type { NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport validateFileNameInput from './utils/validate-file-name-input';\nimport getFormattedDate from './utils/get-formatted-date';\n\nexport default (plop: NodePlopAPI) => {\n // Migration generator\n plop.setGenerator('migration', {\n description: 'Generate a migration',\n prompts: [\n {\n type: 'input',\n name: 'name',\n message: 'Migration name',\n validate: (input) => validateFileNameInput(input),\n },\n ],\n actions() {\n const currentDir = process.cwd();\n const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n const timestamp = getFormattedDate();\n\n return [\n {\n type: 'add',\n path: `${currentDir}/database/migrations/${timestamp}.{{ name }}.${language}`,\n templateFile: `templates/${language}/migration.${language}.hbs`,\n },\n ];\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateFileNameInput","actions","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","timestamp","getFormattedDate","path","templateFile"],"mappings":";;;;;;AAKA,wBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,WAAa,EAAA;QAC7BC,WAAa,EAAA,sBAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,MAAA;gBACNC,OAAS,EAAA,gBAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,qBAAsBD,CAAAA,KAAAA;AAC7C;AACD,SAAA;AACDE,QAAAA,OAAAA,CAAAA,GAAAA;YACE,MAAMC,UAAAA,GAAaC,QAAQC,GAAG,EAAA;AAC9B,YAAA,MAAMC,QAAWC,GAAAA,OAAAA,CAAQC,qBAAqB,CAACL,cAAc,IAAO,GAAA,IAAA;AACpE,YAAA,MAAMM,SAAYC,GAAAA,gBAAAA,EAAAA;YAElB,OAAO;AACL,gBAAA;oBACEd,IAAM,EAAA,KAAA;AACNe,oBAAAA,IAAAA,EAAM,GAAGR,UAAW,CAAA,qBAAqB,EAAEM,SAAU,CAAA,YAAY,EAAEH,QAAU,CAAA,CAAA;oBAC7EM,YAAc,EAAA,CAAC,UAAU,EAAEN,QAAAA,CAAS,WAAW,EAAEA,QAAAA,CAAS,IAAI;AAChE;AACD,aAAA;AACH;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
@@ -0,0 +1,33 @@
1
+ import tsUtils from '@strapi/typescript-utils';
2
+ import validateFileNameInput from './utils/validate-file-name-input.mjs';
3
+ import getFormattedDate from './utils/get-formatted-date.mjs';
4
+
5
+ var generateMigration = ((plop)=>{
6
+ // Migration generator
7
+ plop.setGenerator('migration', {
8
+ description: 'Generate a migration',
9
+ prompts: [
10
+ {
11
+ type: 'input',
12
+ name: 'name',
13
+ message: 'Migration name',
14
+ validate: (input)=>validateFileNameInput(input)
15
+ }
16
+ ],
17
+ actions () {
18
+ const currentDir = process.cwd();
19
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
20
+ const timestamp = getFormattedDate();
21
+ return [
22
+ {
23
+ type: 'add',
24
+ path: `${currentDir}/database/migrations/${timestamp}.{{ name }}.${language}`,
25
+ templateFile: `templates/${language}/migration.${language}.hbs`
26
+ }
27
+ ];
28
+ }
29
+ });
30
+ });
31
+
32
+ export { generateMigration as default };
33
+ //# sourceMappingURL=migration.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.mjs","sources":["../../src/plops/migration.ts"],"sourcesContent":["import type { NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport validateFileNameInput from './utils/validate-file-name-input';\nimport getFormattedDate from './utils/get-formatted-date';\n\nexport default (plop: NodePlopAPI) => {\n // Migration generator\n plop.setGenerator('migration', {\n description: 'Generate a migration',\n prompts: [\n {\n type: 'input',\n name: 'name',\n message: 'Migration name',\n validate: (input) => validateFileNameInput(input),\n },\n ],\n actions() {\n const currentDir = process.cwd();\n const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n const timestamp = getFormattedDate();\n\n return [\n {\n type: 'add',\n path: `${currentDir}/database/migrations/${timestamp}.{{ name }}.${language}`,\n templateFile: `templates/${language}/migration.${language}.hbs`,\n },\n ];\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateFileNameInput","actions","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","timestamp","getFormattedDate","path","templateFile"],"mappings":";;;;AAKA,wBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,WAAa,EAAA;QAC7BC,WAAa,EAAA,sBAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,MAAA;gBACNC,OAAS,EAAA,gBAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,qBAAsBD,CAAAA,KAAAA;AAC7C;AACD,SAAA;AACDE,QAAAA,OAAAA,CAAAA,GAAAA;YACE,MAAMC,UAAAA,GAAaC,QAAQC,GAAG,EAAA;AAC9B,YAAA,MAAMC,QAAWC,GAAAA,OAAAA,CAAQC,qBAAqB,CAACL,cAAc,IAAO,GAAA,IAAA;AACpE,YAAA,MAAMM,SAAYC,GAAAA,gBAAAA,EAAAA;YAElB,OAAO;AACL,gBAAA;oBACEd,IAAM,EAAA,KAAA;AACNe,oBAAAA,IAAAA,EAAM,GAAGR,UAAW,CAAA,qBAAqB,EAAEM,SAAU,CAAA,YAAY,EAAEH,QAAU,CAAA,CAAA;oBAC7EM,YAAc,EAAA,CAAC,UAAU,EAAEN,QAAAA,CAAS,WAAW,EAAEA,QAAAA,CAAS,IAAI;AAChE;AACD,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=policy.d.ts.map