bin-build
Advanced tools
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); | ||
}; |
{ | ||
"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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
5
104
0
4536
5
32
+ Addedexeca@^0.7.0
+ Addedp-map-series@^1.0.0
+ Addedbase64-js@1.5.1(transitive)
+ Addedbuffer@5.7.1(transitive)
+ Addedcaw@2.0.1(transitive)
+ Addedconfig-chain@1.1.13(transitive)
+ Addedcontent-disposition@0.5.4(transitive)
+ Addedcross-spawn@5.1.0(transitive)
+ Addeddecompress@4.2.1(transitive)
+ Addeddecompress-response@3.3.0(transitive)
+ Addeddecompress-tar@4.1.1(transitive)
+ Addeddecompress-tarbz2@4.1.1(transitive)
+ Addeddecompress-targz@4.1.1(transitive)
+ Addeddecompress-unzip@4.0.1(transitive)
+ Addeddownload@6.2.5(transitive)
+ Addedduplexer3@0.1.5(transitive)
+ Addedexeca@0.7.0(transitive)
+ Addedext-list@2.2.2(transitive)
+ Addedext-name@5.0.0(transitive)
+ Addedfile-type@5.2.06.2.0(transitive)
+ Addedfilename-reserved-regex@2.0.0(transitive)
+ Addedfilenamify@2.1.0(transitive)
+ Addedget-proxy@2.1.0(transitive)
+ Addedget-stream@2.3.13.0.0(transitive)
+ Addedgot@7.1.0(transitive)
+ Addedhas-symbol-support-x@1.4.2(transitive)
+ Addedhas-to-string-tag-x@1.4.1(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedis-natural-number@4.0.1(transitive)
+ Addedis-object@1.0.2(transitive)
+ Addedis-plain-obj@1.1.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedisurl@1.0.0(transitive)
+ Addedlru-cache@4.1.5(transitive)
+ Addedmake-dir@1.3.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmimic-response@1.0.1(transitive)
+ Addednpm-conf@1.1.3(transitive)
+ Addednpm-run-path@2.0.2(transitive)
+ Addedp-cancelable@0.3.0(transitive)
+ Addedp-event@1.3.0(transitive)
+ Addedp-finally@1.0.0(transitive)
+ Addedp-map-series@1.0.0(transitive)
+ Addedp-reduce@1.0.0(transitive)
+ Addedp-timeout@1.2.1(transitive)
+ Addedpath-key@2.0.1(transitive)
+ Addedpify@2.3.03.0.0(transitive)
+ Addedproto-list@1.2.4(transitive)
+ Addedpseudomap@1.0.2(transitive)
+ Addedshebang-command@1.2.0(transitive)
+ Addedshebang-regex@1.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedsort-keys@1.1.2(transitive)
+ Addedsort-keys-length@1.0.1(transitive)
+ Addedstrip-dirs@2.1.0(transitive)
+ Addedstrip-eof@1.0.0(transitive)
+ Addedtemp-dir@1.0.0(transitive)
+ Addedtempfile@2.0.0(transitive)
+ Addedthrough@2.3.8(transitive)
+ Addedtimed-out@4.0.1(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedunbzip2-stream@1.4.3(transitive)
+ Addedurl-to-options@1.0.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedyallist@2.1.2(transitive)
- Removedarchive-type@^3.0.1
- Removedexec-series@^1.0.0
- Removedrimraf@^2.2.6
- Removedurl-regex@^3.0.0
- Removedansi-gray@0.1.1(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedansi-wrap@0.1.0(transitive)
- Removedarchive-type@3.2.0(transitive)
- Removedarr-diff@2.0.0(transitive)
- Removedarr-flatten@1.1.0(transitive)
- Removedarray-differ@1.0.0(transitive)
- Removedarray-uniq@1.0.3(transitive)
- Removedarray-unique@0.2.1(transitive)
- Removedasync-each-series@1.1.0(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbeeper@1.1.1(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbraces@1.8.5(transitive)
- Removedbuffer-from@1.1.2(transitive)
- Removedbuffer-to-vinyl@1.1.0(transitive)
- Removedcapture-stack-trace@1.0.2(transitive)
- Removedcaw@1.2.0(transitive)
- Removedchalk@1.1.3(transitive)
- Removedclone@0.2.01.0.4(transitive)
- Removedclone-stats@0.0.1(transitive)
- Removedco@3.1.0(transitive)
- Removedcolor-support@1.1.3(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedconcat-stream@1.6.2(transitive)
- Removedconvert-source-map@1.9.0(transitive)
- Removedcreate-error-class@3.0.2(transitive)
- Removeddateformat@2.2.0(transitive)
- Removeddecompress@3.0.0(transitive)
- Removeddecompress-tar@3.1.0(transitive)
- Removeddecompress-tarbz2@3.1.0(transitive)
- Removeddecompress-targz@3.1.0(transitive)
- Removeddecompress-unzip@3.4.0(transitive)
- Removeddeep-extend@0.6.0(transitive)
- Removeddownload@4.4.3(transitive)
- Removedduplexer2@0.0.20.1.4(transitive)
- Removedduplexify@3.7.1(transitive)
- Removedeach-async@1.1.1(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedexec-series@1.0.3(transitive)
- Removedexpand-brackets@0.1.5(transitive)
- Removedexpand-range@1.8.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextend-shallow@2.0.1(transitive)
- Removedextglob@0.3.2(transitive)
- Removedfancy-log@1.3.3(transitive)
- Removedfilename-regex@2.0.1(transitive)
- Removedfilename-reserved-regex@1.0.0(transitive)
- Removedfilenamify@1.2.1(transitive)
- Removedfill-range@2.2.4(transitive)
- Removedfirst-chunk-stream@1.0.0(transitive)
- Removedfor-in@1.0.2(transitive)
- Removedfor-own@0.1.5(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedget-proxy@1.1.0(transitive)
- Removedget-stdin@4.0.1(transitive)
- Removedglob@5.0.157.2.3(transitive)
- Removedglob-base@0.3.0(transitive)
- Removedglob-parent@2.0.03.1.0(transitive)
- Removedglob-stream@5.3.5(transitive)
- Removedglogg@1.0.2(transitive)
- Removedgot@5.7.1(transitive)
- Removedgulp-decompress@1.2.0(transitive)
- Removedgulp-rename@1.4.0(transitive)
- Removedgulp-sourcemaps@1.6.0(transitive)
- Removedgulp-util@3.0.8(transitive)
- Removedgulplog@1.0.0(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhas-gulplog@0.1.0(transitive)
- Removedinflight@1.0.6(transitive)
- Removedip-regex@1.0.3(transitive)
- Removedis-absolute@0.1.7(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-bzip2@1.0.0(transitive)
- Removedis-dotfile@1.0.3(transitive)
- Removedis-equal-shallow@0.1.3(transitive)
- Removedis-extendable@0.1.1(transitive)
- Removedis-extglob@1.0.02.1.1(transitive)
- Removedis-glob@2.0.13.1.0(transitive)
- Removedis-gzip@1.0.0(transitive)
- Removedis-natural-number@2.1.1(transitive)
- Removedis-number@2.1.04.0.0(transitive)
- Removedis-obj@1.0.1(transitive)
- Removedis-posix-bracket@0.1.1(transitive)
- Removedis-primitive@2.0.0(transitive)
- Removedis-redirect@1.0.0(transitive)
- Removedis-relative@0.1.3(transitive)
- Removedis-tar@1.0.0(transitive)
- Removedis-url@1.2.4(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedis-valid-glob@0.3.0(transitive)
- Removedis-zip@1.0.0(transitive)
- Removedisarray@0.0.1(transitive)
- Removedisobject@2.1.0(transitive)
- Removedjson-stable-stringify-without-jsonify@1.0.1(transitive)
- Removedkind-of@3.2.26.0.3(transitive)
- Removedlazystream@1.0.1(transitive)
- Removedlodash._basecopy@3.0.1(transitive)
- Removedlodash._basetostring@3.0.1(transitive)
- Removedlodash._basevalues@3.0.0(transitive)
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash._isiterateecall@3.0.9(transitive)
- Removedlodash._reescape@3.0.0(transitive)
- Removedlodash._reevaluate@3.0.0(transitive)
- Removedlodash._reinterpolate@3.0.0(transitive)
- Removedlodash._root@3.0.1(transitive)
- Removedlodash.escape@3.2.0(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedlodash.isarray@3.0.4(transitive)
- Removedlodash.isequal@4.5.0(transitive)
- Removedlodash.keys@3.1.2(transitive)
- Removedlodash.restparam@3.6.1(transitive)
- Removedlodash.template@3.6.2(transitive)
- Removedlodash.templatesettings@3.1.1(transitive)
- Removedmath-random@1.0.4(transitive)
- Removedmerge-stream@1.0.1(transitive)
- Removedmicromatch@2.3.11(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removedmultipipe@0.1.2(transitive)
- Removednode-status-codes@1.0.0(transitive)
- Removednormalize-path@2.1.1(transitive)
- Removedobject-assign@2.1.13.0.0(transitive)
- Removedobject.omit@2.0.1(transitive)
- Removedonetime@1.1.0(transitive)
- Removedordered-read-streams@0.3.0(transitive)
- Removedos-tmpdir@1.0.2(transitive)
- Removedparse-glob@3.0.4(transitive)
- Removedparse-json@2.2.0(transitive)
- Removedparse-node-version@1.0.1(transitive)
- Removedpath-dirname@1.0.2(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpreserve@0.2.0(transitive)
- Removedrandomatic@3.1.1(transitive)
- Removedrc@1.2.8(transitive)
- Removedread-all-stream@3.1.0(transitive)
- Removedreadable-stream@1.0.341.1.143.6.2(transitive)
- Removedregex-cache@0.4.4(transitive)
- Removedremove-trailing-separator@1.1.0(transitive)
- Removedrepeat-element@1.1.4(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedreplace-ext@0.0.1(transitive)
- Removedrimraf@2.7.1(transitive)
- Removedset-immediate-shim@1.0.1(transitive)
- Removedsparkles@1.0.1(transitive)
- Removedstat-mode@0.2.2(transitive)
- Removedstream-combiner2@1.1.1(transitive)
- Removedstream-shift@1.0.3(transitive)
- Removedstring_decoder@0.10.311.3.0(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedstrip-bom-stream@1.0.0(transitive)
- Removedstrip-dirs@1.1.1(transitive)
- Removedstrip-json-comments@2.0.1(transitive)
- Removedsum-up@1.0.3(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedtempfile@1.1.1(transitive)
- Removedthrough2@0.6.52.0.54.0.2(transitive)
- Removedthrough2-filter@2.0.03.1.0(transitive)
- Removedtime-stamp@1.1.0(transitive)
- Removedtimed-out@3.1.3(transitive)
- Removedto-absolute-glob@0.1.1(transitive)
- Removedtunnel-agent@0.4.3(transitive)
- Removedtypedarray@0.0.6(transitive)
- Removedunique-stream@2.3.1(transitive)
- Removedunzip-response@1.0.2(transitive)
- Removedurl-regex@3.2.0(transitive)
- Removeduuid@2.0.3(transitive)
- Removedvali-date@1.0.0(transitive)
- Removedvinyl@0.4.60.5.31.2.0(transitive)
- Removedvinyl-assign@1.2.1(transitive)
- Removedvinyl-fs@2.4.4(transitive)
- Removedware@1.3.0(transitive)
- Removedwrap-fn@0.1.5(transitive)
Updateddecompress@^4.0.0
Updateddownload@^6.2.2
Updatedtempfile@^2.0.0