markmap-cli 0.17.2 → 0.17.3-alpha.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.
- package/dist/index.js +18 -32
- package/dist/util.d.ts +0 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import { createReadStream, createWriteStream } from "fs";
|
|
|
16
16
|
import { Hono } from "hono";
|
|
17
17
|
import { Readable } from "stream";
|
|
18
18
|
import { finished } from "stream/promises";
|
|
19
|
-
const TOOLBAR_VERSION = "0.17.
|
|
19
|
+
const TOOLBAR_VERSION = "0.17.3-alpha.1";
|
|
20
20
|
const TOOLBAR_CSS = `markmap-toolbar@${TOOLBAR_VERSION}/dist/style.css`;
|
|
21
21
|
const TOOLBAR_JS = `markmap-toolbar@${TOOLBAR_VERSION}/dist/index.js`;
|
|
22
22
|
const currentDir = dirname(fileURLToPath(import.meta.url));
|
|
@@ -75,8 +75,9 @@ const config = {
|
|
|
75
75
|
var getMimeType = (filename) => {
|
|
76
76
|
const regexp = /\.([a-zA-Z0-9]+?)$/;
|
|
77
77
|
const match = filename.match(regexp);
|
|
78
|
-
if (!match)
|
|
78
|
+
if (!match) {
|
|
79
79
|
return;
|
|
80
|
+
}
|
|
80
81
|
let mimeType = mimes[match[1]];
|
|
81
82
|
if (mimeType && mimeType.startsWith("text") || mimeType === "application/json") {
|
|
82
83
|
mimeType += "; charset=utf-8";
|
|
@@ -258,16 +259,14 @@ function startServer(paddingBottom) {
|
|
|
258
259
|
({ root, frontmatter, contentLineOffset: offset } = res.result);
|
|
259
260
|
mm.setOptions(markmap.deriveOptions(frontmatter == null ? void 0 : frontmatter.markmap));
|
|
260
261
|
mm.setData(root);
|
|
261
|
-
if (!ts)
|
|
262
|
-
mm.fit();
|
|
262
|
+
if (!ts) mm.fit();
|
|
263
263
|
ts = res.ts;
|
|
264
264
|
line = -1;
|
|
265
265
|
}
|
|
266
266
|
if (root && res.line != null && line !== res.line) {
|
|
267
267
|
line = res.line;
|
|
268
268
|
const active = findActiveNode();
|
|
269
|
-
if (active)
|
|
270
|
-
mm.ensureView(active, { bottom: paddingBottom });
|
|
269
|
+
if (active) mm.ensureView(active, { bottom: paddingBottom });
|
|
271
270
|
}
|
|
272
271
|
setTimeout(refresh, 300);
|
|
273
272
|
});
|
|
@@ -289,8 +288,7 @@ function startServer(paddingBottom) {
|
|
|
289
288
|
}
|
|
290
289
|
async function setUpServer(transformer, provider, options) {
|
|
291
290
|
let assets = transformer.getAssets();
|
|
292
|
-
if (options.toolbar)
|
|
293
|
-
assets = addToolbar(transformer.urlBuilder, assets);
|
|
291
|
+
if (options.toolbar) assets = addToolbar(transformer.urlBuilder, assets);
|
|
294
292
|
const html = `${fillTemplate(null, assets, {
|
|
295
293
|
urlBuilder: transformer.urlBuilder
|
|
296
294
|
})}<script>(${startServer.toString()})(${options.toolbar ? 60 : 0})<\/script>`;
|
|
@@ -313,15 +311,13 @@ async function setUpServer(transformer, provider, options) {
|
|
|
313
311
|
const realpath = join(assetsDir, relpath);
|
|
314
312
|
try {
|
|
315
313
|
const result = await stat(realpath);
|
|
316
|
-
if (!result.isFile())
|
|
317
|
-
throw new Error("File not found");
|
|
314
|
+
if (!result.isFile()) throw new Error("File not found");
|
|
318
315
|
} catch {
|
|
319
316
|
return c.body("File not found", 404);
|
|
320
317
|
}
|
|
321
318
|
const stream = createReadStream(realpath);
|
|
322
319
|
const type = getMimeType(relpath);
|
|
323
|
-
if (type)
|
|
324
|
-
c.header("content-type", type);
|
|
320
|
+
if (type) c.header("content-type", type);
|
|
325
321
|
return c.body(createStreamBody(stream));
|
|
326
322
|
});
|
|
327
323
|
const server = serve(
|
|
@@ -332,8 +328,7 @@ async function setUpServer(transformer, provider, options) {
|
|
|
332
328
|
(info) => {
|
|
333
329
|
const { port } = info;
|
|
334
330
|
console.info(`Listening at http://localhost:${port}`);
|
|
335
|
-
if (options.open)
|
|
336
|
-
open(`http://localhost:${port}`);
|
|
331
|
+
if (options.open) open(`http://localhost:${port}`);
|
|
337
332
|
}
|
|
338
333
|
);
|
|
339
334
|
let closing;
|
|
@@ -343,10 +338,8 @@ async function setUpServer(transformer, provider, options) {
|
|
|
343
338
|
if (!closing) {
|
|
344
339
|
closing = new Promise(
|
|
345
340
|
(resolve2, reject) => server.close((err) => {
|
|
346
|
-
if (err)
|
|
347
|
-
|
|
348
|
-
else
|
|
349
|
-
resolve2();
|
|
341
|
+
if (err) reject(err);
|
|
342
|
+
else resolve2();
|
|
350
343
|
})
|
|
351
344
|
);
|
|
352
345
|
}
|
|
@@ -398,14 +391,12 @@ async function fetchAssets(assetsDir = config.assetsDir) {
|
|
|
398
391
|
async function downloadAsset(fullPath, resolveUrl) {
|
|
399
392
|
try {
|
|
400
393
|
const result = await stat(fullPath);
|
|
401
|
-
if (result.isFile())
|
|
402
|
-
return;
|
|
394
|
+
if (result.isFile()) return;
|
|
403
395
|
} catch {
|
|
404
396
|
}
|
|
405
397
|
const url = await resolveUrl();
|
|
406
398
|
const res = await fetch(url);
|
|
407
|
-
if (!res.ok || !res.body)
|
|
408
|
-
throw new Error(`Failed to download: ${url}`);
|
|
399
|
+
if (!res.ok || !res.body) throw new Error(`Failed to download: ${url}`);
|
|
409
400
|
await mkdir(dirname(fullPath), { recursive: true });
|
|
410
401
|
await finished(
|
|
411
402
|
Readable.fromWeb(res.body).pipe(
|
|
@@ -419,8 +410,7 @@ async function loadFile(path) {
|
|
|
419
410
|
return readFile(resolve(config.assetsDir, relpath), "utf8");
|
|
420
411
|
}
|
|
421
412
|
const res = await fetch(path);
|
|
422
|
-
if (!res.ok)
|
|
423
|
-
throw res;
|
|
413
|
+
if (!res.ok) throw res;
|
|
424
414
|
return res.text();
|
|
425
415
|
}
|
|
426
416
|
async function inlineAssets(assets) {
|
|
@@ -484,16 +474,14 @@ async function createMarkmap(options) {
|
|
|
484
474
|
});
|
|
485
475
|
const output = options.output || "markmap.html";
|
|
486
476
|
await writeFile(output, html, "utf8");
|
|
487
|
-
if (options.open)
|
|
488
|
-
open(output);
|
|
477
|
+
if (options.open) open(output);
|
|
489
478
|
}
|
|
490
479
|
async function main() {
|
|
491
480
|
var _a;
|
|
492
481
|
const pkg = (_a = await readPackageUp({
|
|
493
482
|
cwd: fileURLToPath(import.meta.url)
|
|
494
483
|
})) == null ? void 0 : _a.packageJson;
|
|
495
|
-
if (!pkg)
|
|
496
|
-
throw new Error("package.json not found");
|
|
484
|
+
if (!pkg) throw new Error("package.json not found");
|
|
497
485
|
const notifier = updateNotifier({ pkg });
|
|
498
486
|
notifier.notify();
|
|
499
487
|
const program = new Command();
|
|
@@ -505,10 +493,8 @@ async function main() {
|
|
|
505
493
|
"watch the input file and update output on the fly, note that this feature is for development only"
|
|
506
494
|
).action(async (input, cmd) => {
|
|
507
495
|
let { offline } = cmd;
|
|
508
|
-
if (cmd.watch)
|
|
509
|
-
|
|
510
|
-
if (offline)
|
|
511
|
-
await fetchAssets();
|
|
496
|
+
if (cmd.watch) offline = true;
|
|
497
|
+
if (offline) await fetchAssets();
|
|
512
498
|
const content = await readFile(input, "utf8");
|
|
513
499
|
const output = cmd.output || `${input.replace(/\.\w*$/, "")}.html`;
|
|
514
500
|
if (cmd.watch) {
|
package/dist/util.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markmap-cli",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.3-alpha.1+4942a37",
|
|
4
4
|
"description": "Create markmaps from CLI",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,13 +50,13 @@
|
|
|
50
50
|
"commander": "^11.1.0",
|
|
51
51
|
"hono": "^3.11.8",
|
|
52
52
|
"markmap-common": "0.17.1",
|
|
53
|
-
"markmap-lib": "0.17.
|
|
54
|
-
"markmap-render": "0.17.
|
|
55
|
-
"markmap-toolbar": "0.17.
|
|
53
|
+
"markmap-lib": "0.17.3-alpha.1+4942a37",
|
|
54
|
+
"markmap-render": "0.17.3-alpha.1+4942a37",
|
|
55
|
+
"markmap-toolbar": "0.17.3-alpha.1+4942a37",
|
|
56
56
|
"open": "^10.0.0",
|
|
57
57
|
"pkg-dir": "^8.0.0",
|
|
58
58
|
"read-package-up": "^11.0.0",
|
|
59
59
|
"update-notifier": "^7.0.0"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "4942a3759db08bbbc179034c0b08c5c2112566dc"
|
|
62
62
|
}
|