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