MCPcopy Index your code
hub / github.com/massCodeIO/massCode / startMarkdownWatcher

Function startMarkdownWatcher

src/main/storage/providers/markdown/watcher.ts:335–449  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

333}
334
335export function startMarkdownWatcher(): void {
336 const vaultRootPath = getVaultPath()
337 const paths = getPaths(vaultRootPath)
338 const runtimeCache = peekRuntimeCache()
339 const notesPaths = getNotesPaths(vaultRootPath)
340 const notesRuntimeCache = peekNotesRuntimeCache()
341 const httpPaths = getHttpPaths(vaultRootPath)
342 const httpRuntimeCache = peekHttpRuntimeCache()
343
344 if (markdownWatcher && watchedVaultPath === vaultRootPath) {
345 if (!runtimeCache || runtimeCache.paths.vaultPath !== paths.vaultPath) {
346 ensureStateFile(paths)
347 syncRuntimeWithDisk(paths)
348 }
349
350 if (
351 !notesRuntimeCache
352 || notesRuntimeCache.paths.notesRoot !== notesPaths.notesRoot
353 ) {
354 syncNotesRuntimeWithDisk(notesPaths)
355 }
356
357 if (
358 !httpRuntimeCache
359 || httpRuntimeCache.paths.httpRoot !== httpPaths.httpRoot
360 ) {
361 syncHttpRuntimeWithDisk(httpPaths)
362 }
363
364 return
365 }
366
367 stopMarkdownWatcher()
368 ensureStateFile(paths)
369 syncRuntimeWithDisk(paths)
370 syncNotesRuntimeWithDisk(notesPaths)
371 syncHttpRuntimeWithDisk(httpPaths)
372
373 const startToken = ++watcherStartToken
374
375 void getChokidarWatch()
376 .then((watch) => {
377 if (startToken !== watcherStartToken) {
378 return
379 }
380
381 const watcher = watch(vaultRootPath, {
382 awaitWriteFinish: {
383 pollInterval: 100,
384 stabilityThreshold: 200,
385 },
386 ignoreInitial: true,
387 ignored: (watchPath: string) =>
388 shouldIgnoreWatchPath(vaultRootPath, watchPath),
389 persistent: true,
390 })
391
392 watcher

Callers 1

index.tsFile · 0.90

Calls 15

getVaultPathFunction · 0.90
getPathsFunction · 0.90
peekRuntimeCacheFunction · 0.90
getNotesPathsFunction · 0.90
peekNotesRuntimeCacheFunction · 0.90
getHttpPathsFunction · 0.90
peekHttpRuntimeCacheFunction · 0.90
ensureStateFileFunction · 0.90
syncRuntimeWithDiskFunction · 0.90
syncNotesRuntimeWithDiskFunction · 0.90
syncHttpRuntimeWithDiskFunction · 0.90
shouldIgnoreWatchPathFunction · 0.90

Tested by

no test coverage detected