@prismicio/cli 0.0.3-beta.10 → 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 +6 -0
- package/dist/{cli-OGQCKk2j.js → cli-orR365ka.js} +142 -24
- package/dist/{cli-OGQCKk2j.js.map → cli-orR365ka.js.map} +1 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +1 -1
- package/dist/commands/sync.d.ts +1 -0
- package/dist/core/watch.d.ts +7 -0
- package/dist/{index-CegrglQ8.js → index-B8Jc4vYC.js} +2 -2
- package/dist/{index-CegrglQ8.js.map → index-B8Jc4vYC.js.map} +1 -1
- package/dist/index.js +1 -1
- package/dist/{multipart-parser-C19VLxhS.js → multipart-parser-pPf53n-l.js} +2 -2
- package/dist/{multipart-parser-C19VLxhS.js.map → multipart-parser-pPf53n-l.js.map} +1 -1
- package/package.json +6 -6
- package/src/cli.ts +9 -1
- package/src/commands/sync.ts +23 -17
- package/src/core/watch.ts +181 -0
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";
|
|
@@ -1178,7 +1178,9 @@ function readRawBody(event, encoding = "utf8") {
|
|
|
1178
1178
|
});
|
|
1179
1179
|
return encoding ? promise2.then((buff) => buff.toString(encoding)) : promise2;
|
|
1180
1180
|
}
|
|
1181
|
-
if (!Number.parseInt(event.node.req.headers["content-length"] || "") &&
|
|
1181
|
+
if (!Number.parseInt(event.node.req.headers["content-length"] || "") && !/\bchunked\b/i.test(
|
|
1182
|
+
String(event.node.req.headers["transfer-encoding"] ?? "")
|
|
1183
|
+
)) {
|
|
1182
1184
|
return Promise.resolve(void 0);
|
|
1183
1185
|
}
|
|
1184
1186
|
const promise = event.node.req[RawBodySymbol] = new Promise(
|
|
@@ -2513,7 +2515,7 @@ class Body {
|
|
|
2513
2515
|
}
|
|
2514
2516
|
return formData;
|
|
2515
2517
|
}
|
|
2516
|
-
const { toFormData } = await import("./multipart-parser-
|
|
2518
|
+
const { toFormData } = await import("./multipart-parser-pPf53n-l.js");
|
|
2517
2519
|
return toFormData(this.body, ct2);
|
|
2518
2520
|
}
|
|
2519
2521
|
/**
|
|
@@ -68324,7 +68326,7 @@ function pTimeout(promise, timeout2) {
|
|
|
68324
68326
|
}).catch(reject);
|
|
68325
68327
|
});
|
|
68326
68328
|
}
|
|
68327
|
-
function sleep$
|
|
68329
|
+
function sleep$2(timeoutInMs) {
|
|
68328
68330
|
return new Promise(function(resolve3) {
|
|
68329
68331
|
return setTimeout(resolve3, timeoutInMs);
|
|
68330
68332
|
});
|
|
@@ -68337,7 +68339,7 @@ function invokeCallback(ctx, callback, delay2) {
|
|
|
68337
68339
|
return Promise.reject(err);
|
|
68338
68340
|
}
|
|
68339
68341
|
};
|
|
68340
|
-
return sleep$
|
|
68342
|
+
return sleep$2(delay2).then(function() {
|
|
68341
68343
|
return pTimeout(cb(), 1e3);
|
|
68342
68344
|
}).catch(function(err) {
|
|
68343
68345
|
ctx === null || ctx === void 0 ? void 0 : ctx.log("warn", "Callback Error", { error: err });
|
|
@@ -70142,7 +70144,7 @@ class TokenManager {
|
|
|
70142
70144
|
} else {
|
|
70143
70145
|
timeUntilRefreshInMs = 5 * 1e3;
|
|
70144
70146
|
}
|
|
70145
|
-
await sleep$
|
|
70147
|
+
await sleep$2(timeUntilRefreshInMs);
|
|
70146
70148
|
timeUntilRefreshInMs = 0;
|
|
70147
70149
|
}
|
|
70148
70150
|
this.queueNextPoll(timeUntilRefreshInMs);
|
|
@@ -70226,7 +70228,7 @@ class TokenManager {
|
|
|
70226
70228
|
return typeof token2 !== "undefined" && token2 !== null && token2.expires_in < Date.now() / 1e3;
|
|
70227
70229
|
}
|
|
70228
70230
|
}
|
|
70229
|
-
function sleep(timeoutInMs) {
|
|
70231
|
+
function sleep$1(timeoutInMs) {
|
|
70230
70232
|
return new Promise((resolve3) => setTimeout(resolve3, timeoutInMs));
|
|
70231
70233
|
}
|
|
70232
70234
|
function noop() {
|
|
@@ -70416,7 +70418,7 @@ class Publisher {
|
|
|
70416
70418
|
resolveFailedBatch(batch, failureReason);
|
|
70417
70419
|
return;
|
|
70418
70420
|
}
|
|
70419
|
-
await sleep(requestedRetryTimeout ? requestedRetryTimeout : backoff({
|
|
70421
|
+
await sleep$1(requestedRetryTimeout ? requestedRetryTimeout : backoff({
|
|
70420
70422
|
attempt: currentAttempt,
|
|
70421
70423
|
minTimeout: 25,
|
|
70422
70424
|
maxTimeout: 1e3
|
|
@@ -70605,7 +70607,7 @@ const fetch = async (...args) => {
|
|
|
70605
70607
|
if (globalThis.fetch) {
|
|
70606
70608
|
return globalThis.fetch(...args);
|
|
70607
70609
|
} else if (typeof EdgeRuntime !== "string") {
|
|
70608
|
-
return (await import("./index-
|
|
70610
|
+
return (await import("./index-B8Jc4vYC.js")).default(...args);
|
|
70609
70611
|
} else {
|
|
70610
70612
|
throw new Error("Invariant: an edge runtime that does not support fetch should not exist");
|
|
70611
70613
|
}
|
|
@@ -82517,7 +82519,7 @@ const meow = (helpText, options8 = {}) => {
|
|
|
82517
82519
|
return result;
|
|
82518
82520
|
};
|
|
82519
82521
|
const name$4 = "@prismicio/cli";
|
|
82520
|
-
const version$k = "0.0.3-beta.
|
|
82522
|
+
const version$k = "0.0.3-beta.12";
|
|
82521
82523
|
const description = "Prismic CLI";
|
|
82522
82524
|
const keywords = ["typescript", "prismic"];
|
|
82523
82525
|
const repository = { "type": "git", "url": "git+https://github.com/prismicio/devtools.git" };
|
|
@@ -149855,8 +149857,111 @@ async function init(args) {
|
|
|
149855
149857
|
});
|
|
149856
149858
|
displaySuccess("Project initialized successfully!", "You're all set to start building with Prismic.");
|
|
149857
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
|
+
}
|
|
149858
149963
|
async function sync(args) {
|
|
149859
|
-
const { manager } = args;
|
|
149964
|
+
const { manager, watch = false } = args;
|
|
149860
149965
|
await login(manager);
|
|
149861
149966
|
await detectProjectState({ manager, commandType: "sync" });
|
|
149862
149967
|
const repositoryName = await manager.project.getRepositoryName();
|
|
@@ -149864,16 +149969,21 @@ async function sync(args) {
|
|
|
149864
149969
|
await detectProjectContext(manager);
|
|
149865
149970
|
await checkCLIVersion({ manager, currentVersion: version$k });
|
|
149866
149971
|
await manager.plugins.initPlugins();
|
|
149867
|
-
|
|
149868
|
-
|
|
149869
|
-
|
|
149870
|
-
|
|
149871
|
-
|
|
149872
|
-
|
|
149873
|
-
|
|
149874
|
-
|
|
149875
|
-
|
|
149876
|
-
|
|
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
|
+
}
|
|
149877
149987
|
}
|
|
149878
149988
|
async function initTelemetry(args) {
|
|
149879
149989
|
const { manager, commandType, repositoryName } = args;
|
|
@@ -149920,9 +150030,11 @@ VERSION
|
|
|
149920
150030
|
USAGE
|
|
149921
150031
|
$ npx prismic@latest init --repository <repository-id>
|
|
149922
150032
|
$ npx prismic@latest sync
|
|
150033
|
+
$ npx prismic@latest sync --watch
|
|
149923
150034
|
|
|
149924
150035
|
OPTIONS
|
|
149925
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)
|
|
149926
150038
|
|
|
149927
150039
|
--help, -h Display CLI help
|
|
149928
150040
|
--version, -v Display CLI version
|
|
@@ -149933,6 +150045,11 @@ OPTIONS
|
|
|
149933
150045
|
type: "string",
|
|
149934
150046
|
shortFlag: "r"
|
|
149935
150047
|
},
|
|
150048
|
+
watch: {
|
|
150049
|
+
type: "boolean",
|
|
150050
|
+
shortFlag: "w",
|
|
150051
|
+
default: false
|
|
150052
|
+
},
|
|
149936
150053
|
help: {
|
|
149937
150054
|
type: "boolean",
|
|
149938
150055
|
shortFlag: "h",
|
|
@@ -149959,7 +150076,8 @@ const CLIArgs = discriminatedUnion("commandType", [
|
|
|
149959
150076
|
object$1({
|
|
149960
150077
|
commandType: literal$2("sync"),
|
|
149961
150078
|
help: boolean$2().optional(),
|
|
149962
|
-
version: boolean$2().optional()
|
|
150079
|
+
version: boolean$2().optional(),
|
|
150080
|
+
watch: boolean$2().optional()
|
|
149963
150081
|
})
|
|
149964
150082
|
]);
|
|
149965
150083
|
async function run() {
|
|
@@ -150021,7 +150139,7 @@ async function run() {
|
|
|
150021
150139
|
process.exit(0);
|
|
150022
150140
|
}
|
|
150023
150141
|
if (commandType === "sync") {
|
|
150024
|
-
await sync({ manager });
|
|
150142
|
+
await sync({ manager, watch: cliArgs.data.watch });
|
|
150025
150143
|
process.exit(0);
|
|
150026
150144
|
}
|
|
150027
150145
|
throw new Error("Unknown command type.");
|
|
@@ -150048,4 +150166,4 @@ export {
|
|
|
150048
150166
|
getDefaultExportFromCjs$3 as g,
|
|
150049
150167
|
run as r
|
|
150050
150168
|
};
|
|
150051
|
-
//# sourceMappingURL=cli-
|
|
150169
|
+
//# sourceMappingURL=cli-orR365ka.js.map
|