(Don't judge me for my obsession with badges)
[!CAUTION]
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. Check out the
dev
branch to see the latest updates! 😉 (except that I currently don't care and just push to main)
This project allows you to download any folder inside a repo on github.
You need to have installed latest node, git, npm
From default NPM registry
npm i fetch-github-folder
From JSR
Unfortunately JSR doesn't support publishing executables yet, so you can install only script library with functions that will allow you to fetch github folder from other scripts.
npx jsr add @nikelborm/fetch-github-folder
-
Generate
Personal access token (classic)
withread:packages
scope -
Save the token
-
Login to Github's NPM registry (yes you need to do it, even if the package is public):
npm login --scope=@nikelborm --auth-type=legacy --registry=https://npm.pkg.github.com
You can also read more about
--auth-type=legacy
here -
Enter your username when asked
-
Paste the token as password value
-
Then install the package by executing:
npm i @nikelborm/fetch-github-folder
# Clone this repo:
git clone -b main https://github.com/nikelborm/fetch-github-folder.git
# cd to it:
cd fetch-github-folder
# Install dependencies:
npm install
# Create .env file:
cp template.env .env
# Ask for token
read -sp 'Enter github access token: ' gh_token; echo;
# And immediately put it into .env
sed -i "s/\(GITHUB_ACCESS_TOKEN\)='.*'/\1='$gh_token'/" .env
-
GITHUB_ACCESS_TOKEN
: This is your personal access token from GitHub. It is used to authenticate your requests to the GitHub API. You can generate one here. -
REPO_OWNER
: This is the username of the owner of the repository you are trying to download from. For example, if the repository's URL ishttps://github.com/apache/superset
, the owner isapache
. -
REPO_NAME
: This is the name of the repository you are trying to download from. In the example above, the repository name issuperset
. -
PATH_TO_ENTITY_IN_REPO
: This is the path to the directory you want to download. It can be directory that lies inside root of repo likedocker
or it can be some nested directory likedocker/nginx
. -
GIT_REF
: This is the commit SHA hash, branch name, or tag name you want to download from. If you don't specify it, the default branch in the repository will be used. -
DESTINATION_PATH
: If entity atPATH_TO_ENTITY_IN_REPO
is a file, then destination path is a path to downloaded file. If it's a directory, then all files and directories from target directory of remote repository atPATH_TO_ENTITY_IN_REPO
will be put into a directory with path fromDESTINATION_PATH
. If the directory doesn't exist, it will be automatically created.
- Set env variables in
.env
file - Run
npm start