@strapi/generators
Version:
Interactive API generator.
1 lines • 2.41 kB
Source Map (JSON)
{"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 const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n return [\n {\n type: 'add',\n path: `${filePath}/controllers/{{ id }}.${language}`,\n templateFile: `templates/${language}/controller.${language}.hbs`,\n },\n ];\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","getDestinationPrompts","getDestBasePath","actions","answers","filePath","getFilePath","destination","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","path","templateFile"],"mappings":";;;;;AAOA,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,OAAAA,CAAQG,WAAW,CAAA;YAChD,MAAMC,UAAAA,GAAaC,QAAQC,GAAG,EAAA;AAC9B,YAAA,MAAMC,QAAWC,GAAAA,OAAAA,CAAQC,qBAAqB,CAACL,cAAc,IAAO,GAAA,IAAA;YAEpE,OAAO;AACL,gBAAA;oBACEb,IAAM,EAAA,KAAA;AACNmB,oBAAAA,IAAAA,EAAM,CAAC,EAAET,QAAAA,CAAS,sBAAsB,EAAEM,SAAS,CAAC;oBACpDI,YAAc,EAAA,CAAC,UAAU,EAAEJ,QAAAA,CAAS,YAAY,EAAEA,QAAAA,CAAS,IAAI;AACjE;AACD,aAAA;AACH;AACF,KAAA,CAAA;AACF,CAAA;;;;"}