jsmdcui 0.8.0 → 0.10.1

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.
@@ -2,6 +2,7 @@ import { expect, test } from "bun:test";
2
2
  import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
+ import { readMarkdownInput } from "../runmd.mjs";
5
6
 
6
7
  const tui = join(import.meta.dir, "..", "tui");
7
8
  const bunBin = Bun.which("bun") || process.argv0;
@@ -14,13 +15,14 @@ test("--help describes the non-overwriting demo behavior", () => {
14
15
 
15
16
  expect(result.exitCode).toBe(0);
16
17
  const output = result.stdout.toString();
17
- expect(output).toContain("use the existing ./testapp.md without overwriting it");
18
- expect(output).toContain("If ./testapp.md is missing, write the bundled demo there first");
18
+ expect(output).toContain("Execute an existing ./testapp.md");
19
+ expect(output).toContain("Or write the bundled demo if missing");
19
20
  expect(output).toContain("--demo-<filename>");
20
21
  expect(output).toContain("demos/<filename>.md");
21
22
  expect(output.match(/Open it in the TUI and write 5 generated files beside it/g)?.length).toBe(2);
22
23
  expect(output).toContain("--demo-imgtool");
23
24
  expect(output).toContain("--demo-imgtool-zh");
25
+ expect(output).toContain("--cdp-maze");
24
26
  });
25
27
 
