2019-02-28 12:16:31 +08:00
|
|
|
import { exec, execSync } from "child_process";
|
2019-01-08 08:46:19 +08:00
|
|
|
import { existsSync, readdirSync } from "fs";
|
2019-02-28 12:16:31 +08:00
|
|
|
import * as os from "os";
|
2019-01-08 08:46:19 +08:00
|
|
|
import { join, resolve } from "path";
|
2019-01-15 04:58:34 +08:00
|
|
|
import { logger, field } from "../packages/logger";
|
2019-01-08 08:46:19 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Install dependencies for a single package.
|
|
|
|
*/
|
2019-03-01 04:04:19 +08:00
|
|
|
const doInstall = (pkg: string, path: string): Promise<void> => {
|
2019-01-08 08:46:19 +08:00
|
|
|
logger.info(`Installing "${pkg}" dependencies...`);
|
|
|
|
|
2019-03-01 04:04:19 +08:00
|
|
|
return new Promise((resolve): void => {
|
|
|
|
exec("yarn --network-concurrency 1", {
|
|
|
|
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!`);
|
|
|
|
resolve();
|
|
|
|
});
|
2019-01-08 08:46:19 +08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Install dependencies for all packages.
|
|
|
|
*/
|
2019-03-01 04:04:19 +08:00
|
|
|
const handlePackages = async (dir: string): Promise<void> => {
|
|
|
|
const dirs = readdirSync(dir);
|
|
|
|
for (let i = 0; i < dirs.length; i++) {
|
|
|
|
const pkg = dirs[i];
|
2019-01-08 08:46:19 +08:00
|
|
|
const pkgDir = join(dir, pkg);
|
|
|
|
const pkgJsonPath = join(pkgDir, "package.json");
|
|
|
|
if (existsSync(pkgJsonPath)) {
|
2019-03-01 04:04:19 +08:00
|
|
|
const ip = doInstall(pkg, pkgDir);
|
|
|
|
if (os.platform() === "win32") {
|
|
|
|
await ip;
|
|
|
|
}
|
2019-01-08 08:46:19 +08:00
|
|
|
}
|
2019-03-01 04:04:19 +08:00
|
|
|
}
|
2019-01-08 08:46:19 +08:00
|
|
|
};
|
|
|
|
|
2019-03-01 04:04:19 +08:00
|
|
|
handlePackages(resolve(__dirname, "..", "packages")).then(() => {
|
|
|
|
return handlePackages(resolve(__dirname, "..", "packages", "app"));
|
|
|
|
});
|