@strapi/generators 0.0.0-next.f426350b859ddae6592e9bfa99e6be94ae22e117 → 0.0.0-next.f4ec69568d980c6fee91ce2ee0f41c138347aa81

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 (150) hide show
  1. package/LICENSE +18 -3
  2. package/dist/index.d.ts +3 -2
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +53 -27
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +34 -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 +585 -28
  11. package/dist/plopfile.js.map +1 -1
  12. package/dist/plopfile.mjs +582 -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/content-type.d.ts +2 -1
  17. package/dist/plops/content-type.d.ts.map +1 -0
  18. package/dist/plops/controller.d.ts +2 -1
  19. package/dist/plops/controller.d.ts.map +1 -0
  20. package/dist/plops/middleware.d.ts +2 -1
  21. package/dist/plops/middleware.d.ts.map +1 -0
  22. package/dist/plops/migration.d.ts +2 -1
  23. package/dist/plops/migration.d.ts.map +1 -0
  24. package/dist/plops/policy.d.ts +2 -1
  25. package/dist/plops/policy.d.ts.map +1 -0
  26. package/dist/plops/prompts/bootstrap-api-prompts.d.ts +1 -0
  27. package/dist/plops/prompts/bootstrap-api-prompts.d.ts.map +1 -0
  28. package/dist/plops/prompts/ct-names-prompts.d.ts +1 -0
  29. package/dist/plops/prompts/ct-names-prompts.d.ts.map +1 -0
  30. package/dist/plops/prompts/get-attributes-prompts.d.ts +1 -0
  31. package/dist/plops/prompts/get-attributes-prompts.d.ts.map +1 -0
  32. package/dist/plops/prompts/get-destination-prompts.d.ts +1 -0
  33. package/dist/plops/prompts/get-destination-prompts.d.ts.map +1 -0
  34. package/dist/plops/prompts/kind-prompts.d.ts +1 -0
  35. package/dist/plops/prompts/kind-prompts.d.ts.map +1 -0
  36. package/dist/plops/service.d.ts +2 -1
  37. package/dist/plops/service.d.ts.map +1 -0
  38. package/dist/plops/utils/get-file-path.d.ts +1 -0
  39. package/dist/plops/utils/get-file-path.d.ts.map +1 -0
  40. package/dist/plops/utils/get-formatted-date.d.ts +1 -0
  41. package/dist/plops/utils/get-formatted-date.d.ts.map +1 -0
  42. package/dist/plops/utils/validate-attribute-input.d.ts +1 -0
  43. package/dist/plops/utils/validate-attribute-input.d.ts.map +1 -0
  44. package/dist/plops/utils/validate-file-name-input.d.ts +1 -0
  45. package/dist/plops/utils/validate-file-name-input.d.ts.map +1 -0
  46. package/dist/plops/utils/validate-input.d.ts +1 -0
  47. package/dist/plops/utils/validate-input.d.ts.map +1 -0
  48. package/dist/templates/js/content-type.schema.json.hbs +0 -1
  49. package/dist/templates/ts/content-type.schema.json.hbs +0 -1
  50. package/dist/templates/ts/middleware.ts.hbs +2 -2
  51. package/package.json +18 -15
  52. package/dist/files/js/plugin/.editorconfig +0 -7
  53. package/dist/files/js/plugin/.gitattributes +0 -103
  54. package/dist/files/js/plugin/admin/src/components/Initializer/index.js +0 -26
  55. package/dist/files/js/plugin/admin/src/components/PluginIcon/index.js +0 -12
  56. package/dist/files/js/plugin/admin/src/index.js +0 -63
  57. package/dist/files/js/plugin/admin/src/pages/App/index.js +0 -25
  58. package/dist/files/js/plugin/admin/src/pages/HomePage/index.js +0 -20
  59. package/dist/files/js/plugin/admin/src/pluginId.js +0 -5
  60. package/dist/files/js/plugin/admin/src/translations/en.json +0 -1
  61. package/dist/files/js/plugin/admin/src/translations/fr.json +0 -1
  62. package/dist/files/js/plugin/admin/src/utils/getTrad.js +0 -5
  63. package/dist/files/js/plugin/server/bootstrap.js +0 -5
  64. package/dist/files/js/plugin/server/config/index.js +0 -6
  65. package/dist/files/js/plugin/server/content-types/index.js +0 -3
  66. package/dist/files/js/plugin/server/controllers/index.js +0 -7
  67. package/dist/files/js/plugin/server/controllers/my-controller.js.hbs +0 -10
  68. package/dist/files/js/plugin/server/destroy.js +0 -5
  69. package/dist/files/js/plugin/server/index.js +0 -25
  70. package/dist/files/js/plugin/server/middlewares/index.js +0 -3
  71. package/dist/files/js/plugin/server/policies/index.js +0 -3
  72. package/dist/files/js/plugin/server/register.js +0 -5
  73. package/dist/files/js/plugin/server/routes/index.js +0 -10
  74. package/dist/files/js/plugin/server/services/index.js +0 -7
  75. package/dist/files/js/plugin/server/services/my-service.js +0 -7
  76. package/dist/files/js/plugin/strapi-admin.js +0 -3
  77. package/dist/files/js/plugin/strapi-server.js +0 -3
  78. package/dist/files/ts/plugin/.editorconfig +0 -7
  79. package/dist/files/ts/plugin/.gitattributes +0 -103
  80. package/dist/files/ts/plugin/admin/src/components/Initializer/index.tsx +0 -24
  81. package/dist/files/ts/plugin/admin/src/components/PluginIcon/index.tsx +0 -12
  82. package/dist/files/ts/plugin/admin/src/index.tsx +0 -67
  83. package/dist/files/ts/plugin/admin/src/pages/App/index.tsx +0 -25
  84. package/dist/files/ts/plugin/admin/src/pages/HomePage/index.tsx +0 -19
  85. package/dist/files/ts/plugin/admin/src/pluginId.ts +0 -5
  86. package/dist/files/ts/plugin/admin/src/translations/en.json +0 -1
  87. package/dist/files/ts/plugin/admin/src/translations/fr.json +0 -1
  88. package/dist/files/ts/plugin/admin/src/utils/getTrad.ts +0 -5
  89. package/dist/files/ts/plugin/custom.d.ts +0 -5
  90. package/dist/files/ts/plugin/server/bootstrap.ts +0 -5
  91. package/dist/files/ts/plugin/server/config/index.ts +0 -4
  92. package/dist/files/ts/plugin/server/content-types/index.ts +0 -1
  93. package/dist/files/ts/plugin/server/controllers/index.ts +0 -5
  94. package/dist/files/ts/plugin/server/controllers/my-controller.ts.hbs +0 -10
  95. package/dist/files/ts/plugin/server/destroy.ts +0 -5
  96. package/dist/files/ts/plugin/server/index.ts +0 -23
  97. package/dist/files/ts/plugin/server/middlewares/index.ts +0 -1
  98. package/dist/files/ts/plugin/server/policies/index.ts +0 -1
  99. package/dist/files/ts/plugin/server/register.ts +0 -5
  100. package/dist/files/ts/plugin/server/routes/index.ts +0 -10
  101. package/dist/files/ts/plugin/server/services/index.ts +0 -5
  102. package/dist/files/ts/plugin/server/services/my-service.ts +0 -7
  103. package/dist/files/ts/plugin/strapi-admin.js +0 -3
  104. package/dist/files/ts/plugin/strapi-server.js +0 -3
  105. package/dist/files/ts/plugin/tsconfig.json +0 -20
  106. package/dist/files/ts/plugin/tsconfig.server.json +0 -25
  107. package/dist/plops/api.js +0 -79
  108. package/dist/plops/api.js.map +0 -1
  109. package/dist/plops/content-type.js +0 -158
  110. package/dist/plops/content-type.js.map +0 -1
  111. package/dist/plops/controller.js +0 -40
  112. package/dist/plops/controller.js.map +0 -1
  113. package/dist/plops/middleware.js +0 -40
  114. package/dist/plops/middleware.js.map +0 -1
  115. package/dist/plops/migration.js +0 -35
  116. package/dist/plops/migration.js.map +0 -1
  117. package/dist/plops/plugin.d.ts +0 -3
  118. package/dist/plops/plugin.js +0 -107
  119. package/dist/plops/plugin.js.map +0 -1
  120. package/dist/plops/policy.js +0 -40
  121. package/dist/plops/policy.js.map +0 -1
  122. package/dist/plops/prompts/bootstrap-api-prompts.js +0 -12
  123. package/dist/plops/prompts/bootstrap-api-prompts.js.map +0 -1
  124. package/dist/plops/prompts/ct-names-prompts.js +0 -68
  125. package/dist/plops/prompts/ct-names-prompts.js.map +0 -1
  126. package/dist/plops/prompts/draft-and-publish-prompts.d.ts +0 -3
  127. package/dist/plops/prompts/draft-and-publish-prompts.js +0 -12
  128. package/dist/plops/prompts/draft-and-publish-prompts.js.map +0 -1
  129. package/dist/plops/prompts/get-attributes-prompts.js +0 -95
  130. package/dist/plops/prompts/get-attributes-prompts.js.map +0 -1
  131. package/dist/plops/prompts/get-destination-prompts.js +0 -72
  132. package/dist/plops/prompts/get-destination-prompts.js.map +0 -1
  133. package/dist/plops/prompts/kind-prompts.js +0 -21
  134. package/dist/plops/prompts/kind-prompts.js.map +0 -1
  135. package/dist/plops/service.js +0 -38
  136. package/dist/plops/service.js.map +0 -1
  137. package/dist/plops/utils/get-file-path.js +0 -15
  138. package/dist/plops/utils/get-file-path.js.map +0 -1
  139. package/dist/plops/utils/get-formatted-date.js +0 -9
  140. package/dist/plops/utils/get-formatted-date.js.map +0 -1
  141. package/dist/plops/utils/validate-attribute-input.js +0 -10
  142. package/dist/plops/utils/validate-attribute-input.js.map +0 -1
  143. package/dist/plops/utils/validate-file-name-input.js +0 -10
  144. package/dist/plops/utils/validate-file-name-input.js.map +0 -1
  145. package/dist/plops/utils/validate-input.js +0 -10
  146. package/dist/plops/utils/validate-input.js.map +0 -1
  147. package/dist/templates/js/README.md.hbs +0 -3
  148. package/dist/templates/js/plugin-package.json.hbs +0 -42
  149. package/dist/templates/ts/README.md.hbs +0 -3
  150. package/dist/templates/ts/plugin-package.json.hbs +0 -51
