Minor tweaks.

This commit is contained in:
André Cruz
2013-04-14 17:18:59 +01:00
parent 643f4fddf9
commit 85d2a33620
7 changed files with 22 additions and 65 deletions

View File

@@ -35,13 +35,13 @@ Resolver.prototype.getTempDir = function () {
};
Resolver.prototype.resolve = function () {
// 1nd - Create temporary dir
// Create temporary dir
return this._createTempDir()
// 2nd - Resolve self
// Resolve self
.then(this._resolveSelf.bind(this))
// 3th - Read json
// Read json
.then(this._readJson.bind(this))
// 4th - Parse json
// Parse json
.then(this._parseJson.bind(this));
};

View File

@@ -6,18 +6,19 @@ var UrlResolver = require('./resolvers/UrlResolver');
function createResolver(endpoint, options) {
var split = endpoint.split('#'),
source,
target;
// Extract the range from the endpoint
endpoint = split[0];
// Extract the source and target from the endpoint
source = split[0];
target = split[1];
// Ensure options
options = options || {};
options.target = options.target || target;
// TODO: analyze endpoint and create appropriate package
return Q.fcall(new GitRemoteResolver(endpoint, options));
// TODO: analyze source and create appropriate package
return Q.fcall(new GitRemoteResolver(source, options));
}
module.exports = createResolver;

View File

@@ -11,37 +11,16 @@ util.inherits(FsResolver, Resolver);
// -----------------
FsResolver.prototype._resolveSelf = function () {
var promise;
console.log('_resolveSelf of fs resolver');
promise = this.copy()
return this._copy()
.then(this._extract.bind(this));
return promise;
};
FsResolver.prototype._copy = function () {
var deferred = Q.defer();
console.log('_download');
setTimeout(function () {
deferred.resolve();
}, 1000);
return deferred.promise;
};
FsResolver.prototype._extract = function () {
var deferred = Q.defer();
// If the file extension is not a zip and a tar, resolve the promise on next tick
console.log('_extract');
setTimeout(function () {
deferred.resolve();
}, 1000);
return deferred.promise;
};
module.exports = FsResolver;

View File

@@ -77,7 +77,7 @@ GitFsResolver.prototype._checkout = function (resolution) {
// -----------------
// Override the fetch refs to grab them locally
// Grab refs locally
GitFsResolver.fetchRefs = function (source) {
if (this._refs && this._refs[source]) {
return Q.resolve(this._refs[source]);

View File

@@ -42,6 +42,7 @@ GitRemoteResolver.prototype._checkout = function (resolution) {
// ------------------------------
// Grab refs remotely
GitRemoteResolver.fetchRefs = function (source) {
if (this._refs && this._refs[source]) {
return Q.resolve(this._refs[source]);

View File

@@ -9,6 +9,8 @@ var GitResolver = function (source, options) {
Resolver.call(this, source, options);
// Set the source path to be the same as the original source by default
// The source path is the real location of the repository since it
// can be infered from the source or simply a different one
this._sourcePath = this._source;
};
@@ -19,13 +21,13 @@ util.inherits(GitResolver, Resolver);
GitResolver.prototype.hasNew = function (oldTarget, oldResolution) {
return this._findResolution()
.then(function (resolution) {
// Resolution types are different
// Check if resolution types are different
if (oldResolution.type !== resolution.type) {
return true;
}
// If resolved to a tag
// There is new content if the tags are not equal
// If resolved to a tag, there is new content
// if the tags are not equal
if (resolution.type === 'tag') {
return semver.neq(resolution.tag, oldResolution.tag);
}
@@ -63,20 +65,15 @@ GitResolver.prototype._findResolution = function () {
}.bind(this));
}
// Resolve the rest to a commit version
promise = self.fetchHeads(this._sourcePath);
// Target is a commit, so it's a stale target (not a moving target)
// There's nothing to do in this case
if ((/^[a-f0-9]{40}$/).test(this._target)) {
return Q.resolve({ type: 'commit', commit: this._target });
}
// If target is *, use master branch
target = this._target === '*' ? 'master' : this._target;
// Target is a branch
return promise.then(function (heads) {
// Otherwise, assume target is a branch
return self.fetchHeads(this._sourcePath)
.then(function (heads) {
if (!heads[target]) {
branches = Object.keys(heads);
throw createError('Branch "' + target + '" does not exist', 'ENORESTARGET', {
@@ -106,7 +103,7 @@ GitResolver.fetchVersions = function (source) {
.then(function (refs) {
var versions = [];
// Parse each ref line, extracting the tag
// Foreach line in the refs, match only the tags
refs.forEach(function (line) {
var match = line.match(/^[a-f0-9]{40}\s+refs\/tags\/(\S+)/),
cleaned;

View File

@@ -11,37 +11,16 @@ util.inherits(UrlResolver, Resolver);
// -----------------
UrlResolver.prototype._resolveSelf = function () {
var promise;
console.log('_resolveSelf of url resolver');
promise = this._download()
return this._download()
.then(this._extract.bind(this));
return promise;
};
UrlResolver.prototype._download = function () {
var deferred = Q.defer();
console.log('_download');
setTimeout(function () {
deferred.resolve();
}, 1000);
return deferred.promise;
};
UrlResolver.prototype._extract = function () {
var deferred = Q.defer();
// If the file extension is not a zip and a tar, resolve the promise on next tick
console.log('_extract');
setTimeout(function () {
deferred.resolve();
}, 1000);
return deferred.promise;
};
module.exports = UrlResolver;