Skip to content

Instantly share code, notes, and snippets.

@ThomasCrevoisier
Last active November 8, 2016 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasCrevoisier/a3aa3038d60a04c6b1c7746c6d696e09 to your computer and use it in GitHub Desktop.
Save ThomasCrevoisier/a3aa3038d60a04c6b1c7746c6d696e09 to your computer and use it in GitHub Desktop.
Don't require to type full version
diff --git a/package.json b/package.json
index ae772cd..02fae50 100644
--- a/package.json
+++ b/package.json
@@ -3,9 +3,9 @@
"version": "0.1.2",
"description": "Purescript Version Manager",
"preferGlobal": "true",
- "repository" : {
- "type" : "git",
- "url" : "https://github.com/ThomasCrvsr/psvm-js.git"
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/ThomasCrvsr/psvm-js.git"
},
"bin": {
"psvm": "src/cli.js"
@@ -20,6 +20,7 @@
"nugget": "^1.5.4",
"ramda": "^0.17.1",
"rimraf": "^2.4.2",
+ "semver": "^5.3.0",
"tarball-extract": "0.0.3"
}
}
diff --git a/src/lib.js b/src/lib.js
index 875a9d7..cbfbb00 100644
--- a/src/lib.js
+++ b/src/lib.js
@@ -8,6 +8,7 @@ var got = require('got'),
Promise = require('bluebird'),
fs = Promise.promisifyAll(require('fs')),
glob = Promise.promisify(require('glob')),
+ semver = require('semver'),
PURESCRIPT_REPO_API_URL = 'https://api.github.com/repos/purescript/purescript',
PURESCRIPT_DOWNLOAD_URL = 'https://github.com/purescript/purescript';
@@ -15,7 +16,8 @@ function getReleases() {
return gotGithubApi('/releases')
.then(util.parseResponseBody)
.then(function (body) {
- return R.map(R.prop('tag_name'), body);
+ var releases = R.map(R.prop('tag_name'), body);
+ return R.filter(releases => semver.valid(releases), releases);
});
}
@@ -55,11 +57,13 @@ function installVersion(version) {
return getReleases()
.then(function (releases) {
- if (R.contains(version, releases)) {
- return downloadVersion(version, osType)
+ var matchingVersion = semver.maxSatisfying(releases, version);
+
+ if (matchingVersion) {
+ return downloadVersion(matchingVersion, osType)
.then(function () {
- util.createNonExistingDir(path.join(paths.PSVM_VERSIONS, version));
- return util.extract(path.join(paths.PSVM_ARCHIVES, version + '-' + osType + '.tar.gz'), path.join(paths.PSVM_VERSIONS, version));
+ util.createNonExistingDir(path.join(paths.PSVM_VERSIONS, matchingVersion));
+ return util.extract(path.join(paths.PSVM_ARCHIVES, matchingVersion + '-' + osType + '.tar.gz'), path.join(paths.PSVM_VERSIONS, matchingVersion));
});
} else {
return new Promise(function (resolve, reject) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment