Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lencx/download-github
⬇️ Download directory from a GitHub repo.
https://github.com/lencx/download-github
cli clone-repo dgh download download-github file-downloader
Last synced: 3 months ago
JSON representation
⬇️ Download directory from a GitHub repo.
- Host: GitHub
- URL: https://github.com/lencx/download-github
- Owner: lencx
- License: mit
- Created: 2021-11-13T03:58:08.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-12T12:49:37.000Z (about 3 years ago)
- Last Synced: 2024-05-22T06:00:32.745Z (8 months ago)
- Topics: cli, clone-repo, dgh, download, download-github, file-downloader
- Language: TypeScript
- Homepage:
- Size: 28.3 KB
- Stars: 8
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# download-github
> ⬇️ Download directory from a GitHub repo.
## Usage
[![asciicast](https://asciinema.org/a/453727.svg)](https://asciinema.org/a/453727)
```bash
npm install dgh
``````js
import dgh from "dgh";dgh({
owner: "lencx",
repo: "download-github",
name: "test-dgh",
ref: "main", // default `HEAD`
overwrite: true, // default `true`
root: "./", // default `process.cwd()`
});
``````js
/* *** repo subdir & file overwrite *** */import dgh from "dgh";
dgh({
owner: "lencx",
repo: "download-github",
name: "test-dgh",
ref: "HEAD", // github branch, default 'HEAD'
subdir: "src",
})
.on("info", (msg) => {
console.log(msg);
})
.on("overwrite", (files, fs) => {
files.forEach((file) => {
if (/\/utils.ts$/.test(file)) {
// @see https://github.com/jprichardson/node-fs-extra
fs.appendFileSync(file, `\nexport const DGH = 'DGH';\n`);
}
});
})
.on("end", () => {
console.log("dgh end");
});
```### Options
| Options | Required | Description |
| ----------- | :------: | ------------------------------------ |
| `owner` | Y | github username or organization |
| `repo` | Y | github repository |
| `name` | Y | app name |
| `root` | N | app path, default `process.cwd()` |
| `ref` | N | github branch, default `HEAD` |
| `subdir` | N | repository subdirectory |
| `overwrite` | N | rewrite file content, default `true` |### Event
- `on('overwrite', (files, fs) => void))` - rewrite file content, the options `overwrite` must be `true`
- files: all file paths
- fs: [fs-extra](https://github.com/jprichardson/node-fs-extra) instance
- `on('end', () => void))` - download complete callback event
- `on('info', () => void))` - debug logs## Cli
```bash
npx dgh \
--owner= \
--repo= \
--name= \
--subdir= \
--root=
``````bash
npm install -g dgh
```## Command Args
| Args | Required | Description |
| ---------------- | :------: | --------------------------------- |
| `-h` or `--help` | | dgh command help |
| `--owner` | Y | github username or organization |
| `--repo` | Y | github repository |
| `--name` | Y | app name |
| `--root` | N | app path, default `process.cwd()` |
| `--ref` | N | github branch, default `HEAD` |
| `--subdir` | N | repository subdirectory |### Examples
```bash
# test command 1
npx dgh \
--owner=lencx \
--repo="learn-wasm" \
--name="dgh-test-download" \
--root="my/path"
``````bash
# test command 2
npx dgh \
--owner=lencx \
--repo="learn-wasm" \
--name="dgh-test-download-2" \
--ref="gh-pages" \
--root="my/path"
``````bash
# test command 3
npx dgh \
--owner=lencx \
--repo="learn-wasm" \
--name="dgh-test-download-3" \
--ref="gh-pages" \
--subdir="assets" \
--root="my/path"
```## Related
- [create-mpl](https://github.com/lencx/create-mpl) - ⚡️ Create a project in seconds!