watcher.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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('npx sass ui/css/omlink.scss:ui/css/omlink.css', (error, out, err) => {
  10. console.log('------------------------------ CSS built ------------------------------');
  11. if (error) {
  12. console.log(error);
  13. return;
  14. }
  15. exec('npm run build', (error, out, err) => {
  16. console.log('------------------------------ Bundle JS/CSS ------------------------------');
  17. if (error) {
  18. console.log(error);
  19. return;
  20. }
  21. });
  22. });
  23. }
  24. twiceFix = true;
  25. }
  26. console.log('Adding watcher for ui/css/omlink.scss');
  27. fs.watch('ui/css/omlink.scss', function (event, fname) {
  28. compileAll(event, fname);
  29. });
  30. console.log('Adding watcher for ui/customizations/dimatec.scss');
  31. fs.watch('ui/customizations/dimatec.scss', function (event, fname) {
  32. compileAll(event, fname);
  33. });
  34. console.log('Adding watcher for ui/customizations/lamborghini.scss');
  35. fs.watch('ui/customizations/lamborghini.scss', function (event, fname) {
  36. compileAll(event, fname);
  37. });
  38. console.log('Adding watcher for ui/js/onlink.js');
  39. fs.watch('ui/js/omlink.js', function (event, fname) {
  40. compileAll(event, fname);
  41. });