26
28
  test("--demo-list lists root and automatically discovered demos", () => {
@@ -38,6 +40,27 @@ test("--demo-list lists root and automatically discovered demos", () => {
38
40
  expect(output).toContain("--demo-imgtool --demo-image-processor");
39
41
  });
40
42
 
43
+ test("--export-cdp-maze writes and overwrites the bundled solver", async () => {
44
+ const dir = await mkdtemp(join(tmpdir(), "jsmdcui-export-cdp-maze-"));
45
+ const outputPath = join(dir, "cdp-maze.js");
46
+ try {
47
+ await writeFile(outputPath, "old solver\n");
48
+ const result = Bun.spawnSync([bunBin, tui, "--export-cdp-maze"], {
49
+ cwd: dir,
50
+ stdout: "pipe",
51
+ stderr: "pipe",
52
+ });
53
+
54
+ expect(result.exitCode).toBe(0);
55
+ expect(result.stdout.toString()).toContain(`Wrote ${outputPath}`);
56
+ const exported = await readFile(outputPath, "utf8");
57
+ expect(exported).toContain("export async function runCdpMaze");
58
+ expect(exported).not.toContain("old solver");
59
+ } finally {
60
+ await rm(dir, { recursive: true, force: true });
61
+ }
62
+ });
63
+
41
64
  test("--demo writes bundled testapp.md to cwd before opening it", async () => {
42
65
  const dir = await mkdtemp(join(tmpdir(), "jsmdcui-demo-"));
43
66
  try {
@@ -75,6 +98,44 @@ test("--demo preserves an existing testapp.md", async () => {
75
98
  }
76
99
  });
77
100
 
101
+ test("--overwrite-demo replaces an existing demo with the bundled copy", async () => {
102
+ const dir = await mkdtemp(join(tmpdir(), "jsmdcui-demo-overwrite-"));
103
+ const existing = "# Replace my demo\n";
104
+ try {
105
+ await writeFile(join(dir, "testapp.md"), existing);
106
+ const result = Bun.spawnSync(
107
+ [bunBin, tui, "--overwrite-demo", "--demo", "-cat", "-encoding", "utf8"],
108
+ {
109
+ cwd: dir,
110
+ stdout: "pipe",
111
+ stderr: "pipe",
112
+ },
113
+ );
114
+
115
+ expect(result.exitCode).toBe(0);
116
+ const written = await readFile(join(dir, "testapp.md"), "utf8");
117
+ expect(written).toContain("計算機");
118
+ expect(written).not.toBe(existing);
119
+ expect(Bun.stripANSI(result.stdout.toString())).toContain("計算機");
120
+ } finally {
121
+ await rm(dir, { recursive: true, force: true });
122
+ }
123
+ });
124
+
125
+ test("WUI demo loading can overwrite an existing testapp.md", async () => {
126
+ const dir = await mkdtemp(join(tmpdir(), "jsmdcui-wui-demo-overwrite-"));
127
+ const demoPath = join(dir, "testapp.md");
128
+ try {
129
+ await writeFile(demoPath, "# Replace my WUI demo\n");
130
+ const source = await readMarkdownInput(demoPath, true);
131
+
132
+ expect(source).toContain("計算機");
133
+ expect(await readFile(demoPath, "utf8")).toBe(source);
134
+ } finally {
135
+ await rm(dir, { recursive: true, force: true });
136
+ }
137
+ });
138
+
78
139
  test("--demo-<filename> automatically loads a matching demos file", async () => {
79
140
  const dir = await mkdtemp(join(tmpdir(), "jsmdcui-demo-generic-"));
80
141
  try {
@@ -94,6 +155,24 @@ test("--demo-<filename> automatically loads a matching demos file", async () =>
94
155
  }
95
156
  });
96
157
 
158
+ test("--cdp-maze loads the maze demo", async () => {
159
+ const dir = await mkdtemp(join(tmpdir(), "jsmdcui-cdp-maze-"));
160
+ try {
161
+ const result = Bun.spawnSync([bunBin, tui, "--cdp-maze", "-cat", "-encoding", "utf8"], {
162
+ cwd: dir,
163
+ stdout: "pipe",
164
+ stderr: "pipe",
165
+ });
166
+
167
+ expect(result.exitCode).toBe(0);
168
+ const written = await readFile(join(dir, "maze.md"), "utf8");
169
+ expect(written).toContain("Put the cursor here");
170
+ expect(Bun.stripANSI(result.stdout.toString())).toContain("Put the cursor here");
171
+ } finally {
172
+ await rm(dir, { recursive: true, force: true });
173
+ }
174
+ });
175
+
97
176
  test("--demo-<filename> preserves an existing local copy", async () => {
98
177
  const dir = await mkdtemp(join(tmpdir(), "jsmdcui-demo-generic-existing-"));
99
178
  const existing = "# Keep my selector demo\n";
@@ -83,7 +83,7 @@ Content before the image, line 10.
83
83
 
84
84
  ## Image anchor
85
85
 
86
- ![img](../demo.resized.jpg)
86
+ ![img](../maze.jpg)
87
87
 
88
88
  ## After image 01
89
89
  Content after the image, line 01.
package/demo.resized.jpg DELETED
Binary file
@@ -1,25 +0,0 @@
1
- import { basename, dirname, resolve } from "node:path";
2
- import { readFileSync } from "node:fs";
3
- import { fileURLToPath } from "node:url";
4
-
5
- export function isCompiledBinary(argv = process.argv) {
6
- return Boolean(argv?.[1]?.startsWith?.("/$bunfs/"));
7
- }
8
-
9
- export function resolveCompiledBaseDir({ argv = process.argv, execPath = process.execPath } = {}) {
10
- const bn = basename(execPath);
11
- if (bn.startsWith("ld") ||
12
- bn.startsWith("libld") ||
13
- bn.startsWith("linker") ) {
14
- const realArgv = readFileSync("/proc/self/cmdline", "utf8").match(/[^\0]+/g);
15
- return dirname(realArgv?.[1] ?? execPath);
16
- }
17
- return dirname(execPath) || process.cwd();
18
- }
19
-
20
- export function resolveRepoRoot(importMetaUrl, options = {}) {
21
- if (isCompiledBinary(options.argv)) {
22
- return resolveCompiledBaseDir(options);
23
- }
24
- return resolve(dirname(fileURLToPath(importMetaUrl)), "..");
25
- }