Skip to content

Commit

Permalink
feat: init
Browse files Browse the repository at this point in the history
  • Loading branch information
xlei1123 committed Sep 20, 2024
1 parent 5f908d2 commit fb9b1fb
Show file tree
Hide file tree
Showing 54 changed files with 7,944 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.git
/.vscode
/dist
/lib
.eslintrc.js
node_modules
30 changes: 30 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
parser : '@typescript-eslint/parser', // Specifies the ESLint parser
parserOptions: {
ecmaVersion : 2018, // Allows for the parsing of modern ECMAScript features
sourceType : 'module', // Allows for the use of imports
ecmaFeatures: {},
},
'extends': [ '@dking/typescript' ],
settings : {
'import/parsers': {
'@typescript-eslint/parser': [
'.ts',
'.tsx',
],
},
'import/resolver': {
// use <root>/path/to/folder/tsconfig.json
typescript: { directory: './tsconfig.json' },
},
},
env: {
browser : true, // enable all browser global variables
commonjs: true,
es6 : true,
jest : true,
node : true,
},

rules: {},
};
26 changes: 26 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Node CI

on: [push]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [8.x, 10.x, 12.x]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install, build, and test
run: |
npm install
npm run build:ts --if-present
npm run test:mocha
env:
CI: true
68 changes: 61 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,63 @@
# Dependencies
.psci_modules
.spago
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components
node_modules

# Generated files
.psci
output
# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

yarn.lock
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 JohnApache

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
167 changes: 167 additions & 0 deletions README.en_US.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Dgit

<!-- [![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]
[npm-image]: https://img.shields.io/npm/v/:packageName.svg?style=flat-square
[npm-url]: https://npmjs.org/package/:packageName
[travis-image]: https://www.travis-ci.org/JohnApache/:packageName.svg
[travis-url]: https://travis-ci.org/JohnApache/:packageName
[codecov-image]: https://codecov.io/gh/JohnApache/:packageName/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/JohnApache/:packageName
[snyk-image]: https://snyk.io/test/github/JohnApache/:packageName/badge.svg?targetFile=package.json
[snyk-url]: https://snyk.io/test/github/JohnApache/:packageName?targetFile=package.json
[download-image]: https://img.shields.io/npm/dm/:packageName.svg?style=flat-square
[download-url]: https://npmjs.org/package/:packageName -->

- [English](README.en_US.md)
- [简体中文](README.md)

> 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](#install)
- [Usage](#usage)
- [Configuration](#configuration)
- [TIPS](#tips)
- [Example](#example)
- [Questions](#questions)
- [License](#license)

## Install
+ Global Installation
```bash
$ npm install @limu/dgit -g
```
+ Local Installation
```bash
$ npm install @limu/dgit --save
$ yarn add @limu/dgit
```

## Usage
+ Global installation, using as command line
```bash
$ dgit d https://github.com/JohnApache/hasaki-cli/tree/master/src -d ./abc
```

+ Local installation as module
```js
import dgit from '@limu/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] [githubLink] Download the specified files of the specified repo or all files under the specified directory
- Options:
* --owner <ownerName> Git repository author name
* --repo-name <repoName> Git repo name
* --ref <refName> Git repo branch,commit hash or tagname
* --relative-path <relativePath> Specifies the relative location of the directory or file that git needs to download. default: '.'
* -d, --dest <destPath> Specify the file output directory, either absolute path or relative path of the current terminal execution path
* -l, --parallel-limit, <number> Specify the number of concurrent downloads,default: 10.
* -u, --username, <username> Specify git account name, configuration parameters required when downloading private repo.
* -p --password, <password> Specify the git account password, which is used with username, and the configuration parameters required when downloading the private repo.
* -t --token, <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
```js
import dgit from '@limu/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;
```bash
$ 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

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

## Questions
Please open an issue [here](https://github.com/JohnApache/dgit/issues).

## License

[MIT](LICENSE)
Loading

0 comments on commit fb9b1fb

Please sign in to comment.