remove-sibling.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 path from packages/all-packages/tsconfig.json
  35. var tsconfigPath = path.join(basePath, 'packages', 'all-packages', 'tsconfig.json');
  36. var tsconfig = require(tsconfigPath);
  37. tsconfig.compilerOptions.paths[package.name] = undefined;
  38. fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2) + '\n');
  39. // Remove the extension from packages/all-packages/src/index.ts
  40. var indexPath = path.join(basePath, 'packages', 'all-packages', 'src', 'index.ts');
  41. var index = fs.readFileSync(indexPath, 'utf8');
  42. var indexEntries = index.split('\n');
  43. var indexEntries = indexEntries.filter(function(e) {
  44. return e.indexOf(package.name) === -1;
  45. });
  46. fs.writeFileSync(indexPath, indexEntries.join('\n'));
  47. // Remove the extension from jupyterlab/package.json
  48. var jupyterlabPackagePath = path.join(basePath, 'jupyterlab', 'package.json');
  49. var jupyterlabPackage = require(jupyterlabPackagePath);
  50. jupyterlabPackage.dependencies[package.name] = undefined;
  51. let extensions = jupyterlabPackage.jupyterlab.extensions.filter(function(e) {
  52. return e.indexOf(package.name) === -1;
  53. });
  54. jupyterlabPackage.jupyterlab.extensions = extensions;
  55. fs.writeFileSync(jupyterlabPackagePath, JSON.stringify(jupyterlabPackage, null, 2) + '\n');