@strapi/generators 5.29.0 → 5.30.1
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.
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/index.mjs.map +1 -1
- package/dist/plops/api.d.ts.map +1 -1
- package/dist/plops/api.js +79 -11
- package/dist/plops/api.js.map +1 -1
- package/dist/plops/api.mjs +79 -11
- package/dist/plops/api.mjs.map +1 -1
- package/dist/plops/content-type.d.ts.map +1 -1
- package/dist/plops/content-type.js +98 -2
- package/dist/plops/content-type.js.map +1 -1
- package/dist/plops/content-type.mjs +98 -2
- package/dist/plops/content-type.mjs.map +1 -1
- package/dist/plops/controller.d.ts.map +1 -1
- package/dist/plops/controller.js +35 -2
- package/dist/plops/controller.js.map +1 -1
- package/dist/plops/controller.mjs +35 -2
- package/dist/plops/controller.mjs.map +1 -1
- package/dist/plops/middleware.d.ts.map +1 -1
- package/dist/plops/middleware.js +35 -2
- package/dist/plops/middleware.js.map +1 -1
- package/dist/plops/middleware.mjs +35 -2
- package/dist/plops/middleware.mjs.map +1 -1
- package/dist/plops/migration.js.map +1 -1
- package/dist/plops/migration.mjs.map +1 -1
- package/dist/plops/policy.d.ts.map +1 -1
- package/dist/plops/policy.js +35 -2
- package/dist/plops/policy.js.map +1 -1
- package/dist/plops/policy.mjs +35 -2
- package/dist/plops/policy.mjs.map +1 -1
- package/dist/plops/service.d.ts.map +1 -1
- package/dist/plops/service.js +35 -2
- package/dist/plops/service.js.map +1 -1
- package/dist/plops/service.mjs +35 -2
- package/dist/plops/service.mjs.map +1 -1
- package/dist/plops/utils/extend-plugin-index-files.d.ts +8 -0
- package/dist/plops/utils/extend-plugin-index-files.d.ts.map +1 -0
- package/dist/plops/utils/extend-plugin-index-files.js +356 -0
- package/dist/plops/utils/extend-plugin-index-files.js.map +1 -0
- package/dist/plops/utils/extend-plugin-index-files.mjs +335 -0
- package/dist/plops/utils/extend-plugin-index-files.mjs.map +1 -0
- package/dist/plops/utils/get-file-path.d.ts +1 -1
- package/dist/plops/utils/get-file-path.js +2 -2
- package/dist/plops/utils/get-file-path.js.map +1 -1
- package/dist/plops/utils/get-file-path.mjs +2 -2
- package/dist/plops/utils/get-file-path.mjs.map +1 -1
- package/dist/templates/js/plugin/plugin.index.js.hbs +3 -0
- package/dist/templates/js/plugin/plugin.routes.index.js.hbs +12 -0
- package/dist/templates/js/plugin/plugin.routes.type.index.js.hbs +6 -0
- package/dist/templates/ts/plugin/plugin.index.ts.hbs +1 -0
- package/dist/templates/ts/plugin/plugin.routes.index.ts.hbs +9 -0
- package/dist/templates/ts/plugin/plugin.routes.type.index.ts.hbs +4 -0
- package/package.json +9 -5
|
@@ -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';\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 const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n templateFile: `templates/${language}/content-type.schema.json.hbs`,\n data: {\n collectionName: slugify(answers.pluralName, { separator: '_' }),\n },\n },\n ];\n\n if (Object.entries(attributes).length > 0) {\n baseActions.push({\n type: 'modify',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n transform(template: string) {\n const parsedTemplate = JSON.parse(template);\n parsedTemplate.attributes = attributes;\n return JSON.stringify(parsedTemplate, null, 2);\n },\n });\n }\n\n if (answers.bootstrapApi) {\n const { singularName } = answers;\n\n let uid;\n if (answers.destination === 'new') {\n uid = `api::${answers.id}.${singularName}`;\n } else if (answers.api) {\n uid = `api::${answers.api}.${singularName}`;\n } else if (answers.plugin) {\n uid = `plugin::${answers.plugin}.${singularName}`;\n }\n\n baseActions.push(\n {\n type: 'add',\n path: `${filePath}/controllers/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-controller.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/services/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-service.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/routes/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-router.${language}.hbs`,\n data: { uid },\n }\n );\n }\n\n return baseActions;\n },\n });\n};\n"],"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","baseActions","path","templateFile","data","collectionName","slugify","pluralName","separator","entries","length","push","transform","template","parsedTemplate","JSON","parse","stringify","bootstrapApi","uid","id","plugin"],"mappings":";;;;;;;;;;;;;;AAcA,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,KAA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,EAAErE,OAAAA,CAAQuE,MAAM,CAAC,CAAC,EAAElE,YAAAA,CAAa,CAAC;AACnD;AAEA8C,gBAAAA,WAAAA,CAAYU,IAAI,CACd;oBACE3D,IAAM,EAAA,KAAA;AACNkD,oBAAAA,IAAAA,EAAM,CAAC,EAAET,QAAAA,CAAS,gCAAgC,EAAEK,SAAS,CAAC;oBAC9DK,YAAc,EAAA,CAAC,UAAU,EAAEL,QAAAA,CAAS,iBAAiB,EAAEA,QAAAA,CAAS,IAAI,CAAC;oBACrEM,IAAM,EAAA;AAAEe,wBAAAA;AAAI;iBAEd,EAAA;oBACEnE,IAAM,EAAA,KAAA;AACNkD,oBAAAA,IAAAA,EAAM,CAAC,EAAET,QAAAA,CAAS,6BAA6B,EAAEK,SAAS,CAAC;oBAC3DK,YAAc,EAAA,CAAC,UAAU,EAAEL,QAAAA,CAAS,cAAc,EAAEA,QAAAA,CAAS,IAAI,CAAC;oBAClEM,IAAM,EAAA;AAAEe,wBAAAA;AAAI;iBAEd,EAAA;oBACEnE,IAAM,EAAA,KAAA;AACNkD,oBAAAA,IAAAA,EAAM,CAAC,EAAET,QAAAA,CAAS,2BAA2B,EAAEK,SAAS,CAAC;oBACzDK,YAAc,EAAA,CAAC,UAAU,EAAEL,QAAAA,CAAS,aAAa,EAAEA,QAAAA,CAAS,IAAI,CAAC;oBACjEM,IAAM,EAAA;AAAEe,wBAAAA;AAAI;AACd,iBAAA,CAAA;AAEJ;YAEA,OAAOlB,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,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,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,OAAAA,EAASd,OAAOe,YAAY;oBAC5BC,OAAS,EAAA,sBAAA;AACT,oBAAA,MAAMC,UAASC,KAAK,EAAA;AA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,CAAA;AACF,qBAAA,CAAA;AACF;AACF;YAEA,OAAOiD,WAAAA;AACT;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
|
@@ -9,6 +9,7 @@ import questions from './prompts/ct-names-prompts.mjs';
|
|
|
9
9
|
import questions$1 from './prompts/kind-prompts.mjs';
|
|
10
10
|
import getAttributesPrompts from './prompts/get-attributes-prompts.mjs';
|
|
11
11
|
import questions$2 from './prompts/bootstrap-api-prompts.mjs';
|
|
12
|
+
import { appendToFile } from './utils/extend-plugin-index-files.mjs';
|
|
12
13
|
|
|
13
14
|
var generateContentType = ((plop)=>{
|
|
14
15
|
// Model generator
|
|
@@ -81,7 +82,12 @@ var generateContentType = ((plop)=>{
|
|
|
81
82
|
}, {});
|
|
82
83
|
const filePath = getFilePath(answers.destination);
|
|
83
84
|
const currentDir = process.cwd();
|
|
84
|
-
|
|
85
|
+
let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
86
|
+
if (answers.plugin) {
|
|
87
|
+
// The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
|
|
88
|
+
const pluginServerDir = join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
|
|
89
|
+
language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
|
|
90
|
+
}
|
|
85
91
|
const baseActions = [
|
|
86
92
|
{
|
|
87
93
|
type: 'add',
|
|
@@ -105,6 +111,30 @@ var generateContentType = ((plop)=>{
|
|
|
105
111
|
}
|
|
106
112
|
});
|
|
107
113
|
}
|
|
114
|
+
if (answers.plugin) {
|
|
115
|
+
const indexPath = join(plop.getDestBasePath(), `${filePath}/content-types/index.${language}`);
|
|
116
|
+
const exists = fs.existsSync(indexPath);
|
|
117
|
+
if (!exists) {
|
|
118
|
+
// Create index file if it doesn't exist
|
|
119
|
+
baseActions.push({
|
|
120
|
+
type: 'add',
|
|
121
|
+
path: `${filePath}/content-types/index.${language}`,
|
|
122
|
+
templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
|
|
123
|
+
skipIfExists: true
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
// Append the new content type to the index.ts file
|
|
127
|
+
baseActions.push({
|
|
128
|
+
type: 'modify',
|
|
129
|
+
path: `${filePath}/content-types/index.${language}`,
|
|
130
|
+
transform (template) {
|
|
131
|
+
return appendToFile(template, {
|
|
132
|
+
type: 'content-type',
|
|
133
|
+
singularName: answers.singularName
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
108
138
|
if (answers.bootstrapApi) {
|
|
109
139
|
const { singularName } = answers;
|
|
110
140
|
let uid;
|
|
@@ -131,12 +161,78 @@ var generateContentType = ((plop)=>{
|
|
|
131
161
|
}
|
|
132
162
|
}, {
|
|
133
163
|
type: 'add',
|
|
134
|
-
path: `${filePath}/routes/{{ singularName }}.${language}`,
|
|
164
|
+
path: `${filePath}/routes/${answers.plugin ? 'content-api/' : ''}{{ singularName }}.${language}`,
|
|
135
165
|
templateFile: `templates/${language}/core-router.${language}.hbs`,
|
|
136
166
|
data: {
|
|
137
167
|
uid
|
|
138
168
|
}
|
|
139
169
|
});
|
|
170
|
+
if (answers.plugin) {
|
|
171
|
+
const indexFiles = [
|
|
172
|
+
'controllers',
|
|
173
|
+
'services',
|
|
174
|
+
'routes'
|
|
175
|
+
];
|
|
176
|
+
indexFiles.forEach((type)=>{
|
|
177
|
+
const indexPath = join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);
|
|
178
|
+
const exists = fs.existsSync(indexPath);
|
|
179
|
+
if (!exists && type !== 'routes') {
|
|
180
|
+
baseActions.push({
|
|
181
|
+
type: 'add',
|
|
182
|
+
path: `${filePath}/${type}/index.${language}`,
|
|
183
|
+
templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
|
|
184
|
+
skipIfExists: true
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
if (type === 'routes') {
|
|
188
|
+
const indexPath = join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);
|
|
189
|
+
const exists = fs.existsSync(indexPath);
|
|
190
|
+
if (!exists) {
|
|
191
|
+
baseActions.push({
|
|
192
|
+
type: 'add',
|
|
193
|
+
path: `${filePath}/${type}/index.${language}`,
|
|
194
|
+
templateFile: `templates/${language}/plugin/plugin.routes.index.${language}.hbs`,
|
|
195
|
+
skipIfExists: true
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
const routeIndexFiles = [
|
|
199
|
+
'content-api',
|
|
200
|
+
'admin'
|
|
201
|
+
];
|
|
202
|
+
routeIndexFiles.forEach((routeType)=>{
|
|
203
|
+
const routeTypeIndexPath = join(plop.getDestBasePath(), `${filePath}/${type}/${routeType}/index.${language}`);
|
|
204
|
+
const routeTypeExists = fs.existsSync(routeTypeIndexPath);
|
|
205
|
+
if (!routeTypeExists) {
|
|
206
|
+
baseActions.push({
|
|
207
|
+
type: 'add',
|
|
208
|
+
path: `${filePath}/${type}/${routeType}/index.${language}`,
|
|
209
|
+
templateFile: `templates/${language}/plugin/plugin.routes.type.index.${language}.hbs`,
|
|
210
|
+
data: {
|
|
211
|
+
type: routeType
|
|
212
|
+
},
|
|
213
|
+
skipIfExists: true
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
baseActions.push({
|
|
219
|
+
type: 'modify',
|
|
220
|
+
path: `${filePath}/${type}/${type === 'routes' ? 'content-api/' : ''}index.${language}`,
|
|
221
|
+
transform (template) {
|
|
222
|
+
if (type === 'routes') {
|
|
223
|
+
return appendToFile(template, {
|
|
224
|
+
type: 'routes',
|
|
225
|
+
singularName: answers.singularName
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
return appendToFile(template, {
|
|
229
|
+
type: 'index',
|
|
230
|
+
singularName: answers.singularName
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
}
|
|
140
236
|
}
|
|
141
237
|
return baseActions;
|
|
142
238
|
}
|
|
@@ -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';\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 const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n templateFile: `templates/${language}/content-type.schema.json.hbs`,\n data: {\n collectionName: slugify(answers.pluralName, { separator: '_' }),\n },\n },\n ];\n\n if (Object.entries(attributes).length > 0) {\n baseActions.push({\n type: 'modify',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n transform(template: string) {\n const parsedTemplate = JSON.parse(template);\n parsedTemplate.attributes = attributes;\n return JSON.stringify(parsedTemplate, null, 2);\n },\n });\n }\n\n if (answers.bootstrapApi) {\n const { singularName } = answers;\n\n let uid;\n if (answers.destination === 'new') {\n uid = `api::${answers.id}.${singularName}`;\n } else if (answers.api) {\n uid = `api::${answers.api}.${singularName}`;\n } else if (answers.plugin) {\n uid = `plugin::${answers.plugin}.${singularName}`;\n }\n\n baseActions.push(\n {\n type: 'add',\n path: `${filePath}/controllers/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-controller.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/services/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-service.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/routes/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-router.${language}.hbs`,\n data: { uid },\n }\n );\n }\n\n return baseActions;\n },\n });\n};\n"],"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","baseActions","path","templateFile","data","collectionName","slugify","pluralName","separator","entries","length","push","transform","template","parsedTemplate","JSON","parse","stringify","bootstrapApi","uid","id","plugin"],"mappings":";;;;;;;;;;;;AAcA,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,OAAAA,EAASd,OAAOe,YAAY;oBAC5BC,OAAS,EAAA,sBAAA;AACT,oBAAA,MAAMC,UAASC,KAAK,EAAA;AAClB,wBAAA,IAAI,CAACC,OAAAA,CAAQC,WAAW,CAACF,KAAQ,CAAA,EAAA;4BAC/B,OAAO,6BAAA;AACT;AAEA,wBAAA,MAAMG,OAAUC,GAAAA,IAAAA,CAAK3B,IAAKa,CAAAA,eAAe,EAAI,EA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AAS,6BAA6B,EAAEK,SAAS,CAAC;oBAC3DK,YAAc,EAAA,CAAC,UAAU,EAAEL,QAAAA,CAAS,cAAc,EAAEA,QAAAA,CAAS,IAAI,CAAC;oBAClEM,IAAM,EAAA;AAAEe,wBAAAA;AAAI;iBAEd,EAAA;oBACEnE,IAAM,EAAA,KAAA;AACNkD,oBAAAA,IAAAA,EAAM,CAAC,EAAET,QAAAA,CAAS,2BAA2B,EAAEK,SAAS,CAAC;oBACzDK,YAAc,EAAA,CAAC,UAAU,EAAEL,QAAAA,CAAS,aAAa,EAAEA,QAAAA,CAAS,IAAI,CAAC;oBACjEM,IAAM,EAAA;AAAEe,wBAAAA;AAAI;AACd,iBAAA,CAAA;AAEJ;YAEA,OAAOlB,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","routeT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AiC,EAAEA,QAAAA,CAAS,IAAI,CAAC;wCACrFS,IAAM,EAAA;4CAAEvD,IAAM+E,EAAAA;AAAU,yCAAA;wCACxBR,YAAc,EAAA;AAChB,qCAAA,CAAA;AACF;AACF,6BAAA,CAAA;AACF;AAEAnB,wBAAAA,WAAAA,CAAYU,IAAI,CAAC;4BACf9D,IAAM,EAAA,QAAA;AACNqD,4BAAAA,IAAAA,EAAM,CAAGZ,EAAAA,QAAAA,CAAS,CAAC,EAAEzC,IAAK,CAAA,CAAC,EAAEA,IAAAA,KAAS,QAAW,GAAA,cAAA,GAAiB,EAAG,CAAA,MAAM,EAAE8C,QAAU,CAAA,CAAA;AACvFiB,4BAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,gCAAA,IAAIhE,SAAS,QAAU,EAAA;AACrB,oCAAA,OAAOwE,aAAaR,QAAU,EAAA;wCAC5BhE,IAAM,EAAA,QAAA;AACNG,wCAAAA,YAAAA,EAAcL,QAAQK;AACxB,qCAAA,CAAA;AACF;AAEA,gCAAA,OAAOqE,aAAaR,QAAU,EAAA;oCAC5BhE,IAAM,EAAA,OAAA;AACNG,oCAAAA,YAAAA,EAAcL,QAAQK;AACxB,iCAAA,CAAA;AACF;AACF,yBAAA,CAAA;AACF,qBAAA,CAAA;AACF;AACF;YAEA,OAAOiD,WAAAA;AACT;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/plops/controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/plops/controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,MAAM,CAAC;+BAU9B,WAAW;AAAjC,wBAoEE"}
|
package/dist/plops/controller.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var tsUtils = require('@strapi/typescript-utils');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var fs = require('fs');
|
|
4
6
|
var getDestinationPrompts = require('./prompts/get-destination-prompts.js');
|
|
5
7
|
var getFilePath = require('./utils/get-file-path.js');
|
|
6
8
|
var validateInput = require('./utils/validate-input.js');
|
|
9
|
+
var extendPluginIndexFiles = require('./utils/extend-plugin-index-files.js');
|
|
7
10
|
|
|
8
11
|
var generateController = ((plop)=>{
|
|
9
12
|
// Controller generator
|
|
@@ -24,14 +27,44 @@ var generateController = ((plop)=>{
|
|
|
24
27
|
}
|
|
25
28
|
const filePath = getFilePath(answers.destination);
|
|
26
29
|
const currentDir = process.cwd();
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
31
|
+
if (answers.plugin) {
|
|
32
|
+
// The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
|
|
33
|
+
const pluginServerDir = path.join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
|
|
34
|
+
language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
|
|
35
|
+
}
|
|
36
|
+
const baseActions = [
|
|
29
37
|
{
|
|
30
38
|
type: 'add',
|
|
31
39
|
path: `${filePath}/controllers/{{ id }}.${language}`,
|
|
32
40
|
templateFile: `templates/${language}/controller.${language}.hbs`
|
|
33
41
|
}
|
|
34
42
|
];
|
|
43
|
+
if (answers.plugin) {
|
|
44
|
+
const indexPath = path.join(plop.getDestBasePath(), `${filePath}/controllers/index.${language}`);
|
|
45
|
+
const exists = fs.existsSync(indexPath);
|
|
46
|
+
if (!exists) {
|
|
47
|
+
// Create index file if it doesn't exist
|
|
48
|
+
baseActions.push({
|
|
49
|
+
type: 'add',
|
|
50
|
+
path: `${filePath}/controllers/index.${language}`,
|
|
51
|
+
templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
|
|
52
|
+
skipIfExists: true
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
// Append the new controller to the index.ts file
|
|
56
|
+
baseActions.push({
|
|
57
|
+
type: 'modify',
|
|
58
|
+
path: `${filePath}/controllers/index.${language}`,
|
|
59
|
+
transform (template) {
|
|
60
|
+
return extendPluginIndexFiles.appendToFile(template, {
|
|
61
|
+
type: 'index',
|
|
62
|
+
singularName: answers.id
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return baseActions;
|
|
35
68
|
}
|
|
36
69
|
});
|
|
37
70
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","sources":["../../src/plops/controller.ts"],"sourcesContent":["import type { NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport validateInput from './utils/validate-input';\n\nexport default (plop: NodePlopAPI) => {\n // Controller generator\n plop.setGenerator('controller', {\n description: 'Generate a controller for an API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'Controller name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('controller', plop.getDestBasePath()),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n
|
|
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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EM,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,7 +1,10 @@
|
|
|
1
1
|
import tsUtils from '@strapi/typescript-utils';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
2
4
|
import getDestinationPrompts from './prompts/get-destination-prompts.mjs';
|
|
3
5
|
import getFilePath from './utils/get-file-path.mjs';
|
|
4
6
|
import validateInput from './utils/validate-input.mjs';
|
|
7
|
+
import { appendToFile } from './utils/extend-plugin-index-files.mjs';
|
|
5
8
|
|
|
6
9
|
var generateController = ((plop)=>{
|
|
7
10
|
// Controller generator
|
|
@@ -22,14 +25,44 @@ var generateController = ((plop)=>{
|
|
|
22
25
|
}
|
|
23
26
|
const filePath = getFilePath(answers.destination);
|
|
24
27
|
const currentDir = process.cwd();
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
29
|
+
if (answers.plugin) {
|
|
30
|
+
// The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
|
|
31
|
+
const pluginServerDir = join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
|
|
32
|
+
language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
|
|
33
|
+
}
|
|
34
|
+
const baseActions = [
|
|
27
35
|
{
|
|
28
36
|
type: 'add',
|
|
29
37
|
path: `${filePath}/controllers/{{ id }}.${language}`,
|
|
30
38
|
templateFile: `templates/${language}/controller.${language}.hbs`
|
|
31
39
|
}
|
|
32
40
|
];
|
|
41
|
+
if (answers.plugin) {
|
|
42
|
+
const indexPath = join(plop.getDestBasePath(), `${filePath}/controllers/index.${language}`);
|
|
43
|
+
const exists = fs.existsSync(indexPath);
|
|
44
|
+
if (!exists) {
|
|
45
|
+
// Create index file if it doesn't exist
|
|
46
|
+
baseActions.push({
|
|
47
|
+
type: 'add',
|
|
48
|
+
path: `${filePath}/controllers/index.${language}`,
|
|
49
|
+
templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
|
|
50
|
+
skipIfExists: true
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// Append the new controller to the index.ts file
|
|
54
|
+
baseActions.push({
|
|
55
|
+
type: 'modify',
|
|
56
|
+
path: `${filePath}/controllers/index.${language}`,
|
|
57
|
+
transform (template) {
|
|
58
|
+
return appendToFile(template, {
|
|
59
|
+
type: 'index',
|
|
60
|
+
singularName: answers.id
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return baseActions;
|
|
33
66
|
}
|
|
34
67
|
});
|
|
35
68
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.mjs","sources":["../../src/plops/controller.ts"],"sourcesContent":["import type { NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport validateInput from './utils/validate-input';\n\nexport default (plop: NodePlopAPI) => {\n // Controller generator\n plop.setGenerator('controller', {\n description: 'Generate a controller for an API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'Controller name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('controller', plop.getDestBasePath()),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n
|
|
1
|
+
{"version":3,"file":"controller.mjs","sources":["../../src/plops/controller.ts"],"sourcesContent":["import type { ActionType, NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport { join } from 'path';\nimport fs from 'fs';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport validateInput from './utils/validate-input';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // Controller generator\n plop.setGenerator('controller', {\n description: 'Generate a controller for an API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'Controller name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('controller', plop.getDestBasePath()),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/controllers/{{ id }}.${language}`,\n templateFile: `templates/${language}/controller.${language}.hbs`,\n },\n ];\n\n if (answers.plugin) {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/controllers/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/controllers/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new controller to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/controllers/index.${language}`,\n transform(template: string) {\n return appendToFile(template, { type: 'index', singularName: answers.id });\n },\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","getDestinationPrompts","getDestBasePath","actions","answers","filePath","getFilePath","destination","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","join","replace","baseActions","path","templateFile","indexPath","exists","fs","existsSync","push","skipIfExists","transform","template","appendToFile","singularName","id"],"mappings":";;;;;;;;AAUA,yBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,YAAc,EAAA;QAC9BC,WAAa,EAAA,kCAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,IAAA;gBACNC,OAAS,EAAA,iBAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,aAAcD,CAAAA,KAAAA;AACrC,aAAA;eACGE,qBAAsB,CAAA,YAAA,EAAcV,KAAKW,eAAe,EAAA;AAC5D,SAAA;AACDC,QAAAA,OAAAA,CAAAA,CAAQC,OAAO,EAAA;AACb,YAAA,IAAI,CAACA,OAAS,EAAA;AACZ,gBAAA,OAAO,EAAE;AACX;YAEA,MAAMC,QAAAA,GAAWC,WAAYF,CAAAA,OAA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AAAA,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/plops/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/plops/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,MAAM,CAAC;+BAU9B,WAAW;AAAjC,wBAoEE"}
|
package/dist/plops/middleware.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var tsUtils = require('@strapi/typescript-utils');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var fs = require('fs');
|
|
4
6
|
var getDestinationPrompts = require('./prompts/get-destination-prompts.js');
|
|
5
7
|
var validateInput = require('./utils/validate-input.js');
|
|
6
8
|
var getFilePath = require('./utils/get-file-path.js');
|
|
9
|
+
var extendPluginIndexFiles = require('./utils/extend-plugin-index-files.js');
|
|
7
10
|
|
|
8
11
|
var generateMiddleware = ((plop)=>{
|
|
9
12
|
// middleware generator
|
|
@@ -26,14 +29,44 @@ var generateMiddleware = ((plop)=>{
|
|
|
26
29
|
}
|
|
27
30
|
const filePath = getFilePath(answers.destination);
|
|
28
31
|
const currentDir = process.cwd();
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
33
|
+
if (answers.plugin) {
|
|
34
|
+
// The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
|
|
35
|
+
const pluginServerDir = path.join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
|
|
36
|
+
language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
|
|
37
|
+
}
|
|
38
|
+
const baseActions = [
|
|
31
39
|
{
|
|
32
40
|
type: 'add',
|
|
33
41
|
path: `${filePath}/middlewares/{{ name }}.${language}`,
|
|
34
42
|
templateFile: `templates/${language}/middleware.${language}.hbs`
|
|
35
43
|
}
|
|
36
44
|
];
|
|
45
|
+
if (answers.plugin) {
|
|
46
|
+
const indexPath = path.join(plop.getDestBasePath(), `${filePath}/middlewares/index.${language}`);
|
|
47
|
+
const exists = fs.existsSync(indexPath);
|
|
48
|
+
if (!exists) {
|
|
49
|
+
// Create index file if it doesn't exist
|
|
50
|
+
baseActions.push({
|
|
51
|
+
type: 'add',
|
|
52
|
+
path: `${filePath}/middlewares/index.${language}`,
|
|
53
|
+
templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
|
|
54
|
+
skipIfExists: true
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
// Append the new middleware to the index.ts file
|
|
58
|
+
baseActions.push({
|
|
59
|
+
type: 'modify',
|
|
60
|
+
path: `${filePath}/middlewares/index.${language}`,
|
|
61
|
+
transform (template) {
|
|
62
|
+
return extendPluginIndexFiles.appendToFile(template, {
|
|
63
|
+
type: 'index',
|
|
64
|
+
singularName: answers.name
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return baseActions;
|
|
37
70
|
}
|
|
38
71
|
});
|
|
39
72
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sources":["../../src/plops/middleware.ts"],"sourcesContent":["import type { NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport validateInput from './utils/validate-input';\nimport getFilePath from './utils/get-file-path';\n\nexport default (plop: NodePlopAPI) => {\n // middleware generator\n plop.setGenerator('middleware', {\n description: 'Generate a middleware for an API',\n prompts: [\n {\n type: 'input',\n name: 'name',\n message: 'Middleware name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('middleware', plop.getDestBasePath(), { rootFolder: true }),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n
|
|
1
|
+
{"version":3,"file":"middleware.js","sources":["../../src/plops/middleware.ts"],"sourcesContent":["import type { ActionType, NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport { join } from 'path';\nimport fs from 'fs';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport validateInput from './utils/validate-input';\nimport getFilePath from './utils/get-file-path';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // middleware generator\n plop.setGenerator('middleware', {\n description: 'Generate a middleware for an API',\n prompts: [\n {\n type: 'input',\n name: 'name',\n message: 'Middleware name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('middleware', plop.getDestBasePath(), { rootFolder: true }),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\n const currentDir = process.cwd();\n let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/middlewares/{{ name }}.${language}`,\n templateFile: `templates/${language}/middleware.${language}.hbs`,\n },\n ];\n\n if (answers.plugin) {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/middlewares/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/middlewares/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new middleware to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/middlewares/index.${language}`,\n transform(template: string) {\n return appendToFile(template, { type: 'index', singularName: answers.name });\n },\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","getDestinationPrompts","getDestBasePath","rootFolder","actions","answers","filePath","getFilePath","destination","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","join","replace","baseActions","path","templateFile","indexPath","exists","fs","existsSync","push","skipIfExists","transform","template","appendToFile","singularName"],"mappings":";;;;;;;;;;AAUA,yBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,YAAc,EAAA;QAC9BC,WAAa,EAAA,kCAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,MAAA;gBACNC,OAAS,EAAA,iBAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,aAAcD,CAAAA,KAAAA;AACrC,aAAA;eACGE,qBAAsB,CAAA,YAAA,EAAcV,IAAKW,CAAAA,eAAe,EAAI,EAAA;gBAAEC,UAAY,EAAA;AAAK,aAAA;AACnF,SAAA;AACDC,QAAAA,OAAAA,CAAAA,CAAQC,OAAO,EAAA;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,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,7 +1,10 @@
|
|
|
1
1
|
import tsUtils from '@strapi/typescript-utils';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
2
4
|
import getDestinationPrompts from './prompts/get-destination-prompts.mjs';
|
|
3
5
|
import validateInput from './utils/validate-input.mjs';
|
|
4
6
|
import getFilePath from './utils/get-file-path.mjs';
|
|
7
|
+
import { appendToFile } from './utils/extend-plugin-index-files.mjs';
|
|
5
8
|
|
|
6
9
|
var generateMiddleware = ((plop)=>{
|
|
7
10
|
// middleware generator
|
|
@@ -24,14 +27,44 @@ var generateMiddleware = ((plop)=>{
|
|
|
24
27
|
}
|
|
25
28
|
const filePath = getFilePath(answers.destination);
|
|
26
29
|
const currentDir = process.cwd();
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
31
|
+
if (answers.plugin) {
|
|
32
|
+
// The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
|
|
33
|
+
const pluginServerDir = join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
|
|
34
|
+
language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
|
|
35
|
+
}
|
|
36
|
+
const baseActions = [
|
|
29
37
|
{
|
|
30
38
|
type: 'add',
|
|
31
39
|
path: `${filePath}/middlewares/{{ name }}.${language}`,
|
|
32
40
|
templateFile: `templates/${language}/middleware.${language}.hbs`
|
|
33
41
|
}
|
|
34
42
|
];
|
|
43
|
+
if (answers.plugin) {
|
|
44
|
+
const indexPath = join(plop.getDestBasePath(), `${filePath}/middlewares/index.${language}`);
|
|
45
|
+
const exists = fs.existsSync(indexPath);
|
|
46
|
+
if (!exists) {
|
|
47
|
+
// Create index file if it doesn't exist
|
|
48
|
+
baseActions.push({
|
|
49
|
+
type: 'add',
|
|
50
|
+
path: `${filePath}/middlewares/index.${language}`,
|
|
51
|
+
templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
|
|
52
|
+
skipIfExists: true
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
// Append the new middleware to the index.ts file
|
|
56
|
+
baseActions.push({
|
|
57
|
+
type: 'modify',
|
|
58
|
+
path: `${filePath}/middlewares/index.${language}`,
|
|
59
|
+
transform (template) {
|
|
60
|
+
return appendToFile(template, {
|
|
61
|
+
type: 'index',
|
|
62
|
+
singularName: answers.name
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return baseActions;
|
|
35
68
|
}
|
|
36
69
|
});
|
|
37
70
|
});
|