monaco-editor/build/npm/installAll.ts

45 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2021-11-16 16:23:03 +08:00
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
2022-02-03 21:56:52 +08:00
import glob = require('glob');
import path = require('path');
import fs = require('fs');
import cp = require('child_process');
2021-11-16 16:23:03 +08:00
const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
2022-02-03 21:56:52 +08:00
import { REPO_ROOT } from '../utils';
2021-11-16 16:23:03 +08:00
const files = glob.sync('**/package.json', {
cwd: REPO_ROOT,
ignore: ['**/node_modules/**', '**/dist/**', '**/out/**']
2021-11-16 16:23:03 +08:00
});
for (const file of files) {
const filePath = path.join(REPO_ROOT, file);
const contents = JSON.parse(fs.readFileSync(filePath).toString());
if (!contents.dependencies && !contents.devDependencies && !contents.optionalDependencies) {
// nothing to install
continue;
}
npmInstall(path.dirname(file));
}
function npmInstall(location) {
const stdio = 'inherit';
const args = ['install'];
console.log(`Installing dependencies in ${location}...`);
console.log(`$ npm ${args.join(' ')}`);
2022-02-03 21:56:52 +08:00
const result = cp.spawnSync(npm, args, {
env: process.env,
cwd: location,
stdio
});
2021-11-16 16:23:03 +08:00
if (result.error || result.status !== 0) {
process.exit(1);
}
}