Tweaks to notifications.

This commit is contained in:
André Cruz
2013-05-23 23:43:11 +01:00
parent c4bfbd3f94
commit 382c857a4b
6 changed files with 54 additions and 32 deletions

View File

@@ -45,7 +45,7 @@ PackageRepository.prototype.fetch = function (decEndpoint) {
level: 'action',
tag: 'resolve',
resolver: resolver,
data: 'Resolving ' + resolver.getSource(),
data: resolver.getSource() + '#' + resolver.getTarget()
});
return that._resolve(resolver);
}
@@ -67,7 +67,7 @@ PackageRepository.prototype.fetch = function (decEndpoint) {
// Otherwise, we have to resolve it
deferred.notify({
level: 'info',
tag: 'not-cached',
tag: 'uncached',
data: 'No cached version for ' + resolver.getSource() + '#' + resolver.getTarget(),
});
deferred.notify({

View File

@@ -47,7 +47,7 @@ GitFsResolver.fetchRefs = function (source) {
cache = this._refs[source];
if (cache) {
// If cached value is a promise, simply return it
// This is to avoid duplicate fetches for the same source
// This avoids duplicate fetches for the same source
if (cache.then) {
return cache;
}

View File

@@ -56,7 +56,7 @@ GitRemoteResolver.fetchRefs = function (source) {
cache = this._refs[source];
if (cache) {
// If cached value is a promise, simply return it
// This is to avoid duplicate fetches for the same source
// This avoids duplicate fetches for the same source
if (cache.then) {
return cache;
}

View File

@@ -38,35 +38,25 @@ GitResolver.prototype._hasNew = function (canonicalPkg, pkgMeta) {
};
GitResolver.prototype._resolve = function () {
var that = this;
var deferred = Q.defer();
deferred.notify({
level: 'action',
tag: 'versions',
data: 'Finding resolution'
});
this._findResolution()
.then(function (resolution) {
deferred.notify({
level: 'action',
tag: 'checkout',
data: 'Checking out "' + (resolution.tag || resolution.branch || resolution.commit) + '"'
data: resolution.tag || resolution.branch || resolution.commit
});
return this._checkout()
return that._checkout()
// Always run cleanup after checkout to ensure that .git is removed!
// If it's not removed, problems might arise when the "tmp" module attempts
// to delete the temporary folder
.fin(function () {
deferred.notify({
level: 'action',
tag: 'cleanup',
data: 'Cleaning up git artifacts'
});
return this._cleanup();
}.bind(this));
}.bind(this))
return that._cleanup();
});
})
.then(deferred.resolve, deferred.reject, deferred.notify);
return deferred.promise;

View File

@@ -85,9 +85,7 @@ Resolver.prototype.resolve = function () {
// Resolve self
.then(this._resolve.bind(this))
// Read json, generating the package meta
.then(function () {
return that._readJson(that._tempDir);
})
.then(this._readJson.bind(this, this._tempDir))
.then(function (meta) {
return Q.all([
// Apply package meta
@@ -158,7 +156,7 @@ Resolver.prototype._readJson = function (dir) {
level: 'warn',
tag: 'deprecated',
json: filename,
data: 'Package "' + this._name + '" is using the deprecated component.json file'
data: 'Package ' + this._name + ' is using the deprecated component.json file'
});
}

View File

@@ -92,9 +92,18 @@ UrlResolver.prototype._resolve = function () {
return Q.reject(createError('URL sources can\'t resolve targets', 'ENORESTARGET'));
}
// Download
return this._download()
// Parse headers
.spread(this._parseHeaders.bind(this))
.spread(this._extract.bind(this))
// Extract file
.spread(function (file, response) {
return this._extract(file, response)
.progress(function (notification) {
return notification;
});
}.bind(this))
// Rename file to index
.then(this._rename.bind(this));
};
@@ -102,13 +111,23 @@ UrlResolver.prototype._resolve = function () {
UrlResolver.prototype._download = function () {
var file = path.join(this._tempDir, path.basename(this._source));
var deferred = Q.defer();
var reqHeaders = {};
var that = this;
var deferred = Q.defer();
if (this._config.userAgent) {
reqHeaders['User-Agent'] = this._config.userAgent;
}
process.nextTick(function () {
deferred.notify({
level: 'action',
tag: 'download',
data: that._source,
url: that._source
});
});
// Download the file
request(this._source, {
proxy: this._remote.protocol === 'https:' ? this._config.httpsProxy : this._config.proxy,
@@ -118,15 +137,15 @@ UrlResolver.prototype._download = function () {
agent: false // Do not use keep alive, solves #437
})
.on('response', function (response) {
this._response = response;
}.bind(this))
that._response = response;
})
.on('error', deferred.reject)
// Pipe read stream to write stream
.pipe(fs.createWriteStream(file))
.on('error', deferred.reject)
.on('close', function () {
deferred.resolve([file, this._response]);
}.bind(this));
deferred.resolve([file, that._response]);
});
return deferred.promise;
};
@@ -174,6 +193,7 @@ UrlResolver.prototype._parseHeaders = function (file, response) {
UrlResolver.prototype._extract = function (file, response) {
var mimeType = response.headers['content-type'];
var deferred;
if (mimeType) {
// Clean everything after ; and trim the end result
@@ -184,9 +204,23 @@ UrlResolver.prototype._extract = function (file, response) {
return Q.resolve();
}
return extract(file, this._tempDir, {
mimeType: mimeType
deferred = Q.defer();
process.nextTick(function () {
deferred.notify({
level: 'action',
tag: 'extract',
data: path.basename(file),
file: file
});
});
extract(file, this._tempDir, {
mimeType: mimeType
})
.then(deferred.resolve, deferred.reject, deferred.notify);
return deferred.promise;
};
UrlResolver.prototype._rename = function () {