markmap-cli 0.15.9-alpha.11 → 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.
@@ -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,7 +8,6 @@ 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
11
  import { serve } from "@hono/node-server";
13
12
  import chokidar from "chokidar";
14
13
  import { EventEmitter } from "events";
@@ -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);
@@ -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 = await assetsDirPromise;
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
- const assetsDir = await assetsDirPromise;
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.11+d60da2f",
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",
@@ -48,13 +48,13 @@
48
48
  "chokidar": "^3.5.3",
49
49
  "commander": "^11.1.0",
50
50
  "hono": "^3.11.8",
51
- "markmap-common": "0.15.9-alpha.11+d60da2f",
52
- "markmap-lib": "0.15.9-alpha.11+d60da2f",
53
- "markmap-toolbar": "0.15.9-alpha.11+d60da2f",
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",
54
54
  "open": "^10.0.0",
55
55
  "pkg-dir": "^8.0.0",
56
56
  "read-package-up": "^11.0.0",
57
57
  "update-notifier": "^7.0.0"
58
58
  },
59
- "gitHead": "d60da2fb13a85edec875ef002f1be414a0c00abe"
59
+ "gitHead": "e2132d2615f5b19e246478dc9dbb6b6ca4d6d75f"
60
60
  }