-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkgManager.php
37 lines (31 loc) · 928 Bytes
/
pkgManager.php
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
36
37
<?php
/**
* Returns a command to run a Node package, with support for npm and yarn (v1).
*/
function getPkgManagerRunner($projectRoot, $bin) {
$path = Filesystem::resolvePath($projectRoot, "yarn.lock");
if (Filesystem::pathExists($path)) {
list($stdout, $err) = execx("yarn -s --cwd %s bin %s", $projectRoot, $bin);
if ($stdout) {
return trim($stdout);
}
}
list($stdout, $err) = execx("npm bin");
if ($stdout) {
$path = trim($stdout);
}
if (isset($path) && $path) {
$resolvedBin = Filesystem::resolvePath("eslint", $path);
if (Filesystem::binaryExists($resolvedBin)) {
return $resolvedBin;
}
}
return $bin;
}
function getPkgManagerInstall($projectRoot, $pkg) {
$path = Filesystem::resolvePath($projectRoot, "yarn.lock");
if (Filesystem::pathExists($path)) {
return csprintf("yarn add --dev %s", $pkg);
}
return csprintf("npm --save-dev %s", $pkg);
}