-
-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
168 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* Contains update helpers. | ||
* | ||
* @since 3.0.0 | ||
* @fires pre-bootstrap | ||
* @module update | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// Modules | ||
var _ = require('./node')._; | ||
var GitHubApi = require('github'); | ||
var Promise = require('./promise'); | ||
var semver = require('./node').semver; | ||
|
||
/** | ||
* Compares two versions | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
exports.updateAvailable = function(version1, version2) { | ||
return semver.lt(version1, version2); | ||
}; | ||
|
||
/** | ||
* Determines whether we need to fetch updatest or not | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
exports.fetch = function(data) { | ||
|
||
// Return true immediately if update is undefined | ||
if (!data) { | ||
return true; | ||
} | ||
|
||
// Else return based on the expiration | ||
return !(data.expires >= Math.floor(Date.now())); | ||
|
||
}; | ||
|
||
/** | ||
* Get latest version info from github | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
exports.refresh = function(version) { | ||
|
||
// GitHub object | ||
var github = new GitHubApi({Promise: Promise}); | ||
|
||
// GitHub repo config | ||
var landoRepoConfig = { | ||
owner: 'lando', | ||
repo: 'lando', | ||
page: 1, | ||
'per_page': 1 | ||
}; | ||
|
||
// This i promise you | ||
return github.repos.getReleases(landoRepoConfig) | ||
|
||
// Extract and return the metadata | ||
.then(function(data) { | ||
return { | ||
version: _.trimStart(_.get(data, 'data.[0].tag_name', version), 'v'), | ||
url: _.get(data, 'data.[0].html_url', ''), | ||
expires: Math.floor(Date.now()) + 3600000 | ||
}; | ||
}) | ||
|
||
// Dont let an error here kill things | ||
.catch(function() { | ||
return { | ||
version: _.trimStart(version, 'v'), | ||
url: '', | ||
expires: Math.floor(Date.now()) + 3600000 | ||
}; | ||
}); | ||
|
||
}; |