const fs = require('fs'); const {exec} = require('child_process'); // this is for fix because the event fire twice let twiceFix = false; function compileAll(event, fname) { console.log(`${fname} as changed`); if (event == 'change' && twiceFix) { twiceFix = false; exec('npx sass ui/css/omlink.scss:ui/css/omlink.css', (error, out, err) => { console.log('------------------------------ CSS built ------------------------------'); if (error) { console.log(error); return; } exec('npm run build', (error, out, err) => { console.log('------------------------------ Bundle JS/CSS ------------------------------'); if (error) { console.log(error); return; } }); }); } twiceFix = true; } console.log('Adding watcher for ui/css/omlink.scss'); fs.watch('ui/css/omlink.scss', function (event, fname) { compileAll(event, fname); }); console.log('Adding watcher for ui/js/onlink.js'); fs.watch('ui/js/omlink.js', function (event, fname) { compileAll(event, fname); });