ensure-buildutils.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* -----------------------------------------------------------------------------
  2. | Copyright (c) Jupyter Development Team.
  3. | Distributed under the terms of the Modified BSD License.
  4. |----------------------------------------------------------------------------*/
  5. // uncomment to time script
  6. // var start = new Date();
  7. const fs = require('fs-extra');
  8. const glob = require('glob');
  9. const path = require('path');
  10. const childProcess = require('child_process');
  11. const basePath = path.join(path.resolve('.'), 'buildutils');
  12. // Make sure that buildutils is built and current
  13. let current = true;
  14. if (fs.existsSync(path.join(basePath, 'lib'))) {
  15. const srcFiles = glob.sync(path.join(basePath, 'src', '*'));
  16. const libFiles = glob.sync(path.join(basePath, 'lib', '*'));
  17. srcFiles.forEach(function(srcPath) {
  18. // bail early if already not current
  19. if (!current) {
  20. return;
  21. }
  22. if (srcPath.endsWith('.d.ts')) {
  23. // bail if this is a src declarations file
  24. return;
  25. }
  26. const name = path.basename(srcPath);
  27. const ext = path.extname(name);
  28. if (ext !== '.ts') {
  29. current = false;
  30. return;
  31. }
  32. const libPath = path.join(basePath, 'lib', name.replace('.ts', '.js'));
  33. if (libFiles.indexOf(libPath) === -1) {
  34. current = false;
  35. return;
  36. }
  37. const srcTime = fs.statSync(srcPath).mtime;
  38. const libTime = fs.statSync(libPath).mtime;
  39. if (libTime < srcTime) {
  40. current = false;
  41. }
  42. });
  43. } else {
  44. current = false;
  45. }
  46. if (!current) {
  47. // This must be "npm" because it is run during `pip install -e .` before
  48. // jlpm is installed.
  49. childProcess.execSync('npm run build', {
  50. stdio: [0, 1, 2],
  51. cwd: path.resolve('./buildutils')
  52. });
  53. }
  54. // uncomment to time script
  55. // var end = new Date() - start;
  56. // console.info('Execution time: %dms', end);