{"version":3,"file":"index.cjs","names":["mswGenerator","handlersGenerator","pluginOasName","pluginTsName","pluginFakerName","path","options","groupName: Group['name']","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = definePlugin<PluginMsw>((options) => {\n  const {\n    output = { path: 'handlers', barrelType: 'named' },\n    group,\n    exclude = [],\n    include,\n    override = [],\n    transformers = {},\n    handlers = false,\n    parser = 'data',\n    generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n    contentType,\n    baseURL,\n  } = options\n\n  return {\n    name: pluginMswName,\n    options: {\n      output,\n      parser,\n      group,\n      baseURL,\n    },\n    pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),\n    resolvePath(baseName, pathMode, options) {\n      const root = path.resolve(this.config.root, this.config.output.path)\n      const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n      if (mode === 'single') {\n        /**\n         * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n         * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n         */\n        return path.resolve(root, output.path)\n      }\n\n      if (group && (options?.group?.path || options?.group?.tag)) {\n        const groupName: Group['name'] = group?.name\n          ? group.name\n          : (ctx) => {\n              if (group?.type === 'path') {\n                return `${ctx.group.split('/')[1]}`\n              }\n              return `${camelCase(ctx.group)}Controller`\n            }\n\n        return path.resolve(\n          root,\n          output.path,\n          groupName({\n            group: group.type === 'path' ? options.group.path! : options.group.tag!,\n          }),\n          baseName,\n        )\n      }\n\n      return path.resolve(root, output.path, baseName)\n    },\n    resolveName(name, type) {\n      const resolvedName = camelCase(name, {\n        suffix: type ? 'handler' : undefined,\n        isFile: type === 'file',\n      })\n\n      if (type) {\n        return transformers?.name?.(resolvedName, type) || resolvedName\n      }\n\n      return resolvedName\n    },\n    async install() {\n      const root = path.resolve(this.config.root, this.config.output.path)\n      const mode = getMode(path.resolve(root, output.path))\n      const oas = await this.getOas()\n\n      const operationGenerator = new OperationGenerator(this.plugin.options, {\n        fabric: this.fabric,\n        oas,\n        pluginManager: this.pluginManager,\n        plugin: this.plugin,\n        contentType,\n        exclude,\n        include,\n        override,\n        mode,\n      })\n\n      const files = await operationGenerator.build(...generators)\n      await this.addFile(...files)\n\n      const barrelFiles = await getBarrelFiles(this.fabric.files, {\n        type: output.barrelType ?? 'named',\n        root,\n        output,\n        meta: {\n          pluginKey: this.plugin.key,\n        },\n        logger: this.logger,\n      })\n\n      await this.addFile(...barrelFiles)\n    },\n  }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAa,gBAAgB;AAE7B,MAAa,2CAAqC,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAY,YAAY;EAAS,EAClD,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,WAAW,OACX,SAAS,QACT,aAAa,CAACA,iCAAc,WAAWC,uCAAoB,OAAU,CAAC,OAAO,QAAQ,EACrF,aACA,YACE;AAEJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA;GACA;GACD;EACD,KAAK;GAACC;GAAeC;GAAc,WAAW,UAAUC,sCAAkB;GAAU,CAAC,OAAO,QAAQ;EACpG,YAAY,UAAU,UAAU,WAAS;GACvC,MAAM,OAAOC,kBAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;AAGpE,QAFa,qCAAoBA,kBAAK,QAAQ,MAAM,OAAO,KAAK,CAAC,MAEp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