๐Ÿ“ฆ lencx / download-github

โฌ‡๏ธ Download directory from a GitHub repo.

โ˜… 10 stars โ‘‚ 2 forks ๐Ÿ‘ 10 watching โš–๏ธ MIT License
cliclone-repodghdownloaddownload-githubfile-downloader
๐Ÿ“ฅ Clone https://github.com/lencx/download-github.git
HTTPS git clone https://github.com/lencx/download-github.git
SSH git clone git@github.com:lencx/download-github.git
CLI gh repo clone lencx/download-github
lencx lencx chore: end event d042d9b 4 years ago ๐Ÿ“ History
๐Ÿ“‚ main View all commits โ†’
๐Ÿ“ bin
๐Ÿ“ src
๐Ÿ“„ .gitignore
๐Ÿ“„ LICENSE
๐Ÿ“„ package.json
๐Ÿ“„ README.md
๐Ÿ“„ tsconfig.json
๐Ÿ“„ README.md

download-github

โฌ‡๏ธ Download directory from a GitHub repo.

Usage

asciicast

npm install dgh

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()`
});

/* *** 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

OptionsRequiredDescription
ownerYgithub username or organization
repoYgithub repository
nameYapp name
rootNapp path, default process.cwd()
refNgithub branch, default HEAD
subdirNrepository subdirectory
overwriteNrewrite 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 instance
  • on('end', () => void)) - download complete callback event
  • on('info', () => void)) - debug logs

Cli

npx dgh \
  --owner=<github_owner> \
  --repo=<github_repo> \
  --name=<app_name> \
  --subdir=<repo_subdir> \
  --root=<app_path>

npm install -g dgh

Command Args

ArgsRequiredDescription
-h or --helpdgh command help
--ownerYgithub username or organization
--repoYgithub repository
--nameYapp name
--rootNapp path, default process.cwd()
--refNgithub branch, default HEAD
--subdirNrepository subdirectory

Examples

# test command 1
npx dgh \
  --owner=lencx \
  --repo="learn-wasm" \
  --name="dgh-test-download" \
  --root="my/path"

# test command 2
npx dgh \
  --owner=lencx \
  --repo="learn-wasm" \
  --name="dgh-test-download-2" \
  --ref="gh-pages" \
  --root="my/path"

# 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 - โšก๏ธ Create a project in seconds!