markmap-cli 0.14.4 → 0.14.5-alpha.15
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 +101 -71
- package/package.json +14 -14
- package/types/index.d.ts +1 -1
- package/types/util.d.ts +8 -2
package/dist/index.js
CHANGED
|
@@ -1,26 +1,35 @@
|
|
|
1
|
-
/*! markmap-cli v0.14.
|
|
1
|
+
/*! markmap-cli v0.14.5-alpha.15+1fe26c8 | 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 markmapCommon = require('markmap-common');
|
|
7
8
|
var markmapLib = require('markmap-lib');
|
|
9
|
+
var path = require('path');
|
|
8
10
|
var events = require('events');
|
|
9
11
|
var http = require('http');
|
|
10
12
|
var Koa = require('koa');
|
|
11
13
|
var chokidar = require('chokidar');
|
|
12
14
|
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
+
}
|
|
23
29
|
|
|
30
|
+
const TOOLBAR_VERSION = "0.14.5-alpha.15+1fe26c8";
|
|
31
|
+
const TOOLBAR_CSS = `markmap-toolbar@${TOOLBAR_VERSION}/dist/style.css`;
|
|
32
|
+
const TOOLBAR_JS = `markmap-toolbar@${TOOLBAR_VERSION}/dist/index.js`;
|
|
24
33
|
const renderToolbar = () => {
|
|
25
34
|
const {
|
|
26
35
|
markmap,
|
|
@@ -32,21 +41,10 @@ const renderToolbar = () => {
|
|
|
32
41
|
el.setAttribute('style', 'position:absolute;bottom:20px;right:20px');
|
|
33
42
|
document.body.append(el);
|
|
34
43
|
};
|
|
35
|
-
|
|
36
44
|
function addToolbar(assets) {
|
|
37
45
|
return {
|
|
38
|
-
styles: [...(assets.styles || []),
|
|
39
|
-
|
|
40
|
-
data: {
|
|
41
|
-
href: `https://cdn.jsdelivr.net/${TOOLBAR_CSS}`
|
|
42
|
-
}
|
|
43
|
-
}],
|
|
44
|
-
scripts: [...(assets.scripts || []), {
|
|
45
|
-
type: 'script',
|
|
46
|
-
data: {
|
|
47
|
-
src: `https://cdn.jsdelivr.net/${TOOLBAR_JS}`
|
|
48
|
-
}
|
|
49
|
-
}, {
|
|
46
|
+
styles: [...(assets.styles || []), ...[TOOLBAR_CSS].map(path => markmapCommon.buildCSSItem(path))],
|
|
47
|
+
scripts: [...(assets.scripts || []), ...[TOOLBAR_JS].map(path => markmapCommon.buildJSItem(path)), {
|
|
50
48
|
type: 'iife',
|
|
51
49
|
data: {
|
|
52
50
|
fn: r => {
|
|
@@ -64,25 +62,24 @@ class Defer {
|
|
|
64
62
|
this.reject = reject;
|
|
65
63
|
});
|
|
66
64
|
}
|
|
67
|
-
|
|
65
|
+
}
|
|
66
|
+
function localProvider(path) {
|
|
67
|
+
const parts = path.split('/');
|
|
68
|
+
parts[0] = parts[0].replace(/@[\d.]+$/, '');
|
|
69
|
+
path = parts.join('/');
|
|
70
|
+
return `/node_modules/${path}`;
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
/* eslint-disable max-classes-per-file */
|
|
71
|
-
|
|
72
|
-
function consecutive(fn) {
|
|
74
|
+
function sequence(fn) {
|
|
73
75
|
let promise;
|
|
74
76
|
return () => {
|
|
75
|
-
|
|
76
|
-
promise =
|
|
77
|
-
|
|
78
|
-
promise = null;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
77
|
+
promise || (promise = fn().finally(() => {
|
|
78
|
+
promise = null;
|
|
79
|
+
}));
|
|
82
80
|
return promise;
|
|
83
81
|
};
|
|
84
82
|
}
|
|
85
|
-
|
|
86
83
|
class BufferContentProvider {
|
|
87
84
|
constructor() {
|
|
88
85
|
this.deferredSet = new Set();
|
|
@@ -100,24 +97,20 @@ class BufferContentProvider {
|
|
|
100
97
|
});
|
|
101
98
|
});
|
|
102
99
|
}
|
|
103
|
-
|
|
104
100
|
async getUpdate(ts, timeout = 10000) {
|
|
105
101
|
const deferred = new Defer();
|
|
106
102
|
this.deferredSet.add(deferred);
|
|
107
103
|
setTimeout(() => {
|
|
108
104
|
this.feed({}, deferred);
|
|
109
105
|
}, timeout);
|
|
110
|
-
|
|
111
106
|
if (ts < this.ts) {
|
|
112
107
|
this.feed({
|
|
113
108
|
ts: this.ts,
|
|
114
109
|
content: this.content
|
|
115
110
|
}, deferred);
|
|
116
111
|
}
|
|
117
|
-
|
|
118
112
|
return deferred.promise;
|
|
119
113
|
}
|
|
120
|
-
|
|
121
114
|
feed(data, deferred) {
|
|
122
115
|
if (deferred) {
|
|
123
116
|
deferred.resolve(data);
|
|
@@ -126,45 +119,37 @@ class BufferContentProvider {
|
|
|
126
119
|
for (const d of this.deferredSet) {
|
|
127
120
|
d.resolve(data);
|
|
128
121
|
}
|
|
129
|
-
|
|
130
122
|
this.deferredSet.clear();
|
|
131
123
|
}
|
|
132
124
|
}
|
|
133
|
-
|
|
134
125
|
setCursor(line) {
|
|
135
126
|
this.line = line;
|
|
136
127
|
this.events.emit('cursor');
|
|
137
128
|
}
|
|
138
|
-
|
|
139
129
|
setContent(content) {
|
|
140
130
|
this.ts = Date.now();
|
|
141
131
|
this.content = content;
|
|
142
132
|
this.events.emit('content');
|
|
143
133
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
134
|
+
dispose() {
|
|
135
|
+
/* noop */
|
|
136
|
+
}
|
|
147
137
|
}
|
|
148
|
-
|
|
149
138
|
class FileSystemProvider extends BufferContentProvider {
|
|
150
139
|
constructor(fileName) {
|
|
151
140
|
super();
|
|
152
141
|
this.fileName = fileName;
|
|
153
|
-
this.watcher =
|
|
142
|
+
this.watcher = chokidar.watch(fileName).on('all', sequence(() => this.update()));
|
|
154
143
|
}
|
|
155
|
-
|
|
156
144
|
async update() {
|
|
157
145
|
const content = await fs.promises.readFile(this.fileName, 'utf8');
|
|
158
146
|
this.setContent(content);
|
|
159
147
|
}
|
|
160
|
-
|
|
161
148
|
dispose() {
|
|
162
149
|
super.dispose();
|
|
163
150
|
this.watcher.close();
|
|
164
151
|
}
|
|
165
|
-
|
|
166
152
|
}
|
|
167
|
-
|
|
168
153
|
function startServer(paddingBottom) {
|
|
169
154
|
let ts = 0;
|
|
170
155
|
const {
|
|
@@ -172,30 +157,28 @@ function startServer(paddingBottom) {
|
|
|
172
157
|
markmap
|
|
173
158
|
} = window;
|
|
174
159
|
refresh();
|
|
175
|
-
|
|
176
160
|
function refresh() {
|
|
177
161
|
fetch(`/data?ts=${ts}`).then(res => res.json()).then(res => {
|
|
178
162
|
if (res.ts && res.ts > ts && res.result) {
|
|
179
163
|
const {
|
|
180
164
|
root,
|
|
181
|
-
frontmatter
|
|
165
|
+
frontmatter,
|
|
166
|
+
contentLineOffset
|
|
182
167
|
} = res.result;
|
|
183
168
|
mm.setOptions(markmap.deriveOptions(frontmatter == null ? void 0 : frontmatter.markmap));
|
|
184
169
|
mm.setData(root);
|
|
185
170
|
if (!ts) mm.fit();
|
|
186
171
|
ts = res.ts;
|
|
187
172
|
}
|
|
188
|
-
|
|
189
173
|
setTimeout(refresh, 300);
|
|
190
174
|
});
|
|
191
175
|
}
|
|
192
176
|
}
|
|
193
|
-
|
|
194
177
|
function setUpServer(transformer, provider, options) {
|
|
195
178
|
let assets = transformer.getAssets();
|
|
196
179
|
if (options.toolbar) assets = addToolbar(assets);
|
|
197
180
|
const html = `${markmapLib.fillTemplate(null, assets)}<script>(${startServer.toString()})(${options.toolbar ? 60 : 0})</script>`;
|
|
198
|
-
const app = new
|
|
181
|
+
const app = new Koa();
|
|
199
182
|
app.use(async (ctx, next) => {
|
|
200
183
|
if (ctx.path === '/') {
|
|
201
184
|
ctx.body = html;
|
|
@@ -208,42 +191,79 @@ function setUpServer(transformer, provider, options) {
|
|
|
208
191
|
line: update.line
|
|
209
192
|
};
|
|
210
193
|
} else {
|
|
194
|
+
if (ctx.path.startsWith('/node_modules/')) {
|
|
195
|
+
const relpath = ctx.path.slice(14);
|
|
196
|
+
try {
|
|
197
|
+
const realpath = require.resolve(relpath);
|
|
198
|
+
ctx.type = path.extname(relpath);
|
|
199
|
+
ctx.body = fs.createReadStream(realpath);
|
|
200
|
+
return;
|
|
201
|
+
} catch (_unused) {
|
|
202
|
+
// ignore
|
|
203
|
+
}
|
|
204
|
+
}
|
|
211
205
|
await next();
|
|
212
206
|
}
|
|
213
207
|
});
|
|
214
208
|
const handle = app.callback();
|
|
215
|
-
const server =
|
|
209
|
+
const server = http.createServer(handle);
|
|
216
210
|
server.listen(() => {
|
|
217
211
|
const {
|
|
218
212
|
port
|
|
219
213
|
} = server.address();
|
|
220
214
|
console.info(`Listening at http://localhost:${port}`);
|
|
221
|
-
if (options.open)
|
|
215
|
+
if (options.open) open(`http://localhost:${port}`);
|
|
222
216
|
});
|
|
223
217
|
let closing;
|
|
224
218
|
return {
|
|
225
219
|
provider,
|
|
226
|
-
|
|
227
220
|
close() {
|
|
228
221
|
if (!closing) {
|
|
229
222
|
closing = new Promise((resolve, reject) => server.close(err => {
|
|
230
223
|
if (err) reject(err);else resolve();
|
|
231
224
|
}));
|
|
232
225
|
}
|
|
233
|
-
|
|
234
226
|
return closing;
|
|
235
227
|
}
|
|
236
|
-
|
|
237
228
|
};
|
|
238
229
|
}
|
|
239
|
-
|
|
240
230
|
async function develop(fileName, options) {
|
|
231
|
+
markmapCommon.setProvider('local', localProvider);
|
|
241
232
|
const transformer = new markmapLib.Transformer();
|
|
242
233
|
const provider = fileName ? new FileSystemProvider(fileName) : new BufferContentProvider();
|
|
243
234
|
return setUpServer(transformer, provider, options);
|
|
244
235
|
}
|
|
245
236
|
|
|
237
|
+
async function loadFile(path) {
|
|
238
|
+
if (path.startsWith('/node_modules/')) {
|
|
239
|
+
const relpath = path.slice(14);
|
|
240
|
+
return fs.promises.readFile(require.resolve(relpath), 'utf8');
|
|
241
|
+
}
|
|
242
|
+
const res = await fetch(path);
|
|
243
|
+
if (!res.ok) throw res;
|
|
244
|
+
return res.text();
|
|
245
|
+
}
|
|
246
|
+
async function inlineAssets(assets) {
|
|
247
|
+
const [scripts, styles] = await Promise.all([Promise.all((assets.scripts || []).map(async item => item.type === 'script' && item.data.src ? {
|
|
248
|
+
type: 'script',
|
|
249
|
+
data: {
|
|
250
|
+
textContent: await loadFile(item.data.src)
|
|
251
|
+
}
|
|
252
|
+
} : item)), Promise.all((assets.styles || []).map(async item => item.type === 'stylesheet' ? {
|
|
253
|
+
type: 'style',
|
|
254
|
+
data: await loadFile(item.data.href)
|
|
255
|
+
} : item))]);
|
|
256
|
+
return {
|
|
257
|
+
scripts,
|
|
258
|
+
styles
|
|
259
|
+
};
|
|
260
|
+
}
|
|
246
261
|
async function createMarkmap(options) {
|
|
262
|
+
if (options.offline) {
|
|
263
|
+
markmapCommon.setProvider('local', localProvider);
|
|
264
|
+
} else {
|
|
265
|
+
await markmapCommon.findFastestProvider();
|
|
266
|
+
}
|
|
247
267
|
const transformer = new markmapLib.Transformer();
|
|
248
268
|
const {
|
|
249
269
|
root,
|
|
@@ -251,31 +271,41 @@ async function createMarkmap(options) {
|
|
|
251
271
|
frontmatter
|
|
252
272
|
} = transformer.transform(options.content || '');
|
|
253
273
|
let assets = transformer.getUsedAssets(features);
|
|
254
|
-
|
|
274
|
+
assets = _extends({}, assets, {
|
|
275
|
+
scripts: [...markmapLib.baseJsPaths.map(path => markmapCommon.buildJSItem(path)), ...(assets.scripts || [])]
|
|
276
|
+
});
|
|
277
|
+
if (options.toolbar) {
|
|
278
|
+
assets = addToolbar(assets);
|
|
279
|
+
}
|
|
280
|
+
if (options.offline) {
|
|
281
|
+
assets = await inlineAssets(assets);
|
|
282
|
+
}
|
|
255
283
|
const html = markmapLib.fillTemplate(root, assets, {
|
|
284
|
+
baseJs: [],
|
|
256
285
|
jsonOptions: frontmatter == null ? void 0 : frontmatter.markmap
|
|
257
286
|
});
|
|
258
287
|
const output = options.output || 'markmap.html';
|
|
259
288
|
await fs.promises.writeFile(output, html, 'utf8');
|
|
260
|
-
if (options.open)
|
|
289
|
+
if (options.open) open(output);
|
|
261
290
|
}
|
|
262
291
|
function main(version) {
|
|
263
292
|
const program = new commander.Command();
|
|
264
|
-
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) => {
|
|
293
|
+
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) => {
|
|
265
294
|
const content = await fs.promises.readFile(input, 'utf8');
|
|
266
295
|
const output = cmd.output || `${input.replace(/\.\w*$/, '')}.html`;
|
|
267
|
-
|
|
268
296
|
if (cmd.watch) {
|
|
269
297
|
await develop(input, {
|
|
270
298
|
open: cmd.open,
|
|
271
|
-
toolbar: cmd.toolbar
|
|
299
|
+
toolbar: cmd.toolbar,
|
|
300
|
+
offline: true
|
|
272
301
|
});
|
|
273
302
|
} else {
|
|
274
303
|
await createMarkmap({
|
|
275
304
|
content,
|
|
276
305
|
output,
|
|
277
306
|
open: cmd.open,
|
|
278
|
-
toolbar: cmd.toolbar
|
|
307
|
+
toolbar: cmd.toolbar,
|
|
308
|
+
offline: cmd.offline
|
|
279
309
|
});
|
|
280
310
|
}
|
|
281
311
|
});
|
|
@@ -285,6 +315,6 @@ function main(version) {
|
|
|
285
315
|
exports.createMarkmap = createMarkmap;
|
|
286
316
|
exports.develop = develop;
|
|
287
317
|
exports.main = main;
|
|
288
|
-
|
|
289
|
-
if (k !== 'default' && !
|
|
290
|
-
}
|
|
318
|
+
Object.keys(markmapLib).forEach(function (k) {
|
|
319
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = markmapLib[k];
|
|
320
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markmap-cli",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.5-alpha.15+1fe26c8",
|
|
4
4
|
"description": "Create markmaps from CLI",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
"markdown",
|
|
13
13
|
"mindmap"
|
|
14
14
|
],
|
|
15
|
-
"homepage": "https://github.com/
|
|
15
|
+
"homepage": "https://github.com/markmap/markmap/packages/markmap-cli#readme",
|
|
16
16
|
"publishConfig": {
|
|
17
17
|
"access": "public",
|
|
18
18
|
"registry": "https://registry.npmjs.org/"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": "git+https://github.com/
|
|
22
|
+
"url": "git+https://github.com/markmap/markmap.git"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"dev": "rollup -wc rollup.conf.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"build:js": "rollup -c rollup.conf.js"
|
|
29
29
|
},
|
|
30
30
|
"bugs": {
|
|
31
|
-
"url": "https://github.com/
|
|
31
|
+
"url": "https://github.com/markmap/markmap/issues"
|
|
32
32
|
},
|
|
33
33
|
"main": "dist/index.js",
|
|
34
34
|
"files": [
|
|
@@ -41,17 +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": "
|
|
46
|
-
"markmap-lib": "
|
|
47
|
+
"markmap-common": "0.14.5-alpha.15+1fe26c8",
|
|
48
|
+
"markmap-lib": "0.14.5-alpha.15+1fe26c8",
|
|
49
|
+
"markmap-toolbar": "0.14.5-alpha.15+1fe26c8",
|
|
50
|
+
"markmap-view": "0.14.5-alpha.15+1fe26c8",
|
|
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-view": "^0.14.4"
|
|
52
|
-
},
|
|
53
|
-
"engines": {
|
|
54
|
-
"node": ">=10"
|
|
55
|
-
},
|
|
56
|
-
"gitHead": "8eb2fa223ab85d1a7699d2c9660fdb5fac24acd1"
|
|
56
|
+
"gitHead": "1fe26c8234296e2188e466c7b9dbf3b7e171857d"
|
|
57
57
|
}
|
package/types/index.d.ts
CHANGED
package/types/util.d.ts
CHANGED
|
@@ -1,13 +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
18
|
export declare class Defer<T> {
|
|
@@ -15,3 +20,4 @@ export declare class Defer<T> {
|
|
|
15
20
|
reject: (err: Error) => void;
|
|
16
21
|
promise: Promise<unknown>;
|
|
17
22
|
}
|
|
23
|
+
export declare function localProvider(path: string): string;
|