done-coding-git 0.5.5-alpha.1

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,11 @@
1
+ #!/usr/bin/env node
2
+ import { c as m } from "./index-49e07bde.js";
3
+ import "@done-coding/cli-utils";
4
+ import "./clone-11819b7f.js";
5
+ import "@done-coding/request-axios";
6
+ import "axios";
7
+ import "node:fs";
8
+ import "node:path";
9
+ import "node:child_process";
10
+ import "node:os";
11
+ m();
@@ -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.5-alpha.1",
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-11819b7f.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-11819b7f.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 ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ import { a as s, h as c } from "./index-49e07bde.js";
3
+ import { c as l, f } from "./clone-11819b7f.js";
4
+ import "@done-coding/cli-utils";
5
+ import "node:os";
6
+ import "@done-coding/request-axios";
7
+ import "axios";
8
+ import "node:fs";
9
+ import "node:path";
10
+ import "node:child_process";
11
+ export {
12
+ l as cloneHandler,
13
+ s as crateAsSubcommand,
14
+ f as getTargetRepoUrl,
15
+ c as handler
16
+ };
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "done-coding-git",
3
+ "version": "0.5.5-alpha.1",
4
+ "description": "git跨平台操作命令行工具",
5
+ "private": false,
6
+ "module": "es/index.mjs",
7
+ "type": "module",
8
+ "types": "types/index.d.ts",
9
+ "bin": "es/cli.mjs",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./es/index.mjs"
13
+ },
14
+ "./helpers": {
15
+ "import": "./es/helpers.mjs",
16
+ "types": "./types/helpers.d.ts"
17
+ }
18
+ },
19
+ "typesVersions": {
20
+ "*": {
21
+ "helpers": [
22
+ "./types/helpers.d.ts"
23
+ ]
24
+ }
25
+ },
26
+ "files": [
27
+ "es",
28
+ "lib",
29
+ "types"
30
+ ],
31
+ "scripts": {},
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://gitee.com/justsosu/done-coding-cli.git",
35
+ "directory": "packages/git"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public",
39
+ "registry": "https://registry.npmjs.org/"
40
+ },
41
+ "author": "JustSoSu",
42
+ "license": "MIT",
43
+ "sideEffects": false,
44
+ "devDependencies": {
45
+ "@done-coding/cli-inject": "^0.5.8-alpha.0",
46
+ "@types/node": "^18.0.0",
47
+ "@types/yargs": "^17.0.28",
48
+ "rimraf": "^6.0.1",
49
+ "typescript": "^5.2.2",
50
+ "vite": "^4.4.11",
51
+ "vite-plugin-dts": "^3.6.0"
52
+ },
53
+ "engines": {
54
+ "node": ">=18.0.0"
55
+ },
56
+ "dependencies": {
57
+ "@done-coding/cli-utils": "^0.6.0-alpha.0",
58
+ "@done-coding/request-axios": "^1.1.1",
59
+ "axios": "^1.8.4"
60
+ },
61
+ "gitHead": "5879161383e32e7bed351d71d3ef607d81dc021a"
62
+ }
@@ -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,21 @@
1
+ /** 获取 gitee 仓库信息 */
2
+ export interface GiteeRepoInfo {
3
+ /** 仓库名 */
4
+ name: string;
5
+ /** ssh */
6
+ ssh_url: string;
7
+ /** https */
8
+ html_url: string;
9
+ /** 描述 */
10
+ description?: string | null;
11
+ }
12
+ /** 获取 gitee 用户公开的仓库列表 */
13
+ export declare const getGiteeUserPublicRepos: ({ username, }: {
14
+ username: string;
15
+ accessToken?: string | undefined;
16
+ }) => Promise<import("@done-coding/request-axios").RequestResult<GiteeRepoInfo[]>>;
17
+ /** 获取 gitee 用户的所有仓库列表 */
18
+ export declare const getGiteeUserAllRepos: ({ accessToken, }: {
19
+ username: string;
20
+ accessToken?: string | undefined;
21
+ }) => Promise<import("@done-coding/request-axios").RequestResult<GiteeRepoInfo[]>>;
@@ -0,0 +1,21 @@
1
+ /** 获取 github 仓库信息 */
2
+ export interface GithubRepoInfo {
3
+ /** 仓库名 */
4
+ name: string;
5
+ /** ssh */
6
+ ssh_url: string;
7
+ /** https */
8
+ clone_url: string;
9
+ /** 描述 */
10
+ description?: string | null;
11
+ }
12
+ /** 获取 github 用户公开仓库列表 */
13
+ export declare const getGithubUserPublicRepos: ({ username, }: {
14
+ username: string;
15
+ accessToken?: string | undefined;
16
+ }) => Promise<import("@done-coding/request-axios").RequestResult<GithubRepoInfo[]>>;
17
+ /** 获取 github 用户所有仓库列表 */
18
+ export declare const getGithubUserAllRepos: ({ accessToken, }: {
19
+ username: string;
20
+ accessToken?: string | undefined;
21
+ }) => Promise<import("@done-coding/request-axios").RequestResult<GithubRepoInfo[]>>;
package/types/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,5 @@
1
+ import { SubcommandEnum } from './utils';
2
+ import type { InitOptions, CloneOptions } from './utils';
3
+ import type { CliHandlerArgv } from "@done-coding/cli-utils";
4
+ /** 子命令处理函数 */
5
+ export declare const handler: (command: SubcommandEnum, argv: CliHandlerArgv<InitOptions | CloneOptions>) => Promise<void>;
@@ -0,0 +1,2 @@
1
+ /** 克隆done-coding系列项目 */
2
+ export declare const cloneDoneCodingSeries: (projectName?: string) => Promise<void>;
@@ -0,0 +1 @@
1
+ export * from './helpers-assets/done-coding';
@@ -0,0 +1,3 @@
1
+ export { handler } from "./handler";
2
+ export { crateAsSubcommand } from "./main";
3
+ export { getTargetRepoUrl, cloneHandler } from "./utils";
@@ -0,0 +1,11 @@
1
+ declare const _default: {
2
+ "name": "@done-coding/cli-git",
3
+ "version": "0.5.5-alpha.1",
4
+ "description": "git跨平台操作命令行工具",
5
+ "cliConfig": {
6
+ "namespaceDir": ".done-coding",
7
+ "moduleName": "git"
8
+ }
9
+ };
10
+
11
+ export default _default;
@@ -0,0 +1,9 @@
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<{}, {}>;
@@ -0,0 +1,7 @@
1
+ import { type CloneOptions } from "./types";
2
+ import type { CliInfo } from "@done-coding/cli-utils";
3
+ export declare const getCloneOptions: () => CliInfo["options"];
4
+ /** 获取克隆命令的位置参数 */
5
+ export declare const getClonePositionals: () => CliInfo["positionals"];
6
+ /** 克隆目标仓库 */
7
+ export declare const cloneHandler: (options: CloneOptions) => Promise<void>;
@@ -0,0 +1,14 @@
1
+ import type { GitConfigInfo, GitParamsInfo } from "./types";
2
+ /**
3
+ * 获取配置信息
4
+ */
5
+ export declare const getGitConfigInfo: (params: GitParamsInfo) => GitConfigInfo | undefined;
6
+ /**
7
+ * 设置配置信息
8
+ */
9
+ export declare const setGitConfigInfo: ({ rootDir, username, platform, accessToken, }: {
10
+ /** 根目录 */
11
+ rootDir: string;
12
+ /** 访问令牌 */
13
+ accessToken: string;
14
+ } & GitParamsInfo) => void;
@@ -0,0 +1,3 @@
1
+ import { type GitParamsInfo } from "./types";
2
+ /** 获取目标仓库地址 */
3
+ export declare const getTargetRepoUrl: ({ platform: platformInit, username: usernameInit, }?: Partial<GitParamsInfo>) => Promise<any>;
@@ -0,0 +1,7 @@
1
+ export * from "./types";
2
+ export * from "./get-repo";
3
+ export * from "./init";
4
+ export * from "./clone";
5
+ export * from "./path";
6
+ export * from "./config";
7
+ export * from "./question";
@@ -0,0 +1,9 @@
1
+ /// <reference types="yargs" />
2
+ import type { CliHandlerArgv } from "@done-coding/cli-utils";
3
+ import type { InitOptions } from "./types";
4
+ /** 获取初始化选项 */
5
+ export declare const getInitOptions: () => {
6
+ rootDir: import("yargs").Options;
7
+ };
8
+ /** 初始化命令处理器 */
9
+ export declare const initHandler: (argv: CliHandlerArgv<InitOptions>) => Promise<void>;
@@ -0,0 +1,2 @@
1
+ /** 模块配置相对路径 */
2
+ export declare const MODULE_CONFIG_RELATIVE_PATH: string;
@@ -0,0 +1,8 @@
1
+ import type { PromptObject } from "@done-coding/cli-utils";
2
+ import { GitPlatformEnum } from "./types";
3
+ /** git平台选择表单 */
4
+ export declare const getPlatformForm: (initialValue?: GitPlatformEnum) => PromptObject<string>;
5
+ /** git用户名表单 */
6
+ export declare const getGitUsernameForm: (initial?: PromptObject["initial"]) => PromptObject<string>;
7
+ /** git access token表单 */
8
+ export declare const gitAccessTokenForm: PromptObject<string>;
@@ -0,0 +1,33 @@
1
+ import type { InitConfigFileOptions } from "@done-coding/cli-utils";
2
+ /** 子命令枚举 */
3
+ export declare enum SubcommandEnum {
4
+ /** 初始化配置文件 */
5
+ INIT = "init",
6
+ /** 克隆 */
7
+ CLONE = "clone"
8
+ }
9
+ /** 初始化选项 */
10
+ export type InitOptions = Pick<InitConfigFileOptions, "rootDir">;
11
+ /** Git 平台枚举 */
12
+ export declare enum GitPlatformEnum {
13
+ /** GitHub */
14
+ GITHUB = "github",
15
+ /** Gitee */
16
+ GITEE = "gitee"
17
+ }
18
+ /** git参数信息 */
19
+ export interface GitParamsInfo {
20
+ /** 平台 */
21
+ platform: GitPlatformEnum;
22
+ /** 用户名 */
23
+ username: string;
24
+ /** 项目名称 */
25
+ projectName?: string;
26
+ }
27
+ /** 可控选项 */
28
+ export type CloneOptions = GitParamsInfo;
29
+ /** Git 配置信息 */
30
+ export interface GitConfigInfo {
31
+ /** token */
32
+ accessToken: string;
33
+ }