Cleanup package install related files.

Former-commit-id: ac905fe660af05077a52b001b295ee557aaacfa8
This commit is contained in:
John-David Dalton
2012-10-18 23:13:55 -07:00
parent 6452e5976b
commit e6f4935c7b
3 changed files with 43 additions and 54 deletions

View File

@@ -3,5 +3,5 @@ node_js:
- 0.6 - 0.6
- 0.8 - 0.8
before_script: before_script:
- "curl -H'Accept: application/vnd.github.v3.raw' https://api.github.com/repos/bestiejs/lodash/git/blobs/aa29a2ecf6f51d4da5a2a418c0d4ea0e368ee80d | tar xvz -Cvendor" - "curl -H 'Accept: application/vnd.github.v3.raw' https://api.github.com/repos/bestiejs/lodash/git/blobs/aa29a2ecf6f51d4da5a2a418c0d4ea0e368ee80d | tar xvz -C vendor"
- "curl -H'Accept: application/vnd.github.v3.raw' https://api.github.com/repos/bestiejs/lodash/git/blobs/827f406a02626c1c6723e8ae281b6785d36375c1 | tar xvz -Cvendor" - "curl -H 'Accept: application/vnd.github.v3.raw' https://api.github.com/repos/bestiejs/lodash/git/blobs/827f406a02626c1c6723e8ae281b6785d36375c1 | tar xvz -C vendor"

View File

@@ -8,10 +8,10 @@
path = require('path'), path = require('path'),
spawn = require('child_process').spawn; spawn = require('child_process').spawn;
/** The directory that is the base of the repository */ /** The path of the directory that is the base of the repository */
var basePath = fs.realpathSync(path.join(__dirname, '..')); var basePath = fs.realpathSync(path.join(__dirname, '..'));
/** The directory where the Closure Compiler is located */ /** The path of the directory where the Closure Compiler is located */
var closurePath = path.join(basePath, 'vendor', 'closure-compiler', 'compiler.jar'); var closurePath = path.join(basePath, 'vendor', 'closure-compiler', 'compiler.jar');
/** Load other modules */ /** Load other modules */

View File

@@ -3,82 +3,71 @@
'use strict'; 'use strict';
/** Load Node modules */ /** Load Node modules */
var fs = require('fs'), var exec = require('child_process').exec,
zlib = require('zlib'), fs = require('fs'),
path = require('path'),
https = require('https'), https = require('https'),
exec = require('child_process').exec, path = require('path'),
tar = require('tar'); tar = require('tar'),
zlib = require('zlib');
/** The directory that is the base of the repository */ /** The path of 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 */ /** The path of the `vendor` directory */
var vendorPath = path.join(basePath, 'vendor'); var vendorPath = path.join(basePath, 'vendor');
/** /**
* Fetches a required `.tar.gz` dependency with the given Git object ID from * 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 * the Lo-Dash repo on GitHub. The object ID may be obtained by running
* hash-object path/to/dependency.tar.gz`. * `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.
* *
* @param {String} objectId The Git object ID of the `.tar.gz` package.
* @param {String} The extraction target directory.
* @param {Function} callback The function to call once the extraction finishes.
*/ */
function getDependency(source, targets, callback) { function getDependency(objectId, targets, callback) {
https.get({ https.get({
'host': 'api.github.com', 'host': 'api.github.com',
'path': '/repos/bestiejs/lodash/git/blobs/' + source, 'path': '/repos/bestiejs/lodash/git/blobs/' + objectId,
'headers': { 'headers': {
'Accept': 'application/vnd.github.v3.raw' 'Accept': 'application/vnd.github.v3.raw'
} }
}, function(response) { }, function(response) {
var parser; var parser = new tar.Extract({
if (typeof targets == 'string') { 'path': targets
parser = new tar.Extract({ })
'path': targets .on('end', callback)
}); .on('error', callback);
} 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); response.pipe(zlib.createUnzip()).pipe(parser);
}).on('error', callback); })
.on('error', callback);
} }
exec('npm -g root', function(exception, stdout, stderr) { exec('npm -g root', function(exception, stdout, stderr) {
if (exception || stderr) { if (exception || stderr) {
console.error('There was a problem loading the npm registry.'); console.error('There was a problem loading the npm registry.');
process.exit(1); process.exit(1);
} else if (path.resolve(basePath, '..') == stdout.trim()) { }
// download Closure Compiler // exit early if not a global install
getDependency('aa29a2ecf6f51d4da5a2a418c0d4ea0e368ee80d', vendorPath, function(exception) { if (path.resolve(basePath, '..') != stdout.trim()) {
var statusCode = 0; return;
}
// download Closure Compiler
getDependency('aa29a2ecf6f51d4da5a2a418c0d4ea0e368ee80d', vendorPath, function(exception) {
var statusCode = 0;
if (exception) {
console.error('There was a problem downloading the Closure Compiler.');
statusCode = 1;
}
// download UglifyJS
getDependency('827f406a02626c1c6723e8ae281b6785d36375c1', vendorPath, function(exception) {
if (exception) { if (exception) {
console.error('There was a problem downloading the Closure Compiler.'); console.error('There was a problem downloading UglifyJS.');
statusCode = 1; statusCode = 1;
} }
// download UglifyJS process.exit(statusCode);
getDependency('827f406a02626c1c6723e8ae281b6785d36375c1', vendorPath, function(exception) {
if (exception) {
console.error('There was a problem downloading UglifyJS.');
statusCode = 1;
}
process.exit(statusCode);
});
}); });
} });
}); });
}()); }());