download-git-repo 是个npm包,用来从一个代码仓库中下载代码用的。官网摘抄如下:
Download and extract a git repository (GitHub, GitLab, Bitbucket) from node.
接口如下:
download(repository, destination, options, callback)
Download a git repository
to a destination
folder with options
, and callback
.
此API的第一个参数repository 用两种写法,一个是代码仓库的简写形式:
- GitHub -
github:owner/name
or simplyowner/name
- GitLab -
gitlab:owner/name
- Bitbucket -
bitbucket:owner/name
例如你的GitHub上有个项目,可以这么写:
const download = require('download-git-repo');
download('github:liubbc/uni-app',src/uni-app, function (err) {
console.log(err ? 'Error:' : 'Success:')
})
这样写是不行的:
const download = require('download-git-repo');
download('git@github.com:liubbc/uni-app.git', src/uni-app, function (err) {
console.log(err ? 'Error:' : 'Success:')
})
另外一种写法是直接写url的形式,例如:
const download = require('download-git-repo');
download('direct:https://github.com/liubbc/uni-app.git', src/uni-app, { clone: true }, function (err) {
console.log(err ? 'Error:' : 'Success:')
})
如果我们的项目代码放在了gerrit库中,那么要用直接写url的形式,例如:
const download = require('download-git-repo');
download('direct:http://10.128.128.128:8092/HTML5/miniProgram', src/uni-app, { clone: true }, function (err) {
console.log(err ? 'Error:' : 'Success:')
})
详细用法还是看download-git-repo 官网