mirror of
https://github.com/bower/bower.git
synced 2026-04-24 03:00:19 -04:00
[WIP] Errors improvement.
This commit is contained in:
@@ -36,17 +36,43 @@ var Manager = function (endpoints, opts) {
|
||||
this.endpoints = endpoints || [];
|
||||
this.unitWork = new UnitWork;
|
||||
this.opts = opts || {};
|
||||
this.errors = {};
|
||||
};
|
||||
|
||||
Manager.prototype = Object.create(events.EventEmitter.prototype);
|
||||
Manager.prototype.constructor = Manager;
|
||||
|
||||
Manager.prototype.loadJSON = function () {
|
||||
var json = path.join(this.cwd, config.json);
|
||||
fileExists(json, function (exists) {
|
||||
if (!exists) {
|
||||
// If the json does not exist, assume one
|
||||
this.json = {
|
||||
name: path.basename(this.cwd),
|
||||
version: '0.0.0'
|
||||
},
|
||||
this.name = this.json.name;
|
||||
this.version = this.json.version;
|
||||
return this.emit('loadJSON');
|
||||
}
|
||||
|
||||
fs.readFile(json, 'utf8', function (err, json) {
|
||||
if (err) return this.emit('error', err);
|
||||
this.json = JSON.parse(json);
|
||||
this.name = json.name;
|
||||
this.version = json.version;
|
||||
this.emit('loadJSON');
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
Manager.prototype.resolve = function () {
|
||||
var resolved = function () {
|
||||
// If there is errors, report them
|
||||
if (this.errors) return this.reportErrors();
|
||||
// If there is an error while pruning (conflict) then abort installation
|
||||
if (!this.prune()) return this.emit('resolve');
|
||||
this.on('install', this.emit.bind(this, 'resolve'));
|
||||
this.install();
|
||||
this.once('install', this.emit.bind(this, 'resolve')).install();
|
||||
}.bind(this);
|
||||
|
||||
this.once('resolveLocal', function () {
|
||||
@@ -84,32 +110,12 @@ Manager.prototype.resolveEndpoints = function () {
|
||||
var pkg = new Package(name, endpoint, this);
|
||||
this.dependencies[name] = this.dependencies[name] || [];
|
||||
this.dependencies[name].push(pkg);
|
||||
pkg.on('resolve', next).resolve();
|
||||
}.bind(this), this.emit.bind(this, 'resolveEndpoints'));
|
||||
};
|
||||
|
||||
Manager.prototype.loadJSON = function () {
|
||||
var json = path.join(this.cwd, config.json);
|
||||
fileExists(json, function (exists) {
|
||||
if (!exists) {
|
||||
// If the json does not exist, assume one
|
||||
this.json = {
|
||||
name: path.basename(this.cwd),
|
||||
version: '0.0.0'
|
||||
},
|
||||
this.name = this.json.name;
|
||||
this.version = this.json.version;
|
||||
return this.emit('loadJSON');
|
||||
}
|
||||
|
||||
fs.readFile(json, 'utf8', function (err, json) {
|
||||
if (err) return this.emit('error', err);
|
||||
this.json = JSON.parse(json);
|
||||
this.name = json.name;
|
||||
this.version = json.version;
|
||||
this.emit('loadJSON');
|
||||
pkg.once('resolve', next).resolve();
|
||||
pkg.once('error', function (err) {
|
||||
this.errors[pkg.name] = err;
|
||||
next();
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
}.bind(this), this.emit.bind(this, 'resolveEndpoints'));
|
||||
};
|
||||
|
||||
Manager.prototype.resolveFromJson = function () {
|
||||
@@ -126,7 +132,11 @@ Manager.prototype.resolveFromJson = function () {
|
||||
var pkg = new Package(name, endpoint, this);
|
||||
this.dependencies[name] = this.dependencies[name] || [];
|
||||
this.dependencies[name].push(pkg);
|
||||
pkg.on('resolve', next).resolve();
|
||||
pkg.once('resolve', next).resolve();
|
||||
pkg.once('error', function (err) {
|
||||
this.errors[pkg.name] = err;
|
||||
next();
|
||||
}.bind(this));
|
||||
}.bind(this), this.emit.bind(this, 'resolveFromJson'));
|
||||
|
||||
}.bind(this)).loadJSON();
|
||||
@@ -166,4 +176,8 @@ Manager.prototype.install = function () {
|
||||
return this;
|
||||
};
|
||||
|
||||
Manager.prototype.reportErrors = function () {
|
||||
console.log(this.errors);
|
||||
};
|
||||
|
||||
module.exports = Manager;
|
||||
@@ -241,7 +241,7 @@ Package.prototype.loadJSON = function () {
|
||||
fileExists(jsonFile, function (exists) {
|
||||
// If the json does not exists, we attempt to at least get the version
|
||||
if (!exists) {
|
||||
return this.on('describeTag', function (tag) {
|
||||
return this.once('describeTag', function (tag) {
|
||||
tag = semver.clean(tag);
|
||||
if (!tag) this.version = this.tag;
|
||||
else {
|
||||
@@ -555,7 +555,7 @@ Package.prototype.describeTag = function () {
|
||||
};
|
||||
|
||||
Package.prototype.versions = function () {
|
||||
this.on('fetch', function () {
|
||||
this.once('fetch', function () {
|
||||
var cp = spawn('git', ['tag'], { cwd: this.gitPath });
|
||||
|
||||
var versions = '';
|
||||
|
||||
Reference in New Issue
Block a user