@contentful/experience-design-system-cli 2.35.1-dev-build-3ab9e99e.0 → 2.36.1-dev-build-29bacd34.0
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/app.js +190 -231
- package/dist/index.js +201 -249
- package/dist/package.json +1 -1
- package/dist/src/tui/debug-store.d.ts +0 -1
- package/legacy/dist/src/import/tui/steps/WizardPreviewStep.d.ts +1 -2
- package/legacy/dist/src/index.js +166 -598
- package/legacy/package.json +1 -1
- package/package.json +2 -2
- package/legacy/dist/src/apply/dangling-token-defaults.d.ts +0 -17
- package/legacy/dist/src/helpers/fetch-existing-token-ids.d.ts +0 -11
- package/legacy/dist/src/lib/push-debug-log.d.ts +0 -29
package/dist/index.js
CHANGED
|
@@ -297,193 +297,6 @@ var init_PageContainer = __esm({
|
|
|
297
297
|
}
|
|
298
298
|
});
|
|
299
299
|
|
|
300
|
-
// packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts
|
|
301
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
302
|
-
import { dirname as dirname2, join as join4 } from "node:path";
|
|
303
|
-
function debugModeSettingPath() {
|
|
304
|
-
return join4(findPackageRoot(import.meta.url, PACKAGE_NAME3), ".contentful", "config", "debug_mode.json");
|
|
305
|
-
}
|
|
306
|
-
async function readDebugModeSetting() {
|
|
307
|
-
try {
|
|
308
|
-
const raw = await readFile(debugModeSettingPath(), "utf8");
|
|
309
|
-
const parsed = JSON.parse(raw);
|
|
310
|
-
return { ...DEFAULT_DEBUG_MODE_SETTING, ...parsed };
|
|
311
|
-
} catch {
|
|
312
|
-
return { ...DEFAULT_DEBUG_MODE_SETTING };
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
async function writeDebugModeSetting(setting) {
|
|
316
|
-
const path = debugModeSettingPath();
|
|
317
|
-
await mkdir(dirname2(path), { recursive: true });
|
|
318
|
-
await writeFile(path, `${JSON.stringify(setting, null, 2)}
|
|
319
|
-
`, { mode: 384 });
|
|
320
|
-
}
|
|
321
|
-
var PACKAGE_NAME3, DEFAULT_DEBUG_MODE_SETTING;
|
|
322
|
-
var init_debug_mode_store = __esm({
|
|
323
|
-
"packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts"() {
|
|
324
|
-
"use strict";
|
|
325
|
-
init_package_root();
|
|
326
|
-
PACKAGE_NAME3 = "@contentful/experience-design-system-cli";
|
|
327
|
-
DEFAULT_DEBUG_MODE_SETTING = {
|
|
328
|
-
enabled: true
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
// packages/experience-design-system-cli/src/tui/debug-store.ts
|
|
334
|
-
import { mkdir as mkdir2, writeFile as writeFile2 } from "node:fs/promises";
|
|
335
|
-
import { existsSync as existsSync3, readdirSync } from "node:fs";
|
|
336
|
-
import { join as join5 } from "node:path";
|
|
337
|
-
function generateRunId() {
|
|
338
|
-
const now = /* @__PURE__ */ new Date();
|
|
339
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
340
|
-
return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
|
|
341
|
-
}
|
|
342
|
-
function sessionsRootDir() {
|
|
343
|
-
return join5(findPackageRoot(import.meta.url, PACKAGE_NAME4), ".contentful", "debug", "sessions");
|
|
344
|
-
}
|
|
345
|
-
function datePrefix(now = /* @__PURE__ */ new Date()) {
|
|
346
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
347
|
-
return `${pad(now.getMonth() + 1)}-${pad(now.getDate())}-${now.getFullYear()}`;
|
|
348
|
-
}
|
|
349
|
-
function slugify(value) {
|
|
350
|
-
return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
351
|
-
}
|
|
352
|
-
function generateSessionId() {
|
|
353
|
-
const today = datePrefix();
|
|
354
|
-
const root = sessionsRootDir();
|
|
355
|
-
const existing = existsSync3(root) ? readdirSync(root) : [];
|
|
356
|
-
const seqPattern = new RegExp(`^${today}-session-(\\d+)$`);
|
|
357
|
-
const maxSeq = existing.reduce((max, entry) => {
|
|
358
|
-
const match = seqPattern.exec(entry);
|
|
359
|
-
return match ? Math.max(max, Number(match[1])) : max;
|
|
360
|
-
}, 0);
|
|
361
|
-
return `${today}-session-${maxSeq + 1}`;
|
|
362
|
-
}
|
|
363
|
-
function sessionDebugDir() {
|
|
364
|
-
return join5(sessionsRootDir(), SESSION_ID);
|
|
365
|
-
}
|
|
366
|
-
async function debugSessionDirIfEnabled() {
|
|
367
|
-
return await isDebugModeEnabled() ? sessionDebugDir() : void 0;
|
|
368
|
-
}
|
|
369
|
-
async function isDebugModeEnabled() {
|
|
370
|
-
try {
|
|
371
|
-
return (await readDebugModeSetting()).enabled;
|
|
372
|
-
} catch {
|
|
373
|
-
return true;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
function redact(value) {
|
|
377
|
-
const clone = { ...value };
|
|
378
|
-
if ("cma_token" in clone) {
|
|
379
|
-
const raw = clone.cma_token;
|
|
380
|
-
clone.cma_token = typeof raw === "string" && raw.length > 0 ? `[present, ${raw.length} chars]` : "[not set]";
|
|
381
|
-
}
|
|
382
|
-
return clone;
|
|
383
|
-
}
|
|
384
|
-
function startDebugRun({
|
|
385
|
-
flow,
|
|
386
|
-
step,
|
|
387
|
-
menuOption,
|
|
388
|
-
inputs
|
|
389
|
-
}) {
|
|
390
|
-
const runId = generateRunId();
|
|
391
|
-
const startedAt = Date.now();
|
|
392
|
-
const redactedInputs = redact(inputs);
|
|
393
|
-
isDebugModeEnabled().then((enabled) => {
|
|
394
|
-
if (!enabled) return;
|
|
395
|
-
pendingRun = { flow, step, runId, menuOption, inputs: redactedInputs, startedAt };
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
async function finishDebugRun({
|
|
399
|
-
outputs,
|
|
400
|
-
status,
|
|
401
|
-
exitMethod
|
|
402
|
-
}) {
|
|
403
|
-
const run = pendingRun;
|
|
404
|
-
if (!run) return;
|
|
405
|
-
pendingRun = void 0;
|
|
406
|
-
const durationMs = Date.now() - run.startedAt;
|
|
407
|
-
const content = renderMarkdown(run, { outputs: redact(outputs), status, exitMethod, durationMs });
|
|
408
|
-
const flowSegments = run.flow.split("/");
|
|
409
|
-
const dir = join5(sessionDebugDir(), ...flowSegments);
|
|
410
|
-
await mkdir2(dir, { recursive: true });
|
|
411
|
-
const filename = nextAttemptFilename(dir, run.menuOption);
|
|
412
|
-
await writeFile2(join5(dir, filename), content, { mode: 384 });
|
|
413
|
-
}
|
|
414
|
-
function nextAttemptFilename(dir, menuOption) {
|
|
415
|
-
const today = datePrefix();
|
|
416
|
-
const optionSlug = slugify(menuOption);
|
|
417
|
-
const existing = existsSync3(dir) ? readdirSync(dir) : [];
|
|
418
|
-
const attemptPattern = new RegExp(`^${today}-${optionSlug}-attempt-(\\d+)\\.md$`);
|
|
419
|
-
const maxAttempt = existing.reduce((max, entry) => {
|
|
420
|
-
const match = attemptPattern.exec(entry);
|
|
421
|
-
return match ? Math.max(max, Number(match[1])) : max;
|
|
422
|
-
}, 0);
|
|
423
|
-
return `${today}-${optionSlug}-attempt-${maxAttempt + 1}.md`;
|
|
424
|
-
}
|
|
425
|
-
function renderMarkdown(run, finish) {
|
|
426
|
-
const stepMatch = /^(\d+)-(.+)$/.exec(run.step);
|
|
427
|
-
const stepLabel = stepMatch ? `${stepMatch[1]} - ${stepMatch[2]}` : run.step;
|
|
428
|
-
const flowSlug = run.flow.split("/").join("-");
|
|
429
|
-
return `# Debug Log
|
|
430
|
-
|
|
431
|
-
- Run ID: ${run.runId}
|
|
432
|
-
- Flow: ${flowSlug}
|
|
433
|
-
- Step: ${stepLabel}
|
|
434
|
-
- Menu option: ${run.menuOption}
|
|
435
|
-
- Date: ${(/* @__PURE__ */ new Date()).toISOString()}
|
|
436
|
-
- CLI version: ${readPackageVersion()}
|
|
437
|
-
- Platform: ${process.platform} / Node ${process.version}
|
|
438
|
-
- Duration on screen: ${finish.durationMs}ms
|
|
439
|
-
- Status: ${finish.status}
|
|
440
|
-
- Exit method: ${finish.exitMethod}
|
|
441
|
-
|
|
442
|
-
## Inputs
|
|
443
|
-
\`\`\`json
|
|
444
|
-
${JSON.stringify(run.inputs, null, 2)}
|
|
445
|
-
\`\`\`
|
|
446
|
-
|
|
447
|
-
## Outputs
|
|
448
|
-
\`\`\`json
|
|
449
|
-
${JSON.stringify(finish.outputs, null, 2)}
|
|
450
|
-
\`\`\`
|
|
451
|
-
`;
|
|
452
|
-
}
|
|
453
|
-
function handleCrash() {
|
|
454
|
-
return finishDebugRun({ outputs: {}, status: "error", exitMethod: "crashed" });
|
|
455
|
-
}
|
|
456
|
-
var PACKAGE_NAME4, pendingRun, SESSION_ID;
|
|
457
|
-
var init_debug_store = __esm({
|
|
458
|
-
"packages/experience-design-system-cli/src/tui/debug-store.ts"() {
|
|
459
|
-
"use strict";
|
|
460
|
-
init_package_root();
|
|
461
|
-
init_version();
|
|
462
|
-
init_debug_mode_store();
|
|
463
|
-
PACKAGE_NAME4 = "@contentful/experience-design-system-cli";
|
|
464
|
-
SESSION_ID = generateSessionId();
|
|
465
|
-
void isDebugModeEnabled().then((enabled) => {
|
|
466
|
-
if (!enabled) return void 0;
|
|
467
|
-
return mkdir2(sessionDebugDir(), { recursive: true });
|
|
468
|
-
});
|
|
469
|
-
process.once("uncaughtException", (err) => {
|
|
470
|
-
void handleCrash().finally(() => {
|
|
471
|
-
throw err;
|
|
472
|
-
});
|
|
473
|
-
});
|
|
474
|
-
process.once("unhandledRejection", (reason) => {
|
|
475
|
-
void handleCrash().finally(() => {
|
|
476
|
-
throw reason;
|
|
477
|
-
});
|
|
478
|
-
});
|
|
479
|
-
process.once("SIGINT", () => {
|
|
480
|
-
void handleCrash().finally(() => {
|
|
481
|
-
process.exit(130);
|
|
482
|
-
});
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
});
|
|
486
|
-
|
|
487
300
|
// packages/experience-design-system-cli/src/tui/import/spawn-v1-import.ts
|
|
488
301
|
import { spawn as spawn2 } from "node:child_process";
|
|
489
302
|
function buildArgs(options) {
|
|
@@ -496,11 +309,9 @@ function buildArgs(options) {
|
|
|
496
309
|
async function spawnV1Import(options = {}) {
|
|
497
310
|
const cliPath = findLegacyCliPath();
|
|
498
311
|
const args = buildArgs(options);
|
|
499
|
-
const debugSessionDir = await debugSessionDirIfEnabled();
|
|
500
312
|
return new Promise((resolvePromise) => {
|
|
501
313
|
const child = spawn2("node", [cliPath, ...args], {
|
|
502
|
-
stdio: "inherit"
|
|
503
|
-
env: debugSessionDir ? { ...process.env, EDS_DEBUG_SESSION_DIR: debugSessionDir } : process.env
|
|
314
|
+
stdio: "inherit"
|
|
504
315
|
});
|
|
505
316
|
child.on("close", (code) => {
|
|
506
317
|
resolvePromise({ exitCode: code ?? 1, result: void 0, stdout: "", stderr: "" });
|
|
@@ -514,7 +325,6 @@ var init_spawn_v1_import = __esm({
|
|
|
514
325
|
"packages/experience-design-system-cli/src/tui/import/spawn-v1-import.ts"() {
|
|
515
326
|
"use strict";
|
|
516
327
|
init_legacy_cli_path();
|
|
517
|
-
init_debug_store();
|
|
518
328
|
}
|
|
519
329
|
});
|
|
520
330
|
|
|
@@ -542,24 +352,16 @@ var init_terminal_input = __esm({
|
|
|
542
352
|
});
|
|
543
353
|
|
|
544
354
|
// packages/experience-design-system-cli/src/tui/help/PageContainer.tsx
|
|
545
|
-
import { useEffect as useEffect3 } from "react";
|
|
546
355
|
import { Box as Box3, Text as Text3, useInput as useInput3 } from "ink";
|
|
547
356
|
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
548
357
|
function HelpScreen({ onDone }) {
|
|
549
|
-
useEffect3(() => {
|
|
550
|
-
startDebugRun({ flow: "help", step: "01-help", menuOption: "Help", inputs: {} });
|
|
551
|
-
}, []);
|
|
552
|
-
const leave = (exitMethod) => {
|
|
553
|
-
void finishDebugRun({ outputs: {}, status: "success", exitMethod });
|
|
554
|
-
onDone();
|
|
555
|
-
};
|
|
556
358
|
useInput3((input, key) => {
|
|
557
359
|
if (key.return) {
|
|
558
|
-
|
|
360
|
+
onDone();
|
|
559
361
|
return;
|
|
560
362
|
}
|
|
561
363
|
if (key.escape || input === "q") {
|
|
562
|
-
|
|
364
|
+
onDone();
|
|
563
365
|
return;
|
|
564
366
|
}
|
|
565
367
|
});
|
|
@@ -574,7 +376,6 @@ function HelpScreen({ onDone }) {
|
|
|
574
376
|
var init_PageContainer2 = __esm({
|
|
575
377
|
"packages/experience-design-system-cli/src/tui/help/PageContainer.tsx"() {
|
|
576
378
|
"use strict";
|
|
577
|
-
init_debug_store();
|
|
578
379
|
}
|
|
579
380
|
});
|
|
580
381
|
|
|
@@ -630,27 +431,27 @@ var init_PageContainer3 = __esm({
|
|
|
630
431
|
});
|
|
631
432
|
|
|
632
433
|
// packages/experience-design-system-cli/src/tui/settings/utils/v1-store.ts
|
|
633
|
-
import { readFile
|
|
634
|
-
import { join as
|
|
434
|
+
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
435
|
+
import { join as join4 } from "node:path";
|
|
635
436
|
import { homedir } from "node:os";
|
|
636
437
|
async function readV1Store() {
|
|
637
438
|
try {
|
|
638
|
-
const raw = await
|
|
439
|
+
const raw = await readFile(V1_STORE_PATH, "utf8");
|
|
639
440
|
return JSON.parse(raw);
|
|
640
441
|
} catch {
|
|
641
442
|
return {};
|
|
642
443
|
}
|
|
643
444
|
}
|
|
644
445
|
async function writeV1Store(data) {
|
|
645
|
-
await
|
|
646
|
-
await
|
|
446
|
+
await mkdir(join4(homedir(), ".config", "experiences"), { recursive: true });
|
|
447
|
+
await writeFile(V1_STORE_PATH, `${JSON.stringify(data, null, 2)}
|
|
647
448
|
`, { mode: 384 });
|
|
648
449
|
}
|
|
649
450
|
var V1_STORE_PATH;
|
|
650
451
|
var init_v1_store = __esm({
|
|
651
452
|
"packages/experience-design-system-cli/src/tui/settings/utils/v1-store.ts"() {
|
|
652
453
|
"use strict";
|
|
653
|
-
V1_STORE_PATH =
|
|
454
|
+
V1_STORE_PATH = join4(homedir(), ".config", "experiences", "credentials.json");
|
|
654
455
|
}
|
|
655
456
|
});
|
|
656
457
|
|
|
@@ -683,32 +484,18 @@ var init_config_store = __esm({
|
|
|
683
484
|
});
|
|
684
485
|
|
|
685
486
|
// packages/experience-design-system-cli/src/tui/settings/contentful-configuration/ContentfulConfigScreen.tsx
|
|
686
|
-
import { useEffect as
|
|
487
|
+
import { useEffect as useEffect3, useState as useState4 } from "react";
|
|
687
488
|
import { Box as Box5, Text as Text5, useInput as useInput5 } from "ink";
|
|
688
489
|
import { Fragment, jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
689
|
-
function debugFields(config) {
|
|
690
|
-
return {
|
|
691
|
-
space_id: config?.spaceId ?? "",
|
|
692
|
-
environment_id: config?.environmentId ?? "",
|
|
693
|
-
cma_token: config?.cmaToken ?? "",
|
|
694
|
-
host: config?.host ?? ""
|
|
695
|
-
};
|
|
696
|
-
}
|
|
697
490
|
function ConfigurationScreen({ onDone }) {
|
|
698
491
|
const [stage, setStage] = useState4("loading");
|
|
699
492
|
const [config, setConfig] = useState4(null);
|
|
700
493
|
const [activeField, setActiveField] = useState4("spaceId");
|
|
701
494
|
const [message, setMessage] = useState4(null);
|
|
702
|
-
|
|
495
|
+
useEffect3(() => {
|
|
703
496
|
readCredentials().then((cfg) => {
|
|
704
497
|
setConfig(cfg);
|
|
705
498
|
setStage("form");
|
|
706
|
-
startDebugRun({
|
|
707
|
-
flow: "settings/contentful-configuration",
|
|
708
|
-
step: "01-configuration",
|
|
709
|
-
menuOption: "Configuration",
|
|
710
|
-
inputs: debugFields(cfg)
|
|
711
|
-
});
|
|
712
499
|
});
|
|
713
500
|
}, []);
|
|
714
501
|
function fieldValue(field) {
|
|
@@ -735,13 +522,11 @@ function ConfigurationScreen({ onDone }) {
|
|
|
735
522
|
if (stage === "loading" || stage === "saving") return;
|
|
736
523
|
if (stage === "saved") {
|
|
737
524
|
if (key.return || key.escape || input === "q") {
|
|
738
|
-
void finishDebugRun({ outputs: debugFields(config), status: "success", exitMethod: "saved" });
|
|
739
525
|
onDone();
|
|
740
526
|
}
|
|
741
527
|
return;
|
|
742
528
|
}
|
|
743
529
|
if (key.escape || input === "q") {
|
|
744
|
-
void finishDebugRun({ outputs: {}, status: "success", exitMethod: "discarded" });
|
|
745
530
|
onDone();
|
|
746
531
|
return;
|
|
747
532
|
}
|
|
@@ -827,7 +612,6 @@ var init_ContentfulConfigScreen = __esm({
|
|
|
827
612
|
"use strict";
|
|
828
613
|
init_home_theme();
|
|
829
614
|
init_config_store();
|
|
830
|
-
init_debug_store();
|
|
831
615
|
FIELD_ORDER = ["spaceId", "environmentId", "cmaToken", "host"];
|
|
832
616
|
FIELD_LABELS = {
|
|
833
617
|
spaceId: "Space ID",
|
|
@@ -860,22 +644,16 @@ var init_analytics_store = __esm({
|
|
|
860
644
|
});
|
|
861
645
|
|
|
862
646
|
// packages/experience-design-system-cli/src/tui/settings/opt-in-analytics/screen.tsx
|
|
863
|
-
import { useEffect as
|
|
647
|
+
import { useEffect as useEffect4, useState as useState5 } from "react";
|
|
864
648
|
import { Box as Box6, Text as Text6, useInput as useInput6 } from "ink";
|
|
865
649
|
import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
866
650
|
function OptInAnalyticsScreen({ onDone }) {
|
|
867
651
|
const [loading, setLoading] = useState5(true);
|
|
868
652
|
const [enabled, setEnabled] = useState5(true);
|
|
869
|
-
|
|
653
|
+
useEffect4(() => {
|
|
870
654
|
readAnalyticsSetting().then((setting) => {
|
|
871
655
|
setEnabled(setting.enabled);
|
|
872
656
|
setLoading(false);
|
|
873
|
-
startDebugRun({
|
|
874
|
-
flow: "settings/opt-in-analytics",
|
|
875
|
-
step: "01-opt-in-analytics",
|
|
876
|
-
menuOption: "Opt-in Analytics",
|
|
877
|
-
inputs: { enabled: setting.enabled }
|
|
878
|
-
});
|
|
879
657
|
});
|
|
880
658
|
}, []);
|
|
881
659
|
useInput6((input, key) => {
|
|
@@ -889,7 +667,6 @@ function OptInAnalyticsScreen({ onDone }) {
|
|
|
889
667
|
return;
|
|
890
668
|
}
|
|
891
669
|
if (key.escape || input === "q") {
|
|
892
|
-
void finishDebugRun({ outputs: { enabled }, status: "success", exitMethod: "saved" });
|
|
893
670
|
onDone();
|
|
894
671
|
}
|
|
895
672
|
});
|
|
@@ -915,17 +692,200 @@ var init_screen = __esm({
|
|
|
915
692
|
"use strict";
|
|
916
693
|
init_home_theme();
|
|
917
694
|
init_analytics_store();
|
|
918
|
-
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
// packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts
|
|
699
|
+
import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
|
|
700
|
+
import { dirname as dirname2, join as join5 } from "node:path";
|
|
701
|
+
function debugModeSettingPath() {
|
|
702
|
+
return join5(findPackageRoot(import.meta.url, PACKAGE_NAME3), ".contentful", "config", "debug_mode.json");
|
|
703
|
+
}
|
|
704
|
+
async function readDebugModeSetting() {
|
|
705
|
+
try {
|
|
706
|
+
const raw = await readFile2(debugModeSettingPath(), "utf8");
|
|
707
|
+
const parsed = JSON.parse(raw);
|
|
708
|
+
return { ...DEFAULT_DEBUG_MODE_SETTING, ...parsed };
|
|
709
|
+
} catch {
|
|
710
|
+
return { ...DEFAULT_DEBUG_MODE_SETTING };
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
async function writeDebugModeSetting(setting) {
|
|
714
|
+
const path = debugModeSettingPath();
|
|
715
|
+
await mkdir2(dirname2(path), { recursive: true });
|
|
716
|
+
await writeFile2(path, `${JSON.stringify(setting, null, 2)}
|
|
717
|
+
`, { mode: 384 });
|
|
718
|
+
}
|
|
719
|
+
var PACKAGE_NAME3, DEFAULT_DEBUG_MODE_SETTING;
|
|
720
|
+
var init_debug_mode_store = __esm({
|
|
721
|
+
"packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts"() {
|
|
722
|
+
"use strict";
|
|
723
|
+
init_package_root();
|
|
724
|
+
PACKAGE_NAME3 = "@contentful/experience-design-system-cli";
|
|
725
|
+
DEFAULT_DEBUG_MODE_SETTING = {
|
|
726
|
+
enabled: true
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
// packages/experience-design-system-cli/src/tui/debug-store.ts
|
|
732
|
+
import { mkdir as mkdir3, writeFile as writeFile3 } from "node:fs/promises";
|
|
733
|
+
import { existsSync as existsSync3, readdirSync } from "node:fs";
|
|
734
|
+
import { join as join6 } from "node:path";
|
|
735
|
+
function generateRunId() {
|
|
736
|
+
const now = /* @__PURE__ */ new Date();
|
|
737
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
738
|
+
return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
|
|
739
|
+
}
|
|
740
|
+
function sessionsRootDir() {
|
|
741
|
+
return join6(findPackageRoot(import.meta.url, PACKAGE_NAME4), ".contentful", "debug", "sessions");
|
|
742
|
+
}
|
|
743
|
+
function datePrefix(now = /* @__PURE__ */ new Date()) {
|
|
744
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
745
|
+
return `${pad(now.getMonth() + 1)}-${pad(now.getDate())}-${now.getFullYear()}`;
|
|
746
|
+
}
|
|
747
|
+
function slugify(value) {
|
|
748
|
+
return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
749
|
+
}
|
|
750
|
+
function generateSessionId() {
|
|
751
|
+
const today = datePrefix();
|
|
752
|
+
const root = sessionsRootDir();
|
|
753
|
+
const existing = existsSync3(root) ? readdirSync(root) : [];
|
|
754
|
+
const seqPattern = new RegExp(`^${today}-session-(\\d+)$`);
|
|
755
|
+
const maxSeq = existing.reduce((max, entry) => {
|
|
756
|
+
const match = seqPattern.exec(entry);
|
|
757
|
+
return match ? Math.max(max, Number(match[1])) : max;
|
|
758
|
+
}, 0);
|
|
759
|
+
return `${today}-session-${maxSeq + 1}`;
|
|
760
|
+
}
|
|
761
|
+
function sessionDebugDir() {
|
|
762
|
+
return join6(sessionsRootDir(), SESSION_ID);
|
|
763
|
+
}
|
|
764
|
+
async function isDebugModeEnabled() {
|
|
765
|
+
try {
|
|
766
|
+
return (await readDebugModeSetting()).enabled;
|
|
767
|
+
} catch {
|
|
768
|
+
return true;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
function redact(value) {
|
|
772
|
+
const clone = { ...value };
|
|
773
|
+
if ("cma_token" in clone) {
|
|
774
|
+
const raw = clone.cma_token;
|
|
775
|
+
clone.cma_token = typeof raw === "string" && raw.length > 0 ? `[present, ${raw.length} chars]` : "[not set]";
|
|
776
|
+
}
|
|
777
|
+
return clone;
|
|
778
|
+
}
|
|
779
|
+
function startDebugRun({
|
|
780
|
+
flow,
|
|
781
|
+
step,
|
|
782
|
+
menuOption,
|
|
783
|
+
inputs
|
|
784
|
+
}) {
|
|
785
|
+
const runId = generateRunId();
|
|
786
|
+
const startedAt = Date.now();
|
|
787
|
+
const redactedInputs = redact(inputs);
|
|
788
|
+
isDebugModeEnabled().then((enabled) => {
|
|
789
|
+
if (!enabled) return;
|
|
790
|
+
pendingRun = { flow, step, runId, menuOption, inputs: redactedInputs, startedAt };
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
async function finishDebugRun({
|
|
794
|
+
outputs,
|
|
795
|
+
status,
|
|
796
|
+
exitMethod
|
|
797
|
+
}) {
|
|
798
|
+
const run = pendingRun;
|
|
799
|
+
if (!run) return;
|
|
800
|
+
pendingRun = void 0;
|
|
801
|
+
const durationMs = Date.now() - run.startedAt;
|
|
802
|
+
const content = renderMarkdown(run, { outputs: redact(outputs), status, exitMethod, durationMs });
|
|
803
|
+
const flowSegments = run.flow.split("/");
|
|
804
|
+
const dir = join6(sessionDebugDir(), ...flowSegments);
|
|
805
|
+
await mkdir3(dir, { recursive: true });
|
|
806
|
+
const filename = nextAttemptFilename(dir, run.menuOption);
|
|
807
|
+
await writeFile3(join6(dir, filename), content, { mode: 384 });
|
|
808
|
+
}
|
|
809
|
+
function nextAttemptFilename(dir, menuOption) {
|
|
810
|
+
const today = datePrefix();
|
|
811
|
+
const optionSlug = slugify(menuOption);
|
|
812
|
+
const existing = existsSync3(dir) ? readdirSync(dir) : [];
|
|
813
|
+
const attemptPattern = new RegExp(`^${today}-${optionSlug}-attempt-(\\d+)\\.md$`);
|
|
814
|
+
const maxAttempt = existing.reduce((max, entry) => {
|
|
815
|
+
const match = attemptPattern.exec(entry);
|
|
816
|
+
return match ? Math.max(max, Number(match[1])) : max;
|
|
817
|
+
}, 0);
|
|
818
|
+
return `${today}-${optionSlug}-attempt-${maxAttempt + 1}.md`;
|
|
819
|
+
}
|
|
820
|
+
function renderMarkdown(run, finish) {
|
|
821
|
+
const stepMatch = /^(\d+)-(.+)$/.exec(run.step);
|
|
822
|
+
const stepLabel = stepMatch ? `${stepMatch[1]} - ${stepMatch[2]}` : run.step;
|
|
823
|
+
const flowSlug = run.flow.split("/").join("-");
|
|
824
|
+
return `# Debug Log
|
|
825
|
+
|
|
826
|
+
- Run ID: ${run.runId}
|
|
827
|
+
- Flow: ${flowSlug}
|
|
828
|
+
- Step: ${stepLabel}
|
|
829
|
+
- Menu option: ${run.menuOption}
|
|
830
|
+
- Date: ${(/* @__PURE__ */ new Date()).toISOString()}
|
|
831
|
+
- CLI version: ${readPackageVersion()}
|
|
832
|
+
- Platform: ${process.platform} / Node ${process.version}
|
|
833
|
+
- Duration on screen: ${finish.durationMs}ms
|
|
834
|
+
- Status: ${finish.status}
|
|
835
|
+
- Exit method: ${finish.exitMethod}
|
|
836
|
+
|
|
837
|
+
## Inputs
|
|
838
|
+
\`\`\`json
|
|
839
|
+
${JSON.stringify(run.inputs, null, 2)}
|
|
840
|
+
\`\`\`
|
|
841
|
+
|
|
842
|
+
## Outputs
|
|
843
|
+
\`\`\`json
|
|
844
|
+
${JSON.stringify(finish.outputs, null, 2)}
|
|
845
|
+
\`\`\`
|
|
846
|
+
`;
|
|
847
|
+
}
|
|
848
|
+
function handleCrash() {
|
|
849
|
+
return finishDebugRun({ outputs: {}, status: "error", exitMethod: "crashed" });
|
|
850
|
+
}
|
|
851
|
+
var PACKAGE_NAME4, pendingRun, SESSION_ID;
|
|
852
|
+
var init_debug_store = __esm({
|
|
853
|
+
"packages/experience-design-system-cli/src/tui/debug-store.ts"() {
|
|
854
|
+
"use strict";
|
|
855
|
+
init_package_root();
|
|
856
|
+
init_version();
|
|
857
|
+
init_debug_mode_store();
|
|
858
|
+
PACKAGE_NAME4 = "@contentful/experience-design-system-cli";
|
|
859
|
+
SESSION_ID = generateSessionId();
|
|
860
|
+
void isDebugModeEnabled().then((enabled) => {
|
|
861
|
+
if (!enabled) return void 0;
|
|
862
|
+
return mkdir3(sessionDebugDir(), { recursive: true });
|
|
863
|
+
});
|
|
864
|
+
process.once("uncaughtException", (err) => {
|
|
865
|
+
void handleCrash().finally(() => {
|
|
866
|
+
throw err;
|
|
867
|
+
});
|
|
868
|
+
});
|
|
869
|
+
process.once("unhandledRejection", (reason) => {
|
|
870
|
+
void handleCrash().finally(() => {
|
|
871
|
+
throw reason;
|
|
872
|
+
});
|
|
873
|
+
});
|
|
874
|
+
process.once("SIGINT", () => {
|
|
875
|
+
void handleCrash().finally(() => {
|
|
876
|
+
process.exit(130);
|
|
877
|
+
});
|
|
878
|
+
});
|
|
919
879
|
}
|
|
920
880
|
});
|
|
921
881
|
|
|
922
882
|
// packages/experience-design-system-cli/src/tui/upgrade/PageContainer.tsx
|
|
923
|
-
import { useEffect as
|
|
883
|
+
import { useEffect as useEffect5, useState as useState6 } from "react";
|
|
924
884
|
import { Box as Box7, Text as Text7, useInput as useInput7 } from "ink";
|
|
925
885
|
import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
926
886
|
function UpgradeScreen({ onDone }) {
|
|
927
887
|
const [upgradeCheck, setUpgradeCheck] = useState6();
|
|
928
|
-
|
|
888
|
+
useEffect5(() => {
|
|
929
889
|
startDebugRun({
|
|
930
890
|
flow: "upgrade",
|
|
931
891
|
step: "01-upgrade",
|
|
@@ -1000,22 +960,16 @@ var init_PageContainer4 = __esm({
|
|
|
1000
960
|
});
|
|
1001
961
|
|
|
1002
962
|
// packages/experience-design-system-cli/src/tui/settings/debug-mode/screen.tsx
|
|
1003
|
-
import { useEffect as
|
|
963
|
+
import { useEffect as useEffect6, useState as useState7 } from "react";
|
|
1004
964
|
import { Box as Box8, Text as Text8, useInput as useInput8 } from "ink";
|
|
1005
965
|
import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1006
966
|
function DebugModeScreen({ onDone }) {
|
|
1007
967
|
const [loading, setLoading] = useState7(true);
|
|
1008
968
|
const [enabled, setEnabled] = useState7(true);
|
|
1009
|
-
|
|
969
|
+
useEffect6(() => {
|
|
1010
970
|
readDebugModeSetting().then((setting) => {
|
|
1011
971
|
setEnabled(setting.enabled);
|
|
1012
972
|
setLoading(false);
|
|
1013
|
-
startDebugRun({
|
|
1014
|
-
flow: "settings/debug-mode",
|
|
1015
|
-
step: "01-debug-mode",
|
|
1016
|
-
menuOption: "Debug Mode",
|
|
1017
|
-
inputs: { enabled: setting.enabled }
|
|
1018
|
-
});
|
|
1019
973
|
});
|
|
1020
974
|
}, []);
|
|
1021
975
|
useInput8((input, key) => {
|
|
@@ -1029,7 +983,6 @@ function DebugModeScreen({ onDone }) {
|
|
|
1029
983
|
return;
|
|
1030
984
|
}
|
|
1031
985
|
if (key.escape || input === "q") {
|
|
1032
|
-
void finishDebugRun({ outputs: { enabled }, status: "success", exitMethod: "saved" });
|
|
1033
986
|
onDone();
|
|
1034
987
|
}
|
|
1035
988
|
});
|
|
@@ -1050,7 +1003,6 @@ var init_screen2 = __esm({
|
|
|
1050
1003
|
"use strict";
|
|
1051
1004
|
init_home_theme();
|
|
1052
1005
|
init_debug_mode_store();
|
|
1053
|
-
init_debug_store();
|
|
1054
1006
|
}
|
|
1055
1007
|
});
|
|
1056
1008
|
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
type Status = 'success' | 'error';
|
|
2
2
|
type ExitMethod = 'saved' | 'discarded' | 'crashed';
|
|
3
|
-
export declare function debugSessionDirIfEnabled(): Promise<string | undefined>;
|
|
4
3
|
export declare function startDebugRun({ flow, step, menuOption, inputs, }: {
|
|
5
4
|
flow: string;
|
|
6
5
|
step: string;
|
|
@@ -13,10 +13,9 @@ type WizardPreviewStepProps = {
|
|
|
13
13
|
environmentId: string;
|
|
14
14
|
stepNumber: number;
|
|
15
15
|
totalSteps: number;
|
|
16
|
-
droppedTokenDefaults?: string[];
|
|
17
16
|
onConfirm: (acknowledge: boolean) => void;
|
|
18
17
|
onEdit?: () => void;
|
|
19
18
|
onQuit: () => void;
|
|
20
19
|
};
|
|
21
|
-
export declare function WizardPreviewStep({ preview, spaceId, environmentId, stepNumber, totalSteps,
|
|
20
|
+
export declare function WizardPreviewStep({ preview, spaceId, environmentId, stepNumber, totalSteps, onConfirm, onEdit, onQuit, }: WizardPreviewStepProps): React.ReactElement;
|
|
22
21
|
export {};
|