forked from prebuild/prebuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
68 lines (60 loc) · 1.54 KB
/
util.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
59
60
61
62
63
64
65
66
67
68
var path = require('path')
var cp = require('child_process')
var execSpawn = require('execspawn')
var error = require('./error')
function getTarPath (opts, abi) {
return path.join('prebuilds', [
opts.pkg.name,
'-v', opts.pkg.version,
'-', opts.runtime || 'node',
'-v', abi,
'-', opts.platform,
opts.libc,
'-', opts.arch,
'.tar.gz'
].join(''))
}
function spawn (cmd, args, cb) {
return cp.spawn(cmd, args).on('exit', function (code) {
if (code === 0) return cb()
cb(error.spawnFailed(cmd, args, code))
})
}
function fork (file, cb) {
return cp.fork(file).on('exit', function (code) {
if (code === 0) return cb()
cb(error.spawnFailed(file, code))
})
}
function exec (cmd, cb) {
return execSpawn(cmd, { stdio: 'inherit' }).on('exit', function (code) {
if (code === 0) return cb()
cb(error.spawnFailed(cmd, [], code))
})
}
function run (item, cb) {
if (path.extname(item) === '.js') {
return fork(item, cb)
} else {
return exec(item, cb)
}
}
function platform () {
return process.platform
}
function releaseFolder (opts, version) {
var type = (opts.debug ? 'Debug' : 'Release')
var binary = opts.pkg.binary
if (opts.backend === 'node-ninja') {
return (binary && binary.module_path) || 'build/' + version + '/' + type
} else {
return (binary && binary.module_path) || 'build/' + type
}
}
exports.getTarPath = getTarPath
exports.spawn = spawn
exports.fork = fork
exports.exec = exec
exports.run = run
exports.platform = platform
exports.releaseFolder = releaseFolder