@rudderhq/cli 0.2.1-canary.3 → 0.2.1-canary.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6178,6 +6178,70 @@ var DESKTOP_APP_NAME = "Rudder";
6178
6178
  var DESKTOP_METADATA_FILE = ".rudder-desktop-install.json";
6179
6179
  var DESKTOP_CHECKSUM_ASSET_NAME = "SHASUMS256.txt";
6180
6180
  var GITHUB_ASSET_DOWNLOAD_ACCEPT = "application/octet-stream";
6181
+ function normalizeProgressTotal(totalBytes) {
6182
+ return typeof totalBytes === "number" && Number.isFinite(totalBytes) && totalBytes > 0 ? totalBytes : null;
6183
+ }
6184
+ function writeDesktopProgress(event) {
6185
+ const payload = {
6186
+ source: "rudder-desktop-update",
6187
+ ...event,
6188
+ at: (/* @__PURE__ */ new Date()).toISOString()
6189
+ };
6190
+ try {
6191
+ process.stdout.write(`${JSON.stringify(payload)}
6192
+ `);
6193
+ } catch (error) {
6194
+ const code = typeof error === "object" && error && "code" in error ? String(error.code) : "";
6195
+ if (code !== "EPIPE") throw error;
6196
+ }
6197
+ }
6198
+ function desktopDownloadPhase(label) {
6199
+ return label.toLowerCase().includes("shasums") ? "downloading_checksums" : "downloading_asset";
6200
+ }
6201
+ function createDesktopProgressFactory() {
6202
+ return (label) => {
6203
+ const phase = desktopDownloadPhase(label);
6204
+ let latestReceivedBytes = 0;
6205
+ let latestTotalBytes = null;
6206
+ function emitByteProgress(message, receivedBytes, totalBytes) {
6207
+ const total = normalizeProgressTotal(totalBytes);
6208
+ writeDesktopProgress({
6209
+ phase,
6210
+ message,
6211
+ transferredBytes: Math.max(0, receivedBytes),
6212
+ ...total === null ? {} : {
6213
+ totalBytes: total,
6214
+ percent: Math.max(0, Math.min(100, Math.floor(Math.max(0, receivedBytes) / total * 100)))
6215
+ }
6216
+ });
6217
+ }
6218
+ return {
6219
+ start(totalBytes) {
6220
+ latestReceivedBytes = 0;
6221
+ latestTotalBytes = totalBytes;
6222
+ emitByteProgress(label, 0, totalBytes);
6223
+ },
6224
+ update(receivedBytes, totalBytes) {
6225
+ latestReceivedBytes = receivedBytes;
6226
+ latestTotalBytes = totalBytes;
6227
+ emitByteProgress(label, receivedBytes, totalBytes);
6228
+ },
6229
+ finish(receivedBytes = latestReceivedBytes, totalBytes = latestTotalBytes) {
6230
+ latestReceivedBytes = receivedBytes;
6231
+ latestTotalBytes = totalBytes;
6232
+ emitByteProgress(`${label} complete`, receivedBytes, totalBytes);
6233
+ },
6234
+ fail() {
6235
+ writeDesktopProgress({
6236
+ phase,
6237
+ message: `${label} failed`,
6238
+ transferredBytes: Math.max(0, latestReceivedBytes),
6239
+ error: `${label} failed`
6240
+ });
6241
+ }
6242
+ };
6243
+ };
6244
+ }
6181
6245
  function resolveCurrentCliVersion(env = process.env) {
6182
6246
  const version = resolveCliVersion(import.meta.url, env);
6183
6247
  return version === "0.0.0" ? "latest" : version;
@@ -6730,15 +6794,28 @@ async function writeInstallMetadata(paths, releaseTag, assetName, assetChecksum)
6730
6794
  await writeFile2(paths.metadataPath, `${JSON.stringify(metadata, null, 2)}
6731
6795
  `, "utf8");
6732
6796
  }
