{"version":3,"file":"presenter.cjs","names":[],"sources":["../../../../src/cli/commands/sync/presenter.ts"],"sourcesContent":["/**\n * Step-by-step progress for `doompi sync`.\n *\n * Sync spends almost all of its wall clock in three places a user cannot see:\n * the registry check, the mode build, and the runtime precompile. A terminal\n * gets a live line that the finished step overwrites, so the transcript stays\n * as short as the existing summary. Anything else (a pipe, CI, the embedded\n * dpi runner) gets one line per completed step and no escape sequences.\n */\n\nconst LABEL_WIDTH = 10;\nconst ANSI_ESCAPE = String.fromCharCode(0x1b);\nconst CLEAR_LINE = `${ANSI_ESCAPE}[2K\\r`;\nconst MILLISECONDS_PER_SECOND = 1000;\n\nexport interface SyncProgressOutput {\n  write: NodeJS.WritableStream['write'];\n  isTTY?: boolean;\n}\n\n/** Closes the step a `start` call opened, recording how long it took. */\nexport type SyncStepDone = (summary: string) => void;\n\nexport function formatProgressLine(label: string, message: string): string {\n  return `${`${label}:`.padEnd(LABEL_WIDTH)}${message}`;\n}\n\nfunction formatElapsed(milliseconds: number): string {\n  return `${(milliseconds / MILLISECONDS_PER_SECOND).toFixed(1)}s`;\n}\n\n/** Reports sync phases as they run rather than only after everything is done. */\nexport class SyncProgress {\n  private readonly output: SyncProgressOutput;\n  private readonly now: () => number;\n  private live = false;\n\n  constructor(output: SyncProgressOutput, now: () => number = Date.now) {\n    this.output = output;\n    this.now = now;\n  }\n\n  /** Opens a timed step and returns the call that closes it. */\n  start(label: string, message: string): SyncStepDone {\n    const startedAt = this.now();\n    this.drawLive(formatProgressLine(label, `${message}...`));\n    return (summary) => {\n      this.clearLive();\n      this.output.write(`${formatProgressLine(label, `${summary} (${formatElapsed(this.now() - startedAt)})`)}\\n`);\n    };\n  }\n\n  /** Writes a standalone line, such as one package moving to a new version. */\n  line(label: string, message: string): void {\n    this.clearLive();\n    this.output.write(`${formatProgressLine(label, message)}\\n`);\n  }\n\n  private drawLive(text: string): void {\n    if (!this.output.isTTY) return;\n    this.output.write(`${CLEAR_LINE}${text}`);\n    this.live = true;\n  }\n\n  private clearLive(): void {\n    if (!this.live) return;\n    this.output.write(CLEAR_LINE);\n    this.live = false;\n  }\n}\n"],"mappings":";;;;;;;;;;AAUA,MAAM,cAAc;AAEpB,MAAM,aAAa,GADC,OAAO,aAAa,EACR,EAAE;AAClC,MAAM,0BAA0B;AAUhC,SAAgB,mBAAmB,OAAe,SAAyB;CACzE,OAAO,GAAG,GAAG,MAAM,GAAG,OAAO,WAAW,IAAI;AAC9C;AAEA,SAAS,cAAc,cAA8B;CACnD,OAAO,IAAI,eAAe,wBAAA,CAAyB,QAAQ,CAAC,EAAE;AAChE;;AAGA,IAAa,eAAb,MAA0B;CACxB;CACA;CACA,OAAe;CAEf,YAAY,QAA4B,MAAoB,KAAK,KAAK;EACpE,KAAK,SAAS;EACd,KAAK,MAAM;CACb;;CAGA,MAAM,OAAe,SAA+B;EAClD,MAAM,YAAY,KAAK,IAAI;EAC3B,KAAK,SAAS,mBAAmB,OAAO,GAAG,QAAQ,IAAI,CAAC;EACxD,QAAQ,YAAY;GAClB,KAAK,UAAU;GACf,KAAK,OAAO,MAAM,GAAG,mBAAmB,OAAO,GAAG,QAAQ,IAAI,cAAc,KAAK,IAAI,IAAI,SAAS,EAAE,EAAE,EAAE,GAAG;EAC7G;CACF;;CAGA,KAAK,OAAe,SAAuB;EACzC,KAAK,UAAU;EACf,KAAK,OAAO,MAAM,GAAG,mBAAmB,OAAO,OAAO,EAAE,GAAG;CAC7D;CAEA,SAAiB,MAAoB;EACnC,IAAI,CAAC,KAAK,OAAO,OAAO;EACxB,KAAK,OAAO,MAAM,GAAG,aAAa,MAAM;EACxC,KAAK,OAAO;CACd;CAEA,YAA0B;EACxB,IAAI,CAAC,KAAK,MAAM;EAChB,KAAK,OAAO,MAAM,UAAU;EAC5B,KAAK,OAAO;CACd;AACF"}