remove-sibling.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env node
  2. /**
  3. * Remove an extension from the relevant metadata
  4. * files of the JupyterLab source tree so that it
  5. * is not included in the build. Intended for testing
  6. * adding/removing extensions against development
  7. * branches of JupyterLab.
  8. *
  9. * Note: this does not remove any files or submodules
  10. * that may have been copied by the add-sibling.js
  11. * script, and as such they are not true inverses of
  12. * each other.
  13. */
  14. var fs = require('fs');
  15. var path = require('path');
  16. var childProcess = require('child_process');
  17. // Make sure we have required command line arguments.
  18. if (process.argv.length < 3) {
  19. var msg = '** Must supply a target extension name';
  20. process.stderr.write(msg);
  21. process.exit(1);
  22. }
  23. // Get the repository name.
  24. var target = process.argv[2];
  25. var basePath = path.resolve('.');
  26. // Get the package.json of the extension.
  27. var packagePath = path.join(basePath, 'packages', target);
  28. var package = require(path.join(packagePath, 'package.json'));
  29. // Remove the extension from packages/all-packages/package.json
  30. var allPackagesPath = path.join(basePath, 'packages', 'all-packages', 'package.json');
  31. var allPackages = require(allPackagesPath);
  32. allPackages.dependencies[package.name] = undefined;
  33. fs.writeFileSync(allPackagesPath, JSON.stringify(allPackages, null, 2) + '\n');
  34. // Remove the extension from packages/all-packages/src/index.ts
  35. var indexPath = path.join(basePath, 'packages', 'all-packages', 'src', 'index.ts');
  36. var index = fs.readFileSync(indexPath, 'utf8');
  37. var indexEntries = index.split('\n');
  38. var indexEntries = indexEntries.filter(function(e) {
  39. return e.indexOf(package.name) === -1;
  40. });
  41. fs.writeFileSync(indexPath, indexEntries.join('\n'));
  42. // Remove the extension from jupyterlab/package.json
  43. var jupyterlabPackagePath = path.join(basePath, 'jupyterlab', 'package.json');
  44. var jupyterlabPackage = require(jupyterlabPackagePath);
  45. jupyterlabPackage.dependencies[package.name] = undefined;
  46. let extensions = jupyterlabPackage.jupyterlab.extensions.filter(function(e) {
  47. return e.indexOf(package.name) === -1;
  48. });
  49. jupyterlabPackage.jupyterlab.extensions = extensions;
  50. fs.writeFileSync(jupyterlabPackagePath, JSON.stringify(jupyterlabPackage, null, 2) + '\n');