@strapi/generators 0.0.0-experimental.6340da17068c3bed7fb006e7bcc554c71129e282 → 0.0.0-experimental.63624e21eb5b0713345a0cf2f68f1c40eab427bc

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 (62) hide show
  1. package/dist/index.d.ts.map +1 -1
  2. package/dist/index.js +7 -2
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +8 -3
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/plops/api.d.ts.map +1 -1
  7. package/dist/plops/api.js +5 -9
  8. package/dist/plops/api.js.map +1 -1
  9. package/dist/plops/api.mjs +5 -8
  10. package/dist/plops/api.mjs.map +1 -1
  11. package/dist/plops/content-type.d.ts.map +1 -1
  12. package/dist/plops/content-type.js +45 -19
  13. package/dist/plops/content-type.js.map +1 -1
  14. package/dist/plops/content-type.mjs +44 -18
  15. package/dist/plops/content-type.mjs.map +1 -1
  16. package/dist/plops/controller.d.ts.map +1 -1
  17. package/dist/plops/controller.js +5 -9
  18. package/dist/plops/controller.js.map +1 -1
  19. package/dist/plops/controller.mjs +5 -8
  20. package/dist/plops/controller.mjs.map +1 -1
  21. package/dist/plops/middleware.d.ts.map +1 -1
  22. package/dist/plops/middleware.js +5 -9
  23. package/dist/plops/middleware.js.map +1 -1
  24. package/dist/plops/middleware.mjs +5 -8
  25. package/dist/plops/middleware.mjs.map +1 -1
  26. package/dist/plops/migration.js +19 -3
  27. package/dist/plops/migration.js.map +1 -1
  28. package/dist/plops/migration.mjs +1 -1
  29. package/dist/plops/migration.mjs.map +1 -1
  30. package/dist/plops/policy.d.ts.map +1 -1
  31. package/dist/plops/policy.js +5 -9
  32. package/dist/plops/policy.js.map +1 -1
  33. package/dist/plops/policy.mjs +5 -8
  34. package/dist/plops/policy.mjs.map +1 -1
  35. package/dist/plops/prompts/get-folder-prompts.d.ts +14 -0
  36. package/dist/plops/prompts/get-folder-prompts.d.ts.map +1 -0
  37. package/dist/plops/prompts/get-folder-prompts.js +105 -0
  38. package/dist/plops/prompts/get-folder-prompts.js.map +1 -0
  39. package/dist/plops/prompts/get-folder-prompts.mjs +103 -0
  40. package/dist/plops/prompts/get-folder-prompts.mjs.map +1 -0
  41. package/dist/plops/service.d.ts.map +1 -1
  42. package/dist/plops/service.js +5 -9
  43. package/dist/plops/service.js.map +1 -1
  44. package/dist/plops/service.mjs +5 -8
  45. package/dist/plops/service.mjs.map +1 -1
  46. package/dist/plops/utils/content-structure.d.ts +42 -0
  47. package/dist/plops/utils/content-structure.d.ts.map +1 -0
  48. package/dist/plops/utils/content-structure.js +260 -0
  49. package/dist/plops/utils/content-structure.js.map +1 -0
  50. package/dist/plops/utils/content-structure.mjs +247 -0
  51. package/dist/plops/utils/content-structure.mjs.map +1 -0
  52. package/dist/plops/utils/extend-plugin-index-files.js +1 -1
  53. package/dist/plops/utils/extend-plugin-index-files.js.map +1 -1
  54. package/dist/plops/utils/extend-plugin-index-files.mjs +1 -1
  55. package/dist/plops/utils/extend-plugin-index-files.mjs.map +1 -1
  56. package/dist/plops/utils/get-generator-language.d.ts +15 -0
  57. package/dist/plops/utils/get-generator-language.d.ts.map +1 -0
  58. package/dist/plops/utils/get-generator-language.js +22 -0
  59. package/dist/plops/utils/get-generator-language.js.map +1 -0
  60. package/dist/plops/utils/get-generator-language.mjs +20 -0
  61. package/dist/plops/utils/get-generator-language.mjs.map +1 -0
  62. package/package.json +15 -12
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,MAAM,qBAiBlB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAUF,eAAO,MAAM,QAAQ,GAAU,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC1D,eAAe,MAAM,EACrB,SAAS,CAAC,EACV,oBAAmD,eAAoB;;EAkDxE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,MAAM,qBAiBlB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAYF,eAAO,MAAM,QAAQ,GAAU,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC1D,eAAe,MAAM,EACrB,SAAS,CAAC,EACV,oBAAmD,eAAoB;;EAoDxE,CAAC"}
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ const runCLI = async ()=>{
25
25
  });
