@done-coding/cli-git 0.2.1 → 0.2.3-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 CHANGED
@@ -1,10 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { c as r } from "./index-e8035171.js";
3
- import "chalk";
2
+ import { c as r } from "./index-ac221b4b.js";
3
+ import "@done-coding/cli-utils";
4
4
  import "@done-coding/request-axios";
5
5
  import "axios";
6
- import "prompts";
7
- import "@done-coding/node-tools";
8
6
  import "node:fs";
9
7
  import "node:path";
10
8
  import "node:child_process";
@@ -0,0 +1,192 @@
1
+ #!/usr/bin/env node
2
+ import { lookForParentTarget as G, log as r, decryptAES as v, xPrompts as g } from "@done-coding/cli-utils";
3
+ import { createRequest as C } from "@done-coding/request-axios";
4
+ import S from "axios";
5
+ import w from "node:fs";
6
+ import "node:path";
7
+ import { execSync as x } from "node:child_process";
8
+ import B from "yargs";
9
+ import { hideBin as I } from "yargs/helpers";
10
+ import N from "lodash.curry";
11
+ var l = /* @__PURE__ */ ((e) => (e.CLONE = "clone", e))(l || {}), c = /* @__PURE__ */ ((e) => (e.GITHUB = "github", e.GITEE = "gitee", e))(c || {});
12
+ const P = 1e4, f = Math.random(), $ = {
13
+ timeout: P,
14
+ getBusinessCode() {
15
+ return f;
16
+ },
17
+ getBusinessMsg(e) {
18
+ return e.statusText;
19
+ },
20
+ getBusinessData(e) {
21
+ return e.data;
22
+ },
23
+ businessSuccessCodeList: [f],
24
+ axios: S
25
+ }, b = C({
26
+ basePath: " https://gitee.com",
27
+ ...$
28
+ }), _ = C({
29
+ basePath: "https://api.github.com",
30
+ ...$
31
+ }), O = ({
32
+ username: e
33
+ }) => b({
34
+ url: `/api/v5/users/${e}/repos`,
35
+ method: "GET"
36
+ }), D = ({
37
+ accessToken: e
38
+ }) => b({
39
+ url: "/api/v5/user/repos",
40
+ method: "GET",
41
+ params: {
42
+ access_token: e,
43
+ per_page: 100,
44
+ page: 1,
45
+ sort: "updated"
46
+ }
47
+ }), R = ({
48
+ username: e
49
+ }) => _({
50
+ url: `/users/${e}/repos`,
51
+ method: "GET"
52
+ }), p = {
53
+ version: "0.2.3-alpha.0",
54
+ name: "@done-coding/cli-git",
55
+ description: "git跨平台操作命令行工具",
56
+ cliConfig: {
57
+ namespaceDir: ".done-coding",
58
+ moduleName: "git"
59
+ }
60
+ }, { namespaceDir: k, moduleName: H } = p.cliConfig, L = `${k}/${H}`, F = (e) => `${L}/.${e}`, q = ({
61
+ secretKey: e,
62
+ platform: s
63
+ }) => {
64
+ const n = F(s), o = G(n);
65
+ if (!o) {
66
+ r.warn("配置文件不存在");
67
+ return;
68
+ }
69
+ const a = `${o}/${n}`, i = w.readFileSync(a, "utf-8"), m = v({ encryptedText: i, secretKey: e });
70
+ if (!m) {
71
+ r.warn("配置文件解密失败");
72
+ return;
73
+ }
74
+ return JSON.parse(m);
75
+ }, M = async ({
76
+ platform: e,
77
+ username: s
78
+ } = {}) => {
79
+ const n = {
80
+ platform: e,
81
+ username: s
82
+ };
83
+ if (!e) {
84
+ const t = [
85
+ { title: "GitHub", value: c.GITHUB },
86
+ { title: "Gitee", value: c.GITEE }
87
+ ];
88
+ n.platform = (await g({
89
+ type: "select",
90
+ name: "platform",
91
+ message: "选择git平台",
92
+ choices: t
93
+ })).platform;
94
+ }
95
+ s || (n.username = (await g({
96
+ type: "text",
97
+ name: "username",
98
+ message: "请输入用户名",
99
+ format: (t) => t.trim(),
100
+ validate: (t) => t.length > 0 || "用户名不能为空"
101
+ })).username);
102
+ const { platform: o, username: a } = n;
103
+ let i = [];
104
+ const m = q({
105
+ secretKey: a,
106
+ platform: o
107
+ });
108
+ let d = m == null ? void 0 : m.accessToken;
109
+ r.stage(`正在获取${a}的${o}仓库列表...`);
110
+ const u = {
111
+ username: a,
112
+ accessToken: d
113
+ };
114
+ switch (n.platform) {
115
+ case c.GITHUB: {
116
+ i = (await R(u)).data.map((t) => ({
117
+ name: t.name,
118
+ httpUrl: t.clone_url,
119
+ sshUrl: t.ssh_url,
120
+ description: t.description || ""
121
+ }));
122
+ break;
123
+ }
124
+ case c.GITEE: {
125
+ i = (await (u.accessToken ? D : O)(u)).data.map((t) => ({
126
+ name: t.name,
127
+ httpUrl: t.html_url,
128
+ sshUrl: t.ssh_url,
129
+ description: t.description || ""
130
+ }));
131
+ break;
132
+ }
133
+ default:
134
+ return r.error(`未知平台${o}`), process.exit(1);
135
+ }
136
+ if (r.success(`获取${a}的${o}仓库列表成功`), i.length === 0) {
137
+ r.warn(`${a} 可获取${o}仓库列表为空`);
138
+ return;
139
+ } else
140
+ r.stage(`共${i.length}个仓库`);
141
+ const { repoUrl: E } = await g({
142
+ name: "repoUrl",
143
+ type: "select",
144
+ message: "选择仓库",
145
+ choices: i.map((t) => ({
146
+ title: `${t.name} ${t.description}`,
147
+ value: t.sshUrl
148
+ }))
149
+ });
150
+ return E;
151
+ }, A = async (e) => {
152
+ const s = await M(e);
153
+ x(`git clone ${s} 1>&2`), r.success(`克隆${s}成功`);
154
+ }, j = async (e, s) => e === l.CLONE ? A(s) : (r.error(`无效的命令: ${e}`), process.exit(1)), U = async (e) => {
155
+ }, T = p.cliConfig.moduleName, J = (e, s) => {
156
+ e ? r.error(e) : r.error(s.message), process.exit(1);
157
+ }, K = p.description, z = `Usage: $0 ${T} <command> [options]`, Q = "Usage: $0 <command> [options]", V = {
158
+ command: `${l.CLONE} <platform> <username>`,
159
+ describe: "从选择的git平台克隆代码",
160
+ builder: (e) => e.positional("platform", {
161
+ describe: "选择git平台",
162
+ type: "string",
163
+ choices: [c.GITHUB, c.GITEE]
164
+ }).positional("username", {
165
+ describe: "git平台用户名",
166
+ type: "string"
167
+ }),
168
+ /** @ts-ignore */
169
+ async handler(e) {
170
+ return await N(j)(l.CLONE)(
171
+ e
172
+ ), process.exit(0);
173
+ }
174
+ }, h = (e) => e.command(V).demandCommand(1), y = (e, s = !1) => s ? h(e.strict().usage(z)) : h(
175
+ e.strict().usage(Q).help("help").version(p.version).alias("v", "version").alias("h", "help")
176
+ ).fail(J).argv, W = (e) => y(e, !0), ae = {
177
+ command: T,
178
+ describe: K,
179
+ builder: W,
180
+ handler: U
181
+ }, ie = async () => {
182
+ const e = B(I(process.argv));
183
+ return await y(e), U();
184
+ };
185
+ export {
186
+ ae as a,
187
+ M as b,
188
+ ie as c,
189
+ A as d,
190
+ V as g,
191
+ U as h
192
+ };
package/es/index.mjs CHANGED
@@ -1,10 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { a as C, b, d as h, g as c, h as f } from "./index-e8035171.js";
3
- import "chalk";
2
+ import { a as g, b as l, d as C, g as b, h } from "./index-ac221b4b.js";
3
+ import "@done-coding/cli-utils";
4
4
  import "@done-coding/request-axios";
