installAll.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. //@ts-check
  6. const glob = require('glob');
  7. const path = require('path');
  8. const fs = require('fs');
  9. const cp = require('child_process');
  10. const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
  11. const { REPO_ROOT } = require('../utils');
  12. const files = glob.sync('**/package.json', {
  13. cwd: REPO_ROOT,
  14. ignore: ['**/node_modules/**', '**/out/**', '**/release/**']
  15. });
  16. for (const file of files) {
  17. const filePath = path.join(REPO_ROOT, file);
  18. const contents = JSON.parse(fs.readFileSync(filePath).toString());
  19. if (!contents.dependencies && !contents.devDependencies && !contents.optionalDependencies) {
  20. // nothing to install
  21. continue;
  22. }
  23. npmInstall(path.dirname(file));
  24. }
  25. function npmInstall(location) {
  26. /** @type {'inherit'} */
  27. const stdio = 'inherit';
  28. const opts = {
  29. env: process.env,
  30. cwd: location,
  31. stdio
  32. };
  33. const args = ['install'];
  34. console.log(`Installing dependencies in ${location}...`);
  35. console.log(`$ npm ${args.join(' ')}`);
  36. const result = cp.spawnSync(npm, args, opts);
  37. if (result.error || result.status !== 0) {
  38. process.exit(1);
  39. }
  40. }