@done-coding/cli-utils 0.8.0 → 0.8.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 +104 -2
- package/es/index.mjs +321 -330
- package/package.json +2 -2
- package/types/index.d.ts +25 -10
package/README.md
CHANGED
|
@@ -1,7 +1,109 @@
|
|
|
1
1
|
# @done-coding/cli-utils
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
CLI 通用工具库 - 为 done-coding CLI 生态系统提供基础工具函数
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@done-coding/cli-utils)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
7
|
|
|
8
|
+
## 安装
|
|
9
|
+
|
|
10
|
+
```bash
|
|
7
11
|
npm install @done-coding/cli-utils
|
|
12
|
+
# 或
|
|
13
|
+
pnpm add @done-coding/cli-utils
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## 快速开始
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# 作为依赖库使用,不提供独立的 CLI 命令
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 功能特性
|
|
23
|
+
|
|
24
|
+
- ✅ **基础工具**: 提供通用的 CLI 工具函数
|
|
25
|
+
- 🔧 **类型定义**: 统一的 TypeScript 类型定义
|
|
26
|
+
- 📝 **配置处理**: 配置文件读取和处理工具
|
|
27
|
+
- 🎨 **命令行美化**: 基于 chalk 的命令行输出美化
|
|
28
|
+
- 🔄 **数据处理**: 基于 lodash 的数据操作工具
|
|
29
|
+
|
|
30
|
+
## API 文档
|
|
31
|
+
|
|
32
|
+
本包是一个工具库,不提供独立的 CLI 命令,主要为其他 done-coding CLI 包提供基础功能。
|
|
33
|
+
|
|
34
|
+
### 主要依赖
|
|
35
|
+
|
|
36
|
+
- **chalk**: 命令行输出美化
|
|
37
|
+
- **json5**: JSON5 格式支持
|
|
38
|
+
- **lodash**: 数据操作工具函数
|
|
39
|
+
- **prompts**: 交互式命令行提示
|
|
40
|
+
- **semver**: 版本号处理
|
|
41
|
+
- **uuid**: UUID 生成
|
|
42
|
+
- **yargs**: 命令行参数解析
|
|
43
|
+
|
|
44
|
+
## 使用示例
|
|
45
|
+
|
|
46
|
+
### 作为依赖使用
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
import { /* 具体导出内容 */ } from '@done-coding/cli-utils';
|
|
50
|
+
|
|
51
|
+
// 具体使用方法需要查看包的导出内容
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 编程接口
|
|
55
|
+
|
|
56
|
+
本包提供了编程接口,具体的导出内容请查看包的类型定义文件。
|
|
57
|
+
|
|
58
|
+
## 包依赖关系
|
|
59
|
+
|
|
60
|
+
### 被其他包依赖
|
|
61
|
+
|
|
62
|
+
`@done-coding/cli-utils` 是基础工具库,被以下包依赖:
|
|
63
|
+
|
|
64
|
+
- `@done-coding/cli` - 主 CLI 工具
|
|
65
|
+
- `@done-coding/cli-component` - 组件生成工具
|
|
66
|
+
- `@done-coding/cli-config` - 工程配置工具
|
|
67
|
+
- `@done-coding/cli-extract` - 信息提取工具
|
|
68
|
+
- `@done-coding/cli-git` - Git 操作工具
|
|
69
|
+
- `@done-coding/cli-inject` - 信息注入工具
|
|
70
|
+
- `@done-coding/cli-publish` - 项目发布工具
|
|
71
|
+
- `@done-coding/cli-template` - 模板处理工具
|
|
72
|
+
- `create-done-coding` - 项目创建工具
|
|
73
|
+
|
|
74
|
+
## 贡献指南
|
|
75
|
+
|
|
76
|
+
我们欢迎贡献!请遵循以下步骤:
|
|
77
|
+
|
|
78
|
+
1. Fork 本仓库
|
|
79
|
+
2. 创建功能分支:`git checkout -b feature/amazing-feature`
|
|
80
|
+
3. 提交更改:`git commit -m "feat: add amazing feature"`
|
|
81
|
+
4. 推送分支:`git push origin feature/amazing-feature`
|
|
82
|
+
5. 创建 Pull Request
|
|
83
|
+
|
|
84
|
+
### 开发环境设置
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# 克隆仓库
|
|
88
|
+
git clone https://gitee.com/done-coding/done-coding-cli.git
|
|
89
|
+
cd done-coding-cli/packages/utils
|
|
90
|
+
|
|
91
|
+
# 安装依赖
|
|
92
|
+
pnpm install
|
|
93
|
+
|
|
94
|
+
# 开发模式
|
|
95
|
+
pnpm dev
|
|
96
|
+
|
|
97
|
+
# 构建
|
|
98
|
+
pnpm build
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## 许可证
|
|
102
|
+
|
|
103
|
+
MIT © [JustSoSu](https://gitee.com/done-coding)
|
|
104
|
+
|
|
105
|
+
## 相关链接
|
|
106
|
+
|
|
107
|
+
- [主 CLI 工具](https://www.npmjs.com/package/@done-coding/cli)
|
|
108
|
+
- [Gitee 仓库](https://gitee.com/done-coding/done-coding-cli)
|
|
109
|
+
- [更新日志](./CHANGELOG.md)
|
package/es/index.mjs
CHANGED
|
@@ -1,56 +1,55 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import { default as Ie } from "chalk";
|
|
2
|
+
import q from "chalk";
|
|
4
3
|
import l from "node:path";
|
|
5
|
-
import m, { existsSync as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { hideBin as
|
|
10
|
-
import { execSync as
|
|
4
|
+
import m, { existsSync as v, mkdirSync as z, writeFileSync as P, readFileSync as _ } from "node:fs";
|
|
5
|
+
import R from "crypto";
|
|
6
|
+
import Q from "prompts";
|
|
7
|
+
import Z from "yargs";
|
|
8
|
+
import { hideBin as tt } from "yargs/helpers";
|
|
9
|
+
import { execSync as g } from "node:child_process";
|
|
11
10
|
import F from "json5";
|
|
12
11
|
export * from "json5";
|
|
13
12
|
import { default as Ae } from "json5";
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import { tmpdir as
|
|
13
|
+
import et from "lodash.merge";
|
|
14
|
+
import rt from "semver";
|
|
15
|
+
import { tmpdir as st, homedir as nt } from "node:os";
|
|
17
16
|
import { v4 as ot } from "uuid";
|
|
18
|
-
import { v4 as
|
|
17
|
+
import { v4 as we } from "uuid";
|
|
19
18
|
import { default as Te } from "lodash.get";
|
|
20
19
|
import { default as Ne } from "lodash.set";
|
|
21
|
-
import { default as
|
|
22
|
-
import
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
{
|
|
20
|
+
import { default as Be } from "lodash.curry";
|
|
21
|
+
import y from "pinyin";
|
|
22
|
+
const G = (t) => {
|
|
23
|
+
const e = (...[r, ...n]) => t(q[r](...n));
|
|
24
|
+
return Object.assign(e, {
|
|
26
25
|
/** 成功 */
|
|
27
|
-
success: (...
|
|
26
|
+
success: (...r) => e("green", ...r),
|
|
28
27
|
/** /步骤 */
|
|
29
|
-
stage: (...
|
|
28
|
+
stage: (...r) => e("blue", ...r),
|
|
30
29
|
/** 提示信息 */
|
|
31
|
-
info: (...
|
|
30
|
+
info: (...r) => e("cyan", ...r),
|
|
32
31
|
/** 警告 */
|
|
33
|
-
warn: (...
|
|
32
|
+
warn: (...r) => e("yellow", ...r),
|
|
34
33
|
/** 错误 */
|
|
35
|
-
error: (...
|
|
34
|
+
error: (...r) => e("red", ...r),
|
|
36
35
|
/** 跳过 */
|
|
37
|
-
skip: (...
|
|
38
|
-
}
|
|
39
|
-
),
|
|
36
|
+
skip: (...r) => e("gray", ...r)
|
|
37
|
+
});
|
|
38
|
+
}, a = G(console.log), Zt = G((t) => t), te = (t, {
|
|
40
39
|
/** 当前目录 */
|
|
41
40
|
currentDir: e = process.cwd(),
|
|
42
41
|
/** 优先找最远的父目录 */
|
|
43
42
|
isFindFarthest: r = !0
|
|
44
43
|
} = {}) => {
|
|
45
|
-
const
|
|
46
|
-
for (;
|
|
47
|
-
const s = r ?
|
|
48
|
-
if (m.existsSync(
|
|
44
|
+
const n = l.resolve(e).split(l.sep).map((s, o, c) => c.slice(0, o).concat(s).join(l.sep) || l.sep);
|
|
45
|
+
for (; n.length; ) {
|
|
46
|
+
const s = r ? n.shift() : n.pop(), o = l.join(s, t);
|
|
47
|
+
if (m.existsSync(o))
|
|
49
48
|
return s;
|
|
50
49
|
}
|
|
51
|
-
},
|
|
52
|
-
function
|
|
53
|
-
return
|
|
50
|
+
}, k = "aes-256-cbc", x = 16, C = "hex", w = ":";
|
|
51
|
+
function j(t) {
|
|
52
|
+
return R.pbkdf2Sync(
|
|
54
53
|
t,
|
|
55
54
|
"done-coding-cli-salt",
|
|
56
55
|
// 使用固定的盐值
|
|
@@ -61,55 +60,55 @@ function k(t) {
|
|
|
61
60
|
"sha256"
|
|
62
61
|
);
|
|
63
62
|
}
|
|
64
|
-
function
|
|
63
|
+
function ee({
|
|
65
64
|
text: t,
|
|
66
65
|
secretKey: e
|
|
67
66
|
}) {
|
|
68
67
|
try {
|
|
69
|
-
const r =
|
|
70
|
-
let
|
|
71
|
-
|
|
72
|
-
const c =
|
|
68
|
+
const r = j(e), n = R.randomBytes(x), s = R.createCipheriv(k, r, n);
|
|
69
|
+
let o = s.update(t);
|
|
70
|
+
o = Buffer.concat([o, s.final()]);
|
|
71
|
+
const c = n.toString(C), i = o.toString(C);
|
|
73
72
|
return `${c}${w}${i}`;
|
|
74
73
|
} catch (r) {
|
|
75
|
-
return
|
|
74
|
+
return a.error(
|
|
76
75
|
`加密失败: ${r instanceof Error ? r.message : String(r)}`
|
|
77
76
|
), "";
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
|
-
function
|
|
79
|
+
function re({
|
|
81
80
|
encryptedText: t,
|
|
82
81
|
secretKey: e
|
|
83
82
|
}) {
|
|
84
83
|
try {
|
|
85
84
|
if (!t.includes(w))
|
|
86
85
|
return "";
|
|
87
|
-
const r =
|
|
88
|
-
if (
|
|
86
|
+
const r = j(e), [n, s] = t.split(w);
|
|
87
|
+
if (n.length !== x * 2)
|
|
89
88
|
return "";
|
|
90
|
-
const
|
|
91
|
-
let
|
|
92
|
-
return
|
|
89
|
+
const o = Buffer.from(n, C), c = Buffer.from(s, C), i = R.createDecipheriv(k, r, o);
|
|
90
|
+
let u = i.update(c);
|
|
91
|
+
return u = Buffer.concat([u, i.final()]), u.toString();
|
|
93
92
|
} catch (r) {
|
|
94
|
-
return
|
|
93
|
+
return a.error(
|
|
95
94
|
`解密失败: ${r instanceof Error ? r.message : String(r)}`
|
|
96
95
|
), "";
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
|
-
const
|
|
98
|
+
const U = (...t) => {
|
|
100
99
|
const [e, r = {}] = t;
|
|
101
|
-
return
|
|
102
|
-
onCancel(
|
|
103
|
-
return
|
|
100
|
+
return Q(e, {
|
|
101
|
+
onCancel(n) {
|
|
102
|
+
return a.error(`退出${n == null ? void 0 : n.name}输入`), process.exit(1);
|
|
104
103
|
},
|
|
105
104
|
...r
|
|
106
105
|
});
|
|
107
|
-
},
|
|
108
|
-
t ?
|
|
109
|
-
},
|
|
110
|
-
const t =
|
|
111
|
-
return
|
|
112
|
-
},
|
|
106
|
+
}, it = (t, e) => {
|
|
107
|
+
t ? a.error(t) : a.error(e.message), e != null && e.stack && a.error(e.stack), process.exit(1);
|
|
108
|
+
}, ct = () => {
|
|
109
|
+
const t = tt(process.argv);
|
|
110
|
+
return Z(t);
|
|
111
|
+
}, se = ({
|
|
113
112
|
rootScriptName: t,
|
|
114
113
|
packageJson: e
|
|
115
114
|
}) => {
|
|
@@ -117,51 +116,51 @@ const H = (...t) => {
|
|
|
117
116
|
return t;
|
|
118
117
|
if (!e)
|
|
119
118
|
return;
|
|
120
|
-
const { bin: r, name:
|
|
119
|
+
const { bin: r, name: n } = e;
|
|
121
120
|
if (r) {
|
|
122
121
|
if (typeof r == "string")
|
|
123
|
-
return
|
|
122
|
+
return n.includes("/") ? void 0 : n;
|
|
124
123
|
if (typeof r == "object") {
|
|
125
|
-
const s = Object.entries(r),
|
|
124
|
+
const s = Object.entries(r), o = process.argv[1], c = s.filter(([, u]) => o == null ? void 0 : o.endsWith(u));
|
|
126
125
|
if (c.length !== 1)
|
|
127
126
|
return;
|
|
128
127
|
const [i] = c[0];
|
|
129
128
|
return process.platform === "win32" ? i.toLowerCase() : i;
|
|
130
129
|
}
|
|
131
130
|
}
|
|
132
|
-
},
|
|
131
|
+
}, H = (t, {
|
|
133
132
|
usage: e,
|
|
134
133
|
version: r,
|
|
135
|
-
demandCommandCount:
|
|
134
|
+
demandCommandCount: n,
|
|
136
135
|
options: s,
|
|
137
|
-
positionals:
|
|
136
|
+
positionals: o,
|
|
138
137
|
subcommands: c,
|
|
139
138
|
rootScriptName: i
|
|
140
|
-
},
|
|
141
|
-
let
|
|
142
|
-
e && (
|
|
143
|
-
const
|
|
144
|
-
return
|
|
145
|
-
},
|
|
146
|
-
const r = await
|
|
147
|
-
|
|
139
|
+
}, u) => {
|
|
140
|
+
let f = t.strict();
|
|
141
|
+
e && (f = f.usage(`Usage: ${e}`)), n && (f = f.demandCommand(n));
|
|
142
|
+
const p = "help";
|
|
143
|
+
return f = f.help(p), r ? f = f.version(r).alias("h", p).alias("v", "version") : f = f.alias("h", p), s && (f = f.options(s)), o && (f = Object.entries(o).reduce((S, [$, h]) => S.positional($, h), f)), c && (f = f.command(c)), u && i && (f = f.scriptName(i)), f;
|
|
144
|
+
}, ne = async ({ handler: t, ...e }) => {
|
|
145
|
+
const r = await H(ct(), e, !0).fail(
|
|
146
|
+
it
|
|
148
147
|
).argv;
|
|
149
148
|
return t ? t(r) : r;
|
|
150
|
-
},
|
|
151
|
-
const { command: e, describe: r, handler:
|
|
149
|
+
}, oe = (t) => {
|
|
150
|
+
const { command: e, describe: r, handler: n = () => {
|
|
152
151
|
}, ...s } = t;
|
|
153
152
|
return {
|
|
154
153
|
command: e,
|
|
155
154
|
describe: r,
|
|
156
|
-
builder(
|
|
157
|
-
return
|
|
155
|
+
builder(o) {
|
|
156
|
+
return H(o, s, !1);
|
|
158
157
|
},
|
|
159
|
-
handler:
|
|
158
|
+
handler: n
|
|
160
159
|
};
|
|
161
160
|
};
|
|
162
|
-
var
|
|
163
|
-
const
|
|
164
|
-
const { editorType: t } = await
|
|
161
|
+
var at = /* @__PURE__ */ ((t) => (t.VSCODE = "VsCode", t.CURSOR = "Cursor", t.OTHER = "其他", t))(at || {});
|
|
162
|
+
const ft = async () => {
|
|
163
|
+
const { editorType: t } = await U([
|
|
165
164
|
{
|
|
166
165
|
name: "editorType",
|
|
167
166
|
type: "select",
|
|
@@ -181,29 +180,29 @@ const at = async () => {
|
|
|
181
180
|
}, lt = {
|
|
182
181
|
Cursor: "cursor",
|
|
183
182
|
VsCode: "code"
|
|
184
|
-
},
|
|
183
|
+
}, ut = (t, e, r) => {
|
|
185
184
|
try {
|
|
186
|
-
|
|
185
|
+
g(`${t} -v`, { stdio: "ignore" }), g(`${t} ${e}`);
|
|
187
186
|
} catch {
|
|
188
187
|
r();
|
|
189
188
|
}
|
|
190
189
|
}, gt = (t, e) => {
|
|
191
|
-
const r = (
|
|
192
|
-
${
|
|
190
|
+
const r = (n) => a.info(`
|
|
191
|
+
${n}, 请用编辑器打开 ${t} 进行编辑
|
|
193
192
|
`);
|
|
194
193
|
switch (e) {
|
|
195
194
|
case "Cursor":
|
|
196
195
|
case "VsCode": {
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
r(`${
|
|
196
|
+
const n = lt[e];
|
|
197
|
+
ut(n, t, () => {
|
|
198
|
+
r(`${n}命令未安装`);
|
|
200
199
|
});
|
|
201
200
|
break;
|
|
202
201
|
}
|
|
203
202
|
default:
|
|
204
203
|
r("其他编辑器");
|
|
205
204
|
}
|
|
206
|
-
},
|
|
205
|
+
}, mt = (t = process.cwd()) => ({
|
|
207
206
|
/** 必须保留 */
|
|
208
207
|
rootDir: {
|
|
209
208
|
type: "string",
|
|
@@ -212,12 +211,12 @@ const at = async () => {
|
|
|
212
211
|
/** 必须设置默认值 */
|
|
213
212
|
default: t
|
|
214
213
|
}
|
|
215
|
-
}),
|
|
214
|
+
}), ie = ({
|
|
216
215
|
configPathDefault: t,
|
|
217
216
|
rootDirDefault: e
|
|
218
217
|
}) => ({
|
|
219
218
|
/** 必须保留 */
|
|
220
|
-
...
|
|
219
|
+
...mt(e),
|
|
221
220
|
/** 必须保留 */
|
|
222
221
|
configPath: {
|
|
223
222
|
type: "string",
|
|
@@ -226,279 +225,275 @@ const at = async () => {
|
|
|
226
225
|
/** 必须设置默认值 */
|
|
227
226
|
default: t
|
|
228
227
|
}
|
|
229
|
-
}),
|
|
230
|
-
const { configPath: r, rootDir:
|
|
231
|
-
return
|
|
228
|
+
}), pt = async (t, e) => {
|
|
229
|
+
const { configPath: r, rootDir: n } = e, s = l.resolve(n, r), o = l.dirname(s);
|
|
230
|
+
return v(o) || z(o, {
|
|
232
231
|
recursive: !0
|
|
233
|
-
}), s.endsWith(".json5") ? (
|
|
234
|
-
},
|
|
232
|
+
}), s.endsWith(".json5") ? (a.info(`json5模式写入 ${s}`), P(s, F.stringify(t, null, 2)), s) : (a.info(`json模式写入 ${s}`), P(s, JSON.stringify(t, null, 2)), s);
|
|
233
|
+
}, ce = async (t, e, {
|
|
235
234
|
onFileGenerated: r,
|
|
236
|
-
edit:
|
|
235
|
+
edit: n = !1
|
|
237
236
|
} = {}) => {
|
|
238
|
-
const s = await
|
|
239
|
-
if (r == null || r(s),
|
|
240
|
-
const
|
|
241
|
-
gt(e.configPath,
|
|
237
|
+
const s = await pt(t, e);
|
|
238
|
+
if (r == null || r(s), n) {
|
|
239
|
+
const o = await ft();
|
|
240
|
+
gt(e.configPath, o);
|
|
242
241
|
}
|
|
243
|
-
},
|
|
244
|
-
const { configPath: r, rootDir:
|
|
245
|
-
if (!
|
|
242
|
+
}, ae = async (t, e) => {
|
|
243
|
+
const { configPath: r, rootDir: n } = t, s = l.resolve(n, r);
|
|
244
|
+
if (!v(s)) {
|
|
246
245
|
if (e)
|
|
247
|
-
return
|
|
248
|
-
const
|
|
249
|
-
throw new Error(
|
|
246
|
+
return a.info("配置文件不存在,使用onNotExists返回值"), e();
|
|
247
|
+
const o = `配置文件不存在 ${s}`;
|
|
248
|
+
throw new Error(o);
|
|
250
249
|
}
|
|
251
|
-
return s.endsWith(".json5") ? (
|
|
252
|
-
},
|
|
253
|
-
const { useDefaultConfig: t } = await
|
|
250
|
+
return s.endsWith(".json5") ? (a.info(`json5模式解析 ${s}`), F.parse(_(s, "utf8"))) : (a.info(`json模式解析 ${s}`), JSON.parse(_(s, "utf8")));
|
|
251
|
+
}, fe = async () => {
|
|
252
|
+
const { useDefaultConfig: t } = await U({
|
|
254
253
|
name: "useDefaultConfig",
|
|
255
254
|
type: "confirm",
|
|
256
255
|
message: "使用默认模板配置",
|
|
257
256
|
initial: !0
|
|
258
257
|
});
|
|
259
258
|
return t;
|
|
260
|
-
}, J = "package.json",
|
|
259
|
+
}, J = "package.json", T = ({
|
|
261
260
|
rootDir: t
|
|
262
261
|
}) => {
|
|
263
262
|
const e = l.resolve(t, J);
|
|
264
|
-
if (!
|
|
263
|
+
if (!v(e))
|
|
265
264
|
throw new Error(`${t}未找到package.json文件`);
|
|
266
|
-
const r =
|
|
265
|
+
const r = _(e, "utf-8");
|
|
267
266
|
return JSON.parse(r);
|
|
268
|
-
},
|
|
267
|
+
}, ht = ({
|
|
269
268
|
rootDir: t,
|
|
270
269
|
pkgJson: e,
|
|
271
270
|
pkgName: r,
|
|
272
|
-
isDevPkg:
|
|
271
|
+
isDevPkg: n
|
|
273
272
|
}) => {
|
|
274
|
-
const s = e ||
|
|
275
|
-
let c =
|
|
273
|
+
const s = e || T({ rootDir: t }), o = n ? s.devDependencies : s.dependencies;
|
|
274
|
+
let c = o == null ? void 0 : o[r];
|
|
276
275
|
if (!c) {
|
|
277
|
-
const i =
|
|
278
|
-
c = i == null ? void 0 : i[r], c &&
|
|
279
|
-
|
|
280
|
-
`${o ? "开发" : "生产"}依赖包${r}可能错误的安装在${o ? "dependencies" : "devDependencies"}`
|
|
281
|
-
)
|
|
276
|
+
const i = n ? s.dependencies : s.devDependencies;
|
|
277
|
+
c = i == null ? void 0 : i[r], c && a.warn(
|
|
278
|
+
`${n ? "开发" : "生产"}依赖包${r}可能错误的安装在${n ? "dependencies" : "devDependencies"}`
|
|
282
279
|
);
|
|
283
280
|
return;
|
|
284
281
|
}
|
|
285
|
-
return c ||
|
|
286
|
-
},
|
|
282
|
+
return c || a.info(`依赖包${r}未安装`), c;
|
|
283
|
+
}, le = ({
|
|
287
284
|
patchConfig: t,
|
|
288
285
|
rootDir: e
|
|
289
286
|
}) => {
|
|
290
287
|
if (!t)
|
|
291
288
|
return;
|
|
292
|
-
const r =
|
|
293
|
-
|
|
294
|
-
},
|
|
295
|
-
const r =
|
|
289
|
+
const r = T({ rootDir: e }), n = et(r, t), s = l.resolve(e, J);
|
|
290
|
+
P(s, JSON.stringify(n, null, 2), "utf-8");
|
|
291
|
+
}, I = (t) => {
|
|
292
|
+
const r = g("git rev-parse --show-toplevel", {
|
|
296
293
|
cwd: t
|
|
297
294
|
}).toString();
|
|
298
295
|
if (!r)
|
|
299
296
|
throw new Error("获取git根目录失败");
|
|
300
297
|
return r.trim();
|
|
301
|
-
},
|
|
298
|
+
}, ue = () => {
|
|
302
299
|
var t;
|
|
303
300
|
try {
|
|
304
|
-
const e =
|
|
301
|
+
const e = g("git symbolic-ref --short HEAD", {
|
|
305
302
|
stdio: "ignore"
|
|
306
303
|
});
|
|
307
304
|
return (t = e == null ? void 0 : e.toString()) == null ? void 0 : t.trim();
|
|
308
305
|
} catch {
|
|
309
306
|
try {
|
|
310
|
-
const r =
|
|
311
|
-
|
|
307
|
+
const r = g("git rev-parse --short HEAD").toString().trim();
|
|
308
|
+
a.skip(`当前未指向具体某个分支, 当前commit hash: ${r}`);
|
|
312
309
|
} finally {
|
|
313
310
|
return;
|
|
314
311
|
}
|
|
315
312
|
}
|
|
316
|
-
},
|
|
313
|
+
}, dt = (t) => {
|
|
317
314
|
const e = t.match(/moving\s+from\s+(.*)\s+to\s+(.*)/);
|
|
318
315
|
if (e) {
|
|
319
|
-
const [, r,
|
|
316
|
+
const [, r, n] = e;
|
|
320
317
|
return {
|
|
321
318
|
fromBranch: r.trim(),
|
|
322
|
-
toBranch:
|
|
319
|
+
toBranch: n.trim()
|
|
323
320
|
};
|
|
324
321
|
}
|
|
325
|
-
},
|
|
322
|
+
}, A = 73, St = (t) => {
|
|
326
323
|
const r = m.statSync(t).mode;
|
|
327
|
-
if ((r &
|
|
324
|
+
if ((r & A) === A)
|
|
328
325
|
return;
|
|
329
|
-
|
|
330
|
-
const
|
|
331
|
-
m.chmodSync(t,
|
|
332
|
-
}, V = (t) => m.existsSync(t),
|
|
326
|
+
a.stage(`${t} 没有执行权限 添加... `);
|
|
327
|
+
const n = r | A;
|
|
328
|
+
m.chmodSync(t, n), a.success(`${t} 添加执行权限成功`);
|
|
329
|
+
}, V = (t) => m.existsSync(t), D = async (t) => {
|
|
333
330
|
try {
|
|
334
331
|
return await m.promises.lstat(t), !0;
|
|
335
332
|
} catch (e) {
|
|
336
333
|
return e.code !== "ENOENT";
|
|
337
334
|
}
|
|
338
|
-
},
|
|
335
|
+
}, Et = (t, e = !1) => {
|
|
339
336
|
V(t) && m.rmSync(t, { recursive: !0, force: e });
|
|
340
|
-
},
|
|
341
|
-
await
|
|
342
|
-
}, yt = (t) => m.readFileSync(t, "utf-8"),
|
|
343
|
-
var
|
|
344
|
-
const
|
|
345
|
-
const e =
|
|
337
|
+
}, ge = async (t, e = !1) => {
|
|
338
|
+
await D(t) && await m.promises.rm(t, { recursive: !0, force: e });
|
|
339
|
+
}, yt = (t) => m.readFileSync(t, "utf-8"), _t = (t) => m.promises.readFile(t, "utf-8"), me = (t, e) => JSON.parse(yt(t)) || e, K = async (t, e) => JSON.parse(await _t(t)) || e;
|
|
340
|
+
var d = /* @__PURE__ */ ((t) => (t.PRE_COMMIT = "pre-commit", t.PRE_MERGE_COMMIT = "pre-merge-commit", t.PREPARE_COMMIT_MSG = "prepare-commit-msg", t.COMMIT_MSG = "commit-msg", t.PRE_REBASE = "pre-rebase", t.POST_COMMIT = "post-commit", t.POST_MERGE = "post-merge", t.PRE_PUSH = "pre-push", t))(d || {});
|
|
341
|
+
const Rt = "husky", Ct = ".husky", Ot = ({ rootDir: t }) => {
|
|
342
|
+
const e = I(t), r = ht({
|
|
346
343
|
rootDir: e,
|
|
347
|
-
pkgJson:
|
|
348
|
-
pkgName:
|
|
344
|
+
pkgJson: T({ rootDir: e }),
|
|
345
|
+
pkgName: Rt,
|
|
349
346
|
isDevPkg: !0
|
|
350
347
|
});
|
|
351
348
|
if (!r)
|
|
352
349
|
throw new Error("husky版本获取失败, 可能husky未安装");
|
|
353
|
-
const
|
|
354
|
-
return
|
|
355
|
-
. "$(dirname -- "$0")/_/husky.sh"`) : (
|
|
356
|
-
},
|
|
357
|
-
const e =
|
|
358
|
-
return l.resolve(e,
|
|
359
|
-
},
|
|
350
|
+
const n = r.replace(/^(\^|~)/, ""), s = "<9.0.0";
|
|
351
|
+
return rt.satisfies(n, s) ? (a.info(`${n}符合${s}`), `#!/usr/bin/env sh
|
|
352
|
+
. "$(dirname -- "$0")/_/husky.sh"`) : (a.info(`${n}不符合${s}`), "");
|
|
353
|
+
}, vt = ({ rootDir: t }) => {
|
|
354
|
+
const e = I(t);
|
|
355
|
+
return l.resolve(e, Ct);
|
|
356
|
+
}, pe = ({
|
|
360
357
|
hookNames: t,
|
|
361
358
|
rootDir: e,
|
|
362
359
|
getCode: r
|
|
363
360
|
}) => {
|
|
364
|
-
const
|
|
365
|
-
m.existsSync(
|
|
366
|
-
const
|
|
361
|
+
const n = vt({ rootDir: e });
|
|
362
|
+
m.existsSync(n) || m.mkdirSync(n, { recursive: !0 }), t.forEach((s) => {
|
|
363
|
+
const o = l.resolve(n, s), c = m.existsSync(o);
|
|
367
364
|
let i = r(s);
|
|
368
365
|
if (c)
|
|
369
|
-
m.readFileSync(
|
|
370
|
-
|
|
371
|
-
) : (m.appendFileSync(
|
|
372
|
-
n,
|
|
366
|
+
m.readFileSync(o, "utf-8").includes(i) ? a.skip(`${o} ${s}相关调用 ${i} 已存在 跳过`) : (m.appendFileSync(
|
|
367
|
+
o,
|
|
373
368
|
`
|
|
374
369
|
${i}
|
|
375
370
|
`
|
|
376
|
-
),
|
|
371
|
+
), a.success(`${o} 添加 ${s}相关调用成功`));
|
|
377
372
|
else {
|
|
378
|
-
const
|
|
373
|
+
const u = Ot({
|
|
379
374
|
rootDir: e
|
|
380
375
|
});
|
|
381
376
|
m.writeFileSync(
|
|
382
|
-
|
|
383
|
-
`${
|
|
377
|
+
o,
|
|
378
|
+
`${u}
|
|
384
379
|
|
|
385
380
|
${i}
|
|
386
381
|
`,
|
|
387
382
|
"utf-8"
|
|
388
|
-
),
|
|
383
|
+
), a.success(`${o} 添加 ${s}相关调用成功`);
|
|
389
384
|
}
|
|
390
|
-
|
|
385
|
+
St(o);
|
|
391
386
|
});
|
|
392
|
-
},
|
|
387
|
+
}, he = [
|
|
393
388
|
// HooksNameEnum.PRE_MERGE_COMMIT,
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
],
|
|
389
|
+
d.PREPARE_COMMIT_MSG,
|
|
390
|
+
d.COMMIT_MSG
|
|
391
|
+
], de = ({
|
|
397
392
|
hookName: t,
|
|
398
393
|
rootDir: e
|
|
399
394
|
}) => {
|
|
400
|
-
const r =
|
|
395
|
+
const r = I(e), n = l.resolve(r, ".git");
|
|
401
396
|
switch (t) {
|
|
402
|
-
case
|
|
403
|
-
case
|
|
404
|
-
const s = l.resolve(
|
|
405
|
-
if (
|
|
406
|
-
return
|
|
397
|
+
case d.PREPARE_COMMIT_MSG:
|
|
398
|
+
case d.COMMIT_MSG: {
|
|
399
|
+
const s = l.resolve(n, "MERGE_MSG");
|
|
400
|
+
if (v(s))
|
|
401
|
+
return _(s, "utf-8");
|
|
407
402
|
}
|
|
408
403
|
}
|
|
409
404
|
return "";
|
|
410
|
-
},
|
|
405
|
+
}, Se = ({
|
|
411
406
|
remoteAlias: t = "origin"
|
|
412
407
|
} = {}) => {
|
|
413
408
|
try {
|
|
414
|
-
const e =
|
|
415
|
-
let
|
|
409
|
+
const e = g("git rev-parse HEAD").toString().trim(), r = g('git log -1 --pretty=format:"%an"').toString().trim(), n = g('git log -1 --pretty=format:"%ae"').toString().trim(), s = g('git log -1 --pretty=format:"%s"').toString().trim(), o = g("git config user.name").toString().trim(), c = g("git config user.email").toString().trim(), i = g("git rev-parse --abbrev-ref HEAD").toString().trim();
|
|
410
|
+
let u = "";
|
|
416
411
|
try {
|
|
417
|
-
|
|
412
|
+
u = g(`git config --get remote.${t}.url`).toString().trim();
|
|
418
413
|
} catch {
|
|
419
|
-
|
|
414
|
+
a.warn("git远程仓库地址获取失败或者不存在");
|
|
420
415
|
}
|
|
421
416
|
return {
|
|
422
417
|
lastHash: e,
|
|
423
418
|
lastCommitter: r,
|
|
424
|
-
lastCommitterPinYin:
|
|
425
|
-
style:
|
|
419
|
+
lastCommitterPinYin: y(r, {
|
|
420
|
+
style: y.STYLE_NORMAL,
|
|
426
421
|
heteronym: !1
|
|
427
422
|
}).join(""),
|
|
428
|
-
lastCommitEmail:
|
|
423
|
+
lastCommitEmail: n,
|
|
429
424
|
lastCommitMsg: s,
|
|
430
|
-
userName:
|
|
431
|
-
userNamePinYin:
|
|
432
|
-
style:
|
|
425
|
+
userName: o,
|
|
426
|
+
userNamePinYin: y(o, {
|
|
427
|
+
style: y.STYLE_NORMAL,
|
|
433
428
|
heteronym: !1
|
|
434
429
|
}).join(""),
|
|
435
430
|
userEmail: c,
|
|
436
431
|
branchName: i,
|
|
437
|
-
remoteInfo:
|
|
432
|
+
remoteInfo: u ? {
|
|
438
433
|
alias: t,
|
|
439
|
-
url:
|
|
434
|
+
url: u
|
|
440
435
|
} : void 0
|
|
441
436
|
};
|
|
442
437
|
} catch (e) {
|
|
443
|
-
throw
|
|
438
|
+
throw a.error("获取git最后提交信息失败"), e;
|
|
444
439
|
}
|
|
445
440
|
}, Y = (t = "") => {
|
|
446
441
|
const e = /\s*Merge\s+branch\s+['|"](.+)['|"]\s+into\s+['|"](.+)['|"]\s*/i, r = t.match(e);
|
|
447
442
|
if (r) {
|
|
448
|
-
const [, i,
|
|
443
|
+
const [, i, u] = r;
|
|
449
444
|
return {
|
|
450
445
|
fromBranch: i,
|
|
451
|
-
toBranch:
|
|
446
|
+
toBranch: u
|
|
452
447
|
};
|
|
453
448
|
}
|
|
454
|
-
const
|
|
449
|
+
const n = /\s*Merge\s+branch\s+['|"](.+)['|"]\s+of\s+.+\s+into\s+['|"](.+)['|"]\s*/i, s = t.match(n);
|
|
455
450
|
if (s) {
|
|
456
|
-
const [, i,
|
|
451
|
+
const [, i, u] = s;
|
|
457
452
|
return {
|
|
458
453
|
fromBranch: i,
|
|
459
|
-
toBranch:
|
|
454
|
+
toBranch: u
|
|
460
455
|
};
|
|
461
456
|
}
|
|
462
|
-
const
|
|
457
|
+
const o = /\s*Merge\s+branch\s+['|"](.+)['|"](\s+of)?\s*/i, c = t.match(o);
|
|
463
458
|
if (c) {
|
|
464
459
|
const [, i] = c;
|
|
465
460
|
return {
|
|
466
461
|
fromBranch: i
|
|
467
462
|
};
|
|
468
463
|
}
|
|
469
|
-
},
|
|
470
|
-
if (t.startsWith(
|
|
464
|
+
}, It = (t) => {
|
|
465
|
+
if (t.startsWith(b.MERGE))
|
|
471
466
|
return {
|
|
472
|
-
fromBranch: t.replace(
|
|
467
|
+
fromBranch: t.replace(b.MERGE, "").trim()
|
|
473
468
|
};
|
|
474
|
-
},
|
|
469
|
+
}, Ee = () => {
|
|
475
470
|
const t = process.env.GIT_REFLOG_ACTION || "";
|
|
476
471
|
if (!t)
|
|
477
472
|
return;
|
|
478
473
|
const e = /merge\s+([^\s]+)\s*/i, r = t.match(e);
|
|
479
474
|
if (r) {
|
|
480
|
-
const [,
|
|
475
|
+
const [, o] = r;
|
|
481
476
|
return {
|
|
482
|
-
fromBranch:
|
|
477
|
+
fromBranch: o
|
|
483
478
|
};
|
|
484
479
|
}
|
|
485
|
-
const
|
|
480
|
+
const n = /pull\s+([^\s]+)\s+([^\s]+)/, s = t.match(n);
|
|
486
481
|
if (s) {
|
|
487
|
-
const [, ,
|
|
482
|
+
const [, , o] = s;
|
|
488
483
|
return {
|
|
489
|
-
fromBranch:
|
|
484
|
+
fromBranch: o
|
|
490
485
|
};
|
|
491
486
|
}
|
|
492
487
|
};
|
|
493
|
-
var
|
|
494
|
-
const
|
|
488
|
+
var b = /* @__PURE__ */ ((t) => (t.CHECKOUT = "checkout", t.MERGE = "merge", t.COMMIT = "commit", t.COMMIT_MERGE = "commit (merge)", t.PULL = "pull", t.RESET = "reset", t.REBASE_START = "rebase (start)", t.REBASE_FINISH = "rebase (finish)", t.REBASE_ABORT = "rebase (abort)", t.REBASE_CONTINUE = "rebase (continue)", t))(b || {});
|
|
489
|
+
const B = "__GIT_REPLACE_MARK__", O = {
|
|
495
490
|
stringify(t) {
|
|
496
|
-
return JSON.stringify(t).replace(/"/g,
|
|
491
|
+
return JSON.stringify(t).replace(/"/g, B);
|
|
497
492
|
},
|
|
498
493
|
parse(t) {
|
|
499
|
-
return JSON.parse(t.replace(new RegExp(
|
|
494
|
+
return JSON.parse(t.replace(new RegExp(B, "g"), '"'));
|
|
500
495
|
}
|
|
501
|
-
},
|
|
496
|
+
}, ye = ({
|
|
502
497
|
count: t = 100
|
|
503
498
|
} = {}) => {
|
|
504
499
|
if (t <= 0)
|
|
@@ -520,19 +515,19 @@ const L = "__GIT_REPLACE_MARK__", v = {
|
|
|
520
515
|
/** 提交日期 */
|
|
521
516
|
commitTime: "%ci"
|
|
522
517
|
};
|
|
523
|
-
return
|
|
524
|
-
`git --no-pager log --oneline -n ${t} --pretty=format:"${
|
|
518
|
+
return g(
|
|
519
|
+
`git --no-pager log --oneline -n ${t} --pretty=format:"${O.stringify(
|
|
525
520
|
e
|
|
526
521
|
)}"`
|
|
527
522
|
).toString().split(`
|
|
528
|
-
`).map((
|
|
529
|
-
const c =
|
|
523
|
+
`).map((o) => {
|
|
524
|
+
const c = O.parse(o);
|
|
530
525
|
return {
|
|
531
526
|
...c,
|
|
532
527
|
mergeInfo: Y(c.message)
|
|
533
528
|
};
|
|
534
529
|
});
|
|
535
|
-
},
|
|
530
|
+
}, _e = ({
|
|
536
531
|
count: t = 100,
|
|
537
532
|
filterItem: e = () => !0
|
|
538
533
|
} = {}) => {
|
|
@@ -545,201 +540,197 @@ const L = "__GIT_REPLACE_MARK__", v = {
|
|
|
545
540
|
committerEmail: "%ce",
|
|
546
541
|
commitTime: "%ci"
|
|
547
542
|
};
|
|
548
|
-
return
|
|
549
|
-
`git --no-pager reflog -n ${t} --pretty=format:"${
|
|
543
|
+
return g(
|
|
544
|
+
`git --no-pager reflog -n ${t} --pretty=format:"${O.stringify(
|
|
550
545
|
r
|
|
551
546
|
)}"`
|
|
552
547
|
).toString().split(`
|
|
553
|
-
`).map((i) =>
|
|
554
|
-
const { fullMessage:
|
|
555
|
-
let
|
|
556
|
-
if (
|
|
548
|
+
`).map((i) => O.parse(i)).filter(e).map((i) => {
|
|
549
|
+
const { fullMessage: u, ...f } = i, p = ":", [S] = u.split(p, 1), $ = u.slice(`${S}${p}`.length), h = S.trim(), E = $.trim();
|
|
550
|
+
let M, N, X;
|
|
551
|
+
if (h.startsWith(
|
|
557
552
|
"checkout"
|
|
558
553
|
/* CHECKOUT */
|
|
559
554
|
))
|
|
560
|
-
|
|
561
|
-
else if (
|
|
555
|
+
N = dt(E);
|
|
556
|
+
else if (h.startsWith(
|
|
562
557
|
"merge"
|
|
563
558
|
/* MERGE */
|
|
564
559
|
))
|
|
565
|
-
|
|
566
|
-
else if (
|
|
560
|
+
M = It(h);
|
|
561
|
+
else if (h.startsWith(
|
|
567
562
|
"commit (merge)"
|
|
568
563
|
/* COMMIT_MERGE */
|
|
569
564
|
)) {
|
|
570
|
-
const
|
|
571
|
-
|
|
565
|
+
const L = Y(E);
|
|
566
|
+
L || a.warn(
|
|
572
567
|
`${i.hash} 是合并提交 但是未从提交信息(${E})中检测到合并分支信息,推测手动更改了提交内容`
|
|
573
|
-
),
|
|
568
|
+
), M = L;
|
|
574
569
|
}
|
|
575
570
|
return {
|
|
576
|
-
...
|
|
577
|
-
type:
|
|
571
|
+
...f,
|
|
572
|
+
type: h,
|
|
578
573
|
message: E,
|
|
579
|
-
mergeInfo:
|
|
580
|
-
checkoutInfo:
|
|
574
|
+
mergeInfo: M,
|
|
575
|
+
checkoutInfo: N,
|
|
581
576
|
rebaseInfo: X
|
|
582
577
|
};
|
|
583
578
|
});
|
|
584
|
-
},
|
|
585
|
-
const e =
|
|
586
|
-
if (m.existsSync(
|
|
579
|
+
}, Re = (t) => {
|
|
580
|
+
const e = I(t), r = l.resolve(e, ".git"), n = l.resolve(r, "rebase-merge");
|
|
581
|
+
if (m.existsSync(n))
|
|
587
582
|
return !0;
|
|
588
583
|
const s = l.resolve(r, "rebase-apply");
|
|
589
584
|
if (m.existsSync(s))
|
|
590
585
|
return !0;
|
|
591
|
-
const
|
|
592
|
-
return !!m.existsSync(
|
|
593
|
-
},
|
|
586
|
+
const o = l.resolve(r, "REBASE_HEAD");
|
|
587
|
+
return !!m.existsSync(o);
|
|
588
|
+
}, Ce = ({
|
|
594
589
|
branchName: t,
|
|
595
590
|
version: e,
|
|
596
591
|
remoteInfo: r
|
|
597
592
|
}) => {
|
|
598
|
-
r && (
|
|
593
|
+
r && (g(`git push ${r.alias} v${e}`, {
|
|
599
594
|
stdio: "inherit"
|
|
600
|
-
}),
|
|
595
|
+
}), g(`git push ${r.alias} ${t}`, {
|
|
601
596
|
stdio: "inherit"
|
|
602
597
|
}));
|
|
603
|
-
},
|
|
598
|
+
}, $t = (t) => /^https?:\/\//.test(t), Mt = (t) => /^git@/.test(t), Oe = (t) => {
|
|
604
599
|
const { hostname: e, pathname: r } = new URL(t);
|
|
605
600
|
return `git@${e}:${r.replace("/", "")}`;
|
|
606
|
-
}, W = ".done-coding",
|
|
601
|
+
}, W = ".done-coding", At = `${W}/cli/assets-config`, Pt = "assets", wt = "index.json", bt = `${W}/config.json`, Tt = "https://gitee.com/justsosu/done-coding-cli-assets-config.git", Dt = ({
|
|
607
602
|
dir: t,
|
|
608
603
|
fn: e,
|
|
609
604
|
endClear: r = !0,
|
|
610
|
-
exitClear:
|
|
605
|
+
exitClear: n = !0
|
|
611
606
|
}) => {
|
|
612
607
|
if (V(t))
|
|
613
|
-
return
|
|
608
|
+
return a.error(`${t} 已存在,请手动删除该目录再试`), process.exit(1);
|
|
614
609
|
const s = () => {
|
|
615
|
-
|
|
610
|
+
a.stage("正在清理临时目录...", t), Et(t);
|
|
616
611
|
};
|
|
617
|
-
|
|
618
|
-
|
|
612
|
+
n && process.once("exit", () => {
|
|
613
|
+
a.stage("发现进程退出,正在清理临时目录...", t), s();
|
|
619
614
|
});
|
|
620
|
-
let
|
|
615
|
+
let o;
|
|
621
616
|
try {
|
|
622
|
-
|
|
617
|
+
o = e(t);
|
|
623
618
|
} catch (c) {
|
|
624
619
|
throw r && s(), c;
|
|
625
620
|
}
|
|
626
|
-
return r && (
|
|
621
|
+
return r && (o instanceof Promise ? o.finally(s) : s()), o;
|
|
627
622
|
};
|
|
628
|
-
var
|
|
629
|
-
const
|
|
630
|
-
|
|
631
|
-
|
|
623
|
+
var Nt = /* @__PURE__ */ ((t) => (t.ASSETS_CONFIG_REPO_URL = "ASSETS_CONFIG_REPO_URL", t))(Nt || {});
|
|
624
|
+
const Lt = (t) => l.resolve(
|
|
625
|
+
st(),
|
|
626
|
+
At,
|
|
632
627
|
`${t}-${ot()}`
|
|
633
|
-
), Bt = () => l.resolve(
|
|
634
|
-
const t = Bt()
|
|
635
|
-
|
|
636
|
-
const e = {
|
|
637
|
-
ASSETS_CONFIG_REPO_URL: wt
|
|
628
|
+
), Bt = () => l.resolve(nt(), bt), Ft = async () => {
|
|
629
|
+
const t = Bt(), e = {
|
|
630
|
+
ASSETS_CONFIG_REPO_URL: Tt
|
|
638
631
|
};
|
|
639
632
|
try {
|
|
640
|
-
if (await
|
|
633
|
+
if (await D(t)) {
|
|
641
634
|
const r = await K(t, {});
|
|
642
|
-
Object.entries(r).forEach(([
|
|
643
|
-
e[
|
|
635
|
+
Object.entries(r).forEach(([n, s]) => {
|
|
636
|
+
e[n] = s;
|
|
644
637
|
});
|
|
645
638
|
}
|
|
646
639
|
} catch {
|
|
647
640
|
}
|
|
648
|
-
return
|
|
649
|
-
},
|
|
650
|
-
if (
|
|
651
|
-
return
|
|
652
|
-
p.red(`${t} 已存在,请手动删除该目录再试`)
|
|
653
|
-
), process.exit(1);
|
|
641
|
+
return e;
|
|
642
|
+
}, Gt = async (t) => {
|
|
643
|
+
if (await D(t))
|
|
644
|
+
return a.error(`${t} 已存在,请手动删除该目录再试`), process.exit(1);
|
|
654
645
|
const {
|
|
655
646
|
[
|
|
656
647
|
"ASSETS_CONFIG_REPO_URL"
|
|
657
648
|
/* ASSETS_CONFIG_REPO_URL */
|
|
658
649
|
]: e
|
|
659
|
-
} = await
|
|
660
|
-
return
|
|
650
|
+
} = await Ft();
|
|
651
|
+
return Mt(e) || $t(e) ? g(`git clone ${e} ${t} --depth=1`) : (m.mkdirSync(t, { recursive: !0 }), g(`cp -r ${e}/ ${t}/`)), {
|
|
661
652
|
assetConfigRepoUrl: e
|
|
662
653
|
};
|
|
663
|
-
},
|
|
654
|
+
}, ve = async ({
|
|
664
655
|
moduleName: t,
|
|
665
656
|
onSuccess: e
|
|
666
|
-
}) => (
|
|
657
|
+
}) => (a.stage(`拉取${t}配置,请稍等...`), Dt({
|
|
667
658
|
// 资源配置仓库临时文件夹
|
|
668
|
-
dir:
|
|
659
|
+
dir: Lt(t),
|
|
669
660
|
fn: async (r) => {
|
|
670
|
-
const { assetConfigRepoUrl:
|
|
671
|
-
|
|
661
|
+
const { assetConfigRepoUrl: n } = await Gt(r), s = l.join(
|
|
662
|
+
Pt,
|
|
672
663
|
t
|
|
673
|
-
),
|
|
664
|
+
), o = l.join(
|
|
674
665
|
s,
|
|
675
|
-
|
|
676
|
-
), c = l.resolve(r,
|
|
666
|
+
wt
|
|
667
|
+
), c = l.resolve(r, o), i = await K(c);
|
|
677
668
|
return await e({
|
|
678
|
-
repoUrl:
|
|
669
|
+
repoUrl: n,
|
|
679
670
|
config: i,
|
|
680
671
|
moduleDirFileRelativePath: s,
|
|
681
|
-
moduleEntryFileRelativePath:
|
|
672
|
+
moduleEntryFileRelativePath: o,
|
|
682
673
|
assetsConfigRepoTempDir: r
|
|
683
674
|
}), i;
|
|
684
675
|
}
|
|
685
676
|
}));
|
|
686
677
|
export {
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
678
|
+
Nt as DoneCodingCliGlobalConfigKeyEnum,
|
|
679
|
+
at as EditorTypeEnum,
|
|
680
|
+
b as GitRefLogTypeEnum,
|
|
681
|
+
d as HooksNameEnum,
|
|
682
|
+
he as SUPPORT_GET_COMMIT_BY_HOOKS_NAMES,
|
|
683
|
+
Be as _curry,
|
|
693
684
|
Te as _get,
|
|
694
685
|
Ne as _set,
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
686
|
+
pe as addHuskyHooks,
|
|
687
|
+
le as addPackageConfig,
|
|
688
|
+
Dt as applyUseTempDir,
|
|
698
689
|
V as assetIsExits,
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
690
|
+
D as assetIsExitsAsync,
|
|
691
|
+
Re as checkCurrentIsRebasing,
|
|
692
|
+
ne as createMainCommand,
|
|
693
|
+
oe as createSubcommand,
|
|
694
|
+
re as decryptAES,
|
|
695
|
+
ee as encryptAES,
|
|
696
|
+
St as fileAddX,
|
|
697
|
+
Lt as getCliModuleTempDir,
|
|
698
|
+
de as getCommitByHookName,
|
|
699
|
+
ie as getConfigFileCommonOptions,
|
|
700
|
+
ye as getCurrentBranchLastCommitList,
|
|
701
|
+
ue as getCurrentBranchName,
|
|
702
|
+
ft as getEditorType,
|
|
703
|
+
Se as getGitLastCommitInfo,
|
|
704
|
+
I as getGitProjectDir,
|
|
705
|
+
_e as getLastReflogList,
|
|
706
|
+
Zt as getLogText,
|
|
707
|
+
T as getPackageJson,
|
|
708
|
+
ht as getRelyPkgVersion,
|
|
709
|
+
mt as getRootDirOptions,
|
|
710
|
+
se as getRootScriptName,
|
|
711
|
+
fe as getUseDefaultConfig,
|
|
712
|
+
Oe as http2sshGitUrl,
|
|
713
|
+
pt as initConfigFile,
|
|
714
|
+
ce as initHandlerCommon,
|
|
715
|
+
$t as isHttpGitUrl,
|
|
716
|
+
Mt as isSshGitUrl,
|
|
726
717
|
Ae as json5,
|
|
727
|
-
|
|
728
|
-
|
|
718
|
+
a as log,
|
|
719
|
+
te as lookForParentTarget,
|
|
729
720
|
gt as openFileInEditor,
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
721
|
+
Ce as pushGitPublishInfoToRemote,
|
|
722
|
+
ve as readCliModuleAssetsConfig,
|
|
723
|
+
ae as readConfigFile,
|
|
733
724
|
yt as readFile,
|
|
734
|
-
|
|
735
|
-
|
|
725
|
+
_t as readFileAsync,
|
|
726
|
+
me as readJsonFile,
|
|
736
727
|
K as readJsonFileAsync,
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
728
|
+
Et as removeAsset,
|
|
729
|
+
ge as removeAssetAsync,
|
|
730
|
+
dt as resolveCheckoutInfoByRefInfo,
|
|
740
731
|
Y as resolveMergeInfoByCommitMsg,
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
732
|
+
Ee as resolveMergeInfoByGitReflogAction,
|
|
733
|
+
It as resolveMergeInfoByRefType,
|
|
734
|
+
we as uuidv4,
|
|
735
|
+
U as xPrompts
|
|
745
736
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-utils",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "cli utils",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"uuid": "^11.1.0",
|
|
71
71
|
"yargs": "^17.7.2"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "0930f800167c04a86b56eae9741872dd51bec0c6"
|
|
74
74
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ArgumentsCamelCase } from 'yargs';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
2
|
import type { CommandModule } from 'yargs';
|
|
4
3
|
import _curry from 'lodash.curry';
|
|
5
4
|
import _get from 'lodash.get';
|
|
@@ -60,8 +59,6 @@ export declare const assetIsExits: (assetPath: string) => boolean;
|
|
|
60
59
|
*/
|
|
61
60
|
export declare const assetIsExitsAsync: (path: string) => Promise<boolean>;
|
|
62
61
|
|
|
63
|
-
export { chalk }
|
|
64
|
-
|
|
65
62
|
/** 检测当前正在变基 */
|
|
66
63
|
export declare const checkCurrentIsRebasing: (rootDir: string) => boolean;
|
|
67
64
|
|
|
@@ -214,6 +211,22 @@ export declare const getLastReflogList: ({ count, filterItem, }?: {
|
|
|
214
211
|
filterItem?: ((item: GitReflogItemInfoRaw) => boolean) | undefined;
|
|
215
212
|
}) => GitReflogItemInfo[];
|
|
216
213
|
|
|
214
|
+
/** 获取输出文字 */
|
|
215
|
+
export declare const getLogText: ((type: LogTypeEnum, ...messages: unknown[]) => string) & {
|
|
216
|
+
/** 成功 */
|
|
217
|
+
success: (...messages: unknown[]) => string;
|
|
218
|
+
/** /步骤 */
|
|
219
|
+
stage: (...messages: unknown[]) => string;
|
|
220
|
+
/** 提示信息 */
|
|
221
|
+
info: (...messages: unknown[]) => string;
|
|
222
|
+
/** 警告 */
|
|
223
|
+
warn: (...messages: unknown[]) => string;
|
|
224
|
+
/** 错误 */
|
|
225
|
+
error: (...messages: unknown[]) => string;
|
|
226
|
+
/** 跳过 */
|
|
227
|
+
skip: (...messages: unknown[]) => string;
|
|
228
|
+
};
|
|
229
|
+
|
|
217
230
|
/** 获取package.json文件内容 */
|
|
218
231
|
export declare const getPackageJson: <R extends PackageJson>({ rootDir, }: {
|
|
219
232
|
rootDir: string;
|
|
@@ -434,21 +447,23 @@ export declare const isSshGitUrl: (url: string) => boolean;
|
|
|
434
447
|
export { json5 }
|
|
435
448
|
|
|
436
449
|
/** 日志 */
|
|
437
|
-
export declare const log: ((type: LogTypeEnum, ...messages:
|
|
450
|
+
export declare const log: ((type: LogTypeEnum, ...messages: unknown[]) => void) & {
|
|
438
451
|
/** 成功 */
|
|
439
|
-
success: (...messages:
|
|
452
|
+
success: (...messages: unknown[]) => void;
|
|
440
453
|
/** /步骤 */
|
|
441
|
-
stage: (...messages:
|
|
454
|
+
stage: (...messages: unknown[]) => void;
|
|
442
455
|
/** 提示信息 */
|
|
443
|
-
info: (...messages:
|
|
456
|
+
info: (...messages: unknown[]) => void;
|
|
444
457
|
/** 警告 */
|
|
445
|
-
warn: (...messages:
|
|
458
|
+
warn: (...messages: unknown[]) => void;
|
|
446
459
|
/** 错误 */
|
|
447
|
-
error: (...messages:
|
|
460
|
+
error: (...messages: unknown[]) => void;
|
|
448
461
|
/** 跳过 */
|
|
449
|
-
skip: (...messages:
|
|
462
|
+
skip: (...messages: unknown[]) => void;
|
|
450
463
|
};
|
|
451
464
|
|
|
465
|
+
export declare type LogParams = [type: LogTypeEnum, ...messages: unknown[]];
|
|
466
|
+
|
|
452
467
|
/** 日志类型 */
|
|
453
468
|
declare enum LogTypeEnum {
|
|
454
469
|
/** 成功 */
|