|
| 1 | +# Grab GitHub Release |
| 2 | + |
| 3 | +[ |
| 4 | +  |
| 5 | +](https://www.npmjs.com/package/grab-github-release) |
| 6 | +[](https://codecov.io/gh/prantlf/grab-github-release) |
| 7 | + |
| 8 | +Downloads and optionally unpacks an archive from GitHub release assets for the current platform. |
| 9 | + |
| 10 | +## Synopsis |
| 11 | + |
| 12 | +```js |
| 13 | +import grab from 'grab-github-release' |
| 14 | + |
| 15 | +try { |
| 16 | + const repository = 'prantlf/v-jsonlint' |
| 17 | + const platformSuffixes = { |
| 18 | + darwin: 'macos', |
| 19 | + win32: 'windows' |
| 20 | + } |
| 21 | + // downloads and unpacks the jsonlint executable to the current directory |
| 22 | + await grab({ repository, platformSuffixes, unpackExecutable: true }) |
| 23 | +} catch(err) { |
| 24 | + console.error(err.message) |
| 25 | + process.exitCode = 1 |
| 26 | +} |
| 27 | +``` |
| 28 | + |
| 29 | +## Installation |
| 30 | + |
| 31 | +This package can be installed globally, if you want to use the `grab-github-release` script (or the `ggr` alias). You can install it during the first usage with `npx` too: |
| 32 | + |
| 33 | +```sh |
| 34 | +$ npm i -g grab-github-release |
| 35 | +$ npx grab-github-release ... |
| 36 | +``` |
| 37 | + |
| 38 | +This package can be installed locally too, if you want to use it programmatically: |
| 39 | + |
| 40 | +```sh |
| 41 | +$ npm i -g grab-github-release |
| 42 | +$ npx grab-github-release ... |
| 43 | +``` |
| 44 | + |
| 45 | +Make sure, that you use [Node.js] version 18 or newer. |
| 46 | + |
| 47 | +## Command-line Usage |
| 48 | + |
| 49 | + Usage: [options] |
| 50 | + |
| 51 | + Options: |
| 52 | + -r|--repository <repository> GitHub repository formatted "owner/name" |
| 53 | + -i|--version-spec <semver> semantic version specifier or "latest" |
| 54 | + -n|--name <file-name> archive name without the platform suffix |
| 55 | + -p|--platform-suffixes <map> unpack the executable and remove the archive |
| 56 | + -e|--unpack-exe unpack the executable and remove the archive |
| 57 | + -v|--verbose prints extra information on the console |
| 58 | + -V|--version print version number and exit |
| 59 | + -h|--help print usage instructions and exit |
| 60 | + |
| 61 | + The version specifier is "latest" by default. The file name will be inferred |
| 62 | + from the first archive asset found for the current platform, if not specified. |
| 63 | + |
| 64 | + Examples: |
| 65 | + $ grab-github-release -r prantlf/v-jsonlint -p darwin=macos,win32=windows -u |
| 66 | + $ grab-github-release -r prantlf/v-jsonlint -i >=0.0.6 |
| 67 | + |
| 68 | +## API |
| 69 | + |
| 70 | +```ts |
| 71 | +// map where keys are Node.js platform names and values are their replacements |
| 72 | +// to be used in names of archive looked for among GitHub release assets |
| 73 | +type PlatformSuffixes = Record<string, string> |
| 74 | + |
| 75 | +interface GrabOptions { |
| 76 | + // GitHub repository formatted "owner/name", mandatory |
| 77 | + repository: string |
| 78 | + // semantic version specifier or "latest"; defaults to "latest", if unspecified |
| 79 | + version?: string |
| 80 | + // archive name without the platform and architecture suffix |
| 81 | + // and without the ".zip" extension as well |
| 82 | + name?: string |
| 83 | + // archive name without the platform suffix; if not specified, it will be |
| 84 | + // inferred from the first archive asset found for the current platform |
| 85 | + platformSuffixes?: PlatformSuffixes |
| 86 | + // unpack the executable and remove the archive |
| 87 | + unpackExecutable?: boolean |
| 88 | +} |
| 89 | + |
| 90 | +interface GrabResult { |
| 91 | + // actual version number as specified or picked from the list of releases |
| 92 | + version: string |
| 93 | + // downloaded archive name, if not removed (and the executable not unpacked) |
| 94 | + archive?: string |
| 95 | + // executable file name, if it was unpacked (and the archive removed) |
| 96 | + executable?: string |
| 97 | +} |
| 98 | + |
| 99 | +// downloads and optionally unpacks an archive from GitHub release assets |
| 100 | +// for the current platform |
| 101 | +export default function grab(options: GrabOptions): GrabResult |
| 102 | +``` |
| 103 | + |
| 104 | +## Contributing |
| 105 | + |
| 106 | +In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt. |
| 107 | + |
| 108 | +## License |
| 109 | + |
| 110 | +Copyright (c) 2023 Ferdinand Prantl |
| 111 | + |
| 112 | +Licensed under the MIT license. |
| 113 | + |
| 114 | +[Node.js]: http://nodejs.org/ |
0 commit comments