@done-coding/cli-git 0.4.0 → 0.5.0-alpha.0
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/es/cli.mjs +2 -1
- package/es/clone-b1e0e99e.js +222 -0
- package/es/helpers.mjs +29 -0
- package/es/index-d59ae109.js +60 -0
- package/es/index.mjs +7 -6
- package/package.json +13 -2
- package/types/helpers-assets/done-coding.d.ts +2 -0
- package/types/helpers.d.ts +1 -0
- package/types/injectInfo.json.d.ts +1 -1
- package/types/utils/clone.d.ts +1 -0
- package/types/utils/index.d.ts +1 -0
- package/types/utils/question.d.ts +3 -2
- package/types/utils/types.d.ts +2 -0
- package/es/index-aab46de7.js +0 -248
package/es/cli.mjs
CHANGED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequest as $ } from "@done-coding/request-axios";
|
|
3
|
+
import C from "axios";
|
|
4
|
+
import { lookForParentTarget as S, log as a, decryptAES as I, encryptAES as P, xPrompts as m } from "@done-coding/cli-utils";
|
|
5
|
+
import f from "node:fs";
|
|
6
|
+
import d from "node:path";
|
|
7
|
+
import { execSync as k } from "node:child_process";
|
|
8
|
+
var v = /* @__PURE__ */ ((e) => (e.INIT = "init", e.CLONE = "clone", e))(v || {}), l = /* @__PURE__ */ ((e) => (e.GITHUB = "github", e.GITEE = "gitee", e))(l || {});
|
|
9
|
+
const w = 3e4, h = Math.random(), G = {
|
|
10
|
+
timeout: w,
|
|
11
|
+
getBusinessCode() {
|
|
12
|
+
return h;
|
|
13
|
+
},
|
|
14
|
+
getBusinessMsg(e) {
|
|
15
|
+
return e.statusText;
|
|
16
|
+
},
|
|
17
|
+
getBusinessData(e) {
|
|
18
|
+
return e.data;
|
|
19
|
+
},
|
|
20
|
+
businessSuccessCodeList: [h],
|
|
21
|
+
axios: C
|
|
22
|
+
}, y = $({
|
|
23
|
+
basePath: " https://gitee.com",
|
|
24
|
+
...G
|
|
25
|
+
}), U = $({
|
|
26
|
+
basePath: "https://api.github.com",
|
|
27
|
+
...G
|
|
28
|
+
}), B = ({
|
|
29
|
+
username: e
|
|
30
|
+
}) => y({
|
|
31
|
+
url: `/api/v5/users/${e}/repos`,
|
|
32
|
+
method: "GET"
|
|
33
|
+
}), F = ({
|
|
34
|
+
accessToken: e
|
|
35
|
+
}) => y({
|
|
36
|
+
url: "/api/v5/user/repos",
|
|
37
|
+
method: "GET",
|
|
38
|
+
params: {
|
|
39
|
+
access_token: e,
|
|
40
|
+
per_page: 100,
|
|
41
|
+
page: 1,
|
|
42
|
+
sort: "updated"
|
|
43
|
+
}
|
|
44
|
+
}), _ = ({
|
|
45
|
+
username: e
|
|
46
|
+
}) => U({
|
|
47
|
+
url: `/users/${e}/repos`,
|
|
48
|
+
method: "GET"
|
|
49
|
+
}), x = ({
|
|
50
|
+
accessToken: e
|
|
51
|
+
}) => U({
|
|
52
|
+
url: "/user/repos",
|
|
53
|
+
method: "GET",
|
|
54
|
+
headers: {
|
|
55
|
+
Authorization: `Bearer ${e}`
|
|
56
|
+
},
|
|
57
|
+
params: {
|
|
58
|
+
per_page: 100,
|
|
59
|
+
page: 1,
|
|
60
|
+
sort: "updated"
|
|
61
|
+
}
|
|
62
|
+
}), N = {
|
|
63
|
+
name: "@done-coding/cli-git",
|
|
64
|
+
version: "0.5.0-alpha.0",
|
|
65
|
+
description: "git跨平台操作命令行工具",
|
|
66
|
+
cliConfig: {
|
|
67
|
+
namespaceDir: ".done-coding",
|
|
68
|
+
moduleName: "git"
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
cliConfig: { namespaceDir: O, moduleName: R }
|
|
72
|
+
} = N, A = `./${O}/${R}`, E = (e) => `${A}/.${e}`, b = ({ platform: e, username: t }) => `${e}/${t}`, D = (e) => {
|
|
73
|
+
const { platform: t } = e, s = E(t), n = S(s, {
|
|
74
|
+
isFindFarthest: !1
|
|
75
|
+
});
|
|
76
|
+
if (!n) {
|
|
77
|
+
a.warn("配置文件不存在");
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const o = `${n}/${s}`, c = f.readFileSync(o, "utf-8"), i = b(e), u = I({ encryptedText: c, secretKey: i });
|
|
81
|
+
if (!u) {
|
|
82
|
+
a.warn("配置文件解密失败");
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
return JSON.parse(u);
|
|
86
|
+
}, V = ({
|
|
87
|
+
rootDir: e,
|
|
88
|
+
username: t,
|
|
89
|
+
platform: s,
|
|
90
|
+
accessToken: n
|
|
91
|
+
}) => {
|
|
92
|
+
const o = E(s), i = JSON.stringify({
|
|
93
|
+
accessToken: n
|
|
94
|
+
}), u = b({ platform: s, username: t }), p = P({ text: i, secretKey: u }), g = d.join(e, o);
|
|
95
|
+
f.mkdirSync(d.dirname(g), {
|
|
96
|
+
recursive: !0
|
|
97
|
+
}), f.writeFileSync(g, p, "utf-8"), a.success(`配置信息保存成功 ${g}`);
|
|
98
|
+
}, T = [
|
|
99
|
+
{ title: "GitHub", value: l.GITHUB },
|
|
100
|
+
{ title: "Gitee", value: l.GITEE }
|
|
101
|
+
], H = (e) => {
|
|
102
|
+
let t = 0;
|
|
103
|
+
if (e) {
|
|
104
|
+
const s = T.findIndex(
|
|
105
|
+
(n) => n.value === e
|
|
106
|
+
);
|
|
107
|
+
s >= 0 && (t = s);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
type: "select",
|
|
111
|
+
name: "platform",
|
|
112
|
+
message: "选择git平台",
|
|
113
|
+
choices: T,
|
|
114
|
+
initial: t
|
|
115
|
+
};
|
|
116
|
+
}, j = (e) => ({
|
|
117
|
+
type: "text",
|
|
118
|
+
name: "username",
|
|
119
|
+
message: "请输入用户名",
|
|
120
|
+
format: (t) => t.trim(),
|
|
121
|
+
validate: (t) => t.length > 0 || "用户名不能为空",
|
|
122
|
+
initial: e
|
|
123
|
+
}), W = {
|
|
124
|
+
type: "password",
|
|
125
|
+
name: "accessToken",
|
|
126
|
+
message: "请输入git access token",
|
|
127
|
+
format: (e) => e.trim(),
|
|
128
|
+
validate: (e) => e.length > 0 || "access token不能为空"
|
|
129
|
+
}, L = async ({
|
|
130
|
+
platform: e,
|
|
131
|
+
username: t
|
|
132
|
+
} = {}) => {
|
|
133
|
+
const s = {
|
|
134
|
+
platform: e,
|
|
135
|
+
username: t
|
|
136
|
+
};
|
|
137
|
+
e || (s.platform = (await m(H())).platform), t || (s.username = (await m(j())).username);
|
|
138
|
+
const { platform: n, username: o } = s;
|
|
139
|
+
let c = [];
|
|
140
|
+
const i = D({
|
|
141
|
+
username: o,
|
|
142
|
+
platform: n
|
|
143
|
+
});
|
|
144
|
+
let u = i == null ? void 0 : i.accessToken;
|
|
145
|
+
a.stage(`正在获取${o}的${n}仓库列表...`);
|
|
146
|
+
const p = {
|
|
147
|
+
username: o,
|
|
148
|
+
accessToken: u
|
|
149
|
+
};
|
|
150
|
+
switch (s.platform) {
|
|
151
|
+
case l.GITHUB: {
|
|
152
|
+
c = (await (p.accessToken ? x : _)(p)).data.map((r) => ({
|
|
153
|
+
name: r.name,
|
|
154
|
+
httpUrl: r.clone_url,
|
|
155
|
+
sshUrl: r.ssh_url,
|
|
156
|
+
description: r.description || ""
|
|
157
|
+
}));
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case l.GITEE: {
|
|
161
|
+
c = (await (p.accessToken ? F : B)(p)).data.map((r) => ({
|
|
162
|
+
name: r.name,
|
|
163
|
+
httpUrl: r.html_url,
|
|
164
|
+
sshUrl: r.ssh_url,
|
|
165
|
+
description: r.description || ""
|
|
166
|
+
}));
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
default:
|
|
170
|
+
return a.error(`未知平台${n}`), process.exit(1);
|
|
171
|
+
}
|
|
172
|
+
if (a.success(`获取${o}的${n}仓库列表成功`), c.length === 0) {
|
|
173
|
+
a.warn(`${o} 可获取${n}仓库列表为空`);
|
|
174
|
+
return;
|
|
175
|
+
} else
|
|
176
|
+
a.stage(`共${c.length}个仓库`);
|
|
177
|
+
const { repoUrl: g } = await m({
|
|
178
|
+
name: "repoUrl",
|
|
179
|
+
type: "select",
|
|
180
|
+
message: "选择仓库",
|
|
181
|
+
choices: c.map((r) => ({
|
|
182
|
+
title: `${r.name} ${r.description}`,
|
|
183
|
+
value: r.sshUrl
|
|
184
|
+
}))
|
|
185
|
+
});
|
|
186
|
+
return g;
|
|
187
|
+
}, X = () => ({
|
|
188
|
+
projectName: {
|
|
189
|
+
type: "string",
|
|
190
|
+
alias: "p",
|
|
191
|
+
describe: "项目名称"
|
|
192
|
+
}
|
|
193
|
+
}), Y = () => ({
|
|
194
|
+
platform: {
|
|
195
|
+
describe: "选择git平台",
|
|
196
|
+
type: "string",
|
|
197
|
+
choices: [l.GITHUB, l.GITEE]
|
|
198
|
+
},
|
|
199
|
+
username: {
|
|
200
|
+
describe: "git平台用户名",
|
|
201
|
+
type: "string"
|
|
202
|
+
}
|
|
203
|
+
}), Z = async (e) => {
|
|
204
|
+
const t = await L(e), { projectName: s } = e;
|
|
205
|
+
k(
|
|
206
|
+
`git clone ${t} ${s ? `${s} ` : ""}--depth=1`,
|
|
207
|
+
{ stdio: "inherit" }
|
|
208
|
+
), a.success(`克隆${t}成功`);
|
|
209
|
+
};
|
|
210
|
+
export {
|
|
211
|
+
l as G,
|
|
212
|
+
v as S,
|
|
213
|
+
j as a,
|
|
214
|
+
W as b,
|
|
215
|
+
Z as c,
|
|
216
|
+
X as d,
|
|
217
|
+
Y as e,
|
|
218
|
+
L as f,
|
|
219
|
+
H as g,
|
|
220
|
+
N as i,
|
|
221
|
+
V as s
|
|
222
|
+
};
|
package/es/helpers.mjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { xPrompts as t } from "@done-coding/cli-utils";
|
|
3
|
+
import { g as s, G as n, a, c as m } from "./clone-b1e0e99e.js";
|
|
4
|
+
import "@done-coding/request-axios";
|
|
5
|
+
import "axios";
|
|
6
|
+
import "node:fs";
|
|
7
|
+
import "node:path";
|
|
8
|
+
import "node:child_process";
|
|
9
|
+
const u = async (r) => {
|
|
10
|
+
console.log("克隆done-coding系列项目"), console.log("选择平台:");
|
|
11
|
+
const { platform: o } = await t(s(n.GITEE));
|
|
12
|
+
console.log("选择用户名:");
|
|
13
|
+
const { username: e } = await t(
|
|
14
|
+
a(
|
|
15
|
+
{
|
|
16
|
+
[n.GITHUB]: "done-coding",
|
|
17
|
+
[n.GITEE]: "justsosu"
|
|
18
|
+
}[o]
|
|
19
|
+
)
|
|
20
|
+
);
|
|
21
|
+
console.log("platform:", o), console.log("username:", e), await m({
|
|
22
|
+
platform: o,
|
|
23
|
+
username: e,
|
|
24
|
+
projectName: r
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
u as cloneDoneCodingSeries
|
|
29
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { getRootDirOptions as p, xPrompts as e, log as C, _curry as r, createSubcommand as c, createMainCommand as f } from "@done-coding/cli-utils";
|
|
3
|
+
import { g, a as I, b, s as h, S as t, c as N, d as O, e as w, i as T } from "./clone-b1e0e99e.js";
|
|
4
|
+
import $ from "node:os";
|
|
5
|
+
const y = () => p($.homedir()), E = async (o) => {
|
|
6
|
+
const { rootDir: n } = o, { platform: s } = await e(g()), { username: l } = await e(I()), { accessToken: u } = await e(b);
|
|
7
|
+
await h({
|
|
8
|
+
rootDir: n,
|
|
9
|
+
platform: s,
|
|
10
|
+
username: l,
|
|
11
|
+
accessToken: u
|
|
12
|
+
});
|
|
13
|
+
}, i = async (o, n) => {
|
|
14
|
+
switch (o) {
|
|
15
|
+
case t.INIT:
|
|
16
|
+
return E(n);
|
|
17
|
+
case t.CLONE:
|
|
18
|
+
return N(n);
|
|
19
|
+
default:
|
|
20
|
+
return C.error(`无效的命令: ${o}`), process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
}, {
|
|
23
|
+
version: x,
|
|
24
|
+
description: A,
|
|
25
|
+
cliConfig: { moduleName: a }
|
|
26
|
+
} = T, F = {
|
|
27
|
+
command: t.INIT,
|
|
28
|
+
describe: "初始化git配置文件",
|
|
29
|
+
options: y(),
|
|
30
|
+
handler: r(i)(
|
|
31
|
+
t.INIT
|
|
32
|
+
)
|
|
33
|
+
}, L = {
|
|
34
|
+
command: `${t.CLONE} <platform> <username>`,
|
|
35
|
+
describe: "从选择的git平台克隆代码",
|
|
36
|
+
options: O(),
|
|
37
|
+
positionals: w(),
|
|
38
|
+
handler: r(i)(
|
|
39
|
+
t.CLONE
|
|
40
|
+
)
|
|
41
|
+
}, m = {
|
|
42
|
+
describe: A,
|
|
43
|
+
version: x,
|
|
44
|
+
subcommands: [F, L].map(c),
|
|
45
|
+
demandCommandCount: 1
|
|
46
|
+
}, d = (o = !1) => {
|
|
47
|
+
const n = o ? a : void 0, s = `$0${o ? ` ${a}` : ""} <command> [options]`;
|
|
48
|
+
return { command: n, usage: s };
|
|
49
|
+
}, v = async () => f({
|
|
50
|
+
...m,
|
|
51
|
+
...d()
|
|
52
|
+
}), D = () => c({
|
|
53
|
+
...m,
|
|
54
|
+
...d(!0)
|
|
55
|
+
});
|
|
56
|
+
export {
|
|
57
|
+
D as a,
|
|
58
|
+
v as c,
|
|
59
|
+
i as h
|
|
60
|
+
};
|
package/es/index.mjs
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { a as s, h as c } from "./index-d59ae109.js";
|
|
3
|
+
import { c as l, f } from "./clone-b1e0e99e.js";
|
|
3
4
|
import "@done-coding/cli-utils";
|
|
5
|
+
import "node:os";
|
|
4
6
|
import "@done-coding/request-axios";
|
|
5
7
|
import "axios";
|
|
6
8
|
import "node:fs";
|
|
7
9
|
import "node:path";
|
|
8
10
|
import "node:child_process";
|
|
9
|
-
import "node:os";
|
|
10
11
|
export {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
l as cloneHandler,
|
|
13
|
+
s as crateAsSubcommand,
|
|
14
|
+
f as getTargetRepoUrl,
|
|
15
|
+
c as handler
|
|
15
16
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-git",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-alpha.0",
|
|
4
4
|
"description": "git跨平台操作命令行工具",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -12,6 +12,17 @@
|
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
14
|
"import": "./es/index.mjs"
|
|
15
|
+
},
|
|
16
|
+
"./helpers": {
|
|
17
|
+
"import": "./es/helpers.mjs",
|
|
18
|
+
"types": "./types/helpers.d.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"typesVersions": {
|
|
22
|
+
"*": {
|
|
23
|
+
"helpers": [
|
|
24
|
+
"./types/helpers.d.ts"
|
|
25
|
+
]
|
|
15
26
|
}
|
|
16
27
|
},
|
|
17
28
|
"files": [
|
|
@@ -56,5 +67,5 @@
|
|
|
56
67
|
"@done-coding/request-axios": "^1.1.1",
|
|
57
68
|
"axios": "^1.8.4"
|
|
58
69
|
},
|
|
59
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "5bed4b8d73ff879d9ad9be94f2078d5c61bcf7ed"
|
|
60
71
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './helpers-assets/done-coding';
|
package/types/utils/clone.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type CloneOptions } from "./types";
|
|
2
2
|
import type { CliInfo } from "@done-coding/cli-utils";
|
|
3
|
+
export declare const getCloneOptions: () => CliInfo["options"];
|
|
3
4
|
/** 获取克隆命令的位置参数 */
|
|
4
5
|
export declare const getClonePositionals: () => CliInfo["positionals"];
|
|
5
6
|
/** 克隆目标仓库 */
|
package/types/utils/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { PromptObject } from "@done-coding/cli-utils";
|
|
2
|
+
import { GitPlatformEnum } from "./types";
|
|
2
3
|
/** git平台选择表单 */
|
|
3
|
-
export declare const
|
|
4
|
+
export declare const getPlatformForm: (initialValue?: GitPlatformEnum) => PromptObject<string>;
|
|
4
5
|
/** git用户名表单 */
|
|
5
|
-
export declare const
|
|
6
|
+
export declare const getGitUsernameForm: (initial?: PromptObject["initial"]) => PromptObject<string>;
|
|
6
7
|
/** git access token表单 */
|
|
7
8
|
export declare const gitAccessTokenForm: PromptObject<string>;
|
package/types/utils/types.d.ts
CHANGED
package/es/index-aab46de7.js
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { lookForParentTarget as _, log as a, decryptAES as B, encryptAES as F, xPrompts as g, getRootDirOptions as x, _curry as $, createSubcommand as y, createMainCommand as A } from "@done-coding/cli-utils";
|
|
3
|
-
import { createRequest as I } from "@done-coding/request-axios";
|
|
4
|
-
import R from "axios";
|
|
5
|
-
import f from "node:fs";
|
|
6
|
-
import h from "node:path";
|
|
7
|
-
import { execSync as D } from "node:child_process";
|
|
8
|
-
import H from "node:os";
|
|
9
|
-
var l = /* @__PURE__ */ ((e) => (e.INIT = "init", e.CLONE = "clone", e))(l || {}), p = /* @__PURE__ */ ((e) => (e.GITHUB = "github", e.GITEE = "gitee", e))(p || {});
|
|
10
|
-
const L = 3e4, C = Math.random(), E = {
|
|
11
|
-
timeout: L,
|
|
12
|
-
getBusinessCode() {
|
|
13
|
-
return C;
|
|
14
|
-
},
|
|
15
|
-
getBusinessMsg(e) {
|
|
16
|
-
return e.statusText;
|
|
17
|
-
},
|
|
18
|
-
getBusinessData(e) {
|
|
19
|
-
return e.data;
|
|
20
|
-
},
|
|
21
|
-
businessSuccessCodeList: [C],
|
|
22
|
-
axios: R
|
|
23
|
-
}, U = I({
|
|
24
|
-
basePath: " https://gitee.com",
|
|
25
|
-
...E
|
|
26
|
-
}), b = I({
|
|
27
|
-
basePath: "https://api.github.com",
|
|
28
|
-
...E
|
|
29
|
-
}), M = ({
|
|
30
|
-
username: e
|
|
31
|
-
}) => U({
|
|
32
|
-
url: `/api/v5/users/${e}/repos`,
|
|
33
|
-
method: "GET"
|
|
34
|
-
}), q = ({
|
|
35
|
-
accessToken: e
|
|
36
|
-
}) => U({
|
|
37
|
-
url: "/api/v5/user/repos",
|
|
38
|
-
method: "GET",
|
|
39
|
-
params: {
|
|
40
|
-
access_token: e,
|
|
41
|
-
per_page: 100,
|
|
42
|
-
page: 1,
|
|
43
|
-
sort: "updated"
|
|
44
|
-
}
|
|
45
|
-
}), K = ({
|
|
46
|
-
username: e
|
|
47
|
-
}) => b({
|
|
48
|
-
url: `/users/${e}/repos`,
|
|
49
|
-
method: "GET"
|
|
50
|
-
}), j = ({
|
|
51
|
-
accessToken: e
|
|
52
|
-
}) => b({
|
|
53
|
-
url: "/user/repos",
|
|
54
|
-
method: "GET",
|
|
55
|
-
headers: {
|
|
56
|
-
Authorization: `Bearer ${e}`
|
|
57
|
-
},
|
|
58
|
-
params: {
|
|
59
|
-
per_page: 100,
|
|
60
|
-
page: 1,
|
|
61
|
-
sort: "updated"
|
|
62
|
-
}
|
|
63
|
-
}), G = {
|
|
64
|
-
name: "@done-coding/cli-git",
|
|
65
|
-
version: "0.4.0",
|
|
66
|
-
description: "git跨平台操作命令行工具",
|
|
67
|
-
cliConfig: {
|
|
68
|
-
namespaceDir: ".done-coding",
|
|
69
|
-
moduleName: "git"
|
|
70
|
-
}
|
|
71
|
-
}, {
|
|
72
|
-
cliConfig: { namespaceDir: J, moduleName: z }
|
|
73
|
-
} = G, V = `./${J}/${z}`, S = (e) => `${V}/.${e}`, w = ({ platform: e, username: t }) => `${e}/${t}`, Q = (e) => {
|
|
74
|
-
const { platform: t } = e, s = S(t), o = _(s, {
|
|
75
|
-
isFindFarthest: !1
|
|
76
|
-
});
|
|
77
|
-
if (!o) {
|
|
78
|
-
a.warn("配置文件不存在");
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const r = `${o}/${s}`, c = f.readFileSync(r, "utf-8"), i = w(e), u = B({ encryptedText: c, secretKey: i });
|
|
82
|
-
if (!u) {
|
|
83
|
-
a.warn("配置文件解密失败");
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
return JSON.parse(u);
|
|
87
|
-
}, W = ({
|
|
88
|
-
rootDir: e,
|
|
89
|
-
username: t,
|
|
90
|
-
platform: s,
|
|
91
|
-
accessToken: o
|
|
92
|
-
}) => {
|
|
93
|
-
const r = S(s), i = JSON.stringify({
|
|
94
|
-
accessToken: o
|
|
95
|
-
}), u = w({ platform: s, username: t }), m = F({ text: i, secretKey: u }), d = h.join(e, r);
|
|
96
|
-
f.mkdirSync(h.dirname(d), {
|
|
97
|
-
recursive: !0
|
|
98
|
-
}), f.writeFileSync(d, m, "utf-8"), a.success(`配置信息保存成功 ${d}`);
|
|
99
|
-
}, X = [
|
|
100
|
-
{ title: "GitHub", value: p.GITHUB },
|
|
101
|
-
{ title: "Gitee", value: p.GITEE }
|
|
102
|
-
], N = {
|
|
103
|
-
type: "select",
|
|
104
|
-
name: "platform",
|
|
105
|
-
message: "选择git平台",
|
|
106
|
-
choices: X
|
|
107
|
-
}, k = {
|
|
108
|
-
type: "text",
|
|
109
|
-
name: "username",
|
|
110
|
-
message: "请输入用户名",
|
|
111
|
-
format: (e) => e.trim(),
|
|
112
|
-
validate: (e) => e.length > 0 || "用户名不能为空"
|
|
113
|
-
}, Y = {
|
|
114
|
-
type: "password",
|
|
115
|
-
name: "accessToken",
|
|
116
|
-
message: "请输入git access token",
|
|
117
|
-
format: (e) => e.trim(),
|
|
118
|
-
validate: (e) => e.length > 0 || "access token不能为空"
|
|
119
|
-
}, Z = async ({
|
|
120
|
-
platform: e,
|
|
121
|
-
username: t
|
|
122
|
-
} = {}) => {
|
|
123
|
-
const s = {
|
|
124
|
-
platform: e,
|
|
125
|
-
username: t
|
|
126
|
-
};
|
|
127
|
-
e || (s.platform = (await g(N)).platform), t || (s.username = (await g(k)).username);
|
|
128
|
-
const { platform: o, username: r } = s;
|
|
129
|
-
let c = [];
|
|
130
|
-
const i = Q({
|
|
131
|
-
username: r,
|
|
132
|
-
platform: o
|
|
133
|
-
});
|
|
134
|
-
let u = i == null ? void 0 : i.accessToken;
|
|
135
|
-
a.stage(`正在获取${r}的${o}仓库列表...`);
|
|
136
|
-
const m = {
|
|
137
|
-
username: r,
|
|
138
|
-
accessToken: u
|
|
139
|
-
};
|
|
140
|
-
switch (s.platform) {
|
|
141
|
-
case p.GITHUB: {
|
|
142
|
-
c = (await (m.accessToken ? j : K)(m)).data.map((n) => ({
|
|
143
|
-
name: n.name,
|
|
144
|
-
httpUrl: n.clone_url,
|
|
145
|
-
sshUrl: n.ssh_url,
|
|
146
|
-
description: n.description || ""
|
|
147
|
-
}));
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
case p.GITEE: {
|
|
151
|
-
c = (await (m.accessToken ? q : M)(m)).data.map((n) => ({
|
|
152
|
-
name: n.name,
|
|
153
|
-
httpUrl: n.html_url,
|
|
154
|
-
sshUrl: n.ssh_url,
|
|
155
|
-
description: n.description || ""
|
|
156
|
-
}));
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
default:
|
|
160
|
-
return a.error(`未知平台${o}`), process.exit(1);
|
|
161
|
-
}
|
|
162
|
-
if (a.success(`获取${r}的${o}仓库列表成功`), c.length === 0) {
|
|
163
|
-
a.warn(`${r} 可获取${o}仓库列表为空`);
|
|
164
|
-
return;
|
|
165
|
-
} else
|
|
166
|
-
a.stage(`共${c.length}个仓库`);
|
|
167
|
-
const { repoUrl: d } = await g({
|
|
168
|
-
name: "repoUrl",
|
|
169
|
-
type: "select",
|
|
170
|
-
message: "选择仓库",
|
|
171
|
-
choices: c.map((n) => ({
|
|
172
|
-
title: `${n.name} ${n.description}`,
|
|
173
|
-
value: n.sshUrl
|
|
174
|
-
}))
|
|
175
|
-
});
|
|
176
|
-
return d;
|
|
177
|
-
}, ee = () => x(H.homedir()), te = async (e) => {
|
|
178
|
-
const { rootDir: t } = e, { platform: s } = await g(N), { username: o } = await g(k), { accessToken: r } = await g(Y);
|
|
179
|
-
await W({
|
|
180
|
-
rootDir: t,
|
|
181
|
-
platform: s,
|
|
182
|
-
username: o,
|
|
183
|
-
accessToken: r
|
|
184
|
-
});
|
|
185
|
-
}, se = () => ({
|
|
186
|
-
platform: {
|
|
187
|
-
describe: "选择git平台",
|
|
188
|
-
type: "string",
|
|
189
|
-
choices: [p.GITHUB, p.GITEE]
|
|
190
|
-
},
|
|
191
|
-
username: {
|
|
192
|
-
describe: "git平台用户名",
|
|
193
|
-
type: "string"
|
|
194
|
-
}
|
|
195
|
-
}), ne = async (e) => {
|
|
196
|
-
const t = await Z(e);
|
|
197
|
-
D(`git clone ${t}`, {
|
|
198
|
-
stdio: "inherit"
|
|
199
|
-
}), a.success(`克隆${t}成功`);
|
|
200
|
-
}, P = async (e, t) => {
|
|
201
|
-
switch (e) {
|
|
202
|
-
case l.INIT:
|
|
203
|
-
return te(t);
|
|
204
|
-
case l.CLONE:
|
|
205
|
-
return ne(t);
|
|
206
|
-
default:
|
|
207
|
-
return a.error(`无效的命令: ${e}`), process.exit(1);
|
|
208
|
-
}
|
|
209
|
-
}, {
|
|
210
|
-
version: oe,
|
|
211
|
-
description: re,
|
|
212
|
-
cliConfig: { moduleName: T }
|
|
213
|
-
} = G, ae = {
|
|
214
|
-
command: l.INIT,
|
|
215
|
-
describe: "初始化git配置文件",
|
|
216
|
-
options: ee(),
|
|
217
|
-
handler: $(P)(
|
|
218
|
-
l.INIT
|
|
219
|
-
)
|
|
220
|
-
}, ce = {
|
|
221
|
-
command: `${l.CLONE} <platform> <username>`,
|
|
222
|
-
describe: "从选择的git平台克隆代码",
|
|
223
|
-
positionals: se(),
|
|
224
|
-
handler: $(P)(
|
|
225
|
-
l.CLONE
|
|
226
|
-
)
|
|
227
|
-
}, v = {
|
|
228
|
-
describe: re,
|
|
229
|
-
version: oe,
|
|
230
|
-
subcommands: [ae, ce].map(y),
|
|
231
|
-
demandCommandCount: 1
|
|
232
|
-
}, O = (e = !1) => {
|
|
233
|
-
const t = e ? T : void 0, s = `$0${e ? ` ${T}` : ""} <command> [options]`;
|
|
234
|
-
return { command: t, usage: s };
|
|
235
|
-
}, fe = async () => A({
|
|
236
|
-
...v,
|
|
237
|
-
...O()
|
|
238
|
-
}), he = () => y({
|
|
239
|
-
...v,
|
|
240
|
-
...O(!0)
|
|
241
|
-
});
|
|
242
|
-
export {
|
|
243
|
-
he as a,
|
|
244
|
-
ne as b,
|
|
245
|
-
fe as c,
|
|
246
|
-
Z as g,
|
|
247
|
-
P as h
|
|
248
|
-
};
|