@contentful/experience-design-system-cli 2.35.1-dev-build-3ab9e99e.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 +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/app.js
CHANGED
|
@@ -251,180 +251,6 @@ ${candidates.join("\n")}`);
|
|
|
251
251
|
return found;
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
-
// packages/experience-design-system-cli/src/tui/debug-store.ts
|
|
255
|
-
import { mkdir as mkdir2, writeFile as writeFile2 } from "node:fs/promises";
|
|
256
|
-
import { existsSync as existsSync3, readdirSync } from "node:fs";
|
|
257
|
-
import { join as join5 } from "node:path";
|
|
258
|
-
|
|
259
|
-
// packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts
|
|
260
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
261
|
-
import { dirname as dirname2, join as join4 } from "node:path";
|
|
262
|
-
var PACKAGE_NAME3 = "@contentful/experience-design-system-cli";
|
|
263
|
-
var DEFAULT_DEBUG_MODE_SETTING = {
|
|
264
|
-
enabled: true
|
|
265
|
-
};
|
|
266
|
-
function debugModeSettingPath() {
|
|
267
|
-
return join4(findPackageRoot(import.meta.url, PACKAGE_NAME3), ".contentful", "config", "debug_mode.json");
|
|
268
|
-
}
|
|
269
|
-
async function readDebugModeSetting() {
|
|
270
|
-
try {
|
|
271
|
-
const raw = await readFile(debugModeSettingPath(), "utf8");
|
|
272
|
-
const parsed = JSON.parse(raw);
|
|
273
|
-
return { ...DEFAULT_DEBUG_MODE_SETTING, ...parsed };
|
|
274
|
-
} catch {
|
|
275
|
-
return { ...DEFAULT_DEBUG_MODE_SETTING };
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
async function writeDebugModeSetting(setting) {
|
|
279
|
-
const path = debugModeSettingPath();
|
|
280
|
-
await mkdir(dirname2(path), { recursive: true });
|
|
281
|
-
await writeFile(path, `${JSON.stringify(setting, null, 2)}
|
|
282
|
-
`, { mode: 384 });
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// packages/experience-design-system-cli/src/tui/debug-store.ts
|
|
286
|
-
var PACKAGE_NAME4 = "@contentful/experience-design-system-cli";
|
|
287
|
-
var pendingRun;
|
|
288
|
-
function generateRunId() {
|
|
289
|
-
const now = /* @__PURE__ */ new Date();
|
|
290
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
291
|
-
return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
|
|
292
|
-
}
|
|
293
|
-
function sessionsRootDir() {
|
|
294
|
-
return join5(findPackageRoot(import.meta.url, PACKAGE_NAME4), ".contentful", "debug", "sessions");
|
|
295
|
-
}
|
|
296
|
-
function datePrefix(now = /* @__PURE__ */ new Date()) {
|
|
297
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
298
|
-
return `${pad(now.getMonth() + 1)}-${pad(now.getDate())}-${now.getFullYear()}`;
|
|
299
|
-
}
|
|
300
|
-
function slugify(value) {
|
|
301
|
-
return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
302
|
-
}
|
|
303
|
-
function generateSessionId() {
|
|
304
|
-
const today = datePrefix();
|
|
305
|
-
const root = sessionsRootDir();
|
|
306
|
-
const existing = existsSync3(root) ? readdirSync(root) : [];
|
|
307
|
-
const seqPattern = new RegExp(`^${today}-session-(\\d+)$`);
|
|
308
|
-
const maxSeq = existing.reduce((max, entry) => {
|
|
309
|
-
const match = seqPattern.exec(entry);
|
|
310
|
-
return match ? Math.max(max, Number(match[1])) : max;
|
|
311
|
-
}, 0);
|
|
312
|
-
return `${today}-session-${maxSeq + 1}`;
|
|
313
|
-
}
|
|
314
|
-
var SESSION_ID = generateSessionId();
|
|
315
|
-
function sessionDebugDir() {
|
|
316
|
-
return join5(sessionsRootDir(), SESSION_ID);
|
|
317
|
-
}
|
|
318
|
-
async function debugSessionDirIfEnabled() {
|
|
319
|
-
return await isDebugModeEnabled() ? sessionDebugDir() : void 0;
|
|
320
|
-
}
|
|
321
|
-
void isDebugModeEnabled().then((enabled) => {
|
|
322
|
-
if (!enabled) return void 0;
|
|
323
|
-
return mkdir2(sessionDebugDir(), { recursive: true });
|
|
324
|
-
});
|
|
325
|
-
async function isDebugModeEnabled() {
|
|
326
|
-
try {
|
|
327
|
-
return (await readDebugModeSetting()).enabled;
|
|
328
|
-
} catch {
|
|
329
|
-
return true;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
function redact(value) {
|
|
333
|
-
const clone = { ...value };
|
|
334
|
-
if ("cma_token" in clone) {
|
|
335
|
-
const raw = clone.cma_token;
|
|
336
|
-
clone.cma_token = typeof raw === "string" && raw.length > 0 ? `[present, ${raw.length} chars]` : "[not set]";
|
|
337
|
-
}
|
|
338
|
-
return clone;
|
|
339
|
-
}
|
|
340
|
-
function startDebugRun({
|
|
341
|
-
flow,
|
|
342
|
-
step,
|
|
343
|
-
menuOption,
|
|
344
|
-
inputs
|
|
345
|
-
}) {
|
|
346
|
-
const runId = generateRunId();
|
|
347
|
-
const startedAt = Date.now();
|
|
348
|
-
const redactedInputs = redact(inputs);
|
|
349
|
-
isDebugModeEnabled().then((enabled) => {
|
|
350
|
-
if (!enabled) return;
|
|
351
|
-
pendingRun = { flow, step, runId, menuOption, inputs: redactedInputs, startedAt };
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
async function finishDebugRun({
|
|
355
|
-
outputs,
|
|
356
|
-
status,
|
|
357
|
-
exitMethod
|
|
358
|
-
}) {
|
|
359
|
-
const run = pendingRun;
|
|
360
|
-
if (!run) return;
|
|
361
|
-
pendingRun = void 0;
|
|
362
|
-
const durationMs = Date.now() - run.startedAt;
|
|
363
|
-
const content = renderMarkdown(run, { outputs: redact(outputs), status, exitMethod, durationMs });
|
|
364
|
-
const flowSegments = run.flow.split("/");
|
|
365
|
-
const dir = join5(sessionDebugDir(), ...flowSegments);
|
|
366
|
-
await mkdir2(dir, { recursive: true });
|
|
367
|
-
const filename = nextAttemptFilename(dir, run.menuOption);
|
|
368
|
-
await writeFile2(join5(dir, filename), content, { mode: 384 });
|
|
369
|
-
}
|
|
370
|
-
function nextAttemptFilename(dir, menuOption) {
|
|
371
|
-
const today = datePrefix();
|
|
372
|
-
const optionSlug = slugify(menuOption);
|
|
373
|
-
const existing = existsSync3(dir) ? readdirSync(dir) : [];
|
|
374
|
-
const attemptPattern = new RegExp(`^${today}-${optionSlug}-attempt-(\\d+)\\.md$`);
|
|
375
|
-
const maxAttempt = existing.reduce((max, entry) => {
|
|
376
|
-
const match = attemptPattern.exec(entry);
|
|
377
|
-
return match ? Math.max(max, Number(match[1])) : max;
|
|
378
|
-
}, 0);
|
|
379
|
-
return `${today}-${optionSlug}-attempt-${maxAttempt + 1}.md`;
|
|
380
|
-
}
|
|
381
|
-
function renderMarkdown(run, finish) {
|
|
382
|
-
const stepMatch = /^(\d+)-(.+)$/.exec(run.step);
|
|
383
|
-
const stepLabel = stepMatch ? `${stepMatch[1]} - ${stepMatch[2]}` : run.step;
|
|
384
|
-
const flowSlug = run.flow.split("/").join("-");
|
|
385
|
-
return `# Debug Log
|
|
386
|
-
|
|
387
|
-
- Run ID: ${run.runId}
|
|
388
|
-
- Flow: ${flowSlug}
|
|
389
|
-
- Step: ${stepLabel}
|
|
390
|
-
- Menu option: ${run.menuOption}
|
|
391
|
-
- Date: ${(/* @__PURE__ */ new Date()).toISOString()}
|
|
392
|
-
- CLI version: ${readPackageVersion()}
|
|
393
|
-
- Platform: ${process.platform} / Node ${process.version}
|
|
394
|
-
- Duration on screen: ${finish.durationMs}ms
|
|
395
|
-
- Status: ${finish.status}
|
|
396
|
-
- Exit method: ${finish.exitMethod}
|
|
397
|
-
|
|
398
|
-
## Inputs
|
|
399
|
-
\`\`\`json
|
|
400
|
-
${JSON.stringify(run.inputs, null, 2)}
|
|
401
|
-
\`\`\`
|
|
402
|
-
|
|
403
|
-
## Outputs
|
|
404
|
-
\`\`\`json
|
|
405
|
-
${JSON.stringify(finish.outputs, null, 2)}
|
|
406
|
-
\`\`\`
|
|
407
|
-
`;
|
|
408
|
-
}
|
|
409
|
-
function handleCrash() {
|
|
410
|
-
return finishDebugRun({ outputs: {}, status: "error", exitMethod: "crashed" });
|
|
411
|
-
}
|
|
412
|
-
process.once("uncaughtException", (err) => {
|
|
413
|
-
void handleCrash().finally(() => {
|
|
414
|
-
throw err;
|
|
415
|
-
});
|
|
416
|
-
});
|
|
417
|
-
process.once("unhandledRejection", (reason) => {
|
|
418
|
-
void handleCrash().finally(() => {
|
|
419
|
-
throw reason;
|
|
420
|
-
});
|
|
421
|
-
});
|
|
422
|
-
process.once("SIGINT", () => {
|
|
423
|
-
void handleCrash().finally(() => {
|
|
424
|
-
process.exit(130);
|
|
425
|
-
});
|
|
426
|
-
});
|
|
427
|
-
|
|
428
254
|
// packages/experience-design-system-cli/src/tui/import/spawn-v1-import.ts
|
|
429
255
|
function buildArgs(options) {
|
|
430
256
|
const args = ["import"];
|
|
@@ -436,11 +262,9 @@ function buildArgs(options) {
|
|
|
436
262
|
async function spawnV1Import(options = {}) {
|
|
437
263
|
const cliPath = findLegacyCliPath();
|
|
438
264
|
const args = buildArgs(options);
|
|
439
|
-
const debugSessionDir = await debugSessionDirIfEnabled();
|
|
440
265
|
return new Promise((resolvePromise) => {
|
|
441
266
|
const child = spawn("node", [cliPath, ...args], {
|
|
442
|
-
stdio: "inherit"
|
|
443
|
-
env: debugSessionDir ? { ...process.env, EDS_DEBUG_SESSION_DIR: debugSessionDir } : process.env
|
|
267
|
+
stdio: "inherit"
|
|
444
268
|
});
|
|
445
269
|
child.on("close", (code) => {
|
|
446
270
|
resolvePromise({ exitCode: code ?? 1, result: void 0, stdout: "", stderr: "" });
|
|
@@ -470,24 +294,16 @@ function startReadingTerminal() {
|
|
|
470
294
|
}
|
|
471
295
|
|
|
472
296
|
// packages/experience-design-system-cli/src/tui/help/PageContainer.tsx
|
|
473
|
-
import { useEffect as useEffect3 } from "react";
|
|
474
297
|
import { Box as Box3, Text as Text3, useInput as useInput3 } from "ink";
|
|
475
298
|
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
476
299
|
function HelpScreen({ onDone }) {
|
|
477
|
-
useEffect3(() => {
|
|
478
|
-
startDebugRun({ flow: "help", step: "01-help", menuOption: "Help", inputs: {} });
|
|
479
|
-
}, []);
|
|
480
|
-
const leave = (exitMethod) => {
|
|
481
|
-
void finishDebugRun({ outputs: {}, status: "success", exitMethod });
|
|
482
|
-
onDone();
|
|
483
|
-
};
|
|
484
300
|
useInput3((input, key) => {
|
|
485
301
|
if (key.return) {
|
|
486
|
-
|
|
302
|
+
onDone();
|
|
487
303
|
return;
|
|
488
304
|
}
|
|
489
305
|
if (key.escape || input === "q") {
|
|
490
|
-
|
|
306
|
+
onDone();
|
|
491
307
|
return;
|
|
492
308
|
}
|
|
493
309
|
});
|
|
@@ -547,25 +363,25 @@ function SettingsScreen({
|
|
|
547
363
|
}
|
|
548
364
|
|
|
549
365
|
// packages/experience-design-system-cli/src/tui/settings/contentful-configuration/ContentfulConfigScreen.tsx
|
|
550
|
-
import { useEffect as
|
|
366
|
+
import { useEffect as useEffect3, useState as useState4 } from "react";
|
|
551
367
|
import { Box as Box5, Text as Text5, useInput as useInput5 } from "ink";
|
|
552
368
|
|
|
553
369
|
// packages/experience-design-system-cli/src/tui/settings/utils/v1-store.ts
|
|
554
|
-
import { readFile
|
|
555
|
-
import { join as
|
|
370
|
+
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
371
|
+
import { join as join4 } from "node:path";
|
|
556
372
|
import { homedir } from "node:os";
|
|
557
|
-
var V1_STORE_PATH =
|
|
373
|
+
var V1_STORE_PATH = join4(homedir(), ".config", "experiences", "credentials.json");
|
|
558
374
|
async function readV1Store() {
|
|
559
375
|
try {
|
|
560
|
-
const raw = await
|
|
376
|
+
const raw = await readFile(V1_STORE_PATH, "utf8");
|
|
561
377
|
return JSON.parse(raw);
|
|
562
378
|
} catch {
|
|
563
379
|
return {};
|
|
564
380
|
}
|
|
565
381
|
}
|
|
566
382
|
async function writeV1Store(data) {
|
|
567
|
-
await
|
|
568
|
-
await
|
|
383
|
+
await mkdir(join4(homedir(), ".config", "experiences"), { recursive: true });
|
|
384
|
+
await writeFile(V1_STORE_PATH, `${JSON.stringify(data, null, 2)}
|
|
569
385
|
`, { mode: 384 });
|
|
570
386
|
}
|
|
571
387
|
|
|
@@ -594,14 +410,6 @@ async function writeCredentials(config) {
|
|
|
594
410
|
// packages/experience-design-system-cli/src/tui/settings/contentful-configuration/ContentfulConfigScreen.tsx
|
|
595
411
|
import { Fragment, jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
596
412
|
var FIELD_ORDER = ["spaceId", "environmentId", "cmaToken", "host"];
|
|
597
|
-
function debugFields(config) {
|
|
598
|
-
return {
|
|
599
|
-
space_id: config?.spaceId ?? "",
|
|
600
|
-
environment_id: config?.environmentId ?? "",
|
|
601
|
-
cma_token: config?.cmaToken ?? "",
|
|
602
|
-
host: config?.host ?? ""
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
413
|
var FIELD_LABELS = {
|
|
606
414
|
spaceId: "Space ID",
|
|
607
415
|
environmentId: "Environment ID",
|
|
@@ -613,16 +421,10 @@ function ConfigurationScreen({ onDone }) {
|
|
|
613
421
|
const [config, setConfig] = useState4(null);
|
|
614
422
|
const [activeField, setActiveField] = useState4("spaceId");
|
|
615
423
|
const [message, setMessage] = useState4(null);
|
|
616
|
-
|
|
424
|
+
useEffect3(() => {
|
|
617
425
|
readCredentials().then((cfg) => {
|
|
618
426
|
setConfig(cfg);
|
|
619
427
|
setStage("form");
|
|
620
|
-
startDebugRun({
|
|
621
|
-
flow: "settings/contentful-configuration",
|
|
622
|
-
step: "01-configuration",
|
|
623
|
-
menuOption: "Configuration",
|
|
624
|
-
inputs: debugFields(cfg)
|
|
625
|
-
});
|
|
626
428
|
});
|
|
627
429
|
}, []);
|
|
628
430
|
function fieldValue(field) {
|
|
@@ -649,13 +451,11 @@ function ConfigurationScreen({ onDone }) {
|
|
|
649
451
|
if (stage === "loading" || stage === "saving") return;
|
|
650
452
|
if (stage === "saved") {
|
|
651
453
|
if (key.return || key.escape || input === "q") {
|
|
652
|
-
void finishDebugRun({ outputs: debugFields(config), status: "success", exitMethod: "saved" });
|
|
653
454
|
onDone();
|
|
654
455
|
}
|
|
655
456
|
return;
|
|
656
457
|
}
|
|
657
458
|
if (key.escape || input === "q") {
|
|
658
|
-
void finishDebugRun({ outputs: {}, status: "success", exitMethod: "discarded" });
|
|
659
459
|
onDone();
|
|
660
460
|
return;
|
|
661
461
|
}
|
|
@@ -737,7 +537,7 @@ function ConfigurationScreen({ onDone }) {
|
|
|
737
537
|
}
|
|
738
538
|
|
|
739
539
|
// packages/experience-design-system-cli/src/tui/settings/opt-in-analytics/screen.tsx
|
|
740
|
-
import { useEffect as
|
|
540
|
+
import { useEffect as useEffect4, useState as useState5 } from "react";
|
|
741
541
|
import { Box as Box6, Text as Text6, useInput as useInput6 } from "ink";
|
|
742
542
|
|
|
743
543
|
// packages/experience-design-system-cli/src/tui/settings/opt-in-analytics/analytics-store.ts
|
|
@@ -760,16 +560,10 @@ import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs6 } from "react/jsx-run
|
|
|
760
560
|
function OptInAnalyticsScreen({ onDone }) {
|
|
761
561
|
const [loading, setLoading] = useState5(true);
|
|
762
562
|
const [enabled, setEnabled] = useState5(true);
|
|
763
|
-
|
|
563
|
+
useEffect4(() => {
|
|
764
564
|
readAnalyticsSetting().then((setting) => {
|
|
765
565
|
setEnabled(setting.enabled);
|
|
766
566
|
setLoading(false);
|
|
767
|
-
startDebugRun({
|
|
768
|
-
flow: "settings/opt-in-analytics",
|
|
769
|
-
step: "01-opt-in-analytics",
|
|
770
|
-
menuOption: "Opt-in Analytics",
|
|
771
|
-
inputs: { enabled: setting.enabled }
|
|
772
|
-
});
|
|
773
567
|
});
|
|
774
568
|
}, []);
|
|
775
569
|
useInput6((input, key) => {
|
|
@@ -783,7 +577,6 @@ function OptInAnalyticsScreen({ onDone }) {
|
|
|
783
577
|
return;
|
|
784
578
|
}
|
|
785
579
|
if (key.escape || input === "q") {
|
|
786
|
-
void finishDebugRun({ outputs: { enabled }, status: "success", exitMethod: "saved" });
|
|
787
580
|
onDone();
|
|
788
581
|
}
|
|
789
582
|
});
|
|
@@ -806,13 +599,186 @@ function OptInAnalyticsScreen({ onDone }) {
|
|
|
806
599
|
}
|
|
807
600
|
|
|
808
601
|
// packages/experience-design-system-cli/src/tui/upgrade/PageContainer.tsx
|
|
809
|
-
import { useEffect as
|
|
602
|
+
import { useEffect as useEffect5, useState as useState6 } from "react";
|
|
810
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
|
|
811
777
|
import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
812
778
|
var UPGRADE_COMMANDS = ["git pull", "pnpm install", "pnpm build"];
|
|
813
779
|
function UpgradeScreen({ onDone }) {
|
|
814
780
|
const [upgradeCheck, setUpgradeCheck] = useState6();
|
|
815
|
-
|
|
781
|
+
useEffect5(() => {
|
|
816
782
|
startDebugRun({
|
|
817
783
|
flow: "upgrade",
|
|
818
784
|
step: "01-upgrade",
|
|
@@ -877,22 +843,16 @@ function renderBody(upgradeCheck) {
|
|
|
877
843
|
}
|
|
878
844
|
|
|
879
845
|
// packages/experience-design-system-cli/src/tui/settings/debug-mode/screen.tsx
|
|
880
|
-
import { useEffect as
|
|
846
|
+
import { useEffect as useEffect6, useState as useState7 } from "react";
|
|
881
847
|
import { Box as Box8, Text as Text8, useInput as useInput8 } from "ink";
|
|
882
848
|
import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
883
849
|
function DebugModeScreen({ onDone }) {
|
|
884
850
|
const [loading, setLoading] = useState7(true);
|
|
885
851
|
const [enabled, setEnabled] = useState7(true);
|
|
886
|
-
|
|
852
|
+
useEffect6(() => {
|
|
887
853
|
readDebugModeSetting().then((setting) => {
|
|
888
854
|
setEnabled(setting.enabled);
|
|
889
855
|
setLoading(false);
|
|
890
|
-
startDebugRun({
|
|
891
|
-
flow: "settings/debug-mode",
|
|
892
|
-
step: "01-debug-mode",
|
|
893
|
-
menuOption: "Debug Mode",
|
|
894
|
-
inputs: { enabled: setting.enabled }
|
|
895
|
-
});
|
|
896
856
|
});
|
|
897
857
|
}, []);
|
|
898
858
|
useInput8((input, key) => {
|
|
@@ -906,7 +866,6 @@ function DebugModeScreen({ onDone }) {
|
|
|
906
866
|
return;
|
|
907
867
|
}
|
|
908
868
|
if (key.escape || input === "q") {
|
|
909
|
-
void finishDebugRun({ outputs: { enabled }, status: "success", exitMethod: "saved" });
|
|
910
869
|
onDone();
|
|
911
870
|
}
|
|
912
871
|
});
|