-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
58 lines (42 loc) · 1.28 KB
/
index.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const spawn = require('child_process').spawn
function depVer(dependency)
{
return dependency+'@'+this[dependency]
}
function buildDependencies(PKG, dependenciesField, argv, callback)
{
// Adjust the arguments
if(dependenciesField instanceof Array || dependenciesField instanceof Function)
{
callback = argv
argv = dependenciesField
dependenciesField = null
}
if(argv instanceof Function)
{
callback = argv
argv = null
}
dependenciesField = dependenciesField || 'buildDependencies'
argv = argv || []
// Get the build dependencies list
var buildDependencies = PKG[dependenciesField] || []
const devDependencies = PKG.devDependencies || {}
if(!buildDependencies.length || !Object.keys(devDependencies).length)
return callback()
buildDependencies = buildDependencies.map(depVer, devDependencies)
// Install the build dependencies
var finished = false
function errorOrExit(errCode, signal)
{
if(finished) return
finished = true
callback(errCode || signal)
}
buildDependencies.unshift('install')
Array.prototype.push.apply(buildDependencies, argv)
spawn('npm', buildDependencies, {stdio: 'inherit', env: process.env })
.on('error', errorOrExit)
.on('exit', errorOrExit)
}
module.exports = buildDependencies