markmap-cli 0.15.9-alpha.6 → 0.16.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/README.md +2 -53
- package/dist/dev-server.d.ts +1 -13
- package/dist/fetch-assets.d.ts +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +19 -26
- package/dist/types.d.ts +28 -0
- package/dist/util.d.ts +3 -19
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -6,57 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
Use [markmap-lib](https://markmap.js.org/) in command-line.
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Usage
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
$ yarn global add markmap-cli
|
|
13
|
-
# or
|
|
14
|
-
$ npm install -g markmap-cli
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
You can also use with `npx` without installation:
|
|
18
|
-
|
|
19
|
-
```sh
|
|
20
|
-
$ npx markmap-cli
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Command-line Usage
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
Usage: markmap [options] <input>
|
|
27
|
-
|
|
28
|
-
Create a markmap from a Markdown input file
|
|
29
|
-
|
|
30
|
-
Options:
|
|
31
|
-
-V, --version output the version number
|
|
32
|
-
--no-open do not open the output file after generation
|
|
33
|
-
--no-toolbar do not show toolbar
|
|
34
|
-
-o, --output <output> specify filename of the output HTML
|
|
35
|
-
-w, --watch watch the input file and update output on the fly, note that this feature is for development only
|
|
36
|
-
-h, --help display help for command
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### Creating a markmap
|
|
40
|
-
|
|
41
|
-
Suppose we have a Markdown file named `note.md`.
|
|
42
|
-
|
|
43
|
-
Run the following command to get an interactive mindmap:
|
|
44
|
-
|
|
45
|
-
```sh
|
|
46
|
-
$ markmap note.md
|
|
47
|
-
|
|
48
|
-
# without global installation
|
|
49
|
-
$ npx markmap-lib note.md
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
Then we get `note.html` in the same directory, and hopefully it will be open in your default browser.
|
|
53
|
-
|
|
54
|
-
### Watching changes
|
|
55
|
-
|
|
56
|
-
Enable watching mode by `-w`:
|
|
57
|
-
|
|
58
|
-
```sh
|
|
59
|
-
$ markmap -w note.md
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
A markmap will be created and opened in your browser, and will be updated as soon as changes are saved to the source file.
|
|
11
|
+
See [the documentation](https://markmap.js.org/docs/packages--markmap-cli).
|
package/dist/dev-server.d.ts
CHANGED
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
import { IDevelopOptions } from './
|
|
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 {};
|
package/dist/fetch-assets.d.ts
CHANGED
|
@@ -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 {
|
|
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
|
|
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,14 +1,14 @@
|
|
|
1
1
|
import { readFile, stat, mkdir, writeFile } from "fs/promises";
|
|
2
|
-
import {
|
|
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
|
|
9
|
+
import { Transformer } from "markmap-lib";
|
|
10
10
|
export * from "markmap-lib";
|
|
11
|
-
import {
|
|
11
|
+
import { fillTemplate, baseJsPaths } from "markmap-render";
|
|
12
12
|
import { serve } from "@hono/node-server";
|
|
13
13
|
import chokidar from "chokidar";
|
|
14
14
|
import { EventEmitter } from "events";
|
|
@@ -16,7 +16,8 @@ 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
|
|
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);
|
|
@@ -283,9 +279,7 @@ function startServer(paddingBottom) {
|
|
|
283
279
|
return best;
|
|
284
280
|
function dfs(node) {
|
|
285
281
|
var _a, _b, _c;
|
|
286
|
-
const
|
|
287
|
-
const start = +lines[0];
|
|
288
|
-
const end = +lines[1];
|
|
282
|
+
const [start, end] = ((_b = (_a = node.payload) == null ? void 0 : _a.lines) == null ? void 0 : _b.split(",").map((s) => +s)) || [];
|
|
289
283
|
if (start >= 0 && start <= lineWithoutFrontmatter && lineWithoutFrontmatter < end) {
|
|
290
284
|
best = node;
|
|
291
285
|
}
|
|
@@ -297,10 +291,9 @@ async function setUpServer(transformer, provider, options) {
|
|
|
297
291
|
let assets = transformer.getAssets();
|
|
298
292
|
if (options.toolbar)
|
|
299
293
|
assets = addToolbar(transformer.urlBuilder, assets);
|
|
300
|
-
const html = `${
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
)}<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>`;
|
|
304
297
|
const app = new Hono();
|
|
305
298
|
app.get("/", (c) => c.html(html));
|
|
306
299
|
app.get("/~data", async (c) => {
|
|
@@ -314,7 +307,7 @@ async function setUpServer(transformer, provider, options) {
|
|
|
314
307
|
await ((_a = provider[cmd]) == null ? void 0 : _a.call(provider, ...args));
|
|
315
308
|
return c.body(null, 204);
|
|
316
309
|
});
|
|
317
|
-
const assetsDir =
|
|
310
|
+
const { assetsDir } = config;
|
|
318
311
|
app.get(`${ASSETS_PREFIX}*`, async (c) => {
|
|
319
312
|
const relpath = c.req.path.slice(ASSETS_PREFIX.length);
|
|
320
313
|
const realpath = join(assetsDir, relpath);
|
|
@@ -369,7 +362,7 @@ async function develop(fileName, options) {
|
|
|
369
362
|
return setUpServer(transformer, provider, options);
|
|
370
363
|
}
|
|
371
364
|
const providerName = "local-hook";
|
|
372
|
-
async function fetchAssets() {
|
|
365
|
+
async function fetchAssets(assetsDir = config.assetsDir) {
|
|
373
366
|
var _a, _b;
|
|
374
367
|
const transformer = new Transformer();
|
|
375
368
|
const { provider } = transformer.urlBuilder;
|
|
@@ -388,7 +381,6 @@ async function fetchAssets() {
|
|
|
388
381
|
)) || []
|
|
389
382
|
].filter((url) => url.startsWith(ASSETS_PREFIX)).map((url) => url.slice(ASSETS_PREFIX.length));
|
|
390
383
|
const paths = [...baseJsPaths, ...pluginPaths];
|
|
391
|
-
const assetsDir = await assetsDirPromise;
|
|
392
384
|
const fastest = await transformer.urlBuilder.getFastestProvider();
|
|
393
385
|
await Promise.all(
|
|
394
386
|
paths.map(
|
|
@@ -419,8 +411,7 @@ async function downloadAsset(fullPath, url) {
|
|
|
419
411
|
async function loadFile(path) {
|
|
420
412
|
if (path.startsWith(ASSETS_PREFIX)) {
|
|
421
413
|
const relpath = path.slice(ASSETS_PREFIX.length);
|
|
422
|
-
|
|
423
|
-
return readFile(resolve(assetsDir, relpath), "utf8");
|
|
414
|
+
return readFile(resolve(config.assetsDir, relpath), "utf8");
|
|
424
415
|
}
|
|
425
416
|
const res = await fetch(path);
|
|
426
417
|
if (!res.ok)
|
|
@@ -481,9 +472,10 @@ async function createMarkmap(options) {
|
|
|
481
472
|
if (options.offline) {
|
|
482
473
|
assets = await inlineAssets(assets);
|
|
483
474
|
}
|
|
484
|
-
const html =
|
|
475
|
+
const html = fillTemplate(root, assets, {
|
|
485
476
|
baseJs: [],
|
|
486
|
-
jsonOptions: frontmatter == null ? void 0 : frontmatter.markmap
|
|
477
|
+
jsonOptions: frontmatter == null ? void 0 : frontmatter.markmap,
|
|
478
|
+
urlBuilder: transformer.urlBuilder
|
|
487
479
|
});
|
|
488
480
|
const output = options.output || "markmap.html";
|
|
489
481
|
await writeFile(output, html, "utf8");
|
|
@@ -533,6 +525,7 @@ async function main() {
|
|
|
533
525
|
program.parse(process.argv);
|
|
534
526
|
}
|
|
535
527
|
export {
|
|
528
|
+
config,
|
|
536
529
|
createMarkmap,
|
|
537
530
|
develop,
|
|
538
531
|
fetchAssets,
|
package/dist/types.d.ts
ADDED
|
@@ -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.
|
|
3
|
+
"version": "0.16.1",
|
|
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.
|
|
51
|
-
"markmap-lib": "0.
|
|
52
|
-
"markmap-
|
|
51
|
+
"markmap-common": "0.16.0",
|
|
52
|
+
"markmap-lib": "0.16.1",
|
|
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": "
|
|
60
|
+
"gitHead": "f10ad62ef03e02a1843484cca51521f48989fab7"
|
|
59
61
|
}
|