import { execa } from "execa";
class CLIExecutor {
  async executeCommand(args = []) {
    try {
      const command = "npx";
      const fullArgs = ["-y", "@glide/glide-ui@latest", ...args];
      const { stdout, stderr, exitCode } = await execa(command, fullArgs, {
        reject: false,
        cwd: process.cwd(),
        shell: false,
        env: {
          ...process.env,
          NODE_ENV: "production"
        }
      });
      if (exitCode !== 0) {
        throw new Error(
          `Command failed with exit code ${exitCode}: ${stderr || stdout}`
        );
      }
      if (!stdout || stdout.trim() === "") {
        return {};
      }
      try {
        return JSON.parse(stdout);
      } catch {
        return stdout;
      }
    } catch (error) {
      throw new Error(
        `CLI execution failed: ${error instanceof Error ? error.message : String(error)}`
      );
    }
  }
  async listComponents() {
    const result = await this.executeCommand(["components:list", "--json"]);
    if (typeof result === "object" && result !== null && "components" in result) {
      return result.components;
    }
    return result;
  }
  async getComponentInfo(componentName) {
    const result = await this.executeCommand([
      "components:info",
      "-t",
      componentName,
      "--json"
    ]);
    return result;
  }
  async getComponentByName(name) {
    return this.getComponentInfo(name);
  }
}
export {
  CLIExecutor
};
