mirror of
https://github.com/bower/bower.git
synced 2026-02-11 22:44:58 -05:00
Implement link command.
Also: - CS fixes - Remove options argument from commands that do not have them - Use console.trace instead of err.stack (more reliable)
This commit is contained in:
@@ -112,19 +112,19 @@ Manager.prototype.install = function () {
|
||||
|
||||
mout.object.forOwn(that._dissected, function (decEndpoint, name) {
|
||||
var promise;
|
||||
var dest;
|
||||
var dst;
|
||||
var release = decEndpoint.pkgMeta._release;
|
||||
|
||||
that._logger.action('install', name + (release ? '#' + release : ''), that.toData(decEndpoint));
|
||||
|
||||
// Remove existent and copy canonical dir
|
||||
dest = path.join(componentsDir, name);
|
||||
decEndpoint.dest = dest;
|
||||
dst = path.join(componentsDir, name);
|
||||
decEndpoint.dst = dst;
|
||||
|
||||
promise = Q.nfcall(rimraf, dest)
|
||||
.then(copy.copyDir.bind(copy, decEndpoint.canonicalDir, dest))
|
||||
promise = Q.nfcall(rimraf, dst)
|
||||
.then(copy.copyDir.bind(copy, decEndpoint.canonicalDir, dst))
|
||||
.then(function () {
|
||||
var jsonFile = path.join(dest, '.bower.json');
|
||||
var jsonFile = path.join(dst, '.bower.json');
|
||||
|
||||
// Store _target in bower.json
|
||||
return Q.nfcall(fs.readFile, jsonFile)
|
||||
@@ -146,7 +146,7 @@ Manager.prototype.install = function () {
|
||||
// Resolve with meaningful data
|
||||
return mout.object.map(that._dissected, function (decEndpoint) {
|
||||
var pkg = this.toData(decEndpoint);
|
||||
pkg.canonicalDir = decEndpoint.dest;
|
||||
pkg.canonicalDir = decEndpoint.dst;
|
||||
return pkg;
|
||||
}, that);
|
||||
})
|
||||
|
||||
@@ -45,7 +45,7 @@ Project.prototype.install = function (endpoints, options) {
|
||||
.spread(function (json, tree) {
|
||||
// Walk down the tree adding targets, resolved and incompatibles
|
||||
that._walkTree(tree, function (node, name) {
|
||||
if (node.missing) {
|
||||
if (node.missing || node.linked) {
|
||||
targets.push(node);
|
||||
} else if (node.incompatible) {
|
||||
incompatibles.push(node);
|
||||
@@ -147,7 +147,7 @@ Project.prototype.update = function (names, options) {
|
||||
// Walk down the tree adding missing, incompatible
|
||||
// and resolved
|
||||
that._walkTree(tree, function (node, name) {
|
||||
if (node.missing) {
|
||||
if (node.missing || node.linked) {
|
||||
targets.push(node);
|
||||
} else if (node.incompatible) {
|
||||
incompatibles.push(node);
|
||||
@@ -158,7 +158,7 @@ Project.prototype.update = function (names, options) {
|
||||
|
||||
// Add root packages whose names are specified to be updated
|
||||
that._walkTree(tree, function (node, name) {
|
||||
if (!node.missing && names.indexOf(name) !== -1) {
|
||||
if (!node.missing && !node.linked && names.indexOf(name) !== -1) {
|
||||
targets.push(node);
|
||||
}
|
||||
}, true);
|
||||
@@ -301,7 +301,7 @@ Project.prototype.getTree = function () {
|
||||
.spread(function (json, tree, flattened) {
|
||||
var extraneous = [];
|
||||
|
||||
tree = this._manager.toData(tree, ['missing', 'incompatible']);
|
||||
tree = this._manager.toData(tree, ['missing', 'incompatible', 'linked']);
|
||||
tree.root = true;
|
||||
|
||||
mout.object.forOwn(flattened, function (pkg) {
|
||||
@@ -314,16 +314,21 @@ Project.prototype.getTree = function () {
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
Project.prototype.getJson = function () {
|
||||
return this._readJson();
|
||||
};
|
||||
|
||||
// -----------------
|
||||
|
||||
Project.prototype._analyse = function () {
|
||||
return Q.all([
|
||||
this._readJson(),
|
||||
this._readInstalled()
|
||||
this._readInstalled(),
|
||||
this._readLinks()
|
||||
])
|
||||
.spread(function (json, installed) {
|
||||
.spread(function (json, installed, links) {
|
||||
var root;
|
||||
var flattened = mout.object.mixIn({}, installed);
|
||||
var flattened = mout.object.mixIn({}, installed, links);
|
||||
|
||||
root = {
|
||||
name: json.name,
|
||||
@@ -478,18 +483,17 @@ Project.prototype._readInstalled = function () {
|
||||
dot: true
|
||||
})
|
||||
.then(function (filenames) {
|
||||
var promises = [];
|
||||
var promises;
|
||||
var decEndpoints = {};
|
||||
|
||||
// Foreach bower.json found
|
||||
filenames.forEach(function (filename) {
|
||||
var promise;
|
||||
promises = filenames.map(function (filename) {
|
||||
var name = path.dirname(filename);
|
||||
|
||||
filename = path.join(componentsDir, filename);
|
||||
|
||||
// Read package metadata
|
||||
promise = Q.nfcall(fs.readFile, filename)
|
||||
return Q.nfcall(fs.readFile, filename)
|
||||
.then(function (contents) {
|
||||
return JSON.parse(contents.toString());
|
||||
})
|
||||
@@ -503,8 +507,6 @@ Project.prototype._readInstalled = function () {
|
||||
};
|
||||
// Ignore if failed to read file
|
||||
}, function () {});
|
||||
|
||||
promises.push(promise);
|
||||
});
|
||||
|
||||
// Wait until all files have been read
|
||||
@@ -512,7 +514,47 @@ Project.prototype._readInstalled = function () {
|
||||
return Q.all(promises)
|
||||
.then(function () {
|
||||
return that._installed = decEndpoints;
|
||||
}.bind(this));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Project.prototype._readLinks = function () {
|
||||
var componentsDir;
|
||||
|
||||
// Read directory, looking for links
|
||||
componentsDir = path.join(this._config.cwd, this._config.directory);
|
||||
return Q.nfcall(fs.readdir, componentsDir)
|
||||
.then(function (filenames) {
|
||||
var promises;
|
||||
var decEndpoints = {};
|
||||
|
||||
// Filter only those that are links
|
||||
promises = filenames.map(function (filename) {
|
||||
var dir = path.join(componentsDir, filename);
|
||||
|
||||
return Q.nfcall(fs.lstat, dir)
|
||||
.then(function (stat) {
|
||||
if (stat.isSymbolicLink()) {
|
||||
decEndpoints[filename] = {
|
||||
name: filename,
|
||||
source: dir,
|
||||
target: '*',
|
||||
canonicalDir: dir,
|
||||
pkgMeta: {
|
||||
name: filename
|
||||
},
|
||||
linked: true
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Wait until all links have been read
|
||||
// and resolve with the decomposed endpoints
|
||||
return Q.all(promises)
|
||||
.then(function () {
|
||||
return decEndpoints;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user