@done-coding/cli-config 0.1.3 → 0.1.4-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/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { c as m } from "./index-81fb23ea.js";
2
+ import { c as m } from "./index-82c0dcc4.js";
3
3
  import "@done-coding/cli-utils";
4
4
  import "node:fs";
5
5
  import "node:path";
@@ -1,24 +1,27 @@
1
1
  #!/usr/bin/env node
2
- import { readConfigFile as B, log as r, getPackageJson as Q, getRelyPkgVersion as X, getConfigFileCommonOptions as Y, readCliConfig as Z, xPrompts as j, addPackageConfig as ee, addHuskyHooks as te, createSubcommand as _, createMainCommand as ne } from "@done-coding/cli-utils";
3
- import h, { existsSync as C } from "node:fs";
2
+ import { readConfigFile as B, log as i, getPackageJson as Q, getRelyPkgVersion as X, getConfigFileCommonOptions as Y, readCliConfig as Z, xPrompts as w, addPackageConfig as ee, addHuskyHooks as te, createSubcommand as J, getRootScriptName as ne, createMainCommand as oe } from "@done-coding/cli-utils";
3
+ import k, { existsSync as C } from "node:fs";
4
4
  import g from "node:path";
5
- import { execSync as k } from "node:child_process";
5
+ import { execSync as N } from "node:child_process";
6
6
  var y = /* @__PURE__ */ ((e) => (e.CHECK = "check", e.ADD = "add", e))(y || {}), m = /* @__PURE__ */ ((e) => (e.ESLINT = "eslint", e.PRETTIER = "prettier", e.COMMITLINT = "commitlint", e.LSLINT = "ls-lint", e.MERGELINT = "merge-lint", e))(m || {});
