@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/src/cmd/prompt.ts
CHANGED
|
@@ -1,98 +1,99 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { DownloadPromptInfo, PasswordPromptInfo } from './type';
|
|
1
|
+
import type { Question } from 'inquirer';
|
|
2
|
+
import type { DownloadPromptInfo, PasswordPromptInfo } from './type';
|
|
3
|
+
import inquirer from 'inquirer';
|
|
3
4
|
|
|
4
5
|
export const CreatePrompt = (questions: Array<Question>): Promise<any> => inquirer.prompt(questions);
|
|
5
6
|
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
export async function DownloadPrompt(currentInfo: DownloadPromptInfo): Promise<DownloadPromptInfo> {
|
|
8
|
+
if (
|
|
9
|
+
currentInfo.owner
|
|
10
|
+
&& currentInfo.repoName
|
|
11
|
+
&& currentInfo.ref
|
|
12
|
+
&& currentInfo.relativePath
|
|
13
|
+
&& currentInfo.dest
|
|
14
|
+
) {
|
|
15
|
+
return currentInfo;
|
|
16
|
+
}
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
18
|
+
const questions = [
|
|
19
|
+
{
|
|
20
|
+
type: 'input',
|
|
21
|
+
name: 'owner',
|
|
22
|
+
when() {
|
|
23
|
+
return !currentInfo.owner;
|
|
24
|
+
},
|
|
25
|
+
validate(input: string) {
|
|
26
|
+
return input && input.length > 0;
|
|
27
|
+
},
|
|
28
|
+
message: 'input github ownername.',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
type: 'input',
|
|
32
|
+
name: 'repoName',
|
|
33
|
+
when() {
|
|
34
|
+
return !currentInfo.repoName;
|
|
35
|
+
},
|
|
36
|
+
validate(input: string) {
|
|
37
|
+
return input && input.length > 0;
|
|
38
|
+
},
|
|
39
|
+
message: 'input github repoName.',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
type: 'input',
|
|
43
|
+
name: 'ref',
|
|
44
|
+
when() {
|
|
45
|
+
return !currentInfo.ref;
|
|
46
|
+
},
|
|
47
|
+
validate(input: string) {
|
|
48
|
+
return input && input.length > 0;
|
|
49
|
+
},
|
|
50
|
+
default: 'master',
|
|
51
|
+
message: 'input github branch or commit hash or tagname.',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
type: 'input',
|
|
55
|
+
name: 'relativePath',
|
|
56
|
+
when() {
|
|
57
|
+
return !currentInfo.relativePath;
|
|
58
|
+
},
|
|
59
|
+
validate(input: string) {
|
|
60
|
+
return input && input.length > 0;
|
|
61
|
+
},
|
|
62
|
+
default: '.',
|
|
63
|
+
message: 'input github relative path.',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
type: 'input',
|
|
67
|
+
name: 'dest',
|
|
68
|
+
when() {
|
|
69
|
+
return !currentInfo.dest;
|
|
70
|
+
},
|
|
71
|
+
validate(input: string) {
|
|
72
|
+
return input && input.length > 0;
|
|
73
|
+
},
|
|
74
|
+
default: '.',
|
|
75
|
+
message: 'input template output dest path.',
|
|
76
|
+
},
|
|
77
|
+
];
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
79
|
+
const answer = await 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
|
+
}
|
|
87
88
|
|
|
88
|
-
export
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
89
|
+
export function PasswordPrompt(): Promise<PasswordPromptInfo> {
|
|
90
|
+
const question = {
|
|
91
|
+
type: 'password',
|
|
92
|
+
name: 'password',
|
|
93
|
+
validate(input: string) {
|
|
94
|
+
return input && input.length > 0;
|
|
95
|
+
},
|
|
96
|
+
message: 'input github account password.',
|
|
97
|
+
};
|
|
98
|
+
return CreatePrompt([question]);
|
|
99
|
+
}
|
package/src/cmd/type.ts
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
export interface PackageInfo {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
version: string;
|
|
3
|
+
name: string;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export interface CommandInfo {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
dest?: string;
|
|
8
|
+
owner?: string;
|
|
9
|
+
repoName?: string;
|
|
10
|
+
ref?: string;
|
|
11
|
+
relativePath?: string;
|
|
12
|
+
parallelLimit?: string;
|
|
13
|
+
username?: string;
|
|
14
|
+
password?: string;
|
|
15
|
+
token?: string;
|
|
16
|
+
exclude?: string;
|
|
17
|
+
include?: string;
|
|
18
|
+
log?: boolean;
|
|
19
|
+
logPrefix?: string;
|
|
20
|
+
proxy?: string;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface DownloadPromptInfo {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
dest: string;
|
|
25
|
+
owner: string;
|
|
26
|
+
repoName: string;
|
|
27
|
+
ref: string;
|
|
28
|
+
relativePath: string;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export interface GithubLinkInfo {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
owner: string;
|
|
33
|
+
repoName: string;
|
|
34
|
+
ref: string;
|
|
35
|
+
relativePath: string;
|
|
36
|
+
type: string;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export interface PasswordPromptInfo {
|
|
40
|
-
|
|
40
|
+
password: string;
|
|
41
41
|
}
|
package/src/cmd/utils.ts
CHANGED
|
@@ -1,88 +1,93 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import type { GithubLinkInfo, PackageInfo } from './type';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
5
|
+
export function GetPackageInfo(): PackageInfo {
|
|
6
|
+
const buffer = fs.readFileSync(path.resolve(__dirname, '../../package.json'));
|
|
7
|
+
return JSON.parse(buffer.toString());
|
|
8
|
+
}
|
|
9
9
|
|
|
10
10
|
export const GITHUB_ADDRESS = 'https://github.com/';
|
|
11
11
|
export const isHttpsLink = (link: string) => link.trim().startsWith(GITHUB_ADDRESS);
|
|
12
12
|
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
13
|
+
export function ParseGithubHttpsLink(httpsLink: string): GithubLinkInfo {
|
|
14
|
+
let nextLink = httpsLink.trim().slice(GITHUB_ADDRESS.length);
|
|
15
|
+
let index = nextLink.indexOf('/');
|
|
16
|
+
if (index === -1)
|
|
17
|
+
throw new Error('invalid github address.');
|
|
18
|
+
const owner = nextLink.slice(0, index);
|
|
19
|
+
nextLink = nextLink.slice(owner.length + 1);
|
|
20
|
+
index = nextLink.indexOf('/');
|
|
21
|
+
let repoName: string;
|
|
22
|
+
if (index === -1) {
|
|
23
|
+
repoName = nextLink.slice(0);
|
|
24
|
+
if (!repoName)
|
|
25
|
+
throw new Error('invalid github address.');
|
|
26
|
+
return {
|
|
27
|
+
owner,
|
|
28
|
+
repoName,
|
|
29
|
+
ref: 'master',
|
|
30
|
+
relativePath: '',
|
|
31
|
+
type: 'tree',
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
repoName = nextLink.slice(0, index);
|
|
35
|
+
nextLink = nextLink.slice(repoName.length + 1);
|
|
36
|
+
index = nextLink.indexOf('/');
|
|
37
|
+
let ref = 'master';
|
|
38
|
+
let relativePath = '';
|
|
39
|
+
let type = 'tree';
|
|
40
|
+
if (index === -1) {
|
|
41
|
+
if (repoName.endsWith('.git')) {
|
|
42
|
+
const lastIndex = -4;
|
|
43
|
+
repoName = repoName.slice(0, lastIndex);
|
|
31
44
|
}
|
|
32
|
-
|
|
33
|
-
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
type = nextLink.slice(0, index);
|
|
48
|
+
nextLink = nextLink.slice(type.length + 1);
|
|
34
49
|
index = nextLink.indexOf('/');
|
|
35
|
-
let ref = 'master';
|
|
36
|
-
let relativePath = '';
|
|
37
|
-
let type = 'tree';
|
|
38
50
|
if (index === -1) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
type = nextLink.slice(0, index);
|
|
45
|
-
nextLink = nextLink.slice(type.length + 1);
|
|
46
|
-
index = nextLink.indexOf('/');
|
|
47
|
-
if (index === -1) {
|
|
48
|
-
ref = nextLink.slice(0) || 'master';
|
|
49
|
-
} else {
|
|
50
|
-
ref = nextLink.slice(0, index);
|
|
51
|
-
relativePath = nextLink.slice(ref.length + 1);
|
|
52
|
-
}
|
|
51
|
+
ref = nextLink.slice(0) || 'master';
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
ref = nextLink.slice(0, index);
|
|
55
|
+
relativePath = nextLink.slice(ref.length + 1);
|
|
53
56
|
}
|
|
57
|
+
}
|
|
54
58
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
59
|
+
return {
|
|
60
|
+
owner,
|
|
61
|
+
repoName,
|
|
62
|
+
ref,
|
|
63
|
+
relativePath,
|
|
64
|
+
type,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
63
67
|
|
|
64
|
-
export const TextEllipsis = (text: string, maxLen: number): string => (text.length >= maxLen ? `${
|
|
68
|
+
export const TextEllipsis = (text: string, maxLen: number): string => (text.length >= maxLen ? `${text.slice(0, maxLen)}...` : text);
|
|
65
69
|
|
|
66
|
-
export
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
export function MakeDirs(dirs: string): void {
|
|
71
|
+
const mkdirs = (dir: string, callback?: () => void) => {
|
|
72
|
+
if (fs.existsSync(dir)) {
|
|
73
|
+
callback && callback();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
72
76
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
mkdirs(path.dirname(dir), () => {
|
|
78
|
+
fs.mkdirSync(dir);
|
|
79
|
+
callback && callback();
|
|
80
|
+
});
|
|
81
|
+
};
|
|
78
82
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
if (fs.existsSync(dirs))
|
|
84
|
+
return;
|
|
85
|
+
mkdirs(dirs);
|
|
86
|
+
}
|
|
82
87
|
|
|
83
|
-
export
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
88
|
+
export function AddExtraRandomQs(origin: string): string {
|
|
89
|
+
if (origin.includes('?')) {
|
|
90
|
+
return `${origin}&_t=${Math.random()}`;
|
|
91
|
+
}
|
|
92
|
+
return `${origin}?_t=${Math.random()}`;
|
|
93
|
+
}
|