@contentful/experience-design-system-cli 2.35.1-dev-build-45d6c918.0 → 2.36.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 +189 -227
- package/dist/index.js +200 -242
- package/dist/package.json +1 -1
- package/legacy/dist/src/index.js +668 -867
- package/legacy/package.json +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -351,209 +351,17 @@ var init_terminal_input = __esm({
|
|
|
351
351
|
}
|
|
352
352
|
});
|
|
353
353
|
|
|
354
|
-
// packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts
|
|
355
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
356
|
-
import { dirname as dirname2, join as join4 } from "node:path";
|
|
357
|
-
function debugModeSettingPath() {
|
|
358
|
-
return join4(findPackageRoot(import.meta.url, PACKAGE_NAME3), ".contentful", "config", "debug_mode.json");
|
|
359
|
-
}
|
|
360
|
-
async function readDebugModeSetting() {
|
|
361
|
-
try {
|
|
362
|
-
const raw = await readFile(debugModeSettingPath(), "utf8");
|
|
363
|
-
const parsed = JSON.parse(raw);
|
|
364
|
-
return { ...DEFAULT_DEBUG_MODE_SETTING, ...parsed };
|
|
365
|
-
} catch {
|
|
366
|
-
return { ...DEFAULT_DEBUG_MODE_SETTING };
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
async function writeDebugModeSetting(setting) {
|
|
370
|
-
const path = debugModeSettingPath();
|
|
371
|
-
await mkdir(dirname2(path), { recursive: true });
|
|
372
|
-
await writeFile(path, `${JSON.stringify(setting, null, 2)}
|
|
373
|
-
`, { mode: 384 });
|
|
374
|
-
}
|
|
375
|
-
var PACKAGE_NAME3, DEFAULT_DEBUG_MODE_SETTING;
|
|
376
|
-
var init_debug_mode_store = __esm({
|
|
377
|
-
"packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts"() {
|
|
378
|
-
"use strict";
|
|
379
|
-
init_package_root();
|
|
380
|
-
PACKAGE_NAME3 = "@contentful/experience-design-system-cli";
|
|
381
|
-
DEFAULT_DEBUG_MODE_SETTING = {
|
|
382
|
-
enabled: true
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
// packages/experience-design-system-cli/src/tui/debug-store.ts
|
|
388
|
-
import { mkdir as mkdir2, writeFile as writeFile2 } from "node:fs/promises";
|
|
389
|
-
import { existsSync as existsSync3, readdirSync } from "node:fs";
|
|
390
|
-
import { join as join5 } from "node:path";
|
|
391
|
-
function generateRunId() {
|
|
392
|
-
const now = /* @__PURE__ */ new Date();
|
|
393
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
394
|
-
return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
|
|
395
|
-
}
|
|
396
|
-
function sessionsRootDir() {
|
|
397
|
-
return join5(findPackageRoot(import.meta.url, PACKAGE_NAME4), ".contentful", "debug", "sessions");
|
|
398
|
-
}
|
|
399
|
-
function datePrefix(now = /* @__PURE__ */ new Date()) {
|
|
400
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
401
|
-
return `${pad(now.getMonth() + 1)}-${pad(now.getDate())}-${now.getFullYear()}`;
|
|
402
|
-
}
|
|
403
|
-
function slugify(value) {
|
|
404
|
-
return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
405
|
-
}
|
|
406
|
-
function generateSessionId() {
|
|
407
|
-
const today = datePrefix();
|
|
408
|
-
const root = sessionsRootDir();
|
|
409
|
-
const existing = existsSync3(root) ? readdirSync(root) : [];
|
|
410
|
-
const seqPattern = new RegExp(`^${today}-session-(\\d+)$`);
|
|
411
|
-
const maxSeq = existing.reduce((max, entry) => {
|
|
412
|
-
const match = seqPattern.exec(entry);
|
|
413
|
-
return match ? Math.max(max, Number(match[1])) : max;
|
|
414
|
-
}, 0);
|
|
415
|
-
return `${today}-session-${maxSeq + 1}`;
|
|
416
|
-
}
|
|
417
|
-
function sessionDebugDir() {
|
|
418
|
-
return join5(sessionsRootDir(), SESSION_ID);
|
|
419
|
-
}
|
|
420
|
-
async function isDebugModeEnabled() {
|
|
421
|
-
try {
|
|
422
|
-
return (await readDebugModeSetting()).enabled;
|
|
423
|
-
} catch {
|
|
424
|
-
return true;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
function redact(value) {
|
|
428
|
-
const clone = { ...value };
|
|
429
|
-
if ("cma_token" in clone) {
|
|
430
|
-
const raw = clone.cma_token;
|
|
431
|
-
clone.cma_token = typeof raw === "string" && raw.length > 0 ? `[present, ${raw.length} chars]` : "[not set]";
|
|
432
|
-
}
|
|
433
|
-
return clone;
|
|
434
|
-
}
|
|
435
|
-
function startDebugRun({
|
|
436
|
-
flow,
|
|
437
|
-
step,
|
|
438
|
-
menuOption,
|
|
439
|
-
inputs
|
|
440
|
-
}) {
|
|
441
|
-
const runId = generateRunId();
|
|
442
|
-
const startedAt = Date.now();
|
|
443
|
-
const redactedInputs = redact(inputs);
|
|
444
|
-
isDebugModeEnabled().then((enabled) => {
|
|
445
|
-
if (!enabled) return;
|
|
446
|
-
pendingRun = { flow, step, runId, menuOption, inputs: redactedInputs, startedAt };
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
async function finishDebugRun({
|
|
450
|
-
outputs,
|
|
451
|
-
status,
|
|
452
|
-
exitMethod
|
|
453
|
-
}) {
|
|
454
|
-
const run = pendingRun;
|
|
455
|
-
if (!run) return;
|
|
456
|
-
pendingRun = void 0;
|
|
457
|
-
const durationMs = Date.now() - run.startedAt;
|
|
458
|
-
const content = renderMarkdown(run, { outputs: redact(outputs), status, exitMethod, durationMs });
|
|
459
|
-
const flowSegments = run.flow.split("/");
|
|
460
|
-
const dir = join5(sessionDebugDir(), ...flowSegments);
|
|
461
|
-
await mkdir2(dir, { recursive: true });
|
|
462
|
-
const filename = nextAttemptFilename(dir, run.menuOption);
|
|
463
|
-
await writeFile2(join5(dir, filename), content, { mode: 384 });
|
|
464
|
-
}
|
|
465
|
-
function nextAttemptFilename(dir, menuOption) {
|
|
466
|
-
const today = datePrefix();
|
|
467
|
-
const optionSlug = slugify(menuOption);
|
|
468
|
-
const existing = existsSync3(dir) ? readdirSync(dir) : [];
|
|
469
|
-
const attemptPattern = new RegExp(`^${today}-${optionSlug}-attempt-(\\d+)\\.md$`);
|
|
470
|
-
const maxAttempt = existing.reduce((max, entry) => {
|
|
471
|
-
const match = attemptPattern.exec(entry);
|
|
472
|
-
return match ? Math.max(max, Number(match[1])) : max;
|
|
473
|
-
}, 0);
|
|
474
|
-
return `${today}-${optionSlug}-attempt-${maxAttempt + 1}.md`;
|
|
475
|
-
}
|
|
476
|
-
function renderMarkdown(run, finish) {
|
|
477
|
-
const stepMatch = /^(\d+)-(.+)$/.exec(run.step);
|
|
478
|
-
const stepLabel = stepMatch ? `${stepMatch[1]} - ${stepMatch[2]}` : run.step;
|
|
479
|
-
const flowSlug = run.flow.split("/").join("-");
|
|
480
|
-
return `# Debug Log
|
|
481
|
-
|
|
482
|
-
- Run ID: ${run.runId}
|
|
483
|
-
- Flow: ${flowSlug}
|
|
484
|
-
- Step: ${stepLabel}
|
|
485
|
-
- Menu option: ${run.menuOption}
|
|
486
|
-
- Date: ${(/* @__PURE__ */ new Date()).toISOString()}
|
|
487
|
-
- CLI version: ${readPackageVersion()}
|
|
488
|
-
- Platform: ${process.platform} / Node ${process.version}
|
|
489
|
-
- Duration on screen: ${finish.durationMs}ms
|
|
490
|
-
- Status: ${finish.status}
|
|
491
|
-
- Exit method: ${finish.exitMethod}
|
|
492
|
-
|
|
493
|
-
## Inputs
|
|
494
|
-
\`\`\`json
|
|
495
|
-
${JSON.stringify(run.inputs, null, 2)}
|
|
496
|
-
\`\`\`
|
|
497
|
-
|
|
498
|
-
## Outputs
|
|
499
|
-
\`\`\`json
|
|
500
|
-
${JSON.stringify(finish.outputs, null, 2)}
|
|
501
|
-
\`\`\`
|
|
502
|
-
`;
|
|
503
|
-
}
|
|
504
|
-
function handleCrash() {
|
|
505
|
-
return finishDebugRun({ outputs: {}, status: "error", exitMethod: "crashed" });
|
|
506
|
-
}
|
|
507
|
-
var PACKAGE_NAME4, pendingRun, SESSION_ID;
|
|
508
|
-
var init_debug_store = __esm({
|
|
509
|
-
"packages/experience-design-system-cli/src/tui/debug-store.ts"() {
|
|
510
|
-
"use strict";
|
|
511
|
-
init_package_root();
|
|
512
|
-
init_version();
|
|
513
|
-
init_debug_mode_store();
|
|
514
|
-
PACKAGE_NAME4 = "@contentful/experience-design-system-cli";
|
|
515
|
-
SESSION_ID = generateSessionId();
|
|
516
|
-
void isDebugModeEnabled().then((enabled) => {
|
|
517
|
-
if (!enabled) return void 0;
|
|
518
|
-
return mkdir2(sessionDebugDir(), { recursive: true });
|
|
519
|
-
});
|
|
520
|
-
process.once("uncaughtException", (err) => {
|
|
521
|
-
void handleCrash().finally(() => {
|
|
522
|
-
throw err;
|
|
523
|
-
});
|
|
524
|
-
});
|
|
525
|
-
process.once("unhandledRejection", (reason) => {
|
|
526
|
-
void handleCrash().finally(() => {
|
|
527
|
-
throw reason;
|
|
528
|
-
});
|
|
529
|
-
});
|
|
530
|
-
process.once("SIGINT", () => {
|
|
531
|
-
void handleCrash().finally(() => {
|
|
532
|
-
process.exit(130);
|
|
533
|
-
});
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
});
|
|
537
|
-
|
|
538
354
|
// packages/experience-design-system-cli/src/tui/help/PageContainer.tsx
|
|
539
|
-
import { useEffect as useEffect3 } from "react";
|
|
540
355
|
import { Box as Box3, Text as Text3, useInput as useInput3 } from "ink";
|
|
541
356
|
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
542
357
|
function HelpScreen({ onDone }) {
|
|
543
|
-
useEffect3(() => {
|
|
544
|
-
startDebugRun({ flow: "help", step: "01-help", menuOption: "Help", inputs: {} });
|
|
545
|
-
}, []);
|
|
546
|
-
const leave = (exitMethod) => {
|
|
547
|
-
void finishDebugRun({ outputs: {}, status: "success", exitMethod });
|
|
548
|
-
onDone();
|
|
549
|
-
};
|
|
550
358
|
useInput3((input, key) => {
|
|
551
359
|
if (key.return) {
|
|
552
|
-
|
|
360
|
+
onDone();
|
|
553
361
|
return;
|
|
554
362
|
}
|
|
555
363
|
if (key.escape || input === "q") {
|
|
556
|
-
|
|
364
|
+
onDone();
|
|
557
365
|
return;
|
|
558
366
|
}
|
|
559
367
|
});
|
|
@@ -568,7 +376,6 @@ function HelpScreen({ onDone }) {
|
|
|
568
376
|
var init_PageContainer2 = __esm({
|
|
569
377
|
"packages/experience-design-system-cli/src/tui/help/PageContainer.tsx"() {
|
|
570
378
|
"use strict";
|
|
571
|
-
init_debug_store();
|
|
572
379
|
}
|
|
573
380
|
});
|
|
574
381
|
|
|
@@ -624,27 +431,27 @@ var init_PageContainer3 = __esm({
|
|
|
624
431
|
});
|
|
625
432
|
|
|
626
433
|
// packages/experience-design-system-cli/src/tui/settings/utils/v1-store.ts
|
|
627
|
-
import { readFile
|
|
628
|
-
import { join as
|
|
434
|
+
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
435
|
+
import { join as join4 } from "node:path";
|
|
629
436
|
import { homedir } from "node:os";
|
|
630
437
|
async function readV1Store() {
|
|
631
438
|
try {
|
|
632
|
-
const raw = await
|
|
439
|
+
const raw = await readFile(V1_STORE_PATH, "utf8");
|
|
633
440
|
return JSON.parse(raw);
|
|
634
441
|
} catch {
|
|
635
442
|
return {};
|
|
636
443
|
}
|
|
637
444
|
}
|
|
638
445
|
async function writeV1Store(data) {
|
|
639
|
-
await
|
|
640
|
-
await
|
|
446
|
+
await mkdir(join4(homedir(), ".config", "experiences"), { recursive: true });
|
|
447
|
+
await writeFile(V1_STORE_PATH, `${JSON.stringify(data, null, 2)}
|
|
641
448
|
`, { mode: 384 });
|
|
642
449
|
}
|
|
643
450
|
var V1_STORE_PATH;
|
|
644
451
|
var init_v1_store = __esm({
|
|
645
452
|
"packages/experience-design-system-cli/src/tui/settings/utils/v1-store.ts"() {
|
|
646
453
|
"use strict";
|
|
647
|
-
V1_STORE_PATH =
|
|
454
|
+
V1_STORE_PATH = join4(homedir(), ".config", "experiences", "credentials.json");
|
|
648
455
|
}
|
|
649
456
|
});
|
|
650
457
|
|
|
@@ -677,32 +484,18 @@ var init_config_store = __esm({
|
|
|
677
484
|
});
|
|
678
485
|
|
|
679
486
|
// packages/experience-design-system-cli/src/tui/settings/contentful-configuration/ContentfulConfigScreen.tsx
|
|
680
|
-
import { useEffect as
|
|
487
|
+
import { useEffect as useEffect3, useState as useState4 } from "react";
|
|
681
488
|
import { Box as Box5, Text as Text5, useInput as useInput5 } from "ink";
|
|
682
489
|
import { Fragment, jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
683
|
-
function debugFields(config) {
|
|
684
|
-
return {
|
|
685
|
-
space_id: config?.spaceId ?? "",
|
|
686
|
-
environment_id: config?.environmentId ?? "",
|
|
687
|
-
cma_token: config?.cmaToken ?? "",
|
|
688
|
-
host: config?.host ?? ""
|
|
689
|
-
};
|
|
690
|
-
}
|
|
691
490
|
function ConfigurationScreen({ onDone }) {
|
|
692
491
|
const [stage, setStage] = useState4("loading");
|
|
693
492
|
const [config, setConfig] = useState4(null);
|
|
694
493
|
const [activeField, setActiveField] = useState4("spaceId");
|
|
695
494
|
const [message, setMessage] = useState4(null);
|
|
696
|
-
|
|
495
|
+
useEffect3(() => {
|
|
697
496
|
readCredentials().then((cfg) => {
|
|
698
497
|
setConfig(cfg);
|
|
699
498
|
setStage("form");
|
|
700
|
-
startDebugRun({
|
|
701
|
-
flow: "settings/contentful-configuration",
|
|
702
|
-
step: "01-configuration",
|
|
703
|
-
menuOption: "Configuration",
|
|
704
|
-
inputs: debugFields(cfg)
|
|
705
|
-
});
|
|
706
499
|
});
|
|
707
500
|
}, []);
|
|
708
501
|
function fieldValue(field) {
|
|
@@ -729,13 +522,11 @@ function ConfigurationScreen({ onDone }) {
|
|
|
729
522
|
if (stage === "loading" || stage === "saving") return;
|
|
730
523
|
if (stage === "saved") {
|
|
731
524
|
if (key.return || key.escape || input === "q") {
|
|
732
|
-
void finishDebugRun({ outputs: debugFields(config), status: "success", exitMethod: "saved" });
|
|
733
525
|
onDone();
|
|
734
526
|
}
|
|
735
527
|
return;
|
|
736
528
|
}
|
|
737
529
|
if (key.escape || input === "q") {
|
|
738
|
-
void finishDebugRun({ outputs: {}, status: "success", exitMethod: "discarded" });
|
|
739
530
|
onDone();
|
|
740
531
|
return;
|
|
741
532
|
}
|
|
@@ -821,7 +612,6 @@ var init_ContentfulConfigScreen = __esm({
|
|
|
821
612
|
"use strict";
|
|
822
613
|
init_home_theme();
|
|
823
614
|
init_config_store();
|
|
824
|
-
init_debug_store();
|
|
825
615
|
FIELD_ORDER = ["spaceId", "environmentId", "cmaToken", "host"];
|
|
826
616
|
FIELD_LABELS = {
|
|
827
617
|
spaceId: "Space ID",
|
|
@@ -854,22 +644,16 @@ var init_analytics_store = __esm({
|
|
|
854
644
|
});
|
|
855
645
|
|
|
856
646
|
// packages/experience-design-system-cli/src/tui/settings/opt-in-analytics/screen.tsx
|
|
857
|
-
import { useEffect as
|
|
647
|
+
import { useEffect as useEffect4, useState as useState5 } from "react";
|
|
858
648
|
import { Box as Box6, Text as Text6, useInput as useInput6 } from "ink";
|
|
859
649
|
import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
860
650
|
function OptInAnalyticsScreen({ onDone }) {
|
|
861
651
|
const [loading, setLoading] = useState5(true);
|
|
862
652
|
const [enabled, setEnabled] = useState5(true);
|
|
863
|
-
|
|
653
|
+
useEffect4(() => {
|
|
864
654
|
readAnalyticsSetting().then((setting) => {
|
|
865
655
|
setEnabled(setting.enabled);
|
|
866
656
|
setLoading(false);
|
|
867
|
-
startDebugRun({
|
|
868
|
-
flow: "settings/opt-in-analytics",
|
|
869
|
-
step: "01-opt-in-analytics",
|
|
870
|
-
menuOption: "Opt-in Analytics",
|
|
871
|
-
inputs: { enabled: setting.enabled }
|
|
872
|
-
});
|
|
873
657
|
});
|
|
874
658
|
}, []);
|
|
875
659
|
useInput6((input, key) => {
|
|
@@ -883,7 +667,6 @@ function OptInAnalyticsScreen({ onDone }) {
|
|
|
883
667
|
return;
|
|
884
668
|
}
|
|
885
669
|
if (key.escape || input === "q") {
|
|
886
|
-
void finishDebugRun({ outputs: { enabled }, status: "success", exitMethod: "saved" });
|
|
887
670
|
onDone();
|
|
888
671
|
}
|
|
889
672
|
});
|
|
@@ -909,17 +692,200 @@ var init_screen = __esm({
|
|
|
909
692
|
"use strict";
|
|
910
693
|
init_home_theme();
|
|
911
694
|
init_analytics_store();
|
|
912
|
-
|
|
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
|
+
});
|
|
913
879
|
}
|
|
914
880
|
});
|
|
915
881
|
|
|
916
882
|
// packages/experience-design-system-cli/src/tui/upgrade/PageContainer.tsx
|
|
917
|
-
import { useEffect as
|
|
883
|
+
import { useEffect as useEffect5, useState as useState6 } from "react";
|
|
918
884
|
import { Box as Box7, Text as Text7, useInput as useInput7 } from "ink";
|
|
919
885
|
import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
920
886
|
function UpgradeScreen({ onDone }) {
|
|
921
887
|
const [upgradeCheck, setUpgradeCheck] = useState6();
|
|
922
|
-
|
|
888
|
+
useEffect5(() => {
|
|
923
889
|
startDebugRun({
|
|
924
890
|
flow: "upgrade",
|
|
925
891
|
step: "01-upgrade",
|
|
@@ -994,22 +960,16 @@ var init_PageContainer4 = __esm({
|
|
|
994
960
|
});
|
|
995
961
|
|
|
996
962
|
// packages/experience-design-system-cli/src/tui/settings/debug-mode/screen.tsx
|
|
997
|
-
import { useEffect as
|
|
963
|
+
import { useEffect as useEffect6, useState as useState7 } from "react";
|
|
998
964
|
import { Box as Box8, Text as Text8, useInput as useInput8 } from "ink";
|
|
999
965
|
import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1000
966
|
function DebugModeScreen({ onDone }) {
|
|
1001
967
|
const [loading, setLoading] = useState7(true);
|
|
1002
968
|
const [enabled, setEnabled] = useState7(true);
|
|
1003
|
-
|
|
969
|
+
useEffect6(() => {
|
|
1004
970
|
readDebugModeSetting().then((setting) => {
|
|
1005
971
|
setEnabled(setting.enabled);
|
|
1006
972
|
setLoading(false);
|
|
1007
|
-
startDebugRun({
|
|
1008
|
-
flow: "settings/debug-mode",
|
|
1009
|
-
step: "01-debug-mode",
|
|
1010
|
-
menuOption: "Debug Mode",
|
|
1011
|
-
inputs: { enabled: setting.enabled }
|
|
1012
|
-
});
|
|
1013
973
|
});
|
|
1014
974
|
}, []);
|
|
1015
975
|
useInput8((input, key) => {
|
|
@@ -1023,7 +983,6 @@ function DebugModeScreen({ onDone }) {
|
|
|
1023
983
|
return;
|
|
1024
984
|
}
|
|
1025
985
|
if (key.escape || input === "q") {
|
|
1026
|
-
void finishDebugRun({ outputs: { enabled }, status: "success", exitMethod: "saved" });
|
|
1027
986
|
onDone();
|
|
1028
987
|
}
|
|
1029
988
|
});
|
|
@@ -1044,7 +1003,6 @@ var init_screen2 = __esm({
|
|
|
1044
1003
|
"use strict";
|
|
1045
1004
|
init_home_theme();
|
|
1046
1005
|
init_debug_mode_store();
|
|
1047
|
-
init_debug_store();
|
|
1048
1006
|
}
|
|
1049
1007
|
});
|
|
1050
1008
|
|