forked from bortexz/npm-platform-dependencies
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
executable file
·41 lines (33 loc) · 1.08 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
#! /usr/bin/env node
var path = require('path')
var pkg = require(path.join(process.cwd(), 'package.json'))
var os = require('os')
var platform = os.platform()
var log = console.log
if (process.env.NPMPD_PLATFORM) {
platform = process.env.NPMPD_PLATFORM;
}
platformArg = process.argv.find(x => /^platform=/.test(x));
if (platformArg) {
platform = platformArg.split('=')[1];
}
var spawn = require('cross-spawn')
// Build arguments for npm
var dependencies = platform + 'Dependencies'
var dependenciesObj = pkg[dependencies]
if (dependenciesObj && Object.keys(dependenciesObj).length) {
log('Installing dependencies for ' + platform)
var npmArgs = ['install']
for (var dep in dependenciesObj) {
if (dependenciesObj.hasOwnProperty(dep)) {
npmArgs.push(dep.concat('@').concat(dependenciesObj[dep]))
}
}
npmArgs.push('--no-save');
var options = {
stdio: 'inherit' // feed all child process logging into parent process
}
spawn('npm', npmArgs, options)
} else {
log('No specific dependencies on this platform: ' + platform)
}