watcher.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const fs = require('fs');
  2. const { exec } = require('child_process');
  3. // this is for fix because the event fire twice
  4. let twiceFix = false;
  5. function compileAll(event, fname) {
  6. console.log(`${fname} as changed`);
  7. if(event == 'change' && twiceFix) {
  8. twiceFix = false;
  9. exec('sass ui/css/omlink.scss:ui/css/omlink.css', (error, out, err) => {
  10. console.log('------------------------------ compileAll() ------------------------------');
  11. if(error) {
  12. console.log(error);
  13. return;
  14. }
  15. exec('npm run build dimatec');
  16. });
  17. }
  18. twiceFix = true;
  19. }
  20. console.log('Adding watcher for ui/css/omlink.scss');
  21. fs.watch('ui/css/omlink.scss', function(event, fname) {
  22. compileAll(event, fname);
  23. });
  24. console.log('Adding watcher for ui/customizations/dimatec.scss');
  25. fs.watch('ui/customizations/dimatec.scss', function(event, fname) {
  26. compileAll(event, fname);
  27. });
  28. console.log('Adding watcher for ui/customizations/lamborghini.scss');
  29. fs.watch('ui/customizations/lamborghini.scss', function(event, fname) {
  30. compileAll(event, fname);
  31. });
  32. console.log('Adding watcher for ui/js/onlink.js');
  33. fs.watch('ui/js/omlink.js', function(event, fname) {
  34. compileAll(event, fname);
  35. });