7
- const N = {
7
+ const L = {
8
8
  name: "@done-coding/cli-config",
9
- version: "0.1.3",
9
+ version: "0.1.4-alpha.0",
10
10
  description: "工程化配置命令行工具",
11
+ bin: {
12
+ "dc-config": "es/cli.mjs"
13
+ },
11
14
  cliConfig: {
12
15
  namespaceDir: ".done-coding",
13
16
  moduleName: "config"
14
17
  }
15
18
  }, {
16
- cliConfig: { namespaceDir: oe, moduleName: se }
17
- } = N, re = `./${oe}/${se}`, ie = `${re}.json`, I = Object.values(m).filter(
19
+ cliConfig: { namespaceDir: se, moduleName: ie }
20
+ } = L, re = `./${se}/${ie}`, ce = `${re}.json`, I = Object.values(m).filter(
18
21
  (e) => e.toUpperCase() !== e
19
- ), ce = async (e) => await B(e, () => {
22
+ ), ae = async (e) => await B(e, () => {
20
23
  const { moduleList: t = [] } = e;
21
- return r.info(
24
+ return i.info(
22
25
  `配置文件不存在 读取命令行参数 moduleList: ${JSON.stringify(
23
26
  t,
24
27
  null,
@@ -33,7 +36,7 @@ const N = {
33
36
  [m.COMMITLINT]: "@commitlint/cli",
34
37
  [m.LSLINT]: "@ls-lint/ls-lint",
35
38
  [m.MERGELINT]: "@done-coding/cli-git"
36
- }, n = "_$_", ae = {
39
+ }, n = "_$_", le = {
37
40
  [m.ESLINT]: [
38
41
  `${n}.config.js`,
39
42
  `${n}.config.mjs`,
@@ -74,44 +77,44 @@ const N = {
74
77
  ],
75
78
  [m.LSLINT]: [`.${n}.yaml`, `.${n}.yml`],
76
79
  [m.MERGELINT]: [".done-coding/git.json"]
77
- }, le = (e, t) => t.filter((o) => C(g.resolve(e, o))), H = (e) => e.filter((t) => {
80
+ }, me = (e, t) => t.filter((o) => C(g.resolve(e, o))), _ = (e) => e.filter((t) => {
78
81
  const o = I.includes(t);
79
- return o || r.warn(
82
+ return o || i.warn(
80
83
  `当前不支持${t}的配置检测, 支持的类型有${I.join(
81
84
  ", "
82
85
  )}`
83
86
  ), o;
84
- }), me = ({
87
+ }), de = ({
85
88
  config: e,
86
89
  rootDir: t
87
90
  }) => {
88
- const { moduleList: o = [] } = e, s = H(o);
89
- r.stage(`开始获取${s.join(", ")}配置信息...`);
90
- const i = Q({ rootDir: t });
91
+ const { moduleList: o = [] } = e, s = _(o);
92
+ i.stage(`开始获取${s.join(", ")}配置信息...`);
93
+ const r = Q({ rootDir: t });
91
94
  return s.reduce(
92
95
  (a, l) => {
93
96
  const f = X({
94
97
  rootDir: t,
95
- pkgJson: i,
98
+ pkgJson: r,
96
99
  pkgName: F[l],
97
100
  isDevPkg: !0
98
101
  });
99
102
  if (!f)
100
103
  return a;
101
- const c = ae[l].map((u) => u.replace(n, l));
104
+ const c = le[l].map((u) => u.replace(n, l));
102
105
  return c.length ? (a[l] = {
103
106
  version: f,
104
- configFileRelativePathList: le(
107
+ configFileRelativePathList: me(
105
108
  t,
106
109
  c
107
110
  )
108
- }, a) : (r.warn(`安装了${l}, 但未找到${l}的配置文件 认为未使用`), a);
111
+ }, a) : (i.warn(`安装了${l}, 但未找到${l}的配置文件 认为未使用`), a);
109
112
  },
110
113
  {}
111
114
  );
112
- }, J = () => ({
115
+ }, H = () => ({
113
116
  ...Y({
114
- configPathDefault: ie
117
+ configPathDefault: ce
115
118
  }),
116
119
  moduleList: {
117
120
  type: "array",
@@ -123,91 +126,91 @@ const N = {
123
126
  )
124
127
  }
125
128
  }), E = async (e) => {
126
- const t = await ce(e), o = me({ config: t, rootDir: e.rootDir });
127
- return r.success(`检测到工程化配置信息:
129
+ const t = await ae(e), o = de({ config: t, rootDir: e.rootDir });
130
+ return i.success(`检测到工程化配置信息:
128
131
  ${JSON.stringify(o, null, 2)}`), {
129
132
  config: t,
130
133
  info: o
131
134
  };
132
- }, de = {
135
+ }, ue = {
133
136
  command: y.CHECK,
134
137
  describe: "检测工程化配置",
135
- options: J(),
138
+ options: H(),
136
139
  handler: E
137
140
  }, {
138
- cliConfig: { moduleName: ue }
139
- } = N, fe = () => ({
140
- ...J(),
141
+ cliConfig: { moduleName: fe }
142
+ } = L, ge = () => ({
143
+ ...H(),
141
144
  commitGit: {
142
145
  type: "boolean",
143
146
  alias: "g",
144
147
  description: "添加完成后是否提交到git",
145
148
  default: !1
146
149
  }
147
- }), ge = async ({
150
+ }), $e = async ({
148
151
  moduleName: e,
149
152
  moduleConfigList: t
150
153
  }) => {
151
154
  if (!Array.isArray(t) || t.length === 0) {
152
- r.error(`未找到 ${e} 预设版本配置`);
155
+ i.error(`未找到 ${e} 预设版本配置`);
153
156
  return;
154
157
  }
155
158
  if (t.length === 1) {
156
159
  const s = t[0];
157
- return r.skip(
160
+ return i.skip(
158
161
  `${e} 跳过版本选择: 仅有一个预设版本配置, 默认选择第一个(${s.version})`
159
162
  ), s;
160
163
  }
161
- const { version: o } = await j({
164
+ const { version: o } = await w({
162
165
  type: "select",
163
166
  name: "version",
164
167
  message: `请选择需要添加的${e}版本`,
165
168
  choices: t.map((s) => {
166
- const { version: i } = s;
169
+ const { version: r } = s;
167
170
  return {
168
- title: `${F[e]}@${i}`,
169
- value: i
171
+ title: `${F[e]}@${r}`,
172
+ value: r
170
173
  };
171
174
  })
172
175
  });
173
176
  return t.find((s) => s.version === o);
174
- }, $e = async ({
177
+ }, pe = async ({
175
178
  moduleName: e,
176
179
  moduleConfig: t
177
180
  }) => {
178
181
  const { configFileInfoList: o } = t;
179
182
  if (!Array.isArray(o) || o.length === 0) {
180
- r.error(`未找到 ${e} 配置文件信息列表`);
183
+ i.error(`未找到 ${e} 配置文件信息列表`);
181
184
  return;
182
185
  }
183
186
  if (o.length === 1) {
184
- const i = o[0];
185
- return r.skip(
186
- `${e} 跳过配置文件信息选择: 仅有一个配置文件信息, 默认选择第一个(${i.sourceFile})`
187
- ), i;
187
+ const r = o[0];
188
+ return i.skip(
189
+ `${e} 跳过配置文件信息选择: 仅有一个配置文件信息, 默认选择第一个(${r.sourceFile})`
190
+ ), r;
188
191
  }
189
- const { info: s } = await j({
192
+ const { info: s } = await w({
190
193
  type: "select",
191
194
  name: "info",
192
195
  message: "请选择需要添加的配置文件",
193
- choices: o.map((i) => {
194
- const { sourceFile: a, description: l } = i;
196
+ choices: o.map((r) => {
197
+ const { sourceFile: a, description: l } = r;
195
198
  return {
196
199
  title: a,
197
- value: i,
200
+ value: r,
198
201
  description: l
199
202
  };
200
203
  })
201
204
  });
202
- return o.find((i) => i.sourceFile === s.sourceFile);
203
- }, pe = ({ rootDir: e, list: t }) => {
204
- r.stage(`开始安装依赖包: ${JSON.stringify(t, null, 2)}`);
205
+ return o.find((r) => r.sourceFile === s.sourceFile);
206
+ }, ye = ({ rootDir: e, list: t }) => {
207
+ i.stage(`开始安装依赖包: ${JSON.stringify(t, null, 2)}`);
205
208
  const o = g.resolve(e, "pnpm-workspace.yaml"), s = C(o);
206
- k(`pnpm add -D ${s ? "-w" : ""} ${t.join(" ")}`, {
209
+ N(`pnpm add -D ${s ? "-w" : ""} ${t.join(" ")}`, {
207
210
  cwd: e,
208
211
  stdio: "inherit"
209
212
  });
210
- }, ye = async ({
213
+ }, Le = async ({
211
214
  hooksConfig: e,
212
215
  argv: t
213
216
  }) => Object.entries(e).forEach(async ([o, s]) => {
@@ -216,22 +219,22 @@ ${JSON.stringify(o, null, 2)}`), {
216
219
  rootDir: t.rootDir,
217
220
  getCode: () => s
218
221
  });
219
- }), Le = async ({
222
+ }), he = async ({
220
223
  moduleName: e,
221
224
  moduleConfigList: t,
222
225
  argv: o
223
226
  }) => {
224
- const s = await ge({
227
+ const s = await $e({
225
228
  moduleName: e,
226
229
  moduleConfigList: t
227
230
  });
228
231
  if (!s)
229
232
  return;
230
- const i = await $e({
233
+ const r = await pe({
231
234
  moduleName: e,
232
235
  moduleConfig: s
233
236
  });
234
- if (!i)
237
+ if (!r)
235
238
  return;
236
239
  const {
237
240
  relyPackages: a = [],
@@ -240,32 +243,32 @@ ${JSON.stringify(o, null, 2)}`), {
240
243
  } = s, {
241
244
  relyPackages: c = [],
242
245
  sourceFile: u,
243
- targetFile: w
244
- } = i, $ = [
246
+ targetFile: j
247
+ } = r, $ = [
245
248
  `${F[e]}@${l}`,
246
249
  ...a,
247
250
  ...c
248
251
  ];
249
- return r.stage(`需要安装的依赖包:
252
+ return i.stage(`需要安装的依赖包:
250
253
  ${JSON.stringify($, null, 2)}`), await ee({
251
254
  patchConfig: s.packageJson,
252
255
  rootDir: o.rootDir
253
256
  }), {
254
257
  sourceFile: u,
255
- targetFile: w,
258
+ targetFile: j,
256
259
  version: l,
257
260
  pkgList: $,
258
261
  runScripts: f,
259
262
  /** 方法内部已经使用husky了 但是所有依赖包在最后才统一安装 */
260
263
  addHuskyConfigFn: () => {
261
264
  var p;
262
- return ye({
265
+ return Le({
263
266
  hooksConfig: ((p = s.husky) == null ? void 0 : p.hooks) || {},
264
267
  argv: o
265
268
  });
266
269
  }
267
270
  };
268
- }, he = ({
271
+ }, ke = ({
269
272
  listConfig: e,
270
273
  moduleDir: t,
271
274
  moduleName: o
@@ -277,9 +280,9 @@ ${JSON.stringify($, null, 2)}`), await ee({
277
280
  throw new Error(
278
281
  `${o} 预设列表文件 ${s} 不存在`
279
282
  );
280
- const i = h.readFileSync(s, "utf-8");
283
+ const r = k.readFileSync(s, "utf-8");
281
284
  return JSON.parse(
282
- i
285
+ r
283
286
  );
284
287
  } else {
285
288
  if (!Array.isArray(e))
@@ -289,43 +292,43 @@ ${JSON.stringify($, null, 2)}`), await ee({
289
292
  return e;
290
293
  }
291
294
  }, b = async (e) => {
292
- const { config: t, info: o } = await E(e), { moduleList: s = [] } = t, a = H(s).filter((c) => {
295
+ const { config: t, info: o } = await E(e), { moduleList: s = [] } = t, a = _(s).filter((c) => {
293
296
  const u = o[c];
294
- return u ? (r.skip(`
297
+ return u ? (i.skip(`
295
298
  检测到 ${c} 已配置, ${JSON.stringify(u, null, 2)},
296
299
  跳过添加 ${c}`), !1) : !0;
297
300
  });
298
301
  if (!a.length) {
299
- r.success("所有配置项均已配置, 无需添加");
302
+ i.success("所有配置项均已配置, 无需添加");
300
303
  return;
301
304
  }
302
305
  await Z({
303
- moduleName: ue,
306
+ moduleName: fe,
304
307
  onSuccess: async ({
305
308
  config: c,
306
309
  configTemporaryDir: u,
307
- cliConfigDirRelativePath: w
310
+ cliConfigDirRelativePath: j
308
311
  }) => {
309
312
  if (!(c != null && c.project))
310
313
  throw new Error("项目工程化预设不存在");
311
- r.success("预设配置拉取成功");
312
- const { project: P } = c, { rootDir: $ } = e, p = [], T = [], S = [];
314
+ i.success("预设配置拉取成功");
315
+ const { project: S } = c, { rootDir: $ } = e, p = [], P = [], T = [];
313
316
  for (let d of a) {
314
317
  const v = g.resolve(
315
318
  u,
316
- w,
319
+ j,
317
320
  d
318
- ), D = he({
319
- listConfig: P[d],
321
+ ), D = ke({
322
+ listConfig: S[d],
320
323
  moduleDir: v,
321
324
  moduleName: d
322
325
  });
323
326
  if (!D) {
324
- r.error(`未找到 ${d} 预设配置`);
327
+ i.error(`未找到 ${d} 预设配置`);
325
328
  return;
326
329
  }
327
- r.stage(`开始添加 ${d} 配置`);
328
- const M = await Le({
330
+ i.stage(`开始添加 ${d} 配置`);
331
+ const M = await he({
329
332
  moduleName: d,
330
333
  moduleConfigList: D,
331
334
  argv: e
@@ -338,40 +341,40 @@ ${JSON.stringify($, null, 2)}`), await ee({
338
341
  pkgList: W,
339
342
  addHuskyConfigFn: q,
340
343
  runScripts: z
341
- } = M, A = g.resolve(v, V, U), L = g.resolve($, K);
342
- r.stage(`开始复制 ${A} -> ${L}`);
343
- const O = g.dirname(L);
344
- h.existsSync(O) || h.mkdirSync(O, { recursive: !0 }), h.copyFileSync(A, L), r.success(`添加 ${d} 配置成功, 路径: ${L}`), p.push(...W), T.push(q), S.push(...z);
344
+ } = M, A = g.resolve(v, V, U), h = g.resolve($, K);
345
+ i.stage(`开始复制 ${A} -> ${h}`);
346
+ const R = g.dirname(h);
347
+ k.existsSync(R) || k.mkdirSync(R, { recursive: !0 }), k.copyFileSync(A, h), i.success(`添加 ${d} 配置成功, 路径: ${h}`), p.push(...W), P.push(q), T.push(...z);
345
348
  }
346
349
  }
347
- await pe({
350
+ await ye({
348
351
  rootDir: $,
349
352
  list: [...new Set(p)]
350
353
  });
351
- for (let d of S)
352
- r.stage(`运行脚本: ${d}`), k(d, { cwd: $, stdio: "inherit" });
353
- await Promise.all(T.map((d) => d()));
354
+ for (let d of T)
355
+ i.stage(`运行脚本: ${d}`), N(d, { cwd: $, stdio: "inherit" });
356
+ await Promise.all(P.map((d) => d()));
354
357
  }
355
358
  });
356
359
  const { commitGit: l, rootDir: f } = e;
357
360
  if (l) {
358
- const { commitMsg: c } = await j({
361
+ const { commitMsg: c } = await w({
359
362
  type: "text",
360
363
  name: "commitMsg",
361
364
  message: "请输入提交信息",
362
365
  initial: `chore: 添加 ${a.join(", ")} 工程化配置`
363
366
  });
364
- k("git add .", { cwd: f, stdio: "inherit" }), k(`git commit -m "${c}"`, {
367
+ N("git add .", { cwd: f, stdio: "inherit" }), N(`git commit -m "${c}"`, {
365
368
  cwd: f,
366
369
  stdio: "inherit"
367
370
  });
368
371
  }
369
- }, ke = {
372
+ }, Ne = {
370
373
  command: y.ADD,
371
374
  describe: "添加工程化配置",
372
- options: fe(),
375
+ options: ge(),
373
376
  handler: b
374
- }, Ee = async (e, t) => {
377
+ }, Se = async (e, t) => {
375
378
  switch (e) {
376
379
  case y.CHECK:
377
380
  return E(t);
@@ -380,20 +383,21 @@ ${JSON.stringify($, null, 2)}`), await ee({
380
383
  default:
381
384
  throw new Error(`不支持的命令 ${e}`);
382
385
  }
383
- }, { version: Ie, description: Ne } = N, G = {
384
- describe: Ne,
386
+ }, { version: Ie, description: je } = L, G = {
387
+ describe: je,
385
388
  version: Ie,
386
- subcommands: [de, ke].map(_),
387
- demandCommandCount: 1
389
+ subcommands: [ue, Ne].map(J),
390
+ demandCommandCount: 1,
391
+ rootScriptName: ne({ packageJson: L })
388
392
  }, {
389
- cliConfig: { moduleName: R }
390
- } = N, x = (e = !1) => {
391
- const t = e ? R : void 0, o = `$0${e ? ` ${R}` : ""} <command> [options]`;
393
+ cliConfig: { moduleName: O }
394
+ } = L, x = (e = !1) => {
395
+ const t = e ? O : void 0, o = `$0${e ? ` ${O}` : ""} <command> [options]`;
392
396
  return { command: t, usage: o };
393
- }, Pe = async () => ne({
397
+ }, Pe = async () => oe({
394
398
  ...G,
395
399
  ...x()
396
- }), Te = () => _({
400
+ }), Te = () => J({
397
401
  ...G,
398
402
  ...x(!0)
399
403
  });
@@ -402,5 +406,5 @@ export {
402
406
  y as S,
403
407
  Te as a,
404
408
  Pe as c,
405
- Ee as h
409
+ Se as h
406
410
  };
package/es/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { C as i, S as s, a as t, h as u } from "./index-81fb23ea.js";
2
+ import { C as i, S as s, a as t, h as u } from "./index-82c0dcc4.js";
3
3
  import "@done-coding/cli-utils";
4
4
  import "node:fs";
5
5
  import "node:path";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-config",
3
- "version": "0.1.3",
3
+ "version": "0.1.4-alpha.0",
4
4
  "description": "工程化配置命令行工具",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -40,7 +40,7 @@
40
40
  "license": "MIT",
41
41
  "sideEffects": false,
42
42
  "devDependencies": {
43
- "@done-coding/cli-inject": "^0.5.11",
43
+ "@done-coding/cli-inject": "^0.5.12-alpha.0",
44
44
  "@types/node": "^18.0.0",
45
45
  "@types/yargs": "^17.0.28",
46
46
  "rimraf": "^6.0.1",
@@ -52,7 +52,7 @@
52
52
  "node": ">=18.0.0"
53
53
  },
54
54
  "dependencies": {
55
- "@done-coding/cli-utils": "^0.7.2"
55
+ "@done-coding/cli-utils": "^0.7.3-alpha.0"
56
56
  },
57
- "gitHead": "ad322da7f5d0897ee91a399aff9a14b111d62825"
57
+ "gitHead": "9d9a2e60f255038a0f065e3a4e6d6d35488408ae"
58
58
  }