English | 简体中文
它可以下载 Github 仓库的中部分文件或文件夹
- 下载单个文件
const repo = require('github-download-parts');
// 将会把 index.js 文件下载到本地的 target 文件夹中
repo('pspgbhu/github-download-parts', 'target', 'index.js')
.then(() => {
console.log('download success');
})
.catch(() => {
console.log('download error');
}
- 下载一个文件夹
const repo = require('github-download-parts');
// 将会把 test 文件夹下的全部文件都下载到本地的 target 文件夹中
repo('pspgbhu/github-download-parts', 'target', 'test')
.then(() => {
console.log('download success');
})
.catch(() => {
console.log('download error');
});
- 下载完整的仓库
const repo = require('github-download-parts');
// 将整个仓库都下载到本地的 target 文件夹中
repo('pspgbhu/github-download-parts', 'target')
.then(() => {
console.log('download success');
})
.catch(() => {
console.log('download error');
});
-
git
<string>
可以输入一个字符串作为参数,格式为
"${username}/${repository}"
-
target
<string>
下载的文件将会被创建至该本地文件夹内
-
pathname
<string>
被下载文件在 Github 仓库中的相对地址
或者,你可以使用一个对象来作为 options
参数
- options
<object>
- username
<string>
: Github 的用户名 - repository
<string>
: 仓库的名称. - repo
<string>
:username
和repository
属性的简写,格式为"${username}/${repository}"
- target
<string>
: 下载的文件将会被创建至该本地文件夹内 - pathname
<string>
: 被下载文件在 Github 仓库中的相对地址
- username
# 全局安装
$ npm i -g github-download-parts
# 查看 github-download-parts cli 更多帮助信息
$ repo -h
- 从 Github 仓库中下载文件或文件夹
$ repo -r "username/repository" -t local_folder -p target_file.js
- 下载整个仓库
$ repo -r "username/repository" -t local_folder
-
-r --repo <repo>
: Github 仓库, 格式是"${username}/${repository}"
-
-t --target <dir>
: 下载的文件将会被创建至该本地文件夹内 -
-p --pathname <path>
: 被下载文件在 Github 仓库中的相对地址
通常情况下它不会影响到正常的使用。
由于 Github API 的限制,每个 IP 只允许每小时 60 次的 API 请求,因此 每个 IP 每小时只能进行 60 次的下载