Skip to content

Commit

Permalink
feat(filewatch): 新增 watch (change file)
Browse files Browse the repository at this point in the history
  • Loading branch information
YvetteLau committed Jul 6, 2019
1 parent 5099b27 commit 8071df8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/filewatch/changeFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import addFile from './addFile';
import unlinkFile from './unlinkFile';

export default async function changeFile(path) {
await unlinkFile(path);
await addFile(path);
}
5 changes: 3 additions & 2 deletions src/filewatch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import addFile from './addFile'
import unlinkFile from './unlinkFile'
import unlinkDir from './unlinkDir'
import changeFile from './changeFile'

const chokidar = require('chokidar')
const events = require('events');
Expand All @@ -25,6 +26,7 @@ export default (ignored) => {
{
persistent: watchMode,
ignored,
interval: 1000
})

watcher
Expand All @@ -38,11 +40,10 @@ export default (ignored) => {
}
})
.on('change', async path => {
console.log(path, ' changed!')
changeFile(path)
})
.on('unlink', async path => {
unlinkFile(path)
console.log(path, ' delete!')
})
.on('unlinkDir', async dir => {
unlinkDir(dir)
Expand Down

0 comments on commit 8071df8

Please sign in to comment.