@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
package/package.json
CHANGED
|
@@ -1,77 +1,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bratel/dgit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "@dking/hasaki-cli init application",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"keywords": [
|
|
11
|
-
"dgit",
|
|
12
|
-
"github download tool"
|
|
13
|
-
],
|
|
8
|
+
"author": "JohnApache",
|
|
9
|
+
"license": "MIT",
|
|
14
10
|
"repository": {
|
|
15
11
|
"type": "git",
|
|
16
12
|
"url": "https://github.com/lsq/dgit"
|
|
17
13
|
},
|
|
18
|
-
|
|
19
|
-
"
|
|
14
|
+
"keywords": [
|
|
15
|
+
"dgit",
|
|
16
|
+
"github download tool"
|
|
17
|
+
],
|
|
18
|
+
"main": "./lib/dgit.js",
|
|
19
|
+
"types": "./lib/dgit.d.ts",
|
|
20
|
+
"bin": {
|
|
21
|
+
"dgit": "./bin/cmd.js"
|
|
20
22
|
},
|
|
21
|
-
"author": "JohnApache",
|
|
22
|
-
"license": "MIT",
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build:ts": "tsc --build",
|
|
25
|
-
"lint": "eslint
|
|
26
|
-
"
|
|
27
|
-
"test:mocha
|
|
25
|
+
"lint": "eslint",
|
|
26
|
+
"lint:fix": "eslint src --ext .jsx --ext .js --ext .tsx --ext .ts --cache --fix",
|
|
27
|
+
"test:mocha": "nyc --reporter=text mocha --require ts-node/register test/**/*.{ts,tsx} -t 60000",
|
|
28
|
+
"test:mocha:reporter": "nyc --reporter=lcov --reporter=text mocha --require ts-node/register test/**/*.{ts,tsx} -t 60000 --reporter=mochawesome",
|
|
28
29
|
"watch:ts": "tsc --watch",
|
|
29
30
|
"prepublishOnly": "npm run test:mocha && npm run lint && npm run build:ts"
|
|
30
31
|
},
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@types/async": "^3.2.25",
|
|
34
|
+
"@types/commander": "^2.12.5",
|
|
35
|
+
"@types/inquirer": "^9.0.9",
|
|
36
|
+
"@types/ora": "^3.2.0",
|
|
37
|
+
"@types/progress": "^2.0.7",
|
|
38
|
+
"@types/request": "^2.48.13",
|
|
39
|
+
"async": "^3.2.6",
|
|
40
|
+
"chalk": "^5.6.2",
|
|
41
|
+
"commander": "^14.0.2",
|
|
42
|
+
"inquirer": "^13.1.0",
|
|
43
|
+
"ora": "^9.0.0",
|
|
44
|
+
"progress": "^2.0.3",
|
|
45
|
+
"request": "^2.88.2"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@antfu/eslint-config": "^6.7.3",
|
|
49
|
+
"@types/chai": "^5.2.3",
|
|
50
|
+
"@types/mocha": "^10.0.10",
|
|
51
|
+
"@types/node": "^25.0.3",
|
|
52
|
+
"@typescript-eslint/parser": "^8.50.1",
|
|
53
|
+
"chai": "^6.2.2",
|
|
54
|
+
"eslint": "^9.39.2",
|
|
55
|
+
"husky": "^9.1.7",
|
|
56
|
+
"lint-staged": "^16.2.7",
|
|
57
|
+
"mocha": "^11.7.5",
|
|
58
|
+
"nyc": "^17.1.0",
|
|
59
|
+
"ts-node": "^10.9.2",
|
|
60
|
+
"typescript": "^5.9.3"
|
|
36
61
|
},
|
|
37
62
|
"husky": {
|
|
38
63
|
"hooks": {
|
|
39
64
|
"pre-commit": "lint-staged"
|
|
40
65
|
}
|
|
41
66
|
},
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^2.13.0",
|
|
48
|
-
"@typescript-eslint/parser": "^2.13.0",
|
|
49
|
-
"chai": "^4.2.0",
|
|
50
|
-
"eslint": "^6.8.0",
|
|
51
|
-
"eslint-import-resolver-typescript": "^2.0.0",
|
|
52
|
-
"eslint-plugin-import": "^2.19.1",
|
|
53
|
-
"eslint-plugin-promise": "^4.1.1",
|
|
54
|
-
"husky": "^2.3.0",
|
|
55
|
-
"lint-staged": "^8.1.7",
|
|
56
|
-
"mocha": "^6.2.0",
|
|
57
|
-
"mochawesome": "^4.1.0",
|
|
58
|
-
"nyc": "^14.1.1",
|
|
59
|
-
"ts-node": "^8.3.0",
|
|
60
|
-
"typescript": "^3.7.4"
|
|
61
|
-
},
|
|
62
|
-
"dependencies": {
|
|
63
|
-
"@types/async": "^3.0.3",
|
|
64
|
-
"@types/commander": "^2.12.2",
|
|
65
|
-
"@types/inquirer": "^6.5.0",
|
|
66
|
-
"@types/ora": "^3.2.0",
|
|
67
|
-
"@types/progress": "^2.0.3",
|
|
68
|
-
"@types/request": "^2.48.3",
|
|
69
|
-
"async": "^3.1.0",
|
|
70
|
-
"chalk": "^3.0.0",
|
|
71
|
-
"commander": "^4.0.1",
|
|
72
|
-
"inquirer": "^7.0.0",
|
|
73
|
-
"ora": "^4.0.3",
|
|
74
|
-
"progress": "^2.0.3",
|
|
75
|
-
"request": "^2.88.0"
|
|
67
|
+
"lint-staged": {
|
|
68
|
+
"**/*.{jsx,js}": [
|
|
69
|
+
"npm run lint",
|
|
70
|
+
"git add"
|
|
71
|
+
]
|
|
76
72
|
}
|
|
77
73
|
}
|
package/renovate.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
3
|
+
"extends": ["config:recommended"],
|
|
4
|
+
"dependencyDashboard": true,
|
|
5
|
+
"prHourlyLimit": 2,
|
|
6
|
+
"prConcurrentLimit": 10,
|
|
7
|
+
"packageRules": [
|
|
8
|
+
{
|
|
9
|
+
"matchUpdateTypes": ["minor", "patch"],
|
|
10
|
+
"automerge": true
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"npm": {
|
|
14
|
+
"enabled": true
|
|
15
|
+
},
|
|
16
|
+
"github-actions": {
|
|
17
|
+
"enabled": true
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/cmd/action.ts
CHANGED
|
@@ -1,128 +1,135 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
import type { Ora } from 'ora';
|
|
3
|
+
import type { CommandInfo } from './type';
|
|
4
|
+
import ora from 'ora';
|
|
3
5
|
import ProgressBar from 'progress';
|
|
4
6
|
import dgit from '../dgit';
|
|
5
|
-
import {
|
|
6
|
-
ParseGithubHttpsLink, TextEllipsis, isHttpsLink,
|
|
7
|
-
} from './utils';
|
|
8
|
-
import { CommandInfo } from './type';
|
|
9
7
|
|
|
10
8
|
import { DownloadPrompt, PasswordPrompt } from './prompt';
|
|
9
|
+
import {
|
|
10
|
+
isHttpsLink,
|
|
11
|
+
ParseGithubHttpsLink,
|
|
12
|
+
TextEllipsis,
|
|
13
|
+
} from './utils';
|
|
11
14
|
|
|
12
15
|
const MAX_TEXT_ELLIPSIS = 30;
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
relativePath = '',
|
|
24
|
-
password,
|
|
25
|
-
} = cmd;
|
|
17
|
+
async function DownloadAction(githubLink: string | undefined, cmd: Command & CommandInfo): Promise<any> {
|
|
18
|
+
let {
|
|
19
|
+
ref = '',
|
|
20
|
+
dest = '',
|
|
21
|
+
owner = '',
|
|
22
|
+
repoName = '',
|
|
23
|
+
relativePath = '',
|
|
24
|
+
password,
|
|
25
|
+
} = cmd;
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
const {
|
|
28
|
+
exclude = '',
|
|
29
|
+
include = '',
|
|
30
|
+
log = false,
|
|
31
|
+
logPrefix = '[dgit-logger]',
|
|
32
|
+
} = cmd;
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
const {
|
|
35
|
+
parallelLimit = '',
|
|
36
|
+
username,
|
|
37
|
+
token,
|
|
38
|
+
} = cmd;
|
|
39
|
+
const {
|
|
40
|
+
proxy = '',
|
|
41
|
+
} = cmd;
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
if (githubLink && isHttpsLink(githubLink)) {
|
|
44
|
+
const parseResult = ParseGithubHttpsLink(githubLink);
|
|
45
|
+
ref = parseResult.ref;
|
|
46
|
+
owner = parseResult.owner;
|
|
47
|
+
repoName = parseResult.repoName;
|
|
48
|
+
relativePath = parseResult.relativePath;
|
|
49
|
+
}
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
if (username && !password) {
|
|
52
|
+
const pwdAnswer = await PasswordPrompt();
|
|
53
|
+
password = pwdAnswer.password;
|
|
54
|
+
}
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
const answer = await DownloadPrompt({
|
|
57
|
+
ref,
|
|
58
|
+
dest,
|
|
59
|
+
owner,
|
|
60
|
+
repoName,
|
|
61
|
+
relativePath,
|
|
62
|
+
});
|
|
59
63
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
ref = answer.ref;
|
|
65
|
+
dest = answer.dest;
|
|
66
|
+
owner = answer.owner;
|
|
67
|
+
repoName = answer.repoName;
|
|
68
|
+
relativePath = answer.relativePath;
|
|
65
69
|
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
const excludeList = exclude.split(',').filter(Boolean);
|
|
71
|
+
const includeList = include.split(',').filter(Boolean);
|
|
68
72
|
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
const spinner: Ora = ora(' loading remote repo tree...');
|
|
74
|
+
let bar: ProgressBar;
|
|
71
75
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
76
|
+
try {
|
|
77
|
+
await dgit(
|
|
78
|
+
{
|
|
79
|
+
ref,
|
|
80
|
+
owner,
|
|
81
|
+
repoName,
|
|
82
|
+
relativePath,
|
|
83
|
+
username,
|
|
84
|
+
password,
|
|
85
|
+
token,
|
|
86
|
+
proxy,
|
|
87
|
+
},
|
|
88
|
+
dest,
|
|
89
|
+
{
|
|
90
|
+
log,
|
|
91
|
+
logPrefix,
|
|
92
|
+
parallelLimit: Number(parallelLimit.trim()),
|
|
93
|
+
exclude: excludeList,
|
|
94
|
+
include: includeList,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
beforeLoadTree() {
|
|
98
|
+
spinner.start();
|
|
99
|
+
},
|
|
100
|
+
afterLoadTree() {
|
|
101
|
+
spinner.succeed(' load remote repo tree succeed! ');
|
|
102
|
+
},
|
|
103
|
+
onResolved(status) {
|
|
104
|
+
if (log)
|
|
105
|
+
return;
|
|
106
|
+
const green = '\u001B[42m \u001B[0m';
|
|
107
|
+
const red = '\u001B[41m \u001B[0m';
|
|
108
|
+
const index = 0;
|
|
109
|
+
bar = new ProgressBar(
|
|
110
|
+
' DOWNLOAD |:bar| :current/:total :percent elapsed: :elapseds eta: :eta :file, done.',
|
|
92
111
|
{
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
spinner.succeed(' load remote repo tree succeed! ');
|
|
98
|
-
},
|
|
99
|
-
onResolved (status) {
|
|
100
|
-
if (log) return;
|
|
101
|
-
const green = '\u001b[42m \u001b[0m';
|
|
102
|
-
const red = '\u001b[41m \u001b[0m';
|
|
103
|
-
const index = 0;
|
|
104
|
-
bar = new ProgressBar(
|
|
105
|
-
' DOWNLOAD |:bar| :current/:total :percent elapsed: :elapseds eta: :eta :file, done.',
|
|
106
|
-
{
|
|
107
|
-
total : status.totalCount,
|
|
108
|
-
width : 50,
|
|
109
|
-
complete : green,
|
|
110
|
-
incomplete: red,
|
|
111
|
-
},
|
|
112
|
-
);
|
|
113
|
-
bar.update(index);
|
|
114
|
-
},
|
|
115
|
-
onProgress (_, node) {
|
|
116
|
-
if (log) return;
|
|
117
|
-
bar.tick({ file: TextEllipsis(node.path, MAX_TEXT_ELLIPSIS) });
|
|
118
|
-
},
|
|
112
|
+
total: status.totalCount,
|
|
113
|
+
width: 50,
|
|
114
|
+
complete: green,
|
|
115
|
+
incomplete: red,
|
|
119
116
|
},
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
};
|
|
117
|
+
);
|
|
118
|
+
bar.update(index);
|
|
119
|
+
},
|
|
120
|
+
onProgress(_, node) {
|
|
121
|
+
if (log)
|
|
122
|
+
return;
|
|
123
|
+
bar.tick({ file: TextEllipsis(node.path, MAX_TEXT_ELLIPSIS) });
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
);
|
|
127
|
+
spinner.succeed(' download all files succeed!');
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
console.error(error);
|
|
131
|
+
spinner.fail(' download files failed!');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
127
134
|
|
|
128
135
|
export default DownloadAction;
|
package/src/cmd/main.ts
CHANGED
|
@@ -1,70 +1,72 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { PackageInfo } from './type';
|
|
2
|
+
import process from 'node:process';
|
|
2
3
|
import chalk from 'chalk';
|
|
3
4
|
|
|
4
|
-
import {
|
|
5
|
-
import { GetPackageInfo } from './utils';
|
|
5
|
+
import { Command } from 'commander';
|
|
6
6
|
import DownloadAction from './action';
|
|
7
|
+
import { GetPackageInfo } from './utils';
|
|
7
8
|
|
|
8
9
|
const EXIT_CODE = 1;
|
|
10
|
+
const program = new Command();
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
12
|
+
function Exit(): void {
|
|
13
|
+
process.exit(EXIT_CODE);
|
|
14
|
+
}
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
16
|
+
function UnknownCommand(cmdName: string): void {
|
|
17
|
+
console.log(`${chalk.red('Unknown command')} ${chalk.yellow(cmdName)}.`);
|
|
18
|
+
}
|
|
17
19
|
|
|
18
20
|
const packageInfo: PackageInfo = GetPackageInfo();
|
|
19
21
|
|
|
20
22
|
program.version(packageInfo.version);
|
|
21
23
|
|
|
22
24
|
program
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
25
|
+
.command('download [githubLink]')
|
|
26
|
+
.option('--owner <ownerName>', 'git repo author.')
|
|
27
|
+
.option('--repo-name <repoName>', 'git repo name.')
|
|
28
|
+
.option('--ref <refName>', 'git repo branch, commit hash or tagname.')
|
|
29
|
+
.option(
|
|
30
|
+
'--relative-path <relativePath>',
|
|
31
|
+
'specified repo relative path to download.',
|
|
32
|
+
)
|
|
33
|
+
.option('-d, --dest <destPath>', 'specified dest path.')
|
|
34
|
+
.option(
|
|
35
|
+
'-l, --parallel-limit, <number>',
|
|
36
|
+
'specified download max parallel limit.',
|
|
37
|
+
)
|
|
38
|
+
.option('-u, --username, <username>', 'specified git account username.')
|
|
39
|
+
.option('-p --password, <password>', 'specified git account password.')
|
|
40
|
+
.option(
|
|
41
|
+
'-t --token, <token>',
|
|
42
|
+
'specified git account personal access token.',
|
|
43
|
+
)
|
|
44
|
+
.option(
|
|
45
|
+
'-e --exclude, <relativePath,...,relativePath>',
|
|
46
|
+
'indicates which file paths need to be excluded in the current directory.',
|
|
47
|
+
)
|
|
48
|
+
.option(
|
|
49
|
+
'-i --include, <relativePath,...,relativePath>',
|
|
50
|
+
'indicates which files need to be included in the exclusion file list.',
|
|
51
|
+
)
|
|
52
|
+
.option('--log', 'output dgit internal log details.')
|
|
53
|
+
.option('--log-prefix, <log>', 'dgit internal log prefix.')
|
|
54
|
+
.option('--proxy, <proxyHttp>', 'dgit proxy download url.')
|
|
55
|
+
.alias('d')
|
|
56
|
+
.description('download the file with the specified path of the remote repo.')
|
|
57
|
+
.action(DownloadAction);
|
|
56
58
|
|
|
57
59
|
program.on('command:*', (cmdObj = []) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
const [cmd] = cmdObj;
|
|
61
|
+
if (cmd) {
|
|
62
|
+
program.outputHelp();
|
|
63
|
+
UnknownCommand(cmd);
|
|
64
|
+
Exit();
|
|
65
|
+
}
|
|
64
66
|
});
|
|
65
67
|
|
|
66
68
|
if (process.argv.slice(2).length <= 0) {
|
|
67
|
-
|
|
69
|
+
program.help();
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
program.parse(process.argv);
|