6733
- async function runStartPhase(message, successMessage, task) {
6797
+ async function runStartPhase(message, successMessage, task, progressPhase) {
6798
+ if (progressPhase) {
6799
+ writeDesktopProgress({ phase: progressPhase, message });
6800
+ }
6734
6801
  const spinner3 = p13.spinner();
6735
6802
  spinner3.start(message);
6736
6803
  try {
6737
6804
  const result = await task();
6738
6805
  spinner3.stop(successMessage);
6806
+ if (progressPhase) {
6807
+ writeDesktopProgress({ phase: progressPhase, message: successMessage });
6808
+ }
6739
6809
  return result;
6740
6810
  } catch (error) {
6741
6811
  spinner3.stop(pc8.red(`${message} failed.`));
6812
+ if (progressPhase) {
6813
+ writeDesktopProgress({
6814
+ phase: "failed",
6815
+ message: `${message} failed.`,
6816
+ error: error instanceof Error ? error.message : String(error)
6817
+ });
6818
+ }
6742
6819
  throw error;
6743
6820
  }
6744
6821
  }
@@ -6749,6 +6826,12 @@ async function startCommand(opts) {
6749
6826
  const repo = opts.repo?.trim() || DEFAULT_DESKTOP_RELEASE_REPO;
6750
6827
  const version = opts.targetVersion?.trim() || opts.version?.trim() || resolveCurrentCliVersion();
6751
6828
  const dryRun = opts.dryRun === true;
6829
+ const desktopProgressJson = opts.desktopProgressJson === true;
6830
+ if (desktopProgressJson) {
6831
+ process.stdout.on("error", (error) => {
6832
+ if (error.code !== "EPIPE") throw error;
6833
+ });
6834
+ }
6752
6835
  if (!installCli && !installDesktop && !installRuntime) {
6753
6836
  throw new Error("Nothing to start. Remove --no-cli, --no-runtime, or --no-desktop.");
6754
6837
  }
@@ -6822,13 +6905,14 @@ async function startCommand(opts) {
6822
6905
  return;
6823
6906
  }
6824
6907
  const directReleaseVersion = resolveDesktopReleaseVersion(tag);
6825
- const progressFactory = createByteProgress;
6908
+ const progressFactory = desktopProgressJson ? createDesktopProgressFactory() : createByteProgress;
6826
6909
  let release = null;
6827
6910
  try {
6828
6911
  release = await runStartPhase(
6829
6912
  "Resolving Desktop release...",
6830
6913
  "Desktop release resolved.",
6831
- () => fetchGithubRelease(repo, tag)
6914
+ () => fetchGithubRelease(repo, tag),
6915
+ desktopProgressJson ? "resolving_release" : null
6832
6916
  );
6833
6917
  } catch (error) {
6834
6918
  if (!directReleaseVersion) throw error;
@@ -6856,24 +6940,28 @@ async function startCommand(opts) {
6856
6940
  async () => {
6857
6941
  await removeMacQuarantine(installPaths, target);
6858
6942
  await createPlatformLaunchers(installPaths, target);
6859
- }
6943
+ },
6944
+ desktopProgressJson ? "preparing_restart" : null
6860
6945
  );
6861
6946
  } else {
6862
6947
  const installerPath = await downloadAsset(asset, outputDir, progressFactory);
6863
6948
  const checksum = await runStartPhase(
6864
6949
  "Verifying Desktop checksum...",
6865
6950
  `Verified ${pc8.cyan(path11.basename(installerPath))}.`,
6866
- () => assertChecksumMatch(installerPath, expectedChecksum)
6951
+ () => assertChecksumMatch(installerPath, expectedChecksum),
6952
+ desktopProgressJson ? "verifying_checksum" : null
6867
6953
  );
6868
6954
  await runStartPhase(
6869
6955
  "Replacing existing Rudder Desktop if needed...",
6870
6956
  "Existing Desktop install is ready for replacement.",
6871
- () => prepareForDesktopReplace(installPaths, target, { waitForActiveRuns: opts.waitForActiveRuns === true })
6957
+ () => prepareForDesktopReplace(installPaths, target, { waitForActiveRuns: opts.waitForActiveRuns === true }),
6958
+ desktopProgressJson ? opts.waitForActiveRuns === true ? "waiting_for_active_runs" : "preparing_restart" : null
6872
6959
  );
6873
6960
  await runStartPhase(
6874
6961
  "Installing portable Desktop app...",
6875
6962
  `Installed Rudder Desktop to ${pc8.cyan(installPaths.appPath)}.`,
6876
- () => installPortableDesktop(installerPath, installPaths, target)
6963
+ () => installPortableDesktop(installerPath, installPaths, target),
6964
+ desktopProgressJson ? "preparing_restart" : null
6877
6965
  );
6878
6966
  await runStartPhase(
6879
6967
  "Preparing Desktop launchers...",
@@ -6881,7 +6969,8 @@ async function startCommand(opts) {
6881
6969
  async () => {
6882
6970
  await removeMacQuarantine(installPaths, target);
6883
6971
  await createPlatformLaunchers(installPaths, target);
6884
- }
6972
+ },
6973
+ desktopProgressJson ? "preparing_restart" : null
6885
6974
  );
6886
6975
  await writeInstallMetadata(installPaths, releaseTag, asset.name, checksum);
6887
6976
  }
@@ -6889,7 +6978,8 @@ async function startCommand(opts) {
6889
6978
  await runStartPhase(
6890
6979
  "Launching Rudder Desktop...",
6891
6980
  "Rudder Desktop launched.",
6892
- () => launchDesktop(installPaths, target)
6981
+ () => launchDesktop(installPaths, target),
6982
+ desktopProgressJson ? "closing" : null
6893
6983
  );
6894
6984
  }
6895
6985
  }
