@prismicio/cli 0.0.3-beta.11 → 0.0.3-beta.12

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-Ddo0in9P.js");
2518
+ const { toFormData } = await import("./multipart-parser-pPf53n-l.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-Dbm9IdwU.js")).default(...args);
70610
+ return (await import("./index-B8Jc4vYC.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$4 = "@prismicio/cli";
82522
- const version$k = "0.0.3-beta.11";
82522
+ const version$k = "0.0.3-beta.12";
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" };
@@ -149857,8 +149857,111 @@ async function init(args) {
149857
149857
  });
149858
149858
  displaySuccess("Project initialized successfully!", "You're all set to start building with Prismic.");
149859
149859
  }
149860
+ const POLL_INTERVAL_MS = 5e3;
149861
+ const MAX_BACKOFF_MS = 6e4;
149862
+ const MAX_CONSECUTIVE_ERRORS = 10;
149863
+ const SHUTDOWN_TIMEOUT_MS = 3e3;
149864
+ async function watchForChanges(args) {
149865
+ const { manager, repositoryName } = args;
149866
+ const initialSlices = await manager.slices.fetchRemoteSlices();
149867
+ const initialCustomTypes = await manager.customTypes.fetchRemoteCustomTypes();
149868
+ await saveSlices({ manager });
149869
+ await saveCustomTypes({ manager });
149870
+ let lastSlicesHash = computeHash(initialSlices);
149871
+ let lastCustomTypesHash = computeHash(initialCustomTypes);
149872
+ displaySuccess("Initial sync completed!", "Now watching for changes...");
149873
+ displayWatching({ intervalMs: POLL_INTERVAL_MS });
149874
+ const shutdown = async () => {
149875
+ displayStandout("Watch stopped. Goodbye!");
149876
+ await Promise.race([
149877
+ manager.telemetry.track({
149878
+ event: "prismic-cli:end",
149879
+ commandType: "sync",
149880
+ repository: repositoryName,
149881
+ fullCommand: process.argv.join(" "),
149882
+ success: true,
149883
+ watch: true
149884
+ }),
149885
+ new Promise((resolve3) => setTimeout(resolve3, SHUTDOWN_TIMEOUT_MS))
149886
+ ]);
149887
+ process.exit(0);
149888
+ };
149889
+ process.on("SIGINT", shutdown);
149890
+ process.on("SIGTERM", shutdown);
149891
+ process.on("SIGHUP", shutdown);
149892
+ process.on("SIGQUIT", shutdown);
149893
+ if (process.platform === "win32") {
149894
+ process.on("SIGBREAK", shutdown);
149895
+ }
149896
+ let consecutiveErrors = 0;
149897
+ while (true) {
149898
+ await sleep(consecutiveErrors);
149899
+ try {
149900
+ const remoteSlices = await manager.slices.fetchRemoteSlices();
149901
+ const remoteCustomTypes = await manager.customTypes.fetchRemoteCustomTypes();
149902
+ const slicesHash = computeHash(remoteSlices);
149903
+ const customTypesHash = computeHash(remoteCustomTypes);
149904
+ const slicesChanged = slicesHash !== lastSlicesHash;
149905
+ const customTypesChanged = customTypesHash !== lastCustomTypesHash;
149906
+ if (slicesChanged || customTypesChanged) {
149907
+ displayChange({
149908
+ slices: slicesChanged,
149909
+ customTypes: customTypesChanged
149910
+ });
149911
+ if (slicesChanged) {
149912
+ await saveSlices({ manager });
149913
+ lastSlicesHash = slicesHash;
149914
+ }
149915
+ if (customTypesChanged) {
149916
+ await saveCustomTypes({ manager });
149917
+ lastCustomTypesHash = customTypesHash;
149918
+ }
149919
+ displaySyncComplete();
149920
+ }
149921
+ consecutiveErrors = 0;
149922
+ } catch (error2) {
149923
+ consecutiveErrors++;
149924
+ const message2 = error2 instanceof Error ? error2.message : "Unknown error";
149925
+ const nextDelay = Math.min(POLL_INTERVAL_MS * Math.pow(2, consecutiveErrors - 1), MAX_BACKOFF_MS);
149926
+ displayRetryWarning(`Error checking for changes: ${message2}. Retrying in ${nextDelay / 1e3}s...`);
149927
+ if (consecutiveErrors >= MAX_CONSECUTIVE_ERRORS) {
149928
+ throw new Error(`Too many consecutive errors (${MAX_CONSECUTIVE_ERRORS}), stopping watch.`);
149929
+ }
149930
+ }
149931
+ }
149932
+ }
149933
+ function computeHash(data) {
149934
+ return crypto$1.createHash("sha256").update(JSON.stringify(data)).digest("hex");
149935
+ }
149936
+ function sleep(errorCount) {
149937
+ const delay2 = errorCount === 0 ? POLL_INTERVAL_MS : Math.min(POLL_INTERVAL_MS * Math.pow(2, errorCount - 1), MAX_BACKOFF_MS);
149938
+ return new Promise((resolve3) => setTimeout(resolve3, delay2));
149939
+ }
149940
+ function displayWatching({ intervalMs }) {
149941
+ const seconds2 = intervalMs / 1e3;
149942
+ console.info(chalk.cyan(`
149943
+ Watching for changes (polling every ${seconds2}s)...`));
149944
+ console.info(chalk.gray(" Press Ctrl+C to stop\n"));
149945
+ }
149946
+ function displayChange({ slices: slices2, customTypes }) {
149947
+ const timestamp = (/* @__PURE__ */ new Date()).toLocaleTimeString();
149948
+ const changes = [slices2 && "slices", customTypes && "custom types"].filter(Boolean).join(" and ");
149949
+ console.info(chalk.blue(`
149950
+ [${timestamp}] Changes detected in ${changes}`));
149951
+ }
149952
+ function displaySyncComplete() {
149953
+ console.info(chalk.green(" ✓ Changes synced successfully\n"));
149954
+ }
149955
+ function displayStandout(message2) {
149956
+ console.info(chalk.blue(`
149957
+ ${message2}
149958
+ `));
149959
+ }
149960
+ function displayRetryWarning(message2) {
149961
+ console.warn(chalk.yellow(` ⚠ ${message2}`));
149962
+ }
149860
149963
  async function sync(args) {
149861
- const { manager } = args;
149964
+ const { manager, watch = false } = args;
149862
149965
  await login(manager);
149863
149966
  await detectProjectState({ manager, commandType: "sync" });
149864
149967
  const repositoryName = await manager.project.getRepositoryName();
@@ -149866,16 +149969,21 @@ async function sync(args) {
149866
149969
  await detectProjectContext(manager);
149867
149970
  await checkCLIVersion({ manager, currentVersion: version$k });
149868
149971
  await manager.plugins.initPlugins();
149869
- await saveSlices({ manager });
149870
- await saveCustomTypes({ manager });
149871
- await manager.telemetry.track({
149872
- event: "prismic-cli:end",
149873
- commandType: "sync",
149874
- repository: repositoryName,
149875
- fullCommand: process.argv.join(" "),
149876
- success: true
149877
- });
149878
- displaySuccess("Sync completed successfully!", "Your local types are up to date.");
149972
+ if (watch) {
149973
+ await watchForChanges({ manager, repositoryName });
149974
+ } else {
149975
+ await saveSlices({ manager });
149976
+ await saveCustomTypes({ manager });
149977
+ await manager.telemetry.track({
149978
+ event: "prismic-cli:end",
149979
+ commandType: "sync",
149980
+ repository: repositoryName,
149981
+ fullCommand: process.argv.join(" "),
149982
+ success: true,
149983
+ watch: false
149984
+ });
149985
+ displaySuccess("Sync completed successfully!", "Your local types are up to date.");
149986
+ }
149879
149987
  }
149880
149988
  async function initTelemetry(args) {
149881
149989
  const { manager, commandType, repositoryName } = args;
@@ -149922,9 +150030,11 @@ VERSION
149922
150030
  USAGE
149923
150031
  $ npx prismic@latest init --repository <repository-id>
149924
150032
  $ npx prismic@latest sync
150033
+ $ npx prismic@latest sync --watch
149925
150034
 
149926
150035
  OPTIONS
149927
150036
  --repository, -r Specify a Prismic repository to use when initializing a project
150037
+ --watch, -w Watch for changes and sync continuously (polls every 5s)
149928
150038
 
149929
150039
  --help, -h Display CLI help
149930
150040
  --version, -v Display CLI version
@@ -149935,6 +150045,11 @@ OPTIONS
149935
150045
  type: "string",
149936
150046
  shortFlag: "r"
149937
150047
  },
150048
+ watch: {
150049
+ type: "boolean",
150050
+ shortFlag: "w",
150051
+ default: false
150052
+ },
149938
150053
  help: {
149939
150054
  type: "boolean",
149940
150055
  shortFlag: "h",
@@ -149961,7 +150076,8 @@ const CLIArgs = discriminatedUnion("commandType", [
149961
150076
  object$1({
149962
150077
  commandType: literal$2("sync"),
149963
150078
  help: boolean$2().optional(),
149964
- version: boolean$2().optional()
150079
+ version: boolean$2().optional(),
150080
+ watch: boolean$2().optional()
149965
150081
  })
149966
150082
  ]);
149967
150083
  async function run() {
@@ -150023,7 +150139,7 @@ async function run() {
150023
150139
  process.exit(0);
150024
150140
  }
150025
150141
  if (commandType === "sync") {
150026
- await sync({ manager });
150142
+ await sync({ manager, watch: cliArgs.data.watch });
150027
150143
  process.exit(0);
150028
150144
  }
150029
150145
  throw new Error("Unknown command type.");
@@ -150050,4 +150166,4 @@ export {
150050
150166
  getDefaultExportFromCjs$3 as g,
150051
150167
  run as r
150052
150168
  };
150053
- //# sourceMappingURL=cli-DhqlE1U5.js.map
150169
+ //# sourceMappingURL=cli-orR365ka.js.map