@bratel/dgit 0.0.13 → 0.0.14
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/.github/workflows/nodejs.yml +17 -17
- package/README.en_US.md +20 -22
- package/README.md +25 -26
- package/eslint.config.mjs +15 -0
- package/lib/cmd/action.d.ts +3 -3
- package/lib/cmd/action.js +80 -78
- package/lib/cmd/main.js +17 -15
- package/lib/cmd/prompt.d.ts +4 -4
- package/lib/cmd/prompt.js +82 -76
- package/lib/cmd/utils.d.ts +5 -5
- package/lib/cmd/utils.js +25 -19
- package/lib/dgit.d.ts +2 -2
- package/lib/dgit.js +162 -157
- package/lib/log.d.ts +2 -2
- package/lib/log.js +11 -9
- package/lib/repo.d.ts +1 -1
- package/lib/repo.js +6 -4
- package/lib/request.d.ts +6 -6
- package/lib/request.js +29 -26
- package/lib/type.d.ts +1 -1
- package/package.json +51 -55
- package/renovate.json +19 -0
- package/src/cmd/action.ts +115 -108
- package/src/cmd/main.ts +51 -49
- package/src/cmd/prompt.ts +93 -92
- package/src/cmd/type.ts +27 -27
- package/src/cmd/utils.ts +78 -73
- package/src/dgit.ts +238 -228
- package/src/log.ts +9 -7
- package/src/repo.ts +6 -4
- package/src/request.ts +91 -92
- package/src/type.ts +36 -36
- package/test/dgit.test.ts +122 -119
- package/tsconfig.json +51 -51
- package/tsconfig.tsbuildinfo +1 -0
- package/.eslintignore +0 -6
- package/.eslintrc.js +0 -30
- package/x-npmrc +0 -2
|
@@ -4,13 +4,13 @@ on: [push]
|
|
|
4
4
|
|
|
5
5
|
jobs:
|
|
6
6
|
build:
|
|
7
|
-
if: startsWith(github.ref_name, 'v')
|
|
7
|
+
# if: startsWith(github.ref_name, 'v')
|
|
8
8
|
permissions:
|
|
9
9
|
pull-requests: write # for writing comments
|
|
10
10
|
issues: write # for writing comments
|
|
11
11
|
contents: write # for creating a release
|
|
12
|
-
id-token: write
|
|
13
|
-
|
|
12
|
+
id-token: write # Required for OIDC
|
|
13
|
+
|
|
14
14
|
runs-on: ubuntu-latest
|
|
15
15
|
|
|
16
16
|
strategy:
|
|
@@ -37,20 +37,20 @@ jobs:
|
|
|
37
37
|
npm run test:mocha
|
|
38
38
|
env:
|
|
39
39
|
CI: true
|
|
40
|
-
- name: check auth
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
- name: Upload npmrc
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
54
|
- name: Publish
|
|
55
55
|
if: startsWith(github.ref_name, 'v')
|
|
56
56
|
run: |
|
package/README.en_US.md
CHANGED
|
@@ -52,20 +52,19 @@ $ dgit d https://github.com/JohnApache/hasaki-cli/tree/master/src -d ./abc
|
|
|
52
52
|
import dgit from '@bratel/dgit';
|
|
53
53
|
|
|
54
54
|
(async () => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
})()
|
|
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
66
|
```
|
|
67
67
|
|
|
68
|
-
|
|
69
68
|
## Configuration
|
|
70
69
|
+ Global installation, used as command line, configurable parameters
|
|
71
70
|
- Commands:
|
|
@@ -84,18 +83,18 @@ import dgit from '@bratel/dgit';
|
|
|
84
83
|
* -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
84
|
* -h, --help Output usage information
|
|
86
85
|
|
|
87
|
-
+ Local installation, configurable parameters when used as a module
|
|
86
|
+
+ Local installation, configurable parameters when used as a module
|
|
88
87
|
```js
|
|
89
88
|
import dgit from '@bratel/dgit';
|
|
90
89
|
import path from 'path';
|
|
91
90
|
const repoOption = {
|
|
92
|
-
owner: 'JohnApache'
|
|
93
|
-
repoName: 'hasaki-cli'
|
|
91
|
+
owner: 'JohnApache', // Git repository author name
|
|
92
|
+
repoName: 'hasaki-cli', // Git repo name
|
|
94
93
|
ref: 'master'; // Git repo branch,commit hash or tagname,
|
|
95
|
-
relativePath: '.'
|
|
96
|
-
username: ''
|
|
97
|
-
password: ''
|
|
98
|
-
token: ''
|
|
94
|
+
relativePath: '.', // Specifies the relative location of the directory or file that git needs to download
|
|
95
|
+
username: '', // Specify git account name.
|
|
96
|
+
password: '', // Specify the git account password.
|
|
97
|
+
token: '', // Git token is another configurable parameter of login mode.
|
|
99
98
|
}
|
|
100
99
|
|
|
101
100
|
const githubLinkOption = {
|
|
@@ -121,7 +120,6 @@ import dgit from '@bratel/dgit';
|
|
|
121
120
|
onResolved: (status) => void,
|
|
122
121
|
}
|
|
123
122
|
|
|
124
|
-
|
|
125
123
|
(async () => {
|
|
126
124
|
await dgit(
|
|
127
125
|
repoOption,
|
|
@@ -139,11 +137,11 @@ import dgit from '@bratel/dgit';
|
|
|
139
137
|
);
|
|
140
138
|
console.log('githubLinkOption download succeed.');
|
|
141
139
|
})()
|
|
142
|
-
```
|
|
140
|
+
```
|
|
143
141
|
|
|
144
142
|
## TIPS
|
|
145
143
|
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
|
|
144
|
+
+ Basic authentication
|
|
147
145
|
|
|
148
146
|
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
147
|
```bash
|
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
# Dgit
|
|
2
|
-
<!--
|
|
1
|
+
# Dgit
|
|
2
|
+
<!--
|
|
3
3
|
[![NPM version][npm-image]][npm-url]
|
|
4
4
|
[![build status][travis-image]][travis-url]
|
|
5
5
|
[![Test coverage][codecov-image]][codecov-url]
|
|
@@ -52,17 +52,17 @@ $ dgit d https://github.com/JohnApache/hasaki-cli/tree/master/src -d ./abc
|
|
|
52
52
|
import dgit from '@bratel/dgit';
|
|
53
53
|
|
|
54
54
|
(async () => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
})()
|
|
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
66
|
```
|
|
67
67
|
|
|
68
68
|
## 配置
|
|
@@ -91,13 +91,13 @@ import dgit from '@bratel/dgit';
|
|
|
91
91
|
import dgit from '@bratel/dgit';
|
|
92
92
|
import path from 'path';
|
|
93
93
|
const repoOption = {
|
|
94
|
-
owner: 'JohnApache'
|
|
95
|
-
repoName: 'hasaki-cli'
|
|
96
|
-
ref: 'master'
|
|
97
|
-
relativePath: '.'
|
|
98
|
-
username: ''
|
|
99
|
-
password: ''
|
|
100
|
-
token: ''
|
|
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
101
|
}
|
|
102
102
|
|
|
103
103
|
const githubLinkOption = {
|
|
@@ -122,7 +122,6 @@ import dgit from '@bratel/dgit';
|
|
|
122
122
|
onResolved: (status) => void,
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
|
|
126
125
|
(async () => {
|
|
127
126
|
await dgit(
|
|
128
127
|
repoOption,
|
|
@@ -140,10 +139,10 @@ import dgit from '@bratel/dgit';
|
|
|
140
139
|
);
|
|
141
140
|
console.log('githubLinkOption download succeed.');
|
|
142
141
|
})()
|
|
143
|
-
```
|
|
142
|
+
```
|
|
144
143
|
## 注意
|
|
145
144
|
1. 在下载私有仓库的时候需要提供下载权限,此时需要传入额外的参数,方式有两种
|
|
146
|
-
+ Basic authentication
|
|
145
|
+
+ Basic authentication
|
|
147
146
|
|
|
148
147
|
通过传入 用户名 和 密码,来提供下载权限, 当传入用户名,可以不显式提供密码,在没有提供密码时,会单独出现密码提示
|
|
149
148
|
|
|
@@ -160,9 +159,9 @@ import dgit from '@bratel/dgit';
|
|
|
160
159
|
$ dgit d https://github.com/JohnApache/hasaki-cli/tree/master/src -d ./abc -t OAUTH-TOKEN
|
|
161
160
|
```
|
|
162
161
|
|
|
163
|
-
2. 下载资源失败 `raw.githubusercontent.com` 连接失败
|
|
164
|
-
由于国内访问 `raw.githubusercontent.com` 地址,除了墙以外,大多数还有一种情况就是域名 `dns污染` ,需要查询正确的 ip 地址
|
|
165
|
-
- **【查询方案1】**:打开 `https://www.ipaddress.com/` 输入访问不了的域名,查询之后可以获得正确的 IP 地址,
|
|
162
|
+
2. 下载资源失败 `raw.githubusercontent.com` 连接失败
|
|
163
|
+
由于国内访问 `raw.githubusercontent.com` 地址,除了墙以外,大多数还有一种情况就是域名 `dns污染` ,需要查询正确的 ip 地址
|
|
164
|
+
- **【查询方案1】**:打开 `https://www.ipaddress.com/` 输入访问不了的域名,查询之后可以获得正确的 IP 地址,
|
|
166
165
|
|
|
167
166
|
> Tips: 可能该 ip 因为墙的问题还是访问不了,可以使用下面的方案
|
|
168
167
|
- **【查询方案2】**:打开 `https://site.ip138.com/raw.githubusercontent.com/` ,可以查询到对应国内中国香港的 IP 地址
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// eslint.config.mjs
|
|
2
|
+
import antfu from '@antfu/eslint-config';
|
|
3
|
+
|
|
4
|
+
export default antfu({
|
|
5
|
+
rules: {
|
|
6
|
+
'no-console': ['error', { allow: ['warn', 'log', 'error'] }],
|
|
7
|
+
},
|
|
8
|
+
ignores: ['*.log', 'lib/**', '*.md'],
|
|
9
|
+
gitignore: true,
|
|
10
|
+
stylistic: {
|
|
11
|
+
indent: 2,
|
|
12
|
+
quotes: 'single',
|
|
13
|
+
semi: true,
|
|
14
|
+
},
|
|
15
|
+
});
|
package/lib/cmd/action.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { CommandInfo } from './type';
|
|
3
|
-
declare
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
import type { CommandInfo } from './type';
|
|
3
|
+
declare function DownloadAction(githubLink: string | undefined, cmd: Command & CommandInfo): Promise<any>;
|
|
4
4
|
export default DownloadAction;
|
package/lib/cmd/action.js
CHANGED
|
@@ -4,89 +4,91 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const ora_1 = tslib_1.__importDefault(require("ora"));
|
|
5
5
|
const progress_1 = tslib_1.__importDefault(require("progress"));
|
|
6
6
|
const dgit_1 = tslib_1.__importDefault(require("../dgit"));
|
|
7
|
-
const utils_1 = require("./utils");
|
|
8
7
|
const prompt_1 = require("./prompt");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
9
|
const MAX_TEXT_ELLIPSIS = 30;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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({
|
|
10
|
+
function DownloadAction(githubLink, cmd) {
|
|
11
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
let { ref = '', dest = '', owner = '', repoName = '', relativePath = '', password, } = cmd;
|
|
13
|
+
const { exclude = '', include = '', log = false, logPrefix = '[dgit-logger]', } = cmd;
|
|
14
|
+
const { parallelLimit = '', username, token, } = cmd;
|
|
15
|
+
const { proxy = '', } = cmd;
|
|
16
|
+
if (githubLink && (0, utils_1.isHttpsLink)(githubLink)) {
|
|
17
|
+
const parseResult = (0, utils_1.ParseGithubHttpsLink)(githubLink);
|
|
18
|
+
ref = parseResult.ref;
|
|
19
|
+
owner = parseResult.owner;
|
|
20
|
+
repoName = parseResult.repoName;
|
|
21
|
+
relativePath = parseResult.relativePath;
|
|
22
|
+
}
|
|
23
|
+
if (username && !password) {
|
|
24
|
+
const pwdAnswer = yield (0, prompt_1.PasswordPrompt)();
|
|
25
|
+
password = pwdAnswer.password;
|
|
26
|
+
}
|
|
27
|
+
const answer = yield (0, prompt_1.DownloadPrompt)({
|
|
44
28
|
ref,
|
|
29
|
+
dest,
|
|
45
30
|
owner,
|
|
46
31
|
repoName,
|
|
47
32
|
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
33
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
34
|
+
ref = answer.ref;
|
|
35
|
+
dest = answer.dest;
|
|
36
|
+
owner = answer.owner;
|
|
37
|
+
repoName = answer.repoName;
|
|
38
|
+
relativePath = answer.relativePath;
|
|
39
|
+
const excludeList = exclude.split(',').filter(Boolean);
|
|
40
|
+
const includeList = include.split(',').filter(Boolean);
|
|
41
|
+
const spinner = (0, ora_1.default)(' loading remote repo tree...');
|
|
42
|
+
let bar;
|
|
43
|
+
try {
|
|
44
|
+
yield (0, dgit_1.default)({
|
|
45
|
+
ref,
|
|
46
|
+
owner,
|
|
47
|
+
repoName,
|
|
48
|
+
relativePath,
|
|
49
|
+
username,
|
|
50
|
+
password,
|
|
51
|
+
token,
|
|
52
|
+
proxy,
|
|
53
|
+
}, dest, {
|
|
54
|
+
log,
|
|
55
|
+
logPrefix,
|
|
56
|
+
parallelLimit: Number(parallelLimit.trim()),
|
|
57
|
+
exclude: excludeList,
|
|
58
|
+
include: includeList,
|
|
59
|
+
}, {
|
|
60
|
+
beforeLoadTree() {
|
|
61
|
+
spinner.start();
|
|
62
|
+
},
|
|
63
|
+
afterLoadTree() {
|
|
64
|
+
spinner.succeed(' load remote repo tree succeed! ');
|
|
65
|
+
},
|
|
66
|
+
onResolved(status) {
|
|
67
|
+
if (log)
|
|
68
|
+
return;
|
|
69
|
+
const green = '\u001B[42m \u001B[0m';
|
|
70
|
+
const red = '\u001B[41m \u001B[0m';
|
|
71
|
+
const index = 0;
|
|
72
|
+
bar = new progress_1.default(' DOWNLOAD |:bar| :current/:total :percent elapsed: :elapseds eta: :eta :file, done.', {
|
|
73
|
+
total: status.totalCount,
|
|
74
|
+
width: 50,
|
|
75
|
+
complete: green,
|
|
76
|
+
incomplete: red,
|
|
77
|
+
});
|
|
78
|
+
bar.update(index);
|
|
79
|
+
},
|
|
80
|
+
onProgress(_, node) {
|
|
81
|
+
if (log)
|
|
82
|
+
return;
|
|
83
|
+
bar.tick({ file: (0, utils_1.TextEllipsis)(node.path, MAX_TEXT_ELLIPSIS) });
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
spinner.succeed(' download all files succeed!');
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.error(error);
|
|
90
|
+
spinner.fail(' download files failed!');
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
92
94
|
exports.default = DownloadAction;
|
package/lib/cmd/main.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const
|
|
4
|
+
const node_process_1 = tslib_1.__importDefault(require("node:process"));
|
|
5
5
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
|
-
const
|
|
6
|
+
const commander_1 = require("commander");
|
|
7
7
|
const action_1 = tslib_1.__importDefault(require("./action"));
|
|
8
|
+
const utils_1 = require("./utils");
|
|
8
9
|
const EXIT_CODE = 1;
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const program = new commander_1.Command();
|
|
11
|
+
function Exit() {
|
|
12
|
+
node_process_1.default.exit(EXIT_CODE);
|
|
13
|
+
}
|
|
14
|
+
function UnknownCommand(cmdName) {
|
|
13
15
|
console.log(`${chalk_1.default.red('Unknown command')} ${chalk_1.default.yellow(cmdName)}.`);
|
|
14
|
-
}
|
|
15
|
-
const packageInfo = utils_1.GetPackageInfo();
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
}
|
|
17
|
+
const packageInfo = (0, utils_1.GetPackageInfo)();
|
|
18
|
+
program.version(packageInfo.version);
|
|
19
|
+
program
|
|
18
20
|
.command('download [githubLink]')
|
|
19
21
|
.option('--owner <ownerName>', 'git repo author.')
|
|
20
22
|
.option('--repo-name <repoName>', 'git repo name.')
|
|
@@ -33,15 +35,15 @@ commander_1.default
|
|
|
33
35
|
.alias('d')
|
|
34
36
|
.description('download the file with the specified path of the remote repo.')
|
|
35
37
|
.action(action_1.default);
|
|
36
|
-
|
|
38
|
+
program.on('command:*', (cmdObj = []) => {
|
|
37
39
|
const [cmd] = cmdObj;
|
|
38
40
|
if (cmd) {
|
|
39
|
-
|
|
41
|
+
program.outputHelp();
|
|
40
42
|
UnknownCommand(cmd);
|
|
41
43
|
Exit();
|
|
42
44
|
}
|
|
43
45
|
});
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
+
if (node_process_1.default.argv.slice(2).length <= 0) {
|
|
47
|
+
program.help();
|
|
46
48
|
}
|
|
47
|
-
|
|
49
|
+
program.parse(node_process_1.default.argv);
|
package/lib/cmd/prompt.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Question } from 'inquirer';
|
|
2
|
-
import { DownloadPromptInfo, PasswordPromptInfo } from './type';
|
|
1
|
+
import type { Question } from 'inquirer';
|
|
2
|
+
import type { DownloadPromptInfo, PasswordPromptInfo } from './type';
|
|
3
3
|
export declare const CreatePrompt: (questions: Array<Question>) => Promise<any>;
|
|
4
|
-
export declare
|
|
5
|
-
export declare
|
|
4
|
+
export declare function DownloadPrompt(currentInfo: DownloadPromptInfo): Promise<DownloadPromptInfo>;
|
|
5
|
+
export declare function PasswordPrompt(): Promise<PasswordPromptInfo>;
|
package/lib/cmd/prompt.js
CHANGED
|
@@ -1,86 +1,92 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CreatePrompt = void 0;
|
|
4
|
+
exports.DownloadPrompt = DownloadPrompt;
|
|
5
|
+
exports.PasswordPrompt = PasswordPrompt;
|
|
4
6
|
const tslib_1 = require("tslib");
|
|
5
7
|
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
6
|
-
|
|
7
|
-
exports.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
currentInfo.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
const CreatePrompt = (questions) => inquirer_1.default.prompt(questions);
|
|
9
|
+
exports.CreatePrompt = CreatePrompt;
|
|
10
|
+
function DownloadPrompt(currentInfo) {
|
|
11
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
if (currentInfo.owner
|
|
13
|
+
&& currentInfo.repoName
|
|
14
|
+
&& currentInfo.ref
|
|
15
|
+
&& currentInfo.relativePath
|
|
16
|
+
&& currentInfo.dest) {
|
|
17
|
+
return currentInfo;
|
|
18
|
+
}
|
|
19
|
+
const questions = [
|
|
20
|
+
{
|
|
21
|
+
type: 'input',
|
|
22
|
+
name: 'owner',
|
|
23
|
+
when() {
|
|
24
|
+
return !currentInfo.owner;
|
|
25
|
+
},
|
|
26
|
+
validate(input) {
|
|
27
|
+
return input && input.length > 0;
|
|
28
|
+
},
|
|
29
|
+
message: 'input github ownername.',
|
|
20
30
|
},
|
|
21
|
-
|
|
22
|
-
|
|
31
|
+
{
|
|
32
|
+
type: 'input',
|
|
33
|
+
name: 'repoName',
|
|
34
|
+
when() {
|
|
35
|
+
return !currentInfo.repoName;
|
|
36
|
+
},
|
|
37
|
+
validate(input) {
|
|
38
|
+
return input && input.length > 0;
|
|
39
|
+
},
|
|
40
|
+
message: 'input github repoName.',
|
|
23
41
|
},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
message: 'input github repoName.',
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
type: 'input',
|
|
39
|
-
name: 'ref',
|
|
40
|
-
when() {
|
|
41
|
-
return !currentInfo.ref;
|
|
42
|
-
},
|
|
43
|
-
validate(input) {
|
|
44
|
-
return input && input.length > 0;
|
|
42
|
+
{
|
|
43
|
+
type: 'input',
|
|
44
|
+
name: 'ref',
|
|
45
|
+
when() {
|
|
46
|
+
return !currentInfo.ref;
|
|
47
|
+
},
|
|
48
|
+
validate(input) {
|
|
49
|
+
return input && input.length > 0;
|
|
50
|
+
},
|
|
51
|
+
default: 'master',
|
|
52
|
+
message: 'input github branch or commit hash or tagname.',
|
|
45
53
|
},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
{
|
|
55
|
+
type: 'input',
|
|
56
|
+
name: 'relativePath',
|
|
57
|
+
when() {
|
|
58
|
+
return !currentInfo.relativePath;
|
|
59
|
+
},
|
|
60
|
+
validate(input) {
|
|
61
|
+
return input && input.length > 0;
|
|
62
|
+
},
|
|
63
|
+
default: '.',
|
|
64
|
+
message: 'input github relative path.',
|
|
54
65
|
},
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
{
|
|
67
|
+
type: 'input',
|
|
68
|
+
name: 'dest',
|
|
69
|
+
when() {
|
|
70
|
+
return !currentInfo.dest;
|
|
71
|
+
},
|
|
72
|
+
validate(input) {
|
|
73
|
+
return input && input.length > 0;
|
|
74
|
+
},
|
|
75
|
+
default: '.',
|
|
76
|
+
message: 'input template output dest path.',
|
|
57
77
|
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
'default': '.',
|
|
71
|
-
message: 'input template output dest path.',
|
|
72
|
-
},
|
|
73
|
-
];
|
|
74
|
-
const answer = yield exports.CreatePrompt(questions);
|
|
75
|
-
return {
|
|
76
|
-
owner: answer.owner || currentInfo.owner,
|
|
77
|
-
dest: answer.dest || currentInfo.dest,
|
|
78
|
-
repoName: answer.repoName || currentInfo.repoName,
|
|
79
|
-
relativePath: answer.relativePath || currentInfo.relativePath,
|
|
80
|
-
ref: answer.ref || currentInfo.ref,
|
|
81
|
-
};
|
|
82
|
-
});
|
|
83
|
-
exports.PasswordPrompt = () => {
|
|
78
|
+
];
|
|
79
|
+
const answer = yield (0, exports.CreatePrompt)(questions);
|
|
80
|
+
return {
|
|
81
|
+
owner: answer.owner || currentInfo.owner,
|
|
82
|
+
dest: answer.dest || currentInfo.dest,
|
|
83
|
+
repoName: answer.repoName || currentInfo.repoName,
|
|
84
|
+
relativePath: answer.relativePath || currentInfo.relativePath,
|
|
85
|
+
ref: answer.ref || currentInfo.ref,
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function PasswordPrompt() {
|
|
84
90
|
const question = {
|
|
85
91
|
type: 'password',
|
|
86
92
|
name: 'password',
|
|
@@ -89,5 +95,5 @@ exports.PasswordPrompt = () => {
|
|
|
89
95
|
},
|
|
90
96
|
message: 'input github account password.',
|
|
91
97
|
};
|
|
92
|
-
return exports.CreatePrompt([question]);
|
|
93
|
-
}
|
|
98
|
+
return (0, exports.CreatePrompt)([question]);
|
|
99
|
+
}
|