@done-coding/cli-utils 0.3.2 → 0.3.3

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,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import P from "chalk";
3
- import { default as ar } from "chalk";
3
+ import { default as ae } from "chalk";
4
4
  import f from "node:path";
5
5
  import b, { existsSync as h, mkdirSync as k, writeFileSync as g, readFileSync as m } from "node:fs";
6
6
  import l from "crypto";
@@ -10,42 +10,42 @@ import { hideBin as F } from "yargs/helpers";
10
10
  import { execSync as y } from "node:child_process";
11
11
  import v from "json5";
12
12
  export * from "json5";
13
- import { default as lr } from "json5";
14
- import { default as dr } from "lodash.get";
15
- import { default as mr } from "lodash.set";
16
- import { default as hr } from "lodash.curry";
13
+ import { default as le } from "json5";
14
+ import { default as de } from "lodash.get";
15
+ import { default as me } from "lodash.set";
16
+ import { default as he } from "lodash.curry";
17
17
  const c = Object.assign(
18
- (r, ...e) => console.log(...e.map((t) => P[r](t))),
18
+ (e, ...r) => console.log(...r.map((t) => P[e](t))),
19
19
  {
20
20
  /** 成功 */
21
- success: (...r) => c("green", ...r),
21
+ success: (...e) => c("green", ...e),
22
22
  /** /步骤 */
23
- stage: (...r) => c("blue", ...r),
23
+ stage: (...e) => c("blue", ...e),
24
24
  /** 提示信息 */
25
- info: (...r) => c("cyan", ...r),
25
+ info: (...e) => c("cyan", ...e),
26
26
  /** 警告 */
27
- warn: (...r) => c("yellow", ...r),
27
+ warn: (...e) => c("yellow", ...e),
28
28
  /** 错误 */
29
- error: (...r) => c("red", ...r),
29
+ error: (...e) => c("red", ...e),
30
30
  /** 跳过 */
31
- skip: (...r) => c("gray", ...r)
31
+ skip: (...e) => c("gray", ...e)
32
32
  }
33
- ), Q = (r, {
33
+ ), Q = (e, {
34
34
  /** 当前目录 */
35
- currentDir: e = process.cwd(),
35
+ currentDir: r = process.cwd(),
36
36
  /** 优先找最远的父目录 */
37
37
  isFindFarthest: t = !0
38
38
  } = {}) => {
39
- const o = f.resolve(e).split(f.sep).map((n, i, a) => i ? f.join(a.slice(0, i).join(f.sep), n) : n);
39
+ const o = f.resolve(r).split(f.sep).map((n, i, a) => i ? f.join(a.slice(0, i).join(f.sep), n) : n);
40
40
  for (; o.length; ) {
41
- const n = t ? o.shift() : o.pop(), i = f.join(n, r);
41
+ const n = t ? o.shift() : o.pop(), i = f.join(n, e);
42
42
  if (b.existsSync(i))
43
43
  return n;
44
44
  }
45
45
  }, C = "aes-256-cbc", S = 16, p = "hex", d = ":";
46
- function $(r) {
46
+ function $(e) {
47
47
  return l.pbkdf2Sync(
48
- r,
48
+ e,
49
49
  "done-coding-cli-salt",
50
50
  // 使用固定的盐值
51
51
  1e4,
@@ -56,12 +56,12 @@ function $(r) {
56
56
  );
57
57
  }
58
58
  function X({
59
- text: r,
60
- secretKey: e
59
+ text: e,
60
+ secretKey: r
61
61
  }) {
62
62
  try {
63
- const t = $(e), o = l.randomBytes(S), n = l.createCipheriv(C, t, o);
64
- let i = n.update(r);
63
+ const t = $(r), o = l.randomBytes(S), n = l.createCipheriv(C, t, o);
64
+ let i = n.update(e);
65
65
  i = Buffer.concat([i, n.final()]);
66
66
  const a = o.toString(p), s = i.toString(p);
67
67
  return `${a}${d}${s}`;
@@ -72,13 +72,13 @@ function X({
72
72
  }
73
73
  }
74
74
  function Z({
75
- encryptedText: r,
76
- secretKey: e
75
+ encryptedText: e,
76
+ secretKey: r
77
77
  }) {
78
78
  try {
79
- if (!r.includes(d))
79
+ if (!e.includes(d))
80
80
  return "";
81
- const t = $(e), [o, n] = r.split(d);
81
+ const t = $(r), [o, n] = e.split(d);
82
82
  if (o.length !== S * 2)
83
83
  return "";
84
84
  const i = Buffer.from(o, p), a = Buffer.from(n, p), s = l.createDecipheriv(C, t, i);
@@ -90,39 +90,39 @@ function Z({
90
90
  ), "";
91
91
  }
92
92
  }
93
- const x = (...r) => {
94
- const [e, t = {}] = r;
95
- return H(e, {
93
+ const x = (...e) => {
94
+ const [r, t = {}] = e;
95
+ return H(r, {
96
96
  onCancel(o) {
97
97
  return c.error(`退出${o == null ? void 0 : o.name}输入`), process.exit(1);
98
98
  },
99
99
  ...t
100
100
  });
101
- }, R = (r, e) => {
102
- r ? c.error(r) : c.error(e.message), e != null && e.stack && c.error(e.stack), process.exit(1);
101
+ }, R = (e, r) => {
102
+ e ? c.error(e) : c.error(r.message), r != null && r.stack && c.error(r.stack), process.exit(1);
103
103
  }, T = () => {
104
- const r = F(process.argv);
105
- return E(r);
106
- }, j = (r, {
107
- usage: e,
104
+ const e = F(process.argv);
105
+ return E(e);
106
+ }, j = (e, {
107
+ usage: r,
108
108
  version: t,
109
109
  demandCommandCount: o,
110
110
  options: n,
111
111
  positionals: i,
112
112
  subcommands: a
113
113
  }) => {
114
- let s = r.strict();
115
- e && (s = s.usage(`Usage: ${e}`)), o && (s = s.demandCommand(o));
114
+ let s = e.strict();
115
+ r && (s = s.usage(`Usage: ${r}`)), o && (s = s.demandCommand(o));
116
116
  const u = "help";
117
117
  return s = s.help(u), t ? s = s.version(t).alias("h", u).alias("v", "version") : s = s.alias("h", u), n && (s = s.options(n)), i && (s = Object.entries(i).reduce((w, [D, O]) => w.positional(D, O), s)), a && (s = s.command(a)), s;
118
- }, rr = async ({ handler: r, ...e }) => {
119
- const t = await j(T(), e).fail(R).argv;
120
- return r ? r(t) : t;
121
- }, er = (r) => {
122
- const { command: e, describe: t, handler: o = () => {
123
- }, ...n } = r;
118
+ }, ee = async ({ handler: e, ...r }) => {
119
+ const t = await j(T(), r).fail(R).argv;
120
+ return e ? e(t) : t;
121
+ }, re = (e) => {
122
+ const { command: r, describe: t, handler: o = () => {
123
+ }, ...n } = e;
124
124
  return {
125
- command: e,
125
+ command: r,
126
126
  describe: t,
127
127
  builder(i) {
128
128
  return j(i, n);
@@ -130,9 +130,9 @@ const x = (...r) => {
130
130
  handler: o
131
131
  };
132
132
  };
133
- var _ = /* @__PURE__ */ ((r) => (r.VSCODE = "VsCode", r.CURSOR = "Cursor", r.OTHER = "其他", r))(_ || {});
133
+ var _ = /* @__PURE__ */ ((e) => (e.VSCODE = "VsCode", e.CURSOR = "Cursor", e.OTHER = "其他", e))(_ || {});
134
134
  const A = async () => {
135
- const { editorType: r } = await x([
135
+ const { editorType: e } = await x([
136
136
  {
137
137
  name: "editorType",
138
138
  type: "select",
@@ -142,31 +142,31 @@ const A = async () => {
142
142
  "VsCode",
143
143
  "其他"
144
144
  /* OTHER */
145
- ].map((e) => ({
146
- title: e,
147
- value: e
145
+ ].map((r) => ({
146
+ title: r,
147
+ value: r
148
148
  }))
149
149
  }
150
150
  ]);
151
- return r;
151
+ return e;
152
152
  }, B = {
153
153
  Cursor: "cursor",
154
154
  VsCode: "code"
155
- }, N = (r, e, t) => {
155
+ }, N = (e, r, t) => {
156
156
  try {
157
- y(`${r} -v`, { stdio: "ignore" }), y(`${r} ${e}`);
157
+ y(`${e} -v`, { stdio: "ignore" }), y(`${e} ${r}`);
158
158
  } catch {
159
159
  t();
160
160
  }
161
- }, V = (r, e) => {
161
+ }, V = (e, r) => {
162
162
  const t = (o) => c.info(`
163
- ${o}, 请用编辑器打开 ${r} 进行编辑
163
+ ${o}, 请用编辑器打开 ${e} 进行编辑
164
164
  `);
165
- switch (e) {
165
+ switch (r) {
166
166
  case "Cursor":
167
167
  case "VsCode": {
168
- const o = B[e];
169
- N(o, r, () => {
168
+ const o = B[r];
169
+ N(o, e, () => {
170
170
  t(`${o}命令未安装`);
171
171
  });
172
172
  break;
@@ -174,77 +174,79 @@ const A = async () => {
174
174
  default:
175
175
  t("其他编辑器");
176
176
  }
177
- }, L = (r = process.cwd()) => ({
177
+ }, L = (e = process.cwd()) => ({
178
178
  /** 必须保留 */
179
179
  rootDir: {
180
180
  type: "string",
181
181
  alias: "r",
182
182
  describe: "运行目录",
183
183
  /** 必须设置默认值 */
184
- default: r
184
+ default: e
185
185
  }
186
- }), tr = ({
187
- configPathDefault: r,
188
- rootDirDefault: e
186
+ }), te = ({
187
+ configPathDefault: e,
188
+ rootDirDefault: r
189
189
  }) => ({
190
190
  /** 必须保留 */
191
- ...L(e),
191
+ ...L(r),
192
192
  /** 必须保留 */
193
193
  configPath: {
194
194
  type: "string",
195
195
  alias: "c",
196
196
  describe: "配置文件相对路径",
197
197
  /** 必须设置默认值 */
198
- default: r
198
+ default: e
199
199
  }
200
- }), I = async (r, e) => {
201
- const { configPath: t, rootDir: o } = e, n = f.resolve(o, t), i = f.dirname(n);
200
+ }), I = async (e, r) => {
201
+ const { configPath: t, rootDir: o } = r, n = f.resolve(o, t), i = f.dirname(n);
202
202
  return h(i) || k(i, {
203
203
  recursive: !0
204
- }), n.endsWith(".json5") ? (c.info(`json5模式写入 ${n}`), g(n, v.stringify(r, null, 2)), n) : (c.info(`json模式写入 ${n}`), g(n, JSON.stringify(r, null, 2)), n);
205
- }, or = async (r, e, {
206
- onFileGenerated: t
204
+ }), n.endsWith(".json5") ? (c.info(`json5模式写入 ${n}`), g(n, v.stringify(e, null, 2)), n) : (c.info(`json模式写入 ${n}`), g(n, JSON.stringify(e, null, 2)), n);
205
+ }, oe = async (e, r, {
206
+ onFileGenerated: t,
207
+ edit: o = !1
207
208
  } = {}) => {
208
- const o = await I(r, e);
209
- t == null || t(o);
210
- const n = await A();
211
- V(e.configPath, n);
212
- }, nr = async (r) => {
213
- const { configPath: e, rootDir: t } = r, o = f.resolve(t, e);
209
+ const n = await I(e, r);
210
+ if (t == null || t(n), o) {
211
+ const i = await A();
212
+ V(r.configPath, i);
213
+ }
214
+ }, ne = async (e) => {
215
+ const { configPath: r, rootDir: t } = e, o = f.resolve(t, r);
214
216
  if (!h(o)) {
215
217
  c.warn(`配置文件不存在 ${o}`);
216
218
  return;
217
219
  }
218
220
  return o.endsWith(".json5") ? (c.info(`json5模式解析 ${o}`), v.parse(m(o, "utf8"))) : (c.info(`json模式解析 ${o}`), JSON.parse(m(o, "utf8")));
219
- }, sr = async () => {
220
- const { useDefaultConfig: r } = await x({
221
+ }, se = async () => {
222
+ const { useDefaultConfig: e } = await x({
221
223
  name: "useDefaultConfig",
222
224
  type: "confirm",
223
225
  message: "使用默认模板配置",
224
226
  initial: !0
225
227
  });
226
- return r;
228
+ return e;
227
229
  };
228
230
  export {
229
231
  _ as EditorTypeEnum,
230
- hr as _curry,
231
- dr as _get,
232
- mr as _set,
233
- ar as chalk,
234
- rr as createMainCommand,
235
- er as createSubcommand,
232
+ he as _curry,
233
+ de as _get,
234
+ me as _set,
235
+ ae as chalk,
236
+ ee as createMainCommand,
237
+ re as createSubcommand,
236
238
  Z as decryptAES,
237
239
  X as encryptAES,
238
- tr as getConfigFileCommonOptions,
240
+ te as getConfigFileCommonOptions,
239
241
  A as getEditorType,
240
242
  L as getRootDirOptions,
241
- sr as getUseDefaultConfig,
243
+ se as getUseDefaultConfig,
242
244
  I as initConfigFile,
243
- or as initHandlerCommon,
244
- lr as json5,
245
+ oe as initHandlerCommon,
246
+ le as json5,
245
247
  c as log,
246
248
  Q as lookForParentTarget,
247
249
  V as openFileInEditor,
248
- nr as readConfigFile,
250
+ ne as readConfigFile,
249
251
  x as xPrompts
250
252
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-utils",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "cli utils",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -61,5 +61,5 @@
61
61
  "prompts": "^2.4.2",
62
62
  "yargs": "^17.7.2"
63
63
  },
64
- "gitHead": "7a8d554748b844c8b7694c587983b21af902d5d1"
64
+ "gitHead": "3caf888c1978970b95d95219ac63d0a3ed2b2912"
65
65
  }
@@ -26,9 +26,10 @@ export declare const getConfigFileCommonOptions: ({ configPathDefault, rootDirDe
26
26
  /** 初始化配置文件 */
27
27
  export declare const initConfigFile: <T>(content: T, argv: CliHandlerArgv<InitConfigFileOptions>) => Promise<string>;
28
28
  /** 初始化配置文件通用处理器 */
29
- export declare const initHandlerCommon: <T>(content: T, argv: CliHandlerArgv<InitConfigFileOptions>, { onFileGenerated, }?: {
29
+ export declare const initHandlerCommon: <T>(content: T, argv: CliHandlerArgv<InitConfigFileOptions>, { onFileGenerated, edit, }?: {
30
30
  /** 文件已生成 */
31
31
  onFileGenerated?: ((path: string) => void) | undefined;
32
+ edit?: boolean | undefined;
32
33
  }) => Promise<void>;
33
34
  /** 读取配置文件 */
34
35
  export declare const readConfigFile: <T>(argv: CliHandlerArgv<ReadConfigFileOptions>) => Promise<T | undefined>;