git-dlp 0.2.0

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.
Files changed (103) hide show
  1. package/README.md +290 -0
  2. package/dist/git-dl.js +43 -0
  3. package/dist/git-dl.js.map +1 -0
  4. package/dist/package.json +138 -0
  5. package/dist/src/TaggedErrorVerifyingCause.js +27 -0
  6. package/dist/src/TaggedErrorVerifyingCause.js.map +1 -0
  7. package/dist/src/castToReadableStream.js +28 -0
  8. package/dist/src/castToReadableStream.js.map +1 -0
  9. package/dist/src/cli.js +8 -0
  10. package/dist/src/cli.js.map +1 -0
  11. package/dist/src/commandLineParams.js +172 -0
  12. package/dist/src/commandLineParams.js.map +1 -0
  13. package/dist/src/commonErrors.js +60 -0
  14. package/dist/src/commonErrors.js.map +1 -0
  15. package/dist/src/configContext.js +12 -0
  16. package/dist/src/configContext.js.map +1 -0
  17. package/dist/src/downloadEntityFromRepo.js +21 -0
  18. package/dist/src/downloadEntityFromRepo.js.map +1 -0
  19. package/dist/src/errors.js +10 -0
  20. package/dist/src/errors.js.map +1 -0
  21. package/dist/src/getPathContents/ParsedMetaInfoAboutPathContentsFromGitHubAPI.js +43 -0
  22. package/dist/src/getPathContents/ParsedMetaInfoAboutPathContentsFromGitHubAPI.js.map +1 -0
  23. package/dist/src/getPathContents/PathContentsMetaInfo.js +71 -0
  24. package/dist/src/getPathContents/PathContentsMetaInfo.js.map +1 -0
  25. package/dist/src/getPathContents/RawStreamOfRepoPathContentsFromGitHubAPI.js +4 -0
  26. package/dist/src/getPathContents/RawStreamOfRepoPathContentsFromGitHubAPI.js.map +1 -0
  27. package/dist/src/getPathContents/RepoPathContentsFromGitHubAPI.js +51 -0
  28. package/dist/src/getPathContents/RepoPathContentsFromGitHubAPI.js.map +1 -0
  29. package/dist/src/getPathContents/index.js +5 -0
  30. package/dist/src/getPathContents/index.js.map +1 -0
  31. package/dist/src/getPathContents/parseGitLFSObjectEither.js +70 -0
  32. package/dist/src/getPathContents/parseGitLFSObjectEither.js.map +1 -0
  33. package/dist/src/getReadableTarGzStreamOfRepoDirectory.js +39 -0
  34. package/dist/src/getReadableTarGzStreamOfRepoDirectory.js.map +1 -0
  35. package/dist/src/index.js +8 -0
  36. package/dist/src/index.js.map +1 -0
  37. package/dist/src/octokit.js +6 -0
  38. package/dist/src/octokit.js.map +1 -0
  39. package/dist/src/unpackRepoFolderTarGzStreamToFs.js +31 -0
  40. package/dist/src/unpackRepoFolderTarGzStreamToFs.js.map +1 -0
  41. package/dist/src/writeFileStreamToDestinationPath.js +22 -0
  42. package/dist/src/writeFileStreamToDestinationPath.js.map +1 -0
  43. package/dist-types/git-dl.d.ts +3 -0
  44. package/dist-types/git-dl.d.ts.map +1 -0
  45. package/dist-types/src/TaggedErrorVerifyingCause.d.ts +38 -0
  46. package/dist-types/src/TaggedErrorVerifyingCause.d.ts.map +1 -0
  47. package/dist-types/src/castToReadableStream.d.ts +11 -0
  48. package/dist-types/src/castToReadableStream.d.ts.map +1 -0
  49. package/dist-types/src/cli.d.ts +8 -0
  50. package/dist-types/src/cli.d.ts.map +1 -0
  51. package/dist-types/src/commandLineParams.d.ts +108 -0
  52. package/dist-types/src/commandLineParams.d.ts.map +1 -0
  53. package/dist-types/src/commonErrors.d.ts +60 -0
  54. package/dist-types/src/commonErrors.d.ts.map +1 -0
  55. package/dist-types/src/configContext.d.ts +44 -0
  56. package/dist-types/src/configContext.d.ts.map +1 -0
  57. package/dist-types/src/downloadEntityFromRepo.d.ts +11 -0
  58. package/dist-types/src/downloadEntityFromRepo.d.ts.map +1 -0
  59. package/dist-types/src/errors.d.ts +10 -0
  60. package/dist-types/src/errors.d.ts.map +1 -0
  61. package/dist-types/src/getPathContents/ParsedMetaInfoAboutPathContentsFromGitHubAPI.d.ts +141 -0
  62. package/dist-types/src/getPathContents/ParsedMetaInfoAboutPathContentsFromGitHubAPI.d.ts.map +1 -0
  63. package/dist-types/src/getPathContents/PathContentsMetaInfo.d.ts +66 -0
  64. package/dist-types/src/getPathContents/PathContentsMetaInfo.d.ts.map +1 -0
  65. package/dist-types/src/getPathContents/RawStreamOfRepoPathContentsFromGitHubAPI.d.ts +9 -0
  66. package/dist-types/src/getPathContents/RawStreamOfRepoPathContentsFromGitHubAPI.d.ts.map +1 -0
  67. package/dist-types/src/getPathContents/RepoPathContentsFromGitHubAPI.d.ts +81 -0
  68. package/dist-types/src/getPathContents/RepoPathContentsFromGitHubAPI.d.ts.map +1 -0
  69. package/dist-types/src/getPathContents/index.d.ts +5 -0
  70. package/dist-types/src/getPathContents/index.d.ts.map +1 -0
  71. package/dist-types/src/getPathContents/parseGitLFSObjectEither.d.ts +40 -0
  72. package/dist-types/src/getPathContents/parseGitLFSObjectEither.d.ts.map +1 -0
  73. package/dist-types/src/getReadableTarGzStreamOfRepoDirectory.d.ts +13 -0
  74. package/dist-types/src/getReadableTarGzStreamOfRepoDirectory.d.ts.map +1 -0
  75. package/dist-types/src/index.d.ts +9 -0
  76. package/dist-types/src/index.d.ts.map +1 -0
  77. package/dist-types/src/octokit.d.ts +8 -0
  78. package/dist-types/src/octokit.d.ts.map +1 -0
  79. package/dist-types/src/unpackRepoFolderTarGzStreamToFs.d.ts +16 -0
  80. package/dist-types/src/unpackRepoFolderTarGzStreamToFs.d.ts.map +1 -0
  81. package/dist-types/src/writeFileStreamToDestinationPath.d.ts +16 -0
  82. package/dist-types/src/writeFileStreamToDestinationPath.d.ts.map +1 -0
  83. package/package.json +139 -0
  84. package/src/TaggedErrorVerifyingCause.ts +142 -0
  85. package/src/castToReadableStream.ts +44 -0
  86. package/src/cli.ts +14 -0
  87. package/src/commandLineParams.ts +257 -0
  88. package/src/commonErrors.ts +139 -0
  89. package/src/configContext.ts +46 -0
  90. package/src/downloadEntityFromRepo.ts +86 -0
  91. package/src/errors.ts +24 -0
  92. package/src/getPathContents/ParsedMetaInfoAboutPathContentsFromGitHubAPI.ts +76 -0
  93. package/src/getPathContents/PathContentsMetaInfo.ts +85 -0
  94. package/src/getPathContents/RawStreamOfRepoPathContentsFromGitHubAPI.ts +6 -0
  95. package/src/getPathContents/RepoPathContentsFromGitHubAPI.ts +82 -0
  96. package/src/getPathContents/index.ts +7 -0
  97. package/src/getPathContents/parseGitLFSObjectEither.ts +143 -0
  98. package/src/getReadableTarGzStreamOfRepoDirectory.ts +65 -0
  99. package/src/index.ts +13 -0
  100. package/src/octokit.ts +15 -0
  101. package/src/unpackRepoFolderTarGzStreamToFs.ts +61 -0
  102. package/src/writeFileStreamToDestinationPath.ts +45 -0
  103. package/template.env +13 -0
