Permalink
Browse files

start installing version tree from repositories

  • Loading branch information...
1 parent 00c63b7 commit 09dc48d142ee0f820859e0d8b8618aa6fc327881 @caolan caolan committed Feb 10, 2012
Showing with 76 additions and 7 deletions.
  1. +76 −7 lib/commands/install.js
View
@@ -80,28 +80,27 @@ exports.run = function (settings, args) {
*/
exports.install = function (pkg, opt, callback) {
- var cache = {};
if (/^https?:\/\//.test(pkg)) {
opt.target_dir = opt.target_dir || utils.abspath('packages');
logger.info('installing from URL', pkg);
- return exports.installURL(cache, pkg, opt, callback);
+ return exports.installURL(pkg, opt, callback);
}
fs.stat(pkg, function (err, stats) {
if (err) {
// may not be a file
opt.target_dir = opt.target_dir || utils.abspath('packages');
logger.info('installing from repositories', pkg);
- return exports.installName(cache, pkg, opt, callback);
+ return exports.installRepo(pkg, opt, callback);
}
if (stats.isDirectory()) {
opt.target_dir = opt.target_dir || utils.abspath('packages', pkg);
logger.info('installing from directory', pkg);
- return exports.installDir(cache, pkg, opt, callback);
+ return exports.installDir(pkg, opt, callback);
}
else if (stats.isFile()) {
opt.target_dir = opt.target_dir || utils.abspath('packages');
logger.info('installing from local file', pkg);
- return exports.installFile(cache, pkg, opt, callback);
+ return exports.installFile(pkg, opt, callback);
}
else {
return callback(new Error('Unknown install target: ' + pkg));
@@ -159,7 +158,7 @@ exports.repoSource = function (repositories) {
* @param {Function} callback
*/
-exports.installDir = function (cache, dir, opt, callback) {
+exports.installDir = function (dir, opt, callback) {
if (opt.no_deps) {
return callback();
}
@@ -187,8 +186,78 @@ exports.installDir = function (cache, dir, opt, callback) {
if (err) {
return callback(err);
}
- console.log(packages);
+ exports.installTree(packages, opt, callback);
});
});
});
};
+
+exports.installTree = function (packages, opt, callback) {
+ var names = Object.keys(packages);
+ async.forEachLimit(names, 5, function (name, cb) {
+ var curr = packages[name].current_version;
+ exports.installRepo(name, curr, opt, callback);
+ }, callback);
+};
+
+exports.installRepo = function (name, /*optional*/range, opt, callback) {
+ if (!callback) {
+ // arity 3
+ callback = opt;
+ opt = range;
+ range = null;
+ }
+ if (!range) {
+ if (name.indexOf('@') !== -1) {
+ var parts = name.split('@');
+ name = parts[0];
+ range = parts.slice(1).join('@');
+ }
+ else {
+ range = 'latest';
+ }
+ }
+ repository.fetch(name, range, opt.repositories,
+ function (err, tfile, cdir, v, cfg, from_cache) {
+ if (err) {
+ return callback(err);
+ }
+ logger.info(
+ 'installing',
+ name + '@' + v + (from_cache ? ' (cached)': '')
+ );
+ exports.cpDir(name, cdir, opt, callback);
+ }
+ );
+};
+
+exports.cpDir = function (name, cdir, opt, callback) {
+ var p = opt.target_dir + '/' + name;
+ function cp() {
+ utils.ensureDir(opt.target_dir, function (err) {
+ if (err) {
+ return callback(err);
+ }
+ logger.info('copying', cdir + ' => ' + p);
+ utils.cp('-r', cdir, p, function (err) {
+ return callback(err);
+ });
+ });
+ }
+ path.exists(p, function (exists) {
+ if (exists) {
+ logger.info('removing', name);
+ utils.rm('-rf', p, function (err) {
+ if (err) {
+ return callback(err);
+ }
+ process.nextTick(function () {
+ cp();
+ });
+ });
+ }
+ else {
+ cp();
+ }
+ });
+};

0 comments on commit 09dc48d

Please sign in to comment.