markmap-cli 0.14.4-alpha.1 → 0.14.5-alpha.13
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 +24 -68
- package/package.json +9 -10
- package/types/index.d.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
/*! markmap-cli v0.14.
|
|
1
|
+
/*! markmap-cli v0.14.5-alpha.13+50ca560 | 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
7
|
var markmapLib = require('markmap-lib');
|
|
8
|
+
var markmapCommon = require('markmap-common');
|
|
8
9
|
var events = require('events');
|
|
9
10
|
var http = require('http');
|
|
10
11
|
var Koa = require('koa');
|
|
11
12
|
var chokidar = require('chokidar');
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
|
|
17
|
-
var Koa__default = /*#__PURE__*/_interopDefaultLegacy(Koa);
|
|
18
|
-
var chokidar__default = /*#__PURE__*/_interopDefaultLegacy(chokidar);
|
|
19
|
-
|
|
20
|
-
const TOOLBAR_VERSION = "0.14.4-alpha.1+8a57fea";
|
|
21
|
-
const TOOLBAR_CSS = `npm/markmap-toolbar@${TOOLBAR_VERSION}/dist/style.min.css`;
|
|
22
|
-
const TOOLBAR_JS = `npm/markmap-toolbar@${TOOLBAR_VERSION}/dist/index.umd.min.js`;
|
|
23
|
-
|
|
14
|
+
const TOOLBAR_VERSION = "0.14.5-alpha.13+50ca560";
|
|
15
|
+
const TOOLBAR_CSS = `markmap-toolbar@${TOOLBAR_VERSION}/dist/style.min.css`;
|
|
16
|
+
const TOOLBAR_JS = `markmap-toolbar@${TOOLBAR_VERSION}/dist/index.umd.min.js`;
|
|
24
17
|
const renderToolbar = () => {
|
|
25
18
|
const {
|
|
26
19
|
markmap,
|
|
@@ -32,21 +25,10 @@ const renderToolbar = () => {
|
|
|
32
25
|
el.setAttribute('style', 'position:absolute;bottom:20px;right:20px');
|
|
33
26
|
document.body.append(el);
|
|
34
27
|
};
|
|
35
|
-
|
|
36
28
|
function addToolbar(assets) {
|
|
37
29
|
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
|
-
}, {
|
|
30
|
+
styles: [...(assets.styles || []), ...[TOOLBAR_CSS].map(markmapCommon.buildCSSItem)],
|
|
31
|
+
scripts: [...(assets.scripts || []), ...[TOOLBAR_JS].map(markmapCommon.buildJSItem), {
|
|
50
32
|
type: 'iife',
|
|
51
33
|
data: {
|
|
52
34
|
fn: r => {
|
|
@@ -64,25 +46,18 @@ class Defer {
|
|
|
64
46
|
this.reject = reject;
|
|
65
47
|
});
|
|
66
48
|
}
|
|
67
|
-
|
|
68
49
|
}
|
|
69
50
|
|
|
70
51
|
/* eslint-disable max-classes-per-file */
|
|
71
|
-
|
|
72
|
-
function consecutive(fn) {
|
|
52
|
+
function sequence(fn) {
|
|
73
53
|
let promise;
|
|
74
54
|
return () => {
|
|
75
|
-
|
|
76
|
-
promise =
|
|
77
|
-
|
|
78
|
-
promise = null;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
55
|
+
promise || (promise = fn().finally(() => {
|
|
56
|
+
promise = null;
|
|
57
|
+
}));
|
|
82
58
|
return promise;
|
|
83
59
|
};
|
|
84
60
|
}
|
|
85
|
-
|
|
86
61
|
class BufferContentProvider {
|
|
87
62
|
constructor() {
|
|
88
63
|
this.deferredSet = new Set();
|
|
@@ -100,24 +75,20 @@ class BufferContentProvider {
|
|
|
100
75
|
});
|
|
101
76
|
});
|
|
102
77
|
}
|
|
103
|
-
|
|
104
78
|
async getUpdate(ts, timeout = 10000) {
|
|
105
79
|
const deferred = new Defer();
|
|
106
80
|
this.deferredSet.add(deferred);
|
|
107
81
|
setTimeout(() => {
|
|
108
82
|
this.feed({}, deferred);
|
|
109
83
|
}, timeout);
|
|
110
|
-
|
|
111
84
|
if (ts < this.ts) {
|
|
112
85
|
this.feed({
|
|
113
86
|
ts: this.ts,
|
|
114
87
|
content: this.content
|
|
115
88
|
}, deferred);
|
|
116
89
|
}
|
|
117
|
-
|
|
118
90
|
return deferred.promise;
|
|
119
91
|
}
|
|
120
|
-
|
|
121
92
|
feed(data, deferred) {
|
|
122
93
|
if (deferred) {
|
|
123
94
|
deferred.resolve(data);
|
|
@@ -126,45 +97,37 @@ class BufferContentProvider {
|
|
|
126
97
|
for (const d of this.deferredSet) {
|
|
127
98
|
d.resolve(data);
|
|
128
99
|
}
|
|
129
|
-
|
|
130
100
|
this.deferredSet.clear();
|
|
131
101
|
}
|
|
132
102
|
}
|
|
133
|
-
|
|
134
103
|
setCursor(line) {
|
|
135
104
|
this.line = line;
|
|
136
105
|
this.events.emit('cursor');
|
|
137
106
|
}
|
|
138
|
-
|
|
139
107
|
setContent(content) {
|
|
140
108
|
this.ts = Date.now();
|
|
141
109
|
this.content = content;
|
|
142
110
|
this.events.emit('content');
|
|
143
111
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
112
|
+
dispose() {
|
|
113
|
+
/* noop */
|
|
114
|
+
}
|
|
147
115
|
}
|
|
148
|
-
|
|
149
116
|
class FileSystemProvider extends BufferContentProvider {
|
|
150
117
|
constructor(fileName) {
|
|
151
118
|
super();
|
|
152
119
|
this.fileName = fileName;
|
|
153
|
-
this.watcher =
|
|
120
|
+
this.watcher = chokidar.watch(fileName).on('all', sequence(() => this.update()));
|
|
154
121
|
}
|
|
155
|
-
|
|
156
122
|
async update() {
|
|
157
123
|
const content = await fs.promises.readFile(this.fileName, 'utf8');
|
|
158
124
|
this.setContent(content);
|
|
159
125
|
}
|
|
160
|
-
|
|
161
126
|
dispose() {
|
|
162
127
|
super.dispose();
|
|
163
128
|
this.watcher.close();
|
|
164
129
|
}
|
|
165
|
-
|
|
166
130
|
}
|
|
167
|
-
|
|
168
131
|
function startServer(paddingBottom) {
|
|
169
132
|
let ts = 0;
|
|
170
133
|
const {
|
|
@@ -172,30 +135,28 @@ function startServer(paddingBottom) {
|
|
|
172
135
|
markmap
|
|
173
136
|
} = window;
|
|
174
137
|
refresh();
|
|
175
|
-
|
|
176
138
|
function refresh() {
|
|
177
139
|
fetch(`/data?ts=${ts}`).then(res => res.json()).then(res => {
|
|
178
140
|
if (res.ts && res.ts > ts && res.result) {
|
|
179
141
|
const {
|
|
180
142
|
root,
|
|
181
|
-
frontmatter
|
|
143
|
+
frontmatter,
|
|
144
|
+
contentLineOffset
|
|
182
145
|
} = res.result;
|
|
183
146
|
mm.setOptions(markmap.deriveOptions(frontmatter == null ? void 0 : frontmatter.markmap));
|
|
184
147
|
mm.setData(root);
|
|
185
148
|
if (!ts) mm.fit();
|
|
186
149
|
ts = res.ts;
|
|
187
150
|
}
|
|
188
|
-
|
|
189
151
|
setTimeout(refresh, 300);
|
|
190
152
|
});
|
|
191
153
|
}
|
|
192
154
|
}
|
|
193
|
-
|
|
194
155
|
function setUpServer(transformer, provider, options) {
|
|
195
156
|
let assets = transformer.getAssets();
|
|
196
157
|
if (options.toolbar) assets = addToolbar(assets);
|
|
197
158
|
const html = `${markmapLib.fillTemplate(null, assets)}<script>(${startServer.toString()})(${options.toolbar ? 60 : 0})</script>`;
|
|
198
|
-
const app = new
|
|
159
|
+
const app = new Koa();
|
|
199
160
|
app.use(async (ctx, next) => {
|
|
200
161
|
if (ctx.path === '/') {
|
|
201
162
|
ctx.body = html;
|
|
@@ -212,31 +173,27 @@ function setUpServer(transformer, provider, options) {
|
|
|
212
173
|
}
|
|
213
174
|
});
|
|
214
175
|
const handle = app.callback();
|
|
215
|
-
const server =
|
|
176
|
+
const server = http.createServer(handle);
|
|
216
177
|
server.listen(() => {
|
|
217
178
|
const {
|
|
218
179
|
port
|
|
219
180
|
} = server.address();
|
|
220
181
|
console.info(`Listening at http://localhost:${port}`);
|
|
221
|
-
if (options.open)
|
|
182
|
+
if (options.open) open(`http://localhost:${port}`);
|
|
222
183
|
});
|
|
223
184
|
let closing;
|
|
224
185
|
return {
|
|
225
186
|
provider,
|
|
226
|
-
|
|
227
187
|
close() {
|
|
228
188
|
if (!closing) {
|
|
229
189
|
closing = new Promise((resolve, reject) => server.close(err => {
|
|
230
190
|
if (err) reject(err);else resolve();
|
|
231
191
|
}));
|
|
232
192
|
}
|
|
233
|
-
|
|
234
193
|
return closing;
|
|
235
194
|
}
|
|
236
|
-
|
|
237
195
|
};
|
|
238
196
|
}
|
|
239
|
-
|
|
240
197
|
async function develop(fileName, options) {
|
|
241
198
|
const transformer = new markmapLib.Transformer();
|
|
242
199
|
const provider = fileName ? new FileSystemProvider(fileName) : new BufferContentProvider();
|
|
@@ -257,14 +214,13 @@ async function createMarkmap(options) {
|
|
|
257
214
|
});
|
|
258
215
|
const output = options.output || 'markmap.html';
|
|
259
216
|
await fs.promises.writeFile(output, html, 'utf8');
|
|
260
|
-
if (options.open)
|
|
217
|
+
if (options.open) open(output);
|
|
261
218
|
}
|
|
262
219
|
function main(version) {
|
|
263
220
|
const program = new commander.Command();
|
|
264
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) => {
|
|
265
222
|
const content = await fs.promises.readFile(input, 'utf8');
|
|
266
223
|
const output = cmd.output || `${input.replace(/\.\w*$/, '')}.html`;
|
|
267
|
-
|
|
268
224
|
if (cmd.watch) {
|
|
269
225
|
await develop(input, {
|
|
270
226
|
open: cmd.open,
|
|
@@ -285,6 +241,6 @@ function main(version) {
|
|
|
285
241
|
exports.createMarkmap = createMarkmap;
|
|
286
242
|
exports.develop = develop;
|
|
287
243
|
exports.main = main;
|
|
288
|
-
|
|
289
|
-
if (k !== 'default' && !
|
|
290
|
-
}
|
|
244
|
+
Object.keys(markmapLib).forEach(function (k) {
|
|
245
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = markmapLib[k];
|
|
246
|
+
});
|
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.13+50ca560",
|
|
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": [
|
|
@@ -42,15 +42,14 @@
|
|
|
42
42
|
"chokidar": "^3.5.1",
|
|
43
43
|
"commander": "^7.1.0",
|
|
44
44
|
"koa": "^2.13.1",
|
|
45
|
-
"markmap-
|
|
45
|
+
"markmap-common": "0.14.5-alpha.13+50ca560",
|
|
46
|
+
"markmap-lib": "0.14.5-alpha.13+50ca560",
|
|
46
47
|
"open": "^8.0.3",
|
|
47
48
|
"update-notifier": "^5.1.0"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
|
-
"markmap-
|
|
51
|
+
"markmap-toolbar": "0.14.5-alpha.13+50ca560",
|
|
52
|
+
"markmap-view": "0.14.5-alpha.13+50ca560"
|
|
51
53
|
},
|
|
52
|
-
"
|
|
53
|
-
"node": ">=10"
|
|
54
|
-
},
|
|
55
|
-
"gitHead": "8a57fea7292bee5c50dc0594553d5da62e46d9f8"
|
|
54
|
+
"gitHead": "50ca5603019498f93dba6485c96d0a5630b221e5"
|
|
56
55
|
}
|
package/types/index.d.ts
CHANGED