@done-coding/cli-utils 0.5.0-alpha.0 → 0.6.0-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/index.mjs CHANGED
@@ -1,52 +1,55 @@
1
1
  #!/usr/bin/env node
2
- import O from "chalk";
3
- import { default as pt } from "chalk";
2
+ import u from "chalk";
3
+ import { default as Ae } from "chalk";
4
4
  import g from "node:path";
5
- import b, { existsSync as y, mkdirSync as H, writeFileSync as C, readFileSync as d } from "node:fs";
6
- import m from "crypto";
7
- import D from "prompts";
5
+ import d, { existsSync as p, mkdirSync as j, writeFileSync as S, readFileSync as $, rmSync as A } from "node:fs";
6
+ import y from "crypto";
7
+ import I from "prompts";
8
8
  import N from "yargs";
9
- import { hideBin as A } from "yargs/helpers";
10
- import { execSync as a } from "node:child_process";
11
- import v from "json5";
9
+ import { hideBin as M } from "yargs/helpers";
10
+ import { execSync as f } from "node:child_process";
11
+ import k from "json5";
12
12
  export * from "json5";
13
- import { default as yt } from "json5";
14
- import u from "pinyin";
15
- import { default as Ct } from "lodash.get";
16
- import { default as $t } from "lodash.set";
17
- import { default as wt } from "lodash.curry";
18
- const c = Object.assign(
19
- (t, ...r) => console.log(...r.map((e) => O[t](e))),
13
+ import { default as Me } from "json5";
14
+ import Y from "lodash.merge";
15
+ import m from "pinyin";
16
+ import J from "semver";
17
+ import { tmpdir as L } from "node:os";
18
+ import { default as Je } from "lodash.get";
19
+ import { default as Ge } from "lodash.set";
20
+ import { default as Be } from "lodash.curry";
21
+ const a = Object.assign(
22
+ (e, ...o) => console.log(...o.map((t) => u[e](t))),
20
23
  {
21
24
  /** 成功 */
22
- success: (...t) => c("green", ...t),
25
+ success: (...e) => a("green", ...e),
23
26
  /** /步骤 */
24
- stage: (...t) => c("blue", ...t),
27
+ stage: (...e) => a("blue", ...e),
25
28
  /** 提示信息 */
26
- info: (...t) => c("cyan", ...t),
29
+ info: (...e) => a("cyan", ...e),
27
30
  /** 警告 */
28
- warn: (...t) => c("yellow", ...t),
31
+ warn: (...e) => a("yellow", ...e),
29
32
  /** 错误 */
30
- error: (...t) => c("red", ...t),
33
+ error: (...e) => a("red", ...e),
31
34
  /** 跳过 */
32
- skip: (...t) => c("gray", ...t)
35
+ skip: (...e) => a("gray", ...e)
33
36
  }
34
- ), tt = (t, {
37
+ ), Se = (e, {
35
38
  /** 当前目录 */
36
- currentDir: r = process.cwd(),
39
+ currentDir: o = process.cwd(),
37
40
  /** 优先找最远的父目录 */
38
- isFindFarthest: e = !0
41
+ isFindFarthest: t = !0
39
42
  } = {}) => {
40
- const n = g.resolve(r).split(g.sep).map((o, i, l) => i ? g.join(l.slice(0, i).join(g.sep), o) : o);
41
- for (; n.length; ) {
42
- const o = e ? n.shift() : n.pop(), i = g.join(o, t);
43
- if (b.existsSync(i))
44
- return o;
43
+ const r = g.resolve(o).split(g.sep).map((n, s, c) => s ? g.join(c.slice(0, s).join(g.sep), n) : n);
44
+ for (; r.length; ) {
45
+ const n = t ? r.shift() : r.pop(), s = g.join(n, e);
46
+ if (d.existsSync(s))
47
+ return n;
45
48
  }
46
- }, $ = "aes-256-cbc", P = 16, p = "hex", h = ":";
47
- function w(t) {
48
- return m.pbkdf2Sync(
49
- t,
49
+ }, w = "aes-256-cbc", _ = 16, h = "hex", v = ":";
50
+ function P(e) {
51
+ return y.pbkdf2Sync(
52
+ e,
50
53
  "done-coding-cli-salt",
51
54
  // 使用固定的盐值
52
55
  1e4,
@@ -56,84 +59,84 @@ function w(t) {
56
59
  "sha256"
57
60
  );
58
61
  }
59
- function rt({
60
- text: t,
61
- secretKey: r
62
+ function $e({
63
+ text: e,
64
+ secretKey: o
62
65
  }) {
63
66
  try {
64
- const e = w(r), n = m.randomBytes(P), o = m.createCipheriv($, e, n);
65
- let i = o.update(t);
66
- i = Buffer.concat([i, o.final()]);
67
- const l = n.toString(p), s = i.toString(p);
68
- return `${l}${h}${s}`;
69
- } catch (e) {
70
- return c.error(
71
- `加密失败: ${e instanceof Error ? e.message : String(e)}`
67
+ const t = P(o), r = y.randomBytes(_), n = y.createCipheriv(w, t, r);
68
+ let s = n.update(e);
69
+ s = Buffer.concat([s, n.final()]);
70
+ const c = r.toString(h), i = s.toString(h);
71
+ return `${c}${v}${i}`;
72
+ } catch (t) {
73
+ return a.error(
74
+ `加密失败: ${t instanceof Error ? t.message : String(t)}`
72
75
  ), "";
73
76
  }
74
77
  }
75
- function et({
76
- encryptedText: t,
77
- secretKey: r
78
+ function ve({
79
+ encryptedText: e,
80
+ secretKey: o
78
81
  }) {
79
82
  try {
80
- if (!t.includes(h))
83
+ if (!e.includes(v))
81
84
  return "";
82
- const e = w(r), [n, o] = t.split(h);
83
- if (n.length !== P * 2)
85
+ const t = P(o), [r, n] = e.split(v);
86
+ if (r.length !== _ * 2)
84
87
  return "";
85
- const i = Buffer.from(n, p), l = Buffer.from(o, p), s = m.createDecipheriv($, e, i);
86
- let f = s.update(l);
87
- return f = Buffer.concat([f, s.final()]), f.toString();
88
- } catch (e) {
89
- return c.error(
90
- `解密失败: ${e instanceof Error ? e.message : String(e)}`
88
+ const s = Buffer.from(r, h), c = Buffer.from(n, h), i = y.createDecipheriv(w, t, s);
89
+ let l = i.update(c);
90
+ return l = Buffer.concat([l, i.final()]), l.toString();
91
+ } catch (t) {
92
+ return a.error(
93
+ `解密失败: ${t instanceof Error ? t.message : String(t)}`
91
94
  ), "";
92
95
  }
93
96
  }
94
- const E = (...t) => {
95
- const [r, e = {}] = t;
96
- return D(r, {
97
- onCancel(n) {
98
- return c.error(`退出${n == null ? void 0 : n.name}输入`), process.exit(1);
97
+ const D = (...e) => {
98
+ const [o, t = {}] = e;
99
+ return I(o, {
100
+ onCancel(r) {
101
+ return a.error(`退出${r == null ? void 0 : r.name}输入`), process.exit(1);
99
102
  },
100
- ...e
103
+ ...t
101
104
  });
102
- }, R = (t, r) => {
103
- t ? c.error(t) : c.error(r.message), r != null && r.stack && c.error(r.stack), process.exit(1);
104
- }, T = () => {
105
- const t = A(process.argv);
106
- return N(t);
107
- }, j = (t, {
108
- usage: r,
109
- version: e,
110
- demandCommandCount: n,
111
- options: o,
112
- positionals: i,
113
- subcommands: l
105
+ }, G = (e, o) => {
106
+ e ? a.error(e) : a.error(o.message), o != null && o.stack && a.error(o.stack), process.exit(1);
107
+ }, V = () => {
108
+ const e = M(process.argv);
109
+ return N(e);
110
+ }, x = (e, {
111
+ usage: o,
112
+ version: t,
113
+ demandCommandCount: r,
114
+ options: n,
115
+ positionals: s,
116
+ subcommands: c
114
117
  }) => {
115
- let s = t.strict();
116
- r && (s = s.usage(`Usage: ${r}`)), n && (s = s.demandCommand(n));
117
- const f = "help";
118
- return s = s.help(f), e ? s = s.version(e).alias("h", f).alias("v", "version") : s = s.alias("h", f), o && (s = s.options(o)), i && (s = Object.entries(i).reduce((S, [k, x]) => S.positional(k, x), s)), l && (s = s.command(l)), s;
119
- }, ot = async ({ handler: t, ...r }) => {
120
- const e = await j(T(), r).fail(R).argv;
121
- return t ? t(e) : e;
122
- }, nt = (t) => {
123
- const { command: r, describe: e, handler: n = () => {
124
- }, ...o } = t;
118
+ let i = e.strict();
119
+ o && (i = i.usage(`Usage: ${o}`)), r && (i = i.demandCommand(r));
120
+ const l = "help";
121
+ return i = i.help(l), t ? i = i.version(t).alias("h", l).alias("v", "version") : i = i.alias("h", l), n && (i = i.options(n)), s && (i = Object.entries(s).reduce((E, [H, T]) => E.positional(H, T), i)), c && (i = i.command(c)), i;
122
+ }, Re = async ({ handler: e, ...o }) => {
123
+ const t = await x(V(), o).fail(G).argv;
124
+ return e ? e(t) : t;
125
+ }, Ee = (e) => {
126
+ const { command: o, describe: t, handler: r = () => {
127
+ }, ...n } = e;
125
128
  return {
126
- command: r,
127
- describe: e,
128
- builder(i) {
129
- return j(i, o);
129
+ command: o,
130
+ describe: t,
131
+ builder(s) {
132
+ return x(s, n);
130
133
  },
131
- handler: n
134
+ handler: r
132
135
  };
133
136
  };
134
- var _ = /* @__PURE__ */ ((t) => (t.VSCODE = "VsCode", t.CURSOR = "Cursor", t.OTHER = "其他", t))(_ || {});
135
- const L = async () => {
136
- const { editorType: t } = await E([
137
+ var B = /* @__PURE__ */ ((e) => (e.VSCODE = "VsCode", e.CURSOR = "Cursor", e.OTHER = "其他", e))(B || {});
138
+ const K = async () => {
139
+ const { editorType: e } = await D([
137
140
  {
138
141
  name: "editorType",
139
142
  type: "select",
@@ -143,169 +146,302 @@ const L = async () => {
143
146
  "VsCode",
144
147
  "其他"
145
148
  /* OTHER */
146
- ].map((r) => ({
147
- title: r,
148
- value: r
149
+ ].map((o) => ({
150
+ title: o,
151
+ value: o
149
152
  }))
150
153
  }
151
154
  ]);
152
- return t;
153
- }, F = {
155
+ return e;
156
+ }, U = {
154
157
  Cursor: "cursor",
155
158
  VsCode: "code"
156
- }, M = (t, r, e) => {
159
+ }, W = (e, o, t) => {
157
160
  try {
158
- a(`${t} -v`, { stdio: "ignore" }), a(`${t} ${r}`);
161
+ f(`${e} -v`, { stdio: "ignore" }), f(`${e} ${o}`);
159
162
  } catch {
160
- e();
163
+ t();
161
164
  }
162
- }, B = (t, r) => {
163
- const e = (n) => c.info(`
164
- ${n}, 请用编辑器打开 ${t} 进行编辑
165
+ }, X = (e, o) => {
166
+ const t = (r) => a.info(`
167
+ ${r}, 请用编辑器打开 ${e} 进行编辑
165
168
  `);
166
- switch (r) {
169
+ switch (o) {
167
170
  case "Cursor":
168
171
  case "VsCode": {
169
- const n = F[r];
170
- M(n, t, () => {
171
- e(`${n}命令未安装`);
172
+ const r = U[o];
173
+ W(r, e, () => {
174
+ t(`${r}命令未安装`);
172
175
  });
173
176
  break;
174
177
  }
175
178
  default:
176
- e("其他编辑器");
179
+ t("其他编辑器");
177
180
  }
178
- }, J = (t = process.cwd()) => ({
181
+ }, q = (e = process.cwd()) => ({
179
182
  /** 必须保留 */
180
183
  rootDir: {
181
184
  type: "string",
182
185
  alias: "R",
183
186
  describe: "运行目录",
184
187
  /** 必须设置默认值 */
185
- default: t
188
+ default: e
186
189
  }
187
- }), it = ({
188
- configPathDefault: t,
189
- rootDirDefault: r
190
+ }), Oe = ({
191
+ configPathDefault: e,
192
+ rootDirDefault: o
190
193
  }) => ({
191
194
  /** 必须保留 */
192
- ...J(r),
195
+ ...q(o),
193
196
  /** 必须保留 */
194
197
  configPath: {
195
198
  type: "string",
196
199
  alias: "C",
197
200
  describe: "配置文件相对路径",
198
201
  /** 必须设置默认值 */
199
- default: t
202
+ default: e
200
203
  }
201
- }), V = async (t, r) => {
202
- const { configPath: e, rootDir: n } = r, o = g.resolve(n, e), i = g.dirname(o);
203
- return y(i) || H(i, {
204
+ }), z = async (e, o) => {
205
+ const { configPath: t, rootDir: r } = o, n = g.resolve(r, t), s = g.dirname(n);
206
+ return p(s) || j(s, {
204
207
  recursive: !0
205
- }), o.endsWith(".json5") ? (c.info(`json5模式写入 ${o}`), C(o, v.stringify(t, null, 2)), o) : (c.info(`json模式写入 ${o}`), C(o, JSON.stringify(t, null, 2)), o);
206
- }, st = async (t, r, {
207
- onFileGenerated: e,
208
- edit: n = !1
208
+ }), n.endsWith(".json5") ? (a.info(`json5模式写入 ${n}`), S(n, k.stringify(e, null, 2)), n) : (a.info(`json模式写入 ${n}`), S(n, JSON.stringify(e, null, 2)), n);
209
+ }, ke = async (e, o, {
210
+ onFileGenerated: t,
211
+ edit: r = !1
209
212
  } = {}) => {
210
- const o = await V(t, r);
211
- if (e == null || e(o), n) {
212
- const i = await L();
213
- B(r.configPath, i);
213
+ const n = await z(e, o);
214
+ if (t == null || t(n), r) {
215
+ const s = await K();
216
+ X(o.configPath, s);
214
217
  }
215
- }, ct = async (t, r) => {
216
- const { configPath: e, rootDir: n } = t, o = g.resolve(n, e);
217
- if (!y(o)) {
218
- if (r)
219
- return c.info("配置文件不存在,使用onNotExists返回值"), r();
220
- const i = `配置文件不存在 ${o}`;
221
- throw new Error(i);
218
+ }, we = async (e, o) => {
219
+ const { configPath: t, rootDir: r } = e, n = g.resolve(r, t);
220
+ if (!p(n)) {
221
+ if (o)
222
+ return a.info("配置文件不存在,使用onNotExists返回值"), o();
223
+ const s = `配置文件不存在 ${n}`;
224
+ throw new Error(s);
222
225
  }
223
- return o.endsWith(".json5") ? (c.info(`json5模式解析 ${o}`), v.parse(d(o, "utf8"))) : (c.info(`json模式解析 ${o}`), JSON.parse(d(o, "utf8")));
224
- }, at = async () => {
225
- const { useDefaultConfig: t } = await E({
226
+ return n.endsWith(".json5") ? (a.info(`json5模式解析 ${n}`), k.parse($(n, "utf8"))) : (a.info(`json模式解析 ${n}`), JSON.parse($(n, "utf8")));
227
+ }, _e = async () => {
228
+ const { useDefaultConfig: e } = await D({
226
229
  name: "useDefaultConfig",
227
230
  type: "confirm",
228
231
  message: "使用默认模板配置",
229
232
  initial: !0
230
233
  });
231
- return t;
232
- }, Y = "./package.json", ft = ({
233
- rootDir: t
234
+ return e;
235
+ }, b = "package.json", R = ({
236
+ rootDir: e
234
237
  }) => {
235
- const r = g.resolve(t, Y);
236
- if (!y(r))
237
- throw new Error(`${t}未找到package.json文件`);
238
- const e = d(r, "utf-8");
239
- return JSON.parse(e);
240
- }, lt = ({
241
- remoteAlias: t
238
+ const o = g.resolve(e, b);
239
+ if (!p(o))
240
+ throw new Error(`${e}未找到package.json文件`);
241
+ const t = $(o, "utf-8");
242
+ return JSON.parse(t);
243
+ }, Q = ({
244
+ rootDir: e,
245
+ pkgJson: o,
246
+ pkgName: t,
247
+ isDevPkg: r
248
+ }) => {
249
+ const n = o || R({ rootDir: e }), s = r ? n.devDependencies : n.dependencies;
250
+ let c = s == null ? void 0 : s[t];
251
+ if (!c) {
252
+ const i = r ? n.dependencies : n.devDependencies;
253
+ c = i == null ? void 0 : i[t], c && console.log(
254
+ u.yellow(
255
+ `${r ? "开发" : "生产"}依赖包${t}可能错误的安装在${r ? "dependencies" : "devDependencies"}`
256
+ )
257
+ );
258
+ return;
259
+ }
260
+ return c || console.log(u.cyan(`依赖包${t}未安装`)), c;
261
+ }, Pe = ({
262
+ patchConfig: e,
263
+ rootDir: o
264
+ }) => {
265
+ if (!e)
266
+ return;
267
+ const t = R({ rootDir: o }), r = Y(t, e), n = g.resolve(o, b);
268
+ S(n, JSON.stringify(r, null, 2), "utf-8");
269
+ }, De = (e) => {
270
+ const t = f("git rev-parse --show-toplevel", {
271
+ cwd: e
272
+ }).toString();
273
+ if (!t)
274
+ throw new Error("获取git根目录失败");
275
+ return t.trim();
276
+ }, xe = ({
277
+ remoteAlias: e
242
278
  } = {}) => {
243
279
  try {
244
- const r = a("git rev-parse HEAD").toString().trim(), e = a('git log -1 --pretty=format:"%an"').toString().trim(), n = a('git log -1 --pretty=format:"%ae"').toString().trim(), o = a('git log -1 --pretty=format:"%s"').toString().trim(), i = a("git config user.name").toString().trim(), l = a("git config user.email").toString().trim(), s = a("git rev-parse --abbrev-ref HEAD").toString().trim();
245
- let f = "";
280
+ const o = f("git rev-parse HEAD").toString().trim(), t = f('git log -1 --pretty=format:"%an"').toString().trim(), r = f('git log -1 --pretty=format:"%ae"').toString().trim(), n = f('git log -1 --pretty=format:"%s"').toString().trim(), s = f("git config user.name").toString().trim(), c = f("git config user.email").toString().trim(), i = f("git rev-parse --abbrev-ref HEAD").toString().trim();
281
+ let l = "";
246
282
  try {
247
- f = a(`git config --get remote.${t}.url`).toString().trim();
283
+ l = f(`git config --get remote.${e}.url`).toString().trim();
248
284
  } catch {
249
- c.warn("git远程仓库地址获取失败或者不存在");
285
+ a.warn("git远程仓库地址获取失败或者不存在");
250
286
  }
251
287
  return {
252
- lastHash: r,
253
- lastCommitter: e,
254
- lastCommitterPinYin: u(e, {
255
- style: u.STYLE_NORMAL,
288
+ lastHash: o,
289
+ lastCommitter: t,
290
+ lastCommitterPinYin: m(t, {
291
+ style: m.STYLE_NORMAL,
256
292
  heteronym: !1
257
293
  }).join(""),
258
- lastCommitEmail: n,
259
- lastCommitMsg: o,
260
- userName: i,
261
- userNamePinYin: u(i, {
262
- style: u.STYLE_NORMAL,
294
+ lastCommitEmail: r,
295
+ lastCommitMsg: n,
296
+ userName: s,
297
+ userNamePinYin: m(s, {
298
+ style: m.STYLE_NORMAL,
263
299
  heteronym: !1
264
300
  }).join(""),
265
- userEmail: l,
266
- branchName: s,
267
- remoteInfo: f ? {
268
- alias: t,
269
- url: f
301
+ userEmail: c,
302
+ branchName: i,
303
+ remoteInfo: l ? {
304
+ alias: e,
305
+ url: l
270
306
  } : void 0
271
307
  };
272
- } catch (r) {
273
- throw c.error("获取git最后提交信息失败"), r;
308
+ } catch (o) {
309
+ throw a.error("获取git最后提交信息失败"), o;
274
310
  }
275
- }, gt = ({
276
- branchName: t,
277
- version: r,
278
- remoteInfo: e
311
+ }, be = ({
312
+ branchName: e,
313
+ version: o,
314
+ remoteInfo: t
279
315
  }) => {
280
- e && (a(`git push ${e.alias} v${r}`, {
316
+ t && (f(`git push ${t.alias} v${o}`, {
281
317
  stdio: "inherit"
282
- }), a(`git push ${e.alias} ${t}`, {
318
+ }), f(`git push ${t.alias} ${e}`, {
283
319
  stdio: "inherit"
284
320
  }));
321
+ }, C = 73, Z = (e) => {
322
+ const t = d.statSync(e).mode;
323
+ if ((t & C) === C)
324
+ return;
325
+ console.log(u.blue(`${e} 没有执行权限 添加... `));
326
+ const r = t | C;
327
+ d.chmodSync(e, r), console.log(u.green(`${e} 添加执行权限成功`));
328
+ }, ee = "husky", te = ".husky", oe = ({
329
+ projectRootDir: e
330
+ }) => {
331
+ const o = Q({
332
+ rootDir: e,
333
+ pkgJson: R({ rootDir: e }),
334
+ pkgName: ee,
335
+ isDevPkg: !0
336
+ });
337
+ if (!o)
338
+ throw new Error("husky版本获取失败, 可能husky未安装");
339
+ const t = o.replace(/^(\^|~)/, ""), r = "<9.0.0";
340
+ return J.satisfies(t, r) ? (console.log(u.cyan(`${t}符合${r}`)), `#!/usr/bin/env sh
341
+ . "$(dirname -- "$0")/_/husky.sh"`) : (console.log(u.cyan(`${t}不符合${r}`)), "");
342
+ }, re = ({
343
+ projectRootDir: e
344
+ }) => g.resolve(e, te), Fe = ({
345
+ hookNames: e,
346
+ projectRootDir: o,
347
+ getCode: t
348
+ }) => {
349
+ const r = re({ projectRootDir: o });
350
+ d.existsSync(r) || d.mkdirSync(r, { recursive: !0 }), e.forEach((n) => {
351
+ const s = g.resolve(r, n), c = d.existsSync(s);
352
+ let i = t(n);
353
+ if (c)
354
+ d.readFileSync(s, "utf-8").includes(i) ? console.log(
355
+ u.gray(`${s} ${n}相关调用 ${i} 已存在 跳过`)
356
+ ) : (d.appendFileSync(
357
+ s,
358
+ `
359
+ ${i}
360
+ `
361
+ ), console.log(u.green(`${s} 添加 ${n}相关调用成功`)));
362
+ else {
363
+ const l = oe({
364
+ projectRootDir: o
365
+ });
366
+ d.writeFileSync(
367
+ s,
368
+ `${l}
369
+
370
+ ${i}
371
+ `,
372
+ "utf-8"
373
+ ), console.log(u.green(`${s} 添加 ${n}相关调用成功`));
374
+ }
375
+ Z(s);
376
+ });
377
+ }, O = "git@gitee.com:justsosu/done-coding-cli-assets-config.git", ne = (e) => `./.DONE_CODING_CLI_CONFIG_TEMPORARY_DIRECTORY_FOR_${e}`, F = (e) => `./assets/${e}`, se = (e) => `${F(e)}/index.json`, He = async ({
378
+ moduleName: e,
379
+ onSuccess: o
380
+ }) => {
381
+ console.log(u.blue(`拉取${e}配置,请稍等...`));
382
+ const t = ne(e), r = g.resolve(
383
+ L(),
384
+ t
385
+ );
386
+ if (p(r))
387
+ return console.log(
388
+ u.red(`${r} 已存在,请手动删除该目录再试`)
389
+ ), process.exit(1);
390
+ const n = () => {
391
+ A(r, { recursive: !0, force: !0 });
392
+ };
393
+ let s;
394
+ try {
395
+ f(`git clone ${O} ${r} --depth=1`);
396
+ const c = se(e), i = F(e), l = g.resolve(
397
+ r,
398
+ c
399
+ );
400
+ s = JSON.parse(d.readFileSync(l, "utf-8")), process.once("exit", () => {
401
+ p(r) && (console.log("发现进程退出,正在清理临时目录..."), n());
402
+ }), await o({
403
+ repoUrl: O,
404
+ config: s,
405
+ cliConfigFileRelativePath: c,
406
+ cliConfigDirRelativePath: i,
407
+ configTemporaryDir: r
408
+ });
409
+ } finally {
410
+ n();
411
+ }
412
+ return s;
285
413
  };
286
414
  export {
287
- _ as EditorTypeEnum,
288
- wt as _curry,
289
- Ct as _get,
290
- $t as _set,
291
- pt as chalk,
292
- ot as createMainCommand,
293
- nt as createSubcommand,
294
- et as decryptAES,
295
- rt as encryptAES,
296
- it as getConfigFileCommonOptions,
297
- L as getEditorType,
298
- lt as getGitLastCommitInfo,
299
- ft as getPackageJson,
300
- J as getRootDirOptions,
301
- at as getUseDefaultConfig,
302
- V as initConfigFile,
303
- st as initHandlerCommon,
304
- yt as json5,
305
- c as log,
306
- tt as lookForParentTarget,
307
- B as openFileInEditor,
308
- gt as pushGitPublishInfoToRemote,
309
- ct as readConfigFile,
310
- E as xPrompts
415
+ B as EditorTypeEnum,
416
+ Be as _curry,
417
+ Je as _get,
418
+ Ge as _set,
419
+ Fe as addHuskyHooks,
420
+ Pe as addPackageConfig,
421
+ Ae as chalk,
422
+ Re as createMainCommand,
423
+ Ee as createSubcommand,
424
+ ve as decryptAES,
425
+ $e as encryptAES,
426
+ Z as fileAddX,
427
+ Oe as getConfigFileCommonOptions,
428
+ K as getEditorType,
429
+ xe as getGitLastCommitInfo,
430
+ De as getGitProjectDir,
431
+ oe as getHuskyBootCode,
432
+ re as getHuskyRootDir,
433
+ R as getPackageJson,
434
+ Q as getRelyPkgVersion,
435
+ q as getRootDirOptions,
436
+ _e as getUseDefaultConfig,
437
+ z as initConfigFile,
438
+ ke as initHandlerCommon,
439
+ Me as json5,
440
+ a as log,
441
+ Se as lookForParentTarget,
442
+ X as openFileInEditor,
443
+ be as pushGitPublishInfoToRemote,
444
+ He as readCliConfig,
445
+ we as readConfigFile,
446
+ D as xPrompts
311
447
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-utils",
3
- "version": "0.5.0-alpha.0",
3
+ "version": "0.6.0-alpha.0",
4
4
  "description": "cli utils",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -40,10 +40,12 @@
40
40
  "@types/json5": "^2.2.0",
41
41
  "@types/lodash.curry": "^4.1.8",
42
42
  "@types/lodash.get": "^4.4.9",
43
+ "@types/lodash.merge": "^4.6.9",
43
44
  "@types/lodash.set": "^4.3.9",
44
45
  "@types/node": "^18.0.0",
45
46
  "@types/pinyin": "^2.10.0",
46
47
  "@types/prompts": "^2.4.6",
48
+ "@types/semver": "^7.5.3",
47
49
  "@types/yargs": "^17.0.28",
48
50
  "rimraf": "^6.0.1",
49
51
  "typescript": "^5.2.2",
@@ -58,10 +60,12 @@
58
60
  "json5": "^2.2.3",
59
61
  "lodash.curry": "^4.1.1",
60
62
  "lodash.get": "^4.4.2",
63
+ "lodash.merge": "^4.6.2",
61
64
  "lodash.set": "^4.3.2",
62
65
  "pinyin": "^2.11.2",
63
66
  "prompts": "^2.4.2",
67
+ "semver": "^7.5.4",
64
68
  "yargs": "^17.7.2"
65
69
  },
66
- "gitHead": "86cdd3eaf8cc8be3e48a812b93fd7c2110fcc879"
70
+ "gitHead": "5879161383e32e7bed351d71d3ef607d81dc021a"
67
71
  }
@@ -0,0 +1,15 @@
1
+ /** 读取配置 */
2
+ export declare const readCliConfig: <R>({ moduleName, onSuccess, }: {
3
+ moduleName: string;
4
+ onSuccess: (params: {
5
+ repoUrl: string;
6
+ /** 配置文件相对路径 */
7
+ cliConfigFileRelativePath: string;
8
+ /** 配置文件目录相对路径 */
9
+ cliConfigDirRelativePath: string;
10
+ /** 配置文件内容 */
11
+ config: R;
12
+ /** 配置临时目录 */
13
+ configTemporaryDir: string;
14
+ }) => void | Promise<void>;
15
+ }) => Promise<R>;
@@ -0,0 +1,2 @@
1
+ /** 文件添加执行权限 */
2
+ export declare const fileAddX: (filePath: string) => void;
package/types/git.d.ts CHANGED
@@ -59,6 +59,8 @@ export interface GitLastCommitInfo {
59
59
  /** 远程仓库信息 */
60
60
  remoteInfo?: GitRemoteInfo;
61
61
  }
62
+ /** 获取git项目目录 */
63
+ export declare const getGitProjectDir: (rootDir: string) => string;
62
64
  /**
63
65
  * 获取git 最后提交信息
64
66
  */
@@ -0,0 +1,16 @@
1
+ /** 获取husky引导代码 */
2
+ export declare const getHuskyBootCode: ({ projectRootDir, }: {
3
+ projectRootDir: string;
4
+ }) => "" | "#!/usr/bin/env sh\n. \"$(dirname -- \"$0\")/_/husky.sh\"";
5
+ /** 获取husky根目录 */
6
+ export declare const getHuskyRootDir: ({ projectRootDir, }: {
7
+ projectRootDir: string;
8
+ }) => string;
9
+ /** 添加 husky hooks */
10
+ export declare const addHuskyHooks: <H extends string>({ hookNames, projectRootDir, getCode, }: {
11
+ hookNames: H[];
12
+ /** 项目根目录 */
13
+ projectRootDir: string;
14
+ /** 获取husky hooks 添加的代码 */
15
+ getCode: (hook: string) => string;
16
+ }) => void;
package/types/index.d.ts CHANGED
@@ -9,3 +9,6 @@ export * from "./json5";
9
9
  export * from "./lodash";
10
10
  export * from "./package-json";
11
11
  export * from "./git";
12
+ export * from "./husky";
13
+ export * from "./file-operate";
14
+ export * from "./cli-config";
@@ -1,7 +1,28 @@
1
+ /** package.json文件内容 */
1
2
  export interface PackageJson {
2
3
  name: string;
3
4
  version?: string;
5
+ bin?: Record<string, string> | string;
6
+ scripts?: Record<string, string>;
7
+ files?: string[];
8
+ dependencies?: Record<string, string>;
9
+ devDependencies?: Record<string, string>;
10
+ peerDependencies?: Record<string, string>;
4
11
  }
12
+ /** 获取package.json文件内容 */
5
13
  export declare const getPackageJson: <R extends PackageJson>({ rootDir, }: {
6
14
  rootDir: string;
7
15
  }) => R;
16
+ /** 获取依赖包版本 */
17
+ export declare const getRelyPkgVersion: <R extends PackageJson>({ rootDir, pkgJson, pkgName, isDevPkg, }: {
18
+ rootDir: string;
19
+ pkgJson?: R | undefined;
20
+ pkgName: string;
21
+ /** 是开发依赖包 */
22
+ isDevPkg: boolean;
23
+ }) => string | undefined;
24
+ /** 添加package.json配置 */
25
+ export declare const addPackageConfig: ({ patchConfig, rootDir, }: {
26
+ patchConfig?: Record<string, any> | undefined;
27
+ rootDir: string;
28
+ }) => void;