installAll.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. import glob = require('glob');
  6. import path = require('path');
  7. import fs = require('fs');
  8. import cp = require('child_process');
  9. const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
  10. import { REPO_ROOT } from '../utils';
  11. const files = glob.sync('**/package.json', {
  12. cwd: REPO_ROOT,
  13. ignore: ['**/node_modules/**', '**/dist/**', '**/out/**']
  14. });
  15. for (const file of files) {
  16. const filePath = path.join(REPO_ROOT, file);
  17. const contents = JSON.parse(fs.readFileSync(filePath).toString());
  18. if (!contents.dependencies && !contents.devDependencies && !contents.optionalDependencies) {
  19. // nothing to install
  20. continue;
  21. }
  22. npmInstall(path.dirname(file));
  23. }
  24. function npmInstall(location) {
  25. const stdio = 'inherit';
  26. const args = ['install'];
  27. console.log(`Installing dependencies in ${location}...`);
  28. console.log(`$ npm ${args.join(' ')}`);
  29. const result = cp.spawnSync(npm, args, {
  30. env: process.env,
  31. cwd: location,
  32. stdio
  33. });
  34. if (result.error || result.status !== 0) {
  35. process.exit(1);
  36. }
  37. }