Skip to content

Commit

Permalink
fix: fix watch issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Dec 17, 2024
1 parent a7c478e commit 674d84b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@
]
},
"dependencies": {
"@types/ejs": "^3.1.0",
"@types/fs-extra": "~11.0.0",
"@types/inquirer": "^9.0.0",
"@types/micromatch": "^4.0.2",
"@types/minimist": "~1.2.2",
"@uiw/formatter": "~2.0.0",
"@wcj/markdown-to-html": "^3.0.0",
"auto-config-loader": "^2.0.0",
Expand All @@ -83,5 +78,12 @@
"rehype-video": "^2.3.0",
"remark-github-blockquote-alert": "^1.1.0",
"yaml": "^2.0.0"
},
"devDependencies": {
"@types/ejs": "^3.1.0",
"@types/fs-extra": "~11.0.0",
"@types/inquirer": "^9.0.0",
"@types/micromatch": "^4.0.2",
"@types/minimist": "~1.2.2"
}
}
12 changes: 12 additions & 0 deletions packages/core/src/scripts/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export function watch() {
});

watcher.on('change', async (filepath, stats) => {
if (filepath instanceof Error) {
log.log('\x1b[31midoc:watch:\x1b[0m')(filepath.message);
return;
}
const isTheme = new RegExp(`^${config.data.theme}`).test(filepath);
// Modify Theme files
if (config.data.config.conf === filepath) {
Expand Down Expand Up @@ -57,12 +61,20 @@ export function watch() {
});

watcher.on('add', async (filepath) => {
if (filepath instanceof Error) {
log.log('\x1b[31midoc:watch:\x1b[0m')(filepath.message);
return;
}
watcher.add(filepath);
if (/\.(md|markdown)/i.test(filepath)) {
await compilation(filepath);
}
});
watcher.on('unlink', async (filepath) => {
if (filepath instanceof Error) {
log.log('\x1b[31midoc:watch:\x1b[0m')(filepath.message);
return;
}
watcher.unwatch(filepath);
const isTheme = new RegExp(`^${config.data.theme}`).test(filepath);
if (/\.(md|markdown)$/i.test(filepath)) {
Expand Down

0 comments on commit 674d84b

Please sign in to comment.