@strapi/generators 5.30.0 → 5.31.0

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 (56) hide show
  1. package/dist/index.d.ts.map +1 -1
  2. package/dist/index.js +1 -2
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +1 -2
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/plops/api.d.ts.map +1 -1
  7. package/dist/plops/api.js +79 -11
  8. package/dist/plops/api.js.map +1 -1
  9. package/dist/plops/api.mjs +79 -11
  10. package/dist/plops/api.mjs.map +1 -1
  11. package/dist/plops/content-type.d.ts.map +1 -1
  12. package/dist/plops/content-type.js +98 -2
  13. package/dist/plops/content-type.js.map +1 -1
  14. package/dist/plops/content-type.mjs +98 -2
  15. package/dist/plops/content-type.mjs.map +1 -1
  16. package/dist/plops/controller.d.ts.map +1 -1
  17. package/dist/plops/controller.js +35 -2
  18. package/dist/plops/controller.js.map +1 -1
  19. package/dist/plops/controller.mjs +35 -2
  20. package/dist/plops/controller.mjs.map +1 -1
  21. package/dist/plops/middleware.d.ts.map +1 -1
  22. package/dist/plops/middleware.js +35 -2
  23. package/dist/plops/middleware.js.map +1 -1
  24. package/dist/plops/middleware.mjs +35 -2
  25. package/dist/plops/middleware.mjs.map +1 -1
  26. package/dist/plops/migration.js.map +1 -1
  27. package/dist/plops/migration.mjs.map +1 -1
  28. package/dist/plops/policy.d.ts.map +1 -1
  29. package/dist/plops/policy.js +35 -2
  30. package/dist/plops/policy.js.map +1 -1
  31. package/dist/plops/policy.mjs +35 -2
  32. package/dist/plops/policy.mjs.map +1 -1
  33. package/dist/plops/prompts/get-destination-prompts.d.ts +1 -1
  34. package/dist/plops/service.d.ts.map +1 -1
  35. package/dist/plops/service.js +35 -2
  36. package/dist/plops/service.js.map +1 -1
  37. package/dist/plops/service.mjs +35 -2
  38. package/dist/plops/service.mjs.map +1 -1
  39. package/dist/plops/utils/extend-plugin-index-files.d.ts +8 -0
  40. package/dist/plops/utils/extend-plugin-index-files.d.ts.map +1 -0
  41. package/dist/plops/utils/extend-plugin-index-files.js +356 -0
  42. package/dist/plops/utils/extend-plugin-index-files.js.map +1 -0
  43. package/dist/plops/utils/extend-plugin-index-files.mjs +335 -0
  44. package/dist/plops/utils/extend-plugin-index-files.mjs.map +1 -0
  45. package/dist/plops/utils/get-file-path.d.ts +1 -1
  46. package/dist/plops/utils/get-file-path.js +2 -2
  47. package/dist/plops/utils/get-file-path.js.map +1 -1
  48. package/dist/plops/utils/get-file-path.mjs +2 -2
  49. package/dist/plops/utils/get-file-path.mjs.map +1 -1
  50. package/dist/templates/js/plugin/plugin.index.js.hbs +3 -0
  51. package/dist/templates/js/plugin/plugin.routes.index.js.hbs +12 -0
  52. package/dist/templates/js/plugin/plugin.routes.type.index.js.hbs +6 -0
  53. package/dist/templates/ts/plugin/plugin.index.ts.hbs +1 -0
  54. package/dist/templates/ts/plugin/plugin.routes.index.ts.hbs +9 -0
  55. package/dist/templates/ts/plugin/plugin.routes.type.index.ts.hbs +4 -0
  56. package/package.json +10 -6
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,MAAM,qBAkBlB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAUF,eAAO,MAAM,QAAQ,iDACJ,MAAM,WACZ,CAAC,sBACyC,eAAe;;EAkDnE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,MAAM,qBAiBlB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAUF,eAAO,MAAM,QAAQ,iDACJ,MAAM,WACZ,CAAC,sBACyC,eAAe;;EAkDnE,CAAC"}
package/dist/index.js CHANGED
@@ -10,8 +10,7 @@ const runCLI = async ()=>{
10
10
  Plop.prepare({
11
11
  configPath: node_path.join(__dirname, 'plopfile.js')
12
12
  }, (env)=>{
13
- const argv = process.argv.slice(2); // Extract command-line arguments
14
- Plop.execute(env, argv, (env, argv)=>{
13
+ Plop.execute(env, [], (env, argv)=>{
15
14
  const options = {
16
15
  ...env,
17
16
  dest: node_path.join(process.cwd(), 'src')
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { join, dirname } from 'node:path';\nimport handlebars from 'handlebars';\nimport fs from 'fs-extra';\n\n// Starts the Plop CLI programmatically\nexport const runCLI = async () => {\n const { Plop, run } = await import('plop');\n\n Plop.prepare(\n {\n configPath: join(__dirname, 'plopfile.js'),\n },\n (env) => {\n const argv = process.argv.slice(2); // Extract command-line arguments\n Plop.execute(env, argv, (env, argv) => {\n const options = {\n ...env,\n dest: join(process.cwd(), 'src'), // this will make the destination path to be based on the cwd when calling the wrapper\n };\n return run(options, argv, true); // Pass the third argument 'true' for passArgsBeforeDashes\n });\n }\n );\n};\n\ntype GenerateOptions = {\n dir?: string;\n plopFile?: string;\n};\n\ntype GeneratorAction = {\n type: 'add' | 'modify';\n path: string;\n templateFile?: string;\n data?: Record<string, any>;\n transform?: (content: string) => string;\n};\n\nexport const generate = async <T extends Record<string, any>>(\n generatorName: string,\n options: T,\n { dir = process.cwd(), plopFile = 'plopfile.js' }: GenerateOptions = {}\n) => {\n // Resolve the absolute path to the plopfile (generator definitions)\n const plopfilePath = join(__dirname, plopFile);\n // Dynamically require the plopfile module.\n // Note: This allows loading either CommonJS or transpiled ESM plopfiles.\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const plopModule = require(plopfilePath);\n\n // Internal objects to store registered generators and helpers.\n // These will be populated by the plopfile when it is executed.\n const generators: Record<string, any> = {};\n const helpers: Record<string, any> = {};\n\n // Minimal mock Plop API implementation, exposing only the methods needed by our plopfile.\n // This allows the plopfile to register generators and helpers as it would in a real Plop environment.\n const plopApi = {\n setGenerator(name: string, config: any) {\n generators[name] = config;\n },\n setHelper(name: string, fn: any) {\n helpers[name] = fn;\n },\n getDestBasePath() {\n return join(dir, 'src');\n },\n setWelcomeMessage() {}, // no-op\n };\n\n // Execute the plopfile, passing in our API.\n // This will populate the `generators` and `helpers` objects.\n // Support both CommonJS and ESM default exports.\n if (typeof plopModule.default === 'function') {\n plopModule.default(plopApi);\n } else {\n plopModule(plopApi);\n }\n\n const generator = generators[generatorName];\n if (!generator) {\n throw new Error(`Generator \"${generatorName}\" not found`);\n }\n\n registerHandlebarsHelpers(helpers);\n const actions: GeneratorAction[] =\n typeof generator.actions === 'function' ? generator.actions(options) : generator.actions || [];\n\n await executeActions(actions, options, dir);\n\n return { success: true };\n};\n\nconst registerHandlebarsHelpers = (helpers: Record<string, any>) => {\n Object.entries(helpers).forEach(([name, fn]) => handlebars.registerHelper(name, fn));\n};\n\n// Executes generator actions: add or modify files as specified\nconst executeActions = async (\n actions: GeneratorAction[],\n options: Record<string, any>,\n dir: string\n) => {\n for (const action of actions) {\n const outputPath = handlebars.compile(action.path)(options);\n const fullPath = join(dir, 'src', outputPath);\n\n if (action.type === 'add' && action.templateFile) {\n const templatePath = join(__dirname, action.templateFile);\n const templateContent = await fs.readFile(templatePath, 'utf8');\n const compiled = handlebars.compile(templateContent);\n const output = compiled({ ...options, ...action.data });\n\n await fs.ensureDir(dirname(fullPath));\n await fs.writeFile(fullPath, output);\n }\n\n if (action.type === 'modify') {\n if (await fs.pathExists(fullPath)) {\n const content = await fs.readFile(fullPath, 'utf8');\n const modified = action.transform ? action.transform(content) : content;\n await fs.writeFile(fullPath, modified);\n }\n }\n }\n};\n"],"names":["runCLI","Plop","run","prepare","configPath","join","__dirname","env","argv","process","slice","execute","options","dest","cwd","generate","generatorName","dir","plopFile","plopfilePath","plopModule","require","generators","helpers","plopApi","setGenerator","name","config","setHelper","fn","getDestBasePath","setWelcomeMessage","default","generator","Error","registerHandlebarsHelpers","actions","executeActions","success","Object","entries","forEach","handlebars","registerHelper","action","outputPath","compile","path","fullPath","type","templateFile","templatePath","templateContent","fs","readFile","compiled","output","data","ensureDir","dirname","writeFile","pathExists","content","modified","transform"],"mappings":";;;;;;AAIA;MACaA,MAAS,GAAA,UAAA;IACpB,MAAM,EAAEC,IAAI,EAAEC,GAAG,EAAE,GAAG,MAAM,OAAO,MAAA,CAAA;AAEnCD,IAAAA,IAAAA,CAAKE,OAAO,CACV;AACEC,QAAAA,UAAAA,EAAYC,eAAKC,SAAW,EAAA,aAAA;AAC9B,KAAA,EACA,CAACC,GAAAA,GAAAA;AACC,QAAA,MAAMC,OAAOC,OAAQD,CAAAA,IAAI,CAACE,KAAK,CAAC;AAChCT,QAAAA,IAAAA,CAAKU,OAAO,CAACJ,GAAKC,EAAAA,IAAAA,EAAM,CAACD,GAAKC,EAAAA,IAAAA,GAAAA;AAC5B,YAAA,MAAMI,OAAU,GAAA;AACd,gBAAA,GAAGL,GAAG;gBACNM,IAAMR,EAAAA,cAAAA,CAAKI,OAAQK,CAAAA,GAAG,EAAI,EAAA,KAAA;AAC5B,aAAA;AACA,YAAA,OAAOZ,GAAIU,CAAAA,OAAAA,EAASJ,IAAM,EAAA,IAAA,CAAA,CAAA;AAC5B,SAAA,CAAA;AACF,KAAA,CAAA;AAEJ;MAeaO,QAAW,GAAA,OACtBC,aACAJ,EAAAA,OAAAA,EACA,EAAEK,GAAMR,GAAAA,OAAAA,CAAQK,GAAG,EAAE,EAAEI,QAAW,GAAA,aAAa,EAAmB,GAAG,EAAE,GAAA;;IAGvE,MAAMC,YAAAA,GAAed,eAAKC,SAAWY,EAAAA,QAAAA,CAAAA;;;;AAIrC,IAAA,MAAME,aAAaC,OAAQF,CAAAA,YAAAA,CAAAA;;;AAI3B,IAAA,MAAMG,aAAkC,EAAC;AACzC,IAAA,MAAMC,UAA+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WnB,MAAOoB,CAAAA,SAAS,GAAGpB,MAAOoB,CAAAA,SAAS,CAACF,OAAWA,CAAAA,GAAAA,OAAAA;gBAChE,MAAMT,EAAAA,CAAGO,SAAS,CAACZ,QAAUe,EAAAA,QAAAA,CAAAA;AAC/B;AACF;AACF;AACF,CAAA;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { join, dirname } from 'node:path';\nimport handlebars from 'handlebars';\nimport fs from 'fs-extra';\n\n// Starts the Plop CLI programmatically\nexport const runCLI = async () => {\n const { Plop, run } = await import('plop');\n\n Plop.prepare(\n {\n configPath: join(__dirname, 'plopfile.js'),\n },\n (env) => {\n Plop.execute(env, [], (env, argv) => {\n const options = {\n ...env,\n dest: join(process.cwd(), 'src'), // this will make the destination path to be based on the cwd when calling the wrapper\n };\n return run(options, argv, true); // Pass the third argument 'true' for passArgsBeforeDashes\n });\n }\n );\n};\n\ntype GenerateOptions = {\n dir?: string;\n plopFile?: string;\n};\n\ntype GeneratorAction = {\n type: 'add' | 'modify';\n path: string;\n templateFile?: string;\n data?: Record<string, any>;\n transform?: (content: string) => string;\n};\n\nexport const generate = async <T extends Record<string, any>>(\n generatorName: string,\n options: T,\n { dir = process.cwd(), plopFile = 'plopfile.js' }: GenerateOptions = {}\n) => {\n // Resolve the absolute path to the plopfile (generator definitions)\n const plopfilePath = join(__dirname, plopFile);\n // Dynamically require the plopfile module.\n // Note: This allows loading either CommonJS or transpiled ESM plopfiles.\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const plopModule = require(plopfilePath);\n\n // Internal objects to store registered generators and helpers.\n // These will be populated by the plopfile when it is executed.\n const generators: Record<string, any> = {};\n const helpers: Record<string, any> = {};\n\n // Minimal mock Plop API implementation, exposing only the methods needed by our plopfile.\n // This allows the plopfile to register generators and helpers as it would in a real Plop environment.\n const plopApi = {\n setGenerator(name: string, config: any) {\n generators[name] = config;\n },\n setHelper(name: string, fn: any) {\n helpers[name] = fn;\n },\n getDestBasePath() {\n return join(dir, 'src');\n },\n setWelcomeMessage() {}, // no-op\n };\n\n // Execute the plopfile, passing in our API.\n // This will populate the `generators` and `helpers` objects.\n // Support both CommonJS and ESM default exports.\n if (typeof plopModule.default === 'function') {\n plopModule.default(plopApi);\n } else {\n plopModule(plopApi);\n }\n\n const generator = generators[generatorName];\n if (!generator) {\n throw new Error(`Generator \"${generatorName}\" not found`);\n }\n\n registerHandlebarsHelpers(helpers);\n const actions: GeneratorAction[] =\n typeof generator.actions === 'function' ? generator.actions(options) : generator.actions || [];\n\n await executeActions(actions, options, dir);\n\n return { success: true };\n};\n\nconst registerHandlebarsHelpers = (helpers: Record<string, any>) => {\n Object.entries(helpers).forEach(([name, fn]) => handlebars.registerHelper(name, fn));\n};\n\n// Executes generator actions: add or modify files as specified\nconst executeActions = async (\n actions: GeneratorAction[],\n options: Record<string, any>,\n dir: string\n) => {\n for (const action of actions) {\n const outputPath = handlebars.compile(action.path)(options);\n const fullPath = join(dir, 'src', outputPath);\n\n if (action.type === 'add' && action.templateFile) {\n const templatePath = join(__dirname, action.templateFile);\n const templateContent = await fs.readFile(templatePath, 'utf8');\n const compiled = handlebars.compile(templateContent);\n const output = compiled({ ...options, ...action.data });\n\n await fs.ensureDir(dirname(fullPath));\n await fs.writeFile(fullPath, output);\n }\n\n if (action.type === 'modify') {\n if (await fs.pathExists(fullPath)) {\n const content = await fs.readFile(fullPath, 'utf8');\n const modified = action.transform ? action.transform(content) : content;\n await fs.writeFile(fullPath, modified);\n }\n }\n }\n};\n"],"names":["runCLI","Plop","run","prepare","configPath","join","__dirname","env","execute","argv","options","dest","process","cwd","generate","generatorName","dir","plopFile","plopfilePath","plopModule","require","generators","helpers","plopApi","setGenerator","name","config","setHelper","fn","getDestBasePath","setWelcomeMessage","default","generator","Error","registerHandlebarsHelpers","actions","executeActions","success","Object","entries","forEach","handlebars","registerHelper","action","outputPath","compile","path","fullPath","type","templateFile","templatePath","templateContent","fs","readFile","compiled","output","data","ensureDir","dir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
8
  Plop.prepare({
9
9
  configPath: join(__dirname, 'plopfile.js')
10
10
  }, (env)=>{
11
- const argv = process.argv.slice(2); // Extract command-line arguments
12
- Plop.execute(env, argv, (env, argv)=>{
11
+ Plop.execute(env, [], (env, argv)=>{
13
12
  const options = {
14
13
  ...env,
15
14
  dest: join(process.cwd(), 'src')
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { join, dirname } from 'node:path';\nimport handlebars from 'handlebars';\nimport fs from 'fs-extra';\n\n// Starts the Plop CLI programmatically\nexport const runCLI = async () => {\n const { Plop, run } = await import('plop');\n\n Plop.prepare(\n {\n configPath: join(__dirname, 'plopfile.js'),\n },\n (env) => {\n const argv = process.argv.slice(2); // Extract command-line arguments\n Plop.execute(env, argv, (env, argv) => {\n const options = {\n ...env,\n dest: join(process.cwd(), 'src'), // this will make the destination path to be based on the cwd when calling the wrapper\n };\n return run(options, argv, true); // Pass the third argument 'true' for passArgsBeforeDashes\n });\n }\n );\n};\n\ntype GenerateOptions = {\n dir?: string;\n plopFile?: string;\n};\n\ntype GeneratorAction = {\n type: 'add' | 'modify';\n path: string;\n templateFile?: string;\n data?: Record<string, any>;\n transform?: (content: string) => string;\n};\n\nexport const generate = async <T extends Record<string, any>>(\n generatorName: string,\n options: T,\n { dir = process.cwd(), plopFile = 'plopfile.js' }: GenerateOptions = {}\n) => {\n // Resolve the absolute path to the plopfile (generator definitions)\n const plopfilePath = join(__dirname, plopFile);\n // Dynamically require the plopfile module.\n // Note: This allows loading either CommonJS or transpiled ESM plopfiles.\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const plopModule = require(plopfilePath);\n\n // Internal objects to store registered generators and helpers.\n // These will be populated by the plopfile when it is executed.\n const generators: Record<string, any> = {};\n const helpers: Record<string, any> = {};\n\n // Minimal mock Plop API implementation, exposing only the methods needed by our plopfile.\n // This allows the plopfile to register generators and helpers as it would in a real Plop environment.\n const plopApi = {\n setGenerator(name: string, config: any) {\n generators[name] = config;\n },\n setHelper(name: string, fn: any) {\n helpers[name] = fn;\n },\n getDestBasePath() {\n return join(dir, 'src');\n },\n setWelcomeMessage() {}, // no-op\n };\n\n // Execute the plopfile, passing in our API.\n // This will populate the `generators` and `helpers` objects.\n // Support both CommonJS and ESM default exports.\n if (typeof plopModule.default === 'function') {\n plopModule.default(plopApi);\n } else {\n plopModule(plopApi);\n }\n\n const generator = generators[generatorName];\n if (!generator) {\n throw new Error(`Generator \"${generatorName}\" not found`);\n }\n\n registerHandlebarsHelpers(helpers);\n const actions: GeneratorAction[] =\n typeof generator.actions === 'function' ? generator.actions(options) : generator.actions || [];\n\n await executeActions(actions, options, dir);\n\n return { success: true };\n};\n\nconst registerHandlebarsHelpers = (helpers: Record<string, any>) => {\n Object.entries(helpers).forEach(([name, fn]) => handlebars.registerHelper(name, fn));\n};\n\n// Executes generator actions: add or modify files as specified\nconst executeActions = async (\n actions: GeneratorAction[],\n options: Record<string, any>,\n dir: string\n) => {\n for (const action of actions) {\n const outputPath = handlebars.compile(action.path)(options);\n const fullPath = join(dir, 'src', outputPath);\n\n if (action.type === 'add' && action.templateFile) {\n const templatePath = join(__dirname, action.templateFile);\n const templateContent = await fs.readFile(templatePath, 'utf8');\n const compiled = handlebars.compile(templateContent);\n const output = compiled({ ...options, ...action.data });\n\n await fs.ensureDir(dirname(fullPath));\n await fs.writeFile(fullPath, output);\n }\n\n if (action.type === 'modify') {\n if (await fs.pathExists(fullPath)) {\n const content = await fs.readFile(fullPath, 'utf8');\n const modified = action.transform ? action.transform(content) : content;\n await fs.writeFile(fullPath, modified);\n }\n }\n }\n};\n"],"names":["runCLI","Plop","run","prepare","configPath","join","__dirname","env","argv","process","slice","execute","options","dest","cwd","generate","generatorName","dir","plopFile","plopfilePath","plopModule","require","generators","helpers","plopApi","setGenerator","name","config","setHelper","fn","getDestBasePath","setWelcomeMessage","default","generator","Error","registerHandlebarsHelpers","actions","executeActions","success","Object","entries","forEach","handlebars","registerHelper","action","outputPath","compile","path","fullPath","type","templateFile","templatePath","templateContent","fs","readFile","compiled","output","data","ensureDir","dirname","writeFile","pathExists","content","modified","transform"],"mappings":";;;;AAIA;MACaA,MAAS,GAAA,UAAA;IACpB,MAAM,EAAEC,IAAI,EAAEC,GAAG,EAAE,GAAG,MAAM,OAAO,MAAA,CAAA;AAEnCD,IAAAA,IAAAA,CAAKE,OAAO,CACV;AACEC,QAAAA,UAAAA,EAAYC,KAAKC,SAAW,EAAA,aAAA;AAC9B,KAAA,EACA,CAACC,GAAAA,GAAAA;AACC,QAAA,MAAMC,OAAOC,OAAQD,CAAAA,IAAI,CAACE,KAAK,CAAC;AAChCT,QAAAA,IAAAA,CAAKU,OAAO,CAACJ,GAAKC,EAAAA,IAAAA,EAAM,CAACD,GAAKC,EAAAA,IAAAA,GAAAA;AAC5B,YAAA,MAAMI,OAAU,GAAA;AACd,gBAAA,GAAGL,GAAG;gBACNM,IAAMR,EAAAA,IAAAA,CAAKI,OAAQK,CAAAA,GAAG,EAAI,EAAA,KAAA;AAC5B,aAAA;AACA,YAAA,OAAOZ,GAAIU,CAAAA,OAAAA,EAASJ,IAAM,EAAA,IAAA,CAAA,CAAA;AAC5B,SAAA,CAAA;AACF,KAAA,CAAA;AAEJ;MAeaO,QAAW,GAAA,OACtBC,aACAJ,EAAAA,OAAAA,EACA,EAAEK,GAAMR,GAAAA,OAAAA,CAAQK,GAAG,EAAE,EAAEI,QAAW,GAAA,aAAa,EAAmB,GAAG,EAAE,GAAA;;IAGvE,MAAMC,YAAAA,GAAed,KAAKC,SAAWY,EAAAA,QAAAA,CAAAA;;;;AAIrC,IAAA,MAAME,aAAaC,OAAQF,CAAAA,YAAAA,CAAAA;;;AAI3B,IAAA,MAAMG,aAAkC,EAAC;AACzC,IAAA,MAAMC,UAA+B,EAAC;;;AAItC,IAAA,MAAMC,OAAU,GAAA;QACdC,YAAaC,CAAAA,CAAAA,IAAY,EAAEC,MAAW,EAAA;YACpCL,UAAU,CAACI,KAAK,GAAGC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AACZ,QAAUe,EAAAA,QAAAA,CAAAA;AAC/B;AACF;AACF;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { join, dirname } from 'node:path';\nimport handlebars from 'handlebars';\nimport fs from 'fs-extra';\n\n// Starts the Plop CLI programmatically\nexport const runCLI = async () => {\n const { Plop, run } = await import('plop');\n\n Plop.prepare(\n {\n configPath: join(__dirname, 'plopfile.js'),\n },\n (env) => {\n Plop.execute(env, [], (env, argv) => {\n const options = {\n ...env,\n dest: join(process.cwd(), 'src'), // this will make the destination path to be based on the cwd when calling the wrapper\n };\n return run(options, argv, true); // Pass the third argument 'true' for passArgsBeforeDashes\n });\n }\n );\n};\n\ntype GenerateOptions = {\n dir?: string;\n plopFile?: string;\n};\n\ntype GeneratorAction = {\n type: 'add' | 'modify';\n path: string;\n templateFile?: string;\n data?: Record<string, any>;\n transform?: (content: string) => string;\n};\n\nexport const generate = async <T extends Record<string, any>>(\n generatorName: string,\n options: T,\n { dir = process.cwd(), plopFile = 'plopfile.js' }: GenerateOptions = {}\n) => {\n // Resolve the absolute path to the plopfile (generator definitions)\n const plopfilePath = join(__dirname, plopFile);\n // Dynamically require the plopfile module.\n // Note: This allows loading either CommonJS or transpiled ESM plopfiles.\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const plopModule = require(plopfilePath);\n\n // Internal objects to store registered generators and helpers.\n // These will be populated by the plopfile when it is executed.\n const generators: Record<string, any> = {};\n const helpers: Record<string, any> = {};\n\n // Minimal mock Plop API implementation, exposing only the methods needed by our plopfile.\n // This allows the plopfile to register generators and helpers as it would in a real Plop environment.\n const plopApi = {\n setGenerator(name: string, config: any) {\n generators[name] = config;\n },\n setHelper(name: string, fn: any) {\n helpers[name] = fn;\n },\n getDestBasePath() {\n return join(dir, 'src');\n },\n setWelcomeMessage() {}, // no-op\n };\n\n // Execute the plopfile, passing in our API.\n // This will populate the `generators` and `helpers` objects.\n // Support both CommonJS and ESM default exports.\n if (typeof plopModule.default === 'function') {\n plopModule.default(plopApi);\n } else {\n plopModule(plopApi);\n }\n\n const generator = generators[generatorName];\n if (!generator) {\n throw new Error(`Generator \"${generatorName}\" not found`);\n }\n\n registerHandlebarsHelpers(helpers);\n const actions: GeneratorAction[] =\n typeof generator.actions === 'function' ? generator.actions(options) : generator.actions || [];\n\n await executeActions(actions, options, dir);\n\n return { success: true };\n};\n\nconst registerHandlebarsHelpers = (helpers: Record<string, any>) => {\n Object.entries(helpers).forEach(([name, fn]) => handlebars.registerHelper(name, fn));\n};\n\n// Executes generator actions: add or modify files as specified\nconst executeActions = async (\n actions: GeneratorAction[],\n options: Record<string, any>,\n dir: string\n) => {\n for (const action of actions) {\n const outputPath = handlebars.compile(action.path)(options);\n const fullPath = join(dir, 'src', outputPath);\n\n if (action.type === 'add' && action.templateFile) {\n const templatePath = join(__dirname, action.templateFile);\n const templateContent = await fs.readFile(templatePath, 'utf8');\n const compiled = handlebars.compile(templateContent);\n const output = compiled({ ...options, ...action.data });\n\n await fs.ensureDir(dirname(fullPath));\n await fs.writeFile(fullPath, output);\n }\n\n if (action.type === 'modify') {\n if (await fs.pathExists(fullPath)) {\n const content = await fs.readFile(fullPath, 'utf8');\n const modified = action.transform ? action.transform(content) : content;\n await fs.writeFile(fullPath, modified);\n }\n }\n }\n};\n"],"names":["runCLI","Plop","run","prepare","configPath","join","__dirname","env","execute","argv","options","dest","process","cwd","generate","generatorName","dir","plopFile","plopfilePath","plopModule","require","generators","helpers","plopApi","setGenerator","name","config","setHelper","fn","getDestBasePath","setWelcomeMessage","default","generator","Error","registerHandlebarsHelpers","actions","executeActions","success","Object","entries","forEach","handlebars","registerHelper","action","outputPath","compile","path","fullPath","type","templateFile","templatePath","templateContent","fs","readFile","compiled","output","data","ensureDir","dirname","writeFile","pathExists","content","modified","transform"],"mappings":";;;;AAIA;MACaA,MAAS,GAAA,UAAA;IACpB,MAAM,EAAEC,IAAI,EAAEC,GAAG,EAAE,GAAG,MAAM,OAA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.d.ts","sourceRoot":"","sources":["../../src/plops/api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,MAAM,CAAC;+BAQ9B,WAAW;AAAjC,wBAkJE"}
package/dist/plops/api.js CHANGED
@@ -4,6 +4,8 @@ var path = require('path');
4
4
  var fs = require('fs-extra');
5
5
  var tsUtils = require('@strapi/typescript-utils');
6
6
  var validateInput = require('./utils/validate-input.js');
7
+ var getFilePath = require('./utils/get-file-path.js');
8
+ var extendPluginIndexFiles = require('./utils/extend-plugin-index-files.js');
7
9
 
8
10
  var generateApi = ((plop)=>{
9
11
  // API generator
@@ -47,9 +49,14 @@ var generateApi = ((plop)=>{
47
49
  if (!answers) {
48
50
  return [];
49
51
  }
50
- const filePath = answers.isPluginApi && answers.plugin ? 'plugins/{{ plugin }}/server' : 'api/{{ id }}';
52
+ const filePath = getFilePath(answers.destination || (answers.isPluginApi && answers.plugin ? 'plugin' : 'api'));
51
53
  const currentDir = process.cwd();
52
- const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
54
+ let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
55
+ if (answers.plugin) {
56
+ // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
57
+ const pluginServerDir = path.join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
58
+ language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
59
+ }
53
60
  const baseActions = [
54
61
  {
55
62
  type: 'add',
@@ -60,19 +67,80 @@ var generateApi = ((plop)=>{
60
67
  type: 'add',
61
68
  path: `${filePath}/services/{{ id }}.${language}`,
62
69
  templateFile: `templates/${language}/service.${language}.hbs`
63
- }
64
- ];
65
- if (answers.isPluginApi) {
66
- return baseActions;
67
- }
68
- return [
70
+ },
69
71
  {
70
72
  type: 'add',
71
- path: `${filePath}/routes/{{ id }}.${language}`,
73
+ path: `${filePath}/routes/${answers.plugin ? 'content-api/' : ''}{{ id }}.${language}`,
72
74
  templateFile: `templates/${language}/single-route.${language}.hbs`
73
- },
74
- ...baseActions
75
+ }
75
76
  ];
77
+ if (answers.isPluginApi) {
78
+ const indexFiles = [
79
+ 'controllers',
80
+ 'services',
81
+ 'routes'
82
+ ];
83
+ indexFiles.forEach((type)=>{
84
+ const indexPath = path.join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);
85
+ const exists = fs.existsSync(indexPath);
86
+ if (!exists && type !== 'routes') {
87
+ baseActions.push({
88
+ type: 'add',
89
+ path: `${filePath}/${type}/index.${language}`,
90
+ templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
91
+ skipIfExists: true
92
+ });
93
+ }
94
+ if (type === 'routes') {
95
+ const indexPath = path.join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);
96
+ const exists = fs.existsSync(indexPath);
97
+ if (!exists) {
98
+ baseActions.push({
99
+ type: 'add',
100
+ path: `${filePath}/${type}/index.${language}`,
101
+ templateFile: `templates/${language}/plugin/plugin.routes.index.${language}.hbs`,
102
+ skipIfExists: true
103
+ });
104
+ }
105
+ const routeIndexFiles = [
106
+ 'content-api',
107
+ 'admin'
108
+ ];
109
+ routeIndexFiles.forEach((routeType)=>{
110
+ const routeTypeIndexPath = path.join(plop.getDestBasePath(), `${filePath}/${type}/${routeType}/index.${language}`);
111
+ const routeTypeExists = fs.existsSync(routeTypeIndexPath);
112
+ if (!routeTypeExists) {
113
+ baseActions.push({
114
+ type: 'add',
115
+ path: `${filePath}/${type}/${routeType}/index.${language}`,
116
+ templateFile: `templates/${language}/plugin/plugin.routes.type.index.${language}.hbs`,
117
+ data: {
118
+ type: routeType
119
+ },
120
+ skipIfExists: true
121
+ });
122
+ }
123
+ });
124
+ }
125
+ baseActions.push({
126
+ type: 'modify',
127
+ path: `${filePath}/${type}/${type === 'routes' ? 'content-api/' : ''}index.${language}`,
128
+ transform (template) {
129
+ if (type === 'routes') {
130
+ return extendPluginIndexFiles.appendToFile(template, {
131
+ type: 'routes',
132
+ singularName: answers.id
133
+ });
134
+ }
135
+ return extendPluginIndexFiles.appendToFile(template, {
136
+ type: 'index',
137
+ singularName: answers.id
138
+ });
139
+ }
140
+ });
141
+ });
142
+ }
143
+ return baseActions;
76
144
  }
77
145
  });
78
146
  });
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sources":["../../src/plops/api.ts"],"sourcesContent":["import { join } from 'path';\nimport type { NodePlopAPI } from 'plop';\nimport fs from 'fs-extra';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport validateInput from './utils/validate-input';\n\nexport default (plop: NodePlopAPI) => {\n // API generator\n plop.setGenerator('api', {\n description: 'Generate a basic API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'API name',\n validate: (input) => validateInput(input),\n },\n {\n type: 'confirm',\n name: 'isPluginApi',\n message: 'Is this API for a plugin?',\n },\n {\n when: (answers) => answers.isPluginApi,\n type: 'list',\n name: 'plugin',\n message: 'Plugin name',\n async choices() {\n const pluginsPath = join(plop.getDestBasePath(), 'plugins');\n const exists = await fs.pathExists(pluginsPath);\n if (!exists) {\n throw Error('Couldn\\'t find a \"plugins\" directory');\n }\n\n const pluginsDir = await fs.readdir(pluginsPath, { withFileTypes: true });\n const pluginsDirContent = pluginsDir.filter((fd) => fd.isDirectory());\n\n if (pluginsDirContent.length === 0) {\n throw Error('The \"plugins\" directory is empty');\n }\n\n return pluginsDirContent;\n },\n },\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath =\n answers.isPluginApi && answers.plugin ? 'plugins/{{ plugin }}/server' : 'api/{{ id }}';\n const currentDir = process.cwd();\n const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n const baseActions = [\n {\n type: 'add',\n path: `${filePath}/controllers/{{ id }}.${language}`,\n templateFile: `templates/${language}/controller.${language}.hbs`,\n },\n {\n type: 'add',\n path: `${filePath}/services/{{ id }}.${language}`,\n templateFile: `templates/${language}/service.${language}.hbs`,\n },\n ];\n\n if (answers.isPluginApi) {\n return baseActions;\n }\n\n return [\n {\n type: 'add',\n path: `${filePath}/routes/{{ id }}.${language}`,\n templateFile: `templates/${language}/single-route.${language}.hbs`,\n },\n ...baseActions,\n ];\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","when","answers","isPluginApi","choices","pluginsPath","join","getDestBasePath","exists","fs","pathExists","Error","pluginsDir","readdir","withFileTypes","pluginsDirContent","filter","fd","isDirectory","length","actions","filePath","plugin","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","baseActions","path","templateFile"],"mappings":";;;;;;;AAOA,kBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,KAAO,EAAA;QACvBC,WAAa,EAAA,sBAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,IAAA;gBACNC,OAAS,EAAA,UAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,aAAcD,CAAAA,KAAAA;AACrC,aAAA;AACA,YAAA;gBACEJ,IAAM,EAAA,SAAA;gBACNC,IAAM,EAAA,aAAA;gBACNC,OAAS,EAAA;AACX,aAAA;AACA,YAAA;gBACEI,IAAM,EAAA,CAACC,OAAYA,GAAAA,OAAAA,CAAQC,WAAW;gBACtCR,IAAM,EAAA,MAAA;gBACNC,IAAM,EAAA,QAAA;gBACNC,OAAS,EAAA,aAAA;gBACT,MAAMO,OAAAA,CAAAA,GAAAA;AACJ,oBAAA,MAAMC,WAAcC,GAAAA,SAAAA,CAAKf,IAAKgB,CAAAA,eAAe,EAAI,EAAA,SAAA,CAAA;AACjD,oBAAA,MAAMC,MAAS,GAAA,MAAMC,EAAGC,CAAAA,UAAU,CAACL,WAAAA,CAAAA;AACnC,oBAAA,IAAI,CAACG,MAAQ,EAAA;AACX,wBAAA,MAAMG,KAAM,CAAA,sCAAA,CAAA;AACd;AAEA,oBAAA,MAAMC,UAAa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AACT;YAEA,OAAO;AACL,gBAAA;oBACElC,IAAM,EAAA,KAAA;AACNmC,oBAAAA,IAAAA,EAAM,CAAC,EAAET,QAAAA,CAAS,iBAAiB,EAAEK,SAAS,CAAC;oBAC/CK,YAAc,EAAA,CAAC,UAAU,EAAEL,QAAAA,CAAS,cAAc,EAAEA,QAAAA,CAAS,IAAI;AACnE,iBAAA;AACGG,gBAAAA,GAAAA;AACJ,aAAA;AACH;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"api.js","sources":["../../src/plops/api.ts"],"sourcesContent":["import { join } from 'path';\nimport type { ActionType, NodePlopAPI } from 'plop';\nimport fs from 'fs-extra';\nimport tsUtils from '@strapi/typescript-utils';\n\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 // API generator\n plop.setGenerator('api', {\n description: 'Generate a basic API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'API name',\n validate: (input) => validateInput(input),\n },\n {\n type: 'confirm',\n name: 'isPluginApi',\n message: 'Is this API for a plugin?',\n },\n {\n when: (answers) => answers.isPluginApi,\n type: 'list',\n name: 'plugin',\n message: 'Plugin name',\n async choices() {\n const pluginsPath = join(plop.getDestBasePath(), 'plugins');\n const exists = await fs.pathExists(pluginsPath);\n if (!exists) {\n throw Error('Couldn\\'t find a \"plugins\" directory');\n }\n\n const pluginsDir = await fs.readdir(pluginsPath, { withFileTypes: true });\n const pluginsDirContent = pluginsDir.filter((fd) => fd.isDirectory());\n\n if (pluginsDirContent.length === 0) {\n throw Error('The \"plugins\" directory is empty');\n }\n\n return pluginsDirContent;\n },\n },\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(\n answers.destination || (answers.isPluginApi && answers.plugin ? 'plugin' : 'api')\n );\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 type: 'add',\n path: `${filePath}/services/{{ id }}.${language}`,\n templateFile: `templates/${language}/service.${language}.hbs`,\n },\n {\n type: 'add',\n path: `${filePath}/routes/${answers.plugin ? 'content-api/' : ''}{{ id }}.${language}`,\n templateFile: `templates/${language}/single-route.${language}.hbs`,\n },\n ];\n\n if (answers.isPluginApi) {\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(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);\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, { type: 'routes', singularName: answers.id });\n }\n\n return appendToFile(template, { type: 'index', singularName: answers.id });\n },\n });\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","when","answers","isPluginApi","choices","pluginsPath","join","getDestBasePath","exists","fs","pathExists","Error","pluginsDir","readdir","withFileTypes","pluginsDirContent","filter","fd","isDirectory","length","actions","filePath","getFilePath","destination","plugin","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","pluginServerDir","replace","baseActions","path","templateFile","indexFiles","forEach","indexPath","existsSync","push","skipIfExists","routeIndexFiles","routeType","routeTypeIndexPath","routeTypeExists","data","transform","template","appendToFile","singularName","id"],"mappings":";;;;;;;;;AASA,kBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,KAAO,EAAA;QACvBC,WAAa,EAAA,sBAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,IAAA;gBACNC,OAAS,EAAA,UAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,aAAcD,CAAAA,KAAAA;AACrC,aAAA;AACA,YAAA;gBACEJ,IAAM,EAAA,SAAA;gBACNC,IAAM,EAAA,aAAA;gBACNC,OAAS,EAAA;AACX,aAAA;AACA,YAAA;gBACEI,IAAM,EAAA,CAACC,OAAYA,GAAAA,OAAAA,CAAQC,WAAW;gBACtCR,IAAM,EAAA,MAAA;gBACNC,IAAM,EAAA,QAAA;gBACNC,OAAS,EAAA,aAAA;gBACT,MAAMO,OAAAA,CAAAA,GAAAA;AACJ,oBAAA,MAAMC,WAAcC,GAAAA,SAAAA,CAAK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A;gCAAErD,IAAM,EAAA,OAAA;AAASuD,gCAAAA,YAAAA,EAAchD,QAAQiD;AAAG,6BAAA,CAAA;AAC1E;AACF,qBAAA,CAAA;AACF,iBAAA,CAAA;AACF;YAEA,OAAOlB,WAAAA;AACT;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
@@ -2,6 +2,8 @@ import { join } from 'path';
2
2
  import fs from 'fs-extra';
3
3
  import tsUtils from '@strapi/typescript-utils';
4
4
  import validateInput from './utils/validate-input.mjs';
5
+ import getFilePath from './utils/get-file-path.mjs';
6
+ import { appendToFile } from './utils/extend-plugin-index-files.mjs';
5
7
 
6
8
  var generateApi = ((plop)=>{
7
9
  // API generator
@@ -45,9 +47,14 @@ var generateApi = ((plop)=>{
45
47
  if (!answers) {
46
48
  return [];
47
49
  }
48
- const filePath = answers.isPluginApi && answers.plugin ? 'plugins/{{ plugin }}/server' : 'api/{{ id }}';
50
+ const filePath = getFilePath(answers.destination || (answers.isPluginApi && answers.plugin ? 'plugin' : 'api'));
49
51
  const currentDir = process.cwd();
50
- const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
52
+ let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
53
+ if (answers.plugin) {
54
+ // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
55
+ const pluginServerDir = join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
56
+ language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
57
+ }
51
58
  const baseActions = [
52
59
  {
53
60
  type: 'add',
@@ -58,19 +65,80 @@ var generateApi = ((plop)=>{
58
65
  type: 'add',
59
66
  path: `${filePath}/services/{{ id }}.${language}`,
60
67
  templateFile: `templates/${language}/service.${language}.hbs`
61
- }
62
- ];
63
- if (answers.isPluginApi) {
64
- return baseActions;
65
- }
66
- return [
68
+ },
67
69
  {
68
70
  type: 'add',
69
- path: `${filePath}/routes/{{ id }}.${language}`,
71
+ path: `${filePath}/routes/${answers.plugin ? 'content-api/' : ''}{{ id }}.${language}`,
70
72
  templateFile: `templates/${language}/single-route.${language}.hbs`
71
- },
72
- ...baseActions
73
+ }
73
74
  ];
75
+ if (answers.isPluginApi) {
76
+ const indexFiles = [
77
+ 'controllers',
78
+ 'services',
79
+ 'routes'
80
+ ];
81
+ indexFiles.forEach((type)=>{
82
+ const indexPath = join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);
83
+ const exists = fs.existsSync(indexPath);
84
+ if (!exists && type !== 'routes') {
85
+ baseActions.push({
86
+ type: 'add',
87
+ path: `${filePath}/${type}/index.${language}`,
88
+ templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
89
+ skipIfExists: true
90
+ });
91
+ }
92
+ if (type === 'routes') {
93
+ const indexPath = join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);
94
+ const exists = fs.existsSync(indexPath);
95
+ if (!exists) {
96
+ baseActions.push({
97
+ type: 'add',
98
+ path: `${filePath}/${type}/index.${language}`,
99
+ templateFile: `templates/${language}/plugin/plugin.routes.index.${language}.hbs`,
100
+ skipIfExists: true
101
+ });
102
+ }
103
+ const routeIndexFiles = [
104
+ 'content-api',
105
+ 'admin'
106
+ ];
107
+ routeIndexFiles.forEach((routeType)=>{
108
+ const routeTypeIndexPath = join(plop.getDestBasePath(), `${filePath}/${type}/${routeType}/index.${language}`);
109
+ const routeTypeExists = fs.existsSync(routeTypeIndexPath);
110
+ if (!routeTypeExists) {
111
+ baseActions.push({
112
+ type: 'add',
113
+ path: `${filePath}/${type}/${routeType}/index.${language}`,
114
+ templateFile: `templates/${language}/plugin/plugin.routes.type.index.${language}.hbs`,
115
+ data: {
116
+ type: routeType
117
+ },
118
+ skipIfExists: true
119
+ });
120
+ }
121
+ });
122
+ }
123
+ baseActions.push({
124
+ type: 'modify',
125
+ path: `${filePath}/${type}/${type === 'routes' ? 'content-api/' : ''}index.${language}`,
126
+ transform (template) {
127
+ if (type === 'routes') {
128
+ return appendToFile(template, {
129
+ type: 'routes',
130
+ singularName: answers.id
131
+ });
132
+ }
133
+ return appendToFile(template, {
134
+ type: 'index',
135
+ singularName: answers.id
136
+ });
137
+ }
138
+ });
139
+ });
140
+ }
141
+ return baseActions;
74
142
  }
75
143
  });
76
144
  });
@@ -1 +1 @@
1
- {"version":3,"file":"api.mjs","sources":["../../src/plops/api.ts"],"sourcesContent":["import { join } from 'path';\nimport type { NodePlopAPI } from 'plop';\nimport fs from 'fs-extra';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport validateInput from './utils/validate-input';\n\nexport default (plop: NodePlopAPI) => {\n // API generator\n plop.setGenerator('api', {\n description: 'Generate a basic API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'API name',\n validate: (input) => validateInput(input),\n },\n {\n type: 'confirm',\n name: 'isPluginApi',\n message: 'Is this API for a plugin?',\n },\n {\n when: (answers) => answers.isPluginApi,\n type: 'list',\n name: 'plugin',\n message: 'Plugin name',\n async choices() {\n const pluginsPath = join(plop.getDestBasePath(), 'plugins');\n const exists = await fs.pathExists(pluginsPath);\n if (!exists) {\n throw Error('Couldn\\'t find a \"plugins\" directory');\n }\n\n const pluginsDir = await fs.readdir(pluginsPath, { withFileTypes: true });\n const pluginsDirContent = pluginsDir.filter((fd) => fd.isDirectory());\n\n if (pluginsDirContent.length === 0) {\n throw Error('The \"plugins\" directory is empty');\n }\n\n return pluginsDirContent;\n },\n },\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath =\n answers.isPluginApi && answers.plugin ? 'plugins/{{ plugin }}/server' : 'api/{{ id }}';\n const currentDir = process.cwd();\n const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n const baseActions = [\n {\n type: 'add',\n path: `${filePath}/controllers/{{ id }}.${language}`,\n templateFile: `templates/${language}/controller.${language}.hbs`,\n },\n {\n type: 'add',\n path: `${filePath}/services/{{ id }}.${language}`,\n templateFile: `templates/${language}/service.${language}.hbs`,\n },\n ];\n\n if (answers.isPluginApi) {\n return baseActions;\n }\n\n return [\n {\n type: 'add',\n path: `${filePath}/routes/{{ id }}.${language}`,\n templateFile: `templates/${language}/single-route.${language}.hbs`,\n },\n ...baseActions,\n ];\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","when","answers","isPluginApi","choices","pluginsPath","join","getDestBasePath","exists","fs","pathExists","Error","pluginsDir","readdir","withFileTypes","pluginsDirContent","filter","fd","isDirectory","length","actions","filePath","plugin","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","baseActions","path","templateFile"],"mappings":";;;;;AAOA,kBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,KAAO,EAAA;QACvBC,WAAa,EAAA,sBAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,IAAA;gBACNC,OAAS,EAAA,UAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,aAAcD,CAAAA,KAAAA;AACrC,aAAA;AACA,YAAA;gBACEJ,IAAM,EAAA,SAAA;gBACNC,IAAM,EAAA,aAAA;gBACNC,OAAS,EAAA;AACX,aAAA;AACA,YAAA;gBACEI,IAAM,EAAA,CAACC,OAAYA,GAAAA,OAAAA,CAAQC,WAAW;gBACtCR,IAAM,EAAA,MAAA;gBACNC,IAAM,EAAA,QAAA;gBACNC,OAAS,EAAA,aAAA;gBACT,MAAMO,OAAAA,CAAAA,GAAAA;AACJ,oBAAA,MAAMC,WAAcC,GAAAA,IAAAA,CAAKf,IAAKgB,CAAAA,eAAe,EAAI,EAAA,SAAA,CAAA;AACjD,oBAAA,MAAMC,MAAS,GAAA,MAAMC,EAAGC,CAAAA,UAAU,CAACL,WAAAA,CAAAA;AACnC,oBAAA,IAAI,CAACG,MAAQ,EAAA;AACX,wBAAA,MAAMG,KAAM,CAAA,sCAAA,CAAA;AACd;AAEA,oBAAA,MAAMC,UAAa,GAA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YAEA,OAAO;AACL,gBAAA;oBACElC,IAAM,EAAA,KAAA;AACNmC,oBAAAA,IAAAA,EAAM,CAAC,EAAET,QAAAA,CAAS,iBAAiB,EAAEK,SAAS,CAAC;oBAC/CK,YAAc,EAAA,CAAC,UAAU,EAAEL,QAAAA,CAAS,cAAc,EAAEA,QAAAA,CAAS,IAAI;AACnE,iBAAA;AACGG,gBAAAA,GAAAA;AACJ,aAAA;AACH;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"api.mjs","sources":["../../src/plops/api.ts"],"sourcesContent":["import { join } from 'path';\nimport type { ActionType, NodePlopAPI } from 'plop';\nimport fs from 'fs-extra';\nimport tsUtils from '@strapi/typescript-utils';\n\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 // API generator\n plop.setGenerator('api', {\n description: 'Generate a basic API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'API name',\n validate: (input) => validateInput(input),\n },\n {\n type: 'confirm',\n name: 'isPluginApi',\n message: 'Is this API for a plugin?',\n },\n {\n when: (answers) => answers.isPluginApi,\n type: 'list',\n name: 'plugin',\n message: 'Plugin name',\n async choices() {\n const pluginsPath = join(plop.getDestBasePath(), 'plugins');\n const exists = await fs.pathExists(pluginsPath);\n if (!exists) {\n throw Error('Couldn\\'t find a \"plugins\" directory');\n }\n\n const pluginsDir = await fs.readdir(pluginsPath, { withFileTypes: true });\n const pluginsDirContent = pluginsDir.filter((fd) => fd.isDirectory());\n\n if (pluginsDirContent.length === 0) {\n throw Error('The \"plugins\" directory is empty');\n }\n\n return pluginsDirContent;\n },\n },\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(\n answers.destination || (answers.isPluginApi && answers.plugin ? 'plugin' : 'api')\n );\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 type: 'add',\n path: `${filePath}/services/{{ id }}.${language}`,\n templateFile: `templates/${language}/service.${language}.hbs`,\n },\n {\n type: 'add',\n path: `${filePath}/routes/${answers.plugin ? 'content-api/' : ''}{{ id }}.${language}`,\n templateFile: `templates/${language}/single-route.${language}.hbs`,\n },\n ];\n\n if (answers.isPluginApi) {\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(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);\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, { type: 'routes', singularName: answers.id });\n }\n\n return appendToFile(template, { type: 'index', singularName: answers.id });\n },\n });\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","when","answers","isPluginApi","choices","pluginsPath","join","getDestBasePath","exists","fs","pathExists","Error","pluginsDir","readdir","withFileTypes","pluginsDirContent","filter","fd","isDirectory","length","actions","filePath","getFilePath","destination","plugin","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","pluginServerDir","replace","baseActions","path","templateFile","indexFiles","forEach","indexPath","existsSync","push","skipIfExists","routeIndexFiles","routeType","routeTypeIndexPath","routeTypeExists","data","transform","template","appendToFile","singularName","id"],"mappings":";;;;;;;AASA,kBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,KAAO,EAAA;QACvBC,WAAa,EAAA,sBAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,IAAA;gBACNC,OAAS,EAAA,UAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,aAAcD,CAAAA,KAAAA;AACrC,aAAA;AACA,YAAA;gBACEJ,IAAM,EAAA,SAAA;gBACNC,IAAM,EAAA,aAAA;gBACNC,OAAS,EAAA;AACX,aAAA;AACA,YAAA;gBACEI,IAAM,EAAA,CAACC,OAAYA,GAAAA,OAAAA,CAAQC,WAAW;gBACtCR,IAAM,EAAA,MAAA;gBACNC,IAAM,EAAA,QAAA;gBACNC,OAAS,EAAA,aAAA;gBACT,MAAMO,OAAAA,CAAAA,GAAAA;AACJ,oBAAA,MAAMC,WAAcC,GAAAA,IAAAA,CAAKf,IA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ErD,IAAM,EAAA,OAAA;AAASuD,gCAAAA,YAAAA,EAAchD,QAAQiD;AAAG,6BAAA,CAAA;AAC1E;AACF,qBAAA,CAAA;AACF,iBAAA,CAAA;AACF;YAEA,OAAOlB,WAAAA;AACT;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"content-type.d.ts","sourceRoot":"","sources":["../../src/plops/content-type.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAc,MAAM,MAAM,CAAC;+BAa9B,WAAW;AAAjC,wBAmIE"}
1
+ {"version":3,"file":"content-type.d.ts","sourceRoot":"","sources":["../../src/plops/content-type.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAc,MAAM,MAAM,CAAC;+BAc9B,WAAW;AAAjC,wBAqPE"}
@@ -11,6 +11,7 @@ var ctNamesPrompts = require('./prompts/ct-names-prompts.js');
11
11
  var kindPrompts = require('./prompts/kind-prompts.js');
12
12
  var getAttributesPrompts = require('./prompts/get-attributes-prompts.js');
13
13
  var bootstrapApiPrompts = require('./prompts/bootstrap-api-prompts.js');
14
+ var extendPluginIndexFiles = require('./utils/extend-plugin-index-files.js');
14
15
 
15
16
  var generateContentType = ((plop)=>{
16
17
  // Model generator
@@ -83,7 +84,12 @@ var generateContentType = ((plop)=>{
83
84
  }, {});
84
85
  const filePath = getFilePath(answers.destination);
85
86
  const currentDir = process.cwd();
86
- const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
87
+ let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
88
+ if (answers.plugin) {
89
+ // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
90
+ const pluginServerDir = path.join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
91
+ language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
92
+ }
87
93
  const baseActions = [
88
94
  {
89
95
  type: 'add',
@@ -107,6 +113,30 @@ var generateContentType = ((plop)=>{
107
113
  }
108
114
  });
109
115
  }
116
+ if (answers.plugin) {
117
+ const indexPath = path.join(plop.getDestBasePath(), `${filePath}/content-types/index.${language}`);
118
+ const exists = fs.existsSync(indexPath);
119
+ if (!exists) {
120
+ // Create index file if it doesn't exist
121
+ baseActions.push({
122
+ type: 'add',
123
+ path: `${filePath}/content-types/index.${language}`,
124
+ templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
125
+ skipIfExists: true
126
+ });
127
+ }
128
+ // Append the new content type to the index.ts file
129
+ baseActions.push({
130
+ type: 'modify',
131
+ path: `${filePath}/content-types/index.${language}`,
132
+ transform (template) {
133
+ return extendPluginIndexFiles.appendToFile(template, {
134
+ type: 'content-type',
135
+ singularName: answers.singularName
136
+ });
137
+ }
138
+ });
139
+ }
110
140
  if (answers.bootstrapApi) {
111
141
  const { singularName } = answers;
112
142
  let uid;
@@ -133,12 +163,78 @@ var generateContentType = ((plop)=>{
133
163
  }
134
164
  }, {
135
165
  type: 'add',
136
- path: `${filePath}/routes/{{ singularName }}.${language}`,
166
+ path: `${filePath}/routes/${answers.plugin ? 'content-api/' : ''}{{ singularName }}.${language}`,
137
167
  templateFile: `templates/${language}/core-router.${language}.hbs`,
138
168
  data: {
139
169
  uid
140
170
  }
141
171
  });
172
+ if (answers.plugin) {
173
+ const indexFiles = [
174
+ 'controllers',
175
+ 'services',
176
+ 'routes'
177
+ ];
178
+ indexFiles.forEach((type)=>{
179
+ const indexPath = path.join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);
180
+ const exists = fs.existsSync(indexPath);
181
+ if (!exists && type !== 'routes') {
182
+ baseActions.push({
183
+ type: 'add',
184
+ path: `${filePath}/${type}/index.${language}`,
185
+ templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
186
+ skipIfExists: true
187
+ });
188
+ }
189
+ if (type === 'routes') {
190
+ const indexPath = path.join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);
191
+ const exists = fs.existsSync(indexPath);
192
+ if (!exists) {
193
+ baseActions.push({
194
+ type: 'add',
195
+ path: `${filePath}/${type}/index.${language}`,
196
+ templateFile: `templates/${language}/plugin/plugin.routes.index.${language}.hbs`,
197
+ skipIfExists: true
198
+ });
199
+ }
200
+ const routeIndexFiles = [
201
+ 'content-api',
202
+ 'admin'
203
+ ];
204
+ routeIndexFiles.forEach((routeType)=>{
205
+ const routeTypeIndexPath = path.join(plop.getDestBasePath(), `${filePath}/${type}/${routeType}/index.${language}`);
206
+ const routeTypeExists = fs.existsSync(routeTypeIndexPath);
207
+ if (!routeTypeExists) {
208
+ baseActions.push({
209
+ type: 'add',
210
+ path: `${filePath}/${type}/${routeType}/index.${language}`,
211
+ templateFile: `templates/${language}/plugin/plugin.routes.type.index.${language}.hbs`,
212
+ data: {
213
+ type: routeType
214
+ },
215
+ skipIfExists: true
216
+ });
217
+ }
218
+ });
219
+ }
220
+ baseActions.push({
221
+ type: 'modify',
222
+ path: `${filePath}/${type}/${type === 'routes' ? 'content-api/' : ''}index.${language}`,
223
+ transform (template) {
224
+ if (type === 'routes') {
225
+ return extendPluginIndexFiles.appendToFile(template, {
226
+ type: 'routes',
227
+ singularName: answers.singularName
228
+ });
229
+ }
230
+ return extendPluginIndexFiles.appendToFile(template, {
231
+ type: 'index',
232
+ singularName: answers.singularName
233
+ });
234
+ }
235
+ });
236
+ });
237
+ }
142
238
  }
143
239
  return baseActions;
144
240
  }