extra function to start watching for file-changes, without having to call this file directly with "watch"
()
| 600 | |
| 601 | /** extra function to start watching for file-changes, without having to call this file directly with "watch" */ |
| 602 | function startWatch() { |
| 603 | Object.entries(docsFilemap.fileMap).forEach(([file, fileValue]) => { |
| 604 | let watchPath = path.resolve(cwd, file); |
| 605 | const notifyPath = path.resolve(cwd, file); |
| 606 | |
| 607 | if (fileValue.api) { |
| 608 | watchPath = path.resolve(cwd, fileValue.file); |
| 609 | } |
| 610 | |
| 611 | fs.watchFile(watchPath, { interval: 1000 }, (cur, prev) => { |
| 612 | if (cur.mtime > prev.mtime) { |
| 613 | renderFile(notifyPath, docsFilemap.fileMap[file], true); |
| 614 | } |
| 615 | }); |
| 616 | }); |
| 617 | |
| 618 | fs.watchFile(path.join(cwd, 'docs/layout.pug'), { interval: 1000 }, (cur, prev) => { |
| 619 | if (cur.mtime > prev.mtime) { |
| 620 | console.log('docs/layout.pug modified, reloading all files'); |
| 621 | renderAllFiles(true, true); |
| 622 | } |
| 623 | }); |
| 624 | |
| 625 | fs.watchFile(path.join(cwd, 'docs/api_split.pug'), { interval: 1000 }, (cur, prev) => { |
| 626 | if (cur.mtime > prev.mtime) { |
| 627 | console.log('docs/api_split.pug modified, reloading all api files'); |
| 628 | Promise.all(files.filter(v => v.startsWith('docs/api')).map(async(file) => { |
| 629 | const filename = path.join(cwd, file); |
| 630 | await renderFile(filename, docsFilemap.fileMap[file], true); |
| 631 | })); |
| 632 | } |
| 633 | }); |
| 634 | } |
| 635 | |
| 636 | /** |
| 637 | * Render all files at once |
no test coverage detected