0.0.12 • Published 4 years ago

@dking/dgit v0.0.12

Weekly downloads
13
License
MIT
Repository
-
Last release
4 years ago

Dgit

Dgit is a portable tool for downloading the specified directory or file of GitHub Repo. It can be used as a command line for global installation on the terminal, or as a node module. This tool does not rely on the local git, can directly download the specified directory file, reduce the traffic consumption, and is very suitable for scenarios where you want to download large projects, and can directly download the content you need.

Install

  • Global Installation
$ npm install @dking/dgit -g
  • Local Installation
$ npm install @dking/dgit --save
$ yarn add @dking/dgit

Usage

  • Global installation, using as command line
$ dgit d https://github.com/JohnApache/hasaki-cli/tree/master/src -d ./abc
  • Local installation as module
import dgit from '@dking/dgit';

(async () => {
    await dgit(
        {
            owner: 'JohnApache',
            repoName: 'hasaki-cli',
            ref: 'master',
            relativePath: 'src',
        },
        './aaa',
    );
    console.log('download succeed');
})()

Configuration

  • Global installation, used as command line, configurable parameters

    • Commands:
      • download|d options Download the specified files of the specified repo or all files under the specified directory
    • Options:
      • --owner Git repository author name
      • --repo-name Git repo name
      • --ref Git repo branch,commit hash or tagname
      • --relative-path Specifies the relative location of the directory or file that git needs to download. default: '.'
      • -d, --dest Specify the file output directory, either absolute path or relative path of the current terminal execution path
      • -l, --parallel-limit, Specify the number of concurrent downloads,default: 10.
      • -u, --username, Specify git account name, configuration parameters required when downloading private repo.
      • -p --password, Specify the git account password, which is used with username, and the configuration parameters required when downloading the private repo.
      • -t --token, Git token is another configurable parameter of login mode, which is used to download private repo.
      • -e --exclude, <relativePath,...,relativePath> Specifies the collection of files or directory paths that need to be excluded for the current download directory.
      • -i --include, <relativePath,...,relativePath> Specifies the collection of files or directories that need to be included again in the currently excluded file path collection.
      • -h, --help Output usage information
  • Local installation, configurable parameters when used as a module

    import dgit from '@dking/dgit';
    import path from 'path';
    const repoOption = {
        owner: 'JohnApache'; // Git repository author name
        repoName: 'hasaki-cli'; // Git repo name
        ref: 'master'; // Git repo branch,commit hash or tagname,
        relativePath: '.'; // Specifies the relative location of the directory or file that git needs to download
        username: ''; // Specify git account name.
        password: ''; // Specify the git account password.
        token: ''; // Git token is another configurable parameter of login mode.
    }
    
    const githubLinkOption = {
        githubLink: 'https://github.com/JohnApache/hasaki-cli/blob/master/PLAN.txt',
        // You can also directly specify the download path address of gitHub
    }
    
    const destPath = path.resolve(__dirname, './aaa'); // Specify the file output directory
    
    const dgitOptions = {
        maxRetryCount: 3, // The maximum number of attempts to download again when the download fails due to network problems
        parallelLimit: 10, // Number of parallel downloads
        log: false, // Open internal log
        logSuffix: '', // Log output prefix
        exclude: [], // excluded paths,
        include: [], // include paths
    }
    
    const hooks = {
        onSuccess: () => void,
        onError: (err) => err,
        onProgress: (status, node) => void,
        onResolved: (status) => void,
    }
(async () => {
    await dgit(
        repoOption,
        destPath,
        dgitOptions,
        hooks,
    );
    console.log('repoOption download succeed.');

    await dgit(
        githubLinkOption,
        destPath,
        dgitOptions,
        hooks,
    );
    console.log('githubLinkOption download succeed.');
})()
``` 

TIPS

When downloading the private repo, you need to provide download permission. At this time, you need to pass in additional parameters in two ways

  • Basic authentication

    Download permission is provided by passing in user name and password. When passing in user name, password can not be provided explicitly. When password is not provided, password input option will appear password prompt;

    $ dgit d https://github.com/JohnApache/hasaki-cli/tree/master/src -d ./abc -u JohnApache
  • OAuth2 token

    Token is another way of authority authentication provided by GitHub.

    Set the token method, which is located in Github Settings -> Developer settings -> Personal access tokens

    $ dgit d https://github.com/JohnApache/hasaki-cli/tree/master/src -d ./abc -t OAUTH-TOKEN

Questions

Please open an issue here.

License

MIT