markmap-cli 0.15.9-alpha.0 → 0.15.9-alpha.12
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/fetch-assets.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +16 -22
- package/dist/util.d.ts +3 -2
- package/package.json +6 -5
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,8 @@
|
|
|
1
1
|
import { type IMarkmapCreateOptions } from 'markmap-lib';
|
|
2
|
-
import { IDevelopOptions } from './util';
|
|
2
|
+
import { IDevelopOptions, config } from './util';
|
|
3
3
|
import { develop } from './dev-server';
|
|
4
4
|
import { fetchAssets } from './fetch-assets';
|
|
5
5
|
export * from 'markmap-lib';
|
|
6
|
-
export { develop, fetchAssets };
|
|
6
|
+
export { config, develop, fetchAssets };
|
|
7
7
|
export declare function createMarkmap(options: IMarkmapCreateOptions & IDevelopOptions): Promise<void>;
|
|
8
8
|
export declare function main(): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -8,15 +8,14 @@ import { readPackageUp } from "read-package-up";
|
|
|
8
8
|
import { buildCSSItem, buildJSItem, defer } from "markmap-common";
|
|
9
9
|
import { Transformer, baseJsPaths } from "markmap-lib";
|
|
10
10
|
export * from "markmap-lib";
|
|
11
|
-
import { packageDirectory } from "pkg-dir";
|
|
12
|
-
import { createReadStream, createWriteStream } from "fs";
|
|
13
|
-
import { EventEmitter } from "events";
|
|
14
11
|
import { serve } from "@hono/node-server";
|
|
15
|
-
import { Hono } from "hono";
|
|
16
12
|
import chokidar from "chokidar";
|
|
13
|
+
import { EventEmitter } from "events";
|
|
14
|
+
import { createReadStream, createWriteStream } from "fs";
|
|
15
|
+
import { Hono } from "hono";
|
|
17
16
|
import { Readable } from "stream";
|
|
18
17
|
import { finished } from "stream/promises";
|
|
19
|
-
const TOOLBAR_VERSION = "0.15.
|
|
18
|
+
const TOOLBAR_VERSION = "0.15.8";
|
|
20
19
|
const TOOLBAR_CSS = `markmap-toolbar@${TOOLBAR_VERSION}/dist/style.css`;
|
|
21
20
|
const TOOLBAR_JS = `markmap-toolbar@${TOOLBAR_VERSION}/dist/index.js`;
|
|
22
21
|
const ASSETS_PREFIX = "/assets/";
|
|
@@ -52,14 +51,6 @@ function addToolbar(urlBuilder, assets) {
|
|
|
52
51
|
function localProvider(path) {
|
|
53
52
|
return `${ASSETS_PREFIX}${path}`;
|
|
54
53
|
}
|
|
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
54
|
function createStreamBody(stream) {
|
|
64
55
|
const body = new ReadableStream({
|
|
65
56
|
start(controller) {
|
|
@@ -76,6 +67,10 @@ function createStreamBody(stream) {
|
|
|
76
67
|
});
|
|
77
68
|
return body;
|
|
78
69
|
}
|
|
70
|
+
const rootDir = new URL(import.meta.url).pathname;
|
|
71
|
+
const config = {
|
|
72
|
+
assetsDir: resolve(rootDir, `.${ASSETS_PREFIX}`)
|
|
73
|
+
};
|
|
79
74
|
var getMimeType = (filename) => {
|
|
80
75
|
const regexp = /\.([a-zA-Z0-9]+?)$/;
|
|
81
76
|
const match = filename.match(regexp);
|
|
@@ -282,12 +277,12 @@ function startServer(paddingBottom) {
|
|
|
282
277
|
dfs(root);
|
|
283
278
|
return best;
|
|
284
279
|
function dfs(node) {
|
|
285
|
-
var _a, _b;
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
280
|
+
var _a, _b, _c;
|
|
281
|
+
const [start, end] = ((_b = (_a = node.payload) == null ? void 0 : _a.lines) == null ? void 0 : _b.split(",").map((s) => +s)) || [];
|
|
282
|
+
if (start >= 0 && start <= lineWithoutFrontmatter && lineWithoutFrontmatter < end) {
|
|
288
283
|
best = node;
|
|
289
284
|
}
|
|
290
|
-
(
|
|
285
|
+
(_c = node.children) == null ? void 0 : _c.forEach(dfs);
|
|
291
286
|
}
|
|
292
287
|
}
|
|
293
288
|
}
|
|
@@ -312,7 +307,7 @@ async function setUpServer(transformer, provider, options) {
|
|
|
312
307
|
await ((_a = provider[cmd]) == null ? void 0 : _a.call(provider, ...args));
|
|
313
308
|
return c.body(null, 204);
|
|
314
309
|
});
|
|
315
|
-
const assetsDir =
|
|
310
|
+
const { assetsDir } = config;
|
|
316
311
|
app.get(`${ASSETS_PREFIX}*`, async (c) => {
|
|
317
312
|
const relpath = c.req.path.slice(ASSETS_PREFIX.length);
|
|
318
313
|
const realpath = join(assetsDir, relpath);
|
|
@@ -367,7 +362,7 @@ async function develop(fileName, options) {
|
|
|
367
362
|
return setUpServer(transformer, provider, options);
|
|
368
363
|
}
|
|
369
364
|
const providerName = "local-hook";
|
|
370
|
-
async function fetchAssets() {
|
|
365
|
+
async function fetchAssets(assetsDir = config.assetsDir) {
|
|
371
366
|
var _a, _b;
|
|
372
367
|
const transformer = new Transformer();
|
|
373
368
|
const { provider } = transformer.urlBuilder;
|
|
@@ -386,7 +381,6 @@ async function fetchAssets() {
|
|
|
386
381
|
)) || []
|
|
387
382
|
].filter((url) => url.startsWith(ASSETS_PREFIX)).map((url) => url.slice(ASSETS_PREFIX.length));
|
|
388
383
|
const paths = [...baseJsPaths, ...pluginPaths];
|
|
389
|
-
const assetsDir = await assetsDirPromise;
|
|
390
384
|
const fastest = await transformer.urlBuilder.getFastestProvider();
|
|
391
385
|
await Promise.all(
|
|
392
386
|
paths.map(
|
|
@@ -417,8 +411,7 @@ async function downloadAsset(fullPath, url) {
|
|
|
417
411
|
async function loadFile(path) {
|
|
418
412
|
if (path.startsWith(ASSETS_PREFIX)) {
|
|
419
413
|
const relpath = path.slice(ASSETS_PREFIX.length);
|
|
420
|
-
|
|
421
|
-
return readFile(resolve(assetsDir, relpath), "utf8");
|
|
414
|
+
return readFile(resolve(config.assetsDir, relpath), "utf8");
|
|
422
415
|
}
|
|
423
416
|
const res = await fetch(path);
|
|
424
417
|
if (!res.ok)
|
|
@@ -531,6 +524,7 @@ async function main() {
|
|
|
531
524
|
program.parse(process.argv);
|
|
532
525
|
}
|
|
533
526
|
export {
|
|
527
|
+
config,
|
|
534
528
|
createMarkmap,
|
|
535
529
|
develop,
|
|
536
530
|
fetchAssets,
|
package/dist/util.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export interface IDevelopOptions {
|
|
|
22
22
|
}
|
|
23
23
|
export declare function addToolbar(urlBuilder: UrlBuilder, assets: IAssets): IAssets;
|
|
24
24
|
export declare function localProvider(path: string): string;
|
|
25
|
-
export declare const rootDirPromise: Promise<string | undefined>;
|
|
26
|
-
export declare const assetsDirPromise: Promise<string>;
|
|
27
25
|
export declare function createStreamBody(stream: ReadStream): ReadableStream<any>;
|
|
26
|
+
export declare const config: {
|
|
27
|
+
assetsDir: string;
|
|
28
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markmap-cli",
|
|
3
|
-
"version": "0.15.9-alpha.
|
|
3
|
+
"version": "0.15.9-alpha.12+e2132d2",
|
|
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,13 @@
|
|
|
47
48
|
"chokidar": "^3.5.3",
|
|
48
49
|
"commander": "^11.1.0",
|
|
49
50
|
"hono": "^3.11.8",
|
|
50
|
-
"markmap-common": "0.15.9-alpha.
|
|
51
|
-
"markmap-lib": "0.15.9-alpha.
|
|
52
|
-
"markmap-toolbar": "0.15.9-alpha.
|
|
51
|
+
"markmap-common": "0.15.9-alpha.12+e2132d2",
|
|
52
|
+
"markmap-lib": "0.15.9-alpha.12+e2132d2",
|
|
53
|
+
"markmap-toolbar": "0.15.9-alpha.12+e2132d2",
|
|
53
54
|
"open": "^10.0.0",
|
|
54
55
|
"pkg-dir": "^8.0.0",
|
|
55
56
|
"read-package-up": "^11.0.0",
|
|
56
57
|
"update-notifier": "^7.0.0"
|
|
57
58
|
},
|
|
58
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "e2132d2615f5b19e246478dc9dbb6b6ca4d6d75f"
|
|
59
60
|
}
|