markmap-cli 0.15.9-alpha.5 → 0.16.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.
@@ -1,17 +1,5 @@
1
- import { IDevelopOptions } from './util';
2
- interface IFileUpdate {
3
- ts?: number;
4
- content?: string;
5
- line?: number;
6
- }
7
- interface IContentProvider {
8
- getUpdate: (ts: number, timeout?: number) => Promise<IFileUpdate>;
9
- setContent: (content: string) => void;
10
- setCursor: (line: number) => void;
11
- dispose: () => void;
12
- }
1
+ import { IDevelopOptions, IContentProvider } from './types';
13
2
  export declare function develop(fileName: string | undefined, options: IDevelopOptions): Promise<{
14
3
  provider: IContentProvider;
15
4
  close(): Promise<void>;
16
5
  }>;
17
- export {};
@@ -1 +1 @@
1
- export declare function fetchAssets(): Promise<void>;
1
+ export declare function fetchAssets(assetsDir?: string): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import { type IMarkmapCreateOptions } from 'markmap-lib';
2
- import { IDevelopOptions } from './util';
2
+ import { config } from './util';
3
+ import { IDevelopOptions } from './types';
3
4
  import { develop } from './dev-server';
4
5
  import { fetchAssets } from './fetch-assets';
5
6
  export * from 'markmap-lib';
6
- export { develop, fetchAssets };
7
+ export * from './types';
8
+ export { config, develop, fetchAssets };
7
9
  export declare function createMarkmap(options: IMarkmapCreateOptions & IDevelopOptions): Promise<void>;
8
10
  export declare function main(): Promise<void>;
package/dist/index.js CHANGED
@@ -1,22 +1,23 @@
1
1
  import { readFile, stat, mkdir, writeFile } from "fs/promises";
2
- import { resolve, join, dirname } from "path";
2
+ import { join, resolve, dirname } from "path";
3
3
  import { fileURLToPath } from "url";
4
4
  import { Command } from "commander";
5
5
  import open from "open";
6
6
  import updateNotifier from "update-notifier";
7
7
  import { readPackageUp } from "read-package-up";
8
8
  import { buildCSSItem, buildJSItem, defer } from "markmap-common";
9
- import { Transformer, baseJsPaths } from "markmap-lib";
9
+ import { Transformer } from "markmap-lib";
10
10
  export * from "markmap-lib";
11
- import { packageDirectory } from "pkg-dir";
12
- import { createReadStream, createWriteStream } from "fs";
13
- import { EventEmitter } from "events";
11
+ import { fillTemplate, baseJsPaths } from "markmap-render";
14
12
  import { serve } from "@hono/node-server";
15
- import { Hono } from "hono";
16
13
  import chokidar from "chokidar";
14
+ import { EventEmitter } from "events";
15
+ import { createReadStream, createWriteStream } from "fs";
16
+ import { Hono } from "hono";
17
17
  import { Readable } from "stream";
18
18
  import { finished } from "stream/promises";
19
- const TOOLBAR_VERSION = "0.15.9-alpha.5";
19
+ const __vite_glob_0_0 = "data:application/octet-stream;base64,L2Fzc2V0cwo=";
20
+ const TOOLBAR_VERSION = "0.16.0";
20
21
  const TOOLBAR_CSS = `markmap-toolbar@${TOOLBAR_VERSION}/dist/style.css`;
21
22
  const TOOLBAR_JS = `markmap-toolbar@${TOOLBAR_VERSION}/dist/index.js`;
22
23
  const ASSETS_PREFIX = "/assets/";
