@done-coding/cli-git 0.1.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/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # @done-coding/cli-git
2
+
3
+ ```
4
+ git跨平台操作命令行工具
5
+ ```
6
+
7
+ ## 使用
8
+
9
+ ``` bash
10
+ npm install @done-coding/cli-git
11
+ ```
package/es/cli.mjs ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ import { c as r } from "./index-aab45cf7.js";
3
+ import "chalk";
4
+ import "@done-coding/request-axios";
5
+ import "axios";
6
+ import "prompts";
7
+ import "@done-coding/node-tools";
8
+ import "node:fs";
9
+ import "node:path";
10
+ import "node:child_process";
11
+ import "yargs";
12
+ import "yargs/helpers";
13
+ import "lodash.curry";
14
+ r();
@@ -0,0 +1,189 @@
1
+ #!/usr/bin/env node
2
+ import s from "chalk";
3
+ import { createRequest as $ } from "@done-coding/request-axios";
4
+ import v from "axios";
5
+ import g from "prompts";
6
+ import { lookForParentTarget as G, decryptAES as S } from "@done-coding/node-tools";
7
+ import w from "node:fs";
8
+ import "node:path";
9
+ import { execSync as B } from "node:child_process";
10
+ import I from "yargs";
11
+ import { hideBin as N } from "yargs/helpers";
12
+ import _ 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 x = 1e4, f = Math.random(), b = {
15
+ timeout: x,
16
+ getBusinessCode() {
17
+ return f;
18
+ },
19
+ getBusinessMsg(e) {
20
+ return e.statusText;
21
+ },
22
+ getBusinessData(e) {
23
+ return e.data;
24
+ },
25
+ businessSuccessCodeList: [f],
26
+ axios: v
27
+ }, U = $({
28
+ basePath: " https://gitee.com",
29
+ ...b
30
+ }), O = $({
31
+ basePath: "https://api.github.com",
32
+ ...b
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
+ }), P = ({
50
+ username: e
51
+ }) => O({
52
+ url: `/users/${e}/repos`,
53
+ method: "GET"
54
+ }), u = {
55
+ version: "0.1.0",
56
+ name: "@done-coding/cli-git",
57
+ description: "git跨平台操作命令行工具",
58
+ cliConfig: {
59
+ namespaceDir: ".done-coding",
60
+ moduleName: "git"
61
+ }
62
+ }, { namespaceDir: R, moduleName: H } = u.cliConfig, L = `${R}/${H}`, F = (e) => `${L}/.${e}`, q = ({
63
+ secretKey: e,
64
+ platform: o
65
+ }) => {
66
+ const n = F(o), r = G(n);
67
+ if (!r) {
68
+ console.log(s.yellow("配置文件不存在"));
69
+ return;
70
+ }
71
+ const a = `${r}/${n}`, c = w.readFileSync(a, "utf-8"), l = S({ encryptedText: c, secretKey: e });
72
+ if (!l) {
73
+ console.log(s.yellow("配置文件解密失败"));
74
+ return;
75
+ }
76
+ return JSON.parse(l);
77
+ }, M = async ({
78
+ platform: e,
79
+ username: o
80
+ } = {}) => {
81
+ const n = {
82
+ platform: e,
83
+ username: o
84
+ };
85
+ e || (n.platform = (await g({
86
+ type: "select",
87
+ name: "platform",
88
+ message: "选择git平台",
89
+ choices: [
90
+ {
91
+ title: "Github",
92
+ value: i.GITHUB
93
+ },
94
+ {
95
+ title: "Gitee",
96
+ value: i.GITEE
97
+ }
98
+ ],
99
+ validate: (t) => t === void 0 ? "请选择git平台" : !0
100
+ })).platform), o || (n.username = (await g({
101
+ type: "text",
102
+ name: "username",
103
+ message: "请输入用户名",
104
+ validate: (t) => t.trim() === "" ? "用户名不能为空" : !0
105
+ })).username);
106
+ const { platform: r, username: a } = n;
107
+ let c = [];
108
+ const l = q({
109
+ secretKey: a,
110
+ platform: r
111
+ });
112
+ let d = l == null ? void 0 : l.accessToken;
113
+ console.log(s.blue(`正在获取${a}的${r}仓库列表...`));
114
+ const p = {
115
+ username: a,
116
+ accessToken: d
117
+ };
118
+ switch (n.platform) {
119
+ case i.GITHUB: {
120
+ c = (await P(p)).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 (p.accessToken ? D : k)(p)).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: E } = 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
+ });
154
+ return E;
155
+ }, A = async (e) => {
156
+ const o = await M(e);
157
+ B(`git clone ${o} 1>&2`), console.log(s.green(`克隆${o}成功`));
158
+ }, j = async (e, o) => (console.log("com", o), e === m.CLONE ? A(o) : (console.log(s.red(`无效的命令: ${e}`)), process.exit(1))), y = async (e) => {
159
+ }, C = u.cliConfig.moduleName, J = (e, o) => {
160
+ console.log(e ? s.red(e) : s.red(o.message)), process.exit(1);
161
+ }, K = u.description, z = `Usage: $0 ${C} <command> [options]`, Q = "Usage: $0 <command> [options]", h = (e) => e.command({
162
+ command: `${m.CLONE} <platform> <username>`,
163
+ describe: "从一个某个git平台克隆代码",
164
+ builder: (o) => o.positional("platform", {
165
+ describe: "git平台",
166
+ type: "string",
167
+ choices: [i.GITHUB, i.GITEE]
168
+ }).positional("username", {
169
+ describe: "git平台用户名",
170
+ type: "string"
171
+ }),
172
+ handler: _(j)(m.CLONE)
173
+ }).demandCommand(1), T = (e, o = !1) => o ? h(e.strict().usage(z)) : h(
174
+ e.strict().usage(Q).help("help").version(u.version).alias("v", "version").alias("h", "help")
175
+ ).fail(J).argv, V = (e) => T(e, !0), ce = {
176
+ command: C,
177
+ describe: K,
178
+ builder: V,
179
+ handler: y
180
+ }, ie = async () => {
181
+ const e = I(N(process.argv));
182
+ return await T(e), y();
183
+ };
184
+ export {
185
+ ce as a,
186
+ ie as c,
187
+ M as g,
188
+ y as h
189
+ };
package/es/index.mjs ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ import { a as l, g as b, h as c } from "./index-aab45cf7.js";
3
+ import "chalk";
4
+ import "@done-coding/request-axios";
5
+ import "axios";
6
+ import "prompts";
7
+ import "@done-coding/node-tools";
8
+ import "node:fs";
9
+ import "node:path";
10
+ import "node:child_process";
11
+ import "yargs";
12
+ import "yargs/helpers";
13
+ import "lodash.curry";
14
+ export {
15
+ l as command,
16
+ b as getTargetRepoUrl,
17
+ c as handler
18
+ };
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@done-coding/cli-git",
3
+ "version": "0.1.0",
4
+ "description": "git跨平台操作命令行工具",
5
+ "private": false,
6
+ "module": "es/index.mjs",
7
+ "type": "module",
8
+ "types": "types/index.d.ts",
9
+ "bin": {
10
+ "dc-git": "es/cli.mjs"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "import": "./es/index.mjs"
15
+ }
16
+ },
17
+ "files": [
18
+ "es",
19
+ "lib",
20
+ "types",
21
+ "gif"
22
+ ],
23
+ "scripts": {
24
+ "clean": "rimraf es lib types",
25
+ "predev": "pnpm run clean",
26
+ "dev": "vite build --watch",
27
+ "prebuild": "pnpm run clean",
28
+ "build": "vite build",
29
+ "prepack": "pnpm build"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://gitee.com/justsosu/done-coding-cli.git",
34
+ "directory": "packages/git"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public",
38
+ "registry": "https://registry.npmjs.org/"
39
+ },
40
+ "author": "JustSoSu",
41
+ "license": "MIT",
42
+ "sideEffects": false,
43
+ "devDependencies": {
44
+ "@done-coding/cli-inject": "^0.4.5",
45
+ "@types/lodash.curry": "^4.1.8",
46
+ "@types/node": "^16.0.0",
47
+ "@types/prompts": "^2.4.6",
48
+ "@types/yargs": "^17.0.28",
49
+ "rimraf": "^6.0.1",
50
+ "typescript": "^5.2.2",
51
+ "vite": "^4.4.11",
52
+ "vite-plugin-dts": "^3.6.0"
53
+ },
54
+ "engines": {
55
+ "node": ">=16.0.0"
56
+ },
57
+ "dependencies": {
58
+ "@done-coding/node-tools": "^0.1.0",
59
+ "@done-coding/request-axios": "^1.1.1",
60
+ "axios": "^1.8.4",
61
+ "chalk": "^5.3.0",
62
+ "lodash.curry": "^4.1.1",
63
+ "prompts": "^2.4.2",
64
+ "yargs": "^17.7.2"
65
+ },
66
+ "gitHead": "465ac238437ab8bd3803c5e6fe8ac5a30bc445f3"
67
+ }
@@ -0,0 +1,5 @@
1
+ /** gitee 请求 */
2
+ declare const giteeRequest: <D>(apiConfig: import("@done-coding/request-axios").ApiConfig<import("axios").AxiosRequestConfig<any>>, debug?: boolean | undefined) => Promise<import("@done-coding/request-axios").RequestResult<D>>;
3
+ /** github 请求 */
4
+ declare const githubRequest: <D>(apiConfig: import("@done-coding/request-axios").ApiConfig<import("axios").AxiosRequestConfig<any>>, debug?: boolean | undefined) => Promise<import("@done-coding/request-axios").RequestResult<D>>;
5
+ export { giteeRequest, githubRequest };
@@ -0,0 +1,28 @@
1
+ /** 获取 gitee 用户公开的仓库列表 */
2
+ export declare const getGiteeUserPublicRepos: ({ username, }: {
3
+ username: string;
4
+ accessToken?: string | undefined;
5
+ }) => Promise<import("@done-coding/request-axios").RequestResult<{
6
+ /** 仓库名 */
7
+ name: string;
8
+ /** ssh */
9
+ ssh_url: string;
10
+ /** https */
11
+ html_url: string;
12
+ /** 描述 */
13
+ description?: string | null | undefined;
14
+ }[]>>;
15
+ /** 获取 gitee 用户的所有仓库列表 */
16
+ export declare const getGiteeUserAllRepos: ({ accessToken, }: {
17
+ username: string;
18
+ accessToken?: string | undefined;
19
+ }) => Promise<import("@done-coding/request-axios").RequestResult<{
20
+ /** 仓库名 */
21
+ name: string;
22
+ /** ssh */
23
+ ssh_url: string;
24
+ /** https */
25
+ html_url: string;
26
+ /** 描述 */
27
+ description?: string | null | undefined;
28
+ }[]>>;
@@ -0,0 +1,14 @@
1
+ /** 获取 github 用户公开仓库列表 */
2
+ export declare const getGithubUserPublicRepos: ({ username, }: {
3
+ username: string;
4
+ accessToken?: string | undefined;
5
+ }) => Promise<import("@done-coding/request-axios").RequestResult<{
6
+ /** 仓库名 */
7
+ name: string;
8
+ /** ssh */
9
+ ssh_url: string;
10
+ /** https */
11
+ clone_url: string;
12
+ /** 描述 */
13
+ description?: string | null | undefined;
14
+ }[]>>;
package/types/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,6 @@
1
+ import { SubcommandEnum } from './utils';
2
+ import type { Options } from './utils';
3
+ import type { ArgumentsCamelCase } from "yargs";
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>;
@@ -0,0 +1,3 @@
1
+ export { handler } from "./handler";
2
+ export { command } from "./main";
3
+ export { getTargetRepoUrl } from "./utils";
@@ -0,0 +1,11 @@
1
+ declare const _default: {
2
+ "version": "0.1.0",
3
+ "name": "@done-coding/cli-git",
4
+ "description": "git跨平台操作命令行工具",
5
+ "cliConfig": {
6
+ "namespaceDir": ".done-coding",
7
+ "moduleName": "git"
8
+ }
9
+ };
10
+
11
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import type { CommandModule } from "yargs";
2
+ import { type Options } from './utils';
3
+ export declare const command: CommandModule<Options, Options>;
4
+ export declare const createCli: () => Promise<void>;
@@ -0,0 +1,3 @@
1
+ import type { Options } from "./types";
2
+ /** 克隆目标仓库 */
3
+ export declare const clone: (options: Options) => Promise<void>;
@@ -0,0 +1,20 @@
1
+ import type { GitConfigInfo, GitPlatformEnum } from "./types";
2
+ /**
3
+ * 获取配置信息
4
+ */
5
+ export declare const getGitConfigInfo: ({ secretKey, platform, }: {
6
+ /** 秘钥 */
7
+ secretKey: string;
8
+ /** 平台 */
9
+ platform: GitPlatformEnum;
10
+ }) => GitConfigInfo | undefined;
11
+ /**
12
+ * 设置配置信息
13
+ */
14
+ export declare const setGitConfigInfo: ({ secretKey, platform, accessToken, }: {
15
+ accessToken: string;
16
+ /** 秘钥 */
17
+ secretKey: string;
18
+ /** 平台 */
19
+ platform: GitPlatformEnum;
20
+ }) => void;
@@ -0,0 +1,3 @@
1
+ import { type Options } from "./types";
2
+ /** 获取目标仓库地址 */
3
+ export declare const getTargetRepoUrl: ({ platform: platformInit, username: usernameInit, }?: Partial<Options>) => Promise<any>;
@@ -0,0 +1,3 @@
1
+ export * from "./types";
2
+ export * from "./get-repo";
3
+ export * from "./clone";
@@ -0,0 +1,23 @@
1
+ /** 子命令枚举 */
2
+ export declare enum SubcommandEnum {
3
+ /** 克隆 */
4
+ CLONE = "clone"
5
+ }
6
+ /** Git 平台枚举 */
7
+ export declare enum GitPlatformEnum {
8
+ /** GitHub */
9
+ GITHUB = "github",
10
+ /** Gitee */
11
+ GITEE = "gitee"
12
+ }
13
+ export interface Options {
14
+ /** 平台 */
15
+ platform: GitPlatformEnum;
16
+ /** 用户名 */
17
+ username: string;
18
+ }
19
+ /** Git 配置信息 */
20
+ export interface GitConfigInfo {
21
+ /** token */
22
+ accessToken: string;
23
+ }