markmap-cli 0.14.5-alpha.13 → 0.14.5-alpha.16
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 +88 -21
- package/package.json +11 -9
- package/types/util.d.ts +8 -7
package/dist/index.js
CHANGED
|
@@ -1,19 +1,35 @@
|
|
|
1
|
-
/*! markmap-cli v0.14.5-alpha.
|
|
1
|
+
/*! markmap-cli v0.14.5-alpha.16+33e8294 | MIT License */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var fs = require('fs');
|
|
5
5
|
var commander = require('commander');
|
|
6
6
|
var open = require('open');
|
|
7
|
-
var markmapLib = require('markmap-lib');
|
|
8
7
|
var markmapCommon = require('markmap-common');
|
|
8
|
+
var markmapLib = require('markmap-lib');
|
|
9
|
+
var path = require('path');
|
|
9
10
|
var events = require('events');
|
|
10
11
|
var http = require('http');
|
|
11
12
|
var Koa = require('koa');
|
|
12
13
|
var chokidar = require('chokidar');
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
function _extends() {
|
|
16
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
17
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
18
|
+
var source = arguments[i];
|
|
19
|
+
for (var key in source) {
|
|
20
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
21
|
+
target[key] = source[key];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return target;
|
|
26
|
+
};
|
|
27
|
+
return _extends.apply(this, arguments);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const TOOLBAR_VERSION = "0.14.5-alpha.16+33e8294";
|
|
31
|
+
const TOOLBAR_CSS = `markmap-toolbar@${TOOLBAR_VERSION}/dist/style.css`;
|
|
32
|
+
const TOOLBAR_JS = `markmap-toolbar@${TOOLBAR_VERSION}/dist/index.js`;
|
|
17
33
|
const renderToolbar = () => {
|
|
18
34
|
const {
|
|
19
35
|
markmap,
|
|
@@ -27,8 +43,8 @@ const renderToolbar = () => {
|
|
|
27
43
|
};
|
|
28
44
|
function addToolbar(assets) {
|
|
29
45
|
return {
|
|
30
|
-
styles: [...(assets.styles || []), ...[TOOLBAR_CSS].map(markmapCommon.buildCSSItem)],
|
|
31
|
-
scripts: [...(assets.scripts || []), ...[TOOLBAR_JS].map(markmapCommon.buildJSItem), {
|
|
46
|
+
styles: [...(assets.styles || []), ...[TOOLBAR_CSS].map(path => markmapCommon.buildCSSItem(path))],
|
|
47
|
+
scripts: [...(assets.scripts || []), ...[TOOLBAR_JS].map(path => markmapCommon.buildJSItem(path)), {
|
|
32
48
|
type: 'iife',
|
|
33
49
|
data: {
|
|
34
50
|
fn: r => {
|
|
@@ -39,21 +55,18 @@ function addToolbar(assets) {
|
|
|
39
55
|
}]
|
|
40
56
|
};
|
|
41
57
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
}
|
|
58
|
+
function localProvider(path) {
|
|
59
|
+
const parts = path.split('/');
|
|
60
|
+
parts[0] = parts[0].replace(/@[\d.]+$/, '');
|
|
61
|
+
path = parts.join('/');
|
|
62
|
+
return `/node_modules/${path}`;
|
|
49
63
|
}
|
|
50
64
|
|
|
51
|
-
/* eslint-disable max-classes-per-file */
|
|
52
65
|
function sequence(fn) {
|
|
53
66
|
let promise;
|
|
54
67
|
return () => {
|
|
55
68
|
promise || (promise = fn().finally(() => {
|
|
56
|
-
promise =
|
|
69
|
+
promise = undefined;
|
|
57
70
|
}));
|
|
58
71
|
return promise;
|
|
59
72
|
};
|
|
@@ -63,6 +76,8 @@ class BufferContentProvider {
|
|
|
63
76
|
this.deferredSet = new Set();
|
|
64
77
|
this.events = new events.EventEmitter();
|
|
65
78
|
this.ts = 0;
|
|
79
|
+
this.content = '';
|
|
80
|
+
this.line = -1;
|
|
66
81
|
this.events.on('content', () => {
|
|
67
82
|
this.feed({
|
|
68
83
|
ts: this.ts,
|
|
@@ -76,7 +91,7 @@ class BufferContentProvider {
|
|
|
76
91
|
});
|
|
77
92
|
}
|
|
78
93
|
async getUpdate(ts, timeout = 10000) {
|
|
79
|
-
const deferred =
|
|
94
|
+
const deferred = markmapCommon.defer();
|
|
80
95
|
this.deferredSet.add(deferred);
|
|
81
96
|
setTimeout(() => {
|
|
82
97
|
this.feed({}, deferred);
|
|
@@ -169,6 +184,17 @@ function setUpServer(transformer, provider, options) {
|
|
|
169
184
|
line: update.line
|
|
170
185
|
};
|
|
171
186
|
} else {
|
|
187
|
+
if (ctx.path.startsWith('/node_modules/')) {
|
|
188
|
+
const relpath = ctx.path.slice(14);
|
|
189
|
+
try {
|
|
190
|
+
const realpath = require.resolve(relpath);
|
|
191
|
+
ctx.type = path.extname(relpath);
|
|
192
|
+
ctx.body = fs.createReadStream(realpath);
|
|
193
|
+
return;
|
|
194
|
+
} catch (_unused) {
|
|
195
|
+
// ignore
|
|
196
|
+
}
|
|
197
|
+
}
|
|
172
198
|
await next();
|
|
173
199
|
}
|
|
174
200
|
});
|
|
@@ -195,12 +221,42 @@ function setUpServer(transformer, provider, options) {
|
|
|
195
221
|
};
|
|
196
222
|
}
|
|
197
223
|
async function develop(fileName, options) {
|
|
224
|
+
markmapCommon.setProvider('local', localProvider);
|
|
198
225
|
const transformer = new markmapLib.Transformer();
|
|
199
226
|
const provider = fileName ? new FileSystemProvider(fileName) : new BufferContentProvider();
|
|
200
227
|
return setUpServer(transformer, provider, options);
|
|
201
228
|
}
|
|
202
229
|
|
|
230
|
+
async function loadFile(path) {
|
|
231
|
+
if (path.startsWith('/node_modules/')) {
|
|
232
|
+
const relpath = path.slice(14);
|
|
233
|
+
return fs.promises.readFile(require.resolve(relpath), 'utf8');
|
|
234
|
+
}
|
|
235
|
+
const res = await fetch(path);
|
|
236
|
+
if (!res.ok) throw res;
|
|
237
|
+
return res.text();
|
|
238
|
+
}
|
|
239
|
+
async function inlineAssets(assets) {
|
|
240
|
+
const [scripts, styles] = await Promise.all([Promise.all((assets.scripts || []).map(async item => item.type === 'script' && item.data.src ? {
|
|
241
|
+
type: 'script',
|
|
242
|
+
data: {
|
|
243
|
+
textContent: await loadFile(item.data.src)
|
|
244
|
+
}
|
|
245
|
+
} : item)), Promise.all((assets.styles || []).map(async item => item.type === 'stylesheet' ? {
|
|
246
|
+
type: 'style',
|
|
247
|
+
data: await loadFile(item.data.href)
|
|
248
|
+
} : item))]);
|
|
249
|
+
return {
|
|
250
|
+
scripts,
|
|
251
|
+
styles
|
|
252
|
+
};
|
|
253
|
+
}
|
|
203
254
|
async function createMarkmap(options) {
|
|
255
|
+
if (options.offline) {
|
|
256
|
+
markmapCommon.setProvider('local', localProvider);
|
|
257
|
+
} else {
|
|
258
|
+
await markmapCommon.findFastestProvider();
|
|
259
|
+
}
|
|
204
260
|
const transformer = new markmapLib.Transformer();
|
|
205
261
|
const {
|
|
206
262
|
root,
|
|
@@ -208,8 +264,17 @@ async function createMarkmap(options) {
|
|
|
208
264
|
frontmatter
|
|
209
265
|
} = transformer.transform(options.content || '');
|
|
210
266
|
let assets = transformer.getUsedAssets(features);
|
|
211
|
-
|
|
267
|
+
assets = _extends({}, assets, {
|
|
268
|
+
scripts: [...markmapLib.baseJsPaths.map(path => markmapCommon.buildJSItem(path)), ...(assets.scripts || [])]
|
|
269
|
+
});
|
|
270
|
+
if (options.toolbar) {
|
|
271
|
+
assets = addToolbar(assets);
|
|
272
|
+
}
|
|
273
|
+
if (options.offline) {
|
|
274
|
+
assets = await inlineAssets(assets);
|
|
275
|
+
}
|
|
212
276
|
const html = markmapLib.fillTemplate(root, assets, {
|
|
277
|
+
baseJs: [],
|
|
213
278
|
jsonOptions: frontmatter == null ? void 0 : frontmatter.markmap
|
|
214
279
|
});
|
|
215
280
|
const output = options.output || 'markmap.html';
|
|
@@ -218,20 +283,22 @@ async function createMarkmap(options) {
|
|
|
218
283
|
}
|
|
219
284
|
function main(version) {
|
|
220
285
|
const program = new commander.Command();
|
|
221
|
-
program.version(version).description('Create a markmap from a Markdown input file').arguments('<input>').option('--no-open', 'do not open the output file after generation').option('--no-toolbar', 'do not show toolbar').option('-o, --output <output>', 'specify filename of the output HTML').option('-w, --watch', 'watch the input file and update output on the fly, note that this feature is for development only').action(async (input, cmd) => {
|
|
286
|
+
program.version(version).description('Create a markmap from a Markdown input file').arguments('<input>').option('--no-open', 'do not open the output file after generation').option('--no-toolbar', 'do not show toolbar').option('-o, --output <output>', 'specify filename of the output HTML').option('--offline', 'Inline all assets to allow the generated HTML to work offline').option('-w, --watch', 'watch the input file and update output on the fly, note that this feature is for development only').action(async (input, cmd) => {
|
|
222
287
|
const content = await fs.promises.readFile(input, 'utf8');
|
|
223
288
|
const output = cmd.output || `${input.replace(/\.\w*$/, '')}.html`;
|
|
224
289
|
if (cmd.watch) {
|
|
225
290
|
await develop(input, {
|
|
226
291
|
open: cmd.open,
|
|
227
|
-
toolbar: cmd.toolbar
|
|
292
|
+
toolbar: cmd.toolbar,
|
|
293
|
+
offline: true
|
|
228
294
|
});
|
|
229
295
|
} else {
|
|
230
296
|
await createMarkmap({
|
|
231
297
|
content,
|
|
232
298
|
output,
|
|
233
299
|
open: cmd.open,
|
|
234
|
-
toolbar: cmd.toolbar
|
|
300
|
+
toolbar: cmd.toolbar,
|
|
301
|
+
offline: cmd.offline
|
|
235
302
|
});
|
|
236
303
|
}
|
|
237
304
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markmap-cli",
|
|
3
|
-
"version": "0.14.5-alpha.
|
|
3
|
+
"version": "0.14.5-alpha.16+33e8294",
|
|
4
4
|
"description": "Create markmaps from CLI",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,15 +41,17 @@
|
|
|
41
41
|
"@babel/runtime": "^7.13.10",
|
|
42
42
|
"chokidar": "^3.5.1",
|
|
43
43
|
"commander": "^7.1.0",
|
|
44
|
+
"d3": "^6.2.0",
|
|
45
|
+
"katex": "^0.16.0",
|
|
44
46
|
"koa": "^2.13.1",
|
|
45
|
-
"markmap-common": "0.14.5-alpha.
|
|
46
|
-
"markmap-lib": "0.14.5-alpha.
|
|
47
|
+
"markmap-common": "0.14.5-alpha.16+33e8294",
|
|
48
|
+
"markmap-lib": "0.14.5-alpha.16+33e8294",
|
|
49
|
+
"markmap-toolbar": "0.14.5-alpha.16+33e8294",
|
|
50
|
+
"markmap-view": "0.14.5-alpha.16+33e8294",
|
|
47
51
|
"open": "^8.0.3",
|
|
48
|
-
"
|
|
52
|
+
"prismjs": "^1.28.0",
|
|
53
|
+
"update-notifier": "^5.1.0",
|
|
54
|
+
"webfontloader": "^1.6.28"
|
|
49
55
|
},
|
|
50
|
-
"
|
|
51
|
-
"markmap-toolbar": "0.14.5-alpha.13+50ca560",
|
|
52
|
-
"markmap-view": "0.14.5-alpha.13+50ca560"
|
|
53
|
-
},
|
|
54
|
-
"gitHead": "50ca5603019498f93dba6485c96d0a5630b221e5"
|
|
56
|
+
"gitHead": "33e8294050d7438f6cdadd5bf06a665560585195"
|
|
55
57
|
}
|
package/types/util.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { IAssets } from 'markmap-lib';
|
|
2
2
|
export interface IDevelopOptions {
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Whether to open the generated markmap in browser
|
|
5
5
|
*/
|
|
6
6
|
open: boolean;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Whether to show the default toolbar
|
|
9
9
|
*/
|
|
10
10
|
toolbar: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether to inline all assets to make the HTML work offline.
|
|
13
|
+
* Ignored in watching mode.
|
|
14
|
+
*/
|
|
15
|
+
offline: boolean;
|
|
11
16
|
}
|
|
12
17
|
export declare function addToolbar(assets: IAssets): IAssets;
|
|
13
|
-
export declare
|
|
14
|
-
resolve: (value: T) => void;
|
|
15
|
-
reject: (err: Error) => void;
|
|
16
|
-
promise: Promise<unknown>;
|
|
17
|
-
}
|
|
18
|
+
export declare function localProvider(path: string): string;
|