forked from khanhdodang/nativescript-dev-appium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-dev-deps.js
35 lines (30 loc) · 1.31 KB
/
check-dev-deps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const { basename, resolve } = require("path");
const { existsSync, readFileSync } = require("fs");
const childProcess = require("child_process");
const appRootPath = require('app-root-path').toString();
const packageJsonPath = resolve(appRootPath, "package.json");
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
const isWin = /^win/.test(process.platform);
const executeNpmInstall = (cwd, devDependenciesToInstall) => {
let spawnArgs = [];
let command = "";
if (isWin) {
command = "cmd.exe"
spawnArgs = ["/c", "npm", "install"];
} else {
command = "npm"
spawnArgs = ["install"];
}
if (devDependenciesToInstall && devDependenciesToInstall.length > 0) {
spawnArgs = ["install", "-D", ...devDependenciesToInstall];
}
childProcess.spawnSync(command, spawnArgs, { cwd, stdio: "inherit" });
}
if (basename(appRootPath) !== "nativescript-dev-appium") {
const devDependencies = packageJson.devDependencies;
const modulesPath = resolve(appRootPath, "node_modules");
const devDependenciesToInstall = Object.keys(devDependencies).filter((name => !existsSync(resolve(modulesPath, name))));
if (devDependenciesToInstall && devDependenciesToInstall.length > 0) {
executeNpmInstall(appRootPath, devDependenciesToInstall)
}
}