watch-files.js 833 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. var fs = require('fs-extra');
  4. var path = require('path');
  5. var watch = require('watch');
  6. // Handle a change to a file.
  7. function handleFile(filename) {
  8. var parts = filename.split(path.sep);
  9. parts[0] = '..';
  10. parts[2] = 'lib';
  11. var target = path.resolve(parts.join(path.sep));
  12. fs.copySync(filename, target);
  13. }
  14. // Watch the files in lib.
  15. watch.createMonitor('lib', function (monitor) {
  16. monitor.on('created', function (f) {
  17. watch.createMonitor(f, function (submonitor) {
  18. submonitor.on('changed', handleFile);
  19. });
  20. });
  21. monitor.on('changed', handleFile);
  22. // Handle the initial files.
  23. require('./build');
  24. // eslint-disable-next-line no-console
  25. console.log('Watching the metapackage files...');
  26. });