UNPKG

@builder.io/dev-tools

Version:

Builder.io Visual CMS Devtools

87 lines (86 loc) 2.88 kB
import { type SelectOptions, type ConfirmOptions, type TextOptions } from "@clack/prompts"; import { spinner } from "./spinner"; import type { WebSocket } from "ws"; export interface IOService { log(str: string): void; info(str: string): void; warn(str: string): void; error(str: string): void; write(text: string): void; writeMetadata(metadata: Record<string, any>): void; confirm(options: ConfirmOptions): Promise<boolean | symbol>; text(options: TextOptions): Promise<string | symbol>; select<Value>(options: SelectOptions<Value>): Promise<Value | symbol>; createSpinner(): ReturnType<typeof spinner>; isInteractive(): boolean; isTTY(): boolean; exit(code: number): Promise<void>; } export declare class ConsoleIOService implements IOService { log(str: string): void; info(str: string): void; warn(str: string): void; error(str: string): void; write(text: string): void; writeMetadata(_: Record<string, any>): void; confirm(options: ConfirmOptions): Promise<boolean | symbol>; text(options: TextOptions): Promise<string | symbol>; select<Value>(options: SelectOptions<Value>): Promise<Value | symbol>; createSpinner(): ReturnType<typeof spinner>; isInteractive(): boolean; isTTY(): boolean; exit(code: number): Promise<void>; } export interface BaseMessage { type: string; [key: string]: any; } export interface LogMessage extends BaseMessage { type: "log"; level: "info" | "warn" | "error"; message: string; } export interface WriteMessage extends BaseMessage { type: "write"; text: string; } export interface SpinnerMessage extends BaseMessage { type: "spinner"; status: "start" | "stop"; message: string; code?: number; } export interface PromptRequest extends BaseMessage { type: "prompt"; promptType: "text" | "confirm" | "select"; options: any; requestId: string; } export interface PromptResponse extends BaseMessage { type: "prompt_response"; requestId: string; value: any; cancelled?: boolean; } export declare class WebSocketIOService implements IOService { private ws; private promptCallbacks; private messageQueue; private isProcessing; constructor(ws: WebSocket); private sendMessage; private prompt; log(...args: any[]): void; info(...args: any[]): void; warn(...args: any[]): void; error(...args: any[]): void; write(text: string): void; writeMetadata(metadata: Record<string, any>): void; confirm(options: ConfirmOptions): Promise<boolean | symbol>; text(options: TextOptions): Promise<string | symbol>; select<Value>(options: SelectOptions<Value>): Promise<Value | symbol>; createSpinner(): ReturnType<typeof spinner>; isInteractive(): boolean; isTTY(): boolean; exit(code: number): Promise<void>; }