npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fohlen/github-release-downloader

v1.0.0

Published

A GitHub release asset downloader

Downloads

290

Readme

github-release-downloader

Build Status

A tiny Promise-compliant wrapper around requests to download release assets from GitHub. I use mocha, eslint and Travis for code quality. Also jsdoc-to-markdown is a great help in creating this README.

Get started

To get started, simply install this module via (if you plan using it without progress or command line):

npm i @fohlen/github-release-downloader --save --no-optional

Once that's done you can simply require the downloader in your code

const releaseDownloader = require('@fohlen/github-release-downloader');

releaseDownloader.downloadByPlatformArch('inexorgame/inexor-core').then((downloaded) => {
    console.log(`Hooray! It downloaded my archive at ${downloaed}!`)
}).catch((err) => {
    console.error('omighosh, seems like this platform is not supported')
})

Command line

You can also use this package as a small command-line wrapper to download stuff from GitHub.

npm i @fohlen/github-release-downloader -g

Then go ahead and enjoy the command line,

github-release-downloader --help

Use progress for download progress

You can also pass an optional callback to the downloadAsset function. Given you use progress that would look like

const releaseDownloader = require('github-release-downloader');
const progress = require('progress');

releaseDownloader.getVersion('inexorgame/inexor-core').then((release) => {
    releaseDownloader.getAssetByPlatformArch(release).then((asset) => {
        let progressBar = new ProgressBar(':bar:', { total: asset.size })
        
        releaseDownloader.downloadAsset(asset.url, asset.name, (chunk) => {
            progressBar.tick((asset.size - chunk))
        }).then((downloaded) => {
            console.log(`Successfully downloaded file to ${downloaded}`)
        })
    })
})

Improvement ideas

There's surely plenty room for improvement, and I appreciate pull requests. I think that support for authentication is indeed most needed right now, because the api limit can be rather harsh.

#API

Functions

getReleaseList(repo) ⇒ Promise.<Object>

Retrieves versions and their associated assets

Kind: global function
See: https://developer.github.com/v3/repos/releases/#list-releases-for-a-repository

| Param | Type | Description | | --- | --- | --- | | repo | string | the name of the GitHub name+repo, e.g fohlen/github-release-downloader |

getReleaseByVersion(repo, range) ⇒ Promise.<Object>

Retrieves the assets of a specific release or tries to match a release using the semver

Kind: global function
See: https://developer.github.com/v3/repos/releases/#get-a-single-release

| Param | Type | Default | Description | | --- | --- | --- | --- | | repo | string | | the name of the GitHub name+repo, e.g fohlen/github-release-downloader | | range | string | "latest" | [range=latest] - semver range |

getAssetByPlatformArch(release, platform, arch) ⇒ Promise.<Object>

Tries to match an asset of a release for specific platform and arch. Using platform="", arch="" behaves like a wildcard.

Kind: global function

| Param | Type | Description | | --- | --- | --- | | release | Object | a GitHub release object | | platform | string | [platform=os.platform()] - one of the supported platforms of os.platform | | arch | string | [arch=os.arch()] - one of the supported architectures of os.arch |

downloadAsset(url, name, dir, [progress]) ⇒ Promise.<string>

Downloads a release asset from GitHub. Calls the progress callback with the chunk length progressively. You can get the file size via @see getAssetByPlatformArch

Kind: global function
Returns: Promise.<string> - - the path of the downloaded file

| Param | Type | Default | Description | | --- | --- | --- | --- | | url | string | | | | name | string | | | | dir | string | | [directory=process.cwd()] - an optional download path | | [progress] | function | | an optional callback to hook into with asset download |

downloadAssetByPlatformArch(repo, range, dir, platform, arch) ⇒ Promise.<string>

Tries to download given release by range for specified platform and arch. If the architecture+platform cannot be matched the promise will be rejected.

Kind: global function
Returns: Promise.<string> - - the path of the downloaded file

| Param | Type | Default | Description | | --- | --- | --- | --- | | repo | string | | the name of the GitHub name+repo, e.g fohlen/github-release-downloader | | range | string | "latest" | [range=latest] - semver range | | dir | string | | [directory=process.cwd()] - an optional download path | | platform | string | | [platform=os.platform()] - one of the supported platforms of os.platform | | arch | string | | [arch=os.arch()] - one of the supported architectures of os.arch |