@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/app.js
CHANGED
|
@@ -294,197 +294,16 @@ function startReadingTerminal() {
|
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
// packages/experience-design-system-cli/src/tui/help/PageContainer.tsx
|
|
297
|
-
import { useEffect as useEffect3 } from "react";
|
|
298
297
|
import { Box as Box3, Text as Text3, useInput as useInput3 } from "ink";
|
|
299
|
-
|
|
300
|
-
// packages/experience-design-system-cli/src/tui/debug-store.ts
|
|
301
|
-
import { mkdir as mkdir2, writeFile as writeFile2 } from "node:fs/promises";
|
|
302
|
-
import { existsSync as existsSync3, readdirSync } from "node:fs";
|
|
303
|
-
import { join as join5 } from "node:path";
|
|
304
|
-
|
|
305
|
-
// packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts
|
|
306
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
307
|
-
import { dirname as dirname2, join as join4 } from "node:path";
|
|
308
|
-
var PACKAGE_NAME3 = "@contentful/experience-design-system-cli";
|
|
309
|
-
var DEFAULT_DEBUG_MODE_SETTING = {
|
|
310
|
-
enabled: true
|
|
311
|
-
};
|
|
312
|
-
function debugModeSettingPath() {
|
|
313
|
-
return join4(findPackageRoot(import.meta.url, PACKAGE_NAME3), ".contentful", "config", "debug_mode.json");
|
|
314
|
-
}
|
|
315
|
-
async function readDebugModeSetting() {
|
|
316
|
-
try {
|
|
317
|
-
const raw = await readFile(debugModeSettingPath(), "utf8");
|
|
318
|
-
const parsed = JSON.parse(raw);
|
|
319
|
-
return { ...DEFAULT_DEBUG_MODE_SETTING, ...parsed };
|
|
320
|
-
} catch {
|
|
321
|
-
return { ...DEFAULT_DEBUG_MODE_SETTING };
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
async function writeDebugModeSetting(setting) {
|
|
325
|
-
const path = debugModeSettingPath();
|
|
326
|
-
await mkdir(dirname2(path), { recursive: true });
|
|
327
|
-
await writeFile(path, `${JSON.stringify(setting, null, 2)}
|
|
328
|
-
`, { mode: 384 });
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// packages/experience-design-system-cli/src/tui/debug-store.ts
|
|
332
|
-
var PACKAGE_NAME4 = "@contentful/experience-design-system-cli";
|
|
333
|
-
var pendingRun;
|
|
334
|
-
function generateRunId() {
|
|
335
|
-
const now = /* @__PURE__ */ new Date();
|
|
336
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
337
|
-
return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
|
|
338
|
-
}
|
|
339
|
-
function sessionsRootDir() {
|
|
340
|
-
return join5(findPackageRoot(import.meta.url, PACKAGE_NAME4), ".contentful", "debug", "sessions");
|
|
341
|
-
}
|
|
342
|
-
function datePrefix(now = /* @__PURE__ */ new Date()) {
|
|
343
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
344
|
-
return `${pad(now.getMonth() + 1)}-${pad(now.getDate())}-${now.getFullYear()}`;
|
|
345
|
-
}
|
|
346
|
-
function slugify(value) {
|
|
347
|
-
return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
348
|
-
}
|
|
349
|
-
function generateSessionId() {
|
|
350
|
-
const today = datePrefix();
|
|
351
|
-
const root = sessionsRootDir();
|
|
352
|
-
const existing = existsSync3(root) ? readdirSync(root) : [];
|
|
353
|
-
const seqPattern = new RegExp(`^${today}-session-(\\d+)$`);
|
|
354
|
-
const maxSeq = existing.reduce((max, entry) => {
|
|
355
|
-
const match = seqPattern.exec(entry);
|
|
356
|
-
return match ? Math.max(max, Number(match[1])) : max;
|
|
357
|
-
}, 0);
|
|
358
|
-
return `${today}-session-${maxSeq + 1}`;
|
|
359
|
-
}
|
|
360
|
-
var SESSION_ID = generateSessionId();
|
|
361
|
-
function sessionDebugDir() {
|
|
362
|
-
return join5(sessionsRootDir(), SESSION_ID);
|
|
363
|
-
}
|
|
364
|
-
void isDebugModeEnabled().then((enabled) => {
|
|
365
|
-
if (!enabled) return void 0;
|
|
366
|
-
return mkdir2(sessionDebugDir(), { recursive: true });
|
|
367
|
-
});
|
|
368
|
-
async function isDebugModeEnabled() {
|
|
369
|
-
try {
|
|
370
|
-
return (await readDebugModeSetting()).enabled;
|
|
371
|
-
} catch {
|
|
372
|
-
return true;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
function redact(value) {
|
|
376
|
-
const clone = { ...value };
|
|
377
|
-
if ("cma_token" in clone) {
|
|
378
|
-
const raw = clone.cma_token;
|
|
379
|
-
clone.cma_token = typeof raw === "string" && raw.length > 0 ? `[present, ${raw.length} chars]` : "[not set]";
|
|
380
|
-
}
|
|
381
|
-
return clone;
|
|
382
|
-
}
|
|
383
|
-
function startDebugRun({
|
|
384
|
-
flow,
|
|
385
|
-
step,
|
|
386
|
-
menuOption,
|
|
387
|
-
inputs
|
|
388
|
-
}) {
|
|
389
|
-
const runId = generateRunId();
|
|
390
|
-
const startedAt = Date.now();
|
|
391
|
-
const redactedInputs = redact(inputs);
|
|
392
|
-
isDebugModeEnabled().then((enabled) => {
|
|
393
|
-
if (!enabled) return;
|
|
394
|
-
pendingRun = { flow, step, runId, menuOption, inputs: redactedInputs, startedAt };
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
async function finishDebugRun({
|
|
398
|
-
outputs,
|
|
399
|
-
status,
|
|
400
|
-
exitMethod
|
|
401
|
-
}) {
|
|
402
|
-
const run = pendingRun;
|
|
403
|
-
if (!run) return;
|
|
404
|
-
pendingRun = void 0;
|
|
405
|
-
const durationMs = Date.now() - run.startedAt;
|
|
406
|
-
const content = renderMarkdown(run, { outputs: redact(outputs), status, exitMethod, durationMs });
|
|
407
|
-
const flowSegments = run.flow.split("/");
|
|
408
|
-
const dir = join5(sessionDebugDir(), ...flowSegments);
|
|
409
|
-
await mkdir2(dir, { recursive: true });
|
|
410
|
-
const filename = nextAttemptFilename(dir, run.menuOption);
|
|
411
|
-
await writeFile2(join5(dir, filename), content, { mode: 384 });
|
|
412
|
-
}
|
|
413
|
-
function nextAttemptFilename(dir, menuOption) {
|
|
414
|
-
const today = datePrefix();
|
|
415
|
-
const optionSlug = slugify(menuOption);
|
|
416
|
-
const existing = existsSync3(dir) ? readdirSync(dir) : [];
|
|
417
|
-
const attemptPattern = new RegExp(`^${today}-${optionSlug}-attempt-(\\d+)\\.md$`);
|
|
418
|
-
const maxAttempt = existing.reduce((max, entry) => {
|
|
419
|
-
const match = attemptPattern.exec(entry);
|
|
420
|
-
return match ? Math.max(max, Number(match[1])) : max;
|
|
421
|
-
}, 0);
|
|
422
|
-
return `${today}-${optionSlug}-attempt-${maxAttempt + 1}.md`;
|
|
423
|
-
}
|
|
424
|
-
function renderMarkdown(run, finish) {
|
|
425
|
-
const stepMatch = /^(\d+)-(.+)$/.exec(run.step);
|
|
426
|
-
const stepLabel = stepMatch ? `${stepMatch[1]} - ${stepMatch[2]}` : run.step;
|
|
427
|
-
const flowSlug = run.flow.split("/").join("-");
|
|
428
|
-
return `# Debug Log
|
|
429
|
-
|
|
430
|
-
- Run ID: ${run.runId}
|
|
431
|
-
- Flow: ${flowSlug}
|
|
432
|
-
- Step: ${stepLabel}
|
|
433
|
-
- Menu option: ${run.menuOption}
|
|
434
|
-
- Date: ${(/* @__PURE__ */ new Date()).toISOString()}
|
|
435
|
-
- CLI version: ${readPackageVersion()}
|
|
436
|
-
- Platform: ${process.platform} / Node ${process.version}
|
|
437
|
-
- Duration on screen: ${finish.durationMs}ms
|
|
438
|
-
- Status: ${finish.status}
|
|
439
|
-
- Exit method: ${finish.exitMethod}
|
|
440
|
-
|
|
441
|
-
## Inputs
|
|
442
|
-
\`\`\`json
|
|
443
|
-
${JSON.stringify(run.inputs, null, 2)}
|
|
444
|
-
\`\`\`
|
|
445
|
-
|
|
446
|
-
## Outputs
|
|
447
|
-
\`\`\`json
|
|
448
|
-
${JSON.stringify(finish.outputs, null, 2)}
|
|
449
|
-
\`\`\`
|
|
450
|
-
`;
|
|
451
|
-
}
|
|
452
|
-
function handleCrash() {
|
|
453
|
-
return finishDebugRun({ outputs: {}, status: "error", exitMethod: "crashed" });
|
|
454
|
-
}
|
|
455
|
-
process.once("uncaughtException", (err) => {
|
|
456
|
-
void handleCrash().finally(() => {
|
|
457
|
-
throw err;
|
|
458
|
-
});
|
|
459
|
-
});
|
|
460
|
-
process.once("unhandledRejection", (reason) => {
|
|
461
|
-
void handleCrash().finally(() => {
|
|
462
|
-
throw reason;
|
|
463
|
-
});
|
|
464
|
-
});
|
|
465
|
-
process.once("SIGINT", () => {
|
|
466
|
-
void handleCrash().finally(() => {
|
|
467
|
-
process.exit(130);
|
|
468
|
-
});
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
// packages/experience-design-system-cli/src/tui/help/PageContainer.tsx
|
|
472
298
|
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
473
299
|
function HelpScreen({ onDone }) {
|
|
474
|
-
useEffect3(() => {
|
|
475
|
-
startDebugRun({ flow: "help", step: "01-help", menuOption: "Help", inputs: {} });
|
|
476
|
-
}, []);
|
|
477
|
-
const leave = (exitMethod) => {
|
|
478
|
-
void finishDebugRun({ outputs: {}, status: "success", exitMethod });
|
|
479
|
-
onDone();
|
|
480
|
-
};
|
|
481
300
|
useInput3((input, key) => {
|
|
482
301
|
if (key.return) {
|
|
483
|
-
|
|
302
|
+
onDone();
|
|
484
303
|
return;
|
|
485
304
|
}
|
|
486
305
|
if (key.escape || input === "q") {
|
|
487
|
-
|
|
306
|
+
onDone();
|
|
488
307
|
return;
|
|
489
308
|
}
|
|
490
309
|
});
|
|
@@ -544,25 +363,25 @@ function SettingsScreen({
|
|
|
544
363
|
}
|
|
545
364
|
|
|
546
365
|
// packages/experience-design-system-cli/src/tui/settings/contentful-configuration/ContentfulConfigScreen.tsx
|
|
547
|
-
import { useEffect as
|
|
366
|
+
import { useEffect as useEffect3, useState as useState4 } from "react";
|
|
548
367
|
import { Box as Box5, Text as Text5, useInput as useInput5 } from "ink";
|
|
549
368
|
|
|
550
369
|
// packages/experience-design-system-cli/src/tui/settings/utils/v1-store.ts
|
|
551
|
-
import { readFile
|
|
552
|
-
import { join as
|
|
370
|
+
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
371
|
+
import { join as join4 } from "node:path";
|
|
553
372
|
import { homedir } from "node:os";
|
|
554
|
-
var V1_STORE_PATH =
|
|
373
|
+
var V1_STORE_PATH = join4(homedir(), ".config", "experiences", "credentials.json");
|
|
555
374
|
async function readV1Store() {
|
|
556
375
|
try {
|
|
557
|
-
const raw = await
|
|
376
|
+
const raw = await readFile(V1_STORE_PATH, "utf8");
|
|
558
377
|
return JSON.parse(raw);
|
|
559
378
|
} catch {
|
|
560
379
|
return {};
|
|
561
380
|
}
|
|
562
381
|
}
|
|
563
382
|
async function writeV1Store(data) {
|
|
564
|
-
await
|
|
565
|
-
await
|
|
383
|
+
await mkdir(join4(homedir(), ".config", "experiences"), { recursive: true });
|
|
384
|
+
await writeFile(V1_STORE_PATH, `${JSON.stringify(data, null, 2)}
|
|
566
385
|
`, { mode: 384 });
|
|
567
386
|
}
|
|
568
387
|
|
|
@@ -591,14 +410,6 @@ async function writeCredentials(config) {
|
|
|
591
410
|
// packages/experience-design-system-cli/src/tui/settings/contentful-configuration/ContentfulConfigScreen.tsx
|
|
592
411
|
import { Fragment, jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
593
412
|
var FIELD_ORDER = ["spaceId", "environmentId", "cmaToken", "host"];
|
|
594
|
-
function debugFields(config) {
|
|
595
|
-
return {
|
|
596
|
-
space_id: config?.spaceId ?? "",
|
|
597
|
-
environment_id: config?.environmentId ?? "",
|
|
598
|
-
cma_token: config?.cmaToken ?? "",
|
|
599
|
-
host: config?.host ?? ""
|
|
600
|
-
};
|
|
601
|
-
}
|
|
602
413
|
var FIELD_LABELS = {
|
|
603
414
|
spaceId: "Space ID",
|
|
604
415
|
environmentId: "Environment ID",
|
|
@@ -610,16 +421,10 @@ function ConfigurationScreen({ onDone }) {
|
|
|
610
421
|
const [config, setConfig] = useState4(null);
|
|
611
422
|
const [activeField, setActiveField] = useState4("spaceId");
|
|
612
423
|
const [message, setMessage] = useState4(null);
|
|
613
|
-
|
|
424
|
+
useEffect3(() => {
|
|
614
425
|
readCredentials().then((cfg) => {
|
|
615
426
|
setConfig(cfg);
|
|
616
427
|
setStage("form");
|
|
617
|
-
startDebugRun({
|
|
618
|
-
flow: "settings/contentful-configuration",
|
|
619
|
-
step: "01-configuration",
|
|
620
|
-
menuOption: "Configuration",
|
|
621
|
-
inputs: debugFields(cfg)
|
|
622
|
-
});
|
|
623
428
|
});
|
|
624
429
|
}, []);
|
|
625
430
|
function fieldValue(field) {
|
|
@@ -646,13 +451,11 @@ function ConfigurationScreen({ onDone }) {
|
|
|
646
451
|
if (stage === "loading" || stage === "saving") return;
|
|
647
452
|
if (stage === "saved") {
|
|
648
453
|
if (key.return || key.escape || input === "q") {
|
|
649
|
-
void finishDebugRun({ outputs: debugFields(config), status: "success", exitMethod: "saved" });
|
|
650
454
|
onDone();
|
|
651
455
|
}
|
|
652
456
|
return;
|
|
653
457
|
}
|
|
654
458
|
if (key.escape || input === "q") {
|
|
655
|
-
void finishDebugRun({ outputs: {}, status: "success", exitMethod: "discarded" });
|
|
656
459
|
onDone();
|
|
657
460
|
return;
|
|
658
461
|
}
|
|
@@ -734,7 +537,7 @@ function ConfigurationScreen({ onDone }) {
|
|
|
734
537
|
}
|
|
735
538
|
|
|
736
539
|
// packages/experience-design-system-cli/src/tui/settings/opt-in-analytics/screen.tsx
|
|
737
|
-
import { useEffect as
|
|
540
|
+
import { useEffect as useEffect4, useState as useState5 } from "react";
|
|
738
541
|
import { Box as Box6, Text as Text6, useInput as useInput6 } from "ink";
|
|
739
542
|
|
|
740
543
|
// packages/experience-design-system-cli/src/tui/settings/opt-in-analytics/analytics-store.ts
|
|
@@ -757,16 +560,10 @@ import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs6 } from "react/jsx-run
|
|
|
757
560
|
function OptInAnalyticsScreen({ onDone }) {
|
|
758
561
|
const [loading, setLoading] = useState5(true);
|
|
759
562
|
const [enabled, setEnabled] = useState5(true);
|
|
760
|
-
|
|
563
|
+
useEffect4(() => {
|
|
761
564
|
readAnalyticsSetting().then((setting) => {
|
|
762
565
|
setEnabled(setting.enabled);
|
|
763
566
|
setLoading(false);
|
|
764
|
-
startDebugRun({
|
|
765
|
-
flow: "settings/opt-in-analytics",
|
|
766
|
-
step: "01-opt-in-analytics",
|
|
767
|
-
menuOption: "Opt-in Analytics",
|
|
768
|
-
inputs: { enabled: setting.enabled }
|
|
769
|
-
});
|
|
770
567
|
});
|
|
771
568
|
}, []);
|
|
772
569
|
useInput6((input, key) => {
|
|
@@ -780,7 +577,6 @@ function OptInAnalyticsScreen({ onDone }) {
|
|
|
780
577
|
return;
|
|
781
578
|
}
|
|
782
579
|
if (key.escape || input === "q") {
|
|
783
|
-
void finishDebugRun({ outputs: { enabled }, status: "success", exitMethod: "saved" });
|
|
784
580
|
onDone();
|
|
785
581
|
}
|
|
786
582
|
});
|
|
@@ -803,13 +599,186 @@ function OptInAnalyticsScreen({ onDone }) {
|
|
|
803
599
|
}
|
|
804
600
|
|
|
805
601
|
// packages/experience-design-system-cli/src/tui/upgrade/PageContainer.tsx
|
|
806
|
-
import { useEffect as
|
|
602
|
+
import { useEffect as useEffect5, useState as useState6 } from "react";
|
|
807
603
|
import { Box as Box7, Text as Text7, useInput as useInput7 } from "ink";
|
|
604
|
+
|
|
605
|
+
// packages/experience-design-system-cli/src/tui/debug-store.ts
|
|
606
|
+
import { mkdir as mkdir3, writeFile as writeFile3 } from "node:fs/promises";
|
|
607
|
+
import { existsSync as existsSync3, readdirSync } from "node:fs";
|
|
608
|
+
import { join as join6 } from "node:path";
|
|
609
|
+
|
|
610
|
+
// packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts
|
|
611
|
+
import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
|
|
612
|
+
import { dirname as dirname2, join as join5 } from "node:path";
|
|
613
|
+
var PACKAGE_NAME3 = "@contentful/experience-design-system-cli";
|
|
614
|
+
var DEFAULT_DEBUG_MODE_SETTING = {
|
|
615
|
+
enabled: true
|
|
616
|
+
};
|
|
617
|
+
function debugModeSettingPath() {
|
|
618
|
+
return join5(findPackageRoot(import.meta.url, PACKAGE_NAME3), ".contentful", "config", "debug_mode.json");
|
|
619
|
+
}
|
|
620
|
+
async function readDebugModeSetting() {
|
|
621
|
+
try {
|
|
622
|
+
const raw = await readFile2(debugModeSettingPath(), "utf8");
|
|
623
|
+
const parsed = JSON.parse(raw);
|
|
624
|
+
return { ...DEFAULT_DEBUG_MODE_SETTING, ...parsed };
|
|
625
|
+
} catch {
|
|
626
|
+
return { ...DEFAULT_DEBUG_MODE_SETTING };
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
async function writeDebugModeSetting(setting) {
|
|
630
|
+
const path = debugModeSettingPath();
|
|
631
|
+
await mkdir2(dirname2(path), { recursive: true });
|
|
632
|
+
await writeFile2(path, `${JSON.stringify(setting, null, 2)}
|
|
633
|
+
`, { mode: 384 });
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// packages/experience-design-system-cli/src/tui/debug-store.ts
|
|
637
|
+
var PACKAGE_NAME4 = "@contentful/experience-design-system-cli";
|
|
638
|
+
var pendingRun;
|
|
639
|
+
function generateRunId() {
|
|
640
|
+
const now = /* @__PURE__ */ new Date();
|
|
641
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
642
|
+
return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
|
|
643
|
+
}
|
|
644
|
+
function sessionsRootDir() {
|
|
645
|
+
return join6(findPackageRoot(import.meta.url, PACKAGE_NAME4), ".contentful", "debug", "sessions");
|
|
646
|
+
}
|
|
647
|
+
function datePrefix(now = /* @__PURE__ */ new Date()) {
|
|
648
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
649
|
+
return `${pad(now.getMonth() + 1)}-${pad(now.getDate())}-${now.getFullYear()}`;
|
|
650
|
+
}
|
|
651
|
+
function slugify(value) {
|
|
652
|
+
return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
653
|
+
}
|
|
654
|
+
function generateSessionId() {
|
|
655
|
+
const today = datePrefix();
|
|
656
|
+
const root = sessionsRootDir();
|
|
657
|
+
const existing = existsSync3(root) ? readdirSync(root) : [];
|
|
658
|
+
const seqPattern = new RegExp(`^${today}-session-(\\d+)$`);
|
|
659
|
+
const maxSeq = existing.reduce((max, entry) => {
|
|
660
|
+
const match = seqPattern.exec(entry);
|
|
661
|
+
return match ? Math.max(max, Number(match[1])) : max;
|
|
662
|
+
}, 0);
|
|
663
|
+
return `${today}-session-${maxSeq + 1}`;
|
|
664
|
+
}
|
|
665
|
+
var SESSION_ID = generateSessionId();
|
|
666
|
+
function sessionDebugDir() {
|
|
667
|
+
return join6(sessionsRootDir(), SESSION_ID);
|
|
668
|
+
}
|
|
669
|
+
void isDebugModeEnabled().then((enabled) => {
|
|
670
|
+
if (!enabled) return void 0;
|
|
671
|
+
return mkdir3(sessionDebugDir(), { recursive: true });
|
|
672
|
+
});
|
|
673
|
+
async function isDebugModeEnabled() {
|
|
674
|
+
try {
|
|
675
|
+
return (await readDebugModeSetting()).enabled;
|
|
676
|
+
} catch {
|
|
677
|
+
return true;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
function redact(value) {
|
|
681
|
+
const clone = { ...value };
|
|
682
|
+
if ("cma_token" in clone) {
|
|
683
|
+
const raw = clone.cma_token;
|
|
684
|
+
clone.cma_token = typeof raw === "string" && raw.length > 0 ? `[present, ${raw.length} chars]` : "[not set]";
|
|
685
|
+
}
|
|
686
|
+
return clone;
|
|
687
|
+
}
|
|
688
|
+
function startDebugRun({
|
|
689
|
+
flow,
|
|
690
|
+
step,
|
|
691
|
+
menuOption,
|
|
692
|
+
inputs
|
|
693
|
+
}) {
|
|
694
|
+
const runId = generateRunId();
|
|
695
|
+
const startedAt = Date.now();
|
|
696
|
+
const redactedInputs = redact(inputs);
|
|
697
|
+
isDebugModeEnabled().then((enabled) => {
|
|
698
|
+
if (!enabled) return;
|
|
699
|
+
pendingRun = { flow, step, runId, menuOption, inputs: redactedInputs, startedAt };
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
async function finishDebugRun({
|
|
703
|
+
outputs,
|
|
704
|
+
status,
|
|
705
|
+
exitMethod
|
|
706
|
+
}) {
|
|
707
|
+
const run = pendingRun;
|
|
708
|
+
if (!run) return;
|
|
709
|
+
pendingRun = void 0;
|
|
710
|
+
const durationMs = Date.now() - run.startedAt;
|
|
711
|
+
const content = renderMarkdown(run, { outputs: redact(outputs), status, exitMethod, durationMs });
|
|
712
|
+
const flowSegments = run.flow.split("/");
|
|
713
|
+
const dir = join6(sessionDebugDir(), ...flowSegments);
|
|
714
|
+
await mkdir3(dir, { recursive: true });
|
|
715
|
+
const filename = nextAttemptFilename(dir, run.menuOption);
|
|
716
|
+
await writeFile3(join6(dir, filename), content, { mode: 384 });
|
|
717
|
+
}
|
|
718
|
+
function nextAttemptFilename(dir, menuOption) {
|
|
719
|
+
const today = datePrefix();
|
|
720
|
+
const optionSlug = slugify(menuOption);
|
|
721
|
+
const existing = existsSync3(dir) ? readdirSync(dir) : [];
|
|
722
|
+
const attemptPattern = new RegExp(`^${today}-${optionSlug}-attempt-(\\d+)\\.md$`);
|
|
723
|
+
const maxAttempt = existing.reduce((max, entry) => {
|
|
724
|
+
const match = attemptPattern.exec(entry);
|
|
725
|
+
return match ? Math.max(max, Number(match[1])) : max;
|
|
726
|
+
}, 0);
|
|
727
|
+
return `${today}-${optionSlug}-attempt-${maxAttempt + 1}.md`;
|
|
728
|
+
}
|
|
729
|
+
function renderMarkdown(run, finish) {
|
|
730
|
+
const stepMatch = /^(\d+)-(.+)$/.exec(run.step);
|
|
731
|
+
const stepLabel = stepMatch ? `${stepMatch[1]} - ${stepMatch[2]}` : run.step;
|
|
732
|
+
const flowSlug = run.flow.split("/").join("-");
|
|
733
|
+
return `# Debug Log
|
|
734
|
+
|
|
735
|
+
- Run ID: ${run.runId}
|
|
736
|
+
- Flow: ${flowSlug}
|
|
737
|
+
- Step: ${stepLabel}
|
|
738
|
+
- Menu option: ${run.menuOption}
|
|
739
|
+
- Date: ${(/* @__PURE__ */ new Date()).toISOString()}
|
|
740
|
+
- CLI version: ${readPackageVersion()}
|
|
741
|
+
- Platform: ${process.platform} / Node ${process.version}
|
|
742
|
+
- Duration on screen: ${finish.durationMs}ms
|
|
743
|
+
- Status: ${finish.status}
|
|
744
|
+
- Exit method: ${finish.exitMethod}
|
|
745
|
+
|
|
746
|
+
## Inputs
|
|
747
|
+
\`\`\`json
|
|
748
|
+
${JSON.stringify(run.inputs, null, 2)}
|
|
749
|
+
\`\`\`
|
|
750
|
+
|
|
751
|
+
## Outputs
|
|
752
|
+
\`\`\`json
|
|
753
|
+
${JSON.stringify(finish.outputs, null, 2)}
|
|
754
|
+
\`\`\`
|
|
755
|
+
`;
|
|
756
|
+
}
|
|
757
|
+
function handleCrash() {
|
|
758
|
+
return finishDebugRun({ outputs: {}, status: "error", exitMethod: "crashed" });
|
|
759
|
+
}
|
|
760
|
+
process.once("uncaughtException", (err) => {
|
|
761
|
+
void handleCrash().finally(() => {
|
|
762
|
+
throw err;
|
|
763
|
+
});
|
|
764
|
+
});
|
|
765
|
+
process.once("unhandledRejection", (reason) => {
|
|
766
|
+
void handleCrash().finally(() => {
|
|
767
|
+
throw reason;
|
|
768
|
+
});
|
|
769
|
+
});
|
|
770
|
+
process.once("SIGINT", () => {
|
|
771
|
+
void handleCrash().finally(() => {
|
|
772
|
+
process.exit(130);
|
|
773
|
+
});
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
// packages/experience-design-system-cli/src/tui/upgrade/PageContainer.tsx
|
|
808
777
|
import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
809
778
|
var UPGRADE_COMMANDS = ["git pull", "pnpm install", "pnpm build"];
|
|
810
779
|
function UpgradeScreen({ onDone }) {
|
|
811
780
|
const [upgradeCheck, setUpgradeCheck] = useState6();
|
|
812
|
-
|
|
781
|
+
useEffect5(() => {
|
|
813
782
|
startDebugRun({
|
|
814
783
|
flow: "upgrade",
|
|
815
784
|
step: "01-upgrade",
|
|
@@ -874,22 +843,16 @@ function renderBody(upgradeCheck) {
|
|
|
874
843
|
}
|
|
875
844
|
|
|
876
845
|
// packages/experience-design-system-cli/src/tui/settings/debug-mode/screen.tsx
|
|
877
|
-
import { useEffect as
|
|
846
|
+
import { useEffect as useEffect6, useState as useState7 } from "react";
|
|
878
847
|
import { Box as Box8, Text as Text8, useInput as useInput8 } from "ink";
|
|
879
848
|
import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
880
849
|
function DebugModeScreen({ onDone }) {
|
|
881
850
|
const [loading, setLoading] = useState7(true);
|
|
882
851
|
const [enabled, setEnabled] = useState7(true);
|
|
883
|
-
|
|
852
|
+
useEffect6(() => {
|
|
884
853
|
readDebugModeSetting().then((setting) => {
|
|
885
854
|
setEnabled(setting.enabled);
|
|
886
855
|
setLoading(false);
|
|
887
|
-
startDebugRun({
|
|
888
|
-
flow: "settings/debug-mode",
|
|
889
|
-
step: "01-debug-mode",
|
|
890
|
-
menuOption: "Debug Mode",
|
|
891
|
-
inputs: { enabled: setting.enabled }
|
|
892
|
-
});
|
|
893
856
|
});
|
|
894
857
|
}, []);
|
|
895
858
|
useInput8((input, key) => {
|
|
@@ -903,7 +866,6 @@ function DebugModeScreen({ onDone }) {
|
|
|
903
866
|
return;
|
|
904
867
|
}
|
|
905
868
|
if (key.escape || input === "q") {
|
|
906
|
-
void finishDebugRun({ outputs: { enabled }, status: "success", exitMethod: "saved" });
|
|
907
869
|
onDone();
|
|
908
870
|
}
|
|
909
871
|
});
|