mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
Move dependency downloading into a post-install script.
Former-commit-id: c85d930fe4be787d6583015aa79d922d8909367e
This commit is contained in:
@@ -2,30 +2,22 @@
|
|||||||
;(function() {
|
;(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/** The Node filesystem, `zlib`, path, child process, and HTTPS modules */
|
/** The Node filesystem, path, `zlib`, and child process modules */
|
||||||
var fs = require('fs'),
|
var fs = require('fs'),
|
||||||
zlib = require('zlib'),
|
gzip = require('zlib').gzip,
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
spawn = require('child_process').spawn,
|
spawn = require('child_process').spawn;
|
||||||
https = require('https');
|
|
||||||
|
|
||||||
/** The directory that is the base of the repository */
|
/** The directory that is the base of the repository */
|
||||||
var basePath = fs.realpathSync(path.join(__dirname, '..'));
|
var basePath = fs.realpathSync(path.join(__dirname, '..'));
|
||||||
|
|
||||||
/** The `vendor` directory */
|
|
||||||
var vendorPath = path.join(basePath, 'vendor');
|
|
||||||
|
|
||||||
/** The directory where the Closure Compiler is located */
|
/** The directory where the Closure Compiler is located */
|
||||||
var closurePath = path.join(vendorPath, 'closure-compiler', 'compiler.jar');
|
var closurePath = path.join(basePath, 'vendor', 'closure-compiler', 'compiler.jar');
|
||||||
|
|
||||||
/** The directory where UglifyJS is located */
|
|
||||||
var uglifyPath = path.join(vendorPath, 'uglifyjs', 'uglify-js.js');
|
|
||||||
|
|
||||||
/** Load other modules */
|
/** Load other modules */
|
||||||
var preprocess = require('./pre-compile'),
|
var preprocess = require('./pre-compile'),
|
||||||
postprocess = require('./post-compile'),
|
postprocess = require('./post-compile'),
|
||||||
tar = require('tar'),
|
uglifyJS = require('../vendor/uglifyjs/uglify-js');
|
||||||
uglifyJS = null;
|
|
||||||
|
|
||||||
/** Closure Compiler command-line options */
|
/** Closure Compiler command-line options */
|
||||||
var closureOptions = [
|
var closureOptions = [
|
||||||
@@ -38,50 +30,6 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches a required `.tar.gz` dependency with the given Git object ID from
|
|
||||||
* the Lo-Dash repo on GitHub. The object ID may be obtained by running `git
|
|
||||||
* hash-object path/to/dependency.tar.gz`.
|
|
||||||
*
|
|
||||||
* @param {String} source The Git object ID of the `.tar.gz` package.
|
|
||||||
* @param {String|Object} The extraction target directory, or an object
|
|
||||||
* containing archived file names and target paths as key-value pairs.
|
|
||||||
* @param {Function} callback The function to call once the extraction
|
|
||||||
* finishes.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function getDependency(source, targets, callback) {
|
|
||||||
https.get({
|
|
||||||
'host': 'api.github.com',
|
|
||||||
'path': '/repos/bestiejs/lodash/git/blobs/' + source,
|
|
||||||
'headers': {
|
|
||||||
'Accept': 'application/vnd.github.v3.raw'
|
|
||||||
}
|
|
||||||
}, function(response) {
|
|
||||||
var parser;
|
|
||||||
if (typeof targets == 'string') {
|
|
||||||
parser = new tar.Extract({
|
|
||||||
'path': targets
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
parser = new tar.Parse();
|
|
||||||
parser.on('entry', function(entry) {
|
|
||||||
var path = entry.path;
|
|
||||||
if (path in targets) {
|
|
||||||
entry.pipe(fs.createWriteStream(targets[path]));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
parser.on('end', function() {
|
|
||||||
callback(null, targets);
|
|
||||||
});
|
|
||||||
parser.on('error', callback);
|
|
||||||
response.pipe(zlib.createUnzip()).pipe(parser);
|
|
||||||
}).on('error', callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The exposed `minify` function minifies a given Lo-Dash `source` and invokes
|
* The exposed `minify` function minifies a given Lo-Dash `source` and invokes
|
||||||
* the `onComplete` callback when finished.
|
* the `onComplete` callback when finished.
|
||||||
@@ -166,15 +114,6 @@
|
|||||||
* @param {Function} callback The function to call once the process completes.
|
* @param {Function} callback The function to call once the process completes.
|
||||||
*/
|
*/
|
||||||
function closureCompile(source, message, callback) {
|
function closureCompile(source, message, callback) {
|
||||||
if (!fs.existsSync(closurePath)) {
|
|
||||||
return getDependency('aa29a2ecf6f51d4da5a2a418c0d4ea0e368ee80d', vendorPath, function(exception) {
|
|
||||||
if (exception) {
|
|
||||||
callback(exception);
|
|
||||||
}
|
|
||||||
closureCompile.call(this, source, message, callback)
|
|
||||||
}.bind(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
var options = closureOptions.slice();
|
var options = closureOptions.slice();
|
||||||
|
|
||||||
// use simple optimizations when minifying template files
|
// use simple optimizations when minifying template files
|
||||||
@@ -238,19 +177,6 @@
|
|||||||
* @param {Function} callback The function to call once the process completes.
|
* @param {Function} callback The function to call once the process completes.
|
||||||
*/
|
*/
|
||||||
function uglify(source, message, callback) {
|
function uglify(source, message, callback) {
|
||||||
if (!uglifyJS) {
|
|
||||||
if (fs.existsSync(uglifyPath)) {
|
|
||||||
uglifyJS = require(uglifyPath);
|
|
||||||
} else {
|
|
||||||
return getDependency('827f406a02626c1c6723e8ae281b6785d36375c1', vendorPath, function(exception) {
|
|
||||||
if (exception) {
|
|
||||||
callback(exception);
|
|
||||||
}
|
|
||||||
uglify.call(this, source, message, callback);
|
|
||||||
}.bind(this));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var exception,
|
var exception,
|
||||||
result,
|
result,
|
||||||
ugly = uglifyJS.uglify;
|
ugly = uglifyJS.uglify;
|
||||||
@@ -303,7 +229,7 @@
|
|||||||
}
|
}
|
||||||
// store the post-processed Closure Compiler result and gzip it
|
// store the post-processed Closure Compiler result and gzip it
|
||||||
this.compiled.source = result = postprocess(result);
|
this.compiled.source = result = postprocess(result);
|
||||||
zlib.gzip(result, onClosureGzip.bind(this));
|
gzip(result, onClosureGzip.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -341,7 +267,7 @@
|
|||||||
}
|
}
|
||||||
// store the post-processed Uglified result and gzip it
|
// store the post-processed Uglified result and gzip it
|
||||||
this.uglified.source = result = postprocess(result);
|
this.uglified.source = result = postprocess(result);
|
||||||
zlib.gzip(result, onUglifyGzip.bind(this));
|
gzip(result, onUglifyGzip.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -380,7 +306,7 @@
|
|||||||
}
|
}
|
||||||
// store the post-processed Uglified result and gzip it
|
// store the post-processed Uglified result and gzip it
|
||||||
this.hybrid.source = result = postprocess(result);
|
this.hybrid.source = result = postprocess(result);
|
||||||
zlib.gzip(result, onHybridGzip.bind(this));
|
gzip(result, onHybridGzip.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -50,6 +50,7 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node build",
|
"build": "node build",
|
||||||
"test": "node test/test && node test/test-build"
|
"test": "node test/test && node test/test-build",
|
||||||
|
"install": "node build/post-install"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user