watcher.js 618 B

123456789101112131415161718192021222324
  1. const fs = require('fs');
  2. const {execSync} = require('child_process');
  3. // this is for fix because the event fire twice
  4. let twiceFix = false;
  5. function compileAll(event, fname) {
  6. if (event == 'change' && twiceFix) {
  7. console.log(`${fname} as changed`);
  8. twiceFix = false;
  9. execSync('node build.js');
  10. }
  11. twiceFix = true;
  12. }
  13. console.log('Adding watcher for ui/css/omlink.scss');
  14. fs.watch('ui/css/omlink.scss', function (event, fname) {
  15. compileAll(event, fname);
  16. });
  17. console.log('Adding watcher for ui/js/onlink.js');
  18. fs.watch('ui/js/omlink.js', function (event, fname) {
  19. compileAll(event, fname);
  20. });