This commit is contained in:
chrosey
2017-09-13 07:52:34 +02:00
parent a1f16c37f4
commit 2340b0226b
24621 changed files with 2912161 additions and 149 deletions
+170
View File
@@ -0,0 +1,170 @@
'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');
/**
* Initialize new `BinBuild`
*
* @param {Object} opts
* @api public
*/
function BinBuild(opts) {
if (!(this instanceof BinBuild)) {
return new BinBuild(opts);
}
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;
};
/**
* Add a command to run
*
* @param {String} str
* @api public
*/
BinBuild.prototype.cmd = function (str) {
if (!arguments.length) {
return this._cmd;
}
this._cmd = this._cmd || [];
this._cmd.push(str);
return this;
};
/**
* Build
*
* @param {Function} cb
* @api public
*/
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));
}
fs.readFile(this.src(), function (err, data) {
if (err && err.code !== 'EISDIR') {
cb(err);
return;
}
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));
};
/**
* 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);
};
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Kevin Mårtensson <kevinmartensson@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+111
View File
@@ -0,0 +1,111 @@
{
"_args": [
[
{
"raw": "bin-build@^2.0.0",
"scope": null,
"escapedName": "bin-build",
"name": "bin-build",
"rawSpec": "^2.0.0",
"spec": ">=2.0.0 <3.0.0",
"type": "range"
},
"c:\\xampp\\htdocs\\laravel\\node_modules\\gifsicle"
]
],
"_from": "bin-build@>=2.0.0 <3.0.0",
"_id": "bin-build@2.2.0",
"_inCache": true,
"_location": "/bin-build",
"_nodeVersion": "4.2.1",
"_npmUser": {
"name": "shinnn",
"email": "snnskwtnb@gmail.com"
},
"_npmVersion": "3.3.8",
"_phantomChildren": {},
"_requested": {
"raw": "bin-build@^2.0.0",
"scope": null,
"escapedName": "bin-build",
"name": "bin-build",
"rawSpec": "^2.0.0",
"spec": ">=2.0.0 <3.0.0",
"type": "range"
},
"_requiredBy": [
"/gifsicle",
"/mozjpeg",
"/optipng-bin",
"/pngquant-bin"
],
"_resolved": "https://registry.npmjs.org/bin-build/-/bin-build-2.2.0.tgz",
"_shasum": "11f8dd61f70ffcfa2bdcaa5b46f5e8fedd4221cc",
"_shrinkwrap": null,
"_spec": "bin-build@^2.0.0",
"_where": "c:\\xampp\\htdocs\\laravel\\node_modules\\gifsicle",
"author": {
"name": "Kevin Mårtensson",
"email": "kevinmartensson@gmail.com",
"url": "https://github.com/kevva"
},
"bugs": {
"url": "https://github.com/kevva/bin-build/issues"
},
"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"
},
"description": "Easily build binaries",
"devDependencies": {
"ava": "^0.0.4",
"nock": "^2.6.0",
"path-exists": "^1.0.0",
"xo": "*"
},
"directories": {},
"dist": {
"shasum": "11f8dd61f70ffcfa2bdcaa5b46f5e8fedd4221cc",
"tarball": "https://registry.npmjs.org/bin-build/-/bin-build-2.2.0.tgz"
},
"engines": {
"node": ">=0.10.0"
},
"files": [
"index.js"
],
"gitHead": "81c4bb64c77cec50cc539ec44a279665404633f3",
"homepage": "https://github.com/kevva/bin-build#readme",
"keywords": [
"binary",
"build",
"make"
],
"license": "MIT",
"maintainers": [
{
"name": "kevva",
"email": "kevinmartensson@gmail.com"
},
{
"name": "shinnn",
"email": "snnskwtnb@gmail.com"
}
],
"name": "bin-build",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/kevva/bin-build.git"
},
"scripts": {
"test": "xo && node test/test.js"
},
"version": "2.2.0"
}
+69
View File
@@ -0,0 +1,69 @@
# bin-build [![Build Status](https://travis-ci.org/kevva/bin-build.svg?branch=master)](https://travis-ci.org/kevva/bin-build)
> Easily build binaries
## Install
```
$ npm install --save bin-build
```
## Usage
```js
var 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');
build.run(function (err) {
console.log('gifsicle built successfully');
});
```
## API
### new BinBuild(options)
Creates a new `BinBuild` instance.
#### options.strip
Type: `number`
Strip a number of leading paths from file names on extraction.
### .src(str)
#### str
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.
### .cmd(str)
#### str
Type: `string`
Add a command to run when building.
### .run(callback)
#### callback(err)
Type: `function`
Runs the build and returns an error if something has gone wrong
## License
MIT © [Kevin Mårtensson](https://github.com/kevva)