MCPcopy Index your code
hub / github.com/tinyplex/tinybase / rewritePublishedDocShots

Function rewritePublishedDocShots

site/shots.ts:53–86  ·  view source on GitHub ↗
(outDir: string)

Source from the content-addressed store, hash-verified

51};
52
53const rewritePublishedDocShots = (outDir: string): void => {
54 const refs = getDocShotRefs(outDir);
55 DOC_SHOT_OUTPUT_PATHS.forEach((extension) =>
56 forEachDeepFile(
57 outDir,
58 (filePath) => {
59 const file = readFileSync(filePath, UTF8);
60 const rewritten = refs.reduce((file, ref) => {
61 const publishedRef = `/${DOC_SHOT_DIR}/${ref}`;
62 return file
63 .replaceAll(
64 new RegExp(`(?<!${DOC_SHOT_DIR})/${escapeRegExp(ref)}`, 'g'),
65 publishedRef,
66 )
67 .replaceAll(
68 new RegExp(
69 `(?<!/)${escapeRegExp(`${DOC_SHOT_DIR}/${ref}`)}`,
70 'g',
71 ),
72 publishedRef,
73 )
74 .replaceAll(
75 new RegExp(`(?<![/\\w-])${escapeRegExp(ref)}`, 'g'),
76 publishedRef,
77 );
78 }, file);
79 if (rewritten != file) {
80 writeFileSync(filePath, rewritten, UTF8);
81 }
82 },
83 extension,
84 ),
85 );
86};
87
88const getPublishedDocShotRefs = (outDir: string): Map<string, string[]> => {
89 const refs = new Map<string, string[]>();

Callers 1

Calls 3

getDocShotRefsFunction · 0.85
escapeRegExpFunction · 0.85
forEachDeepFileFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…