UNPKG

@strapi/generators

Version:

Interactive API generator.

1 lines 2.19 kB
{"version":3,"file":"service.mjs","sources":["../../src/plops/service.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';\n\nexport default (plop: NodePlopAPI) => {\n // Service generator\n plop.setGenerator('service', {\n description: 'Generate a service for an API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'Service name',\n },\n ...getDestinationPrompts('service', 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}/services/{{ id }}.${language}`,\n templateFile: `templates/${language}/service.${language}.hbs`,\n },\n ];\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","getDestinationPrompts","getDestBasePath","actions","answers","filePath","getFilePath","destination","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","path","templateFile"],"mappings":";;;;AAMA,sBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,SAAW,EAAA;QAC3BC,WAAa,EAAA,+BAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,IAAA;gBACNC,OAAS,EAAA;AACX,aAAA;eACGC,qBAAsB,CAAA,SAAA,EAAWP,KAAKQ,eAAe,EAAA;AACzD,SAAA;AACDC,QAAAA,OAAAA,CAAAA,CAAQC,OAAO,EAAA;AACb,YAAA,IAAI,CAACA,OAAS,EAAA;AACZ,gBAAA,OAAO,EAAE;AACX;YAEA,MAAMC,QAAAA,GAAWC,YAAYF,OAASG,EAAAA,WAAAA,CAAAA;YACtC,MAAMC,UAAAA,GAAaC,QAAQC,GAAG,EAAA;AAC9B,YAAA,MAAMC,QAAWC,GAAAA,OAAAA,CAAQC,qBAAqB,CAACL,cAAc,IAAO,GAAA,IAAA;YAEpE,OAAO;AACL,gBAAA;oBACEV,IAAM,EAAA,KAAA;AACNgB,oBAAAA,IAAAA,EAAM,CAAC,EAAET,QAAAA,CAAS,mBAAmB,EAAEM,SAAS,CAAC;oBACjDI,YAAc,EAAA,CAAC,UAAU,EAAEJ,QAAAA,CAAS,SAAS,EAAEA,QAAAA,CAAS,IAAI;AAC9D;AACD,aAAA;AACH;AACF,KAAA,CAAA;AACF,CAAA;;;;"}