@@ -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/plops/utils/validate-input.ts","../src/plops/api.ts","../src/plops/prompts/get-destination-prompts.ts","../src/plops/utils/get-file-path.ts","../src/plops/controller.ts","../src/plops/prompts/ct-names-prompts.ts","../src/plops/prompts/kind-prompts.ts","../src/plops/utils/validate-attribute-input.ts","../src/plops/prompts/get-attributes-prompts.ts","../src/plops/prompts/bootstrap-api-prompts.ts","../src/plops/content-type.ts","../src/plops/policy.ts","../src/plops/middleware.ts","../src/plops/utils/validate-file-name-input.ts","../src/plops/utils/get-formatted-date.ts","../src/plops/migration.ts","../src/plops/service.ts","../src/plopfile.ts"],"sourcesContent":["export default (input: string) => {\n const regex = /^[A-Za-z-]+$/g;\n\n if (!input) {\n return 'You must provide an input';\n }\n\n return regex.test(input) || \"Please use only letters, '-' and no spaces\";\n};\n","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\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 }}' : '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","import { join } from 'path';\nimport fs from 'fs-extra';\n\nimport type { PromptQuestion } from 'node-plop';\n\nexport default (\n action: string,\n basePath: string,\n { rootFolder = false } = {}\n): Array<PromptQuestion> => {\n return [\n {\n type: 'list',\n name: 'destination',\n message: `Where do you want to add this ${action}?`,\n choices: [\n ...(rootFolder\n ? [\n {\n name: `Add ${action} to root of project`,\n value: 'root',\n },\n ]\n : [\n {\n name: `Add ${action} to new API`,\n value: 'new',\n },\n ]),\n { name: `Add ${action} to an existing API`, value: 'api' },\n { name: `Add ${action} to an existing plugin`, value: 'plugin' },\n ],\n },\n {\n when: (answers) => answers.destination === 'api',\n type: 'list',\n message: 'Which API is this for?',\n name: 'api',\n async choices() {\n const apiPath = join(basePath, 'api');\n const exists = await fs.pathExists(apiPath);\n\n if (!exists) {\n throw Error('Couldn\\'t find an \"api\" directory');\n }\n\n const apiDir = await fs.readdir(apiPath, { withFileTypes: true });\n const apiDirContent = apiDir.filter((fd) => fd.isDirectory());\n\n if (apiDirContent.length === 0) {\n throw Error('The \"api\" directory is empty');\n }\n\n return apiDirContent;\n },\n },\n {\n when: (answers) => answers.destination === 'plugin',\n type: 'list',\n message: 'Which plugin is this for?',\n name: 'plugin',\n async choices() {\n const pluginsPath = join(basePath, 'plugins');\n const exists = await fs.pathExists(pluginsPath);\n\n if (!exists) {\n throw Error('Couldn\\'t find a \"plugins\" directory');\n }\n\n const pluginsDir = await fs.readdir(pluginsPath);\n const pluginsDirContent = pluginsDir.filter((api) =>\n fs.lstatSync(join(pluginsPath, api)).isDirectory()\n );\n\n if (pluginsDirContent.length === 0) {\n throw Error('The \"plugins\" directory is empty');\n }\n\n return pluginsDirContent;\n },\n },\n ];\n};\n","export default (destination: string) => {\n if (destination === 'api') {\n return `api/{{ api }}`;\n }\n\n if (destination === 'plugin') {\n return `plugins/{{ plugin }}/server`;\n }\n\n if (destination === 'root') {\n return './';\n }\n\n return `api/{{ id }}`;\n};\n","import type { NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport validateInput from './utils/validate-input';\n\nexport default (plop: NodePlopAPI) => {\n // Controller generator\n plop.setGenerator('controller', {\n description: 'Generate a controller for an API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'Controller name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('controller', plop.getDestBasePath()),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n return [\n {\n type: 'add',\n path: `${filePath}/controllers/{{ id }}.${language}`,\n templateFile: `templates/${language}/controller.${language}.hbs`,\n },\n ];\n },\n });\n};\n","import pluralize from 'pluralize';\nimport slugify from '@sindresorhus/slugify';\nimport { strings } from '@strapi/utils';\n\nimport type { PromptQuestion } from 'node-plop';\n\ninterface Answers {\n displayName: string;\n singularName: string;\n pluralName: string;\n}\n\nconst questions: Array<PromptQuestion> = [\n {\n type: 'input',\n name: 'displayName',\n message: 'Content type display name',\n validate: (input: string) => !!input,\n },\n {\n type: 'input',\n name: 'singularName',\n message: 'Content type singular name',\n default: (answers: Answers) => slugify(answers.displayName),\n validate(input) {\n if (!strings.isKebabCase(input)) {\n return 'Value must be in kebab-case';\n }\n\n return true;\n },\n },\n {\n type: 'input',\n name: 'pluralName',\n message: 'Content type plural name',\n default: (answers: Answers) => pluralize(answers.singularName),\n validate(input: string, answers: Answers) {\n if (answers.singularName === input) {\n return 'Singular and plural names cannot be the same';\n }\n\n if (!strings.isKebabCase(input)) {\n return 'Value must be in kebab-case';\n }\n\n return true;\n },\n },\n];\n\nexport default questions;\n","import type { PromptQuestion } from 'node-plop';\n\nimport validateInput from '../utils/validate-input';\n\nconst questions: Array<PromptQuestion> = [\n {\n type: 'list',\n name: 'kind',\n message: 'Please choose the model type',\n default: 'collectionType',\n choices: [\n { name: 'Collection Type', value: 'collectionType' },\n { name: 'Single Type', value: 'singleType' },\n ],\n validate: (input: string) => validateInput(input),\n },\n];\n\nexport default questions;\n","export default (input: string) => {\n const regex = /^[A-Za-z-|_]+$/g;\n\n if (!input) {\n return 'You must provide an input';\n }\n\n return regex.test(input) || \"Please use only letters, '-', '_', and no spaces\";\n};\n","import type { DynamicPromptsFunction } from 'node-plop';\n\nimport validateAttributeInput from '../utils/validate-attribute-input';\n\ninterface AttributeAnswer {\n attributeName: string;\n attributeType: typeof DEFAULT_TYPES;\n enum?: string;\n multiple?: boolean;\n}\n\nconst DEFAULT_TYPES = [\n // advanced types\n 'media',\n\n // scalar types\n 'string',\n 'text',\n 'richtext',\n 'json',\n 'enumeration',\n 'password',\n 'email',\n 'integer',\n 'biginteger',\n 'float',\n 'decimal',\n 'date',\n 'time',\n 'datetime',\n 'timestamp',\n 'boolean',\n] as const;\n\nconst getAttributesPrompts: DynamicPromptsFunction = async (inquirer) => {\n const { addAttributes } = await inquirer.prompt([\n {\n type: 'confirm',\n name: 'addAttributes',\n message: 'Do you want to add attributes?',\n },\n ]);\n\n const attributes: Array<AttributeAnswer> = [];\n\n /**\n * @param {import('inquirer').Inquirer} inquirer\n * @returns {Promise<void>}\n */\n const createNewAttributes = async (inquirer: Parameters<DynamicPromptsFunction>[0]) => {\n const answers = await inquirer.prompt([\n {\n type: 'input',\n name: 'attributeName',\n message: 'Name of attribute',\n validate: (input: string) => validateAttributeInput(input),\n },\n {\n type: 'list',\n name: 'attributeType',\n message: 'What type of attribute',\n pageSize: DEFAULT_TYPES.length,\n choices: DEFAULT_TYPES.map((type) => {\n return { name: type, value: type };\n }),\n },\n {\n when: (answers) => answers.attributeType === 'enumeration',\n type: 'input',\n name: 'enum',\n message: 'Add values separated by a comma',\n },\n {\n when: (answers) => answers.attributeType === 'media',\n type: 'list',\n name: 'multiple',\n message: 'Choose media type',\n choices: [\n { name: 'Multiple', value: true },\n { name: 'Single', value: false },\n ],\n },\n {\n type: 'confirm',\n name: 'addAttributes',\n message: 'Do you want to add another attribute?',\n },\n ]);\n\n attributes.push(answers);\n\n if (!answers.addAttributes) {\n return;\n }\n\n await createNewAttributes(inquirer);\n };\n\n if (addAttributes) {\n await createNewAttributes(inquirer);\n } else {\n console.warn(\n `You won't be able to manage entries from the admin, you can still add attributes later from the content type builder.`\n );\n }\n\n return attributes;\n};\n\nexport default getAttributesPrompts;\n","import type { PromptQuestion } from 'node-plop';\n\nconst questions: Array<PromptQuestion> = [\n {\n type: 'confirm',\n name: 'bootstrapApi',\n default: true,\n message: 'Bootstrap API related files?',\n },\n];\n\nexport default questions;\n","import { join } from 'path';\nimport type { NodePlopAPI, ActionType } from 'plop';\nimport slugify from '@sindresorhus/slugify';\nimport fs from 'fs-extra';\nimport { strings } from '@strapi/utils';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport ctNamesPrompts from './prompts/ct-names-prompts';\nimport kindPrompts from './prompts/kind-prompts';\nimport getAttributesPrompts from './prompts/get-attributes-prompts';\nimport bootstrapApiPrompts from './prompts/bootstrap-api-prompts';\n\nexport default (plop: NodePlopAPI) => {\n // Model generator\n plop.setGenerator('content-type', {\n description: 'Generate a content type for an API',\n async prompts(inquirer) {\n const config = await inquirer.prompt([...ctNamesPrompts, ...kindPrompts]);\n // @ts-expect-error issue with deprecated inquirer.prompts attribute to fix with ugprade to inquirer\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 // TODO: use basePath instead\n const currentDir = process.cwd();\n const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n templateFile: `templates/${language}/content-type.schema.json.hbs`,\n data: {\n collectionName: slugify(answers.pluralName, { separator: '_' }),\n },\n },\n ];\n\n if (Object.entries(attributes).length > 0) {\n baseActions.push({\n type: 'modify',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n transform(template: string) {\n const parsedTemplate = JSON.parse(template);\n parsedTemplate.attributes = attributes;\n return JSON.stringify(parsedTemplate, null, 2);\n },\n });\n }\n\n if (answers.bootstrapApi) {\n const { singularName } = answers;\n\n let uid;\n if (answers.destination === 'new') {\n uid = `api::${answers.id}.${singularName}`;\n } else if (answers.api) {\n uid = `api::${answers.api}.${singularName}`;\n } else if (answers.plugin) {\n uid = `plugin::${answers.plugin}.${singularName}`;\n }\n\n baseActions.push(\n {\n type: 'add',\n path: `${filePath}/controllers/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-controller.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/services/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-service.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/routes/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-router.${language}.hbs`,\n data: { uid },\n }\n );\n }\n\n return baseActions;\n },\n });\n};\n","import type { NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport validateInput from './utils/validate-input';\nimport getFilePath from './utils/get-file-path';\n\nexport default (plop: NodePlopAPI) => {\n // Policy generator\n plop.setGenerator('policy', {\n description: 'Generate a policy for an API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'Policy name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('policy', 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 const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n return [\n {\n type: 'add',\n path: `${filePath}/policies/{{ id }}.${language}`,\n templateFile: `templates/${language}/policy.${language}.hbs`,\n },\n ];\n },\n });\n};\n","import type { NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport validateInput from './utils/validate-input';\nimport getFilePath from './utils/get-file-path';\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 const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n return [\n {\n type: 'add',\n path: `${filePath}/middlewares/{{ name }}.${language}`,\n templateFile: `templates/${language}/middleware.${language}.hbs`,\n },\n ];\n },\n });\n};\n","export default (input: string) => {\n const regex = /^[A-Za-z-_0-9]+$/g;\n\n if (!input) {\n return 'You must provide an input';\n }\n\n return regex.test(input) || \"Please use only letters and number, '-' or '_' and no spaces\";\n};\n","export default (date: Date = new Date()) => {\n return new Date(date.getTime() - date.getTimezoneOffset() * 60000)\n .toJSON()\n .replace(/[-:]/g, '.')\n .replace(/\\....Z/, '');\n};\n","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","import type { NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\n\nexport default (plop: NodePlopAPI) => {\n // Service generator\n plop.setGenerator('service', {\n description: 'Generate a service for an API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'Service name',\n },\n ...getDestinationPrompts('service', plop.getDestBasePath()),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers?.destination);\n const currentDir = process.cwd();\n const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n return [\n {\n type: 'add',\n path: `${filePath}/services/{{ id }}.${language}`,\n templateFile: `templates/${language}/service.${language}.hbs`,\n },\n ];\n },\n });\n};\n","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.addHelper('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":["join","fs","tsUtils","questions","slugify","strings","pluralize","inquirer","answers","ctNamesPrompts","kindPrompts","bootstrapApiPrompts"],"mappings":";;;;;;;;;;;;AAAA,MAAe,gBAAA,CAAC,UAAkB;AAChC,QAAM,QAAQ;AAEd,MAAI,CAAC,OAAO;AACH,WAAA;AAAA,EACT;AA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AAS;AAAA,MACX;AAAA,MACA,GAAG,sBAAsB,WAAW,KAAK,iBAAiB;AAAA,IAC5D;AAAA,IACA,QAAQ,SAAS;AACf,UAAI,CAAC,SAAS;AACZ,eAAO;MACT;AAEM,YAAA,WAAW,YAAY,SAAS,WAAW;AAC3C,YAAA,aAAa,QAAQ;AAC3B,YAAM,WAAWA,iBAAAA,QAAQ,sBAAsB,UAAU,IAAI,OAAO;AAE7D,aAAA;AAAA,QACL;AAAA,UACE,MAAM;AAAA,UACN,MAAM,GAAG,QAAQ,sBAAsB,QAAQ;AAAA,UAC/C,cAAc,aAAa,QAAQ,YAAY,QAAQ;AAAA,QACzD;AAAA,MAAA;AAAA,IAEJ;AAAA,EAAA,CACD;AACH;ACzBA,MAAe,WAAA,CAAC,SAAsB;AAEpC,OAAK,kBAAkB,mBAAmB;AAC1C,OAAK,UAAU,aAAa,CAAC,SAAiBI,mBAAA,QAAU,IAAI,CAAC;AAG7D,cAAY,IAAI;AAChB,qBAAmB,IAAI;AACvB,sBAAoB,IAAI;AACxB,iBAAe,IAAI;AACnB,qBAAmB,IAAI;AACvB,oBAAkB,IAAI;AACtB,kBAAgB,IAAI;AACtB;;"}
@@ -0,0 +1,582 @@
1
+ import pluralize from "pluralize";
2
+ import { join } from "path";
3
+ import fs from "fs-extra";
4
+ import tsUtils from "@strapi/typescript-utils";
5
+ import slugify from "@sindresorhus/slugify";
6
+ import { strings } from "@strapi/utils";
7
+ const validateInput = (input) => {
8
+ const regex = /^[A-Za-z-]+$/g;
9
+ if (!input) {
10
+ return "You must provide an input";
11
+ }
12
+ return regex.test(input) || "Please use only letters, '-' and no spaces";
13
+ };
14
+ const generateApi = (plop) => {
15
+ plop.setGenerator("api", {
16
+ description: "Generate a basic API",
17
+ prompts: [
18
+ {
19
+ type: "input",
20
+ name: "id",
21
+ message: "API name",
22
+ validate: (input) => validateInput(input)
23
+ },
24
+ {
25
+ type: "confirm",
26
+ name: "isPluginApi",
27
+ message: "Is this API for a plugin?"
28
+ },
29
+ {
30
+ when: (answers) => answers.isPluginApi,
31
+ type: "list",
32
+ name: "plugin",
33
+ message: "Plugin name",
34
+ async choices() {
35
+ const pluginsPath = join(plop.getDestBasePath(), "plugins");
36
+ const exists = await fs.pathExists(pluginsPath);
37
+ if (!exists) {
38
+ throw Error(`Couldn't find a "plugins" directory`);
39
+ }
40
+ const pluginsDir = await fs.readdir(pluginsPath, { withFileTypes: true });
41
+ const pluginsDirContent = pluginsDir.filter((fd) => fd.isDirectory());
42
+ if (pluginsDirContent.length === 0) {
43
+ throw Error('The "plugins" directory is empty');
44
+ }
45
+ return pluginsDirContent;
46
+ }
47
+ }
48
+ ],
49
+ actions(answers) {
50
+ if (!answers) {
51
+ return [];
52
+ }
53
+ const filePath = answers.isPluginApi && answers.plugin ? "plugins/{{ plugin }}" : "api/{{ id }}";
54
+ const currentDir = process.cwd();
55
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? "ts" : "js";
56
+ const baseActions = [
57
+ {
58
+ type: "add",
59
+ path: `${filePath}/controllers/{{ id }}.${language}`,
60
+ templateFile: `templates/${language}/controller.${language}.hbs`
61
+ },
62
+ {
63
+ type: "add",
64
+ path: `${filePath}/services/{{ id }}.${language}`,
65
+ templateFile: `templates/${language}/service.${language}.hbs`
66
+ }
67
+ ];
68
+ if (answers.isPluginApi) {
69
+ return baseActions;
70
+ }
71
+ return [
72
+ {
73
+ type: "add",
74
+ path: `${filePath}/routes/{{ id }}.${language}`,
75
+ templateFile: `templates/${language}/single-route.${language}.hbs`
76
+ },
77
+ ...baseActions
78
+ ];
79
+ }
80
+ });
81
+ };
82
+ const getDestinationPrompts = (action, basePath, { rootFolder = false } = {}) => {
83
+ return [
84
+ {
85
+ type: "list",
86
+ name: "destination",
87
+ message: `Where do you want to add this ${action}?`,
88
+ choices: [
89
+ ...rootFolder ? [
90
+ {
91
+ name: `Add ${action} to root of project`,
92
+ value: "root"
93
+ }
94
+ ] : [
95
+ {
96
+ name: `Add ${action} to new API`,
97
+ value: "new"
98
+ }
99
+ ],
100
+ { name: `Add ${action} to an existing API`, value: "api" },
101
+ { name: `Add ${action} to an existing plugin`, value: "plugin" }
102
+ ]
103
+ },
104
+ {
105
+ when: (answers) => answers.destination === "api",
106
+ type: "list",
107
+ message: "Which API is this for?",
108
+ name: "api",
109
+ async choices() {
110
+ const apiPath = join(basePath, "api");
111
+ const exists = await fs.pathExists(apiPath);
112
+ if (!exists) {
113
+ throw Error(`Couldn't find an "api" directory`);
114
+ }
115
+ const apiDir = await fs.readdir(apiPath, { withFileTypes: true });
116
+ const apiDirContent = apiDir.filter((fd) => fd.isDirectory());
117
+ if (apiDirContent.length === 0) {
118
+ throw Error('The "api" directory is empty');
119
+ }
120
+ return apiDirContent;
121
+ }
122
+ },
123
+ {
124
+ when: (answers) => answers.destination === "plugin",
125
+ type: "list",
126
+ message: "Which plugin is this for?",
127
+ name: "plugin",
128
+ async choices() {
129
+ const pluginsPath = join(basePath, "plugins");
130
+ const exists = await fs.pathExists(pluginsPath);
131
+ if (!exists) {
132
+ throw Error(`Couldn't find a "plugins" directory`);
133
+ }
134
+ const pluginsDir = await fs.readdir(pluginsPath);
135
+ const pluginsDirContent = pluginsDir.filter(
136
+ (api) => fs.lstatSync(join(pluginsPath, api)).isDirectory()
137
+ );
138
+ if (pluginsDirContent.length === 0) {
139
+ throw Error('The "plugins" directory is empty');
140
+ }
141
+ return pluginsDirContent;
142
+ }
143
+ }
144
+ ];
145
+ };
146
+ const getFilePath = (destination) => {
147
+ if (destination === "api") {
148
+ return `api/{{ api }}`;
149
+ }
150
+ if (destination === "plugin") {
151
+ return `plugins/{{ plugin }}/server`;
152
+ }
153
+ if (destination === "root") {
154
+ return "./";
155
+ }
156
+ return `api/{{ id }}`;
157
+ };
158
+ const generateController = (plop) => {
159
+ plop.setGenerator("controller", {
160
+ description: "Generate a controller for an API",
161
+ prompts: [
162
+ {
163
+ type: "input",
164
+ name: "id",
165
+ message: "Controller name",
166
+ validate: (input) => validateInput(input)
167
+ },
168
+ ...getDestinationPrompts("controller", plop.getDestBasePath())
169
+ ],
170
+ actions(answers) {
171
+ if (!answers) {
172
+ return [];
173
+ }
174
+ const filePath = getFilePath(answers.destination);
175
+ const currentDir = process.cwd();
176
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? "ts" : "js";
177
+ return [
178
+ {
179
+ type: "add",
180
+ path: `${filePath}/controllers/{{ id }}.${language}`,
181
+ templateFile: `templates/${language}/controller.${language}.hbs`
182
+ }
183
+ ];
184
+ }
185
+ });
186
+ };
187
+ const questions$2 = [
188
+ {
189
+ type: "input",
190
+ name: "displayName",
191
+ message: "Content type display name",
192
+ validate: (input) => !!input
193
+ },
194
+ {
195
+ type: "input",
196
+ name: "singularName",
197
+ message: "Content type singular name",
198
+ default: (answers) => slugify(answers.displayName),
199
+ validate(input) {
200
+ if (!strings.isKebabCase(input)) {
201
+ return "Value must be in kebab-case";
202
+ }
203
+ return true;
204
+ }
205
+ },
206
+ {
207
+ type: "input",
208
+ name: "pluralName",
209
+ message: "Content type plural name",
210
+ default: (answers) => pluralize(answers.singularName),
211
+ validate(input, answers) {
212
+ if (answers.singularName === input) {
213
+ return "Singular and plural names cannot be the same";
214
+ }
215
+ if (!strings.isKebabCase(input)) {
216
+ return "Value must be in kebab-case";
217
+ }
218
+ return true;
219
+ }
220
+ }
221
+ ];
222
+ const questions$1 = [
223
+ {
224
+ type: "list",
225
+ name: "kind",
226
+ message: "Please choose the model type",
227
+ default: "collectionType",
228
+ choices: [
229
+ { name: "Collection Type", value: "collectionType" },
230
+ { name: "Single Type", value: "singleType" }
231
+ ],
232
+ validate: (input) => validateInput(input)
233
+ }
234
+ ];
235
+ const validateAttributeInput = (input) => {
236
+ const regex = /^[A-Za-z-|_]+$/g;
237
+ if (!input) {
238
+ return "You must provide an input";
239
+ }
240
+ return regex.test(input) || "Please use only letters, '-', '_', and no spaces";
241
+ };
242
+ const DEFAULT_TYPES = [
243
+ // advanced types
244
+ "media",
245
+ // scalar types
246
+ "string",
247
+ "text",
248
+ "richtext",
249
+ "json",
250
+ "enumeration",
251
+ "password",
252
+ "email",
253
+ "integer",
254
+ "biginteger",
255
+ "float",
256
+ "decimal",
257
+ "date",
258
+ "time",
259
+ "datetime",
260
+ "timestamp",
261
+ "boolean"
262
+ ];
263
+ const getAttributesPrompts = async (inquirer) => {
264
+ const { addAttributes } = await inquirer.prompt([
265
+ {
266
+ type: "confirm",
267
+ name: "addAttributes",
268
+ message: "Do you want to add attributes?"
269
+ }
270
+ ]);
271
+ const attributes = [];
272
+ const createNewAttributes = async (inquirer2) => {
273
+ const answers = await inquirer2.prompt([
274
+ {
275
+ type: "input",
276
+ name: "attributeName",
277
+ message: "Name of attribute",
278
+ validate: (input) => validateAttributeInput(input)
279
+ },
280
+ {
281
+ type: "list",
282
+ name: "attributeType",
283
+ message: "What type of attribute",
284
+ pageSize: DEFAULT_TYPES.length,
285
+ choices: DEFAULT_TYPES.map((type) => {
286
+ return { name: type, value: type };
287
+ })
288
+ },
289
+ {
290
+ when: (answers2) => answers2.attributeType === "enumeration",
291
+ type: "input",
292
+ name: "enum",
293
+ message: "Add values separated by a comma"
294
+ },
295
+ {
296
+ when: (answers2) => answers2.attributeType === "media",
297
+ type: "list",
298
+ name: "multiple",
299
+ message: "Choose media type",
300
+ choices: [
301
+ { name: "Multiple", value: true },
302
+ { name: "Single", value: false }
303
+ ]
304
+ },
305
+ {
306
+ type: "confirm",
307
+ name: "addAttributes",
308
+ message: "Do you want to add another attribute?"
309
+ }
310
+ ]);
311
+ attributes.push(answers);
312
+ if (!answers.addAttributes) {
313
+ return;
314
+ }
315
+ await createNewAttributes(inquirer2);
316
+ };
317
+ if (addAttributes) {
318
+ await createNewAttributes(inquirer);
319
+ } else {
320
+ console.warn(
321
+ `You won't be able to manage entries from the admin, you can still add attributes later from the content type builder.`
322
+ );
323
+ }
324
+ return attributes;
325
+ };
326
+ const questions = [
327
+ {
328
+ type: "confirm",
329
+ name: "bootstrapApi",
330
+ default: true,
331
+ message: "Bootstrap API related files?"
332
+ }
333
+ ];
334
+ const generateContentType = (plop) => {
335
+ plop.setGenerator("content-type", {
336
+ description: "Generate a content type for an API",
337
+ async prompts(inquirer) {
338
+ const config = await inquirer.prompt([...questions$2, ...questions$1]);
339
+ const attributes = await getAttributesPrompts(inquirer);
340
+ const api = await inquirer.prompt([
341
+ ...getDestinationPrompts("model", plop.getDestBasePath()),
342
+ {
343
+ when: (answers) => answers.destination === "new",
344
+ type: "input",
345
+ name: "id",
346
+ default: config.singularName,
347
+ message: "Name of the new API?",
348
+ async validate(input) {
349
+ if (!strings.isKebabCase(input)) {
350
+ return "Value must be in kebab-case";
351
+ }
352
+ const apiPath = join(plop.getDestBasePath(), "api");
353
+ const exists = await fs.pathExists(apiPath);
354
+ if (!exists) {
355
+ return true;
356
+ }
357
+ const apiDir = await fs.readdir(apiPath, { withFileTypes: true });
358
+ const apiDirContent = apiDir.filter((fd) => fd.isDirectory());
359
+ if (apiDirContent.findIndex((dir) => dir.name === input) !== -1) {
360
+ throw new Error("This name is already taken.");
361
+ }
362
+ return true;
363
+ }
364
+ },
365
+ ...questions
366
+ ]);
367
+ return {
368
+ ...config,
369
+ ...api,
370
+ attributes
371
+ };
372
+ },
373
+ actions(answers) {
374
+ if (!answers) {
375
+ return [];
376
+ }
377
+ const attributes = answers.attributes.reduce((object, answer) => {
378
+ const val = { type: answer.attributeType };
379
+ if (answer.attributeType === "enumeration") {
380
+ val.enum = answer.enum.split(",").map((item) => item.trim());
381
+ }
382
+ if (answer.attributeType === "media") {
383
+ val.allowedTypes = ["images", "files", "videos", "audios"];
384
+ val.multiple = answer.multiple;
385
+ }
386
+ return Object.assign(object, { [answer.attributeName]: val }, {});
387
+ }, {});
388
+ const filePath = getFilePath(answers.destination);
389
+ const currentDir = process.cwd();
390
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? "ts" : "js";
391
+ const baseActions = [
392
+ {
393
+ type: "add",
394
+ path: `${filePath}/content-types/{{ singularName }}/schema.json`,
395
+ templateFile: `templates/${language}/content-type.schema.json.hbs`,
396
+ data: {
397
+ collectionName: slugify(answers.pluralName, { separator: "_" })
398
+ }
399
+ }
400
+ ];
401
+ if (Object.entries(attributes).length > 0) {
402
+ baseActions.push({
403
+ type: "modify",
404
+ path: `${filePath}/content-types/{{ singularName }}/schema.json`,
405
+ transform(template) {
406
+ const parsedTemplate = JSON.parse(template);
407
+ parsedTemplate.attributes = attributes;
408
+ return JSON.stringify(parsedTemplate, null, 2);
409
+ }
410
+ });
411
+ }
412
+ if (answers.bootstrapApi) {
413
+ const { singularName } = answers;
414
+ let uid;
415
+ if (answers.destination === "new") {
416
+ uid = `api::${answers.id}.${singularName}`;
417
+ } else if (answers.api) {
418
+ uid = `api::${answers.api}.${singularName}`;
419
+ } else if (answers.plugin) {
420
+ uid = `plugin::${answers.plugin}.${singularName}`;
421
+ }
422
+ baseActions.push(
423
+ {
424
+ type: "add",
425
+ path: `${filePath}/controllers/{{ singularName }}.${language}`,
426
+ templateFile: `templates/${language}/core-controller.${language}.hbs`,
427
+ data: { uid }
428
+ },
429
+ {
430
+ type: "add",
431
+ path: `${filePath}/services/{{ singularName }}.${language}`,
432
+ templateFile: `templates/${language}/core-service.${language}.hbs`,
433
+ data: { uid }
434
+ },
435
+ {
436
+ type: "add",
437
+ path: `${filePath}/routes/{{ singularName }}.${language}`,
438
+ templateFile: `templates/${language}/core-router.${language}.hbs`,
439
+ data: { uid }
440
+ }
441
+ );
442
+ }
443
+ return baseActions;
444
+ }
445
+ });
446
+ };
447
+ const generatePolicy = (plop) => {
448
+ plop.setGenerator("policy", {
449
+ description: "Generate a policy for an API",
450
+ prompts: [
451
+ {
452
+ type: "input",
453
+ name: "id",
454
+ message: "Policy name",
455
+ validate: (input) => validateInput(input)
456
+ },
457
+ ...getDestinationPrompts("policy", plop.getDestBasePath(), { rootFolder: true })
458
+ ],
459
+ actions(answers) {
460
+ if (!answers) {
461
+ return [];
462
+ }
463
+ const filePath = getFilePath(answers.destination);
464
+ const currentDir = process.cwd();
465
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? "ts" : "js";
466
+ return [
467
+ {
468
+ type: "add",
469
+ path: `${filePath}/policies/{{ id }}.${language}`,
470
+ templateFile: `templates/${language}/policy.${language}.hbs`
471
+ }
472
+ ];
473
+ }
474
+ });
475
+ };
476
+ const generateMiddleware = (plop) => {
477
+ plop.setGenerator("middleware", {
478
+ description: "Generate a middleware for an API",
479
+ prompts: [
480
+ {
481
+ type: "input",
482
+ name: "name",
483
+ message: "Middleware name",
484
+ validate: (input) => validateInput(input)
485
+ },
486
+ ...getDestinationPrompts("middleware", plop.getDestBasePath(), { rootFolder: true })
487
+ ],
488
+ actions(answers) {
489
+ if (!answers) {
490
+ return [];
491
+ }
492
+ const filePath = getFilePath(answers.destination);
493
+ const currentDir = process.cwd();
494
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? "ts" : "js";
495
+ return [
496
+ {
497
+ type: "add",
498
+ path: `${filePath}/middlewares/{{ name }}.${language}`,
499
+ templateFile: `templates/${language}/middleware.${language}.hbs`
500
+ }
501
+ ];
502
+ }
503
+ });
504
+ };
505
+ const validateFileNameInput = (input) => {
506
+ const regex = /^[A-Za-z-_0-9]+$/g;
507
+ if (!input) {
508
+ return "You must provide an input";
509
+ }
510
+ return regex.test(input) || "Please use only letters and number, '-' or '_' and no spaces";
511
+ };
512
+ const getFormattedDate = (date = /* @__PURE__ */ new Date()) => {
513
+ return new Date(date.getTime() - date.getTimezoneOffset() * 6e4).toJSON().replace(/[-:]/g, ".").replace(/\....Z/, "");
514
+ };
515
+ const generateMigration = (plop) => {
516
+ plop.setGenerator("migration", {
517
+ description: "Generate a migration",
518
+ prompts: [
519
+ {
520
+ type: "input",
521
+ name: "name",
522
+ message: "Migration name",
523
+ validate: (input) => validateFileNameInput(input)
524
+ }
525
+ ],
526
+ actions() {
527
+ const currentDir = process.cwd();
528
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? "ts" : "js";
529
+ const timestamp = getFormattedDate();
530
+ return [
531
+ {
532
+ type: "add",
533
+ path: `${currentDir}/database/migrations/${timestamp}.{{ name }}.${language}`,
534
+ templateFile: `templates/${language}/migration.${language}.hbs`
535
+ }
536
+ ];
537
+ }
538
+ });
539
+ };
540
+ const generateService = (plop) => {
541
+ plop.setGenerator("service", {
542
+ description: "Generate a service for an API",
543
+ prompts: [
544
+ {
545
+ type: "input",
546
+ name: "id",
547
+ message: "Service name"
548
+ },
549
+ ...getDestinationPrompts("service", plop.getDestBasePath())
550
+ ],
551
+ actions(answers) {
552
+ if (!answers) {
553
+ return [];
554
+ }
555
+ const filePath = getFilePath(answers?.destination);
556
+ const currentDir = process.cwd();
557
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? "ts" : "js";
558
+ return [
559
+ {
560
+ type: "add",
561
+ path: `${filePath}/services/{{ id }}.${language}`,
562
+ templateFile: `templates/${language}/service.${language}.hbs`
563
+ }
564
+ ];
565
+ }
566
+ });
567
+ };
568
+ const plopfile = (plop) => {
569
+ plop.setWelcomeMessage("Strapi Generators");
570
+ plop.addHelper("pluralize", (text) => pluralize(text));
571
+ generateApi(plop);
572
+ generateController(plop);
573
+ generateContentType(plop);
574
+ generatePolicy(plop);
575
+ generateMiddleware(plop);
576
+ generateMigration(plop);
577
+ generateService(plop);
578
+ };
579
+ export {
580
+ plopfile as default
581
+ };
582
+ //# sourceMappingURL=plopfile.mjs.map