Socket
Socket
Sign inDemoInstall

bin-build

Package Overview
Dependencies
102
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.0 to 3.0.0

177

index.js
'use strict';
var fs = require('fs');
var archiveType = require('archive-type');
var execSeries = require('exec-series');
var Decompress = require('decompress');
var Download = require('download');
var rimraf = require('rimraf');
var tempfile = require('tempfile');
var urlRegex = require('url-regex');
const decompress = require('decompress');
const download = require('download');
const execa = require('execa');
const pMapSeries = require('p-map-series');
const tempfile = require('tempfile');
/**
* Initialize new `BinBuild`
*
* @param {Object} opts
* @api public
*/
const exec = (cmd, cwd) => pMapSeries(cmd, x => execa.shell(x, {cwd}));
function BinBuild(opts) {
if (!(this instanceof BinBuild)) {
return new BinBuild(opts);
exports.directory = (dir, cmd) => {
if (typeof dir !== 'string') {
return Promise.reject(new TypeError(`Expected a \`string\`, got \`${typeof dir}\``));
}
this.opts = opts || {};
this.tmp = tempfile();
if (this.opts.strip <= 0) {
this.opts.strip = 0;
} else if (!this.opts.strip) {
this.opts.strip = 1;
}
}
module.exports = BinBuild;
/**
* Define the source archive to download
*
* @param {String} str
* @api public
*/
BinBuild.prototype.src = function (str) {
if (!arguments.length) {
return this._src;
}
this._src = str;
return this;
return exec(cmd, dir);
};
/**
* Add a command to run
*
* @param {String} str
* @api public
*/
exports.file = (file, cmd, opts) => {
opts = Object.assign({strip: 1}, opts);
BinBuild.prototype.cmd = function (str) {
if (!arguments.length) {
return this._cmd;
if (typeof file !== 'string') {
return Promise.reject(new TypeError(`Expected a \`string\`, got \`${typeof file}\``));
}
this._cmd = this._cmd || [];
this._cmd.push(str);
const tmp = tempfile();
return this;
return decompress(file, tmp, opts).then(() => exec(cmd, tmp));
};
/**
* Build
*
* @param {Function} cb
* @api public
*/
exports.url = (url, cmd, opts) => {
opts = Object.assign({
extract: true,
strip: 1
}, opts);
BinBuild.prototype.run = function (cb) {
cb = cb || function () {};
if (urlRegex().test(this.src())) {
return this.download(function (err) {
if (err) {
cb(err);
return;
}
this.exec(this.tmp, cb);
}.bind(this));
if (typeof url !== 'string') {
return Promise.reject(new TypeError(`Expected a \`string\`, got \`${typeof url}\``));
}
fs.readFile(this.src(), function (err, data) {
if (err && err.code !== 'EISDIR') {
cb(err);
return;
}
const tmp = tempfile();
if (archiveType(data)) {
this.extract(function (err) {
if (err) {
cb(err);
return;
}
this.exec(this.tmp, cb);
}.bind(this));
return;
}
this.exec(this.src(), cb);
}.bind(this));
return download(url, tmp, opts).then(() => exec(cmd, tmp));
};
/**
* Execute commands
*
* @param {String} cwd
* @param {Function} cb
* @api private
*/
BinBuild.prototype.exec = function (cwd, cb) {
execSeries(this.cmd(), {cwd: cwd}, function (err) {
if (err) {
err.message = [this.cmd().join(' && '), err.message].join('\n');
cb(err);
return;
}
rimraf(this.tmp, cb);
}.bind(this));
};
/**
* Decompress source
*
* @param {Function} cb
* @api private
*/
BinBuild.prototype.extract = function (cb) {
var decompress = new Decompress({
mode: '777',
strip: this.opts.strip
});
decompress
.src(this.src())
.dest(this.tmp)
.run(cb);
};
/**
* Download source file
*
* @param {Function} cb
* @api private
*/
BinBuild.prototype.download = function (cb) {
var download = new Download({
strip: this.opts.strip,
extract: true,
mode: '777'
});
download
.get(this.src())
.dest(this.tmp)
.run(cb);
};

28

package.json
{
"name": "bin-build",
"version": "2.2.0",
"version": "3.0.0",
"description": "Easily build binaries",

@@ -13,6 +13,6 @@ "license": "MIT",

"engines": {
"node": ">=0.10.0"
"node": ">=4"
},
"scripts": {
"test": "xo && node test/test.js"
"test": "xo && ava"
},

@@ -28,16 +28,18 @@ "files": [

"dependencies": {
"archive-type": "^3.0.1",
"decompress": "^3.0.0",
"download": "^4.1.2",
"exec-series": "^1.0.0",
"rimraf": "^2.2.6",
"tempfile": "^1.0.0",
"url-regex": "^3.0.0"
"decompress": "^4.0.0",
"download": "^6.2.2",
"execa": "^0.7.0",
"p-map-series": "^1.0.0",
"tempfile": "^2.0.0"
},
"devDependencies": {
"ava": "^0.0.4",
"nock": "^2.6.0",
"path-exists": "^1.0.0",
"ava": "*",
"del": "^3.0.0",
"nock": "^9.0.0",
"path-exists": "^3.0.0",
"xo": "*"
},
"xo": {
"esnext": true
}
}

@@ -16,11 +16,16 @@ # bin-build [![Build Status](https://travis-ci.org/kevva/bin-build.svg?branch=master)](https://travis-ci.org/kevva/bin-build)

```js
var BinBuild = require('bin-build');
const binBuild = require('bin-build');
var build = new BinBuild()
.src('http://www.lcdf.org/gifsicle/gifsicle-1.80.tar.gz')
.cmd('./configure --disable-gifview --disable-gifdiff')
.cmd('make install');
binBuild.url('http://www.lcdf.org/gifsicle/gifsicle-1.80.tar.gz', [
'./configure --disable-gifview --disable-gifdiff',
'make install'
]).then(() => {
console.log('gifsicle built successfully');
});
build.run(function (err) {
console.log('gifsicle built successfully');
binBuild.file('gifsicle-1.80.tar.gz', [
'./configure --disable-gifview --disable-gifdiff',
'make install'
]).then(() => {
console.log('gifsicle built successfully');
});

@@ -32,40 +37,69 @@ ```

### new BinBuild(options)
### binBuild.directory(directory, commands)
Creates a new `BinBuild` instance.
#### directory
#### options.strip
Type: `string`
Type: `number`
Path to a directory containing the source code.
Strip a number of leading paths from file names on extraction.
#### commands
### .src(str)
Type: `Array`
#### str
Commands to run when building.
### binBuild.file(file, commands, [options])
#### file
Type: `string`
Accepts a URL to a archive containing the source code, a path to an archive or a
path to a directory containing the source code.
Path to a archive file containing the source code.
### .cmd(str)
#### commands
#### str
Type: `Array`
Commands to run when building.
#### options
Type: `Object`
##### strip
Type: `number`<br>
Default: `1`
Strip a number of leading paths from file names on extraction.
### binBuild.url(url, commands, [options])
#### url
Type: `string`
Add a command to run when building.
URL to a archive file containing the source code.
### .run(callback)
#### commands
#### callback(err)
Type: `Array`
Type: `function`
Commands to run when building.
Runs the build and returns an error if something has gone wrong
#### options
Type: `Object`
##### strip
Type: `number`<br>
Default: `1`
Strip a number of leading paths from file names on extraction.
## License
MIT © [Kevin Mårtensson](https://github.com/kevva)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc