Code Monkey home page Code Monkey logo

download-github's Introduction

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

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

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

# 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!

download-github's People

Contributors

lencx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.