{"version":3,"file":"get-generator-language.mjs","sources":["../../../src/plops/utils/get-generator-language.ts"],"sourcesContent":["import { dirname, join } from 'node:path';\nimport tsUtils from '@strapi/typescript-utils';\nimport type { NodePlopAPI } from 'plop';\n\ntype GetGeneratorLanguageOptions = {\n plugin?: string;\n filePath: string;\n};\n\n/**\n * Detect whether generated files should use TypeScript or JavaScript templates.\n *\n * For plugin generation, the check is scoped to the plugin server directory derived\n * from the generator output path. For everything else, it checks the `dir` option\n * passed to `generate()` (via `getDestBasePath()`).\n */\nconst getGeneratorLanguage = (\n { plugin, filePath }: GetGeneratorLanguageOptions,\n plop: Pick\n): 'ts' | 'js' => {\n if (plugin) {\n const resolvedFilePath = filePath.replace('{{ plugin }}', plugin);\n const pluginServerDir = join(plop.getDestBasePath(), resolvedFilePath, '..');\n\n return tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n return tsUtils.isUsingTypeScriptSync(dirname(plop.getDestBasePath())) ? 'ts' : 'js';\n};\n\nexport default getGeneratorLanguage;\n"],"names":["getGeneratorLanguage","plugin","filePath","plop","resolvedFilePath","replace","pluginServerDir","join","getDestBasePath","tsUtils","isUsingTypeScriptSync","dirname"],"mappings":";;;AASA;;;;;;IAOA,MAAMA,uBAAuB,CAC3B,EAAEC,MAAM,EAAEC,QAAQ,EAA+B,EACjDC,IAAAA,GAAAA;AAEA,IAAA,IAAIF,MAAAA,EAAQ;AACV,QAAA,MAAMG,gBAAAA,GAAmBF,QAAAA,CAASG,OAAO,CAAC,cAAA,EAAgBJ,MAAAA,CAAAA;AAC1D,QAAA,MAAMK,eAAAA,GAAkBC,IAAAA,CAAKJ,IAAAA,CAAKK,eAAe,IAAIJ,gBAAAA,EAAkB,IAAA,CAAA;AAEvE,QAAA,OAAOK,OAAAA,CAAQC,qBAAqB,CAACJ,eAAAA,CAAAA,GAAmB,IAAA,GAAO,IAAA;AACjE,IAAA;AAEA,IAAA,OAAOG,QAAQC,qBAAqB,CAACC,QAAQR,IAAAA,CAAKK,eAAe,OAAO,IAAA,GAAO,IAAA;AACjF;;;;"}