@bratel/dgit 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintignore ADDED
@@ -0,0 +1,6 @@
1
+ /.git
2
+ /.vscode
3
+ /dist
4
+ /lib
5
+ .eslintrc.js
6
+ node_modules
package/.eslintrc.js ADDED
@@ -0,0 +1,30 @@
1
+ module.exports = {
2
+ parser : '@typescript-eslint/parser', // Specifies the ESLint parser
3
+ parserOptions: {
4
+ ecmaVersion : 2018, // Allows for the parsing of modern ECMAScript features
5
+ sourceType : 'module', // Allows for the use of imports
6
+ ecmaFeatures: {},
7
+ },
8
+ 'extends': [ '@dking/typescript' ],
9
+ settings : {
10
+ 'import/parsers': {
11
+ '@typescript-eslint/parser': [
12
+ '.ts',
13
+ '.tsx',
14
+ ],
15
+ },
16
+ 'import/resolver': {
17
+ // use <root>/path/to/folder/tsconfig.json
18
+ typescript: { directory: './tsconfig.json' },
19
+ },
20
+ },
21
+ env: {
22
+ browser : true, // enable all browser global variables
23
+ commonjs: true,
24
+ es6 : true,
25
+ jest : true,
26
+ node : true,
27
+ },
28
+
29
+ rules: {},
30
+ };
@@ -0,0 +1,70 @@
1
+ name: Node CI
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ if: startsWith(github.ref_name, 'v')
8
+ permissions:
9
+ pull-requests: write # for writing comments
10
+ issues: write # for writing comments
11
+ contents: write # for creating a release
12
+ id-token: write # Required for OIDC
13
+
14
+ runs-on: ubuntu-latest
15
+
16
+ strategy:
17
+ matrix:
18
+ node-version: [24.x]
19
+
20
+ steps:
21
+ - name: Checkout Commit
22
+ uses: actions/checkout@v5 # v5.0.0
23
+ with:
24
+ # Necessary to find the commits included in the release
25
+ fetch-depth: 0
26
+ - name: Setup Node
27
+ uses: actions/setup-node@v6 # v6.0.0
28
+ with:
29
+ node-version: ${{ matrix.node-version }}
30
+ registry-url: 'https://registry.npmjs.org'
31
+ - name: Update npm for publishing
32
+ run: npm install -g npm@latest && npm install yarn@latest -g
33
+ - name: npm install, build, and test
34
+ run: |
35
+ npm install
36
+ npm run build:ts --if-present
37
+ npm run test:mocha
38
+ env:
39
+ CI: true
40
+ - name: check auth
41
+ run: |
42
+ cat .npmrc || echo "pass"
43
+ cat ~/.npmrc || echo "pass"
44
+ echo "=== npm config list ==="
45
+ npm config list
46
+ cat /home/runner/work/_temp/.npmrc || echo "pass"
47
+ cp /home/runner/work/_temp/.npmrc x-npmrc || echo "pass"
48
+ # ls -la "$(npm config get prefix)/etc/npmrc" 2>/dev/null || echo "Not found"
49
+ - name: Upload npmrc
50
+ uses: actions/upload-artifact@v4
51
+ with:
52
+ name: 'npmrc'
53
+ path: 'x-npmrc'
54
+ - name: Publish
55
+ if: startsWith(github.ref_name, 'v')
56
+ run: |
57
+ if git --no-pager log -1 --pretty=%B | grep "^v[0-9]\+\.[0-9]\+\.[0-9]\+$";
58
+ then
59
+ echo "Publishing regular release"
60
+ npm publish --access public
61
+ elif git --no-pager log -1 --pretty=%B | grep "^v[0-9]\+\.[0-9]\+\.[0-9]\+-[0-9]\+$";
62
+ then
63
+ echo "Publishing beta release"
64
+ npm publish --tag beta --access public
65
+ else
66
+ echo "Not a release, skipping publish"
67
+ fi
68
+ env:
69
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 JohnApache
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,167 @@
1
+ # Dgit
2
+
3
+ <!-- [![NPM version][npm-image]][npm-url]
4
+ [![build status][travis-image]][travis-url]
5
+ [![Test coverage][codecov-image]][codecov-url]
6
+ [![Known Vulnerabilities][snyk-image]][snyk-url]
7
+ [![npm download][download-image]][download-url]
8
+
9
+ [npm-image]: https://img.shields.io/npm/v/:packageName.svg?style=flat-square
10
+ [npm-url]: https://npmjs.org/package/:packageName
11
+ [travis-image]: https://www.travis-ci.org/JohnApache/:packageName.svg
12
+ [travis-url]: https://travis-ci.org/JohnApache/:packageName
13
+ [codecov-image]: https://codecov.io/gh/JohnApache/:packageName/branch/master/graph/badge.svg
14
+ [codecov-url]: https://codecov.io/gh/JohnApache/:packageName
15
+ [snyk-image]: https://snyk.io/test/github/JohnApache/:packageName/badge.svg?targetFile=package.json
16
+ [snyk-url]: https://snyk.io/test/github/JohnApache/:packageName?targetFile=package.json
17
+ [download-image]: https://img.shields.io/npm/dm/:packageName.svg?style=flat-square
18
+ [download-url]: https://npmjs.org/package/:packageName -->
19
+
20
+ - [English](README.en_US.md)
21
+ - [简体中文](README.md)
22
+
23
+ > 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.
24
+
25
+ - [Install](#install)
26
+ - [Usage](#usage)
27
+ - [Configuration](#configuration)
28
+ - [TIPS](#tips)
29
+ - [Example](#example)
30
+ - [Questions](#questions)
31
+ - [License](#license)
32
+
33
+ ## Install
34
+ + Global Installation
35
+ ```bash
36
+ $ npm install @bratel/dgit -g
37
+ ```
38
+ + Local Installation
39
+ ```bash
40
+ $ npm install @bratel/dgit --save
41
+ $ yarn add @bratel/dgit
42
+ ```
43
+
44
+ ## Usage
45
+ + Global installation, using as command line
46
+ ```bash
47
+ $ dgit d https://github.com/JohnApache/hasaki-cli/tree/master/src -d ./abc
48
+ ```
49
+
50
+ + Local installation as module
51
+ ```js
52
+ import dgit from '@bratel/dgit';
53
+
54
+ (async () => {
55
+ await dgit(
56
+ {
57
+ owner: 'JohnApache',
58
+ repoName: 'hasaki-cli',
59
+ ref: 'master',
60
+ relativePath: 'src',
61
+ },
62
+ './aaa',
63
+ );
64
+ console.log('download succeed');
65
+ })()
66
+ ```
67
+
68
+
69
+ ## Configuration
70
+ + Global installation, used as command line, configurable parameters
71
+ - Commands:
72
+ * download|d [options] [githubLink] Download the specified files of the specified repo or all files under the specified directory
73
+ - Options:
74
+ * --owner <ownerName> Git repository author name
75
+ * --repo-name <repoName> Git repo name
76
+ * --ref <refName> Git repo branch,commit hash or tagname
77
+ * --relative-path <relativePath> Specifies the relative location of the directory or file that git needs to download. default: '.'
78
+ * -d, --dest <destPath> Specify the file output directory, either absolute path or relative path of the current terminal execution path
79
+ * -l, --parallel-limit, <number> Specify the number of concurrent downloads,default: 10.
80
+ * -u, --username, <username> Specify git account name, configuration parameters required when downloading private repo.
81
+ * -p --password, <password> Specify the git account password, which is used with username, and the configuration parameters required when downloading the private repo.
82
+ * -t --token, <token> Git token is another configurable parameter of login mode, which is used to download private repo.
83
+ * -e --exclude, <relativePath,...,relativePath> Specifies the collection of files or directory paths that need to be excluded for the current download directory.
84
+ * -i --include, <relativePath,...,relativePath> Specifies the collection of files or directories that need to be included again in the currently excluded file path collection.
85
+ * -h, --help Output usage information
86
+
87
+ + Local installation, configurable parameters when used as a module
88
+ ```js
89
+ import dgit from '@bratel/dgit';
90
+ import path from 'path';
91
+ const repoOption = {
92
+ owner: 'JohnApache'; // Git repository author name
93
+ repoName: 'hasaki-cli'; // Git repo name
94
+ ref: 'master'; // Git repo branch,commit hash or tagname,
95
+ relativePath: '.'; // Specifies the relative location of the directory or file that git needs to download
96
+ username: ''; // Specify git account name.
97
+ password: ''; // Specify the git account password.
98
+ token: ''; // Git token is another configurable parameter of login mode.
99
+ }
100
+
101
+ const githubLinkOption = {
102
+ githubLink: 'https://github.com/JohnApache/hasaki-cli/blob/master/PLAN.txt',
103
+ // You can also directly specify the download path address of gitHub
104
+ }
105
+
106
+ const destPath = path.resolve(__dirname, './aaa'); // Specify the file output directory
107
+
108
+ const dgitOptions = {
109
+ maxRetryCount: 3, // The maximum number of attempts to download again when the download fails due to network problems
110
+ parallelLimit: 10, // Number of parallel downloads
111
+ log: false, // Open internal log
112
+ logSuffix: '', // Log output prefix
113
+ exclude: [], // excluded paths,
114
+ include: [], // include paths
115
+ }
116
+
117
+ const hooks = {
118
+ onSuccess: () => void,
119
+ onError: (err) => err,
120
+ onProgress: (status, node) => void,
121
+ onResolved: (status) => void,
122
+ }
123
+
124
+
125
+ (async () => {
126
+ await dgit(
127
+ repoOption,
128
+ destPath,
129
+ dgitOptions,
130
+ hooks,
131
+ );
132
+ console.log('repoOption download succeed.');
133
+
134
+ await dgit(
135
+ githubLinkOption,
136
+ destPath,
137
+ dgitOptions,
138
+ hooks,
139
+ );
140
+ console.log('githubLinkOption download succeed.');
141
+ })()
142
+ ```
143
+
144
+ ## TIPS
145
+ When downloading the private repo, you need to provide download permission. At this time, you need to pass in additional parameters in two ways
146
+ + Basic authentication
147
+
148
+ 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;
149
+ ```bash
150
+ $ dgit d https://github.com/JohnApache/hasaki-cli/tree/master/src -d ./abc -u JohnApache
151
+ ```
152
+ + OAuth2 token
153
+
154
+ Token is another way of authority authentication provided by GitHub.
155
+
156
+ Set the token method, which is located in Github Settings -> Developer settings -> Personal access tokens
157
+
158
+ ```bash
159
+ $ dgit d https://github.com/JohnApache/hasaki-cli/tree/master/src -d ./abc -t OAUTH-TOKEN
160
+ ```
161
+
162
+ ## Questions
163
+ Please open an issue [here](https://github.com/JohnApache/dgit/issues).
164
+
165
+ ## License
166
+
167
+ [MIT](LICENSE)
package/README.md ADDED
@@ -0,0 +1,182 @@
1
+ # Dgit
2
+ <!--
3
+ [![NPM version][npm-image]][npm-url]
4
+ [![build status][travis-image]][travis-url]
5
+ [![Test coverage][codecov-image]][codecov-url]
6
+ [![Known Vulnerabilities][snyk-image]][snyk-url]
7
+ [![npm download][download-image]][download-url]
8
+
9
+ [npm-image]: https://img.shields.io/npm/v/:packageName.svg?style=flat-square
10
+ [npm-url]: https://npmjs.org/package/:packageName
11
+ [travis-image]: https://www.travis-ci.org/JohnApache/:packageName.svg
12
+ [travis-url]: https://travis-ci.org/JohnApache/:packageName
13
+ [codecov-image]: https://codecov.io/gh/JohnApache/:packageName/branch/master/graph/badge.svg
14
+ [codecov-url]: https://codecov.io/gh/JohnApache/:packageName
15
+ [snyk-image]: https://snyk.io/test/github/JohnApache/:packageName/badge.svg?targetFile=package.json
16
+ [snyk-url]: https://snyk.io/test/github/JohnApache/:packageName?targetFile=package.json
17
+ [download-image]: https://img.shields.io/npm/dm/:packageName.svg?style=flat-square
18
+ [download-url]: https://npmjs.org/package/:packageName -->
19
+
20
+ - [English](README.en_US.md)
21
+ - [简体中文](README.md)
22
+
23
+ > Dgit 是一个便携下载 github 仓库指定目录或者指定文件的工具,它可以作为命令行全局安装在终端使用,也可以作为node模块加载使用。 该工具不依赖本地git,可以直接下载指定目录指定文件,减少流量消耗,对于希望下载很大项目的场景非常适合,可以直接下载你需要的内容。
24
+
25
+ - [安装](#安装)
26
+ - [使用](#使用)
27
+ - [配置](#配置)
28
+ - [注意](#注意)
29
+ - [示例](#示例)
30
+ - [建议](#建议)
31
+ - [License](#license)
32
+
33
+ ## 安装
34
+ + 全局安装
35
+ ```bash
36
+ $ npm install @bratel/dgit -g
37
+ ```
38
+ + 本地安装
39
+ ```bash
40
+ $ npm install @bratel/dgit --save
41
+ $ yarn add @bratel/dgit
42
+ ```
43
+
44
+ ## 使用
45
+ + 全局安装,作为命令行使用
46
+ ```bash
47
+ $ dgit d https://github.com/JohnApache/hasaki-cli/tree/master/src -d ./abc
48
+ ```
49
+
50
+ + 本地安装,作为模块使用
51
+ ```js
52
+ import dgit from '@bratel/dgit';
53
+
54
+ (async () => {
55
+ await dgit(
56
+ {
57
+ owner: 'JohnApache',
58
+ repoName: 'hasaki-cli',
59
+ ref: 'master',
60
+ relativePath: 'src',
61
+ },
62
+ './aaa',
63
+ );
64
+ console.log('download succeed');
65
+ })()
66
+ ```
67
+
68
+ ## 配置
69
+ + 全局安装,作为命令行使用,可配置参数
70
+ - Commands:
71
+ * download|d [options] [githubLink] 下载指定仓库的指定文件,或指定目录下的所有文件.
72
+ - Options:
73
+ * --owner <ownerName> git 仓库作者名,当不指定 githubLink的时候可以使用.
74
+ * --repo-name <repoName> git 仓库名称,当不指定 githubLink的时候可以使用.
75
+ * --ref <refName> git 仓库指定 branch,commit hash 或 tagname,当不指定 githubLink的时候可以使用.
76
+ * --relative-path <relativePath> 指定git所需要下载的目录或者文件相对位置,默认为当前目录 '.'
77
+ * -d, --dest <destPath> 指定文件输出目录,可以是绝对路径,也可以是当前终端执行路径的相对路径.
78
+ * -l, --parallel-limit, <number> 指定并行下载数量,默认为 10.
79
+ * -u, --username, <username> 指定git用户名, 在下载私有仓库时需要的配置参数.
80
+ * -p --password, <password> 指定git密码, 同username 一起使用,在下载私有仓库时需要的配置参数.
81
+ * -t --token, <token> git token 是另一种登录方式的可配置参数,用于下载私有仓库.
82
+ * -e --exclude, <relativePath,...,relativePath> 指定当前下载目录需要排除的文件或目录路径集合.
83
+ * -i --include, <relativePath,...,relativePath> 指定当前排除的文件路径集合中需要重新包含的文件或目录集合.
84
+ * --log 打印调试信息.
85
+ * --log-prefix <log_prefix> 在打印信息前添加固定字符串.
86
+ * --proxy <url> 使用代理,比如https://gh-proxy.com
87
+ * -h, --help 帮助文档
88
+
89
+ + 局部安装,作为模块使用时,可配置参数
90
+ ```js
91
+ import dgit from '@bratel/dgit';
92
+ import path from 'path';
93
+ const repoOption = {
94
+ owner: 'JohnApache'; // git 仓库作者名
95
+ repoName: 'hasaki-cli'; // git 仓库名称
96
+ ref: 'master'; // git 仓库指定 branch,commit 或 tag,
97
+ relativePath: '.'; // 指定git所需要下载的目录或者文件相对位置
98
+ username: ''; // 指定git用户名, 在下载私有仓库时需要的配置参数.
99
+ password: ''; // 指定git密码, 同username 一起使用,在下载私有仓库时需要的配置参数.
100
+ token: ''; // git token 是另一种登录方式的可配置参数,用于下载私有仓库.
101
+ }
102
+
103
+ const githubLinkOption = {
104
+ githubLink: 'https://github.com/JohnApache/hasaki-cli/blob/master/PLAN.txt', // 也可以直接指定github 需要下载路径的地址
105
+ }
106
+
107
+ const destPath = path.resolve(__dirname, './aaa'); // 目标下载路径
108
+
109
+ const dgitOptions = {
110
+ maxRetryCount: 3, // 网络问题下载失败时尝试最大重新下载次数
111
+ parallelLimit: 10, // 并行下载个数
112
+ log: false, // 是否开启内部日志
113
+ logSuffix: '', // 日志前缀
114
+ exclude: [], // 需要排除的文件路径,
115
+ include: [], // 需要包含的文件路径
116
+ }
117
+
118
+ const hooks = {
119
+ onSuccess: () => void,
120
+ onError: (err) => err,
121
+ onProgress: (status, node) => void,
122
+ onResolved: (status) => void,
123
+ }
124
+
125
+
126
+ (async () => {
127
+ await dgit(
128
+ repoOption,
129
+ destPath,
130
+ dgitOptions,
131
+ hooks,
132
+ );
133
+ console.log('repoOption download succeed.');
134
+
135
+ await dgit(
136
+ githubLinkOption,
137
+ destPath,
138
+ dgitOptions,
139
+ hooks,
140
+ );
141
+ console.log('githubLinkOption download succeed.');
142
+ })()
143
+ ```
144
+ ## 注意
145
+ 1. 在下载私有仓库的时候需要提供下载权限,此时需要传入额外的参数,方式有两种
146
+ + Basic authentication
147
+
148
+ 通过传入 用户名 和 密码,来提供下载权限, 当传入用户名,可以不显式提供密码,在没有提供密码时,会单独出现密码提示
149
+
150
+ ```bash
151
+ $ dgit d https://github.com/JohnApache/hasaki-cli/tree/master/src -d ./abc -u JohnApache
152
+ ```
153
+ + OAuth2 token
154
+
155
+ Token 是另一种 github 提供的权限认证的方式。
156
+
157
+ 设置token方法 ,就位于Github Settings -> Developer settings -> Personal access tokens
158
+
159
+ ```bash
160
+ $ dgit d https://github.com/JohnApache/hasaki-cli/tree/master/src -d ./abc -t OAUTH-TOKEN
161
+ ```
162
+
163
+ 2. 下载资源失败 `raw.githubusercontent.com` 连接失败
164
+ 由于国内访问 `raw.githubusercontent.com` 地址,除了墙以外,大多数还有一种情况就是域名 `dns污染` ,需要查询正确的 ip 地址
165
+ - **【查询方案1】**:打开 `https://www.ipaddress.com/` 输入访问不了的域名,查询之后可以获得正确的 IP 地址,
166
+
167
+ > Tips: 可能该 ip 因为墙的问题还是访问不了,可以使用下面的方案
168
+ - **【查询方案2】**:打开 `https://site.ip138.com/raw.githubusercontent.com/` ,可以查询到对应国内中国香港的 IP 地址
169
+
170
+ 在本机的 `host` 文件中添加映射,建议使用 [switchhosts](https://github.com/oldj/SwitchHosts/releases) 方便 `host` 管理,在 `host`文件中追加记录,如下选取其中一个即可,国内建议用第二个
171
+
172
+ ```ini
173
+ 199.232.68.133 raw.githubusercontent.com # 美国
174
+ 151.101.76.133 raw.githubusercontent.com # 中国香港
175
+ ```
176
+
177
+ ## 建议
178
+ 欢迎创建issue 或者 pr [here](https://github.com/JohnApache/dgit/issues).
179
+
180
+ ## License
181
+
182
+ [MIT](LICENSE)
package/bin/cmd.js ADDED
@@ -0,0 +1,2 @@
1
+ #! /usr/bin/env node
2
+ require('../lib/cmd/main');
@@ -0,0 +1,4 @@
1
+ import { Command } from 'commander';
2
+ import { CommandInfo } from './type';
3
+ declare const DownloadAction: (githubLink: string | undefined, cmd: Command & CommandInfo) => Promise<any>;
4
+ export default DownloadAction;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const ora_1 = tslib_1.__importDefault(require("ora"));
5
+ const progress_1 = tslib_1.__importDefault(require("progress"));
6
+ const dgit_1 = tslib_1.__importDefault(require("../dgit"));
7
+ const utils_1 = require("./utils");
8
+ const prompt_1 = require("./prompt");
9
+ const MAX_TEXT_ELLIPSIS = 30;
10
+ const DownloadAction = (githubLink, cmd) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
11
+ let { ref = '', dest = '', owner = '', repoName = '', relativePath = '', password, } = cmd;
12
+ const { exclude = '', include = '', log = false, logPrefix = '[dgit-logger]', } = cmd;
13
+ const { parallelLimit = '', username, token, } = cmd;
14
+ const { proxy = '' } = cmd;
15
+ if (githubLink && utils_1.isHttpsLink(githubLink)) {
16
+ const parseResult = utils_1.ParseGithubHttpsLink(githubLink);
17
+ ref = parseResult.ref;
18
+ owner = parseResult.owner;
19
+ repoName = parseResult.repoName;
20
+ relativePath = parseResult.relativePath;
21
+ }
22
+ if (username && !password) {
23
+ const pwdAnswer = yield prompt_1.PasswordPrompt();
24
+ password = pwdAnswer.password;
25
+ }
26
+ const answer = yield prompt_1.DownloadPrompt({
27
+ ref,
28
+ dest,
29
+ owner,
30
+ repoName,
31
+ relativePath,
32
+ });
33
+ ref = answer.ref;
34
+ dest = answer.dest;
35
+ owner = answer.owner;
36
+ repoName = answer.repoName;
37
+ relativePath = answer.relativePath;
38
+ const excludeList = exclude.split(',').filter(Boolean);
39
+ const includeList = include.split(',').filter(Boolean);
40
+ const spinner = ora_1.default(' loading remote repo tree...');
41
+ let bar;
42
+ try {
43
+ yield dgit_1.default({
44
+ ref,
45
+ owner,
46
+ repoName,
47
+ relativePath,
48
+ username,
49
+ password,
50
+ token,
51
+ proxy,
52
+ }, dest, {
53
+ log,
54
+ logPrefix,
55
+ parallelLimit: Number(parallelLimit.trim()),
56
+ exclude: excludeList,
57
+ include: includeList,
58
+ }, {
59
+ beforeLoadTree() {
60
+ spinner.start();
61
+ },
62
+ afterLoadTree() {
63
+ spinner.succeed(' load remote repo tree succeed! ');
64
+ },
65
+ onResolved(status) {
66
+ if (log)
67
+ return;
68
+ const green = '\u001b[42m \u001b[0m';
69
+ const red = '\u001b[41m \u001b[0m';
70
+ const index = 0;
71
+ bar = new progress_1.default(' DOWNLOAD |:bar| :current/:total :percent elapsed: :elapseds eta: :eta :file, done.', {
72
+ total: status.totalCount,
73
+ width: 50,
74
+ complete: green,
75
+ incomplete: red,
76
+ });
77
+ bar.update(index);
78
+ },
79
+ onProgress(_, node) {
80
+ if (log)
81
+ return;
82
+ bar.tick({ file: utils_1.TextEllipsis(node.path, MAX_TEXT_ELLIPSIS) });
83
+ },
84
+ });
85
+ spinner.succeed(' download all files succeed!');
86
+ }
87
+ catch (error) {
88
+ console.error(error);
89
+ spinner.fail(' download files failed!');
90
+ }
91
+ });
92
+ exports.default = DownloadAction;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const commander_1 = tslib_1.__importDefault(require("commander"));
5
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
+ const utils_1 = require("./utils");
7
+ const action_1 = tslib_1.__importDefault(require("./action"));
8
+ const EXIT_CODE = 1;
9
+ const Exit = () => {
10
+ process.exit(EXIT_CODE);
11
+ };
12
+ const UnknownCommand = (cmdName) => {
13
+ console.log(`${chalk_1.default.red('Unknown command')} ${chalk_1.default.yellow(cmdName)}.`);
14
+ };
15
+ const packageInfo = utils_1.GetPackageInfo();
16
+ commander_1.default.version(packageInfo.version);
17
+ commander_1.default
18
+ .command('download [githubLink]')
19
+ .option('--owner <ownerName>', 'git repo author.')
20
+ .option('--repo-name <repoName>', 'git repo name.')
21
+ .option('--ref <refName>', 'git repo branch, commit hash or tagname.')
22
+ .option('--relative-path <relativePath>', 'specified repo relative path to download.')
23
+ .option('-d, --dest <destPath>', 'specified dest path.')
24
+ .option('-l, --parallel-limit, <number>', 'specified download max parallel limit.')
25
+ .option('-u, --username, <username>', 'specified git account username.')
26
+ .option('-p --password, <password>', 'specified git account password.')
27
+ .option('-t --token, <token>', 'specified git account personal access token.')
28
+ .option('-e --exclude, <relativePath,...,relativePath>', 'indicates which file paths need to be excluded in the current directory.')
29
+ .option('-i --include, <relativePath,...,relativePath>', 'indicates which files need to be included in the exclusion file list.')
30
+ .option('--log', 'output dgit internal log details.')
31
+ .option('--log-prefix, <log>', 'dgit internal log prefix.')
32
+ .option('--proxy, <proxyHttp>', 'dgit proxy download url.')
33
+ .alias('d')
34
+ .description('download the file with the specified path of the remote repo.')
35
+ .action(action_1.default);
36
+ commander_1.default.on('command:*', (cmdObj = []) => {
37
+ const [cmd] = cmdObj;
38
+ if (cmd) {
39
+ commander_1.default.outputHelp();
40
+ UnknownCommand(cmd);
41
+ Exit();
42
+ }
43
+ });
44
+ if (process.argv.slice(2).length <= 0) {
45
+ commander_1.default.help();
46
+ }
47
+ commander_1.default.parse(process.argv);
@@ -0,0 +1,5 @@
1
+ import { Question } from 'inquirer';
2
+ import { DownloadPromptInfo, PasswordPromptInfo } from './type';
3
+ export declare const CreatePrompt: (questions: Array<Question>) => Promise<any>;
4
+ export declare const DownloadPrompt: (currentInfo: DownloadPromptInfo) => Promise<DownloadPromptInfo>;
5
+ export declare const PasswordPrompt: () => Promise<PasswordPromptInfo>;