@@ -11444,7 +11534,7 @@ function createProgram() {
11444
11534
  });
11445
11535
  loadRudderEnvFile(options.config);
11446
11536
  });
11447
- program.command("start").description("Start Rudder Desktop and prepare the matching persistent CLI").option("--no-cli", "Skip persistent CLI installation").option("--no-runtime", "Skip Rudder runtime installation").option("--no-desktop", "Skip desktop app installation").option("--version <version>", "Rudder version to start (default: current CLI version)").option("--target-version <version>", "Rudder version to start; avoids the root CLI version flag").option("--repo <owner/repo>", "GitHub repository that hosts desktop releases").option("--output-dir <path>", "Directory for downloaded desktop release assets").option("--desktop-install-dir <path>", "Directory for the portable Desktop install").option("--no-open", "Install Desktop without launching it").option("--wait-for-active-runs", "Wait for active Rudder runs to finish before replacing Desktop", false).option("--no-version-check", "Skip checking npm for a newer Rudder CLI version").option("--dry-run", "Print the start actions without changing the machine", false).action(startCommand);
11537
+ program.command("start").description("Start Rudder Desktop and prepare the matching persistent CLI").option("--no-cli", "Skip persistent CLI installation").option("--no-runtime", "Skip Rudder runtime installation").option("--no-desktop", "Skip desktop app installation").option("--version <version>", "Rudder version to start (default: current CLI version)").option("--target-version <version>", "Rudder version to start; avoids the root CLI version flag").option("--repo <owner/repo>", "GitHub repository that hosts desktop releases").option("--output-dir <path>", "Directory for downloaded desktop release assets").option("--desktop-install-dir <path>", "Directory for the portable Desktop install").option("--no-open", "Install Desktop without launching it").option("--wait-for-active-runs", "Wait for active Rudder runs to finish before replacing Desktop", false).option("--desktop-progress-json", "Emit newline-delimited Desktop update progress events").option("--no-version-check", "Skip checking npm for a newer Rudder CLI version").option("--dry-run", "Print the start actions without changing the machine", false).action(startCommand);
11448
11538
  program.command("onboard").description("Interactive first-run setup wizard").option("-c, --config <path>", "Path to config file").option("-d, --data-dir <path>", DATA_DIR_OPTION_HELP).option("-y, --yes", "Accept defaults (quickstart + start immediately)", false).option("--run", "Start Rudder immediately after saving config", false).action(onboard);
11449
11539
  program.command("doctor").description("Run diagnostic checks on your Rudder setup").option("-c, --config <path>", "Path to config file").option("-d, --data-dir <path>", DATA_DIR_OPTION_HELP).option("--repair", "Attempt to repair issues automatically").alias("--fix").option("-y, --yes", "Skip repair confirmation prompts").action(async (opts) => {
11450
11540
  await doctor(opts);