download-github-repo
Advanced tools
Comparing version 0.0.1 to 0.1.0
0.1.0 - February 11, 2013 | ||
------------------------- | ||
* add option for branch or tag | ||
0.0.1 - January 26, 2013 | ||
------------------------ | ||
:sparkles: |
45
index.js
@@ -15,3 +15,3 @@ | ||
/** | ||
* Download GitHub `repo` to `dest`. | ||
* Download GitHub `repo` to `dest` and callback `fn(err)`. | ||
* | ||
@@ -24,4 +24,3 @@ * @param {String} repo | ||
function download(repo, dest, fn){ | ||
var url = 'https://codeload.github.com/' + repo + '/legacy.tar.gz/master'; | ||
var file = dest + '.tar.gz'; | ||
var url = github(normalize(repo)); | ||
var dl = wget.download(url, dest + '.tar.gz'); | ||
@@ -42,2 +41,42 @@ | ||
}); | ||
} | ||
/** | ||
* Return a GitHub url for a given `repo` object. | ||
* | ||
* @param {Object} repo | ||
* @return {String} | ||
*/ | ||
function github(repo){ | ||
return 'https://codeload.github.com/' | ||
+ repo.owner | ||
+ '/' | ||
+ repo.name | ||
+ '/legacy.tar.gz/' | ||
+ repo.branch; | ||
} | ||
/** | ||
* Normalize a repo string. | ||
* | ||
* @param {String} string | ||
* @return {Object} | ||
*/ | ||
function normalize(string){ | ||
var owner = string.split('/')[0]; | ||
var name = string.split('/')[1]; | ||
var branch = 'master'; | ||
if (~name.indexOf('#')) { | ||
branch = name.split('#')[1]; | ||
name = name.split('#')[0]; | ||
} | ||
return { | ||
owner: owner, | ||
name: name, | ||
branch: branch | ||
}; | ||
} |
@@ -14,3 +14,3 @@ { | ||
], | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
@@ -26,2 +26,2 @@ "dependencies": { | ||
} | ||
} | ||
} |
@@ -14,3 +14,3 @@ | ||
Download a `repo` (eg. `"ianstormtaylor/router"`) to a `destination` folder and `callback`. | ||
Download GitHub `repo` (eg. `ianstormtaylor/router`) to a `destination` folder and `callback`. Defaults to the `master` branch, but you can specify a branch or tag as a URL fragment like `ianstormtaylor/router#my-branch`. | ||
@@ -17,0 +17,0 @@ ## License |
@@ -12,7 +12,7 @@ | ||
it('should work', function(done){ | ||
download('ianstormtaylor/matchuppps', 'test/tmp', function(err){ | ||
it('downloads the master branch by default', function(done){ | ||
download('zeke/download-github-repo-fixture', 'test/tmp', function(err){ | ||
if (err) return done(err); | ||
var actual = read('test/tmp'); | ||
var expected = read('test/fixture'); | ||
var expected = read('test/fixtures/master'); | ||
assert.deepEqual(actual, expected); | ||
@@ -22,2 +22,13 @@ done(); | ||
}); | ||
it('download branches too', function(done){ | ||
download('zeke/download-github-repo-fixture#my-branch', 'test/tmp', function(err){ | ||
if (err) return done(err); | ||
var actual = read('test/tmp'); | ||
var expected = read('test/fixtures/my-branch'); | ||
assert.deepEqual(actual, expected); | ||
done(); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3865
14
91
1