@bratel/dgit 0.0.13 → 0.0.15
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 +82 -78
- package/lib/cmd/main.js +18 -15
- package/lib/cmd/prompt.d.ts +4 -4
- package/lib/cmd/prompt.js +82 -76
- package/lib/cmd/type.d.ts +1 -0
- 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 +171 -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 +2 -1
- package/package.json +61 -55
- package/renovate.json +19 -0
- package/src/cmd/action.ts +117 -108
- package/src/cmd/main.ts +52 -49
- package/src/cmd/prompt.ts +93 -92
- package/src/cmd/type.ts +28 -27
- package/src/cmd/utils.ts +78 -73
- package/src/dgit.ts +247 -228
- package/src/log.ts +9 -7
- package/src/repo.ts +6 -4
- package/src/request.ts +91 -92
- package/src/type.ts +37 -36
- package/test/dgit.test.ts +122 -119
- package/tsconfig.json +54 -51
- package/tsconfig.tsbuildinfo +1 -0
- package/.eslintignore +0 -6
- package/.eslintrc.js +0 -30
- package/x-npmrc +0 -2
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
|
+
}
|
package/lib/cmd/type.d.ts
CHANGED
package/lib/cmd/utils.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare
|
|
1
|
+
import type { GithubLinkInfo, PackageInfo } from './type';
|
|
2
|
+
export declare function GetPackageInfo(): PackageInfo;
|
|
3
3
|
export declare const GITHUB_ADDRESS = "https://github.com/";
|
|
4
4
|
export declare const isHttpsLink: (link: string) => boolean;
|
|
5
|
-
export declare
|
|
5
|
+
export declare function ParseGithubHttpsLink(httpsLink: string): GithubLinkInfo;
|
|
6
6
|
export declare const TextEllipsis: (text: string, maxLen: number) => string;
|
|
7
|
-
export declare
|
|
8
|
-
export declare
|
|
7
|
+
export declare function MakeDirs(dirs: string): void;
|
|
8
|
+
export declare function AddExtraRandomQs(origin: string): string;
|
package/lib/cmd/utils.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.TextEllipsis = exports.isHttpsLink = exports.GITHUB_ADDRESS = void 0;
|
|
4
|
+
exports.GetPackageInfo = GetPackageInfo;
|
|
5
|
+
exports.ParseGithubHttpsLink = ParseGithubHttpsLink;
|
|
6
|
+
exports.MakeDirs = MakeDirs;
|
|
7
|
+
exports.AddExtraRandomQs = AddExtraRandomQs;
|
|
4
8
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const buffer =
|
|
9
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
10
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
11
|
+
function GetPackageInfo() {
|
|
12
|
+
const buffer = node_fs_1.default.readFileSync(node_path_1.default.resolve(__dirname, '../../package.json'));
|
|
9
13
|
return JSON.parse(buffer.toString());
|
|
10
|
-
}
|
|
14
|
+
}
|
|
11
15
|
exports.GITHUB_ADDRESS = 'https://github.com/';
|
|
12
|
-
|
|
13
|
-
exports.
|
|
16
|
+
const isHttpsLink = (link) => link.trim().startsWith(exports.GITHUB_ADDRESS);
|
|
17
|
+
exports.isHttpsLink = isHttpsLink;
|
|
18
|
+
function ParseGithubHttpsLink(httpsLink) {
|
|
14
19
|
let nextLink = httpsLink.trim().slice(exports.GITHUB_ADDRESS.length);
|
|
15
20
|
let index = nextLink.indexOf('/');
|
|
16
21
|
if (index === -1)
|
|
@@ -62,26 +67,27 @@ exports.ParseGithubHttpsLink = (httpsLink) => {
|
|
|
62
67
|
relativePath,
|
|
63
68
|
type,
|
|
64
69
|
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
exports.
|
|
70
|
+
}
|
|
71
|
+
const TextEllipsis = (text, maxLen) => (text.length >= maxLen ? `${text.slice(0, maxLen)}...` : text);
|
|
72
|
+
exports.TextEllipsis = TextEllipsis;
|
|
73
|
+
function MakeDirs(dirs) {
|
|
68
74
|
const mkdirs = (dir, callback) => {
|
|
69
|
-
if (
|
|
75
|
+
if (node_fs_1.default.existsSync(dir)) {
|
|
70
76
|
callback && callback();
|
|
71
77
|
return;
|
|
72
78
|
}
|
|
73
|
-
mkdirs(
|
|
74
|
-
|
|
79
|
+
mkdirs(node_path_1.default.dirname(dir), () => {
|
|
80
|
+
node_fs_1.default.mkdirSync(dir);
|
|
75
81
|
callback && callback();
|
|
76
82
|
});
|
|
77
83
|
};
|
|
78
|
-
if (
|
|
84
|
+
if (node_fs_1.default.existsSync(dirs))
|
|
79
85
|
return;
|
|
80
86
|
mkdirs(dirs);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (origin.
|
|
87
|
+
}
|
|
88
|
+
function AddExtraRandomQs(origin) {
|
|
89
|
+
if (origin.includes('?')) {
|
|
84
90
|
return `${origin}&_t=${Math.random()}`;
|
|
85
91
|
}
|
|
86
92
|
return `${origin}?_t=${Math.random()}`;
|
|
87
|
-
}
|
|
93
|
+
}
|
package/lib/dgit.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DgitGlobalOption,
|
|
2
|
-
declare
|
|
1
|
+
import type { DgitGlobalOption, DgitLifeCycle, DgitLoadGitTree, RepoOptionType } from './type';
|
|
2
|
+
declare function dgit(repoOption: RepoOptionType, dPath: string, dgitOptions?: DgitGlobalOption, hooks?: DgitLifeCycle & DgitLoadGitTree): Promise<void>;
|
|
3
3
|
export default dgit;
|
package/lib/dgit.js
CHANGED
|
@@ -1,179 +1,193 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
5
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
6
|
+
const node_process_1 = tslib_1.__importDefault(require("node:process"));
|
|
6
7
|
const async_1 = tslib_1.__importDefault(require("async"));
|
|
7
|
-
const
|
|
8
|
+
const utils_1 = require("./cmd/utils");
|
|
8
9
|
const log_1 = require("./log");
|
|
10
|
+
const repo_1 = tslib_1.__importDefault(require("./repo"));
|
|
9
11
|
const request_1 = require("./request");
|
|
10
|
-
const utils_1 = require("./cmd/utils");
|
|
11
12
|
const UserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36';
|
|
12
13
|
const DEFAULT_PARALLEL_LIMIT = 10;
|
|
13
14
|
const MAX_PARALLEL_LIMIT = 100;
|
|
14
15
|
const JSON_STRINGIFY_PADDING = 2;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
parallelLimit
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const { onSuccess, onError, onProgress, onFinish, onRetry, onResolved, beforeLoadTree, afterLoadTree, } = hooks || {};
|
|
37
|
-
let onSuccessResolve = () => { };
|
|
38
|
-
let onErrorReject = () => { };
|
|
39
|
-
const prom = new Promise((resolve, reject) => {
|
|
40
|
-
onSuccessResolve = resolve;
|
|
41
|
-
onErrorReject = reject;
|
|
42
|
-
});
|
|
43
|
-
const { getRepoTreeUrl, getDownloadUrl } = repo_1.default(owner, repoName, ref, proxy);
|
|
44
|
-
const url = getRepoTreeUrl();
|
|
45
|
-
const headers = {
|
|
46
|
-
'User-Agent': UserAgent,
|
|
47
|
-
Authorization: token ? `token ${token}` : undefined,
|
|
48
|
-
};
|
|
49
|
-
const auth = username && password ?
|
|
50
|
-
{
|
|
51
|
-
user: username,
|
|
52
|
-
pass: password,
|
|
53
|
-
sendImmediately: true,
|
|
54
|
-
} :
|
|
55
|
-
undefined;
|
|
56
|
-
const options = {
|
|
57
|
-
url, headers, auth,
|
|
58
|
-
};
|
|
59
|
-
const destPath = path_1.default.isAbsolute(dPath) ? dPath : path_1.default.resolve(process.cwd(), dPath);
|
|
60
|
-
logger(' request repo tree options.');
|
|
61
|
-
logger(JSON.stringify(options, null, JSON_STRINGIFY_PADDING));
|
|
62
|
-
try {
|
|
63
|
-
logger(' loading remote repo tree...');
|
|
64
|
-
beforeLoadTree && beforeLoadTree();
|
|
65
|
-
const body = yield request_1.requestGetPromise(options, dgitOptions || {}, {
|
|
66
|
-
onRetry() {
|
|
67
|
-
logger(` request ${url} failed. Retrying...`);
|
|
68
|
-
onRetry && onRetry();
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
logger(' loading remote repo tree succeed.');
|
|
72
|
-
afterLoadTree && afterLoadTree();
|
|
73
|
-
const result = JSON.parse(body);
|
|
74
|
-
if (!result.tree || result.tree.length <= 0) {
|
|
75
|
-
throw new Error('404 repo not found!');
|
|
16
|
+
// https://deepwiki.com/search/python-node-treepythonjula-pyt_e06e7d62-6a9a-4d4b-9e74-0a1cf32f4946?mode=fast
|
|
17
|
+
function dgit(repoOption, dPath, dgitOptions, hooks) {
|
|
18
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const { username, password, token, githubLink, proxy = '', } = repoOption;
|
|
20
|
+
let { owner, repoName, ref = 'master', relativePath = '.', } = repoOption;
|
|
21
|
+
if (githubLink && (0, utils_1.isHttpsLink)(githubLink)) {
|
|
22
|
+
const parseResult = (0, utils_1.ParseGithubHttpsLink)(githubLink);
|
|
23
|
+
owner = parseResult.owner;
|
|
24
|
+
repoName = parseResult.repoName;
|
|
25
|
+
ref = parseResult.ref;
|
|
26
|
+
relativePath = parseResult.relativePath;
|
|
27
|
+
}
|
|
28
|
+
if (!owner || !repoName) {
|
|
29
|
+
throw new Error('invalid repo option.');
|
|
30
|
+
}
|
|
31
|
+
const logger = (0, log_1.createLogger)(dgitOptions);
|
|
32
|
+
const { exclude = [], include = [], exactMatch = false } = dgitOptions || {};
|
|
33
|
+
let { parallelLimit = DEFAULT_PARALLEL_LIMIT } = dgitOptions || {};
|
|
34
|
+
if (!parallelLimit || parallelLimit <= 0) {
|
|
35
|
+
logger('parallelLimit value is invalid.');
|
|
36
|
+
parallelLimit = DEFAULT_PARALLEL_LIMIT;
|
|
76
37
|
}
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
38
|
+
parallelLimit > MAX_PARALLEL_LIMIT && (parallelLimit = MAX_PARALLEL_LIMIT);
|
|
39
|
+
const { onSuccess, onError, onProgress, onFinish, onRetry, onResolved, beforeLoadTree, afterLoadTree, } = hooks || {};
|
|
40
|
+
let onSuccessResolve = () => { };
|
|
41
|
+
let onErrorReject = () => { };
|
|
42
|
+
const prom = new Promise((resolve, reject) => {
|
|
43
|
+
onSuccessResolve = resolve;
|
|
44
|
+
onErrorReject = reject;
|
|
45
|
+
});
|
|
46
|
+
const { getRepoTreeUrl, getDownloadUrl } = (0, repo_1.default)(owner, repoName, ref, proxy);
|
|
47
|
+
const url = getRepoTreeUrl();
|
|
48
|
+
const headers = {
|
|
49
|
+
'User-Agent': UserAgent,
|
|
50
|
+
'Authorization': token ? `token ${token}` : undefined,
|
|
51
|
+
};
|
|
52
|
+
const auth = username && password
|
|
53
|
+
? {
|
|
54
|
+
user: username,
|
|
55
|
+
pass: password,
|
|
56
|
+
sendImmediately: true,
|
|
83
57
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
58
|
+
: undefined;
|
|
59
|
+
const options = {
|
|
60
|
+
url,
|
|
61
|
+
headers,
|
|
62
|
+
auth,
|
|
63
|
+
};
|
|
64
|
+
const destPath = node_path_1.default.isAbsolute(dPath) ? dPath : node_path_1.default.resolve(node_process_1.default.cwd(), dPath);
|
|
65
|
+
logger(' request repo tree options.');
|
|
66
|
+
logger(JSON.stringify(options, null, JSON_STRINGIFY_PADDING));
|
|
67
|
+
try {
|
|
68
|
+
logger(' loading remote repo tree...');
|
|
69
|
+
beforeLoadTree && beforeLoadTree();
|
|
70
|
+
const body = yield (0, request_1.requestGetPromise)(options, dgitOptions || {}, {
|
|
71
|
+
onRetry() {
|
|
72
|
+
logger(` request ${url} failed. Retrying...`);
|
|
73
|
+
onRetry && onRetry();
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
logger(' loading remote repo tree succeed.');
|
|
77
|
+
afterLoadTree && afterLoadTree();
|
|
78
|
+
const result = JSON.parse(body);
|
|
79
|
+
if (!result.tree || result.tree.length <= 0) {
|
|
80
|
+
throw new Error('404 repo not found!');
|
|
87
81
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
82
|
+
const treeNodeList = result.tree;
|
|
83
|
+
const includeTreeNodeList = treeNodeList.filter((node) => {
|
|
84
|
+
const nPath = node_path_1.default.resolve(__dirname, node.path);
|
|
85
|
+
const rPath = node_path_1.default.resolve(__dirname, relativePath);
|
|
86
|
+
let pathMatch;
|
|
87
|
+
if (exactMatch) {
|
|
88
|
+
// 精确匹配:路径完全相等或者路径后跟分隔符
|
|
89
|
+
pathMatch = nPath === rPath || nPath.startsWith(rPath + node_path_1.default.sep) || nPath.startsWith(`${rPath}/`);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
pathMatch = nPath.startsWith(rPath);
|
|
93
|
+
}
|
|
94
|
+
if (!pathMatch || node.type !== 'blob') {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
if (exclude.some(v => nPath.startsWith(node_path_1.default.resolve(rPath, v)))
|
|
98
|
+
&& include.every(v => !nPath.startsWith(node_path_1.default.resolve(rPath, v)))) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
});
|
|
103
|
+
if (includeTreeNodeList.length <= 0) {
|
|
104
|
+
throw new Error(`404 repo ${relativePath} not found!`);
|
|
97
105
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
106
|
+
const totalStatus = includeTreeNodeList.reduce((prev, cur) => {
|
|
107
|
+
if (cur.type === 'blob') {
|
|
108
|
+
prev.size += cur.size;
|
|
109
|
+
prev.count++;
|
|
110
|
+
}
|
|
111
|
+
return prev;
|
|
112
|
+
}, { size: 0, count: 0 });
|
|
113
|
+
let currentSize = 0;
|
|
114
|
+
let currentCount = 0;
|
|
115
|
+
onResolved
|
|
116
|
+
&& onResolved({
|
|
117
|
+
currentSize,
|
|
118
|
+
currentCount,
|
|
119
|
+
totalSize: totalStatus.size,
|
|
120
|
+
totalCount: totalStatus.count,
|
|
121
|
+
});
|
|
122
|
+
logger(' include files resolved.');
|
|
123
|
+
logger('', JSON.stringify({
|
|
104
124
|
currentSize,
|
|
105
125
|
currentCount,
|
|
106
126
|
totalSize: totalStatus.size,
|
|
107
127
|
totalCount: totalStatus.count,
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const ws = fs_1.default.createWriteStream(targetPath);
|
|
133
|
-
logger(` downloading from ${downloadUrl}...`);
|
|
134
|
-
request_1.requestOnStream(downloadUrl, ws, dgitOptions || {}, {
|
|
135
|
-
onSuccess() {
|
|
136
|
-
currentCount++;
|
|
137
|
-
currentSize += node.size;
|
|
138
|
-
logger(` write file ${node.path} succeed.
|
|
128
|
+
}));
|
|
129
|
+
async_1.default.eachLimit(includeTreeNodeList, parallelLimit, (node, callback) => {
|
|
130
|
+
const downloadUrl = getDownloadUrl(node.path);
|
|
131
|
+
const rPath = node_path_1.default.resolve(destPath, relativePath);
|
|
132
|
+
const tPath = node_path_1.default.resolve(destPath, node.path);
|
|
133
|
+
const root = node_path_1.default.resolve(destPath, '.');
|
|
134
|
+
let targetPath;
|
|
135
|
+
if (rPath === tPath) {
|
|
136
|
+
targetPath = node_path_1.default.resolve(destPath, node_path_1.default.basename(tPath));
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
targetPath = tPath.replace(rPath, root);
|
|
140
|
+
}
|
|
141
|
+
logger('', node.path, relativePath, targetPath);
|
|
142
|
+
if (!node_fs_1.default.existsSync(node_path_1.default.dirname(targetPath))) {
|
|
143
|
+
(0, utils_1.MakeDirs)(node_path_1.default.dirname(targetPath));
|
|
144
|
+
}
|
|
145
|
+
const ws = node_fs_1.default.createWriteStream(targetPath);
|
|
146
|
+
logger(` downloading from ${downloadUrl}...`);
|
|
147
|
+
(0, request_1.requestOnStream)(downloadUrl, ws, dgitOptions || {}, {
|
|
148
|
+
onSuccess() {
|
|
149
|
+
currentCount++;
|
|
150
|
+
currentSize += node.size;
|
|
151
|
+
logger(` write file ${node.path} succeed.
|
|
139
152
|
size: [${currentSize}/${totalStatus.size}],
|
|
140
153
|
count: [${currentCount}/${totalStatus.count}]`);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
154
|
+
onProgress
|
|
155
|
+
&& onProgress({
|
|
156
|
+
totalCount: totalStatus.count,
|
|
157
|
+
totalSize: totalStatus.size,
|
|
158
|
+
currentSize,
|
|
159
|
+
currentCount,
|
|
160
|
+
}, node);
|
|
161
|
+
callback();
|
|
162
|
+
},
|
|
163
|
+
onError(err) {
|
|
164
|
+
logger('', err);
|
|
165
|
+
callback(new Error(` request ${downloadUrl} failed.`));
|
|
166
|
+
},
|
|
167
|
+
onRetry() {
|
|
168
|
+
logger(` request ${downloadUrl} failed. Retrying...`);
|
|
169
|
+
onRetry && onRetry();
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
}, (err) => {
|
|
173
|
+
if (err) {
|
|
174
|
+
onError && onError(err);
|
|
175
|
+
onFinish && onFinish();
|
|
176
|
+
onErrorReject(err);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
onSuccess && onSuccess();
|
|
180
|
+
onFinish && onFinish();
|
|
181
|
+
onSuccessResolve();
|
|
182
|
+
}
|
|
158
183
|
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
onSuccessResolve();
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
catch (error) {
|
|
173
|
-
onError && onError(error);
|
|
174
|
-
onFinish && onFinish();
|
|
175
|
-
onErrorReject(error);
|
|
176
|
-
}
|
|
177
|
-
return prom;
|
|
178
|
-
});
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
onError && onError(error);
|
|
187
|
+
onFinish && onFinish();
|
|
188
|
+
onErrorReject(error);
|
|
189
|
+
}
|
|
190
|
+
return prom;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
179
193
|
exports.default = dgit;
|
package/lib/log.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DgitGlobalOption } from './type';
|
|
2
|
-
export declare
|
|
1
|
+
import type { DgitGlobalOption } from './type';
|
|
2
|
+
export declare function createLogger(option?: DgitGlobalOption): (...message: any[]) => void;
|