MCPcopy Index your code
hub / github.com/markmap/markmap / fetchAssets

Function fetchAssets

packages/markmap-cli/src/fetch-assets.ts:18–68  ·  view source on GitHub ↗
({
  assetsDir = config.assetsDir,
  verbose,
}: {
  assetsDir?: string;
  verbose?: boolean;
} = {})

Source from the content-addressed store, hash-verified

16const providerName = 'local-hook';
17
18async function fetchAssets({
19 assetsDir = config.assetsDir,
20 verbose,
21}: {
22 assetsDir?: string;
23 verbose?: boolean;
24} = {}) {
25 const transformer = new Transformer();
26 transformer.urlBuilder.setProvider(providerName, localProvider);
27 transformer.urlBuilder.provider = providerName;
28 const assets = transformer.getAssets();
29 delete transformer.urlBuilder.providers[providerName];
30 const pluginPaths = extractAssets(assets)
31 .filter((url) => url.startsWith(ASSETS_PREFIX))
32 .map((url) => url.slice(ASSETS_PREFIX.length));
33 const resources = transformer.plugins.flatMap(
34 (plugin) => plugin.config?.resources || [],
35 );
36 const paths = [
37 ...baseJsPaths,
38 ...pluginPaths,
39 ...resources,
40 ...extractAssets(toolbarAssets),
41 ];
42 const resolveDepPath = (path: string) => {
43 const parts = path.split('/');
44 const offset = parts[0].startsWith('@') ? 1 : 0;
45 parts[offset] = parts[offset].split('@')[0];
46 path = parts.join('/');
47 if (path.startsWith('d3')) {
48 path = 'markmap-view/node_modules/' + path;
49 } else if (!path.startsWith('markmap-')) {
50 path = 'markmap-lib/node_modules/' + path;
51 }
52 return resolve('..', path);
53 };
54 await Promise.all(
55 paths.map(async (path) => {
56 const fullPath = resolve(assetsDir, path);
57 let url: string | undefined;
58 await downloadAsset(fullPath, async () => (url = resolveDepPath(path)));
59 if (verbose) {
60 console.log(
61 url
62 ? `Fetched: ${url} -> ${fullPath}`
63 : `Skipped existing file: ${fullPath}`,
64 );
65 }
66 }),
67 );
68}
69
70async function downloadAsset(
71 fullPath: string,

Callers 1

mainFunction · 0.85

Calls 4

getAssetsMethod · 0.95
extractAssetsFunction · 0.90
downloadAssetFunction · 0.85
resolveDepPathFunction · 0.85

Tested by

no test coverage detected