@@ -52,14 +53,6 @@ function addToolbar(urlBuilder, assets) {
52
53
  function localProvider(path) {
53
54
  return `${ASSETS_PREFIX}${path}`;
54
55
  }
55
- const rootDirPromise = packageDirectory({
56
- cwd: new URL(import.meta.url).pathname
57
- });
58
- const assetsDirPromise = rootDirPromise.then((rootDir) => {
59
- if (!rootDir)
60
- throw new Error("Could not find root dir");
61
- return resolve(rootDir, `.${ASSETS_PREFIX}`);
62
- });
63
56
  function createStreamBody(stream) {
64
57
  const body = new ReadableStream({
65
58
  start(controller) {
@@ -76,6 +69,9 @@ function createStreamBody(stream) {
76
69
  });
77
70
  return body;
78
71
  }
72
+ const config = {
73
+ assetsDir: fileURLToPath(new URL((/* @__PURE__ */ Object.assign({ "../.gitignore": __vite_glob_0_0 }))[`../.${ASSETS_PREFIX}`], import.meta.url))
74
+ };
79
75
  var getMimeType = (filename) => {
80
76
  const regexp = /\.([a-zA-Z0-9]+?)$/;
81
77
  const match = filename.match(regexp);
@@ -282,12 +278,12 @@ function startServer(paddingBottom) {
282
278
  dfs(root);
283
279
  return best;
284
280
  function dfs(node) {
285
- var _a, _b;
286
- const lines = (_a = node.payload) == null ? void 0 : _a.lines;
287
- if (lines && lines[0] <= lineWithoutFrontmatter && lineWithoutFrontmatter < lines[1]) {
281
+ var _a, _b, _c;
282
+ const [start, end] = ((_b = (_a = node.payload) == null ? void 0 : _a.lines) == null ? void 0 : _b.split(",").map((s) => +s)) || [];
283
+ if (start >= 0 && start <= lineWithoutFrontmatter && lineWithoutFrontmatter < end) {
288
284
  best = node;
289
285
  }
290
- (_b = node.children) == null ? void 0 : _b.forEach(dfs);
286
+ (_c = node.children) == null ? void 0 : _c.forEach(dfs);
291
287
  }
292
288
  }
293
289
  }
@@ -295,10 +291,9 @@ async function setUpServer(transformer, provider, options) {
295
291
  let assets = transformer.getAssets();
296
292
  if (options.toolbar)
297
293
  assets = addToolbar(transformer.urlBuilder, assets);
298
- const html = `${transformer.fillTemplate(
299
- null,
300
- assets
301
- )}<script>(${startServer.toString()})(${options.toolbar ? 60 : 0})<\/script>`;
294
+ const html = `${fillTemplate(null, assets, {
295
+ urlBuilder: transformer.urlBuilder
296
+ })}<script>(${startServer.toString()})(${options.toolbar ? 60 : 0})<\/script>`;
302
297
  const app = new Hono();
303
298
  app.get("/", (c) => c.html(html));
304
299
  app.get("/~data", async (c) => {
@@ -312,7 +307,7 @@ async function setUpServer(transformer, provider, options) {
312
307
  await ((_a = provider[cmd]) == null ? void 0 : _a.call(provider, ...args));
313
308
  return c.body(null, 204);
314
309
  });
315
- const assetsDir = await assetsDirPromise;
310
+ const { assetsDir } = config;
316
311
  app.get(`${ASSETS_PREFIX}*`, async (c) => {
317
312
  const relpath = c.req.path.slice(ASSETS_PREFIX.length);
318
313
  const realpath = join(assetsDir, relpath);
@@ -367,7 +362,7 @@ async function develop(fileName, options) {
367
362
  return setUpServer(transformer, provider, options);
368
363
  }
369
364
  const providerName = "local-hook";
370
- async function fetchAssets() {
365
+ async function fetchAssets(assetsDir = config.assetsDir) {
371
366
  var _a, _b;
372
367
  const transformer = new Transformer();
373
368
  const { provider } = transformer.urlBuilder;
@@ -386,7 +381,6 @@ async function fetchAssets() {
386
381
  )) || []
387
382
  ].filter((url) => url.startsWith(ASSETS_PREFIX)).map((url) => url.slice(ASSETS_PREFIX.length));
388
383
  const paths = [...baseJsPaths, ...pluginPaths];
389
- const assetsDir = await assetsDirPromise;
390
384
  const fastest = await transformer.urlBuilder.getFastestProvider();
391
385
  await Promise.all(
392
386
  paths.map(
@@ -417,8 +411,7 @@ async function downloadAsset(fullPath, url) {
417
411
  async function loadFile(path) {
418
412
  if (path.startsWith(ASSETS_PREFIX)) {
419
413
  const relpath = path.slice(ASSETS_PREFIX.length);
420
- const assetsDir = await assetsDirPromise;
421
- return readFile(resolve(assetsDir, relpath), "utf8");
414
+ return readFile(resolve(config.assetsDir, relpath), "utf8");
422
415
  }
423
416
  const res = await fetch(path);
424
417
  if (!res.ok)
@@ -479,9 +472,10 @@ async function createMarkmap(options) {
479
472
  if (options.offline) {
480
473
  assets = await inlineAssets(assets);
481
474
  }
482
- const html = transformer.fillTemplate(root, assets, {
475
+ const html = fillTemplate(root, assets, {
483
476
  baseJs: [],
484
- jsonOptions: frontmatter == null ? void 0 : frontmatter.markmap
477
+ jsonOptions: frontmatter == null ? void 0 : frontmatter.markmap,
478
+ urlBuilder: transformer.urlBuilder
485
479
  });
486
480
  const output = options.output || "markmap.html";
487
481
  await writeFile(output, html, "utf8");
@@ -531,6 +525,7 @@ async function main() {
531
525
  program.parse(process.argv);
532
526
  }
533
527
  export {
528
+ config,
534
529
  createMarkmap,
535
530
  develop,
536
531
  fetchAssets,
@@ -0,0 +1,28 @@
1
+ export interface IDevelopOptions {
2
+ /**
3
+ * Whether to open the generated markmap in browser
4
+ */
5
+ open: boolean;
6
+ /**
7
+ * Whether to show the default toolbar
8
+ */
9
+ toolbar: boolean;
10
+ /**
11
+ * Whether to inline all assets to make the HTML work offline.
12
+ * Ignored in watching mode.
13
+ */
14
+ offline: boolean;
15
+ /** Port number for the devServer to listen. */
16
+ port?: number;
17
+ }
18
+ export interface IFileUpdate {
19
+ ts?: number;
20
+ content?: string;
21
+ line?: number;
22
+ }
23
+ export interface IContentProvider {
24
+ getUpdate: (ts: number, timeout?: number) => Promise<IFileUpdate>;
25
+ setContent: (content: string) => void;
26
+ setCursor: (line: number) => void;
27
+ dispose: () => void;
28
+ }
package/dist/util.d.ts CHANGED
@@ -3,25 +3,9 @@ import type { ReadStream } from 'fs';
3
3
  import { UrlBuilder } from 'markmap-common';
4
4
  import { IAssets } from 'markmap-lib';
5
5
  export declare const ASSETS_PREFIX = "/assets/";
6
- export interface IDevelopOptions {
7
- /**
8
- * Whether to open the generated markmap in browser
9
- */
10
- open: boolean;
11
- /**
12
- * Whether to show the default toolbar
13
- */
14
- toolbar: boolean;
15
- /**
16
- * Whether to inline all assets to make the HTML work offline.
17
- * Ignored in watching mode.
18
- */
19
- offline: boolean;
20
- /** Port number for the devServer to listen. */
21
- port?: number;
22
- }
23
6
  export declare function addToolbar(urlBuilder: UrlBuilder, assets: IAssets): IAssets;
24
7
  export declare function localProvider(path: string): string;
25
- export declare const rootDirPromise: Promise<string | undefined>;
26
- export declare const assetsDirPromise: Promise<string>;
27
8
  export declare function createStreamBody(stream: ReadStream): ReadableStream<any>;
9
+ export declare const config: {
10
+ assetsDir: string;
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-cli",
3
- "version": "0.15.9-alpha.5+c64866f",
3
+ "version": "0.16.0",
4
4
  "description": "Create markmaps from CLI",
5
5
  "author": "Gerald <gera2ld@live.com>",
6
6
  "license": "MIT",
@@ -28,6 +28,7 @@
28
28
  "clean": "del-cli dist",
29
29
  "build:types": "tsc",
30
30
  "build:js": "vite build",
31
+ "build": "run-s clean build:*",
31
32
  "postinstall": "node -e \"import('./dist/index.js').then(({ fetchAssets }) => fetchAssets()).catch(() => {})\""
32
33
  },
33
34
  "bugs": {
@@ -47,13 +48,14 @@
47
48
  "chokidar": "^3.5.3",
48
49
  "commander": "^11.1.0",
49
50
  "hono": "^3.11.8",
50
- "markmap-common": "0.15.9-alpha.5+c64866f",
51
- "markmap-lib": "0.15.9-alpha.5+c64866f",
52
- "markmap-toolbar": "0.15.9-alpha.5+c64866f",
51
+ "markmap-common": "0.16.0",
52
+ "markmap-lib": "0.16.0",
53
+ "markmap-render": "0.16.0",
54
+ "markmap-toolbar": "0.16.0",
53
55
  "open": "^10.0.0",
54
56
  "pkg-dir": "^8.0.0",
55
57
  "read-package-up": "^11.0.0",
56
58
  "update-notifier": "^7.0.0"
57
59
  },
58
- "gitHead": "c64866fb4873a99923be18ea70715aa49a6dabef"
60
+ "gitHead": "caf3f840ad39c240ba522bfea83c57de62c6cac4"
59
61
  }