@terascope/fetch-github-release 0.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +8 -0
- package/.eslintignore +3 -0
- package/.eslintrc +12 -0
- package/.github/dependabot.yml +15 -0
- package/.travis.yml +26 -0
- package/LICENSE +21 -0
- package/README.md +105 -0
- package/bin/fetch-github-release +5 -0
- package/index.d.ts +54 -0
- package/lib/cli.js +45 -0
- package/lib/download.js +73 -0
- package/lib/downloadRelease.js +189 -0
- package/lib/getLatest.js +44 -0
- package/lib/getReleases.js +70 -0
- package/lib/index.js +7 -0
- package/lib/rpad.js +22 -0
- package/package.json +71 -0
package/.babelrc
ADDED
package/.eslintignore
ADDED
package/.eslintrc
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
- package-ecosystem: npm
|
|
4
|
+
directory: "/"
|
|
5
|
+
schedule:
|
|
6
|
+
interval: monthly
|
|
7
|
+
time: "04:00"
|
|
8
|
+
timezone: US/Arizona
|
|
9
|
+
open-pull-requests-limit: 3
|
|
10
|
+
assignees:
|
|
11
|
+
- peterdemartini
|
|
12
|
+
ignore:
|
|
13
|
+
- dependency-name: "@babel/preset-env"
|
|
14
|
+
versions:
|
|
15
|
+
- 7.13.8
|
package/.travis.yml
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# set the dist to bionic
|
|
2
|
+
dist: bionic
|
|
3
|
+
language: node_js
|
|
4
|
+
node_js:
|
|
5
|
+
- '10'
|
|
6
|
+
- '12'
|
|
7
|
+
branches:
|
|
8
|
+
only:
|
|
9
|
+
- master
|
|
10
|
+
- "/^v\\d+\\.\\d+\\.\\d+/"
|
|
11
|
+
install:
|
|
12
|
+
- yarn
|
|
13
|
+
script:
|
|
14
|
+
- stty cols 80
|
|
15
|
+
- yarn test:cov
|
|
16
|
+
- yarn build:lib
|
|
17
|
+
after_success:
|
|
18
|
+
- bash <(curl -s https://codecov.io/bash)
|
|
19
|
+
deploy:
|
|
20
|
+
provider: npm
|
|
21
|
+
email: ci@terascope.io
|
|
22
|
+
api_key: $NPM_TOKEN
|
|
23
|
+
skip_cleanup: true
|
|
24
|
+
on:
|
|
25
|
+
tags: true
|
|
26
|
+
repo: terascope/fetch-github-release
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Stephan Florquin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Download Github Release
|
|
2
|
+
|
|
3
|
+
A node module to download Github release assets. It will also uncompress zip
|
|
4
|
+
files and skip downloading if a file already exists.
|
|
5
|
+
|
|
6
|
+
[](https://travis-ci.org/terascope/fetch-github-release)
|
|
7
|
+
[](https://codecov.io/gh/terascope/fetch-github-release)
|
|
8
|
+
[](https://david-dm.org/terascope/fetch-github-release)
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
$ fetch-github-release -s darwin-x64 electron electron
|
|
12
|
+
Downloading electron/electron@v1.3.1...
|
|
13
|
+
electron-v1.3.1-darwi... ▇▇▇▇▇---------------------------------------------------- 662.8s
|
|
14
|
+
electron-v1.3.1-darwi... ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇--------- 13.4s
|
|
15
|
+
electron-v1.3.1-darwi... ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇--- 3.6s
|
|
16
|
+
ffmpeg-v1.3.1-darwin-... ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 0.0s
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
This is useful for instance if you have a project that depends on binaries
|
|
20
|
+
released via Github.
|
|
21
|
+
|
|
22
|
+
## Command line
|
|
23
|
+
|
|
24
|
+
### Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install -g @terascope/fetch-github-release
|
|
28
|
+
# or
|
|
29
|
+
yarn global add @terascope/fetch-github-release
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Usage
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
Usage: fetch-github-release [options] <user> <repo> [outputdir]
|
|
36
|
+
|
|
37
|
+
Options:
|
|
38
|
+
-V, --version output the version number
|
|
39
|
+
-p, --prerelease download prerelease
|
|
40
|
+
-s, --search <regexp> filter assets name
|
|
41
|
+
-q, --quiet don't log to console
|
|
42
|
+
-z, --zipped don't extract zip files
|
|
43
|
+
-h, --help output usage information
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Example
|
|
47
|
+
|
|
48
|
+
Download `electron/electron` assets whose name contains `darwin-x64` to `/tmp`.
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
$ fetch-github-release -s darwin-x64 electron electron /tmp
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
If you need to download assets from a private repository or you need to avoid rate limits, you can set the environment variable `GITHUB_TOKEN`. To generate a token go to your Github [settings](https://github.com/settings/tokens) and a token with `public_repo` or `repo` (for private repos) permissions.
|
|
55
|
+
|
|
56
|
+
## API
|
|
57
|
+
|
|
58
|
+
### Installation
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npm install --save @terascope/fetch-github-release
|
|
62
|
+
# or
|
|
63
|
+
yarn add @terascope/fetch-github-release
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Usage
|
|
67
|
+
|
|
68
|
+
```javascript
|
|
69
|
+
const downloadRelease = require('@terascope/fetch-github-release');
|
|
70
|
+
|
|
71
|
+
const user = 'some user';
|
|
72
|
+
const repo = 'some repo';
|
|
73
|
+
const outputdir = 'some output directory';
|
|
74
|
+
const leaveZipped = false;
|
|
75
|
+
const disableLogging = false;
|
|
76
|
+
|
|
77
|
+
// Define a function to filter releases.
|
|
78
|
+
function filterRelease(release) {
|
|
79
|
+
// Filter out prereleases.
|
|
80
|
+
return release.prerelease === false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Define a function to filter assets.
|
|
84
|
+
function filterAsset(asset) {
|
|
85
|
+
// Select assets that contain the string 'windows'.
|
|
86
|
+
return asset.name.includes('windows');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
downloadRelease(user, repo, outputdir, filterRelease, filterAsset, leaveZipped, disableLogging)
|
|
90
|
+
.then(function() {
|
|
91
|
+
console.log('All done!');
|
|
92
|
+
})
|
|
93
|
+
.catch(function(err) {
|
|
94
|
+
console.error(err.message);
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`downloadRelease` returns an array of file paths to all of the files downloaded
|
|
99
|
+
if called with `leaveZipped = true`.
|
|
100
|
+
|
|
101
|
+
## TODO
|
|
102
|
+
|
|
103
|
+
- other compression formats
|
|
104
|
+
- option to download specific release instead of latest?
|
|
105
|
+
- option to download source?
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Type definitions for fetch-github-release 0.3
|
|
2
|
+
// Definitions by: Borek Bernard <https://github.com/borekb>
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Download a specific github release
|
|
6
|
+
* @param user The name of the github user or organization
|
|
7
|
+
* @param repo The name of the github repository
|
|
8
|
+
* @param outputDir The directory to write the release to
|
|
9
|
+
* @param filterRelease Optionally filter the release
|
|
10
|
+
* @param filterAsset Optionally filter the asset for a given release
|
|
11
|
+
* @param leaveZipped Optionally leave the file zipped
|
|
12
|
+
* @param leaveZipped Optionally disable logging for quiet output
|
|
13
|
+
*/
|
|
14
|
+
declare function downloadRelease(
|
|
15
|
+
user: string,
|
|
16
|
+
repo: string,
|
|
17
|
+
outputDir: string,
|
|
18
|
+
filterRelease?: (release: downloadRelease.GithubRelease) => boolean,
|
|
19
|
+
filterAsset?: (asset: downloadRelease.GithubReleaseAsset) => boolean,
|
|
20
|
+
leaveZipped?: boolean,
|
|
21
|
+
disableLogging?: boolean,
|
|
22
|
+
): Promise<string[]>;
|
|
23
|
+
|
|
24
|
+
declare namespace downloadRelease {
|
|
25
|
+
/**
|
|
26
|
+
* See https://developer.github.com/v3/repos/releases/#get-a-single-release-asset
|
|
27
|
+
*/
|
|
28
|
+
export interface GithubRelease {
|
|
29
|
+
id: number;
|
|
30
|
+
url: string;
|
|
31
|
+
tag_name: string;
|
|
32
|
+
name: string;
|
|
33
|
+
body: string;
|
|
34
|
+
draft: boolean;
|
|
35
|
+
prerelease: boolean;
|
|
36
|
+
created_at: string;
|
|
37
|
+
published_at: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* See https://developer.github.com/v3/repos/releases/#get-a-single-release-asset
|
|
42
|
+
*/
|
|
43
|
+
export interface GithubReleaseAsset {
|
|
44
|
+
id: number;
|
|
45
|
+
name: string;
|
|
46
|
+
url: string;
|
|
47
|
+
content_type: string;
|
|
48
|
+
size: number;
|
|
49
|
+
created_at: string;
|
|
50
|
+
updated_at: string;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export = downloadRelease;
|
package/lib/cli.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
4
|
+
|
|
5
|
+
require("core-js/modules/es.string.search.js");
|
|
6
|
+
|
|
7
|
+
require("core-js/modules/es.regexp.constructor.js");
|
|
8
|
+
|
|
9
|
+
require("core-js/modules/es.regexp.to-string.js");
|
|
10
|
+
|
|
11
|
+
require("core-js/modules/es.function.name.js");
|
|
12
|
+
|
|
13
|
+
var _commander = _interopRequireDefault(require("commander"));
|
|
14
|
+
|
|
15
|
+
var _downloadRelease = _interopRequireDefault(require("./downloadRelease"));
|
|
16
|
+
|
|
17
|
+
var _package = require("../package.json");
|
|
18
|
+
|
|
19
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
20
|
+
|
|
21
|
+
_commander["default"].version(_package.version).arguments('<user> <repo> [outputdir]').option('-p, --prerelease', 'download prerelease').option('-s, --search <regexp>', 'filter assets name').option('-q, --quiet', 'don\'t log to console').option('-z, --zipped', 'don\'t extract zip files').parse(process.argv);
|
|
22
|
+
|
|
23
|
+
var user = _commander["default"].args[0];
|
|
24
|
+
var repo = _commander["default"].args[1];
|
|
25
|
+
var outputdir = _commander["default"].args[2] || process.cwd();
|
|
26
|
+
|
|
27
|
+
if (!user || !repo) {
|
|
28
|
+
_commander["default"].help();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function filterRelease(release) {
|
|
32
|
+
return release.draft === false && release.prerelease === !!_commander["default"].prerelease;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function filterAsset(asset) {
|
|
36
|
+
if (!_commander["default"].search) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return new RegExp(_commander["default"].search).exec(asset.name);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
(0, _downloadRelease["default"])(user, repo, outputdir, filterRelease, filterAsset, !!_commander["default"].zipped, !!_commander["default"].quiet)["catch"](function (err) {
|
|
44
|
+
return console.error(err.message);
|
|
45
|
+
});
|
package/lib/download.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.function.name.js");
|
|
4
|
+
|
|
5
|
+
require("core-js/modules/es.object.define-property.js");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports["default"] = download;
|
|
11
|
+
|
|
12
|
+
require("core-js/modules/es.object.assign.js");
|
|
13
|
+
|
|
14
|
+
require("core-js/modules/es.object.to-string.js");
|
|
15
|
+
|
|
16
|
+
require("core-js/modules/es.promise.js");
|
|
17
|
+
|
|
18
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
19
|
+
|
|
20
|
+
require("core-js/modules/es.parse-int.js");
|
|
21
|
+
|
|
22
|
+
var _http = _interopRequireDefault(require("http"));
|
|
23
|
+
|
|
24
|
+
var _https = _interopRequireDefault(require("https"));
|
|
25
|
+
|
|
26
|
+
var _url = _interopRequireDefault(require("url"));
|
|
27
|
+
|
|
28
|
+
var _package = require("../package.json");
|
|
29
|
+
|
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
31
|
+
|
|
32
|
+
var GITHUB_TOKEN = process.env.GITHUB_TOKEN;
|
|
33
|
+
|
|
34
|
+
function getRequestOptions(urlString) {
|
|
35
|
+
var url = _url["default"].parse(urlString);
|
|
36
|
+
|
|
37
|
+
var headers = {
|
|
38
|
+
Accept: 'application/octet-stream',
|
|
39
|
+
'User-Agent': _package.name
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
if (GITHUB_TOKEN) {
|
|
43
|
+
headers.Authorization = "token ".concat(GITHUB_TOKEN);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return Object.assign({}, url, {
|
|
47
|
+
headers: headers
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function download(url, w) {
|
|
52
|
+
var progress = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {};
|
|
53
|
+
return new Promise(function (resolve, reject) {
|
|
54
|
+
var protocol = /^https:/.exec(url) ? _https["default"] : _http["default"];
|
|
55
|
+
var options = getRequestOptions(url);
|
|
56
|
+
progress(0);
|
|
57
|
+
protocol.get(options, function (res1) {
|
|
58
|
+
protocol = /^https:/.exec(res1.headers.location) ? _https["default"] : _http["default"];
|
|
59
|
+
protocol.get(res1.headers.location, function (res2) {
|
|
60
|
+
var total = parseInt(res2.headers['content-length'], 10);
|
|
61
|
+
var completed = 0;
|
|
62
|
+
res2.pipe(w);
|
|
63
|
+
res2.on('data', function (data) {
|
|
64
|
+
completed += data.length;
|
|
65
|
+
progress(completed / total);
|
|
66
|
+
});
|
|
67
|
+
res2.on('progress', progress);
|
|
68
|
+
res2.on('error', reject);
|
|
69
|
+
res2.on('end', resolve);
|
|
70
|
+
}).on('error', reject);
|
|
71
|
+
}).on('error', reject);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.object.define-property.js");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
require("regenerator-runtime/runtime.js");
|
|
11
|
+
|
|
12
|
+
require("core-js/modules/es.object.to-string.js");
|
|
13
|
+
|
|
14
|
+
require("core-js/modules/es.promise.js");
|
|
15
|
+
|
|
16
|
+
require("core-js/modules/es.array.concat.js");
|
|
17
|
+
|
|
18
|
+
require("core-js/modules/es.array.map.js");
|
|
19
|
+
|
|
20
|
+
require("core-js/modules/es.function.name.js");
|
|
21
|
+
|
|
22
|
+
require("core-js/modules/es.function.bind.js");
|
|
23
|
+
|
|
24
|
+
require("core-js/modules/es.array.join.js");
|
|
25
|
+
|
|
26
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
27
|
+
|
|
28
|
+
require("core-js/modules/es.array.iterator.js");
|
|
29
|
+
|
|
30
|
+
require("core-js/modules/es.string.iterator.js");
|
|
31
|
+
|
|
32
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
33
|
+
|
|
34
|
+
var _os = _interopRequireDefault(require("os"));
|
|
35
|
+
|
|
36
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
37
|
+
|
|
38
|
+
var _path = _interopRequireDefault(require("path"));
|
|
39
|
+
|
|
40
|
+
var _extractZip = _interopRequireDefault(require("extract-zip"));
|
|
41
|
+
|
|
42
|
+
var _getReleases = _interopRequireDefault(require("./getReleases"));
|
|
43
|
+
|
|
44
|
+
var _getLatest = _interopRequireDefault(require("./getLatest"));
|
|
45
|
+
|
|
46
|
+
var _download = _interopRequireDefault(require("./download"));
|
|
47
|
+
|
|
48
|
+
var _rpad = _interopRequireDefault(require("./rpad"));
|
|
49
|
+
|
|
50
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
51
|
+
|
|
52
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
53
|
+
|
|
54
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
55
|
+
|
|
56
|
+
function pass() {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
var MultiProgress = require('multi-progress');
|
|
61
|
+
|
|
62
|
+
function downloadRelease(_x, _x2, _x3) {
|
|
63
|
+
return _downloadRelease.apply(this, arguments);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function _downloadRelease() {
|
|
67
|
+
_downloadRelease = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(user, repo, _outputDir) {
|
|
68
|
+
var filterRelease,
|
|
69
|
+
filterAsset,
|
|
70
|
+
leaveZipped,
|
|
71
|
+
disableLogging,
|
|
72
|
+
bars,
|
|
73
|
+
releases,
|
|
74
|
+
release,
|
|
75
|
+
promises,
|
|
76
|
+
_args2 = arguments;
|
|
77
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
78
|
+
while (1) {
|
|
79
|
+
switch (_context2.prev = _context2.next) {
|
|
80
|
+
case 0:
|
|
81
|
+
filterRelease = _args2.length > 3 && _args2[3] !== undefined ? _args2[3] : pass;
|
|
82
|
+
filterAsset = _args2.length > 4 && _args2[4] !== undefined ? _args2[4] : pass;
|
|
83
|
+
leaveZipped = _args2.length > 5 && _args2[5] !== undefined ? _args2[5] : false;
|
|
84
|
+
disableLogging = _args2.length > 6 && _args2[6] !== undefined ? _args2[6] : false;
|
|
85
|
+
bars = new MultiProgress(process.stderr);
|
|
86
|
+
_context2.next = 7;
|
|
87
|
+
return (0, _getReleases["default"])(user, repo);
|
|
88
|
+
|
|
89
|
+
case 7:
|
|
90
|
+
releases = _context2.sent;
|
|
91
|
+
release = (0, _getLatest["default"])(releases, filterRelease, filterAsset);
|
|
92
|
+
|
|
93
|
+
if (release) {
|
|
94
|
+
_context2.next = 11;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
throw new Error("Could not find a release for ".concat(user, "/").concat(repo, " (").concat(_os["default"].platform(), " ").concat(_os["default"].arch(), ")"));
|
|
99
|
+
|
|
100
|
+
case 11:
|
|
101
|
+
if (!disableLogging) {
|
|
102
|
+
console.error("Downloading ".concat(user, "/").concat(repo, "@").concat(release.tag_name, "..."));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
promises = release.assets.map( /*#__PURE__*/function () {
|
|
106
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(asset) {
|
|
107
|
+
var progress, bar, outputDir, destf, dest;
|
|
108
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
109
|
+
while (1) {
|
|
110
|
+
switch (_context.prev = _context.next) {
|
|
111
|
+
case 0:
|
|
112
|
+
if (process.stdout.isTTY && !disableLogging) {
|
|
113
|
+
bar = bars.newBar("".concat((0, _rpad["default"])(asset.name, 24), " :bar :etas"), {
|
|
114
|
+
complete: '▇',
|
|
115
|
+
incomplete: '-',
|
|
116
|
+
width: process.stdout.columns - 36,
|
|
117
|
+
total: 100
|
|
118
|
+
});
|
|
119
|
+
progress = bar.update.bind(bar);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
outputDir = _path["default"].isAbsolute(_outputDir) ? _outputDir : _path["default"].resolve(_outputDir);
|
|
123
|
+
|
|
124
|
+
if (!_fs["default"].existsSync(outputDir)) {
|
|
125
|
+
_fs["default"].mkdirSync(outputDir);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (_fs["default"].statSync(outputDir).isDirectory()) {
|
|
129
|
+
_context.next = 5;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
throw new Error("Output path \"".concat(outputDir, "\" must be a directory"));
|
|
134
|
+
|
|
135
|
+
case 5:
|
|
136
|
+
destf = _path["default"].join(outputDir, asset.name);
|
|
137
|
+
|
|
138
|
+
if (_fs["default"].existsSync(destf)) {
|
|
139
|
+
_context.next = 14;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
dest = _fs["default"].createWriteStream(destf);
|
|
144
|
+
_context.next = 10;
|
|
145
|
+
return (0, _download["default"])(asset.url, dest, progress);
|
|
146
|
+
|
|
147
|
+
case 10:
|
|
148
|
+
if (!(!leaveZipped && /\.zip$/.exec(destf))) {
|
|
149
|
+
_context.next = 14;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
_context.next = 13;
|
|
154
|
+
return (0, _extractZip["default"])(destf, {
|
|
155
|
+
dir: outputDir
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
case 13:
|
|
159
|
+
_fs["default"].unlinkSync(destf);
|
|
160
|
+
|
|
161
|
+
case 14:
|
|
162
|
+
return _context.abrupt("return", destf);
|
|
163
|
+
|
|
164
|
+
case 15:
|
|
165
|
+
case "end":
|
|
166
|
+
return _context.stop();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}, _callee);
|
|
170
|
+
}));
|
|
171
|
+
|
|
172
|
+
return function (_x4) {
|
|
173
|
+
return _ref.apply(this, arguments);
|
|
174
|
+
};
|
|
175
|
+
}());
|
|
176
|
+
return _context2.abrupt("return", Promise.all(promises));
|
|
177
|
+
|
|
178
|
+
case 14:
|
|
179
|
+
case "end":
|
|
180
|
+
return _context2.stop();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}, _callee2);
|
|
184
|
+
}));
|
|
185
|
+
return _downloadRelease.apply(this, arguments);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
var _default = downloadRelease;
|
|
189
|
+
exports["default"] = _default;
|
package/lib/getLatest.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.object.define-property.js");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = getLatest;
|
|
9
|
+
|
|
10
|
+
require("core-js/modules/es.array.filter.js");
|
|
11
|
+
|
|
12
|
+
require("core-js/modules/es.object.assign.js");
|
|
13
|
+
|
|
14
|
+
function pass() {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getLatest(releases) {
|
|
19
|
+
var filterRelease = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : pass;
|
|
20
|
+
var filterAsset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : pass;
|
|
21
|
+
|
|
22
|
+
if (!releases) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var filtered = releases.filter(filterRelease);
|
|
27
|
+
|
|
28
|
+
if (!filtered.length) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for (var i = 0; i < filtered.length; i += 1) {
|
|
33
|
+
var release = filtered[i];
|
|
34
|
+
var assets = release.assets.filter(filterAsset);
|
|
35
|
+
|
|
36
|
+
if (assets.length) {
|
|
37
|
+
return Object.assign({}, release, {
|
|
38
|
+
assets: assets
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.function.name.js");
|
|
4
|
+
|
|
5
|
+
require("core-js/modules/es.object.define-property.js");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports["default"] = getReleases;
|
|
11
|
+
|
|
12
|
+
require("regenerator-runtime/runtime.js");
|
|
13
|
+
|
|
14
|
+
require("core-js/modules/es.object.to-string.js");
|
|
15
|
+
|
|
16
|
+
require("core-js/modules/es.promise.js");
|
|
17
|
+
|
|
18
|
+
require("core-js/modules/es.array.concat.js");
|
|
19
|
+
|
|
20
|
+
var _got = _interopRequireDefault(require("got"));
|
|
21
|
+
|
|
22
|
+
var _package = require("../package.json");
|
|
23
|
+
|
|
24
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
25
|
+
|
|
26
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
27
|
+
|
|
28
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
29
|
+
|
|
30
|
+
var GITHUB_TOKEN = process.env.GITHUB_TOKEN;
|
|
31
|
+
|
|
32
|
+
function getReleases(_x, _x2) {
|
|
33
|
+
return _getReleases.apply(this, arguments);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function _getReleases() {
|
|
37
|
+
_getReleases = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(user, repo) {
|
|
38
|
+
var url, requestConfig, r;
|
|
39
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
40
|
+
while (1) {
|
|
41
|
+
switch (_context.prev = _context.next) {
|
|
42
|
+
case 0:
|
|
43
|
+
url = "https://api.github.com/repos/".concat(user, "/").concat(repo, "/releases");
|
|
44
|
+
requestConfig = {
|
|
45
|
+
headers: {
|
|
46
|
+
'User-Agent': _package.name
|
|
47
|
+
},
|
|
48
|
+
responseType: 'json'
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
if (GITHUB_TOKEN) {
|
|
52
|
+
requestConfig.headers.Authorization = "token ".concat(GITHUB_TOKEN);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
_context.next = 5;
|
|
56
|
+
return _got["default"].get(url, requestConfig);
|
|
57
|
+
|
|
58
|
+
case 5:
|
|
59
|
+
r = _context.sent;
|
|
60
|
+
return _context.abrupt("return", r.body);
|
|
61
|
+
|
|
62
|
+
case 7:
|
|
63
|
+
case "end":
|
|
64
|
+
return _context.stop();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}, _callee);
|
|
68
|
+
}));
|
|
69
|
+
return _getReleases.apply(this, arguments);
|
|
70
|
+
}
|
package/lib/index.js
ADDED
package/lib/rpad.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.object.define-property.js");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = rpad;
|
|
9
|
+
|
|
10
|
+
require("core-js/modules/es.array.concat.js");
|
|
11
|
+
|
|
12
|
+
require("core-js/modules/es.array.join.js");
|
|
13
|
+
|
|
14
|
+
function rpad(text, len) {
|
|
15
|
+
var t = text;
|
|
16
|
+
|
|
17
|
+
if (t.length > len) {
|
|
18
|
+
t = "".concat(text.substr(0, len - 3), "...");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return "".concat(t).concat(new Array(len - t.length + 1).join(' '));
|
|
22
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@terascope/fetch-github-release",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "0.7.8",
|
|
7
|
+
"description": "Download a specific release from github",
|
|
8
|
+
"main": "lib/index.js",
|
|
9
|
+
"typings": "index.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "mocha --require @babel/polyfill --require @babel/register --require should --recursive",
|
|
12
|
+
"test:cov": "babel-node ./node_modules/isparta/bin/isparta cover ./node_modules/mocha/bin/_mocha -- --recursive --require should --require should",
|
|
13
|
+
"lint": "eslint src test",
|
|
14
|
+
"check": "npm run lint && npm run test",
|
|
15
|
+
"build:lib": "babel src --out-dir lib",
|
|
16
|
+
"clean": "rimraf lib coverage",
|
|
17
|
+
"preversion": "npm run clean && npm run check",
|
|
18
|
+
"version": "npm run build:lib",
|
|
19
|
+
"postversion": "git push && git push --tags && npm run clean",
|
|
20
|
+
"prepublishOnly": "npm run clean && npm run build:lib"
|
|
21
|
+
},
|
|
22
|
+
"bin": {
|
|
23
|
+
"fetch-github-release": "bin/fetch-github-release"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/terascope/fetch-github-release.git"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"github",
|
|
31
|
+
"release",
|
|
32
|
+
"download"
|
|
33
|
+
],
|
|
34
|
+
"author": "Stephan Florquin",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/terascope/fetch-github-release/issues"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"commander": "^7.0.0",
|
|
41
|
+
"extract-zip": "^2.0.1",
|
|
42
|
+
"gauge": "^3.0.0",
|
|
43
|
+
"got": "^11.4.0",
|
|
44
|
+
"multi-progress": "^4.0.0",
|
|
45
|
+
"progress": "^2.0.3"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@babel/cli": "^7.10.4",
|
|
49
|
+
"@babel/core": "^7.10.4",
|
|
50
|
+
"@babel/node": "^7.10.4",
|
|
51
|
+
"@babel/polyfill": "^7.10.4",
|
|
52
|
+
"@babel/preset-env": "^7.10.4",
|
|
53
|
+
"@babel/register": "^7.10.4",
|
|
54
|
+
"babel-eslint": "^10.1.0",
|
|
55
|
+
"core-js": "^3.6.5",
|
|
56
|
+
"eslint": "^5.8.0",
|
|
57
|
+
"eslint-config-airbnb": "^17.1.0",
|
|
58
|
+
"eslint-plugin-import": "^2.14.0",
|
|
59
|
+
"eslint-plugin-jsx-a11y": "^6.1.2",
|
|
60
|
+
"eslint-plugin-react": "^7.11.1",
|
|
61
|
+
"isparta": "^4.0.0",
|
|
62
|
+
"mocha": "^8.0.1",
|
|
63
|
+
"nock": "^13.0.2",
|
|
64
|
+
"regenerator-runtime": "^0.13.5",
|
|
65
|
+
"rimraf": "^3.0.0",
|
|
66
|
+
"should": "^13.2.3",
|
|
67
|
+
"sinon": "^11.1.1",
|
|
68
|
+
"stream-buffers": "^3.0.0",
|
|
69
|
+
"tmp": "0.2.1"
|
|
70
|
+
}
|
|
71
|
+
}
|