5
5
  import "axios";
6
- import "prompts";
7
- import "@done-coding/node-tools";
8
6
  import "node:fs";
9
7
  import "node:path";
10
8
  import "node:child_process";
@@ -12,9 +10,9 @@ import "yargs";
12
10
  import "yargs/helpers";
13
11
  import "lodash.curry";
14
12
  export {
15
- C as command,
16
- b as getTargetRepoUrl,
17
- h as gitClone,
18
- c as gitCloneCommand,
19
- f as handler
13
+ g as command,
14
+ l as getTargetRepoUrl,
15
+ C as gitClone,
16
+ b as gitCloneCommand,
17
+ h as handler
20
18
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-git",
3
- "version": "0.2.1",
3
+ "version": "0.2.3-alpha.0",
4
4
  "description": "git跨平台操作命令行工具",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -41,10 +41,9 @@
41
41
  "license": "MIT",
42
42
  "sideEffects": false,
43
43
  "devDependencies": {
44
- "@done-coding/cli-inject": "^0.4.5",
44
+ "@done-coding/cli-inject": "^0.4.7-alpha.0",
45
45
  "@types/lodash.curry": "^4.1.8",
46
46
  "@types/node": "^16.0.0",
47
- "@types/prompts": "^2.4.6",
48
47
  "@types/yargs": "^17.0.28",
49
48
  "rimraf": "^6.0.1",
50
49
  "typescript": "^5.2.2",
@@ -55,13 +54,11 @@
55
54
  "node": ">=16.0.0"
56
55
  },
57
56
  "dependencies": {
58
- "@done-coding/node-tools": "^0.2.0",
57
+ "@done-coding/cli-utils": "^0.2.2-alpha.0",
59
58
  "@done-coding/request-axios": "^1.1.1",
60
59
  "axios": "^1.8.4",
61
- "chalk": "^5.3.0",
62
60
  "lodash.curry": "^4.1.1",
63
- "prompts": "^2.4.2",
64
61
  "yargs": "^17.7.2"
65
62
  },
66
- "gitHead": "0dde53af70143475f5149714152d714802f846f8"
63
+ "gitHead": "2e59e86ee192e023138e7475f4abbb5e7c42b29e"
67
64
  }
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- "version": "0.2.1",
2
+ "version": "0.2.3-alpha.0",
3
3
  "name": "@done-coding/cli-git",
