prebuildify
Advanced tools
Comparing version 2.2.2 to 2.3.0
115
index.js
@@ -1,3 +0,1 @@ | ||
#!/usr/bin/env node | ||
var proc = require('child_process') | ||
@@ -8,3 +6,2 @@ var execspawn = require('execspawn') | ||
var fs = require('fs') | ||
var minimist = require('minimist') | ||
var abi = require('node-abi') | ||
@@ -14,63 +11,53 @@ var mkdirp = require('mkdirp') | ||
var argv = minimist(process.argv.slice(2), { | ||
alias: {target: 't', version: 'v', all: 'a'}, | ||
boolean: ['quiet', 'strip'] | ||
}) | ||
module.exports = prebuildify | ||
var arch = argv.arch || os.arch() | ||
var platform = argv.platform || os.platform() | ||
var cwd = argv._[0] || '.' | ||
var env = xtend(process.env, {ARCH: arch, PREBUILD_ARCH: arch}) | ||
var builds = path.join(cwd, 'prebuilds', platform + '-' + arch) | ||
var output = path.join(cwd, 'build', argv.debug ? 'Debug' : 'Release') | ||
function prebuildify (opts, cb) { | ||
opts = xtend({ | ||
arch: os.arch(), | ||
platform: os.platform(), | ||
cwd: '.', | ||
targets: [] | ||
}, opts) | ||
var targets = [].concat(argv.target || []).map(function (v) { | ||
if (v.indexOf('@') === -1) v = 'node@' + v | ||
return { | ||
runtime: v.split('@')[0], | ||
target: v.split('@')[1].replace(/^v/, '') | ||
if (!opts.targets.length) { | ||
return cb(new Error('You must specify at least one target using --target=runtime@version')) | ||
} | ||
}) | ||
// TODO: also support --lts and get versions from travis | ||
if (argv.all) { | ||
targets = abi.supportedTargets.slice(0) | ||
} | ||
opts = xtend(opts, { | ||
targets: opts.targets.slice(), | ||
env: xtend(process.env, {ARCH: opts.arch, PREBUILD_ARCH: opts.arch}), | ||
builds: path.join(opts.cwd, 'prebuilds', opts.platform + '-' + opts.arch), | ||
output: path.join(opts.cwd, 'build', opts.debug ? 'Debug' : 'Release') | ||
}) | ||
if (!targets.length) { | ||
console.error('You must specify at least one target using --target=runtime@version') | ||
process.exit(1) | ||
mkdirp(opts.builds, function (err) { | ||
if (err) return cb(err) | ||
loop(opts, cb) | ||
}) | ||
} | ||
if (!fs.existsSync(path.join(cwd, 'package.json'))) { | ||
console.error('No package.json found') | ||
process.exit(1) | ||
} | ||
function loop (opts, cb) { | ||
var next = opts.targets.shift() | ||
if (!next) return cb() | ||
mkdirp.sync(builds) | ||
loop(null) | ||
run(opts.preinstall, opts.cmd, opts.env, function (err) { | ||
if (err) return cb(err) | ||
function loop (err) { | ||
if (err) throw err | ||
build(next.target, next.runtime, opts, function (err, filename) { | ||
if (err) return cb(err) | ||
var next = targets.shift() | ||
if (!next) return | ||
run(opts.postinstall, opts.cmd, opts.env, function (err) { | ||
if (err) return cb(err) | ||
run(argv.preinstall, function (err) { | ||
if (err) return loop(err) | ||
copySharedLibs(opts.output, opts.builds, opts, function (err) { | ||
if (err) return cb(err) | ||
build(next.target, next.runtime, function (err, filename) { | ||
if (err) return loop(err) | ||
var name = next.runtime + '-' + abi.getAbi(next.target, next.runtime) + '.node' | ||
var dest = path.join(opts.builds, name) | ||
run(argv.postinstall, function (err) { | ||
if (err) return loop(err) | ||
fs.rename(filename, dest, function (err) { | ||
if (err) return cb(err) | ||
copySharedLibs(output, builds, function (err) { | ||
if (err) return loop(err) | ||
var name = next.runtime + '-' + abi.getAbi(next.target, next.runtime) + '.node' | ||
var dest = path.join(builds, name) | ||
fs.rename(filename, dest, loop) | ||
loop(opts, cb) | ||
}) | ||
}) | ||
@@ -82,3 +69,3 @@ }) | ||
function copySharedLibs (builds, folder, cb) { | ||
function copySharedLibs (builds, folder, opts, cb) { | ||
fs.readdir(builds, function (err, files) { | ||
@@ -98,3 +85,3 @@ if (err) return cb() | ||
strip(path.join(builds, next), function (err) { | ||
strip(path.join(builds, next), opts, function (err) { | ||
if (err) return cb(err) | ||
@@ -107,3 +94,3 @@ copy(path.join(builds, next), path.join(folder, next), loop) | ||
function run (cmd, cb) { | ||
function run (cmd, cwd, env, cb) { | ||
if (!cmd) return cb() | ||
@@ -118,3 +105,3 @@ | ||
function build (target, runtime, cb) { | ||
function build (target, runtime, opts, cb) { | ||
var args = [ | ||
@@ -125,4 +112,4 @@ 'rebuild', | ||
if (argv.arch) { | ||
args.push('--target_arch=' + argv.arch) | ||
if (opts.arch) { | ||
args.push('--target_arch=' + opts.arch) | ||
} | ||
@@ -135,3 +122,3 @@ | ||
if (argv.debug) { | ||
if (opts.debug) { | ||
args.push('--debug') | ||
@@ -143,4 +130,4 @@ } else { | ||
var child = proc.spawn(os.platform() === 'win32' ? 'node-gyp.cmd' : 'node-gyp', args, { | ||
cwd: cwd, | ||
stdio: argv.quiet ? 'ignore' : 'inherit' | ||
cwd: opts.cwd, | ||
stdio: opts.quiet ? 'ignore' : 'inherit' | ||
}) | ||
@@ -151,6 +138,6 @@ | ||
findBuild(output, function (err, output) { | ||
findBuild(opts.output, function (err, output) { | ||
if (err) return cb(err) | ||
strip(output, function (err) { | ||
strip(output, opts, function (err) { | ||
if (err) return cb(err) | ||
@@ -176,6 +163,6 @@ cb(null, output) | ||
function strip (file, cb) { | ||
if (!argv.strip || platform !== 'darwin' && platform !== 'linux') return process.nextTick(cb) | ||
function strip (file, opts, cb) { | ||
if (!opts.strip || (opts.platform !== 'darwin' && opts.platform !== 'linux')) return cb() | ||
var args = platform === 'darwin' ? [file, '-Sx'] : [file, '--strip-all'] | ||
var args = opts.platform === 'darwin' ? [file, '-Sx'] : [file, '--strip-all'] | ||
var child = proc.spawn('strip', args, {stdio: 'ignore'}) | ||
@@ -182,0 +169,0 @@ |
{ | ||
"name": "prebuildify", | ||
"version": "2.2.2", | ||
"version": "2.3.0", | ||
"description": "Create and package prebuilds for native modules", | ||
@@ -14,9 +14,17 @@ "main": "index.js", | ||
"devDependencies": { | ||
"standard": "*" | ||
"nan": "^2.5.1", | ||
"standard": "^9.0.1", | ||
"tape": "^4.6.3" | ||
}, | ||
"bin": { | ||
"prebuildify": "./index.js" | ||
"prebuildify": "./bin.js" | ||
}, | ||
"files": [ | ||
"bin.js", | ||
"index.js" | ||
], | ||
"scripts": { | ||
"test": "standard" | ||
"lint": "standard", | ||
"test": "npm run lint && npm run unit", | ||
"unit": "tape test/*.js" | ||
}, | ||
@@ -23,0 +31,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9131
179
3