ensure-buildutils.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*-----------------------------------------------------------------------------
  2. | Copyright (c) Jupyter Development Team.
  3. | Distributed under the terms of the Modified BSD License.
  4. |----------------------------------------------------------------------------*/
  5. var fs = require('fs-extra');
  6. var glob = require('glob');
  7. var path = require('path');
  8. var childProcess = require('child_process');
  9. // Make sure that buildutils is built and current
  10. var current = true;
  11. if (fs.existsSync(path.join('buildutils', 'lib'))) {
  12. var srcFiles = glob.sync(path.join('buildutils', 'src', '*'));
  13. var libFiles = glob.sync(path.join('buildutils', 'lib', '*'));
  14. srcFiles.forEach(function(srcPath) {
  15. // Bail early if already not current
  16. if (!current) {
  17. return;
  18. }
  19. var name = path.basename(srcPath);
  20. var ext = path.extname(name);
  21. if (ext !== 'js') {
  22. return;
  23. }
  24. var libPath = path.join('buildutils', 'lib', name.replace('.ts', '.js'));
  25. if (libFiles.indexOf(libPath) === -1) {
  26. current = false;
  27. return;
  28. }
  29. var srcTime = fs.statSync(srcPath).mtime;
  30. var libTime = fs.statSync(libPath).mtime;
  31. if (libTime < srcTime) {
  32. current = false;
  33. }
  34. });
  35. } else {
  36. current = false;
  37. }
  38. if (!current) {
  39. // This must be "npm" because it is run during `pip install -e .` before
  40. // jlpm is installed.
  41. childProcess.execSync('npm run build', {
  42. stdio: [0, 1, 2],
  43. cwd: path.resolve('./buildutils')
  44. });
  45. }