4
4
  "description": "git跨平台操作命令行工具",
5
5
  "cliConfig": {
@@ -1,197 +0,0 @@
1
- #!/usr/bin/env node
2
- import s from "chalk";
3
- import { createRequest as C } from "@done-coding/request-axios";
4
- import S from "axios";
5
- import g from "prompts";
6
- import { lookForParentTarget as v, decryptAES as w, onPromptFormStateForSigint as d } from "@done-coding/node-tools";
7
- import B from "node:fs";
8
- import "node:path";
9
- import { execSync as I } from "node:child_process";
10
- import N from "yargs";
11
- import { hideBin as x } from "yargs/helpers";
12
- import P from "lodash.curry";
13
- var m = /* @__PURE__ */ ((e) => (e.CLONE = "clone", e))(m || {}), i = /* @__PURE__ */ ((e) => (e.GITHUB = "github", e.GITEE = "gitee", e))(i || {});
14
- const _ = 1e4, h = Math.random(), $ = {
15
- timeout: _,
16
- getBusinessCode() {
17
- return h;
18
- },
19
- getBusinessMsg(e) {
20
- return e.statusText;
21
- },
22
- getBusinessData(e) {
23
- return e.data;
24
- },
25
- businessSuccessCodeList: [h],
26
- axios: S
27
- }, U = C({
28
- basePath: " https://gitee.com",
29
- ...$
30
- }), O = C({
31
- basePath: "https://api.github.com",
32
- ...$
33
- }), k = ({
34
- username: e
35
- }) => U({
36
- url: `/api/v5/users/${e}/repos`,
37
- method: "GET"
38
- }), D = ({
39
- accessToken: e
40
- }) => U({
41
- url: "/api/v5/user/repos",
42
- method: "GET",
43
- params: {
44
- access_token: e,
45
- per_page: 100,
46
- page: 1,
47
- sort: "updated"
48
- }
49
- }), R = ({
50
- username: e
51
- }) => O({
52
- url: `/users/${e}/repos`,
53
- method: "GET"
54
- }), p = {
55
- version: "0.2.1",
56
- name: "@done-coding/cli-git",
57
- description: "git跨平台操作命令行工具",
58
- cliConfig: {
59
- namespaceDir: ".done-coding",
60
- moduleName: "git"
61
- }
62
- }, { namespaceDir: H, moduleName: F } = p.cliConfig, L = `${H}/${F}`, q = (e) => `${L}/.${e}`, M = ({
63
- secretKey: e,
64
- platform: o
65
- }) => {
66
- const n = q(o), r = v(n);
67
- if (!r) {
68
- console.log(s.yellow("配置文件不存在"));
69
- return;
70
- }
71
- const a = `${r}/${n}`, c = B.readFileSync(a, "utf-8"), l = w({ encryptedText: c, secretKey: e });
72
- if (!l) {
73
- console.log(s.yellow("配置文件解密失败"));
74
- return;
75
- }
76
- return JSON.parse(l);
77
- }, A = async ({
78
- platform: e,
79
- username: o
80
- } = {}) => {
81
- const n = {
82
- platform: e,
83
- username: o
84
- };
85
- if (!e) {
86
- const t = [
87
- { title: "GitHub", value: i.GITHUB },
88
- { title: "Gitee", value: i.GITEE }
89
- ];
90
- n.platform = (await g({
91
- type: "select",
92
- name: "platform",
93
- message: "选择git平台",
94
- choices: t,
95
- onState: d
96
- })).platform;
97
- }
98
- o || (n.username = (await g({
99
- type: "text",
100
- name: "username",
101
- message: "请输入用户名",
102
- format: (t) => t.trim(),
103
- validate: (t) => t.length > 0 || "用户名不能为空",
104
- onState: d
105
- })).username);
106
- const { platform: r, username: a } = n;
107
- let c = [];
108
- const l = M({
109
- secretKey: a,
110
- platform: r
111
- });
112
- let f = l == null ? void 0 : l.accessToken;
113
- console.log(s.blue(`正在获取${a}的${r}仓库列表...`));
114
- const u = {
115
- username: a,
116
- accessToken: f
117
- };
118
- switch (n.platform) {
119
- case i.GITHUB: {
120
- c = (await R(u)).data.map((t) => ({
121
- name: t.name,
122
- httpUrl: t.clone_url,
123
- sshUrl: t.ssh_url,
124
- description: t.description || ""
125
- }));
126
- break;
127
- }
128
- case i.GITEE: {
129
- c = (await (u.accessToken ? D : k)(u)).data.map((t) => ({
130
- name: t.name,
131
- httpUrl: t.html_url,
132
- sshUrl: t.ssh_url,
133
- description: t.description || ""
134
- }));
135
- break;
136
- }
137
- default:
138
- return console.log(s.red(`未知平台${r}`)), process.exit(1);
139
- }
140
- if (console.log(s.green(`获取${a}的${r}仓库列表成功`)), c.length === 0) {
141
- console.log(s.yellow(`${a} 可获取${r}仓库列表为空`));
142
- return;
143
- } else
144
- console.log(s.blue(`共${c.length}个仓库`));
145
- const { repoUrl: G } = await g({
146
- name: "repoUrl",
147
- type: "select",
148
- message: "选择仓库",
149
- choices: c.map((t) => ({
150
- title: `${t.name} ${t.description}`,
151
- value: t.sshUrl
152
- })),
153
- onState: d
154
- });
155
- return G;
156
- }, j = async (e) => {
157
- const o = await A(e);
158
- I(`git clone ${o} 1>&2`), console.log(s.green(`克隆${o}成功`));
159
- }, J = async (e, o) => e === m.CLONE ? j(o) : (console.log(s.red(`无效的命令: ${e}`)), process.exit(1)), y = async (e) => {
160
- }, T = p.cliConfig.moduleName, K = (e, o) => {
161
- console.log(e ? s.red(e) : s.red(o.message)), process.exit(1);
162
- }, z = p.description, Q = `Usage: $0 ${T} <command> [options]`, V = "Usage: $0 <command> [options]", W = {
163
- command: `${m.CLONE} <platform> <username>`,
164
- describe: "从选择的git平台克隆代码",
165
- builder: (e) => e.positional("platform", {
166
- describe: "选择git平台",
167
- type: "string",
168
- choices: [i.GITHUB, i.GITEE]
169
- }).positional("username", {
170
- describe: "git平台用户名",
171
- type: "string"
172
- }),
173
- /** @ts-ignore */
174
- async handler(e) {
175
- return await P(J)(m.CLONE)(
176
- e
177
- ), process.exit(0);
178
- }
179
- }, b = (e) => e.command(W).demandCommand(1), E = (e, o = !1) => o ? b(e.strict().usage(Q)) : b(
180
- e.strict().usage(V).help("help").version(p.version).alias("v", "version").alias("h", "help")
181
- ).fail(K).argv, X = (e) => E(e, !0), le = {
182
- command: T,
183
- describe: z,
184
- builder: X,
185
- handler: y
186
- }, me = async () => {
187
- const e = N(x(process.argv));
188
- return await E(e), y();
189
- };
190
- export {
191
- le as a,
192
- A as b,
193
- me as c,
194
- j as d,
195
- W as g,
196
- y as h
197
- };