package/README.md ADDED
@@ -0,0 +1,290 @@
1
+ # <img src="https://nikelborm.github.io/git-dl/logo.png" align="right" width="40px" height="40px"/> Get git repo contents (git-dl) :lizard:
2
+
3
+ [![Open in VS Code](https://img.shields.io/static/v1?logo=visualstudiocode&label=&message=Open%20in%20VS%20Code&labelColor=2c2c32&color=007acc&logoColor=007acc)](https://github.dev/nikelborm/git-dl)
4
+ [![NPM package version](https://badge.fury.io/js/git-dl.svg)](https://www.npmjs.com/package/git-dl)
5
+ [![NPM downloads](https://img.shields.io/npm/dm/git-dl.svg?style=flat)](https://npmjs.org/package/git-dl)
6
+ [![NPM Last Update](https://img.shields.io/npm/last-update/git-dl)](https://npmjs.org/package/git-dl)
7
+ [![package.json Dependents count](https://badgen.net/npm/dependents/git-dl)](https://www.npmjs.com/package/git-dl?activeTab=dependents)
8
+ [![JSR package version](https://jsr.io/badges/@evadev/git-dl)](https://jsr.io/@evadev/git-dl)
9
+ [![JSR package Score](https://jsr.io/badges/@evadev/git-dl/score)](https://jsr.io/@evadev/git-dl)
10
+ [![JSR package owner](https://jsr.io/badges/@evadev)](https://jsr.io/@evadev)
11
+ [![GitHub commits per month](https://img.shields.io/github/commit-activity/m/nikelborm/git-dl)](https://github.com/nikelborm/git-dl/pulse)
12
+ [![GitHub Total commits Count](https://img.shields.io/github/commit-activity/t/nikelborm/git-dl)](https://github.com/nikelborm/git-dl/graphs/commit-activity)
13
+ [![NPM License](https://img.shields.io/npm/l/git-dl)](https://github.com/nikelborm/git-dl?tab=MIT-1-ov-file)
14
+ [![Coveralls Coverage Percentage](https://coveralls.io/repos/github/nikelborm/git-dl/badge.svg?branch=main&rand=9148876)](https://coveralls.io/github/nikelborm/git-dl?branch=main)
15
+ [![CodeFactor Code quality Grade](https://img.shields.io/codefactor/grade/github/nikelborm/git-dl?label=codefactor)](https://www.codefactor.io/repository/github/nikelborm/git-dl)
16
+ [![Code Climate Technical Debt](https://img.shields.io/codeclimate/tech-debt/nikelborm/git-dl)](https://codeclimate.com/github/nikelborm/git-dl/issues)
17
+ [![Code Climate Issues](https://img.shields.io/codeclimate/issues/nikelborm/git-dl)](https://codeclimate.com/github/nikelborm/git-dl/issues)
18
+ [![GitHub Tests Workflow status](https://github.com/nikelborm/git-dl/actions/workflows/test.yml/badge.svg)](https://github.com/nikelborm/git-dl/actions/workflows/test.yml)
19
+ [![GitHub Release Workflow status](https://github.com/nikelborm/git-dl/actions/workflows/release.yml/badge.svg)](https://github.com/nikelborm/git-dl/actions/workflows/release.yml)
20
+ [![Sonar Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=nikelborm_fetch-github-folder&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
21
+ [![Sonar Bugs Count](https://sonarcloud.io/api/project_badges/measure?project=nikelborm_fetch-github-folder&metric=bugs)](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
22
+ [![Sonar Code Smells Count](https://sonarcloud.io/api/project_badges/measure?project=nikelborm_fetch-github-folder&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
23
+ [![Sonar Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=nikelborm_fetch-github-folder&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
24
+ [![Sonar Lines of Code Count](https://sonarcloud.io/api/project_badges/measure?project=nikelborm_fetch-github-folder&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
25
+ [![Sonar Reliability Grade](https://sonarcloud.io/api/project_badges/measure?project=nikelborm_fetch-github-folder&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
26
+ [![Sonar Security Grade](https://sonarcloud.io/api/project_badges/measure?project=nikelborm_fetch-github-folder&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
27
+ [![Sonar Technical Debt Count](https://sonarcloud.io/api/project_badges/measure?project=nikelborm_fetch-github-folder&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
28
+ [![Sonar Maintainability Grade](https://sonarcloud.io/api/project_badges/measure?project=nikelborm_fetch-github-folder&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
29
+ [![Sonar Vulnerabilities Count](https://sonarcloud.io/api/project_badges/measure?project=nikelborm_fetch-github-folder&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
30
+ ![OSS Lifecycle status](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fnikelborm%2Ffetch-github-folder%2Fblob%2Fmain%2FOSSMETADATA)
31
+
32
+ <!-- Commented because there's some bug in effect library or in bundlephobia that prevents proper rendering of this badge -->
33
+ <!-- [![npm minzipped bundle size](https://img.shields.io/bundlephobia/minzip/git-dl)](https://bundlephobia.com/package/git-dl) -->
34
+ <!-- [![package.json Dependencies count](https://badgen.net/bundlephobia/dependency-count/git-dl)](https://www.npmjs.com/package/git-dl?activeTab=dependencies) -->
35
+
36
+ <!-- commented because it seems that npms.io was acquired by somebody and is slowly dying -->
37
+ <!-- [![npms.io](https://img.shields.io/npms-io/final-score/git-dl)](update_link_later) -->
38
+
39
+ <!-- commented because I haven't started following it yet -->
40
+ <!-- [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org) -->
41
+
42
+ <sup>(Don't judge me for my obsession with badges)</sup>
43
+
44
+ > [!CAUTION]
45
+ >
46
+ > This project currently is not stable, but I'm actively working on writing tests and handling edge cases, such as support for Git-LFS and other.
47
+ > Check out the `dev` branch to see the latest updates! 😉 (except that I currently don't care and just push to main)
48
+
49
+ ## What this library+CLI does?
50
+
51
+ It allows you to download any folder or a file from a repo on github.
52
+
53
+ ## Requirements
54
+
55
+ 1. Latest Node.js (You can install it easily via [mise](https://github.com/jdx/mise))
56
+ 2. Git for development
57
+
58
+ ## Installation
59
+
60
+ We support various installation options. Regardless of what you choose, if you want to make
61
+ CLIs written in JS run faster, I highly recommend adding this line to your `.bashrc`:
62
+
63
+ ```bash
64
+ export NODE_COMPILE_CACHE=~/.cache/nodejs-compile-cache
65
+ ```
66
+
67
+ ### Install package with CLI and functions from [default NPM registry](https://www.npmjs.com/package/git-dl)
68
+
69
+ ```bash
70
+ npm i git-dl
71
+ ```
72
+
73
+ <details>
74
+ <summary>
75
+
76
+ ### Install package with only functions from [JSR](https://jsr.io/@evadev/git-dl)
77
+
78
+ </summary>
79
+
80
+ Unfortunately JSR doesn't support publishing executables yet, so you can install
81
+ only script library with functions that will allow you to fetch github folder
82
+ from other scripts.
83
+
84
+ ```bash
85
+ npx jsr add @evadev/git-dl
86
+ ```
87
+
88
+ </details>
89
+ <details>
90
+ <summary>
91
+
92
+ ### Install package with CLI and functions from [GitHub's NPM registry](https://github.com/nikelborm/git-dl/pkgs/npm/git-dl)
93
+
94
+ </summary>
95
+
96
+ 1. [Generate `Personal access token (classic)` with `read:packages` scope](https://github.com/settings/tokens/new?description=Install%20packages%20from%20GitHub%20NPM%20registry&scopes=read:packages&default_expires_at=none)
97
+ 2. Login to Github's NPM registry (yes you need to do it, even if the package is public):
98
+ 1. Run the following command (Info about `--auth-type=legacy` [here](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#authenticating-with-a-personal-access-token)):
99
+
100
+ ```bash
101
+ npm login --scope=@evadev --auth-type=legacy --registry=https://npm.pkg.github.com
102
+ ```
103
+
104
+ 2. Enter your username when asked
105
+ 3. Paste the access token as password value
106
+
107
+ 3. Install the package by executing:
108
+
109
+ ```bash
110
+ npm i @evadev/git-dl
111
+ ```
112
+
113
+ </details>
114
+ <details>
115
+ <summary>
116
+
117
+ ### Install package with CLI and functions from [Github Releases](https://github.com/nikelborm/git-dl/releases)
118
+
119
+ </summary>
120
+
121
+ ```bash
122
+ PACKAGE=git-dl
123
+
124
+ # Either set specific tag
125
+ TAG=0.1.28 && npm i https://github.com/nikelborm/$PACKAGE/releases/download/$TAG/$PACKAGE.tgz
126
+ # or download the latest
127
+ npm i https://github.com/nikelborm/$PACKAGE/releases/latest/download/$PACKAGE.tgz
128
+ ```
129
+
130
+ </details>
131
+ <details open>
132
+ <summary>
133
+
134
+ ### Install only the CLI directly into the system from [Github Releases](https://github.com/nikelborm/git-dl/releases)
135
+
136
+ </summary>
137
+
138
+ ```bash
139
+ set -euo pipefail
140
+ PACKAGE=git-dl
141
+
142
+ path_to_the_script=/usr/bin/$PACKAGE
143
+
144
+ # Either set specific tag
145
+ TAG=0.1.28 && sudo curl -sLo $path_to_the_script https://github.com/nikelborm/$PACKAGE/releases/download/$TAG/$PACKAGE.js
146
+ # or download the latest
147
+ sudo curl -sLo $path_to_the_script https://github.com/nikelborm/$PACKAGE/releases/latest/download/$PACKAGE.js
148
+
149
+ sudo chmod +x $path_to_the_script
150
+ ```
151
+
152
+ </details>
153
+ <details>
154
+ <summary>
155
+
156
+ ### Setup the repo for local development
157
+
158
+ </summary>
159
+
160
+ ```bash
161
+ git clone -b main git@github.com:nikelborm/git-dl.git
162
+ cd git-dl
163
+ npm install
164
+ cp template.env .env
165
+ read -sp 'Enter github access token: ' gh_token; echo;
166
+ sed -i "s/\(GITHUB_ACCESS_TOKEN\)='.*'/\1='$gh_token'/" .env
167
+ ```
168
+
169
+ </details>
170
+
171
+ ## Usage
172
+
173
+ ### EcmaScript module
174
+
175
+ ```ts
176
+ import {
177
+ downloadEntityFromRepo,
178
+ OctokitLayer,
179
+ FailedToParseGitLFSInfoError,
180
+ GitHubApiBadCredentialsError,
181
+ type InputConfig,
182
+ type OutputConfig,
183
+ type SingleTargetConfig,
184
+ repoNameCLIOptionBackedByEnv,
185
+ repoOwnerCLIOptionBackedByEnv,
186
+ // etc...
187
+ } from 'git-dl';
188
+ // or '@evadev/git-dl' for non-default installation methods
189
+ ```
190
+
191
+ ### Execution of CLI installed with NPM
192
+
193
+ The **easiest way** to execute the CLI (preliminary installation is not required) is
194
+ like this:
195
+
196
+ ```bash
197
+ npx git-dl --repoOwner apache --repoName superset
198
+ ```
199
+
200
+ Also there's a shorter form available (preliminary installation is required):
201
+
202
+ ```bash
203
+ npx gdl --repoOwner apache --repoName superset
204
+ ```
205
+
206
+ <details>
207
+ <summary>
208
+
209
+ ### Non-interactive CLI execution on the fly from [Github Releases](https://github.com/nikelborm/git-dl/releases)
210
+
211
+ </summary>
212
+
213
+ If you already know the supported arguments (e.g. `--help` to print them all),
214
+ you can pipe the bundled and minified script version into node directly and pass
215
+ your arguments after `node -`:
216
+
217
+ ```bash
218
+ set -euo pipefail
219
+
220
+ # Either set specific tag
221
+ TAG=0.1.28 && curl -sL https://github.com/nikelborm/$PACKAGE/releases/download/$TAG/$PACKAGE.js | node - --repoOwner apache --repoName superset
222
+ # or download the latest
223
+ curl -sL https://github.com/nikelborm/$PACKAGE/releases/latest/download/$PACKAGE.js | node - --repoOwner apache --repoName superset
224
+ ```
225
+
226
+ </details>
227
+ <details>
228
+ <summary>
229
+
230
+ ### Interactive CLI execution from [Github Releases](https://github.com/nikelborm/git-dl/releases)
231
+
232
+ </summary>
233
+
234
+ The script also supports interactive mode (`--wizard`), where you will be asked
235
+ to pass arguments sequentially and interactively. Since it requires user input,
236
+ it can't be piped and needs to be saved to a temporary file:
237
+
238
+ ```bash
239
+ set -euo pipefail
240
+ tmp_js=$(mktemp --suffix .js)
241
+
242
+ # Either set specific tag
243
+ TAG=0.1.28 && curl -sLo $tmp_js https://github.com/nikelborm/$PACKAGE/releases/download/$TAG/$PACKAGE.js
244
+ # or download the latest
245
+ curl -sLo $tmp_js https://github.com/nikelborm/$PACKAGE/releases/latest/download/$PACKAGE.js
246
+
247
+ node $tmp_js --wizard
248
+ rm $tmp_js
249
+ ```
250
+
251
+ </details>
252
+ <details open>
253
+ <summary>
254
+
255
+ ### Execution of CLI installed directly into the system
256
+
257
+ </summary>
258
+
259
+ ```bash
260
+ git-dl --repoOwner apache --repoName superset
261
+ ```
262
+
263
+ </details>
264
+
265
+ ## Environment Variables
266
+
267
+ If you often use the CLI, you can permanently set the arguments via env
268
+ variables, and they will be used as a backup if arguments weren't provided
269
+ explicitly.
270
+
271
+ - `GITHUB_ACCESS_TOKEN`: This is your personal access token from GitHub. It is
272
+ used to authenticate your requests to the GitHub API. You can generate one
273
+ [here](https://github.com/settings/tokens/new?description=Read%20repo%20contents%20access%20to%20fetch-github-folder&scopes=public_repo&default_expires_at=none).
274
+ - `REPO_OWNER`: This is the username of the owner of the repository you are
275
+ trying to download from. For example, if the repository's URL is
276
+ `https://github.com/apache/superset`, the owner is `apache`.
277
+ - `REPO_NAME`: This is the name of the repository you are trying to download
278
+ from. In the example above, the repository name is `superset`.
279
+ - `PATH_TO_ENTITY_IN_REPO`: This is the path to the directory you want to
280
+ download. It can be directory that lies inside root of repo like `docker` or
281
+ it can be some nested directory like `docker/nginx`.
282
+ - `GIT_REF`: This is the commit SHA hash, branch name, or tag name you want to
283
+ download from. If you don't specify it, the default branch in the repository
284
+ will be used.
285
+ - `DESTINATION_PATH`: If entity at `PATH_TO_ENTITY_IN_REPO` is a file, then
286
+ destination path is a path to downloaded file. If it's a directory, then all
287
+ files and directories from target directory of remote repository at
288
+ `PATH_TO_ENTITY_IN_REPO` will be put into a directory having
289
+ `DESTINATION_PATH` path. If the directory doesn't exist, it will be
290
+ automatically created.
package/dist/git-dl.js ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ import { prettyPrint } from 'effect-errors';
3
+ import * as CliConfig from '@effect/cli/CliConfig';
4
+ import * as CliCommand from '@effect/cli/Command';
5
+ import * as HelpDocSpan from '@effect/cli/HelpDoc/Span';
6
+ import * as NodeFileSystem from '@effect/platform-node/NodeFileSystem';
7
+ import * as NodePath from '@effect/platform-node/NodePath';
8
+ import * as NodeRuntime from '@effect/platform-node/NodeRuntime';
9
+ import * as NodeTerminal from '@effect/platform-node/NodeTerminal';
10
+ import * as Effect from 'effect/Effect';
11
+ import { pipe } from 'effect/Function';
12
+ import * as Layer from 'effect/Layer';
13
+ import pkg from './package.json' with { type: 'json' };
14
+ import { destinationPathCLIOptionBackedByEnv, gitRefCLIOptionBackedByEnv, pathToEntityInRepoCLIOptionBackedByEnv, repoNameCLIOptionBackedByEnv, repoOwnerCLIOptionBackedByEnv, } from "./src/commandLineParams.js";
15
+ import { downloadEntityFromRepo } from "./src/downloadEntityFromRepo.js";
16
+ import { OctokitLayer } from "./src/octokit.js";
17
+ const appCommand = CliCommand.make(pkg.name, {
18
+ repo: {
19
+ owner: repoOwnerCLIOptionBackedByEnv,
20
+ name: repoNameCLIOptionBackedByEnv,
21
+ },
22
+ pathToEntityInRepo: pathToEntityInRepoCLIOptionBackedByEnv,
23
+ localPathAtWhichEntityFromRepoWillBeAvailable: destinationPathCLIOptionBackedByEnv,
24
+ gitRef: gitRefCLIOptionBackedByEnv,
25
+ }, downloadEntityFromRepo);
26
+ const cli = CliCommand.run(appCommand, {
27
+ name: pkg.name,
28
+ version: pkg.version,
29
+ summary: HelpDocSpan.text(pkg.description),
30
+ });
31
+ const AppLayer = Layer.mergeAll(NodeFileSystem.layer, NodePath.layer, NodeTerminal.layer, CliConfig.layer({ showTypes: false }), OctokitLayer({
32
+ // auth: getEnvVarOrFail('GITHUB_ACCESS_TOKEN'),
33
+ }));
34
+ pipe(process.argv, cli, Effect.withSpan('cli', {
35
+ attributes: {
36
+ name: pkg.name,
37
+ version: pkg.version,
38
+ },
39
+ }), Effect.sandbox, Effect.catchAll(e => {
40
+ console.error(prettyPrint(e));
41
+ return Effect.fail(e);
42
+ }), Effect.provide(AppLayer), NodeRuntime.runMain({ disableErrorReporting: true }));
43
+ //# sourceMappingURL=git-dl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-dl.js","sourceRoot":"","sources":["../git-dl.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAA;AACjD,OAAO,KAAK,WAAW,MAAM,0BAA0B,CAAA;AACvD,OAAO,KAAK,cAAc,MAAM,sCAAsC,CAAA;AACtE,OAAO,KAAK,QAAQ,MAAM,gCAAgC,CAAA;AAC1D,OAAO,KAAK,WAAW,MAAM,mCAAmC,CAAA;AAChE,OAAO,KAAK,YAAY,MAAM,oCAAoC,CAAA;AAClE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,GAAG,MAAM,gBAAgB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AACtD,OAAO,EACL,mCAAmC,EACnC,0BAA0B,EAC1B,sCAAsC,EACtC,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAA;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE/C,MAAM,UAAU,GAAG,UAAU,CAAC,IAAI,CAChC,GAAG,CAAC,IAAI,EACR;IACE,IAAI,EAAE;QACJ,KAAK,EAAE,6BAA6B;QACpC,IAAI,EAAE,4BAA4B;KACnC;IACD,kBAAkB,EAAE,sCAAsC;IAC1D,6CAA6C,EAC3C,mCAAmC;IACrC,MAAM,EAAE,0BAA0B;CACnC,EACD,sBAAsB,CACvB,CAAA;AAED,MAAM,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE;IACrC,IAAI,EAAE,GAAG,CAAC,IAAI;IACd,OAAO,EAAE,GAAG,CAAC,OAAO;IACpB,OAAO,EAAE,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAC7B,cAAc,CAAC,KAAK,EACpB,QAAQ,CAAC,KAAK,EACd,YAAY,CAAC,KAAK,EAClB,SAAS,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,EACrC,YAAY,CAAC;AACX,gDAAgD;CACjD,CAAC,CACH,CAAA;AAED,IAAI,CACF,OAAO,CAAC,IAAI,EACZ,GAAG,EACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE;IACrB,UAAU,EAAE;QACV,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,OAAO,EAAE,GAAG,CAAC,OAAO;KACrB;CACF,CAAC,EACF,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE;IAClB,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;IAE7B,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACvB,CAAC,CAAC,EACF,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EACxB,WAAW,CAAC,OAAO,CAAC,EAAE,qBAAqB,EAAE,IAAI,EAAE,CAAC,CACrD,CAAA"}
@@ -0,0 +1,138 @@
1
+ {
2
+ "name": "git-dl",
3
+ "type": "module",
4
+ "version": "0.2.0",
5
+ "description": "Download any directory at any depth from any repo on GitHub on any git ref",
6
+ "devDependencies": {
7
+ "@effect/language-service": "catalog:",
8
+ "@effect/vitest": "catalog:",
9
+ "@evadev/tsconfig": "workspace:*",
10
+ "@rollup/plugin-commonjs": "catalog:",
11
+ "@rollup/plugin-json": "catalog:",
12
+ "@rollup/plugin-node-resolve": "catalog:",
13
+ "@rollup/plugin-terser": "catalog:",
14
+ "@vitest/coverage-v8": "catalog:",
15
+ "rollup": "catalog:",
16
+ "rollup-plugin-visualizer": "catalog:",
17
+ "ts-namespace-import": "catalog:",
18
+ "ts-patch": "catalog:",
19
+ "typescript": "catalog:",
20
+ "vitest": "catalog:"
21
+ },
22
+ "peerDependencies": {
23
+ "@effect/cli": "catalog:",
24
+ "@effect/platform": "catalog:",
25
+ "@effect/platform-node": "catalog:",
26
+ "effect": "catalog:"
27
+ },
28
+ "dependencies": {
29
+ "@evadev/effect-helpers": "workspace:*",
30
+ "@octokit/core": "catalog:",
31
+ "@octokit/request-error": "catalog:",
32
+ "@octokit/types": "catalog:",
33
+ "@total-typescript/ts-reset": "catalog:",
34
+ "@types/tar-fs": "catalog:",
35
+ "effect-errors": "catalog:",
36
+ "outdent": "catalog:",
37
+ "tar-fs": "catalog:",
38
+ "tsafe": "catalog:"
39
+ },
40
+ "homepage": "https://github.com/nikelborm/effect-garden/tree/main/packages/git-dl#readme",
41
+ "bugs": {
42
+ "url": "https://github.com/nikelborm/effect-garden/issues",
43
+ "email": "evadev@duck.com"
44
+ },
45
+ "keywords": [
46
+ "github",
47
+ "git",
48
+ "octokit",
49
+ "github-api",
50
+ "folder",
51
+ "scraper",
52
+ "downloader",
53
+ "download",
54
+ "extract",
55
+ "tarball",
56
+ "targz",
57
+ "directory"
58
+ ],
59
+ "repository": {
60
+ "type": "git",
61
+ "url": "git+ssh://git@github.com/nikelborm/effect-garden.git",
62
+ "directory": "packages/git-dl"
63
+ },
64
+ "scripts": {
65
+ "build": "./scripts/build.sh",
66
+ "coverage": "vitest run --coverage",
67
+ "doc": "./scripts/generate_docs.sh",
68
+ "docs": "./scripts/generate_docs.sh",
69
+ "print-important-ts-files": "find . -type f -name '*.ts' |grep -vE '^./(node_modules|tmp|dist|(vite\\.config|.*\\.spec|scratchpad)\\.ts)'",
70
+ "scratchpad": "node --use-strict --env-file=.env ./scratchpad.ts",
71
+ "start": "node --env-file=.env ./git-dl.ts",
72
+ "test": "vitest --typecheck --watch",
73
+ "test-jsr": "tspc && jsr publish --dry-run",
74
+ "test-once": "vitest --run",
75
+ "watch-docs": "find src/ cli.ts index.ts errors.ts ./scripts/generate_docs.sh | entr -can ./scripts/generate_docs.sh"
76
+ },
77
+ "author": {
78
+ "name": "nikelborm",
79
+ "email": "evadev@duck.com",
80
+ "url": "https://github.com/nikelborm"
81
+ },
82
+ "contributors": [
83
+ {
84
+ "name": "nikelborm",
85
+ "email": "evadev@duck.com",
86
+ "url": "https://github.com/nikelborm"
87
+ }
88
+ ],
89
+ "maintainers": [
90
+ {
91
+ "name": "nikelborm",
92
+ "email": "evadev@duck.com",
93
+ "url": "https://github.com/nikelborm"
94
+ }
95
+ ],
96
+ "license": "MIT",
97
+ "private": false,
98
+ "publishConfig": {
99
+ "access": "public",
100
+ "provenance": false
101
+ },
102
+ "exports": {
103
+ ".": {
104
+ "types": "./dist-types/index.d.ts",
105
+ "default": "./dist/index.js"
106
+ },
107
+ "./*.js": {
108
+ "types": "./dist-types/src/*.d.ts",
109
+ "default": "./dist/src/*.js"
110
+ },
111
+ "./*.ts": "./src/*.ts",
112
+ "./*": {
113
+ "types": "./dist-types/src/*.d.ts",
114
+ "default": "./dist/src/*.js"
115
+ },
116
+ "./package.json": "./package.json"
117
+ },
118
+ "main": "./dist/index.js",
119
+ "module": "./dist/index.js",
120
+ "types": "./dist-types/index.d.ts",
121
+ "bin": {
122
+ "gdl": "dist/git-dl.js",
123
+ "git-dl": "dist/git-dl.js"
124
+ },
125
+ "files": [
126
+ "dist",
127
+ "dist-types",
128
+ "index.ts",
129
+ "cli.ts",
130
+ "errors.ts",
131
+ "template.env",
132
+ "src",
133
+ "!dist/minified",
134
+ "!**/*.tsbuildinfo",
135
+ "!**/*.spec.*",
136
+ "!**/scratchpad.*"
137
+ ]
138
+ }
@@ -0,0 +1,27 @@
1
+ import * as Data from 'effect/Data';
2
+ import * as Predicate from 'effect/Predicate';
3
+ const removeLastIfItIsEmptyObject = (arr) => Object.keys(arr.at(-1) ?? {}).length ? arr : arr.slice(0, -1);
4
+ export const buildTaggedErrorClassVerifyingCause = () => (errorName, customMessage, expectedCauseClass, staticContext) => {
5
+ // TODO: Consider using Schema.TaggedError instead of Data.TaggedError
6
+ const CustomTaggedErrorClass = (Data.TaggedError(errorName));
7
+ class Base extends CustomTaggedErrorClass {
8
+ constructor(...args) {
9
+ if (expectedCauseClass && !(args[0] instanceof expectedCauseClass))
10
+ throw new Error(`Provided cause of incorrect type to "${errorName}" class. Expected cause class: "${expectedCauseClass.name}"`);
11
+ const customMessageRendererArgs = removeLastIfItIsEmptyObject(expectedCauseClass
12
+ ? [args[0], { ...(args[1] ?? {}), ...staticContext }]
13
+ : [{ ...(args[0] ?? {}), ...staticContext }]);
14
+ super({
15
+ name: errorName,
16
+ message: Predicate.isFunction(customMessage)
17
+ ? customMessage(...customMessageRendererArgs)
18
+ : customMessage,
19
+ ...(!!expectedCauseClass && { cause: args[0] }),
20
+ ...staticContext,
21
+ ...(args[+!!expectedCauseClass] ?? {}), // dynamic context
22
+ });
23
+ }
24
+ }
25
+ return Base;
26
+ };
27
+ //# sourceMappingURL=TaggedErrorVerifyingCause.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TaggedErrorVerifyingCause.js","sourceRoot":"","sources":["../../src/TaggedErrorVerifyingCause.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AACnC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAE7C,MAAM,2BAA2B,GAAG,CAAC,GAAmB,EAAE,EAAE,CAC1D,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAE/D,MAAM,CAAC,MAAM,mCAAmC,GAC9C,GAA8D,EAAE,CAChE,CAWE,SAAoB,EACpB,aAA0E,EAC1E,kBAAuC,EACvC,aAA6B,EACH,EAAE;IAC5B,sEAAsE;IACtE,MAAM,sBAAsB,GAAG,CAAA,IAAI,CAAC,WAAW,CAAC,SAAS,CAExD,CAAA,CAAA;IAED,MAAM,IAAK,SAAQ,sBAAsB;QACvC,YAAY,GAAG,IAA6B;YAC1C,IAAI,kBAAkB,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,kBAAkB,CAAC;gBAChE,MAAM,IAAI,KAAK,CACb,wCACE,SACF,mCAAmC,kBAAkB,CAAC,IAAI,GAAG,CAC9D,CAAA;YAEH,MAAM,yBAAyB,GAAG,2BAA2B,CAC3D,kBAAkB;gBAChB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,aAAa,EAAE,CAAC;gBACrD,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,aAAa,EAAE,CAAC,CAChB,CAAA;YAEhC,KAAK,CAAC;gBACJ,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,SAAS,CAAC,UAAU,CAAC,aAAa,CAAC;oBAC1C,CAAC,CAAC,aAAa,CAAC,GAAG,yBAAyB,CAAC;oBAC7C,CAAC,CAAC,aAAa;gBACjB,GAAG,CAAC,CAAC,CAAC,kBAAkB,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC/C,GAAG,aAAa;gBAChB,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC,EAAE,kBAAkB;aAC3D,CAAC,CAAA;QACJ,CAAC;KACF;IAED,OAAO,IAAgC,CAAA;AACzC,CAAC,CAAA"}
@@ -0,0 +1,28 @@
1
+ import { Readable } from 'node:stream';
2
+ import { ReadableStream } from 'node:stream/web';
3
+ import * as Effect from 'effect/Effect';
4
+ import { buildTaggedErrorClassVerifyingCause, } from "./TaggedErrorVerifyingCause.js";
5
+ // TODO: should eventually delete this shit because:
6
+ // 1. Effect has streams and I now know them well
7
+ // 2. Effect has Platform's utilities like BunSink and BunStream
8
+ export const CastToReadableStream = (self) => Effect.gen(function* () {
9
+ const data = yield* self;
10
+ if (data instanceof ArrayBuffer || data instanceof Buffer)
11
+ return new Readable({
12
+ read() {
13
+ this.push(data);
14
+ this.push(null);
15
+ },
16
+ });
17
+ if (data instanceof ReadableStream)
18
+ return Readable.fromWeb(data);
19
+ if (data instanceof Readable)
20
+ return data;
21
+ return yield* new FailedToCastDataToReadableStreamError();
22
+ });
23
+ // Extracting to a separate type is required by JSR, so that consumers of the
24
+ // library will have much faster type inference
25
+ const _1 = buildTaggedErrorClassVerifyingCause()('FailedToCastDataToReadableStreamError', 'Error: Failed to cast data to Readable stream, type of argument is not familiar');
26
+ export class FailedToCastDataToReadableStreamError extends _1 {
27
+ }
28
+ //# sourceMappingURL=castToReadableStream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"castToReadableStream.js","sourceRoot":"","sources":["../../src/castToReadableStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,EACL,mCAAmC,GAEpC,MAAM,gCAAgC,CAAA;AAEvC,oDAAoD;AACpD,iDAAiD;AACjD,gEAAgE;AAChE,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,IAAkC,EAClC,EAAE,CACF,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,IAAI,CAAA;IAExB,IAAI,IAAI,YAAY,WAAW,IAAI,IAAI,YAAY,MAAM;QACvD,OAAO,IAAI,QAAQ,CAAC;YAClB,IAAI;gBACF,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBACf,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACjB,CAAC;SACF,CAAC,CAAA;IAEJ,IAAI,IAAI,YAAY,cAAc;QAAE,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAEjE,IAAI,IAAI,YAAY,QAAQ;QAAE,OAAO,IAAI,CAAA;IAEzC,OAAO,KAAK,CAAC,CAAC,IAAI,qCAAqC,EAAE,CAAA;AAC3D,CAAC,CAAC,CAAA;AAEJ,6EAA6E;AAC7E,+CAA+C;AAC/C,MAAM,EAAE,GAEH,mCAAmC,EAAE,CACxC,uCAAuC,EACvC,iFAAiF,CAClF,CAAA;AAED,MAAM,OAAO,qCAAsC,SAAQ,EAAE;CAAG"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Reusable in {@link https://effect.website/ Effect} applications CLI Options
3
+ * backed by ENV variables
4
+ *
5
+ * @module
6
+ */
7
+ export { destinationPathCLIOptionBackedByEnv, gitRefCLIOptionBackedByEnv, pathToEntityInRepoCLIOptionBackedByEnv, repoNameCLIOptionBackedByEnv, repoOwnerCLIOptionBackedByEnv, } from "./commandLineParams.js";
8
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,mCAAmC,EACnC,0BAA0B,EAC1B,sCAAsC,EACtC,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,wBAAwB,CAAA"}