Advertisement
rickyc81

Untitled

Feb 10th, 2021
756
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const chokidar = require('chokidar')
  2.  
  3. export let cacheMap = new Map()
  4.  
  5. export default function watchChange(){
  6.     chokidar.watch('src/firmware', {
  7.         persistent: true,
  8.     }).on('all', (event, path) => {
  9.         if (event == "add") {
  10.             cacheMap.set(path.substr(20, 8) + "_" + path.substr(-3), path.substr(13))
  11.         }
  12.         if (event == "unlink") {
  13.             cacheMap.delete(path.substr(20, 8) + "_" + path.substr(-3))
  14.         } else {
  15.             return cacheMap
  16.         }
  17.     })
  18.     return cacheMap
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement