-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
executable file
·57 lines (50 loc) · 1.41 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
#!/usr/bin/env node
'use strict'
const spawn = require('cross-spawn')
const npmRunPath = require('npm-run-path-compat')
const versionChanged = require('version-changed')
const runSeries = require('run-series')
const supportedTargets = require('node-abi').supportedTargets
const buildTargets = require('./build-targets')
const path = require('path')
const pkg = require(path.resolve('package.json'))
if (!process.env.CI) process.exit()
const token = process.env.PREBUILD_TOKEN
if (!token) {
console.error('[prebuild-ci] Skipping: PREBUILD_TOKEN required.')
process.exit(0)
}
function prebuild (runtime, target, cb) {
console.log('[prebuild-ci] Build %s abi %s', runtime, target)
const ps = spawn('prebuild', [
'-r', runtime,
'-t', target,
'-u', token,
'--verbose'
], {
env: npmRunPath.env()
})
ps.stdout.pipe(process.stdout)
ps.stderr.pipe(process.stderr)
ps.on('exit', function (code) {
if (code) return cb(Error(), code)
cb()
})
}
versionChanged(function (err, changed) {
if (err) throw err
if (!changed) {
console.error('[prebuild-ci] Skipping: no version bump.')
process.exit(0)
}
const builds = buildTargets(process.versions, supportedTargets, pkg)
.map(function (target) {
return function (cb) {
prebuild(target.runtime, target.target, cb)
}
})
runSeries(builds, function (err) {
if (err) process.exit(1)
process.exit(0)
})
})