()
| 333 | } |
| 334 | |
| 335 | export 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 |
no test coverage detected