@prismicio/cli 0.0.3-alpha.xru-support-init-simulator.1 → 0.0.3-alpha.xru-support-init-simulator.2

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/README.md CHANGED
@@ -27,6 +27,12 @@ npx @prismicio/cli@latest init --repository <repository>
27
27
  npx @prismicio/cli@latest sync
28
28
  ```
29
29
 
30
+ ### Watch for changes
31
+
32
+ ```bash
33
+ npx @prismicio/cli@latest sync --watch
34
+ ```
35
+
30
36
  ## Documentation
31
37
 
32
38
  For detailed documentation, visit the [official Prismic documentation](https://prismic.io/docs).
@@ -48,7 +48,7 @@ import * as require$$1__default from "https";
48
48
  import require$$1__default__default from "https";
49
49
  import tty$1 from "node:tty";
50
50
  import { StringDecoder } from "string_decoder";
51
- import { randomUUID as randomUUID$1 } from "crypto";
51
+ import crypto$1, { randomUUID as randomUUID$1 } from "crypto";
52
52
  import * as diagnosticsChannel from "node:diagnostics_channel";
53
53
  import diagnosticsChannel__default, { subscribe, unsubscribe } from "node:diagnostics_channel";
54
54
  import { errorMonitor } from "node:events";
@@ -2515,7 +2515,7 @@ class Body {
2515
2515
  }
2516
2516
  return formData;
2517
2517
  }
2518
- const { toFormData } = await import("./multipart-parser-Hi8WlJWF.js");
2518
+ const { toFormData } = await import("./multipart-parser-CX4nS_et.js");
2519
2519
  return toFormData(this.body, ct2);
2520
2520
  }
2521
2521
  /**
@@ -68326,7 +68326,7 @@ function pTimeout(promise, timeout2) {
68326
68326
  }).catch(reject);
68327
68327
  });
68328
68328
  }
68329
- function sleep$1(timeoutInMs) {
68329
+ function sleep$2(timeoutInMs) {
68330
68330
  return new Promise(function(resolve3) {
68331
68331
  return setTimeout(resolve3, timeoutInMs);
68332
68332
  });
@@ -68339,7 +68339,7 @@ function invokeCallback(ctx, callback, delay2) {
68339
68339
  return Promise.reject(err);
68340
68340
  }
68341
68341
  };
68342
- return sleep$1(delay2).then(function() {
68342
+ return sleep$2(delay2).then(function() {
68343
68343
  return pTimeout(cb(), 1e3);
68344
68344
  }).catch(function(err) {
68345
68345
  ctx === null || ctx === void 0 ? void 0 : ctx.log("warn", "Callback Error", { error: err });
@@ -70144,7 +70144,7 @@ class TokenManager {
70144
70144
  } else {
70145
70145
  timeUntilRefreshInMs = 5 * 1e3;
70146
70146
  }
70147
- await sleep$1(timeUntilRefreshInMs);
70147
+ await sleep$2(timeUntilRefreshInMs);
70148
70148
  timeUntilRefreshInMs = 0;
70149
70149
  }
70150
70150
  this.queueNextPoll(timeUntilRefreshInMs);
@@ -70228,7 +70228,7 @@ class TokenManager {
70228
70228
  return typeof token2 !== "undefined" && token2 !== null && token2.expires_in < Date.now() / 1e3;
70229
70229
  }
70230
70230
  }
70231
- function sleep(timeoutInMs) {
70231
+ function sleep$1(timeoutInMs) {
70232
70232
  return new Promise((resolve3) => setTimeout(resolve3, timeoutInMs));
70233
70233
  }
70234
70234
  function noop() {
@@ -70418,7 +70418,7 @@ class Publisher {
70418
70418
  resolveFailedBatch(batch, failureReason);
70419
70419
  return;
70420
70420
  }
70421
- await sleep(requestedRetryTimeout ? requestedRetryTimeout : backoff({
70421
+ await sleep$1(requestedRetryTimeout ? requestedRetryTimeout : backoff({
70422
70422
  attempt: currentAttempt,
70423
70423
  minTimeout: 25,
70424
70424
  maxTimeout: 1e3
@@ -70607,7 +70607,7 @@ const fetch = async (...args) => {
70607
70607
  if (globalThis.fetch) {
70608
70608
  return globalThis.fetch(...args);
70609
70609
  } else if (typeof EdgeRuntime !== "string") {
70610
- return (await import("./index-a4f6KNwr.js")).default(...args);
70610
+ return (await import("./index-CtATwLQ9.js")).default(...args);
70611
70611
  } else {
70612
70612
  throw new Error("Invariant: an edge runtime that does not support fetch should not exist");
70613
70613
  }
@@ -82519,7 +82519,7 @@ const meow = (helpText, options8 = {}) => {
82519
82519
  return result;
82520
82520
  };
82521
82521
  const name$3 = "@prismicio/cli";
82522
- const version$k = "0.0.3-alpha.xru-support-init-simulator.1";
82522
+ const version$k = "0.0.3-alpha.xru-support-init-simulator.2";
82523
82523
  const description = "Prismic CLI";
82524
82524
  const keywords = ["typescript", "prismic"];
82525
82525
  const repository = { "type": "git", "url": "git+https://github.com/prismicio/devtools.git" };
@@ -149644,8 +149644,111 @@ async function init(args) {
149644
149644
  });
149645
149645
  displaySuccess("Project initialized successfully!", "You're all set to start building with Prismic.");
149646
149646
  }
149647
+ const POLL_INTERVAL_MS = 5e3;
149648
+ const MAX_BACKOFF_MS = 6e4;
149649
+ const MAX_CONSECUTIVE_ERRORS = 10;
149650
+ const SHUTDOWN_TIMEOUT_MS = 3e3;
149651
+ async function watchForChanges(args) {
149652
+ const { manager, repositoryName } = args;
149653
+ const initialSlices = await manager.slices.fetchRemoteSlices();
149654
+ const initialCustomTypes = await manager.customTypes.fetchRemoteCustomTypes();
149655
+ await saveSlices({ manager });
149656
+ await saveCustomTypes({ manager });
149657
+ let lastSlicesHash = computeHash(initialSlices);
149658
+ let lastCustomTypesHash = computeHash(initialCustomTypes);
149659
+ displaySuccess("Initial sync completed!", "Now watching for changes...");
149660
+ displayWatching({ intervalMs: POLL_INTERVAL_MS });
149661
+ const shutdown = async () => {
149662
+ displayStandout("Watch stopped. Goodbye!");
149663
+ await Promise.race([
149664
+ manager.telemetry.track({
149665
+ event: "prismic-cli:end",
149666
+ commandType: "sync",
149667
+ repository: repositoryName,
149668
+ fullCommand: process.argv.join(" "),
149669
+ success: true,
149670
+ watch: true
149671
+ }),
149672
+ new Promise((resolve3) => setTimeout(resolve3, SHUTDOWN_TIMEOUT_MS))
149673
+ ]);
149674
+ process.exit(0);
149675
+ };
149676
+ process.on("SIGINT", shutdown);
149677
+ process.on("SIGTERM", shutdown);
149678
+ process.on("SIGHUP", shutdown);
149679
+ process.on("SIGQUIT", shutdown);
149680
+ if (process.platform === "win32") {
149681
+ process.on("SIGBREAK", shutdown);
149682
+ }
149683
+ let consecutiveErrors = 0;
149684
+ while (true) {
149685
+ await sleep(consecutiveErrors);
149686
+ try {
149687
+ const remoteSlices = await manager.slices.fetchRemoteSlices();
149688
+ const remoteCustomTypes = await manager.customTypes.fetchRemoteCustomTypes();
149689
+ const slicesHash = computeHash(remoteSlices);
149690
+ const customTypesHash = computeHash(remoteCustomTypes);
149691
+ const slicesChanged = slicesHash !== lastSlicesHash;
149692
+ const customTypesChanged = customTypesHash !== lastCustomTypesHash;
149693
+ if (slicesChanged || customTypesChanged) {
149694
+ displayChange({
149695
+ slices: slicesChanged,
149696
+ customTypes: customTypesChanged
149697
+ });
149698
+ if (slicesChanged) {
149699
+ await saveSlices({ manager });
149700
+ lastSlicesHash = slicesHash;
149701
+ }
149702
+ if (customTypesChanged) {
149703
+ await saveCustomTypes({ manager });
149704
+ lastCustomTypesHash = customTypesHash;
149705
+ }
149706
+ displaySyncComplete();
149707
+ }
149708
+ consecutiveErrors = 0;
149709
+ } catch (error2) {
149710
+ consecutiveErrors++;
149711
+ const message2 = error2 instanceof Error ? error2.message : "Unknown error";
149712
+ const nextDelay = Math.min(POLL_INTERVAL_MS * Math.pow(2, consecutiveErrors - 1), MAX_BACKOFF_MS);
149713
+ displayRetryWarning(`Error checking for changes: ${message2}. Retrying in ${nextDelay / 1e3}s...`);
149714
+ if (consecutiveErrors >= MAX_CONSECUTIVE_ERRORS) {
149715
+ throw new Error(`Too many consecutive errors (${MAX_CONSECUTIVE_ERRORS}), stopping watch.`);
149716
+ }
149717
+ }
149718
+ }
149719
+ }
149720
+ function computeHash(data) {
149721
+ return crypto$1.createHash("sha256").update(JSON.stringify(data)).digest("hex");
149722
+ }
149723
+ function sleep(errorCount) {
149724
+ const delay2 = errorCount === 0 ? POLL_INTERVAL_MS : Math.min(POLL_INTERVAL_MS * Math.pow(2, errorCount - 1), MAX_BACKOFF_MS);
149725
+ return new Promise((resolve3) => setTimeout(resolve3, delay2));
149726
+ }
149727
+ function displayWatching({ intervalMs }) {
149728
+ const seconds2 = intervalMs / 1e3;
149729
+ console.info(chalk.cyan(`
149730
+ Watching for changes (polling every ${seconds2}s)...`));
149731
+ console.info(chalk.gray(" Press Ctrl+C to stop\n"));
149732
+ }
149733
+ function displayChange({ slices: slices2, customTypes }) {
149734
+ const timestamp = (/* @__PURE__ */ new Date()).toLocaleTimeString();
149735
+ const changes = [slices2 && "slices", customTypes && "custom types"].filter(Boolean).join(" and ");
149736
+ console.info(chalk.blue(`
149737
+ [${timestamp}] Changes detected in ${changes}`));
149738
+ }
149739
+ function displaySyncComplete() {
149740
+ console.info(chalk.green(" ✓ Changes synced successfully\n"));
149741
+ }
149742
+ function displayStandout(message2) {
149743
+ console.info(chalk.blue(`
149744
+ ${message2}
149745
+ `));
149746
+ }
149747
+ function displayRetryWarning(message2) {
149748
+ console.warn(chalk.yellow(` ⚠ ${message2}`));
149749
+ }
149647
149750
  async function sync(args) {
149648
- const { manager } = args;
149751
+ const { manager, watch = false } = args;
149649
149752
  await login(manager);
149650
149753
  await detectProjectState({ manager, commandType: "sync" });
149651
149754
  const repositoryName = await manager.project.getRepositoryName();
@@ -149653,16 +149756,21 @@ async function sync(args) {
149653
149756
  await detectProjectContext(manager);
149654
149757
  await checkCLIVersion({ manager, currentVersion: version$k });
149655
149758
  await manager.plugins.initPlugins();
149656
- await saveSlices({ manager });
149657
- await saveCustomTypes({ manager });
149658
- await manager.telemetry.track({
149659
- event: "prismic-cli:end",
149660
- commandType: "sync",
149661
- repository: repositoryName,
149662
- fullCommand: process.argv.join(" "),
149663
- success: true
149664
- });
149665
- displaySuccess("Sync completed successfully!", "Your local types are up to date.");
149759
+ if (watch) {
149760
+ await watchForChanges({ manager, repositoryName });
149761
+ } else {
149762
+ await saveSlices({ manager });
149763
+ await saveCustomTypes({ manager });
149764
+ await manager.telemetry.track({
149765
+ event: "prismic-cli:end",
149766
+ commandType: "sync",
149767
+ repository: repositoryName,
149768
+ fullCommand: process.argv.join(" "),
149769
+ success: true,
149770
+ watch: false
149771
+ });
149772
+ displaySuccess("Sync completed successfully!", "Your local types are up to date.");
149773
+ }
149666
149774
  }
149667
149775
  async function initTelemetry(args) {
149668
149776
  const { manager, commandType, repositoryName } = args;
@@ -149709,9 +149817,11 @@ VERSION
149709
149817
  USAGE
149710
149818
  $ npx prismic@latest init --repository <repository-id>
149711
149819
  $ npx prismic@latest sync
149820
+ $ npx prismic@latest sync --watch
149712
149821
 
149713
149822
  OPTIONS
149714
149823
  --repository, -r Specify a Prismic repository to use when initializing a project
149824
+ --watch, -w Watch for changes and sync continuously (polls every 5s)
149715
149825
 
149716
149826
  --help, -h Display CLI help
149717
149827
  --version, -v Display CLI version
@@ -149722,6 +149832,11 @@ OPTIONS
149722
149832
  type: "string",
149723
149833
  shortFlag: "r"
149724
149834
  },
149835
+ watch: {
149836
+ type: "boolean",
149837
+ shortFlag: "w",
149838
+ default: false
149839
+ },
149725
149840
  help: {
149726
149841
  type: "boolean",
149727
149842
  shortFlag: "h",
@@ -149748,7 +149863,8 @@ const CLIArgs = discriminatedUnion("commandType", [
149748
149863
  object$1({
149749
149864
  commandType: literal$2("sync"),
149750
149865
  help: boolean$2().optional(),
149751
- version: boolean$2().optional()
149866
+ version: boolean$2().optional(),
149867
+ watch: boolean$2().optional()
149752
149868
  })
149753
149869
  ]);
149754
149870
  async function run() {
@@ -149810,7 +149926,7 @@ async function run() {
149810
149926
  process.exit(0);
149811
149927
  }
149812
149928
  if (commandType === "sync") {
149813
- await sync({ manager });
149929
+ await sync({ manager, watch: cliArgs.data.watch });
149814
149930
  process.exit(0);
149815
149931
  }
149816
149932
  throw new Error("Unknown command type.");
@@ -149837,4 +149953,4 @@ export {
149837
149953
  getDefaultExportFromCjs$3 as g,
149838
149954
  run as r
149839
149955
  };
149840
- //# sourceMappingURL=cli-F1SjQ4nT.js.map
149956
+ //# sourceMappingURL=cli-D5er7abW.js.map