# zdex-downloadgitrepo

> NodeJS git repository 下载工具，支持 GitHub, Gitee, GitLab, Bitbucket

Latest version **1.2.0** (published 2019-03-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install zdex-downloadgitrepo
pnpm add zdex-downloadgitrepo
yarn add zdex-downloadgitrepo
bun add zdex-downloadgitrepo
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2019-03-27 |
| First published | 2019-03-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 17.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | evilrule |
| Maintainers | evilrule |
| Keywords | download, github, gitee, bitbucket, repo, repository, tar, extract, tarball |

## Links

- npm: https://www.npmjs.com/package/zdex-downloadgitrepo
- Repository: https://gitee.com/evilrule/zdex-downloadgitrepo
- npm.io page: https://npm.io/package/zdex-downloadgitrepo

## Dependencies (3)

- [rimraf](https://npm.io/package/rimraf.md) ^2.6.1
- [download](https://npm.io/package/download.md) ^5.0.3
- [git-clone](https://npm.io/package/git-clone.md) ^0.1.0

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 1.2.0 (latest) — 2019-03-27

## README

# [zdex-downloadgitrepo](https://gitee.com/evilrule/zdex-downloadgitrepo)

NodeJS git repository 下载工具，支持 GitHub, Gitee, GitLab, Bitbucket

## 安装

    $ npm install zdex-downloadgitrepo

## API

### download(repository, destination, options, callback)

下载 git `repository` 到目标文件夹 `destination`。可以配置 `options` 参数，下载完成后调用回调函数 `callback`。

#### repository

仓库地址简写字符串：

- **GitHub** - `github:owner/name` 或者 `owner/name`
- **Gitee** - `gitee:owner/name` 
- **GitLab** - `gitlab:owner/name`
- **Bitbucket** - `bitbucket:owner/name`

`repository` 参数默认使用 `master` 分支，你可以通过使用 URL 片段来指定分支 `owner/name#my-branch`。

为了指定下类型，你可以指定一个自定义来源：`gitlab:custom.com:owner/name`。

除非指定了协议, 否则自定义来源将分别默认为 `https` 或 `git @`

除了使用仓库地址简写字符串来指定 git hosts，你也可直接使用仓库地址：

- **Direct** - `direct:url`

使用 direct 将绕过 仓库地址简写字符串 解释器，直接使用 `url` 地址。
如果在非克隆的情况下使用 `direct`， 则必使用完整 zip 文件 url ，如果需要，请指定包括分支的完整路径。
如果在克隆的情况下使用 `direct`，你必须指定 git 仓库的完整地址，可以用 URL 片段指定分支，格式形如: `direct:url#my-branch`

#### destination
下载 repository 的存储目标地址。

#### options

一个可选的参数对象，可设参数包括：

- `clone` - {Boolean} 默认值 `false` - true 表示使用 `git clone` 替代 http 下载；虽然速度可能会稍慢一些, 但如果设置了适当的 SSH 密钥， 则允许使用私有仓库 （private repositories）。

#### callback
形如  `function (err)` 的回调函数。

## Examples

### 仓库地址简写字符串（Shorthand ）

使用 http 方式从 Github repository 的 master 分支下载。

```javascript
download('flipxfx/download-git-repo-fixture', 'test/tmp', function (err) {
  console.log(err ? 'Error' : 'Success')
})
```

使用 git clone 方式从 Gitee repository 的 master 分支下载。

```javascript
download('gitee:evilrule/zdcg-template-common', 'test/tmp', { clone: true }, function (err) {
  console.log(err ? 'Error' : 'Success')
})
```

使用 git clone 方式从 Bitbucket repository 的 my-branch 分支下载。

```javascript
download('bitbucket:flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', { clone: true }, function (err) {
  console.log(err ? 'Error' : 'Success')
})
```

使用 http  方式从 GitLab repository 的 my-branch 分支下载。

```javascript
download('gitlab:mygitlab.com:flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', function (err) {
  console.log(err ? 'Error' : 'Success')
})
```

使用 git clone 方式从自定义来源的和协议的 GitLab repository 下载。

注意：如果从自定义来源的仓库克隆， 仓储类型（`github`,`gitlab` 等）是不需要指定的。

```javascript
download('https://mygitlab.com:flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', { clone: true }, function (err) {
  console.log(err ? 'Error' : 'Success')
})
```

### 直接使用 url（Direct）

直接使用 url 通过 http 下载。

```javascript
download('direct:https://gitlab.com/flipxfx/download-git-repo-fixture/repository/archive.zip', 'test/tmp', function (err) {
  console.log(err ? 'Error' : 'Success')
})
```

使用 url 通过 http 下载 master 分支。

```javascript
download('direct:https://gitlab.com/flipxfx/download-git-repo-fixture.git', 'test/tmp', { clone: true }, function (err) {
  console.log(err ? 'Error' : 'Success')
})
```

使用 url 通过 git clone 下载 my-branch 分支。

```javascript
download('direct:https://gitlab.com/flipxfx/download-git-repo-fixture.git#my-branch', 'test/tmp', { clone: true }, function (err) {
  console.log(err ? 'Error' : 'Success')
})
```

## License

MIT

## 声明

本库基于 [download-git-repo](git://github.com/flipxfx/download-git-repo)  1.1.0 版本扩展开发。

---
_Source: https://npm.io/package/zdex-downloadgitrepo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
