本文根据download-git-repo官方文档和个人阅读理解进行翻译。
用node下载并提取一个 git repository (GitHub, GitLab, Bitbucket)
$ npm install download-git-repo
下载一个 git repository
到 destination
文件夹,配置参数 options
, 和 callback回调
.
repository
一、可以采用下面简写方式
github:owner/name 或者
owner/name
gitlab:owner/name
bitbucket:owner/name
1、
默认是 master
分枝, 但你可以指定分枝和tag ,如 owner/name#my-branch
.
2、你还可以指定自定义来源,如 gitlab:custom.com:owner/name
. 自定义来源默认为 https
或 git@
, 你也可以自己之定义协议.
二、Direct - direct:url方式
这种方式会跳过上面简写的方式,直接传递 url
.
1、如果使用 direct,并且没有
clone配置项, 你必须传入完整的zip文件地址, 包括分枝(如果需要的话).
2、如果使用 direct
并带有 clone配置项, 你必须传入完整的 git repo url , 你可以通过 direct:url#my-branch指定分枝
.
destination
下载仓库的文件路径
options(可选)配置对象:
clone
- boolean 默认 false
- 如果设置成 true,会使用 git clone
http 下载. 这种方式可能会比较慢, 他不支持私人的 repositories.proxy
, headers
, filter
, 等.) 会传递下去,并覆盖默认值
callback
回调函数,会传入err.
使用http 下载 Github repository master 分枝.
download('flippidippi/download-git-repo-fixture', 'test/tmp', function (err) {
console.log(err ? 'Error' : 'Success')
})
使用 git clone 下载 Bitbucket repository my-branch 分枝.
download('bitbucket:flippidippi/download-git-repo-fixture#my-branch', 'test/tmp', { clone: true }, function (err) {
console.log(err ? 'Error' : 'Success')
})
使用 http 下载 GitLab 自定义来源仓库,并附带 token.
download('gitlab:mygitlab.com:flippidippi/download-git-repo-fixture#my-branch', 'test/tmp', { headers: { 'PRIVATE-TOKEN': '1234' } } function (err) {
console.log(err ? 'Error' : 'Success')
})
使用git clone 下载自定义来源和协议 GitLab 仓库. 如果clone 一个自定义来源的仓库,tpye (github
, gitlab
等.) 不是必须的.
download('https://mygitlab.com:flippidippi/download-git-repo-fixture#my-branch', 'test/tmp', { clone: true }, function (err) {
console.log(err ? 'Error' : 'Success')
})
direct url http下载方式.
download('direct:https://gitlab.com/flippidippi/download-git-repo-fixture/repository/archive.zip', 'test/tmp', function (err) {
console.log(err ? 'Error' : 'Success')
})
使用direct url git clone 方式下载master分枝.
download('direct:https://gitlab.com/flippidippi/download-git-repo-fixture.git', 'test/tmp', { clone: true }, function (err) {
console.log(err ? 'Error' : 'Success')
})
使用direct url git clone 方式下载 my-branch分枝.
download('direct:https://gitlab.com/flippidippi/download-git-repo-fixture.git#my-branch', 'test/tmp', { clone: true }, function (err) {
console.log(err ? 'Error' : 'Success')
})