{"version":3,"file":"add-plugin-to-config.cjs","sources":["../../../src/cli/utils/add-plugin-to-config.ts"],"sourcesContent":["import fs from \"fs/promises\";\nimport { addImport } from \"./add-import\";\nimport { addPlugin } from \"./add-plugin\";\n\n/**\n * Add a plugin to the configuration file.\n * @param {Object} options - The options for adding the plugin.\n * @param {string} options.configKey - The key in the configuration file where the plugin will be added.\n * @param {string} options.configPath - The path to the configuration file.\n * @param {string} options.pluginImportPath - The import path of the plugin.\n * @param {string} options.pluginName - The name of the plugin.\n */\nexport async function addPluginToConfig({\n  configKey,\n  configPath,\n  pluginImportPath,\n  pluginName,\n}: {\n  configKey: string;\n  configPath: string;\n  pluginImportPath: string;\n  pluginName: string;\n}) {\n  try {\n    const content = await fs.readFile(configPath, \"utf-8\");\n\n    // Add the import statement for the plugin\n    const updatedContentWithImport = addImport({\n      content,\n      importPath: pluginImportPath,\n      importName: pluginName,\n    });\n\n    // Add the plugin to the configuration\n    const finalUpdatedContent = addPlugin({\n      content: updatedContentWithImport,\n      targetPath: configKey,\n      pluginName,\n    });\n\n    if (finalUpdatedContent !== content) {\n      console.log(`Updating ${configPath} with ${pluginName} plugin...`);\n      await fs.writeFile(configPath, finalUpdatedContent, \"utf-8\");\n    }\n  } catch (error) {\n    console.error(`Failed to setup ${pluginName} plugin:`, error);\n  }\n}\n"],"names":["addImport","addPlugin"],"mappings":";;;;;;AAIO,eAAe,iBAAiB,CAAC;AACxC,EAAE,SAAS;AACX,EAAE,UAAU;AACZ,EAAE,gBAAgB;AAClB,EAAE;AACF,CAAC,EAAE;AACH,EAAE,IAAI;AACN,IAAI,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;AAC1D,IAAI,MAAM,wBAAwB,GAAGA,mBAAS,CAAC;AAC/C,MAAM,OAAO;AACb,MAAM,UAAU,EAAE,gBAAgB;AAClC,MAAM,UAAU,EAAE;AAClB,KAAK,CAAC;AACN,IAAI,MAAM,mBAAmB,GAAGC,mBAAS,CAAC;AAC1C,MAAM,OAAO,EAAE,wBAAwB;AACvC,MAAM,UAAU,EAAE,SAAS;AAC3B,MAAM;AACN,KAAK,CAAC;AACN,IAAI,IAAI,mBAAmB,KAAK,OAAO,EAAE;AACzC,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;AACxE,MAAM,MAAM,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,mBAAmB,EAAE,OAAO,CAAC;AAClE,IAAI;AACJ,EAAE,CAAC,CAAC,OAAO,KAAK,EAAE;AAClB,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,gBAAgB,EAAE,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC;AACjE,EAAE;AACF;;;;"}