dev.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const debug = require('debug')('crowi:crowi:dev');
  2. const path = require('path');
  3. const webpack = require('webpack');
  4. const helpers = require('./helpers')
  5. class CrowiDev {
  6. /**
  7. * Creates an instance of CrowiDev.
  8. * @param {Crowi} crowi
  9. * @param {any} server http server
  10. * @param {any} app express
  11. *
  12. * @memberOf CrowiDev
  13. */
  14. constructor(crowi, server, app) {
  15. this.crowi = crowi;
  16. this.server = server;
  17. this.app = app;
  18. }
  19. setupTools() {
  20. if (helpers.hasProcessFlag('autorefresh')) {
  21. this.setupReload();
  22. }
  23. }
  24. setupReload() {
  25. const reload = require('reload');
  26. const chokidar = require('chokidar');
  27. // refreshing browser settings
  28. // see: https://github.com/jprichardson/reload
  29. const reloadServer = reload(this.server, this.app);
  30. const watcher = chokidar.watch([
  31. path.join(this.crowi.viewsDir),
  32. path.join(this.crowi.publicDir),
  33. ]);
  34. // fire reload() when changes detected
  35. watcher.on('all', (event, path) => {
  36. reloadServer.reload();
  37. });
  38. debug(`watching for live-reloading -> ${this.crowi.libDir}`);
  39. }
  40. }
  41. module.exports = CrowiDev