RawGit

Generate a RawGit URL for a file hosted in a public GitHub repository.

Usage

var rawgit = require( '@stdlib/_tools/utils/rawgit-url' );

rawgit( opts )

Returns a RawGit URL for a file hosted in a public GitHub repository.

var opts = {
    'slug': 'stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34',
    'file': 'README.md'
};

var url = rawgit( opts );
// returns 'https://cdn.rawgit.com/stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34/README.md'

The function accepts the following options:

  • slug: public GitHub repository slug (required). The slug should include owner and repo information and should include either commit, branch, or tag information. For example,

    • stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34
    • stdlib-js/stdlib/develop
    • ...etc.
  • file: filepath (required). For example,

    • lib/index.js
    • ./README.md
    • ...etc.
  • cdn: boolean indicating whether to return a CDN URL. Default: true.

By default, the function returns a CDN URL. To return a (non-production) URL for development or testing, set the cdn option to false.

var opts = {
    'slug': 'stdlib-js/stdlib/develop',
    'file': 'lib/node_modules/@stdlib/index.js',
    'cdn': false
};

var url = rawgit( opts );
// returns 'https://rawgit.com/stdlib-js/stdlib/develop/lib/node_modules/@stdlib/index.js'

Examples

var rawgit = require( '@stdlib/_tools/utils/rawgit-url' );

var opts = {
    'cdn': true,
    'slug': 'stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34',
    'file': 'README.md'
};

var url = rawgit( opts );

console.log( url );
// => 'https://cdn.rawgit.com/stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34/README.md'

CLI

Usage

Usage: rawgit [options] <file>

Options:

  -h,  --help               Print this message.
  -V,  --version            Print the package version.
       --no-cdn             Return a dev/testing URL.
       --slug slug          GitHub repository slug (should include branch,
                            commit, or tag info).

Notes

  • If not provided a slug, the module attempts to resolve a slug from a local .git repository located in the current working directory of the calling process. The slug is a combination of remote.origin.url and the current Git hash. For example,

    $ git config --get remote.origin.url
    https://github.com/stdlib-js/stdlib.git
    
    $ git rev-parse HEAD
    5c53c78310e7c2cb8b3c166555d0fb81a3723f34
    

becomes

var slug = 'stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34';

Examples

$ rawgit README.md --slug 'stdlib-js/stdlib/develop'
https://cdn.rawgit.com/stdlib-js/stdlib/develop/README.md

To infer a GitHub repository slug from a local .git repository, omit the slug option.

$ rawgit docs/assets/web/logo_header.png
https://cdn.rawgit.com/stdlib-js/stdlib/345a31cb0e0cc534ccedaa91775873f3da2038c2/docs/assets/web/logo_header.png