{"version":3,"file":"update-build-config.cjs","sources":["../../../src/cli/utils/update-build-config.ts"],"sourcesContent":["import { parse } from \"@typescript-eslint/typescript-estree\";\nimport * as recast from \"recast\";\nimport { addImport } from \"./add-import\";\n\n/**\n * Updates the build configuration by adding a plugin to the build options.\n *\n * @param {Object} options - The options for updating the build config.\n * @param {string} options.content - The source code content to modify.\n * @param {string} [options.pluginName='flowbiteReact'] - The name to use for the imported plugin.\n * @param {string} options.pluginImportPath - The import path for the plugin.\n * @returns {string} The modified source code with the plugin added.\n */\nexport function updateBuildConfig({\n  content,\n  pluginName,\n  pluginImportPath,\n}: {\n  content: string;\n  pluginName: string;\n  pluginImportPath: string;\n}): string {\n  // Parse the content first\n  const ast = recast.parse(content, {\n    parser: {\n      parse: (source: string) =>\n        parse(source, {\n          loc: true,\n          range: true,\n          tokens: true,\n          comment: true,\n        }),\n    },\n  });\n\n  const b = recast.types.builders;\n\n  // Visit the AST to find build({...}) calls\n  recast.types.visit(ast, {\n    visitCallExpression(path) {\n      const { node } = path;\n\n      // Check if this is a build() or Bun.build() call\n      if (\n        ((node.callee.type === \"Identifier\" && node.callee.name === \"build\") ||\n          (node.callee.type === \"MemberExpression\" &&\n            node.callee.object.type === \"Identifier\" &&\n            node.callee.object.name === \"Bun\" &&\n            node.callee.property.type === \"Identifier\" &&\n            node.callee.property.name === \"build\")) &&\n        node.arguments.length > 0 &&\n        node.arguments[0].type === \"ObjectExpression\"\n      ) {\n        const buildOptions = node.arguments[0];\n\n        // Find or create plugins property\n        let pluginsProperty = buildOptions.properties.find(\n          (p): p is recast.types.namedTypes.Property =>\n            p.type === \"Property\" &&\n            ((p.key.type === \"Identifier\" && p.key.name === \"plugins\") ||\n              (p.key.type === \"Literal\" && p.key.value === \"plugins\")),\n        );\n\n        if (!pluginsProperty) {\n          // Create new plugins array with our plugin\n          pluginsProperty = b.property(\"init\", b.identifier(\"plugins\"), b.arrayExpression([b.identifier(pluginName)]));\n          buildOptions.properties.push(pluginsProperty);\n        } else if (pluginsProperty.value.type === \"ArrayExpression\") {\n          // Check if plugin already exists in array\n          const hasPlugin = pluginsProperty.value.elements.some(\n            (el) => el?.type === \"Identifier\" && el.name === pluginName,\n          );\n\n          if (!hasPlugin) {\n            // Add plugin to existing array\n            pluginsProperty.value.elements.push(b.identifier(pluginName));\n          }\n        }\n      }\n\n      return false;\n    },\n  });\n\n  // Get the modified code\n  let modifiedCode = recast.print(ast).code;\n\n  // Now add the import using the existing utility\n  modifiedCode = addImport({\n    content: modifiedCode,\n    importName: pluginName,\n    importPath: pluginImportPath,\n  });\n\n  return modifiedCode;\n}\n"],"names":["recast","parse","addImport"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAIO,SAAS,iBAAiB,CAAC;AAClC,EAAE,OAAO;AACT,EAAE,UAAU;AACZ,EAAE;AACF,CAAC,EAAE;AACH,EAAE,MAAM,GAAG,GAAGA,iBAAM,CAAC,KAAK,CAAC,OAAO,EAAE;AACpC,IAAI,MAAM,EAAE;AACZ,MAAM,KAAK,EAAE,CAAC,MAAM,KAAKC,sBAAK,CAAC,MAAM,EAAE;AACvC,QAAQ,GAAG,EAAE,IAAI;AACjB,QAAQ,KAAK,EAAE,IAAI;AACnB,QAAQ,MAAM,EAAE,IAAI;AACpB,QAAQ,OAAO,EAAE;AACjB,OAAO;AACP;AACA,GAAG,CAAC;AACJ,EAAE,MAAM,CAAC,GAAGD,iBAAM,CAAC,KAAK,CAAC,QAAQ;AACjC,EAAEA,iBAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE;AAC1B,IAAI,mBAAmB,CAAC,IAAI,EAAE;AAC9B,MAAM,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI;AAC3B,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,YAAY,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,kBAAkB,IAAI,IAAI,CAAC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