code-server-2/scripts/install-packages.ts

52 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-02-28 04:16:31 +00:00
import { exec, execSync } from "child_process";
2019-01-08 00:46:19 +00:00
import { existsSync, readdirSync } from "fs";
2019-02-28 04:16:31 +00:00
import * as os from "os";
2019-01-08 00:46:19 +00:00
import { join, resolve } from "path";
import { logger, field } from "../packages/logger";
2019-01-08 00:46:19 +00:00
/**
* Install dependencies for a single package.
*/
const doInstall = (pkg: string, path: string): void => {
logger.info(`Installing "${pkg}" dependencies...`);
exec("yarn", {
cwd: path,
maxBuffer: 1024 * 1024 * 10,
}, (error, stdout, stderr) => {
if (error) {
logger.error(
`Failed to install "${pkg}" dependencies`,
field("error", error),
field("stdout", stdout),
field("stderr", stderr),
);
process.exit(1);
}
logger.info(`Successfully grabbed \"${pkg}\" dependencies!`);
});
};
/**
* Install dependencies for all packages.
*/
const handlePackages = (dir: string): void => {
readdirSync(dir).forEach((pkg) => {
const pkgDir = join(dir, pkg);
const pkgJsonPath = join(pkgDir, "package.json");
if (existsSync(pkgJsonPath)) {
doInstall(pkg, pkgDir);
}
});
};
2019-02-28 04:16:31 +00:00
if (os.platform() === "win32") {
execSync("yarn", {
cwd: resolve(__dirname, "..", "packages", "vscode"),
maxBuffer: 1024 * 1024 * 10,
});
}
handlePackages(resolve(__dirname, "..", "packages"));
handlePackages(resolve(__dirname, "..", "packages", "app"));