markmap-cli 0.14.5-alpha.13 → 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 CHANGED
@@ -1,19 +1,35 @@
1
- /*! markmap-cli v0.14.5-alpha.13+50ca560 | MIT License */
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 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
- 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`;
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.15+1fe26c8";
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 => {
@@ -47,6 +63,12 @@ class Defer {
47
63
  });
48
64
  }
49
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}`;
71
+ }
50
72
 
51
73
  /* eslint-disable max-classes-per-file */
52
74
  function sequence(fn) {
@@ -169,6 +191,17 @@ function setUpServer(transformer, provider, options) {
169
191
  line: update.line
170
192
  };
171
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
+ }
172
205
  await next();
173
206
  }
174
207
  });
@@ -195,12 +228,42 @@ function setUpServer(transformer, provider, options) {
195
228
  };
196
229
  }
197
230
  async function develop(fileName, options) {
231
+ markmapCommon.setProvider('local', localProvider);
198
232
  const transformer = new markmapLib.Transformer();
199
233
  const provider = fileName ? new FileSystemProvider(fileName) : new BufferContentProvider();
200
234
  return setUpServer(transformer, provider, options);
201
235
  }
202
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
+ }
203
261
  async function createMarkmap(options) {
262
+ if (options.offline) {
263
+ markmapCommon.setProvider('local', localProvider);
264
+ } else {
265
+ await markmapCommon.findFastestProvider();
266
+ }
204
267
  const transformer = new markmapLib.Transformer();
205
268
  const {
206
269
  root,
@@ -208,8 +271,17 @@ async function createMarkmap(options) {
208
271
  frontmatter
209
272
  } = transformer.transform(options.content || '');
210
273
  let assets = transformer.getUsedAssets(features);
211
- if (options.toolbar) assets = addToolbar(assets);
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
+ }
212
283
  const html = markmapLib.fillTemplate(root, assets, {
284
+ baseJs: [],
213
285
  jsonOptions: frontmatter == null ? void 0 : frontmatter.markmap
214
286
  });
215
287
  const output = options.output || 'markmap.html';
@@ -218,20 +290,22 @@ async function createMarkmap(options) {
218
290
  }
219
291
  function main(version) {
220
292
  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) => {
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) => {
222
294
  const content = await fs.promises.readFile(input, 'utf8');
223
295
  const output = cmd.output || `${input.replace(/\.\w*$/, '')}.html`;
224
296
  if (cmd.watch) {
225
297
  await develop(input, {
226
298
  open: cmd.open,
227
- toolbar: cmd.toolbar
299
+ toolbar: cmd.toolbar,
300
+ offline: true
228
301
  });
229
302
  } else {
230
303
  await createMarkmap({
231
304
  content,
232
305
  output,
233
306
  open: cmd.open,
234
- toolbar: cmd.toolbar
307
+ toolbar: cmd.toolbar,
308
+ offline: cmd.offline
235
309
  });
236
310
  }
237
311
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-cli",
3
- "version": "0.14.5-alpha.13+50ca560",
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",
@@ -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.13+50ca560",
46
- "markmap-lib": "0.14.5-alpha.13+50ca560",
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
- "update-notifier": "^5.1.0"
52
+ "prismjs": "^1.28.0",
53
+ "update-notifier": "^5.1.0",
54
+ "webfontloader": "^1.6.28"
49
55
  },
50
- "devDependencies": {
51
- "markmap-toolbar": "0.14.5-alpha.13+50ca560",
52
- "markmap-view": "0.14.5-alpha.13+50ca560"
53
- },
54
- "gitHead": "50ca5603019498f93dba6485c96d0a5630b221e5"
56
+ "gitHead": "1fe26c8234296e2188e466c7b9dbf3b7e171857d"
55
57
  }
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
- * whether to open the generated markmap in browser
4
+ * Whether to open the generated markmap in browser
5
5
  */
6
6
  open: boolean;
7
7
  /**
8
- * whether to show default toolbar
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;