26
26
  };
27
27
  const generate = async (generatorName, options, { dir = process.cwd(), plopFile = 'plopfile.js' } = {})=>{
28
+ const resolvedDir = node_path.resolve(dir);
28
29
  // Resolve the absolute path to the plopfile (generator definitions)
29
30
  const plopfilePath = node_path.join(__dirname, plopFile);
30
31
  // Dynamically require the plopfile module.
@@ -45,7 +46,7 @@ const generate = async (generatorName, options, { dir = process.cwd(), plopFile
45
46
  helpers[name] = fn;
46
47
  },
47
48
  getDestBasePath () {
48
- return node_path.join(dir, 'src');
49
+ return node_path.join(resolvedDir, 'src');
49
50
  },
50
51
  setWelcomeMessage () {}
51
52
  };
@@ -63,7 +64,7 @@ const generate = async (generatorName, options, { dir = process.cwd(), plopFile
63
64
  }
64
65
  registerHandlebarsHelpers(helpers);
65
66
  const actions = typeof generator.actions === 'function' ? generator.actions(options) : generator.actions || [];
66
- await executeActions(actions, options, dir);
67
+ await executeActions(actions, options, resolvedDir);
67
68
  return {
68
69
  success: true
69
70
  };
@@ -74,6 +75,10 @@ const registerHandlebarsHelpers = (helpers)=>{
74
75
  // Executes generator actions: add or modify files as specified
75
76
  const executeActions = async (actions, options, dir)=>{
76
77
  for (const action of actions){
78
+ if (typeof action === 'function') {
79
+ await action(options);
80
+ continue;
81
+ }
77
82
  const outputPath = handlebars__default.default.compile(action.path)(options);
78
83
  const fullPath = node_path.join(dir, 'src', outputPath);
79
84
  if (action.type === 'add' && action.templateFile) {
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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ACF,CAAA;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { join, dirname, resolve } 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 GeneratorFileAction = {\n type: 'add' | 'modify';\n path: string;\n templateFile?: string;\n data?: Record<string, any>;\n transform?: (content: string) => string;\n};\n\ntype GeneratorAction = GeneratorFileAction | ((options: Record<string, any>) => unknown);\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 const resolvedDir = resolve(dir);\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(resolvedDir, '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, resolvedDir);\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 if (typeof action === 'function') {\n await action(options);\n continue;\n }\n\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","resolvedDir","resolve","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":";;;;;;;;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OoB,SAAS,GAAGpB,MAAAA,CAAOoB,SAAS,CAACF,OAAAA,CAAAA,GAAWA,OAAAA;gBAChE,MAAMT,mBAAAA,CAAGO,SAAS,CAACZ,QAAAA,EAAUe,QAAAA,CAAAA;AAC/B,YAAA;AACF,QAAA;AACF,IAAA;AACF,CAAA;;;;;"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { join, dirname } from 'node:path';
1
+ import { join, resolve, dirname } from 'node:path';
2
2
  import handlebars from 'handlebars';
3
3
  import fs from 'fs-extra';
4
4
 
@@ -18,6 +18,7 @@ const runCLI = async ()=>{
18
18
  });
19
19
  };
20
20
  const generate = async (generatorName, options, { dir = process.cwd(), plopFile = 'plopfile.js' } = {})=>{
21
+ const resolvedDir = resolve(dir);
21
22
  // Resolve the absolute path to the plopfile (generator definitions)
22
23
  const plopfilePath = join(__dirname, plopFile);
23
24
  // Dynamically require the plopfile module.
@@ -38,7 +39,7 @@ const generate = async (generatorName, options, { dir = process.cwd(), plopFile
38
39
  helpers[name] = fn;
39
40
  },
40
41
  getDestBasePath () {
41
- return join(dir, 'src');
42
+ return join(resolvedDir, 'src');
42
43
  },
43
44
  setWelcomeMessage () {}
44
45
  };
@@ -56,7 +57,7 @@ const generate = async (generatorName, options, { dir = process.cwd(), plopFile
56
57
  }
57
58
  registerHandlebarsHelpers(helpers);
58
59
  const actions = typeof generator.actions === 'function' ? generator.actions(options) : generator.actions || [];
59
- await executeActions(actions, options, dir);
60
+ await executeActions(actions, options, resolvedDir);
60
61
  return {
61
62
  success: true
62
63
  };
@@ -67,6 +68,10 @@ const registerHandlebarsHelpers = (helpers)=>{
67
68
  // Executes generator actions: add or modify files as specified
68
69
  const executeActions = async (actions, options, dir)=>{
69
70
  for (const action of actions){
71
+ if (typeof action === 'function') {
72
+ await action(options);
73
+ continue;
74
+ }
70
75
  const outputPath = handlebars.compile(action.path)(options);
71
76
  const fullPath = join(dir, 'src', outputPath);
72
77
  if (action.type === 'add' && action.templateFile) {
@@ -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,MAAAA,GAAS,UAAA;IACpB,MAAM,EAAEC,IAAI,EAAEC,GAAG,EAAE,GAAG,MAAM,OAAO,MAAA,CAAA;AAEnCD,IAAAA,IAAAA,CAAKE,OAAO,CACV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,KAAA,EAAO4B,UAAAA,CAAAA;AAElC,QAAA,IAAID,OAAOK,IAAI,KAAK,KAAA,IAASL,MAAAA,CAAOM,YAAY,EAAE;AAChD,YAAA,MAAMC,YAAAA,GAAe7C,IAAAA,CAAKC,SAAAA,EAAWqC,MAAAA,CAAOM,YAAY,CAAA;AACxD,YAAA,MAAME,eAAAA,GAAkB,MAAMC,EAAAA,CAAGC,QAAQ,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
+ {"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { join, dirname, resolve } 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 GeneratorFileAction = {\n type: 'add' | 'modify';\n path: string;\n templateFile?: string;\n data?: Record<string, any>;\n transform?: (content: string) => string;\n};\n\ntype GeneratorAction = GeneratorFileAction | ((options: Record<string, any>) => unknown);\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 const resolvedDir = resolve(dir);\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(resolvedDir, '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, resolvedDir);\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 if (typeof action === 'function') {\n await action(options);\n continue;\n }\n\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","resolvedDir","resolve","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,QAA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ACF,IAAA;AACF,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/plops/api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,MAAM,CAAC;yBAQpC,MAAM,WAAW;AAAjC,wBAkJE"}
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/plops/api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,MAAM,CAAC;yBAQpC,MAAM,WAAW;AAAjC,wBAsIE"}
package/dist/plops/api.js CHANGED
@@ -2,15 +2,14 @@
2
2
 
3
3
  var path = require('path');
4
4
  var fs = require('fs-extra');
5
- var tsUtils = require('@strapi/typescript-utils');
6
5
  var validateInput = require('./utils/validate-input.js');
7
6
  var getFilePath = require('./utils/get-file-path.js');
7
+ var getGeneratorLanguage = require('./utils/get-generator-language.js');
8
8
  var extendPluginIndexFiles = require('./utils/extend-plugin-index-files.js');
9
9
 
10
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
11
 
12
12
  var fs__default = /*#__PURE__*/_interopDefault(fs);
13
- var tsUtils__default = /*#__PURE__*/_interopDefault(tsUtils);
14
13
 
15
14
  var generateApi = ((plop)=>{
16
15
  // API generator
@@ -55,13 +54,10 @@ var generateApi = ((plop)=>{
55
54
  return [];
56
55
  }
57
56
  const filePath = getFilePath(answers.destination || (answers.isPluginApi && answers.plugin ? 'plugin' : 'new'));
58
- const currentDir = process.cwd();
59
- let language = tsUtils__default.default.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
60
- if (answers.plugin) {
61
- // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
62
- const pluginServerDir = path.join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
63
- language = tsUtils__default.default.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
64
- }
57
+ const language = getGeneratorLanguage({
58
+ plugin: answers.plugin,
59
+ filePath
60
+ }, plop);
65
61
  const baseActions = [
66
62
  {
67
63
  type: 'add',
@@ -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' : 'new')\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,mBAAAA,CAAGC,UAAU,CAACL,WAAAA,CAAAA;AACnC,oBAAA,IAAI,CAACG,MAAAA,EAAQ;AACX,wBAAA,MAAMG,KAAAA,CAAM,sCAAA,CA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chD,QAAQiD;AAAG,6BAAA,CAAA;AAC1E,wBAAA;AACF,qBAAA,CAAA;AACF,gBAAA,CAAA,CAAA;AACF,YAAA;YAEA,OAAOlB,WAAAA;AACT,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"api.js","sources":["../../src/plops/api.ts"],"sourcesContent":["import { join } from 'path';\nimport type { ActionType, NodePlopAPI } from 'plop';\nimport fs from 'fs-extra';\n\nimport validateInput from './utils/validate-input';\nimport getFilePath from './utils/get-file-path';\nimport getGeneratorLanguage from './utils/get-generator-language';\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' : 'new')\n );\n const language = getGeneratorLanguage({ plugin: answers.plugin, filePath }, plop);\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","language","getGeneratorLanguage","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,mBAAAA,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,mBAAAA,CAAGI,OAAO,CAACR,WAAAA,EAAa;wBAAES,aAAAA,EAAe;AAAK,qBAAA,CAAA;AACvE,oBA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iCAAiC,EAAEA,QAAAA,CAAS,IAAI,CAAC;oCACrFe,IAAAA,EAAM;wCAAE7C,IAAAA,EAAM0C;AAAU,qCAAA;oCACxBF,YAAAA,EAAc;AAChB,iCAAA,CAAA;AACF,4BAAA;AACF,wBAAA,CAAA,CAAA;AACF,oBAAA;AAEAR,oBAAAA,WAAAA,CAAYO,IAAI,CAAC;wBACfvC,IAAAA,EAAM,QAAA;AACNiC,wBAAAA,IAAAA,EAAM,CAAA,EAAGP,QAAAA,CAAS,CAAC,EAAE1B,IAAAA,CAAK,CAAC,EAAEA,IAAAA,KAAS,QAAA,GAAW,cAAA,GAAiB,EAAA,CAAG,MAAM,EAAE8B,QAAAA,CAAAA,CAAU;AACvFgB,wBAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,4BAAA,IAAI/C,SAAS,QAAA,EAAU;AACrB,gCAAA,OAAOgD,oCAAaD,QAAAA,EAAU;oCAAE/C,IAAAA,EAAM,QAAA;AAAUiD,oCAAAA,YAAAA,EAAc1C,QAAQ2C;AAAG,iCAAA,CAAA;AAC3E,4BAAA;AAEA,4BAAA,OAAOF,oCAAaD,QAAAA,EAAU;gCAAE/C,IAAAA,EAAM,OAAA;AAASiD,gCAAAA,YAAAA,EAAc1C,QAAQ2C;AAAG,6BAAA,CAAA;AAC1E,wBAAA;AACF,qBAAA,CAAA;AACF,gBAAA,CAAA,CAAA;AACF,YAAA;YAEA,OAAOlB,WAAAA;AACT,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
@@ -1,8 +1,8 @@
1
1
  import { join } from 'path';
2
2
  import fs from 'fs-extra';
3
- import tsUtils from '@strapi/typescript-utils';
4
3
  import validateInput from './utils/validate-input.mjs';
5
4
  import getFilePath from './utils/get-file-path.mjs';
5
+ import getGeneratorLanguage from './utils/get-generator-language.mjs';
6
6
  import { appendToFile } from './utils/extend-plugin-index-files.mjs';
7
7
 
8
8
  var generateApi = ((plop)=>{
@@ -48,13 +48,10 @@ var generateApi = ((plop)=>{
48
48
  return [];
49
49
  }
50
50
  const filePath = getFilePath(answers.destination || (answers.isPluginApi && answers.plugin ? 'plugin' : 'new'));
51
- const currentDir = process.cwd();
52
- let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
53
- if (answers.plugin) {
54
- // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
55
- const pluginServerDir = join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
56
- language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
57
- }
51
+ const language = getGeneratorLanguage({
52
+ plugin: answers.plugin,
53
+ filePath
54
+ }, plop);
58
55
  const baseActions = [
59
56
  {
60
57
  type: 'add',
@@ -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' : 'new')\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,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CAAG,MAAM,EAAEiC,QAAAA,CAAAA,CAAU;AACvFmB,wBAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,4BAAA,IAAIrD,SAAS,QAAA,EAAU;AACrB,gCAAA,OAAOsD,aAAaD,QAAAA,EAAU;oCAAErD,IAAAA,EAAM,QAAA;AAAUuD,oCAAAA,YAAAA,EAAchD,QAAQiD;AAAG,iCAAA,CAAA;AAC3E,4BAAA;AAEA,4BAAA,OAAOF,aAAaD,QAAAA,EAAU;gCAAErD,IAAAA,EAAM,OAAA;AAASuD,gCAAAA,YAAAA,EAAchD,QAAQiD;AAAG,6BAAA,CAAA;AAC1E,wBAAA;AACF,qBAAA,CAAA;AACF,gBAAA,CAAA,CAAA;AACF,YAAA;YAEA,OAAOlB,WAAAA;AACT,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"api.mjs","sources":["../../src/plops/api.ts"],"sourcesContent":["import { join } from 'path';\nimport type { ActionType, NodePlopAPI } from 'plop';\nimport fs from 'fs-extra';\n\nimport validateInput from './utils/validate-input';\nimport getFilePath from './utils/get-file-path';\nimport getGeneratorLanguage from './utils/get-generator-language';\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' : 'new')\n );\n const language = getGeneratorLanguage({ plugin: answers.plugin, filePath }, plop);\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","language","getGeneratorLanguage","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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AAA;YAEA,OAAOlB,WAAAA;AACT,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"content-type.d.ts","sourceRoot":"","sources":["../../src/plops/content-type.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAc,MAAM,MAAM,CAAC;yBAcpC,MAAM,WAAW;AAAjC,wBAqPE"}
1
+ {"version":3,"file":"content-type.d.ts","sourceRoot":"","sources":["../../src/plops/content-type.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAc,MAAM,MAAM,CAAC;yBAiBpC,MAAM,WAAW;AAAjC,wBAkRE"}
@@ -2,22 +2,25 @@
2
2
 
3
3
  var path = require('path');
4
4
  var slugify = require('@sindresorhus/slugify');
5
+ var handlebars = require('handlebars');
5
6
  var fs = require('fs-extra');
6
7
  var utils = require('@strapi/utils');
7
- var tsUtils = require('@strapi/typescript-utils');
8
8
  var getDestinationPrompts = require('./prompts/get-destination-prompts.js');
9
9
  var getFilePath = require('./utils/get-file-path.js');
10
+ var getGeneratorLanguage = require('./utils/get-generator-language.js');
10
11
  var ctNamesPrompts = require('./prompts/ct-names-prompts.js');
11
12
  var kindPrompts = require('./prompts/kind-prompts.js');
12
13
  var getAttributesPrompts = require('./prompts/get-attributes-prompts.js');
13
14
  var bootstrapApiPrompts = require('./prompts/bootstrap-api-prompts.js');
15
+ var getFolderPrompts = require('./prompts/get-folder-prompts.js');
14
16
  var extendPluginIndexFiles = require('./utils/extend-plugin-index-files.js');
17
+ var contentStructure = require('./utils/content-structure.js');
15
18
 
16
19
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
17
20
 
18
21
  var slugify__default = /*#__PURE__*/_interopDefault(slugify);
22
+ var handlebars__default = /*#__PURE__*/_interopDefault(handlebars);
19
23
  var fs__default = /*#__PURE__*/_interopDefault(fs);
20
- var tsUtils__default = /*#__PURE__*/_interopDefault(tsUtils);
21
24
 
22
25
  var generateContentType = ((plop)=>{
23
26
  // Model generator
@@ -58,9 +61,14 @@ var generateContentType = ((plop)=>{
58
61
  },
59
62
  ...bootstrapApiPrompts
60
63
  ]);
64
+ const folder = await getFolderPrompts(inquirer, plop, {
65
+ destination: api.destination,
66
+ kind: config.kind
67
+ });
61
68
  return {
62
69
  ...config,
63
70
  ...api,
71
+ ...folder,
64
72
  attributes
65
73
  };
66
74
  },
@@ -89,17 +97,24 @@ var generateContentType = ((plop)=>{
89
97
  }, {});
90
98
  }, {});
91
99
  const filePath = getFilePath(answers.destination);
92
- const currentDir = process.cwd();
93
- let language = tsUtils__default.default.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
94
- if (answers.plugin) {
95
- // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
96
- const pluginServerDir = path.join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
97
- language = tsUtils__default.default.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
100
+ const language = getGeneratorLanguage({
101
+ plugin: answers.plugin,
102
+ filePath
103
+ }, plop);
104
+ const { singularName } = answers;
105
+ const schemaActionPath = `${filePath}/content-types/{{ singularName }}/schema.json`;
106
+ let uid;
107
+ if (answers.destination === 'new') {
108
+ uid = `api::${answers.id}.${singularName}`;
109
+ } else if (answers.api) {
110
+ uid = `api::${answers.api}.${singularName}`;
111
+ } else if (answers.plugin) {
112
+ uid = `plugin::${answers.plugin}.${singularName}`;
98
113
  }
99
114
  const baseActions = [
100
115
  {
101
116
  type: 'add',
102
- path: `${filePath}/content-types/{{ singularName }}/schema.json`,
117
+ path: schemaActionPath,
103
118
  templateFile: `templates/${language}/content-type.schema.json.hbs`,
104
119
  data: {
105
120
  collectionName: slugify__default.default(answers.pluralName, {
@@ -111,7 +126,7 @@ var generateContentType = ((plop)=>{
111
126
  if (Object.entries(attributes).length > 0) {
112
127
  baseActions.push({
113
128
  type: 'modify',
114
- path: `${filePath}/content-types/{{ singularName }}/schema.json`,
129
+ path: schemaActionPath,
115
130
  transform (template) {
116
131
  const parsedTemplate = JSON.parse(template);
117
132
  parsedTemplate.attributes = attributes;
@@ -144,15 +159,6 @@ var generateContentType = ((plop)=>{
144
159
  });
145
160
  }
146
161
  if (answers.bootstrapApi) {
147
- const { singularName } = answers;
148
- let uid;
149
- if (answers.destination === 'new') {
150
- uid = `api::${answers.id}.${singularName}`;
151
- } else if (answers.api) {
152
- uid = `api::${answers.api}.${singularName}`;
153
- } else if (answers.plugin) {
154
- uid = `plugin::${answers.plugin}.${singularName}`;
155
- }
156
162
  baseActions.push({
157
163
  type: 'add',
158
164
  path: `${filePath}/controllers/{{ singularName }}.${language}`,
@@ -242,6 +248,26 @@ var generateContentType = ((plop)=>{
242
248
  });
243
249
  }
244
250
  }
251
+ if (answers.folder) {
252
+ if (!uid) {
253
+ throw new Error('Cannot assign a folder: could not determine the content type uid from the given destination.');
254
+ }
255
+ const contentTypeAlreadyExists = fs__default.default.existsSync(path.join(plop.getDestBasePath(), handlebars__default.default.compile(schemaActionPath)(answers)));
256
+ if (contentTypeAlreadyExists) {
257
+ throw new Error(`Content type "${uid}" already exists — refusing to reassign its folder from the generator.`);
258
+ }
259
+ const assignedUid = uid;
260
+ const commitFolderAssignment = contentStructure.planContentTypeToFolder({
261
+ destBasePath: plop.getDestBasePath(),
262
+ folder: answers.folder,
263
+ kind: answers.kind,
264
+ uid: assignedUid
265
+ });
266
+ baseActions.push(()=>{
267
+ commitFolderAssignment();
268
+ return `assigned "${assignedUid}" to folder`;
269
+ });
270
+ }
245
271
  return baseActions;
246
272
  }
247
273
  });
@@ -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,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,cAAAA;AAAmBC,gBAAAA,GAAAA;AAAY,aAAA,CAAA;YACxE,MAAMC,UAAAA,GAAa,MAAMC,oBAAAA,CAAqBN,QAAAA,CAAAA;AAE9C,YAAA,MAAMO,GAAAA,GAAM,MAAMP,QAAAA,CAASE,MAAM,CAAC;mBAC7BM,qBAAAA,CAAsB,OAAA,EAASZ,KAAKa,eAAe,EAAA,CAAA;AACtD,gBAAA;AACEC,oBAAAA,IAAAA,EAAM,CAACC,OAAAA,GAAYA,OAAAA,CAAQC,WAAW,KAAK,KAAA;oBAC3CC,IAAAA,EAAM,OAAA;oBACNC,IAAAA,EAAM,IAAA;AACNC,oBAAAA,OAAAA,EAASd,OAAOe,YAAY;oBAC5BC,OAAAA,EAAS,sBAAA;AACT,oBA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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
+ {"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 handlebars from 'handlebars';\nimport fs from 'fs-extra';\nimport { strings } from '@strapi/utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport getGeneratorLanguage from './utils/get-generator-language';\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 getFolderPrompts from './prompts/get-folder-prompts';\nimport { appendToFile } from './utils/extend-plugin-index-files';\nimport { planContentTypeToFolder } from './utils/content-structure';\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 const folder = await getFolderPrompts(inquirer, plop, {\n destination: api.destination,\n kind: config.kind,\n });\n\n return {\n ...config,\n ...api,\n ...folder,\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 language = getGeneratorLanguage({ plugin: answers.plugin, filePath }, plop);\n\n const { singularName } = answers;\n\n const schemaActionPath = `${filePath}/content-types/{{ singularName }}/schema.json`;\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 const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: schemaActionPath,\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: schemaActionPath,\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 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 if (answers.folder) {\n if (!uid) {\n throw new Error(\n 'Cannot assign a folder: could not determine the content type uid from the given destination.'\n );\n }\n\n const contentTypeAlreadyExists = fs.existsSync(\n join(plop.getDestBasePath(), handlebars.compile(schemaActionPath)(answers))\n );\n\n if (contentTypeAlreadyExists) {\n throw new Error(\n `Content type \"${uid}\" already exists — refusing to reassign its folder from the generator.`\n );\n }\n\n const assignedUid = uid;\n\n const commitFolderAssignment = planContentTypeToFolder({\n destBasePath: plop.getDestBasePath(),\n folder: answers.folder,\n kind: answers.kind,\n uid: assignedUid,\n });\n\n baseActions.push(() => {\n commitFolderAssignment();\n\n return `assigned \"${assignedUid}\" to folder`;\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","folder","getFolderPrompts","kind","actions","reduce","object","answer","val","attributeType","enum","split","map","item","trim","allowedTypes","multiple","Object","assign","attributeName","filePath","getFilePath","language","getGeneratorLanguage","plugin","schemaActionPath","uid","id","baseActions","path","templateFile","data","collectionName","slugify","pluralName","separator","entries","length","push","transform","template","parsedTemplate","JSON","parse","stringify","indexPath","existsSync","skipIfExists","appendToFile","bootstrapApi","indexFiles","forEach","routeIndexFiles","routeType","routeTypeIndexPath","routeTypeExists","contentTypeAlreadyExists","handlebars","compile","assignedUid","commitFolderAssignment","planContentTypeToFolder","destBasePath"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkBA,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,cAAAA;AAAmBC,gBAAAA,GAAAA;AAAY,aAAA,CAAA;YACxE,MAAMC,UAAAA,GAAa,MAAMC,oBAAAA,CAAqBN,QAAAA,CAAAA;AAE9C,YAAA,MAAMO,GAAAA,GAAM,MAAMP,QAAAA,CAASE,MAAM,CAAC;mBAC7BM,qBAAAA,CAAsB,OAAA,EAASZ,KAAKa,eAAe,EAAA,CAAA;AACtD,gBAAA;AACEC,oBAAAA,IAAAA,EAAM,CAACC,OAAAA,GAAYA,OAAAA,CAAQC,WAAW,KAAK,KAAA;oBAC3CC,IAAAA,EAAM,OAAA;oBACNC,IAAAA,EAAM,IAAA;AACNC,oBAAAA,OAAAA,EAASd,OAAOe,YAAY;oBAC5BC,OAAAA,EAAS,sBAAA;AACT,oBAAA,MAAMC,UAASC,KAAK,EAAA;AAClB,wBAAA,IAAI,CAACC,aAAAA,CAAQC,WAAW,CAACF,KAAAA,CAAAA,EAAQ;4B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