@strapi/generators 5.37.0 → 5.38.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 (43) hide show
  1. package/dist/index.js.map +1 -1
  2. package/dist/index.mjs.map +1 -1
  3. package/dist/plopfile.js.map +1 -1
  4. package/dist/plopfile.mjs.map +1 -1
  5. package/dist/plops/api.js.map +1 -1
  6. package/dist/plops/api.mjs.map +1 -1
  7. package/dist/plops/content-type.js.map +1 -1
  8. package/dist/plops/content-type.mjs.map +1 -1
  9. package/dist/plops/controller.js.map +1 -1
  10. package/dist/plops/controller.mjs.map +1 -1
  11. package/dist/plops/middleware.js.map +1 -1
  12. package/dist/plops/middleware.mjs.map +1 -1
  13. package/dist/plops/migration.js.map +1 -1
  14. package/dist/plops/migration.mjs.map +1 -1
  15. package/dist/plops/policy.js.map +1 -1
  16. package/dist/plops/policy.mjs.map +1 -1
  17. package/dist/plops/prompts/bootstrap-api-prompts.js.map +1 -1
  18. package/dist/plops/prompts/bootstrap-api-prompts.mjs.map +1 -1
  19. package/dist/plops/prompts/ct-names-prompts.js.map +1 -1
  20. package/dist/plops/prompts/ct-names-prompts.mjs.map +1 -1
  21. package/dist/plops/prompts/get-attributes-prompts.js.map +1 -1
  22. package/dist/plops/prompts/get-attributes-prompts.mjs.map +1 -1
  23. package/dist/plops/prompts/get-destination-prompts.js.map +1 -1
  24. package/dist/plops/prompts/get-destination-prompts.mjs.map +1 -1
  25. package/dist/plops/prompts/kind-prompts.js.map +1 -1
  26. package/dist/plops/prompts/kind-prompts.mjs.map +1 -1
  27. package/dist/plops/service.js.map +1 -1
  28. package/dist/plops/service.mjs.map +1 -1
  29. package/dist/plops/utils/extend-plugin-index-files.js +6 -6
  30. package/dist/plops/utils/extend-plugin-index-files.js.map +1 -1
  31. package/dist/plops/utils/extend-plugin-index-files.mjs +6 -6
  32. package/dist/plops/utils/extend-plugin-index-files.mjs.map +1 -1
  33. package/dist/plops/utils/get-file-path.js.map +1 -1
  34. package/dist/plops/utils/get-file-path.mjs.map +1 -1
  35. package/dist/plops/utils/get-formatted-date.js.map +1 -1
  36. package/dist/plops/utils/get-formatted-date.mjs.map +1 -1
  37. package/dist/plops/utils/validate-attribute-input.js.map +1 -1
  38. package/dist/plops/utils/validate-attribute-input.mjs.map +1 -1
  39. package/dist/plops/utils/validate-file-name-input.js.map +1 -1
  40. package/dist/plops/utils/validate-file-name-input.mjs.map +1 -1
  41. package/dist/plops/utils/validate-input.js.map +1 -1
  42. package/dist/plops/utils/validate-input.mjs.map +1 -1
  43. package/package.json +5 -5
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 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,OAAO,MAAA,CAAA;AAEnCD,IAAAA,IAAAA,CAAKE,OAAO,CACV;AACEC,QAAAA,UAAAA,EAAYC,eAAKC,SAAW,EAAA,aAAA;AAC9B,KAAA,EACA,CAACC,GAAAA,GAAAA;AACCN,QAAAA,IAAAA,CAAKO,OAAO,CAACD,GAAAA,EAAK,EAAE,EAAE,CAACA,GAAKE,EAAAA,IAAAA,GAAAA;AAC1B,YAAA,MAAMC,OAAU,GAAA;AACd,gBAAA,GAAGH,GAAG;gBACNI,IAAMN,EAAAA,cAAAA,CAAKO,OAAQC,CAAAA,GAAG,EAAI,EAAA,KAAA;AAC5B,aAAA;AACA,YAAA,OAAOX,GAAIQ,CAAAA,OAAAA,EAASD,IAAM,EAAA,IAAA,CAAA,CAAA;AAC5B,SAAA,CAAA;AACF,KAAA,CAAA;AAEJ;MAeaK,QAAW,GAAA,OACtBC,aACAL,EAAAA,OAAAA,EACA,EAAEM,GAAMJ,GAAAA,OAAAA,CAAQC,GAAG,EAAE,EAAEI,QAAW,GAAA,aAAa,EAAmB,GAAG,EAAE,GAAA;;IAGvE,MAAMC,YAAAA,GAAeb,eAAKC,SAAWW,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,Y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,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","dirname","writeFile","pathExists","content","modified","transform"],"mappings":";;;;;;AAIA;MACaA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
@@ -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 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,OAAO,MAAA,CAAA;AAEnCD,IAAAA,IAAAA,CAAKE,OAAO,CACV;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AAAA,MAAAA,CAAOM,YAAY,EAAE;AAChD,YAAA,MAAMC,YAAe7C,GAAAA,IAAAA,CAAKC,SAAWqC,EAAAA,MAAAA,CAAOM,YAAY,CAAA;AACxD,YAAA,MAAME,eAAkB,GAAA,MAAMC,EAAGC,CAAAA,QAAQ,CAACH,YAAc,EAAA,MAAA,CAAA;YACxD,MAAMI,QAAAA,GAAWb,UAAWI,CAAAA,OAAO,CAACM,eAAAA,CAAAA;AACpC,YAAA,MAAMI,SAASD,QAAS,CAAA;AAAE,gBAAA,GAAG5C,OAAO;AAAE,gBAAA,GAAGiC,OAAOa;AAAK,aAAA,CAAA;YAErD,MAAMJ,EAAAA,CAAGK,SAAS,CAACC,OAAQX,CAAAA,QAAAA,CAAAA,CAAAA;YAC3B,MAAMK,EAAAA,CAAGO,SAAS,CAACZ,QAAUQ,EAAAA,MAAAA,CAAAA;AAC/B;QAEA,IAAIZ,MAAAA,CAAOK,IAAI,KAAK,QAAU,EAAA;AAC5B,YAAA,IAAI,MAAMI,EAAAA,CAAGQ,UAAU,CAACb,QAAW,CAAA,EAAA;AACjC,gBAAA,MAAMc,OAAU,GAAA,MAAMT,EAAGC,CAAAA,QAAQ,CAACN,QAAU,EAAA,MAAA,CAAA;AAC5C,gBAAA,MAAMe,WAAWnB,MAAOoB,CAAAA,SAAS,GAAGpB,MAAOoB,CAAAA,SAAS,CAACF,OAAWA,CAAAA,GAAAA,OAAAA;gBAChE,MAAMT,EAAAA,CAAGO,SAAS,CAACZ,QAAUe,EAAAA,QAAAA,CAAAA;AAC/B;AACF;AACF;AACF,CAAA;;;;"}
1
+ {"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,MAAAA,GAAS,UAAA;IACpB,MAAM,EAAEC,IAAI,EAAEC,GAAG,EAAE,GAAG,MAAM,OAAO,MAAA,CAAA;AAEnCD,IAAAA,IAAAA,CAAKE,OAAO,CACV;AACEC,QAAAA,UAAAA,EAAYC,KAAKC,SAAAA,EAAW,aAAA;AAC9B,KAAA,EACA,CAACC,GAAAA,GAAAA;AACCN,QAAAA,IAAAA,CAAKO,OAAO,CAACD,GAAAA,EAAK,EAAE,EAAE,CAACA,GAAAA,EAAKE,IAAAA,GAAAA;AAC1B,YAAA,MAAMC,OAAAA,GAAU;AACd,gBAAA,GAAGH,GAAG;gBAC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,CAACH,YAAAA,EAAc,MAAA,CAAA;YACxD,MAAMI,QAAAA,GAAWb,UAAAA,CAAWI,OAAO,CAACM,eAAAA,CAAAA;AACpC,YAAA,MAAMI,SAASD,QAAAA,CAAS;AAAE,gBAAA,GAAG5C,OAAO;AAAE,gBAAA,GAAGiC,OAAOa;AAAK,aAAA,CAAA;YAErD,MAAMJ,EAAAA,CAAGK,SAAS,CAACC,OAAAA,CAAQX,QAAAA,CAAAA,CAAAA;YAC3B,MAAMK,EAAAA,CAAGO,SAAS,CAACZ,QAAAA,EAAUQ,MAAAA,CAAAA;AAC/B,QAAA;QAEA,IAAIZ,MAAAA,CAAOK,IAAI,KAAK,QAAA,EAAU;AAC5B,YAAA,IAAI,MAAMI,EAAAA,CAAGQ,UAAU,CAACb,QAAAA,CAAAA,EAAW;AACjC,gBAAA,MAAMc,OAAAA,GAAU,MAAMT,EAAAA,CAAGC,QAAQ,CAACN,QAAAA,EAAU,MAAA,CAAA;AAC5C,gBAAA,MAAMe,WAAWnB,MAAAA,CAAOoB,SAAS,GAAGpB,MAAAA,CAAOoB,SAAS,CAACF,OAAAA,CAAAA,GAAWA,OAAAA;gBAChE,MAAMT,EAAAA,CAAGO,SAAS,CAACZ,QAAAA,EAAUe,QAAAA,CAAAA;AAC/B,YAAA;AACF,QAAA;AACF,IAAA;AACF,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"plopfile.js","sources":["../src/plopfile.ts"],"sourcesContent":["import pluralize from 'pluralize';\nimport type { NodePlopAPI } from 'plop';\n\nimport generateApi from './plops/api';\nimport generateController from './plops/controller';\nimport generateContentType from './plops/content-type';\nimport generatePolicy from './plops/policy';\nimport generateMiddleware from './plops/middleware';\nimport generateMigration from './plops/migration';\nimport generateService from './plops/service';\n\nexport default (plop: NodePlopAPI) => {\n // Plop config\n plop.setWelcomeMessage('Strapi Generators');\n plop.setHelper('pluralize', (text: string) => pluralize(text));\n\n // Generators\n generateApi(plop);\n generateController(plop);\n generateContentType(plop);\n generatePolicy(plop);\n generateMiddleware(plop);\n generateMigration(plop);\n generateService(plop);\n};\n"],"names":["plop","setWelcomeMessage","setHelper","text","pluralize","generateApi","generateController","generateContentType","generatePolicy","generateMiddleware","generateMigration","generateService"],"mappings":";;;;;;;;;;;AAWA,eAAe,CAAA,CAACA,IAAAA,GAAAA;;AAEdA,IAAAA,IAAAA,CAAKC,iBAAiB,CAAC,mBAAA,CAAA;AACvBD,IAAAA,IAAAA,CAAKE,SAAS,CAAC,WAAa,EAAA,CAACC,OAAiBC,SAAUD,CAAAA,IAAAA,CAAAA,CAAAA;;IAGxDE,GAAYL,CAAAA,IAAAA,CAAAA;IACZM,UAAmBN,CAAAA,IAAAA,CAAAA;IACnBO,WAAoBP,CAAAA,IAAAA,CAAAA;IACpBQ,MAAeR,CAAAA,IAAAA,CAAAA;IACfS,UAAmBT,CAAAA,IAAAA,CAAAA;IACnBU,SAAkBV,CAAAA,IAAAA,CAAAA;IAClBW,OAAgBX,CAAAA,IAAAA,CAAAA;AAClB,CAAA;;;;"}
1
+ {"version":3,"file":"plopfile.js","sources":["../src/plopfile.ts"],"sourcesContent":["import pluralize from 'pluralize';\nimport type { NodePlopAPI } from 'plop';\n\nimport generateApi from './plops/api';\nimport generateController from './plops/controller';\nimport generateContentType from './plops/content-type';\nimport generatePolicy from './plops/policy';\nimport generateMiddleware from './plops/middleware';\nimport generateMigration from './plops/migration';\nimport generateService from './plops/service';\n\nexport default (plop: NodePlopAPI) => {\n // Plop config\n plop.setWelcomeMessage('Strapi Generators');\n plop.setHelper('pluralize', (text: string) => pluralize(text));\n\n // Generators\n generateApi(plop);\n generateController(plop);\n generateContentType(plop);\n generatePolicy(plop);\n generateMiddleware(plop);\n generateMigration(plop);\n generateService(plop);\n};\n"],"names":["plop","setWelcomeMessage","setHelper","text","pluralize","generateApi","generateController","generateContentType","generatePolicy","generateMiddleware","generateMigration","generateService"],"mappings":";;;;;;;;;;;AAWA,eAAe,CAAA,CAACA,IAAAA,GAAAA;;AAEdA,IAAAA,IAAAA,CAAKC,iBAAiB,CAAC,mBAAA,CAAA;AACvBD,IAAAA,IAAAA,CAAKE,SAAS,CAAC,WAAA,EAAa,CAACC,OAAiBC,SAAAA,CAAUD,IAAAA,CAAAA,CAAAA;;IAGxDE,GAAAA,CAAYL,IAAAA,CAAAA;IACZM,UAAAA,CAAmBN,IAAAA,CAAAA;IACnBO,WAAAA,CAAoBP,IAAAA,CAAAA;IACpBQ,MAAAA,CAAeR,IAAAA,CAAAA;IACfS,UAAAA,CAAmBT,IAAAA,CAAAA;IACnBU,SAAAA,CAAkBV,IAAAA,CAAAA;IAClBW,OAAAA,CAAgBX,IAAAA,CAAAA;AAClB,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"plopfile.mjs","sources":["../src/plopfile.ts"],"sourcesContent":["import pluralize from 'pluralize';\nimport type { NodePlopAPI } from 'plop';\n\nimport generateApi from './plops/api';\nimport generateController from './plops/controller';\nimport generateContentType from './plops/content-type';\nimport generatePolicy from './plops/policy';\nimport generateMiddleware from './plops/middleware';\nimport generateMigration from './plops/migration';\nimport generateService from './plops/service';\n\nexport default (plop: NodePlopAPI) => {\n // Plop config\n plop.setWelcomeMessage('Strapi Generators');\n plop.setHelper('pluralize', (text: string) => pluralize(text));\n\n // Generators\n generateApi(plop);\n generateController(plop);\n generateContentType(plop);\n generatePolicy(plop);\n generateMiddleware(plop);\n generateMigration(plop);\n generateService(plop);\n};\n"],"names":["plop","setWelcomeMessage","setHelper","text","pluralize","generateApi","generateController","generateContentType","generatePolicy","generateMiddleware","generateMigration","generateService"],"mappings":";;;;;;;;;AAWA,eAAe,CAAA,CAACA,IAAAA,GAAAA;;AAEdA,IAAAA,IAAAA,CAAKC,iBAAiB,CAAC,mBAAA,CAAA;AACvBD,IAAAA,IAAAA,CAAKE,SAAS,CAAC,WAAa,EAAA,CAACC,OAAiBC,SAAUD,CAAAA,IAAAA,CAAAA,CAAAA;;IAGxDE,WAAYL,CAAAA,IAAAA,CAAAA;IACZM,kBAAmBN,CAAAA,IAAAA,CAAAA;IACnBO,mBAAoBP,CAAAA,IAAAA,CAAAA;IACpBQ,cAAeR,CAAAA,IAAAA,CAAAA;IACfS,kBAAmBT,CAAAA,IAAAA,CAAAA;IACnBU,iBAAkBV,CAAAA,IAAAA,CAAAA;IAClBW,eAAgBX,CAAAA,IAAAA,CAAAA;AAClB,CAAA;;;;"}
1
+ {"version":3,"file":"plopfile.mjs","sources":["../src/plopfile.ts"],"sourcesContent":["import pluralize from 'pluralize';\nimport type { NodePlopAPI } from 'plop';\n\nimport generateApi from './plops/api';\nimport generateController from './plops/controller';\nimport generateContentType from './plops/content-type';\nimport generatePolicy from './plops/policy';\nimport generateMiddleware from './plops/middleware';\nimport generateMigration from './plops/migration';\nimport generateService from './plops/service';\n\nexport default (plop: NodePlopAPI) => {\n // Plop config\n plop.setWelcomeMessage('Strapi Generators');\n plop.setHelper('pluralize', (text: string) => pluralize(text));\n\n // Generators\n generateApi(plop);\n generateController(plop);\n generateContentType(plop);\n generatePolicy(plop);\n generateMiddleware(plop);\n generateMigration(plop);\n generateService(plop);\n};\n"],"names":["plop","setWelcomeMessage","setHelper","text","pluralize","generateApi","generateController","generateContentType","generatePolicy","generateMiddleware","generateMigration","generateService"],"mappings":";;;;;;;;;AAWA,eAAe,CAAA,CAACA,IAAAA,GAAAA;;AAEdA,IAAAA,IAAAA,CAAKC,iBAAiB,CAAC,mBAAA,CAAA;AACvBD,IAAAA,IAAAA,CAAKE,SAAS,CAAC,WAAA,EAAa,CAACC,OAAiBC,SAAAA,CAAUD,IAAAA,CAAAA,CAAAA;;IAGxDE,WAAAA,CAAYL,IAAAA,CAAAA;IACZM,kBAAAA,CAAmBN,IAAAA,CAAAA;IACnBO,mBAAAA,CAAoBP,IAAAA,CAAAA;IACpBQ,cAAAA,CAAeR,IAAAA,CAAAA;IACfS,kBAAAA,CAAmBT,IAAAA,CAAAA;IACnBU,iBAAAA,CAAkBV,IAAAA,CAAAA;IAClBW,eAAAA,CAAgBX,IAAAA,CAAAA;AAClB,CAAA;;;;"}
@@ -1 +1 @@
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,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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esContent":["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,IAAAA,CAAKC,YAAY,CAAC,KAAA,EAAO;QACvBC,WAAAA,EAAa,sBAAA;QACbC,OAAAA,EAAS;AACP,YAAA;gBACEC,IAAAA,EAAM,OAAA;gBACNC,IAAAA,EAAM,IAAA;gBACNC,OAAAA,EAAS,UAAA;gBACTC,QAAAA,EAAU,CAACC,QAAUC,aAAAA,CAAcD,KAAAA;AACrC,aAAA;AACA,YAAA;gBACEJ,IAAAA,EAAM,SAAA;gBACNC,IAAAA,EAAM,aAAA;gBACNC,OAAAA,EAAS;AACX,aAAA;AACA,YAAA;gBACEI,IAAAA,EAAM,CAACC,OAAAA,GAAYA,OAAAA,CAAQC,WAAW;gBACtCR,IAAAA,EAAM,MAAA;gBACNC,IAAAA,EAAM,QAAA;gBACNC,OAAAA,EAAS,aAAA;gBACT,MAAMO,OAAAA,CAAAA,GAAAA;AACJ,oBAAA,MAAMC,WAAAA,GAAcC,SAAAA,CAAKf,IAAAA,CAAKgB,eAAe,EAAA,EAAI,SAAA,CAAA;AACjD,oBAAA,MAAMC,MAAAA,GAAS,MAAMC,EAAAA,CAAGC,UAAU,CAACL,WAAAA,CAAAA;AACnC,oBAAA,IAAI,CAACG,MAAAA,EAAQ;AACX,wBAAA,MAAMG,KAAAA,CAAM,sCAAA,CAAA;AACd,oBAAA;AAEA,oBAAA,MAAMC,UAAAA,GAAa,MAAMH,EAAAA,CAAGI,OAAO,CAACR,WAAAA,EAAa;wBAAES,aAAAA,EAAe;AAAK,qBAAA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KAAA,CAAA;AACF,CAAA;;;;"}
@@ -1 +1 @@
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,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,GAAA,MAAMH,EAAGI,CA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{ 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,IAAAA,CAAKC,YAAY,CAAC,KAAA,EAAO;QACvBC,WAAAA,EAAa,sBAAA;QACbC,OAAAA,EAAS;AACP,YAAA;gBACEC,IAAAA,EAAM,OAAA;gBACNC,IAAAA,EAAM,IAAA;gBACNC,OAAAA,EAAS,UAAA;gBACTC,QAAAA,EAAU,CAACC,QAAUC,aAAAA,CAAcD,KAAAA;AACrC,aAAA;AACA,YAAA;gBACEJ,IAAAA,EAAM,SAAA;gBACNC,IAAAA,EAAM,aAAA;gBACNC,OAAAA,EAAS;AACX,aAAA;AACA,YAAA;gBACEI,IAAAA,EAAM,CAACC,OAAAA,GAAYA,OAAAA,CAAQC,WAAW;gBACtCR,IAAAA,EAAM,MAAA;gBACNC,IAAAA,EAAM,QAAA;gBACNC,OAAAA,EAAS,aAAA;gBACT,MAAMO,OAAAA,CAAAA,GAAAA;AACJ,oBAAA,MAAMC,WAAAA,GAAcC,IAAAA,CAAKf,IAAAA,CAAKgB,eAAe,EAAA,EAAI,SAAA,CAAA;AACjD,oBAAA,MAAMC,MAAAA,GAAS,MAAMC,EAAAA,CAAGC,UAAU,CAACL,WAAAA,CAAAA;AACnC,oBAAA,IAAI,CAACG,MAAAA,EAAQ;AACX,wBAAA,MAAMG,KAAAA,CAAM,sCAAA,CAAA;AACd,oBAAA;AAEA,oBAAA,MAAMC,UAAAA,GAAa,MAAMH,EAAAA,CAAGI,OAAO,CAACR,WAAAA,EAAa;wBAAES,aAAAA,EAAe;AAAK,qBAAA,CAAA;AACvE,oBAAA,MAAM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}
@@ -1 +1 @@
1
- {"version":3,"file":"content-type.js","sources":["../../src/plops/content-type.ts"],"sourcesContent":["import { join } from 'path';\nimport type { NodePlopAPI, ActionType } from 'plop';\nimport slugify from '@sindresorhus/slugify';\nimport fs from 'fs-extra';\nimport { strings } from '@strapi/utils';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport ctNamesPrompts from './prompts/ct-names-prompts';\nimport kindPrompts from './prompts/kind-prompts';\nimport getAttributesPrompts from './prompts/get-attributes-prompts';\nimport bootstrapApiPrompts from './prompts/bootstrap-api-prompts';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // Model generator\n plop.setGenerator('content-type', {\n description: 'Generate a content type for an API',\n async prompts(inquirer) {\n const config = await inquirer.prompt([...ctNamesPrompts, ...kindPrompts]);\n const attributes = await getAttributesPrompts(inquirer);\n\n const api = await inquirer.prompt([\n ...getDestinationPrompts('model', plop.getDestBasePath()),\n {\n when: (answers) => answers.destination === 'new',\n type: 'input',\n name: 'id',\n default: config.singularName,\n message: 'Name of the new API?',\n async validate(input) {\n if (!strings.isKebabCase(input)) {\n return 'Value must be in kebab-case';\n }\n\n const apiPath = join(plop.getDestBasePath(), 'api');\n const exists = await fs.pathExists(apiPath);\n\n if (!exists) {\n return true;\n }\n\n const apiDir = await fs.readdir(apiPath, { withFileTypes: true });\n const apiDirContent = apiDir.filter((fd) => fd.isDirectory());\n\n if (apiDirContent.findIndex((dir) => dir.name === input) !== -1) {\n throw new Error('This name is already taken.');\n }\n\n return true;\n },\n },\n ...bootstrapApiPrompts,\n ]);\n\n return {\n ...config,\n ...api,\n attributes,\n };\n },\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const attributes = answers.attributes.reduce((object: any, answer: any) => {\n const val: any = { type: answer.attributeType };\n\n if (answer.attributeType === 'enumeration') {\n val.enum = answer.enum.split(',').map((item: string) => item.trim());\n }\n\n if (answer.attributeType === 'media') {\n val.allowedTypes = ['images', 'files', 'videos', 'audios'];\n val.multiple = answer.multiple;\n }\n\n return Object.assign(object, { [answer.attributeName]: val }, {});\n }, {});\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n templateFile: `templates/${language}/content-type.schema.json.hbs`,\n data: {\n collectionName: slugify(answers.pluralName, { separator: '_' }),\n },\n },\n ];\n\n if (Object.entries(attributes).length > 0) {\n baseActions.push({\n type: 'modify',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n transform(template: string) {\n const parsedTemplate = JSON.parse(template);\n parsedTemplate.attributes = attributes;\n return JSON.stringify(parsedTemplate, null, 2);\n },\n });\n }\n\n if (answers.plugin) {\n const indexPath = join(\n plop.getDestBasePath(),\n `${filePath}/content-types/index.${language}`\n );\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/content-types/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new content type to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/content-types/index.${language}`,\n transform(template: string) {\n return appendToFile(template, {\n type: 'content-type',\n singularName: answers.singularName,\n });\n },\n });\n }\n\n if (answers.bootstrapApi) {\n const { singularName } = answers;\n\n let uid;\n if (answers.destination === 'new') {\n uid = `api::${answers.id}.${singularName}`;\n } else if (answers.api) {\n uid = `api::${answers.api}.${singularName}`;\n } else if (answers.plugin) {\n uid = `plugin::${answers.plugin}.${singularName}`;\n }\n\n baseActions.push(\n {\n type: 'add',\n path: `${filePath}/controllers/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-controller.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/services/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-service.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/routes/${answers.plugin ? 'content-api/' : ''}{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-router.${language}.hbs`,\n data: { uid },\n }\n );\n\n if (answers.plugin) {\n const indexFiles = ['controllers', 'services', 'routes'];\n\n indexFiles.forEach((type) => {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists && type !== 'routes') {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n if (type === 'routes') {\n const indexPath = join(\n plop.getDestBasePath(),\n `${filePath}/${type}/index.${language}`\n );\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.routes.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n const routeIndexFiles = ['content-api', 'admin'];\n\n routeIndexFiles.forEach((routeType) => {\n const routeTypeIndexPath = join(\n plop.getDestBasePath(),\n `${filePath}/${type}/${routeType}/index.${language}`\n );\n const routeTypeExists = fs.existsSync(routeTypeIndexPath);\n\n if (!routeTypeExists) {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/${routeType}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.routes.type.index.${language}.hbs`,\n data: { type: routeType },\n skipIfExists: true,\n });\n }\n });\n }\n\n baseActions.push({\n type: 'modify',\n path: `${filePath}/${type}/${type === 'routes' ? 'content-api/' : ''}index.${language}`,\n transform(template: string) {\n if (type === 'routes') {\n return appendToFile(template, {\n type: 'routes',\n singularName: answers.singularName,\n });\n }\n\n return appendToFile(template, {\n type: 'index',\n singularName: answers.singularName,\n });\n },\n });\n });\n }\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","inquirer","config","prompt","ctNamesPrompts","kindPrompts","attributes","getAttributesPrompts","api","getDestinationPrompts","getDestBasePath","when","answers","destination","type","name","default","singularName","message","validate","input","strings","isKebabCase","apiPath","join","exists","fs","pathExists","apiDir","readdir","withFileTypes","apiDirContent","filter","fd","isDirectory","findIndex","dir","Error","bootstrapApiPrompts","actions","reduce","object","answer","val","attributeType","enum","split","map","item","trim","allowedTypes","multiple","Object","assign","attributeName","filePath","getFilePath","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","replace","baseActions","path","templateFile","data","collectionName","slugify","pluralName","separator","entries","length","push","transform","template","parsedTemplate","JSON","parse","stringify","indexPath","existsSync","skipIfExists","appendToFile","bootstrapApi","uid","id","indexFiles","forEach","routeIndexFiles","routeType","routeTypeIndexPath","routeTypeExists"],"mappings":";;;;;;;;;;;;;;;AAeA,0BAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,cAAgB,EAAA;QAChCC,WAAa,EAAA,oCAAA;AACb,QAAA,MAAMC,SAAQC,QAAQ,EAAA;AACpB,YAAA,MAAMC,MAAS,GAAA,MAAMD,QAASE,CAAAA,MAAM,CAAC;AAAIC,gBAAAA,GAAAA,cAAAA;AAAmBC,gBAAAA,GAAAA;AAAY,aAAA,CAAA;YACxE,MAAMC,UAAAA,GAAa,MAAMC,oBAAqBN,CAAAA,QAAAA,CAAAA;AAE9C,YAAA,MAAMO,GAAM,GAAA,MAAMP,QAASE,CAAAA,MAAM,CAAC;mBAC7BM,qBAAsB,CAAA,OAAA,EAASZ,KA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EAAA;AACrB,oCAAA,OAAOwE,oCAAaR,QAAU,EAAA;wCAC5BhE,IAAM,EAAA,QAAA;AACNG,wCAAAA,YAAAA,EAAcL,QAAQK;AACxB,qCAAA,CAAA;AACF;AAEA,gCAAA,OAAOqE,oCAAaR,QAAU,EAAA;oCAC5BhE,IAAM,EAAA,OAAA;AACNG,oCAAAA,YAAAA,EAAcL,QAAQK;AACxB,iCAAA,CAAA;AACF;AACF,yBAAA,CAAA;AACF,qBAAA,CAAA;AACF;AACF;YAEA,OAAOiD,WAAAA;AACT;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"content-type.js","sources":["../../src/plops/content-type.ts"],"sourcesContent":["import { join } from 'path';\nimport type { NodePlopAPI, ActionType } from 'plop';\nimport slugify from '@sindresorhus/slugify';\nimport fs from 'fs-extra';\nimport { strings } from '@strapi/utils';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport ctNamesPrompts from './prompts/ct-names-prompts';\nimport kindPrompts from './prompts/kind-prompts';\nimport getAttributesPrompts from './prompts/get-attributes-prompts';\nimport bootstrapApiPrompts from './prompts/bootstrap-api-prompts';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // Model generator\n plop.setGenerator('content-type', {\n description: 'Generate a content type for an API',\n async prompts(inquirer) {\n const config = await inquirer.prompt([...ctNamesPrompts, ...kindPrompts]);\n const attributes = await getAttributesPrompts(inquirer);\n\n const api = await inquirer.prompt([\n ...getDestinationPrompts('model', plop.getDestBasePath()),\n {\n when: (answers) => answers.destination === 'new',\n type: 'input',\n name: 'id',\n default: config.singularName,\n message: 'Name of the new API?',\n async validate(input) {\n if (!strings.isKebabCase(input)) {\n return 'Value must be in kebab-case';\n }\n\n const apiPath = join(plop.getDestBasePath(), 'api');\n const exists = await fs.pathExists(apiPath);\n\n if (!exists) {\n return true;\n }\n\n const apiDir = await fs.readdir(apiPath, { withFileTypes: true });\n const apiDirContent = apiDir.filter((fd) => fd.isDirectory());\n\n if (apiDirContent.findIndex((dir) => dir.name === input) !== -1) {\n throw new Error('This name is already taken.');\n }\n\n return true;\n },\n },\n ...bootstrapApiPrompts,\n ]);\n\n return {\n ...config,\n ...api,\n attributes,\n };\n },\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const attributes = answers.attributes.reduce((object: any, answer: any) => {\n const val: any = { type: answer.attributeType };\n\n if (answer.attributeType === 'enumeration') {\n val.enum = answer.enum.split(',').map((item: string) => item.trim());\n }\n\n if (answer.attributeType === 'media') {\n val.allowedTypes = ['images', 'files', 'videos', 'audios'];\n val.multiple = answer.multiple;\n }\n\n return Object.assign(object, { [answer.attributeName]: val }, {});\n }, {});\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n templateFile: `templates/${language}/content-type.schema.json.hbs`,\n data: {\n collectionName: slugify(answers.pluralName, { separator: '_' }),\n },\n },\n ];\n\n if (Object.entries(attributes).length > 0) {\n baseActions.push({\n type: 'modify',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n transform(template: string) {\n const parsedTemplate = JSON.parse(template);\n parsedTemplate.attributes = attributes;\n return JSON.stringify(parsedTemplate, null, 2);\n },\n });\n }\n\n if (answers.plugin) {\n const indexPath = join(\n plop.getDestBasePath(),\n `${filePath}/content-types/index.${language}`\n );\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/content-types/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new content type to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/content-types/index.${language}`,\n transform(template: string) {\n return appendToFile(template, {\n type: 'content-type',\n singularName: answers.singularName,\n });\n },\n });\n }\n\n if (answers.bootstrapApi) {\n const { singularName } = answers;\n\n let uid;\n if (answers.destination === 'new') {\n uid = `api::${answers.id}.${singularName}`;\n } else if (answers.api) {\n uid = `api::${answers.api}.${singularName}`;\n } else if (answers.plugin) {\n uid = `plugin::${answers.plugin}.${singularName}`;\n }\n\n baseActions.push(\n {\n type: 'add',\n path: `${filePath}/controllers/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-controller.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/services/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-service.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/routes/${answers.plugin ? 'content-api/' : ''}{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-router.${language}.hbs`,\n data: { uid },\n }\n );\n\n if (answers.plugin) {\n const indexFiles = ['controllers', 'services', 'routes'];\n\n indexFiles.forEach((type) => {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists && type !== 'routes') {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n if (type === 'routes') {\n const indexPath = join(\n plop.getDestBasePath(),\n `${filePath}/${type}/index.${language}`\n );\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.routes.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n const routeIndexFiles = ['content-api', 'admin'];\n\n routeIndexFiles.forEach((routeType) => {\n const routeTypeIndexPath = join(\n plop.getDestBasePath(),\n `${filePath}/${type}/${routeType}/index.${language}`\n );\n const routeTypeExists = fs.existsSync(routeTypeIndexPath);\n\n if (!routeTypeExists) {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/${routeType}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.routes.type.index.${language}.hbs`,\n data: { type: routeType },\n skipIfExists: true,\n });\n }\n });\n }\n\n baseActions.push({\n type: 'modify',\n path: `${filePath}/${type}/${type === 'routes' ? 'content-api/' : ''}index.${language}`,\n transform(template: string) {\n if (type === 'routes') {\n return appendToFile(template, {\n type: 'routes',\n singularName: answers.singularName,\n });\n }\n\n return appendToFile(template, {\n type: 'index',\n singularName: answers.singularName,\n });\n },\n });\n });\n }\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","inquirer","config","prompt","ctNamesPrompts","kindPrompts","attributes","getAttributesPrompts","api","getDestinationPrompts","getDestBasePath","when","answers","destination","type","name","default","singularName","message","validate","input","strings","isKebabCase","apiPath","join","exists","fs","pathExists","apiDir","readdir","withFileTypes","apiDirContent","filter","fd","isDirectory","findIndex","dir","Error","bootstrapApiPrompts","actions","reduce","object","answer","val","attributeType","enum","split","map","item","trim","allowedTypes","multiple","Object","assign","attributeName","filePath","getFilePath","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","replace","baseActions","path","templateFile","data","collectionName","slugify","pluralName","separator","entries","length","push","transform","template","parsedTemplate","JSON","parse","stringify","indexPath","existsSync","skipIfExists","appendToFile","bootstrapApi","uid","id","indexFiles","forEach","routeIndexFiles","routeType","routeTypeIndexPath","routeTypeExists"],"mappings":";;;;;;;;;;;;;;;AAeA,0BAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAAA,CAAKC,YAAY,CAAC,cAAA,EAAgB;QAChCC,WAA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CAAU,OAAO,EAAEjC,QAAAA,CAAAA,CAAU;wCAC1DQ,YAAAA,EAAc,CAAC,UAAU,EAAER,QAAAA,CAAS,iCAAiC,EAAEA,QAAAA,CAAS,IAAI,CAAC;wCACrFS,IAAAA,EAAM;4CAAEvD,IAAAA,EAAM+E;AAAU,yCAAA;wCACxBR,YAAAA,EAAc;AAChB,qCAAA,CAAA;AACF,gCAAA;AACF,4BAAA,CAAA,CAAA;AACF,wBAAA;AAEAnB,wBAAAA,WAAAA,CAAYU,IAAI,CAAC;4BACf9D,IAAAA,EAAM,QAAA;AACNqD,4BAAAA,IAAAA,EAAM,CAAA,EAAGZ,QAAAA,CAAS,CAAC,EAAEzC,IAAAA,CAAK,CAAC,EAAEA,IAAAA,KAAS,QAAA,GAAW,cAAA,GAAiB,EAAA,CAAG,MAAM,EAAE8C,QAAAA,CAAAA,CAAU;AACvFiB,4BAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,gCAAA,IAAIhE,SAAS,QAAA,EAAU;AACrB,oCAAA,OAAOwE,oCAAaR,QAAAA,EAAU;wCAC5BhE,IAAAA,EAAM,QAAA;AACNG,wCAAAA,YAAAA,EAAcL,QAAQK;AACxB,qCAAA,CAAA;AACF,gCAAA;AAEA,gCAAA,OAAOqE,oCAAaR,QAAAA,EAAU;oCAC5BhE,IAAAA,EAAM,OAAA;AACNG,oCAAAA,YAAAA,EAAcL,QAAQK;AACxB,iCAAA,CAAA;AACF,4BAAA;AACF,yBAAA,CAAA;AACF,oBAAA,CAAA,CAAA;AACF,gBAAA;AACF,YAAA;YAEA,OAAOiD,WAAAA;AACT,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"content-type.mjs","sources":["../../src/plops/content-type.ts"],"sourcesContent":["import { join } from 'path';\nimport type { NodePlopAPI, ActionType } from 'plop';\nimport slugify from '@sindresorhus/slugify';\nimport fs from 'fs-extra';\nimport { strings } from '@strapi/utils';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport ctNamesPrompts from './prompts/ct-names-prompts';\nimport kindPrompts from './prompts/kind-prompts';\nimport getAttributesPrompts from './prompts/get-attributes-prompts';\nimport bootstrapApiPrompts from './prompts/bootstrap-api-prompts';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // Model generator\n plop.setGenerator('content-type', {\n description: 'Generate a content type for an API',\n async prompts(inquirer) {\n const config = await inquirer.prompt([...ctNamesPrompts, ...kindPrompts]);\n const attributes = await getAttributesPrompts(inquirer);\n\n const api = await inquirer.prompt([\n ...getDestinationPrompts('model', plop.getDestBasePath()),\n {\n when: (answers) => answers.destination === 'new',\n type: 'input',\n name: 'id',\n default: config.singularName,\n message: 'Name of the new API?',\n async validate(input) {\n if (!strings.isKebabCase(input)) {\n return 'Value must be in kebab-case';\n }\n\n const apiPath = join(plop.getDestBasePath(), 'api');\n const exists = await fs.pathExists(apiPath);\n\n if (!exists) {\n return true;\n }\n\n const apiDir = await fs.readdir(apiPath, { withFileTypes: true });\n const apiDirContent = apiDir.filter((fd) => fd.isDirectory());\n\n if (apiDirContent.findIndex((dir) => dir.name === input) !== -1) {\n throw new Error('This name is already taken.');\n }\n\n return true;\n },\n },\n ...bootstrapApiPrompts,\n ]);\n\n return {\n ...config,\n ...api,\n attributes,\n };\n },\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const attributes = answers.attributes.reduce((object: any, answer: any) => {\n const val: any = { type: answer.attributeType };\n\n if (answer.attributeType === 'enumeration') {\n val.enum = answer.enum.split(',').map((item: string) => item.trim());\n }\n\n if (answer.attributeType === 'media') {\n val.allowedTypes = ['images', 'files', 'videos', 'audios'];\n val.multiple = answer.multiple;\n }\n\n return Object.assign(object, { [answer.attributeName]: val }, {});\n }, {});\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n templateFile: `templates/${language}/content-type.schema.json.hbs`,\n data: {\n collectionName: slugify(answers.pluralName, { separator: '_' }),\n },\n },\n ];\n\n if (Object.entries(attributes).length > 0) {\n baseActions.push({\n type: 'modify',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n transform(template: string) {\n const parsedTemplate = JSON.parse(template);\n parsedTemplate.attributes = attributes;\n return JSON.stringify(parsedTemplate, null, 2);\n },\n });\n }\n\n if (answers.plugin) {\n const indexPath = join(\n plop.getDestBasePath(),\n `${filePath}/content-types/index.${language}`\n );\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/content-types/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new content type to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/content-types/index.${language}`,\n transform(template: string) {\n return appendToFile(template, {\n type: 'content-type',\n singularName: answers.singularName,\n });\n },\n });\n }\n\n if (answers.bootstrapApi) {\n const { singularName } = answers;\n\n let uid;\n if (answers.destination === 'new') {\n uid = `api::${answers.id}.${singularName}`;\n } else if (answers.api) {\n uid = `api::${answers.api}.${singularName}`;\n } else if (answers.plugin) {\n uid = `plugin::${answers.plugin}.${singularName}`;\n }\n\n baseActions.push(\n {\n type: 'add',\n path: `${filePath}/controllers/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-controller.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/services/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-service.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/routes/${answers.plugin ? 'content-api/' : ''}{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-router.${language}.hbs`,\n data: { uid },\n }\n );\n\n if (answers.plugin) {\n const indexFiles = ['controllers', 'services', 'routes'];\n\n indexFiles.forEach((type) => {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists && type !== 'routes') {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n if (type === 'routes') {\n const indexPath = join(\n plop.getDestBasePath(),\n `${filePath}/${type}/index.${language}`\n );\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.routes.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n const routeIndexFiles = ['content-api', 'admin'];\n\n routeIndexFiles.forEach((routeType) => {\n const routeTypeIndexPath = join(\n plop.getDestBasePath(),\n `${filePath}/${type}/${routeType}/index.${language}`\n );\n const routeTypeExists = fs.existsSync(routeTypeIndexPath);\n\n if (!routeTypeExists) {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/${routeType}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.routes.type.index.${language}.hbs`,\n data: { type: routeType },\n skipIfExists: true,\n });\n }\n });\n }\n\n baseActions.push({\n type: 'modify',\n path: `${filePath}/${type}/${type === 'routes' ? 'content-api/' : ''}index.${language}`,\n transform(template: string) {\n if (type === 'routes') {\n return appendToFile(template, {\n type: 'routes',\n singularName: answers.singularName,\n });\n }\n\n return appendToFile(template, {\n type: 'index',\n singularName: answers.singularName,\n });\n },\n });\n });\n }\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","inquirer","config","prompt","ctNamesPrompts","kindPrompts","attributes","getAttributesPrompts","api","getDestinationPrompts","getDestBasePath","when","answers","destination","type","name","default","singularName","message","validate","input","strings","isKebabCase","apiPath","join","exists","fs","pathExists","apiDir","readdir","withFileTypes","apiDirContent","filter","fd","isDirectory","findIndex","dir","Error","bootstrapApiPrompts","actions","reduce","object","answer","val","attributeType","enum","split","map","item","trim","allowedTypes","multiple","Object","assign","attributeName","filePath","getFilePath","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","replace","baseActions","path","templateFile","data","collectionName","slugify","pluralName","separator","entries","length","push","transform","template","parsedTemplate","JSON","parse","stringify","indexPath","existsSync","skipIfExists","appendToFile","bootstrapApi","uid","id","indexFiles","forEach","routeIndexFiles","routeType","routeTypeIndexPath","routeTypeExists"],"mappings":";;;;;;;;;;;;;AAeA,0BAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,cAAgB,EAAA;QAChCC,WAAa,EAAA,oCAAA;AACb,QAAA,MAAMC,SAAQC,QAAQ,EAAA;AACpB,YAAA,MAAMC,MAAS,GAAA,MAAMD,QAASE,CAAAA,MAAM,CAAC;AAAIC,gBAAAA,GAAAA,SAAAA;AAAmBC,gBAAAA,GAAAA;AAAY,aAAA,CAAA;YACxE,MAAMC,UAAAA,GAAa,MAAMC,oBAAqBN,CAAAA,QAAAA,CAAAA;AAE9C,YAAA,MAAMO,GAAM,GAAA,MAAMP,QAASE,CAAAA,MAAM,CAAC;mBAC7BM,qBAAsB,CAAA,OAAA,EAASZ,KAAKa,eAAe,EAAA,CAAA;AACtD,gBAAA;AACEC,oBAAAA,IAAAA,EAAM,CAACC,OAAAA,GAAYA,OAAQC,CAAAA,WAAW,KAAK,KAAA;oBAC3CC,IAAM,EAAA,OAAA;oBACNC,IAAM,EAAA,IAAA;AACNC,oBAAAA,OAAA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AM,EAAA,OAAA;AACNG,oCAAAA,YAAAA,EAAcL,QAAQK;AACxB,iCAAA,CAAA;AACF;AACF,yBAAA,CAAA;AACF,qBAAA,CAAA;AACF;AACF;YAEA,OAAOiD,WAAAA;AACT;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"content-type.mjs","sources":["../../src/plops/content-type.ts"],"sourcesContent":["import { join } from 'path';\nimport type { NodePlopAPI, ActionType } from 'plop';\nimport slugify from '@sindresorhus/slugify';\nimport fs from 'fs-extra';\nimport { strings } from '@strapi/utils';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport ctNamesPrompts from './prompts/ct-names-prompts';\nimport kindPrompts from './prompts/kind-prompts';\nimport getAttributesPrompts from './prompts/get-attributes-prompts';\nimport bootstrapApiPrompts from './prompts/bootstrap-api-prompts';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // Model generator\n plop.setGenerator('content-type', {\n description: 'Generate a content type for an API',\n async prompts(inquirer) {\n const config = await inquirer.prompt([...ctNamesPrompts, ...kindPrompts]);\n const attributes = await getAttributesPrompts(inquirer);\n\n const api = await inquirer.prompt([\n ...getDestinationPrompts('model', plop.getDestBasePath()),\n {\n when: (answers) => answers.destination === 'new',\n type: 'input',\n name: 'id',\n default: config.singularName,\n message: 'Name of the new API?',\n async validate(input) {\n if (!strings.isKebabCase(input)) {\n return 'Value must be in kebab-case';\n }\n\n const apiPath = join(plop.getDestBasePath(), 'api');\n const exists = await fs.pathExists(apiPath);\n\n if (!exists) {\n return true;\n }\n\n const apiDir = await fs.readdir(apiPath, { withFileTypes: true });\n const apiDirContent = apiDir.filter((fd) => fd.isDirectory());\n\n if (apiDirContent.findIndex((dir) => dir.name === input) !== -1) {\n throw new Error('This name is already taken.');\n }\n\n return true;\n },\n },\n ...bootstrapApiPrompts,\n ]);\n\n return {\n ...config,\n ...api,\n attributes,\n };\n },\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const attributes = answers.attributes.reduce((object: any, answer: any) => {\n const val: any = { type: answer.attributeType };\n\n if (answer.attributeType === 'enumeration') {\n val.enum = answer.enum.split(',').map((item: string) => item.trim());\n }\n\n if (answer.attributeType === 'media') {\n val.allowedTypes = ['images', 'files', 'videos', 'audios'];\n val.multiple = answer.multiple;\n }\n\n return Object.assign(object, { [answer.attributeName]: val }, {});\n }, {});\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n templateFile: `templates/${language}/content-type.schema.json.hbs`,\n data: {\n collectionName: slugify(answers.pluralName, { separator: '_' }),\n },\n },\n ];\n\n if (Object.entries(attributes).length > 0) {\n baseActions.push({\n type: 'modify',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n transform(template: string) {\n const parsedTemplate = JSON.parse(template);\n parsedTemplate.attributes = attributes;\n return JSON.stringify(parsedTemplate, null, 2);\n },\n });\n }\n\n if (answers.plugin) {\n const indexPath = join(\n plop.getDestBasePath(),\n `${filePath}/content-types/index.${language}`\n );\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/content-types/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new content type to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/content-types/index.${language}`,\n transform(template: string) {\n return appendToFile(template, {\n type: 'content-type',\n singularName: answers.singularName,\n });\n },\n });\n }\n\n if (answers.bootstrapApi) {\n const { singularName } = answers;\n\n let uid;\n if (answers.destination === 'new') {\n uid = `api::${answers.id}.${singularName}`;\n } else if (answers.api) {\n uid = `api::${answers.api}.${singularName}`;\n } else if (answers.plugin) {\n uid = `plugin::${answers.plugin}.${singularName}`;\n }\n\n baseActions.push(\n {\n type: 'add',\n path: `${filePath}/controllers/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-controller.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/services/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-service.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/routes/${answers.plugin ? 'content-api/' : ''}{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-router.${language}.hbs`,\n data: { uid },\n }\n );\n\n if (answers.plugin) {\n const indexFiles = ['controllers', 'services', 'routes'];\n\n indexFiles.forEach((type) => {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists && type !== 'routes') {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n if (type === 'routes') {\n const indexPath = join(\n plop.getDestBasePath(),\n `${filePath}/${type}/index.${language}`\n );\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.routes.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n const routeIndexFiles = ['content-api', 'admin'];\n\n routeIndexFiles.forEach((routeType) => {\n const routeTypeIndexPath = join(\n plop.getDestBasePath(),\n `${filePath}/${type}/${routeType}/index.${language}`\n );\n const routeTypeExists = fs.existsSync(routeTypeIndexPath);\n\n if (!routeTypeExists) {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/${routeType}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.routes.type.index.${language}.hbs`,\n data: { type: routeType },\n skipIfExists: true,\n });\n }\n });\n }\n\n baseActions.push({\n type: 'modify',\n path: `${filePath}/${type}/${type === 'routes' ? 'content-api/' : ''}index.${language}`,\n transform(template: string) {\n if (type === 'routes') {\n return appendToFile(template, {\n type: 'routes',\n singularName: answers.singularName,\n });\n }\n\n return appendToFile(template, {\n type: 'index',\n singularName: answers.singularName,\n });\n },\n });\n });\n }\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","inquirer","config","prompt","ctNamesPrompts","kindPrompts","attributes","getAttributesPrompts","api","getDestinationPrompts","getDestBasePath","when","answers","destination","type","name","default","singularName","message","validate","input","strings","isKebabCase","apiPath","join","exists","fs","pathExists","apiDir","readdir","withFileTypes","apiDirContent","filter","fd","isDirectory","findIndex","dir","Error","bootstrapApiPrompts","actions","reduce","object","answer","val","attributeType","enum","split","map","item","trim","allowedTypes","multiple","Object","assign","attributeName","filePath","getFilePath","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","replace","baseActions","path","templateFile","data","collectionName","slugify","pluralName","separator","entries","length","push","transform","template","parsedTemplate","JSON","parse","stringify","indexPath","existsSync","skipIfExists","appendToFile","bootstrapApi","uid","id","indexFiles","forEach","routeIndexFiles","routeType","routeTypeIndexPath","routeTypeExists"],"mappings":";;;;;;;;;;;;;AAeA,0BAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAAA,CAAKC,YAAY,CAAC,cAAA,EAAgB;QAChCC,WAAAA,EAAa,oCAAA;AACb,QAAA,MAAMC,SAAQC,QAAQ,EAAA;AACpB,YAAA,MAAMC,MAAAA,GAAS,MAAMD,QAAAA,CAASE,MAAM,CAAC;AAAIC,gBAAAA,GAAAA,SAAAA;AAAmBC,gBAAAA,GAAAA;AAAY,aAAA,CAAA;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AA;wCACxBR,YAAAA,EAAc;AAChB,qCAAA,CAAA;AACF,gCAAA;AACF,4BAAA,CAAA,CAAA;AACF,wBAAA;AAEAnB,wBAAAA,WAAAA,CAAYU,IAAI,CAAC;4BACf9D,IAAAA,EAAM,QAAA;AACNqD,4BAAAA,IAAAA,EAAM,CAAA,EAAGZ,QAAAA,CAAS,CAAC,EAAEzC,IAAAA,CAAK,CAAC,EAAEA,IAAAA,KAAS,QAAA,GAAW,cAAA,GAAiB,EAAA,CAAG,MAAM,EAAE8C,QAAAA,CAAAA,CAAU;AACvFiB,4BAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,gCAAA,IAAIhE,SAAS,QAAA,EAAU;AACrB,oCAAA,OAAOwE,aAAaR,QAAAA,EAAU;wCAC5BhE,IAAAA,EAAM,QAAA;AACNG,wCAAAA,YAAAA,EAAcL,QAAQK;AACxB,qCAAA,CAAA;AACF,gCAAA;AAEA,gCAAA,OAAOqE,aAAaR,QAAAA,EAAU;oCAC5BhE,IAAAA,EAAM,OAAA;AACNG,oCAAAA,YAAAA,EAAcL,QAAQK;AACxB,iCAAA,CAAA;AACF,4BAAA;AACF,yBAAA,CAAA;AACF,oBAAA,CAAA,CAAA;AACF,gBAAA;AACF,YAAA;YAEA,OAAOiD,WAAAA;AACT,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"controller.js","sources":["../../src/plops/controller.ts"],"sourcesContent":["import type { ActionType, NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport { join } from 'path';\nimport fs from 'fs';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport validateInput from './utils/validate-input';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // Controller generator\n plop.setGenerator('controller', {\n description: 'Generate a controller for an API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'Controller name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('controller', plop.getDestBasePath()),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/controllers/{{ id }}.${language}`,\n templateFile: `templates/${language}/controller.${language}.hbs`,\n },\n ];\n\n if (answers.plugin) {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/controllers/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/controllers/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new controller to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/controllers/index.${language}`,\n transform(template: string) {\n return appendToFile(template, { type: 'index', singularName: answers.id });\n },\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","getDestinationPrompts","getDestBasePath","actions","answers","filePath","getFilePath","destination","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","join","replace","baseActions","path","templateFile","indexPath","exists","fs","existsSync","push","skipIfExists","transform","template","appendToFile","singularName","id"],"mappings":";;;;;;;;;;AAUA,yBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,YAAc,EAAA;QAC9BC,WAAa,EAAA,kCAAA;QACbC,OAAS,EAAA;AACP,YAAA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AEM,QAAU,CAAA,CAAA,CAAA;gBAC1F,MAAMW,MAAAA,GAASC,EAAGC,CAAAA,UAAU,CAACH,SAAAA,CAAAA;AAE7B,gBAAA,IAAI,CAACC,MAAQ,EAAA;;AAEXJ,oBAAAA,WAAAA,CAAYO,IAAI,CAAC;wBACf9B,IAAM,EAAA,KAAA;AACNwB,wBAAAA,IAAAA,EAAM,CAAGd,EAAAA,QAAAA,CAAS,mBAAmB,EAAEM,QAAU,CAAA,CAAA;wBACjDS,YAAc,EAAA,CAAC,UAAU,EAAET,QAAAA,CAAS,qBAAqB,EAAEA,QAAAA,CAAS,IAAI,CAAC;wBACzEe,YAAc,EAAA;AAChB,qBAAA,CAAA;AACF;;AAGAR,gBAAAA,WAAAA,CAAYO,IAAI,CAAC;oBACf9B,IAAM,EAAA,QAAA;AACNwB,oBAAAA,IAAAA,EAAM,CAAGd,EAAAA,QAAAA,CAAS,mBAAmB,EAAEM,QAAU,CAAA,CAAA;AACjDgB,oBAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,wBAAA,OAAOC,oCAAaD,QAAU,EAAA;4BAAEjC,IAAM,EAAA,OAAA;AAASmC,4BAAAA,YAAAA,EAAc1B,QAAQ2B;AAAG,yBAAA,CAAA;AAC1E;AACF,iBAAA,CAAA;AACF;YAEA,OAAOb,WAAAA;AACT;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"controller.js","sources":["../../src/plops/controller.ts"],"sourcesContent":["import type { ActionType, NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport { join } from 'path';\nimport fs from 'fs';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport validateInput from './utils/validate-input';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // Controller generator\n plop.setGenerator('controller', {\n description: 'Generate a controller for an API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'Controller name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('controller', plop.getDestBasePath()),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/controllers/{{ id }}.${language}`,\n templateFile: `templates/${language}/controller.${language}.hbs`,\n },\n ];\n\n if (answers.plugin) {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/controllers/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/controllers/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new controller to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/controllers/index.${language}`,\n transform(template: string) {\n return appendToFile(template, { type: 'index', singularName: answers.id });\n },\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","getDestinationPrompts","getDestBasePath","actions","answers","filePath","getFilePath","destination","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","join","replace","baseActions","path","templateFile","indexPath","exists","fs","existsSync","push","skipIfExists","transform","template","appendToFile","singularName","id"],"mappings":";;;;;;;;;;AAUA,yBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAAA,CAAKC,YAAY,CAAC,YAAA,EAAc;QAC9BC,WAAAA,EAAa,kCAAA;QACbC,OAAAA,EAAS;AAC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AGG,QAAAA,CAAS,mBAAmB,EAAEM,QAAAA,CAAAA,CAAU,CAAA;gBAC1F,MAAMW,MAAAA,GAASC,EAAAA,CAAGC,UAAU,CAACH,SAAAA,CAAAA;AAE7B,gBAAA,IAAI,CAACC,MAAAA,EAAQ;;AAEXJ,oBAAAA,WAAAA,CAAYO,IAAI,CAAC;wBACf9B,IAAAA,EAAM,KAAA;AACNwB,wBAAAA,IAAAA,EAAM,CAAA,EAAGd,QAAAA,CAAS,mBAAmB,EAAEM,QAAAA,CAAAA,CAAU;wBACjDS,YAAAA,EAAc,CAAC,UAAU,EAAET,QAAAA,CAAS,qBAAqB,EAAEA,QAAAA,CAAS,IAAI,CAAC;wBACzEe,YAAAA,EAAc;AAChB,qBAAA,CAAA;AACF,gBAAA;;AAGAR,gBAAAA,WAAAA,CAAYO,IAAI,CAAC;oBACf9B,IAAAA,EAAM,QAAA;AACNwB,oBAAAA,IAAAA,EAAM,CAAA,EAAGd,QAAAA,CAAS,mBAAmB,EAAEM,QAAAA,CAAAA,CAAU;AACjDgB,oBAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,wBAAA,OAAOC,oCAAaD,QAAAA,EAAU;4BAAEjC,IAAAA,EAAM,OAAA;AAASmC,4BAAAA,YAAAA,EAAc1B,QAAQ2B;AAAG,yBAAA,CAAA;AAC1E,oBAAA;AACF,iBAAA,CAAA;AACF,YAAA;YAEA,OAAOb,WAAAA;AACT,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"controller.mjs","sources":["../../src/plops/controller.ts"],"sourcesContent":["import type { ActionType, NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport { join } from 'path';\nimport fs from 'fs';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport validateInput from './utils/validate-input';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // Controller generator\n plop.setGenerator('controller', {\n description: 'Generate a controller for an API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'Controller name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('controller', plop.getDestBasePath()),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/controllers/{{ id }}.${language}`,\n templateFile: `templates/${language}/controller.${language}.hbs`,\n },\n ];\n\n if (answers.plugin) {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/controllers/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/controllers/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new controller to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/controllers/index.${language}`,\n transform(template: string) {\n return appendToFile(template, { type: 'index', singularName: answers.id });\n },\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","getDestinationPrompts","getDestBasePath","actions","answers","filePath","getFilePath","destination","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","join","replace","baseActions","path","templateFile","indexPath","exists","fs","existsSync","push","skipIfExists","transform","template","appendToFile","singularName","id"],"mappings":";;;;;;;;AAUA,yBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,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AAAA,GAAYL,KAAKzB,IAAKW,CAAAA,eAAe,IAAI,CAAGG,EAAAA,QAAAA,CAAS,mBAAmB,EAAEM,QAAU,CAAA,CAAA,CAAA;gBAC1F,MAAMW,MAAAA,GAASC,EAAGC,CAAAA,UAAU,CAACH,SAAAA,CAAAA;AAE7B,gBAAA,IAAI,CAACC,MAAQ,EAAA;;AAEXJ,oBAAAA,WAAAA,CAAYO,IAAI,CAAC;wBACf9B,IAAM,EAAA,KAAA;AACNwB,wBAAAA,IAAAA,EAAM,CAAGd,EAAAA,QAAAA,CAAS,mBAAmB,EAAEM,QAAU,CAAA,CAAA;wBACjDS,YAAc,EAAA,CAAC,UAAU,EAAET,QAAAA,CAAS,qBAAqB,EAAEA,QAAAA,CAAS,IAAI,CAAC;wBACzEe,YAAc,EAAA;AAChB,qBAAA,CAAA;AACF;;AAGAR,gBAAAA,WAAAA,CAAYO,IAAI,CAAC;oBACf9B,IAAM,EAAA,QAAA;AACNwB,oBAAAA,IAAAA,EAAM,CAAGd,EAAAA,QAAAA,CAAS,mBAAmB,EAAEM,QAAU,CAAA,CAAA;AACjDgB,oBAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,wBAAA,OAAOC,aAAaD,QAAU,EAAA;4BAAEjC,IAAM,EAAA,OAAA;AAASmC,4BAAAA,YAAAA,EAAc1B,QAAQ2B;AAAG,yBAAA,CAAA;AAC1E;AACF,iBAAA,CAAA;AACF;YAEA,OAAOb,WAAAA;AACT;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"controller.mjs","sources":["../../src/plops/controller.ts"],"sourcesContent":["import type { ActionType, NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport { join } from 'path';\nimport fs from 'fs';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport validateInput from './utils/validate-input';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // Controller generator\n plop.setGenerator('controller', {\n description: 'Generate a controller for an API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'Controller name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('controller', plop.getDestBasePath()),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/controllers/{{ id }}.${language}`,\n templateFile: `templates/${language}/controller.${language}.hbs`,\n },\n ];\n\n if (answers.plugin) {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/controllers/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/controllers/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new controller to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/controllers/index.${language}`,\n transform(template: string) {\n return appendToFile(template, { type: 'index', singularName: answers.id });\n },\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","getDestinationPrompts","getDestBasePath","actions","answers","filePath","getFilePath","destination","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","join","replace","baseActions","path","templateFile","indexPath","exists","fs","existsSync","push","skipIfExists","transform","template","appendToFile","singularName","id"],"mappings":";;;;;;;;AAUA,yBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAA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,MAAM,EAAE;gBAClB,MAAMO,SAAAA,GAAYL,KAAKzB,IAAAA,CAAKW,eAAe,IAAI,CAAA,EAAGG,QAAAA,CAAS,mBAAmB,EAAEM,QAAAA,CAAAA,CAAU,CAAA;gBAC1F,MAAMW,MAAAA,GAASC,EAAAA,CAAGC,UAAU,CAACH,SAAAA,CAAAA;AAE7B,gBAAA,IAAI,CAACC,MAAAA,EAAQ;;AAEXJ,oBAAAA,WAAAA,CAAYO,IAAI,CAAC;wBACf9B,IAAAA,EAAM,KAAA;AACNwB,wBAAAA,IAAAA,EAAM,CAAA,EAAGd,QAAAA,CAAS,mBAAmB,EAAEM,QAAAA,CAAAA,CAAU;wBACjDS,YAAAA,EAAc,CAAC,UAAU,EAAET,QAAAA,CAAS,qBAAqB,EAAEA,QAAAA,CAAS,IAAI,CAAC;wBACzEe,YAAAA,EAAc;AAChB,qBAAA,CAAA;AACF,gBAAA;;AAGAR,gBAAAA,WAAAA,CAAYO,IAAI,CAAC;oBACf9B,IAAAA,EAAM,QAAA;AACNwB,oBAAAA,IAAAA,EAAM,CAAA,EAAGd,QAAAA,CAAS,mBAAmB,EAAEM,QAAAA,CAAAA,CAAU;AACjDgB,oBAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,wBAAA,OAAOC,aAAaD,QAAAA,EAAU;4BAAEjC,IAAAA,EAAM,OAAA;AAASmC,4BAAAA,YAAAA,EAAc1B,QAAQ2B;AAAG,yBAAA,CAAA;AAC1E,oBAAA;AACF,iBAAA,CAAA;AACF,YAAA;YAEA,OAAOb,WAAAA;AACT,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.js","sources":["../../src/plops/middleware.ts"],"sourcesContent":["import type { ActionType, NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport { join } from 'path';\nimport fs from 'fs';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport validateInput from './utils/validate-input';\nimport getFilePath from './utils/get-file-path';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // middleware generator\n plop.setGenerator('middleware', {\n description: 'Generate a middleware for an API',\n prompts: [\n {\n type: 'input',\n name: 'name',\n message: 'Middleware name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('middleware', plop.getDestBasePath(), { rootFolder: true }),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/middlewares/{{ name }}.${language}`,\n templateFile: `templates/${language}/middleware.${language}.hbs`,\n },\n ];\n\n if (answers.plugin) {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/middlewares/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/middlewares/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new middleware to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/middlewares/index.${language}`,\n transform(template: string) {\n return appendToFile(template, { type: 'index', singularName: answers.name });\n },\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","getDestinationPrompts","getDestBasePath","rootFolder","actions","answers","filePath","getFilePath","destination","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","join","replace","baseActions","path","templateFile","indexPath","ex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AA;oBACtDS,YAAc,EAAA,CAAC,UAAU,EAAET,QAAAA,CAAS,YAAY,EAAEA,QAAAA,CAAS,IAAI;AACjE;AACD,aAAA;YAED,IAAIP,OAAAA,CAAQU,MAAM,EAAE;gBAClB,MAAMO,SAAAA,GAAYL,UAAK1B,IAAKW,CAAAA,eAAe,IAAI,CAAGI,EAAAA,QAAAA,CAAS,mBAAmB,EAAEM,QAAU,CAAA,CAAA,CAAA;gBAC1F,MAAMW,MAAAA,GAASC,EAAGC,CAAAA,UAAU,CAACH,SAAAA,CAAAA;AAE7B,gBAAA,IAAI,CAACC,MAAQ,EAAA;;AAEXJ,oBAAAA,WAAAA,CAAYO,IAAI,CAAC;wBACf/B,IAAM,EAAA,KAAA;AACNyB,wBAAAA,IAAAA,EAAM,CAAGd,EAAAA,QAAAA,CAAS,mBAAmB,EAAEM,QAAU,CAAA,CAAA;wBACjDS,YAAc,EAAA,CAAC,UAAU,EAAET,QAAAA,CAAS,qBAAqB,EAAEA,QAAAA,CAAS,IAAI,CAAC;wBACzEe,YAAc,EAAA;AAChB,qBAAA,CAAA;AACF;;AAGAR,gBAAAA,WAAAA,CAAYO,IAAI,CAAC;oBACf/B,IAAM,EAAA,QAAA;AACNyB,oBAAAA,IAAAA,EAAM,CAAGd,EAAAA,QAAAA,CAAS,mBAAmB,EAAEM,QAAU,CAAA,CAAA;AACjDgB,oBAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,wBAAA,OAAOC,oCAAaD,QAAU,EAAA;4BAAElC,IAAM,EAAA,OAAA;AAASoC,4BAAAA,YAAAA,EAAc1B,QAAQT;AAAK,yBAAA,CAAA;AAC5E;AACF,iBAAA,CAAA;AACF;YAEA,OAAOuB,WAAAA;AACT;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"middleware.js","sources":["../../src/plops/middleware.ts"],"sourcesContent":["import type { ActionType, NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport { join } from 'path';\nimport fs from 'fs';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport validateInput from './utils/validate-input';\nimport getFilePath from './utils/get-file-path';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // middleware generator\n plop.setGenerator('middleware', {\n description: 'Generate a middleware for an API',\n prompts: [\n {\n type: 'input',\n name: 'name',\n message: 'Middleware name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('middleware', plop.getDestBasePath(), { rootFolder: true }),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/middlewares/{{ name }}.${language}`,\n templateFile: `templates/${language}/middleware.${language}.hbs`,\n },\n ];\n\n if (answers.plugin) {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/middlewares/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/middlewares/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new middleware to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/middlewares/index.${language}`,\n transform(template: string) {\n return appendToFile(template, { type: 'index', singularName: answers.name });\n },\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","getDestinationPrompts","getDestBasePath","rootFolder","actions","answers","filePath","getFilePath","destination","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","join","replace","baseActions","path","templateFile","indexPath","exists","fs","existsSync","push","skipIfExists","transform","template","appendToFile","singularName"],"mappings":";;;;;;;;;;AAUA,yBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAAA,CAAKC,YAAY,CAAC,YAAA,EAAc;QAC9BC,WAAAA,EAAa,kCAAA;QACbC,OAAAA,EAAS;AACP,YAAA;gBACEC,IAAAA,EAAM,OAAA;gBACNC,IAAAA,EAAM,MAAA;gBACNC,OAAAA,EAAS,iBAAA;gBACTC,QAAAA,EAAU,CAACC,QAAUC,aAAAA,CAAcD,KAAAA;AACrC,aAAA;eACGE,qBAAAA,CAAsB,YAAA,EAAcV,IAAAA,CAAKW,eAAe,EAAA,EAAI;gBAAEC,UAAAA,EAAY;AAAK,aAAA;AACnF,SAAA;AACDC,QAAAA,OAAAA,CAAAA,CAAQC,OAAO,EAAA;AACb,YAAA,IAAI,CAACA,OAAAA,EAAS;AACZ,gBAAA,OAAO,EAAE;AACX,YAAA;YAEA,MAAMC,QAAAA,GAAWC,WAAAA,CAAYF,OAAAA,CAAQG,WAAW,CAAA;YAChD,MAAMC,UAAAA,GAAaC,QAAQC,GAAG,EAAA;AAC9B,YAAA,IAAIC,QAAAA,GAAWC,OAAAA,CAAQC,qBAAqB,CAACL,cAAc,IAAA,GAAO,IAAA;YAElE,IAAIJ,OAAAA,CAAQU,MAAM,EAAE;;gBAElB,MAAMC,eAAAA,GAAkBC,SAAAA,CACtBR,UAAAA,EACA,KAAA,EACAH,QAAAA,CAASY,OAAO,CAAC,cAAA,EAAgBb,OAAAA,CAAQU,MAAM,CAAA,EAC/C,KAAA,CAAA;AAEFH,gBAAAA,QAAAA,GAAWC,OAAAA,CAAQC,qBAAqB,CAACE,eAAAA,CAAAA,GAAmB,IAAA,GAAO,IAAA;AACrE,YAAA;AAEA,YAAA,MAAMG,WAAAA,GAAiC;AACrC,gBAAA;oBACExB,IAAA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