/
index.js
executable file
·64 lines (55 loc) · 1.53 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
59
60
61
62
63
64
#!/usr/bin/env node
const spawn = require('cross-spawn')
const npmRunPath = require('npm-run-path-compat')
const log = require('npmlog')
const versionChanged = require('version-changed')
const version = require('./package').version
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()
log.heading = 'prebuild-ci'
log.level = 'verbose'
const token = process.env.PREBUILD_TOKEN
if (!token) {
log.error('PREBUILD_TOKEN required')
process.exit(0)
}
function prebuild (runtime, target, cb) {
log.info('build', runtime, 'abi', 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()
})
}
log.info('begin', 'Prebuild-CI version', version)
versionChanged(function (err, changed) {
if (err) throw err
if (!changed) {
log.info('No version bump, exiting')
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)
log.info('All done!')
process.exit(0)
})
})