github-fetch-file v1.0.1
Fetch File
Fetch a file from one or more public Github repositories.
Installation
$ npm install github-fetch-fileUsage
var fetch = require( 'github-fetch-file' );fetch( filepath, repos, clbk )
Fetches a file from one or more public Github repositories.
// List of repository slugs (username|org/repo):
var repos = [
'kgryte/utils-copy',
'dstructs/matrix',
'math-io/gamma',
'unknown_user/repo'
];
// Fetch a top-level `README.md` file from each repo:
fetch( 'README.md', repos, clbk );
function clbk( error, results ) {
if ( error ) {
throw new Error( error.message );
}
console.dir( results );
/*
{
"meta": {
"total": 4,
"success": 3,
"failure": 1
},
"data": {
"kgryte/utils-copy": "...",
"dstructs/matrix": "...",
"math-io/gamma": "..."
},
"failures": {
"unknown_user/repo": "Not Found"
}
}
*/
}fetch.factory( filepath, repos, clbk )
Creates a reusable function.
var repos = [
'kgryte/utils-copy',
'dstructs/matrix',
'math-io/gamma',
'unknown_user/repo'
];
var get = fetch.factory( 'README.md', repos, clbk );
get();
get();
get();
// ...The factory method accepts the same arguments as fetch().
Notes
- If the module encounters an application-level
error(e.g., no network connection, etc), theerroris returned immediately to the providedcallback. - If the module encounters a downstream
error(e.g., timeout, reset connection, etc), theerroris included in the returned results under thefailuresfield.
Examples
var fetch = require( 'github-fetch-file' );
var repos = [
'kgryte/utils-copy',
'math-io/gamma',
'dstructs/matrix'
];
fetch( 'README.md', repos, clbk );
function clbk( error, results ) {
if ( error ) {
throw new Error( error.message );
}
console.dir( results );
}To run the example code from the top-level application directory,
$ DEBUG=* node ./examples/index.jsCLI
Installation
To use the module as a general utility, install the module globally
$ npm install -g github-fetch-fileUsage
Usage: ghfetchfile [options] file --repo slug1 --repo slug2 ...
Options:
-h, --help Print this message.
-V, --version Print the package version.
--repo slug Repository slug; e.g., kgryte/github-fetch-file.Notes
- If a repository file is successfully resolved, the file content is written to
stdout. - If a repository file cannot be resolved due to a downstream
error(failure), the reposlug(and its associatederror) is written tosterr. - Output order is not guaranteed to match input order.
Examples
$ DEBUG=* ghfetchfile README.md --repo 'kgryte/utils-copy' --repo 'dstructs/matrix' --repo 'math-io/gamma'
# => {...}For local installations, modify the command to point to the local installation directory; e.g.,
$ DEBUG=* ./node_modules/.bin/ghfetchfile README.md --repo 'kgryte/utils-copy' --repo 'dstructs/matrix' --repo 'math-io/gamma'
# => {...}Or, if you have cloned this repository and run npm install, modify the command to point to the executable; e.g.,
$ DEBUG=* node ./bin/cli README.md --repo 'kgryte/utils-copy' --repo 'dstructs/matrix' --repo 'math-io/gamma'
# => {...}Tests
Unit
This repository uses tape for unit tests. To run the tests, execute the following command in the top-level application directory:
$ make testAll new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-covIstanbul creates a ./reports/coverage directory. To access an HTML version of the report,
$ make view-covBrowser Support
This repository uses Testling for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:
$ make test-browsersTo view the tests in a local web browser,
$ make view-browser-testsLicense
Copyright
Copyright © 2016. Athan Reines.