Skip to content
This repository has been archived by the owner on Jan 31, 2019. It is now read-only.

Commit

Permalink
add install from file support
Browse files Browse the repository at this point in the history
  • Loading branch information
Caolan McMahon committed Feb 11, 2012
1 parent 8f76ddd commit 8672746
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions lib/commands/install.js
Expand Up @@ -14,6 +14,21 @@ var semver = require('semver'),
fs = require('fs');


/**
* TODO: before installing from file, be sure to manually add an entry to the
* version tree for that file otherwise when building the initial tree it might
* complain if the file is not in the repositories.
*
* Can test this by packing vertest/packages/testpkg1, removing and trying to
* install from the .tar.gz file
*
* TODO: review comments in tree module since the apis might have changed
* slightly
*
* TODO: refactor this module now because it won't get done otherwise
*/


exports.summary = 'Installs a package and its dependencies';

exports.usage = '' +
Expand Down Expand Up @@ -180,6 +195,11 @@ exports.installTree = function (packages, opt, callback) {
if (packages[name].versions[curr].source === 'repository') {
exports.installRepo(name, curr, opt, cb);
}
else if (packages[name].versions[curr].source === 'tmp') {
var v = packages[name].versions[curr];
logger.info('copying files', v.basename);
exports.cpDir(name, curr, false, v.path, opt, cb);
}
else {
process.nextTick(cb);
}
Expand Down Expand Up @@ -281,3 +301,78 @@ exports.cpDir = function (name, v, from_cache, cdir, opt, callback) {
}
});
};


exports.installFile = function (filename, opt, callback) {
var tmp = repository.TMP_DIR + '/' + path.basename(filename);
var tmp_extracted = repository.TMP_DIR + '/package';

// clean up tmp dir after attempted install, even if error
var _callback = callback;
var callback = function (err) {
var args = arguments;
var that = this;
utils.rm('-rf', [tmp, tmp_extracted], function (err2) {
if (err2) {
logger.error(err2);
}
_callback.apply(that, args);
});
};

async.series({
tmpdir: async.apply(utils.ensureDir, repository.TMP_DIR),
dir: async.apply(utils.ensureDir, opt.target_dir),
cp: function (cb) {
if (filename === tmp) {
// installing from a file in tmp already
return cb();
}
utils.cp('-r', filename, tmp, cb);
},
extract: async.apply(tar.extract, tmp),
cfg: async.apply(settings.load, tmp_extracted)
},
function (err, results) {
if (err) {
return callback(err);
}
var v = results.cfg.version;
var name = results.cfg.name;

kansorc.loadFile('.kansorc', function (err, _settings) {
if (err) {
return logger.error(err);
}
if (_settings.repositories && !opt.fixed_repositories) {
// overwrite repository list with package directory's list
opt.repositories = _settings.repositories;
}
settings.load('.', function (err, cfg) {
if (err) {
return callback(err);
}
var sources = [
exports.dirSource(opt.target_dir),
exports.repoSource(opt.repositories)
];
var packages = {};
packages[name] = tree.createPackage([]);
packages[name].current_version = results.cfg.version;
packages[name].versions[results.cfg.version] = {
source: 'tmp',
path: tmp_extracted,
basename: path.basename(filename),
config: results.cfg
};
var root = {config: cfg, source: 'root'}
tree.extend(root, sources, packages, function (err, packages) {
if (err) {
return callback(err);
}
exports.installTree(packages, opt, callback);
});
});
});
});
};

0 comments on commit 8672746

Please sign in to comment.