├── .circleci └── config.yml ├── .editorconfig ├── .gitignore ├── .npmignore ├── .releaserc ├── CHANGELOG.md ├── LICENSE ├── README.md ├── bin ├── cli.js └── get-version.js ├── jest.config.js ├── package-lock.json ├── package.json ├── src ├── download.ts ├── get-releases.ts ├── index.test.ts └── index.ts ├── tsconfig.json ├── tsfmt.json └── tslint.json /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | aliases: 4 | # ------------------------- 5 | # ALIASES: Caches 6 | # ------------------------- 7 | - &restore-deps-cache 8 | key: deps-cache-{{ checksum "package.json" }} 9 | 10 | - &save-deps-cache 11 | key: deps-cache-{{ checksum "package.json" }} 12 | paths: 13 | - ~/dl-github-releases/node_modules 14 | 15 | # ------------------------- 16 | # ALIASES: Branch Filters 17 | # ------------------------- 18 | - &filter-only-master 19 | branches: 20 | only: master 21 | - &filter-only-semantic-pr 22 | branches: 23 | only: /^(pull|dependabot|fix|feat)\/.*$/ 24 | - &filter-only-fork-pr 25 | branches: 26 | only: /^pull\/.*$/ 27 | 28 | defaults: &defaults 29 | working_directory: ~/dl-github-releases 30 | docker: 31 | - image: circleci/node:10 32 | 33 | jobs: 34 | test: 35 | <<: *defaults 36 | steps: 37 | - checkout 38 | - run: curl https://sh.rustup.rs -sSf | sh -s -- -y 39 | - run: echo 'export PATH=$HOME/.cargo/bin:$PATH' >> $BASH_ENV 40 | - run: source /home/circleci/.bashrc 41 | - restore_cache: *restore-deps-cache 42 | - run: npm install 43 | - run: npm install codecov 44 | - run: npm test 45 | - run: ./node_modules/.bin/codecov 46 | - save_cache: *save-deps-cache 47 | 48 | build: 49 | <<: *defaults 50 | steps: 51 | - checkout 52 | - restore_cache: *restore-deps-cache 53 | - run: npm install 54 | - run: npm run build 55 | - save_cache: *save-deps-cache 56 | 57 | release: 58 | <<: *defaults 59 | steps: 60 | - checkout 61 | - restore_cache: *restore-deps-cache 62 | - run: npm install 63 | - run: npm run build 64 | - run: npm install semantic-release @semantic-release/changelog @semantic-release/git @semantic-release/github @semantic-release/npm @semantic-release/commit-analyzer @semantic-release/release-notes-generator @qiwi/semantic-release-gh-pages-plugin 65 | - run: git checkout package.json package-lock.json 66 | - run: ./node_modules/.bin/semantic-release 67 | - save_cache: *save-deps-cache 68 | 69 | workflows: 70 | version: 2 71 | analysis: 72 | jobs: 73 | - test: 74 | filters: *filter-only-semantic-pr 75 | - build: 76 | filters: *filter-only-semantic-pr 77 | requires: 78 | - test 79 | 80 | release: 81 | jobs: 82 | - test: 83 | filters: *filter-only-master 84 | - build: 85 | filters: *filter-only-master 86 | - hold: 87 | filters: *filter-only-master 88 | type: approval 89 | requires: 90 | - test 91 | - build 92 | - release: 93 | filters: *filter-only-master 94 | requires: 95 | - hold 96 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | indent_style = space 9 | indent_size = 2 10 | tab_width = 2 11 | end_of_line = lf 12 | charset = utf-8 13 | trim_trailing_whitespace = true 14 | insert_final_newline = true 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | node_modules 3 | test 4 | coverage 5 | docs 6 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.log 3 | test 4 | tmp 5 | coverage 6 | -------------------------------------------------------------------------------- /.releaserc: -------------------------------------------------------------------------------- 1 | { 2 | "tagFormat": "${version}", 3 | "branch": "master", 4 | "plugins": [ 5 | "@semantic-release/commit-analyzer", 6 | "@semantic-release/release-notes-generator", 7 | "@semantic-release/changelog", 8 | "@semantic-release/github", 9 | ["@semantic-release/git", { 10 | "assets": ["CHANGELOG.md"], 11 | "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" 12 | }], 13 | "@semantic-release/npm" 14 | ], 15 | "verifyConditions": [ 16 | "@semantic-release/changelog", 17 | "@semantic-release/npm", 18 | "@semantic-release/git", 19 | "@semantic-release/github", 20 | "@qiwi/semantic-release-gh-pages-plugin" 21 | ], 22 | "publish": [ 23 | "@semantic-release/github", 24 | { 25 | "path": "@qiwi/semantic-release-gh-pages-plugin", 26 | "msg": "github pages release", 27 | "src": "docs/", 28 | "branch": "gh-pages" 29 | }, 30 | "@semantic-release/npm" 31 | ], 32 | "success": [ 33 | "@semantic-release/github" 34 | ], 35 | "fail": [ 36 | "@semantic-release/github" 37 | ] 38 | } 39 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [1.2.1](https://github.com/etclabscore/dl-github-releases/compare/1.2.0...1.2.1) (2020-09-30) 2 | 3 | 4 | ### Bug Fixes 5 | 6 | * fs-extra is not a dev-dep ([c90de81](https://github.com/etclabscore/dl-github-releases/commit/c90de81b5adb7c744de124c389442935e10ccd72)) 7 | 8 | # [1.2.0](https://github.com/etclabscore/dl-github-releases/compare/1.1.2...1.2.0) (2020-09-30) 9 | 10 | 11 | ### Bug Fixes 12 | 13 | * add hekka sweet badges ([3e4101c](https://github.com/etclabscore/dl-github-releases/commit/3e4101cad814e2984090cc33ceada081da662065)) 14 | * add missing dep ([b9ce8f7](https://github.com/etclabscore/dl-github-releases/commit/b9ce8f785425cff687b2685ee4ae13d11ad3b806)) 15 | * make apache 2 licensed ([04c5d43](https://github.com/etclabscore/dl-github-releases/commit/04c5d43313464a9b3ae9f8d5600b3a0710007cfc)) 16 | 17 | 18 | ### Features 19 | 20 | * update all deps ([50562b0](https://github.com/etclabscore/dl-github-releases/commit/50562b04556b534cf73d5f47ea902efde755e043)) 21 | 22 | ## [1.1.2](https://github.com/etclabscore/dl-github-releases/compare/1.1.1...1.1.2) (2020-04-16) 23 | 24 | 25 | ### Bug Fixes 26 | 27 | * checkout before deploying to keep npm clean ([df37d92](https://github.com/etclabscore/dl-github-releases/commit/df37d92ba2bb493bd31224b9bd8f7c22cbcbbcc7)) 28 | 29 | ## [1.1.1](https://github.com/etclabscore/dl-github-releases/compare/1.1.0...1.1.1) (2020-04-16) 30 | 31 | 32 | ### Bug Fixes 33 | 34 | * update deps ([53c1f84](https://github.com/etclabscore/dl-github-releases/commit/53c1f8405eb6eb112803d4872efa5038c5261bdf)) 35 | 36 | # [1.1.0](https://github.com/etclabscore/dl-github-releases/compare/1.0.9...1.1.0) (2019-06-10) 37 | 38 | 39 | ### Bug Fixes 40 | 41 | * add tslint dep ([6d1f5f0](https://github.com/etclabscore/dl-github-releases/commit/6d1f5f0)) 42 | * add typedoc configs ([4086dd8](https://github.com/etclabscore/dl-github-releases/commit/4086dd8)) 43 | * git ignore coverage ([22cb00c](https://github.com/etclabscore/dl-github-releases/commit/22cb00c)) 44 | * git ignore docs ([1ea16fc](https://github.com/etclabscore/dl-github-releases/commit/1ea16fc)) 45 | * remove coverage report ([803aa73](https://github.com/etclabscore/dl-github-releases/commit/803aa73)) 46 | * remove docs ([7e020fc](https://github.com/etclabscore/dl-github-releases/commit/7e020fc)) 47 | * typedoc errors ([519d85b](https://github.com/etclabscore/dl-github-releases/commit/519d85b)) 48 | 49 | 50 | ### Features 51 | 52 | * the upgrade powerpack ([9f2894a](https://github.com/etclabscore/dl-github-releases/commit/9f2894a)), closes [#7](https://github.com/etclabscore/dl-github-releases/issues/7) 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DL Github Releases 2 | 3 |
4 | 5 | CircleCI branch 6 | Dependabot status 7 | npm 8 | GitHub release 9 | GitHub commits since latest release 10 | 11 |
12 | 13 | A node module to download Github assets for Github releases. It will also uncompress zip files. 14 | 15 | ## Command line 16 | 17 | ``` 18 | $ npm install -g @etclabscore/dl-github-releases 19 | 20 | 21 | $ dl-github-releases --help 22 | 23 | Usage: download-github-releases [options] 24 | 25 | Options: 26 | -V, --version output the version number 27 | -o, --outputDir [output] output directory [output] (default: "/Users/zb/Code/etclabs/dl-github-releases") 28 | -p, --includePre download prerelease 29 | -d, --includeDraft download draft releases 30 | -a, --filterAssetsByName filter assets name 31 | -z, --zipped don't extract zip files 32 | -h, --help output usage information 33 | Usage: download-github-release [options] [outputdir] 34 | 35 | Options: 36 | 37 | -h, --help output usage information 38 | -V, --version output the version number 39 | -p, --prerelease download prerelease 40 | -s, --search filter assets name 41 | 42 | 43 | $ dl-github-releases -a *.md open-rpc spec 44 | 45 | Downloading open-rpc/spec@1.0.0... 46 | spec.md ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 0.0s 47 | spec.pdf ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇--------- 0.1s 48 | ``` 49 | 50 | ## Javascript API 51 | 52 | ### Installation 53 | 54 | ```bash 55 | npm install --save dl-github-releases 56 | ``` 57 | 58 | ### Usage 59 | 60 | ```javascript 61 | var downloadReleases = require('dl-github-releases'); 62 | 63 | var user = 'some user'; 64 | var repo = 'some repo'; 65 | var outputdir = 'some output directory'; 66 | 67 | // Define a function to filter releases. 68 | function filterRelease(release) { 69 | // Filter out prereleases. 70 | return release.prerelease === false; 71 | } 72 | 73 | // Define a function to filter assets. 74 | function filterAsset(asset) { 75 | // Select assets that contain the string 'windows'. 76 | return asset.name.indexOf('windows') >= 0; 77 | } 78 | 79 | downloadReleases(user, repo, outputdir, filterRelease, filterAsset) 80 | .then(function() { 81 | console.log('All done!'); 82 | }) 83 | .catch(function(err) { 84 | console.error(err.message); 85 | }); 86 | ``` 87 | -------------------------------------------------------------------------------- /bin/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const commander = require('commander'); 4 | const downloadReleases = require("../build/").default; 5 | 6 | commander 7 | .version(require('./get-version')) 8 | .arguments(' ') 9 | .option('-o, --outputDir [output]', 'output directory [output]', process.cwd()) 10 | .option('-p, --includePre', 'download prerelease', false) 11 | .option('-d, --includeDraft', 'download draft releases', false) 12 | .option('-a, --filterAssetsByName ', 'filter assets name') 13 | .option('-z, --zipped', 'don\'t extract zip files') 14 | .parse(process.argv); 15 | 16 | const user = commander.args[0]; 17 | const repo = commander.args[1]; 18 | 19 | if (!user || !repo) { 20 | commander.help(); 21 | } 22 | 23 | function filterRelease(release) { 24 | return release.draft === !!commander.includingDraft && release.prerelease === !!commander.prerelease; 25 | } 26 | 27 | function filterAsset(asset) { 28 | if (!commander.filterAssetsByName) { 29 | return true; 30 | } 31 | 32 | return new RegExp(commander.search).exec(asset.name); 33 | } 34 | 35 | downloadReleases(user, repo, commander.outputDir, filterRelease, filterAsset, !!commander.zipped) 36 | .catch(err => console.error(err.message)); 37 | -------------------------------------------------------------------------------- /bin/get-version.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | module.exports = require('../package.json').version; 3 | if (require.main === module) { 4 | console.log(module.exports); 5 | } 6 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | clearMocks: true, 3 | coverageDirectory: '../coverage', 4 | resetMocks: true, 5 | restoreMocks: true, 6 | rootDir: './src', 7 | testEnvironment: 'node', 8 | preset: 'ts-jest', 9 | } 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@etclabscore/dl-github-releases", 3 | "version": "1.0.3", 4 | "description": "", 5 | "main": "build/index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/etclabscore/dl-github-releases.git" 9 | }, 10 | "keywords": [ 11 | "github", 12 | "release", 13 | "download" 14 | ], 15 | "bin": { 16 | "dl-github-releases": "bin/cli.js" 17 | }, 18 | "files": [ 19 | "build", 20 | "bin" 21 | ], 22 | "scripts": { 23 | "build": "npm run build:code && npm run build:docs", 24 | "build:docs": "typedoc", 25 | "build:code": "tsc", 26 | "test": "npm run test:lint && npm run test:unit", 27 | "test:lint": "tslint -c tslint.json 'src/**/*.ts' --fix", 28 | "test:unit": "jest --coverage", 29 | "watch:test": "jest --watch" 30 | }, 31 | "author": "ETCLabs Core", 32 | "license": "Apache 2.0", 33 | "dependencies": { 34 | "commander": "^6.1.0", 35 | "extract-zip": "^2.0.1", 36 | "lodash": "^4.17.20", 37 | "fs-extra": "^9.0.1", 38 | "node-fetch": "^2.6.1" 39 | }, 40 | "devDependencies": { 41 | "@types/extract-zip": "^1.6.2", 42 | "@types/fs-extra": "^9.0.1", 43 | "@types/jest": "^26.0.14", 44 | "@types/lodash": "^4.14.161", 45 | "@types/node": "^14.11.2", 46 | "@types/node-fetch": "^2.5.7", 47 | "jest": "^26.4.2", 48 | "ts-jest": "^26.4.1", 49 | "tslint": "^6.1.3", 50 | "typedoc": "^0.19.2", 51 | "typescript": "^4.0.3" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/download.ts: -------------------------------------------------------------------------------- 1 | import http from "http"; 2 | import https from "https"; 3 | 4 | export default (url: string, w: any) => { 5 | return new Promise((resolve, reject) => { 6 | let protocol = /^https:/.exec(url) ? https : http; 7 | 8 | protocol 9 | .get(url, (res1: any) => { 10 | protocol = /^https:/.exec(res1.headers.location) ? https : http; 11 | 12 | protocol 13 | .get(res1.headers.location, (res2: any) => { 14 | const total = parseInt(res2.headers["content-length"], 10); 15 | res2.pipe(w); 16 | res2.on("error", reject); 17 | res2.on("end", resolve); 18 | }) 19 | .on("error", reject); 20 | }) 21 | .on("error", reject); 22 | }); 23 | }; 24 | -------------------------------------------------------------------------------- /src/get-releases.ts: -------------------------------------------------------------------------------- 1 | import fetch from "node-fetch"; 2 | 3 | export type Releases = Release[]; 4 | 5 | export interface Release { 6 | url: string; 7 | assets_url: string; 8 | upload_url: string; 9 | html_url: string; 10 | id: number; 11 | node_id: string; 12 | tag_name: string; 13 | target_commitish: string; 14 | name: string; 15 | draft: boolean; 16 | author: Author; 17 | prerelease: boolean; 18 | created_at: Date; 19 | published_at: Date; 20 | assets: Asset[]; 21 | tarball_url: string; 22 | zipball_url: string; 23 | body: string; 24 | } 25 | 26 | export interface Asset { 27 | url: string; 28 | id: number; 29 | node_id: string; 30 | name: string; 31 | label: string; 32 | uploader: Author; 33 | content_type: string; 34 | state: string; 35 | size: number; 36 | download_count: number; 37 | created_at: Date; 38 | updated_at: Date; 39 | browser_download_url: string; 40 | } 41 | 42 | export interface Author { 43 | login: string; 44 | id: number; 45 | node_id: string; 46 | avatar_url: string; 47 | gravatar_id: string; 48 | url: string; 49 | html_url: string; 50 | followers_url: string; 51 | following_url: string; 52 | gists_url: string; 53 | starred_url: string; 54 | subscriptions_url: string; 55 | organizations_url: string; 56 | repos_url: string; 57 | events_url: string; 58 | received_events_url: string; 59 | type: string; 60 | site_admin: boolean; 61 | } 62 | 63 | export default async (user: string, repo: string): Promise => { 64 | const url = `https://api.github.com/repos/${user}/${repo}/releases`; 65 | 66 | const res = await fetch(url); 67 | const resJson = await res.json(); 68 | 69 | return resJson; 70 | }; 71 | -------------------------------------------------------------------------------- /src/index.test.ts: -------------------------------------------------------------------------------- 1 | import downloadReleases from "."; 2 | import { stat, emptyDir } from "fs-extra"; 3 | 4 | describe("dl-gh-release", () => { 5 | afterAll(async () => await emptyDir("./test")); 6 | it("downloads releases of spec", async () => { 7 | await downloadReleases( 8 | "open-rpc", 9 | "spec", 10 | "./test", 11 | ); 12 | expect(stat("./test")).toBeTruthy(); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { unlinkSync, createWriteStream } from "fs"; 2 | import getReleases, { Releases, Asset } from "./get-releases"; 3 | import download from "./download"; 4 | import _extractZip from "extract-zip"; 5 | import { promisify } from "util"; 6 | import { join } from "path"; 7 | import { ensureDir } from "fs-extra"; 8 | import { flatten } from "lodash"; 9 | 10 | const extract = promisify(_extractZip); 11 | 12 | function pass() { 13 | return true; 14 | } 15 | 16 | const getFilteredReleases = async ( 17 | user: string, 18 | repo: string, 19 | filterRelease = pass, 20 | filterAsset = pass, 21 | ): Promise => { 22 | const releases = await getReleases(user, repo); 23 | const filteredReleases = releases.filter(filterRelease) 24 | .map((release) => { 25 | const filteredAssets = release.assets.filter(filterAsset); 26 | return { ...release, assets: filteredAssets }; 27 | }); 28 | 29 | return filteredReleases; 30 | }; 31 | 32 | /** 33 | * Gives a list of the releases made for a repository, optionally filtered by release 34 | * and/or based on inclusion of a particular asset. 35 | * 36 | * @param user the name of the user or organization that owns the repo 37 | * @param repo the name of the repository that you want to list releases of 38 | * @param filterRelease the release filter function 39 | * @param filterAsset the asset filter function 40 | */ 41 | export async function listReleases( 42 | user: string, 43 | repo: string, 44 | filterRelease = pass, 45 | filterAsset = pass, 46 | ): Promise { 47 | const releases = await getFilteredReleases(user, repo, filterRelease, filterAsset); 48 | return releases.map(({ tag_name }) => tag_name) as string[]; 49 | } 50 | 51 | /** 52 | * Downloads the releases for a particular repo, optionally filtered by release 53 | * and/or based on inclusion of a particular asset. 54 | * 55 | * @param user the name of the user or organization that owns the repo 56 | * @param repo the name of the repository that you want to list releases of 57 | * @param outputDir the relative path to a directory to write the downloaded releases to 58 | * @param filterRelease the release filter function 59 | * @param filterAsset the asset filter function 60 | * @param unzip pass true if you want it the result to be unzipped as well. 61 | */ 62 | export default async function downloadReleases( 63 | user: string, 64 | repo: string, 65 | outputDir: string, 66 | filterRelease = pass, 67 | filterAsset = pass, 68 | unzip = false, 69 | ): Promise { 70 | const releases = await getFilteredReleases(user, repo, filterRelease, filterAsset); 71 | 72 | const bigResult = await Promise.all(releases.map(async (release: any) => { 73 | if (!release) { 74 | throw new Error(`could not find a release for ${user}/${repo}`); 75 | } 76 | 77 | const promises = release.assets.map(async (asset: Asset): Promise => { 78 | const destd = join(outputDir, release.tag_name); 79 | await ensureDir(destd); 80 | const destf = join(destd, asset.name); 81 | const dest = createWriteStream(destf); 82 | 83 | await download(asset.browser_download_url, dest); 84 | 85 | if (unzip && /\.zip$/.exec(destf)) { 86 | await extract(destf, { dir: destd }); 87 | await unlinkSync(destf); 88 | } 89 | return asset.name; 90 | }) as Array>; 91 | 92 | const result = await Promise.all(promises) as string[]; 93 | 94 | return result; 95 | })); 96 | 97 | return flatten(bigResult) as string[]; 98 | } 99 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "lib": [ 6 | "ES2015" 7 | ], 8 | "declaration": true, 9 | "outDir": "./build", 10 | "strict": true, 11 | "esModuleInterop": true, 12 | "resolveJsonModule": true 13 | }, 14 | "typedocOptions": { 15 | "name": "@etclabscore/dl-github-releases", 16 | "mode": "file", 17 | "src": [ "./src/index.ts" ], 18 | "out": "docs", 19 | "includeDeclarations": true, 20 | "excludeNotExported": true, 21 | "excludePrivate": true, 22 | "excludeProtected": true, 23 | "hideGenerator": true, 24 | "listInvalidSymbolLinks": true, 25 | "readme": "./README.md", 26 | "exclude": [ 27 | "node_modules", 28 | "lib", 29 | "docs", 30 | "build", 31 | "jest.config.js", 32 | "src/**/*.test.ts" 33 | ], 34 | "toc": [ 35 | "downloadReleases", 36 | "listReleases" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tsfmt.json: -------------------------------------------------------------------------------- 1 | { 2 | "baseIndentSize": 0, 3 | "indentSize": 2, 4 | "tabSize": 2, 5 | "indentStyle": 2, 6 | "newLineCharacter": "\r\n", 7 | "convertTabsToSpaces": true, 8 | "insertSpaceAfterCommaDelimiter": true, 9 | "insertSpaceAfterSemicolonInForStatements": true, 10 | "insertSpaceBeforeAndAfterBinaryOperators": true, 11 | "insertSpaceAfterConstructor": false, 12 | "insertSpaceAfterKeywordsInControlFlowStatements": true, 13 | "insertSpaceAfterFunctionKeywordForAnonymousFunctions": false, 14 | "insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false, 15 | "insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, 16 | "insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true, 17 | "insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false, 18 | "insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false, 19 | "insertSpaceAfterTypeAssertion": false, 20 | "insertSpaceBeforeFunctionParenthesis": false, 21 | "insertSpaceBeforeTypeAnnotation": false, 22 | "placeOpenBraceOnNewLineForFunctions": false, 23 | "placeOpenBraceOnNewLineForControlBlocks": false 24 | } 25 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "tslint:recommended" 4 | ], 5 | "rules": { 6 | "ordered-imports": false, 7 | "indent": [true, "spaces", 2], 8 | "no-unused-variable": true, 9 | "interface-name": [false] 10 | } 11 | } 12 | --------------------------------------------------------------------------------