@vc-shell/release-config 1.2.4-beta.5 → 1.2.4-beta.6

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.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as i } from "./generate-changelogs-uhMg9Loz.js";
2
+ import { c as i } from "./generate-changelogs-ujWf_gXz.js";
3
3
  import { resolve as s } from "node:path";
4
4
  import e from "chalk";
5
5
  async function l() {
@@ -0,0 +1,352 @@
1
+ import { sync as p } from "cross-spawn";
2
+ import { existsSync as v, readFileSync as G, writeFileSync as H } from "node:fs";
3
+ import $ from "node:path";
4
+ import a from "chalk";
5
+ import { valid as R, rcompare as j } from "semver";
6
+ function _(e, t) {
7
+ const s = p("git", ["describe", "--tags", "--abbrev=0", "--match", `${t}${e}.*`], {
8
+ stdio: "pipe",
9
+ encoding: "utf-8"
10
+ });
11
+ return s.status === 0 && s.stdout ? s.stdout.toString().trim() : null;
12
+ }
13
+ function x() {
14
+ const e = p("git", ["remote", "get-url", "origin"], {
15
+ stdio: "pipe",
16
+ encoding: "utf-8"
17
+ });
18
+ return e.status === 0 && e.stdout ? e.stdout.toString().trim().replace(/\.git$/, "").replace(/^git@github\.com:/, "https://github.com/") : null;
19
+ }
20
+ function V(e) {
21
+ return p("git", ["rev-parse", "--verify", `refs/tags/${e}`], {
22
+ stdio: "pipe"
23
+ }).status === 0;
24
+ }
25
+ function F(e) {
26
+ return p("git", ["merge-base", "--is-ancestor", e, "HEAD"], {
27
+ stdio: "pipe"
28
+ }).status === 0;
29
+ }
30
+ function P(e, t) {
31
+ const s = p("git", ["merge-base", e, t], {
32
+ stdio: "pipe",
33
+ encoding: "utf-8"
34
+ });
35
+ return s.status === 0 && s.stdout ? s.stdout.toString().trim() : null;
36
+ }
37
+ function S(e, t, s) {
38
+ const l = ["log", "--format=%H %s", `${e}..${t}`];
39
+ s && l.push("--", s);
40
+ const r = p("git", l, {
41
+ stdio: "pipe",
42
+ encoding: "utf-8"
43
+ });
44
+ if (r.status !== 0 || !r.stdout) return [];
45
+ const i = [], n = r.stdout.toString().trim().split(`
46
+ `).filter(Boolean), c = /^(\w+)(?:\(([^)]+)\))?(!)?\s*:\s*(.+)$/;
47
+ for (const o of n) {
48
+ const h = o.indexOf(" ");
49
+ if (h === -1) continue;
50
+ const d = o.substring(0, h), m = o.substring(h + 1).match(c);
51
+ m && i.push({
52
+ hash: d,
53
+ shortHash: d.substring(0, 7),
54
+ type: m[1],
55
+ scope: m[2] || null,
56
+ subject: m[4],
57
+ breaking: !!m[3]
58
+ });
59
+ }
60
+ return i;
61
+ }
62
+ function J() {
63
+ const e = p("git", ["describe", "--tags", "--abbrev=0"], {
64
+ stdio: "pipe",
65
+ encoding: "utf-8"
66
+ });
67
+ return e.status === 0 && e.stdout ? e.stdout.toString().trim() : null;
68
+ }
69
+ function K() {
70
+ p("git", ["add", "-u"], { stdio: "inherit" }).status !== 0 && (console.error(a.red(`
71
+ Failed to stage changes
72
+ `)), process.exit(1)), p("git", ["commit", "--amend", "--no-edit"], { stdio: "inherit" }).status !== 0 && (console.error(a.red(`
73
+ Failed to amend commit
74
+ `)), process.exit(1));
75
+ }
76
+ function Q(e) {
77
+ p("git", ["tag", "-f", "-a", e, "-m", e], { stdio: "inherit" }).status !== 0 && (console.error(a.red(`
78
+ Failed to recreate tag
79
+ `)), process.exit(1));
80
+ }
81
+ function X(e) {
82
+ console.log(a.cyan(`
83
+ Pushing changes to remote...
84
+ `)), p("git", ["push", "origin", "HEAD", "--force-with-lease"], { stdio: "inherit" }).status !== 0 && (console.error(a.red(`
85
+ Failed to push commit
86
+ `)), process.exit(1)), p("git", ["push", "origin", e, "--force"], { stdio: "inherit" }).status !== 0 && (console.error(a.red(`
87
+ Failed to push tag
88
+ `)), process.exit(1));
89
+ }
90
+ function O(e) {
91
+ let t = e;
92
+ return t = t.replace(/^# CHANGELOG\s*\n/gm, ""), t = t.replace(/^# Change Log\s*\n/gm, ""), t = t.replace(
93
+ /^All notable changes to this (project|package) will be documented in this file\.\s*\n/gm,
94
+ ""
95
+ ), t = t.replace(
96
+ /^See \[Conventional Commits\]\(https:\/\/conventionalcommits\.org\) for commit guidelines\.\s*\n/gm,
97
+ ""
98
+ ), t = t.replace(/\n{3,}/g, `
99
+
100
+ `), t;
101
+ }
102
+ function L(e) {
103
+ return e.replace(
104
+ /^(##\s+\[[^\]]+\][^\n]*\n)\n(##\s+\[|$)/gm,
105
+ `$1
106
+ **Note:** Version bump only for package
107
+
108
+ $2`
109
+ );
110
+ }
111
+ function Z(e, t = !1) {
112
+ console.log(a.cyan(`
113
+ Enhancing changelogs...
114
+ `));
115
+ for (const s of e) {
116
+ const l = $.join(s.path, "CHANGELOG.md");
117
+ if (!v(l)) continue;
118
+ let r = G(l, "utf-8");
119
+ r = O(r), r = L(r), r = r.trim() + `
120
+ `, t || H(l, r, "utf-8");
121
+ }
122
+ }
123
+ function B(e) {
124
+ const t = {}, s = {}, l = e.split(`
125
+ `);
126
+ let r = null, i = [];
127
+ for (const n of l) {
128
+ const c = n.match(/^##\s+(?:\[)?([\d.a-z-]+)(?:\])?(?:\s+\([^)]+\))?/i);
129
+ c ? (r && i.length > 0 && (t[r] = i.join(`
130
+ `).trim()), r = c[1], i = [], s[r] || (s[r] = n.replace(/^##\s+/, ""))) : r && n.trim() !== "" && !n.startsWith("# CHANGELOG") && !n.startsWith("# Change Log") && !n.startsWith("All notable changes") && !n.startsWith("See [Conventional Commits]") && i.push(n);
131
+ }
132
+ return r && i.length > 0 && (t[r] = i.join(`
133
+ `).trim()), { versionContent: t, versionHeaders: s };
134
+ }
135
+ function D(e) {
136
+ return [...e].sort((t, s) => R(t) && R(s) ? j(t, s) : s.localeCompare(t));
137
+ }
138
+ function I(e, t = !1) {
139
+ const { packages: s, rootDir: l = process.cwd(), includeRootHeader: r = !1 } = e;
140
+ console.log(a.cyan(`
141
+ Generating root CHANGELOG with package grouping...
142
+ `));
143
+ const i = $.join(l, "CHANGELOG.md"), n = {}, c = {};
144
+ for (const d of s) {
145
+ const f = $.join(l, d.path, "CHANGELOG.md");
146
+ if (!v(f)) continue;
147
+ const m = G(f, "utf-8"), y = B(m);
148
+ for (const [u, b] of Object.entries(y.versionContent))
149
+ n[u] || (n[u] = {}), n[u][d.displayName] = b, !c[u] && y.versionHeaders[u] && (c[u] = y.versionHeaders[u]);
150
+ }
151
+ let o = "";
152
+ r && (o = `# CHANGELOG
153
+
154
+ All notable changes to this monorepo will be documented in this file.
155
+
156
+ `);
157
+ const h = D(Object.keys(n));
158
+ for (const d of h) {
159
+ const f = n[d], m = Object.values(f).some((b) => !b || !b.trim() ? !1 : b.replace(/\*\*Note:\*\*\s+Version bump only[^\n]*/gi, "").trim().length > 0), y = c[d] || d;
160
+ if (o += `## ${y}
161
+
162
+ `, !m) {
163
+ o += `**Note:** Version bump only for package
164
+
165
+ `;
166
+ continue;
167
+ }
168
+ let u = !1;
169
+ for (const b of s) {
170
+ const C = f[b.displayName];
171
+ C && C.trim() && C.replace(/\*\*Note:\*\*\s+Version bump only[^\n]*/gi, "").trim().length > 0 && (u = !0, o += `### ${b.displayName}
172
+
173
+ `, o += `${C}
174
+
175
+ `);
176
+ }
177
+ u || (o += `**Note:** Version bump only for package
178
+
179
+ `);
180
+ }
181
+ o = o.replace(/\n{3,}/g, `
182
+
183
+ `), o = o.trim() + `
184
+ `, t ? console.log(a.yellow(` [dry-run] Would write root CHANGELOG.md (${h.length} versions)`)) : (H(i, o, "utf-8"), console.log(a.green(" Generated root CHANGELOG.md with package grouping")));
185
+ }
186
+ const T = {
187
+ feat: "Features",
188
+ fix: "Bug Fixes",
189
+ perf: "Performance Improvements",
190
+ revert: "Reverts"
191
+ };
192
+ function N(e) {
193
+ return V(e) ? F(e) ? e : P(e, "HEAD") : null;
194
+ }
195
+ function W(e, t) {
196
+ const s = {};
197
+ for (const i of e) {
198
+ const n = T[i.type];
199
+ n && (s[n] || (s[n] = []), s[n].push(i));
200
+ }
201
+ if (Object.keys(s).length === 0) return "";
202
+ let l = "";
203
+ const r = ["Features", "Bug Fixes", "Performance Improvements", "Reverts"];
204
+ for (const i of r) {
205
+ const n = s[i];
206
+ if (!(!n || n.length === 0)) {
207
+ l += `### ${i}
208
+
209
+ `;
210
+ for (const c of n) {
211
+ const o = t ? `([${c.shortHash}](${t}/commit/${c.hash}))` : `(${c.shortHash})`;
212
+ l += c.scope ? `- **${c.scope}:** ${c.subject} ${o}
213
+ ` : `- ${c.subject} ${o}
214
+ `;
215
+ }
216
+ l += `
217
+ `;
218
+ }
219
+ }
220
+ return l.trim();
221
+ }
222
+ function ee(e, t, s = !1) {
223
+ console.log(a.cyan(`
224
+ Backfilling empty changelog versions...
225
+ `));
226
+ const l = x();
227
+ let r = 0;
228
+ for (const i of e) {
229
+ const n = $.join(i.path, "CHANGELOG.md");
230
+ if (!v(n)) continue;
231
+ let c = G(n, "utf-8");
232
+ const o = [];
233
+ for (const f of c.matchAll(/^##\s+\[?([\d.a-z-]+)\]?/gm))
234
+ o.push(f[1]);
235
+ const h = /^(##\s+\[?([\d.a-z-]+)\]?[^\n]*\n)\n\*\*Note:\*\*\s+Version bump only[^\n]*/gm;
236
+ let d = !1;
237
+ c = c.replace(h, (f, m, y) => {
238
+ const u = o.indexOf(y);
239
+ if (u === -1) return f;
240
+ const b = u < o.length - 1 ? o[u + 1] : null;
241
+ if (!b) return f;
242
+ const C = N(`${t}${b}`);
243
+ if (!C) return f;
244
+ let g = N(`${t}${y}`);
245
+ if (!g) {
246
+ const A = u > 0 ? o[u - 1] : null;
247
+ g = A ? N(`${t}${A}`) : null, g || (g = "HEAD");
248
+ }
249
+ if (C === g) return f;
250
+ const w = S(C, g, i.path).filter((A) => !c.includes(A.shortHash)), E = W(w, l);
251
+ return E ? (d = !0, r++, console.log(a.gray(` Backfilled ${i.name} v${y} (${w.length} commits)`)), `${m}
252
+ ${E}`) : f;
253
+ }), d && !s && H(n, c, "utf-8");
254
+ }
255
+ r > 0 ? console.log(a.green(` Backfilled ${r} empty changelog version(s)`)) : console.log(a.gray(" No empty versions to backfill"));
256
+ }
257
+ function te(e, t = !1) {
258
+ for (const s of e) {
259
+ const l = $.join(s.path, "CHANGELOG.md");
260
+ if (!v(l)) continue;
261
+ const r = G(l, "utf-8"), i = [], n = /^(##\s+\[?[\d.a-z-]+\]?[^\n]*)\n/gm;
262
+ let c = 0, o = "";
263
+ for (const g of r.matchAll(n))
264
+ o && i.push({ header: o, body: r.substring(c, g.index) }), o = g[1], c = g.index + g[0].length;
265
+ if (o && i.push({ header: o, body: r.substring(c) }), i.length < 2) continue;
266
+ const h = /\[([a-f0-9]{7})\]\(/g, d = /* @__PURE__ */ new Set();
267
+ for (let g = 1; g < i.length; g++)
268
+ for (const k of i[g].body.matchAll(h))
269
+ d.add(k[1]);
270
+ if (d.size === 0) continue;
271
+ const f = i[0].body, m = f.split(`
272
+ `).filter((g) => {
273
+ if (!g.startsWith("- ")) return !0;
274
+ const k = g.match(/\[([a-f0-9]{7})\]\(/);
275
+ return !k || !d.has(k[1]);
276
+ }), y = m.join(`
277
+ `);
278
+ if (y === f) continue;
279
+ i[0].body = y;
280
+ let u = "";
281
+ for (const g of i)
282
+ u += `${g.header}
283
+ ${g.body}`;
284
+ u = u.replace(/\n{3,}/g, `
285
+
286
+ `).trim() + `
287
+ `, i[0].body.replace(/###[^\n]*/g, "").trim() || (u = u.replace(
288
+ i[0].body,
289
+ `
290
+ **Note:** Version bump only for package
291
+
292
+ `
293
+ )), t || H(l, u, "utf-8");
294
+ const C = f.split(`
295
+ `).length - m.length;
296
+ C > 0 && console.log(a.gray(` Deduplicated ${s.name}: removed ${C} duplicate entries`));
297
+ }
298
+ }
299
+ async function ne(e) {
300
+ const { packages: t, rootDir: s = process.cwd(), generateRoot: l = !0, includeRootHeader: r = !0 } = e;
301
+ console.log(a.cyan(`
302
+ Generating initial CHANGELOG.md files...
303
+ `));
304
+ for (const i of t) {
305
+ const n = $.join(s, i.path, "CHANGELOG.md");
306
+ if (v(n)) {
307
+ const o = `${n}.backup`, h = G(n, "utf-8");
308
+ H(o, h, "utf-8"), console.log(a.gray(` Backed up ${n} to ${o}`));
309
+ }
310
+ if (console.log(a.blue(`
311
+ Generating changelog for ${i.name}...`)), p(
312
+ "npx",
313
+ [
314
+ "conventional-changelog",
315
+ "-p",
316
+ "conventionalcommits",
317
+ "-i",
318
+ n,
319
+ "-s",
320
+ "-r",
321
+ "0",
322
+ "--commit-path",
323
+ $.join(s, i.path)
324
+ ],
325
+ { stdio: "inherit", cwd: s }
326
+ ).status === 0) {
327
+ if (v(n)) {
328
+ let o = G(n, "utf-8");
329
+ o = O(o), o = L(o), o = o.trim() + `
330
+ `, H(n, o, "utf-8");
331
+ }
332
+ console.log(a.green(` Generated ${n}`));
333
+ } else
334
+ console.log(a.red(` Failed to generate ${n}`));
335
+ }
336
+ l && await I({ packages: t, rootDir: s, includeRootHeader: r }), console.log(a.green(`
337
+ Initial changelogs generated successfully!`)), console.log(a.cyan(`
338
+ Next steps:`)), console.log(a.cyan(" 1. Review the generated CHANGELOG.md files")), console.log(a.cyan(" 2. Make any manual adjustments if needed")), console.log(a.cyan(` 3. Commit the changes
339
+ `));
340
+ }
341
+ export {
342
+ J as a,
343
+ ee as b,
344
+ ne as c,
345
+ te as d,
346
+ Z as e,
347
+ _ as f,
348
+ I as g,
349
+ X as p,
350
+ Q as r,
351
+ K as s
352
+ };
@@ -1,21 +1,21 @@
1
- import { parse as b, valid as V } from "semver";
2
- import { readFileSync as A, existsSync as N, writeFileSync as $ } from "node:fs";
1
+ import { parse as b, valid as N } from "semver";
2
+ import { readFileSync as V, writeFileSync as x } from "node:fs";
3
3
  import R from "node:path";
4
- import S from "mri";
5
- import { argv as T } from "node:process";
4
+ import $ from "mri";
5
+ import { argv as D } from "node:process";
6
6
  import n from "chalk";
7
- import { sync as i } from "cross-spawn";
8
- import m from "prompts";
9
- import { e as D, g as E } from "./generate-changelogs-uhMg9Loz.js";
10
- import { a as le } from "./generate-changelogs-uhMg9Loz.js";
11
- const c = S(T.slice(2));
12
- c.dry;
13
- function v(o) {
14
- const t = R.resolve(o), e = R.resolve(t, "package.json");
15
- return { pkg: JSON.parse(A(e, "utf-8")), pkgDir: t, pkgPath: e };
7
+ import { sync as f } from "cross-spawn";
8
+ import d from "prompts";
9
+ import { f as T, e as I, b as E, d as L, g as S, a as j, s as U, r as J, p as O } from "./generate-changelogs-ujWf_gXz.js";
10
+ import { c as le } from "./generate-changelogs-ujWf_gXz.js";
11
+ const l = $(D.slice(2));
12
+ l.dry;
13
+ function v(t) {
14
+ const o = R.resolve(t), e = R.resolve(o, "package.json");
15
+ return { pkg: JSON.parse(V(e, "utf-8")), pkgDir: o, pkgPath: e };
16
16
  }
17
17
  async function F() {
18
- const { releaseType: o } = await m({
18
+ const { releaseType: t } = await d({
19
19
  type: "select",
20
20
  name: "releaseType",
21
21
  message: "Select release type",
@@ -26,10 +26,10 @@ async function F() {
26
26
  { title: "Custom version", value: "custom" }
27
27
  ]
28
28
  });
29
- return o;
29
+ return t;
30
30
  }
31
- async function L(o) {
32
- const t = b(o), e = t && t.prerelease.length > 0, s = e ? t.prerelease[0] : null, { preid: a } = await m({
31
+ async function G(t) {
32
+ const o = b(t), e = o && o.prerelease.length > 0, s = e ? o.prerelease[0] : null, { preid: i } = await d({
33
33
  type: "select",
34
34
  name: "preid",
35
35
  message: "Select prerelease identifier",
@@ -48,76 +48,76 @@ async function L(o) {
48
48
  }
49
49
  ]
50
50
  });
51
- if (a)
52
- return e && s === a ? { preid: a, lernaVersionArg: "prerelease", lernaPreidArgs: [] } : { preid: a, lernaVersionArg: "prerelease", lernaPreidArgs: ["--preid", a] };
51
+ if (i)
52
+ return e && s === i ? { preid: i, lernaVersionArg: "prerelease", lernaPreidArgs: [] } : { preid: i, lernaVersionArg: "prerelease", lernaPreidArgs: ["--preid", i] };
53
53
  }
54
- async function j(o) {
55
- const { customVersion: t } = await m({
54
+ async function H(t) {
55
+ const { customVersion: o } = await d({
56
56
  type: "text",
57
57
  name: "customVersion",
58
58
  message: "Enter custom version",
59
- initial: o,
60
- validate: (e) => V(e) ? !0 : "Invalid semver version"
59
+ initial: t,
60
+ validate: (e) => N(e) ? !0 : "Invalid semver version"
61
61
  });
62
- return t;
62
+ return o;
63
63
  }
64
- async function G() {
65
- const { yes: o } = await m({
64
+ async function B() {
65
+ const { yes: t } = await d({
66
66
  type: "confirm",
67
67
  name: "yes",
68
68
  message: "Ready to release. Continue?"
69
69
  });
70
- return !!o;
70
+ return !!t;
71
71
  }
72
- function d() {
72
+ function u() {
73
73
  console.log(n.yellow(`
74
74
  Release cancelled
75
75
  `));
76
76
  }
77
- function I(o, t) {
78
- const e = ["lerna", "version", ...o];
79
- return e.push("--tag-version-prefix", t.tagVersionPrefix), e.push("--no-push"), t.isDryRun && e.push("--no-git-tag-version"), t.forcePublish && (e.push("--force-publish"), console.log(n.yellow(`
77
+ function M(t, o) {
78
+ const e = ["lerna", "version", ...t];
79
+ return e.push("--conventional-commits"), e.push("--tag-version-prefix", o.tagVersionPrefix), e.push("--no-push"), o.isDryRun && e.push("--no-git-tag-version"), o.forcePublish && (e.push("--force-publish"), console.log(n.yellow(`
80
80
  Force publish mode - all packages will be versioned
81
81
  `))), e;
82
82
  }
83
- function H(o) {
83
+ function Y(t) {
84
84
  console.log(n.cyan(`
85
- Running: npx ${o.join(" ")}
85
+ Running: npx ${t.join(" ")}
86
86
  `));
87
- const t = i("npx", o, { stdio: "inherit" });
88
- t.status !== 0 && (console.error(n.red(`
87
+ const o = f("npx", t, { stdio: "inherit" });
88
+ o.status !== 0 && (console.error(n.red(`
89
89
  Release process failed
90
- `)), process.exit(t.status || 1));
90
+ `)), process.exit(o.status || 1));
91
91
  }
92
- function O(o) {
93
- const t = {};
94
- for (const e of o) {
92
+ function q(t) {
93
+ const o = {};
94
+ for (const e of t) {
95
95
  const { pkg: s } = v(e.path);
96
- t[e.path] = s.version;
96
+ o[e.path] = s.version;
97
97
  }
98
- return t;
98
+ return o;
99
99
  }
100
- function U(o, t) {
101
- for (const e of o) {
100
+ function z(t, o) {
101
+ for (const e of t) {
102
102
  const { pkg: s } = v(e.path);
103
- if (s.version !== t[e.path])
103
+ if (s.version !== o[e.path])
104
104
  return s.version;
105
105
  }
106
106
  return null;
107
107
  }
108
- function J(o, t, e) {
108
+ function K(t, o, e) {
109
109
  if (console.log(n.gray(`
110
- --- Release diagnostics ---`)), console.log(n.gray(` tagVersionPrefix: "${o}"`)), console.log(n.gray(` looking for tags: ${o}${t}.*`)), e) {
111
- const s = i("git", ["rev-list", "--count", `${e}..HEAD`], {
110
+ --- Release diagnostics ---`)), console.log(n.gray(` tagVersionPrefix: "${t}"`)), console.log(n.gray(` looking for tags: ${t}${o}.*`)), e) {
111
+ const s = f("git", ["rev-list", "--count", `${e}..HEAD`], {
112
112
  stdio: "pipe",
113
113
  encoding: "utf-8"
114
- }), a = s.status === 0 ? s.stdout.trim() : "?", l = i(
114
+ }), i = s.status === 0 ? s.stdout.trim() : "?", a = f(
115
115
  "git",
116
116
  ["log", `${e}..HEAD`, "--oneline", "--grep", "^feat\\|^fix\\|^perf\\|^revert"],
117
117
  { stdio: "pipe", encoding: "utf-8" }
118
- ), f = l.status === 0 ? l.stdout.trim().split(`
118
+ ), g = a.status === 0 ? a.stdout.trim().split(`
119
119
  `).filter(Boolean).length : 0;
120
- console.log(n.gray(` last matching tag: ${e}`)), console.log(n.gray(` commits since tag: ${a}`)), console.log(n.gray(` conventional commits: ${f}`)), f === 0 && parseInt(a) > 0 && console.log(
120
+ console.log(n.gray(` last matching tag: ${e}`)), console.log(n.gray(` commits since tag: ${i}`)), console.log(n.gray(` conventional commits: ${g}`)), g === 0 && parseInt(i) > 0 && console.log(
121
121
  n.yellow(
122
122
  " No conventional commits found. Use --force to publish anyway."
123
123
  )
@@ -127,109 +127,68 @@ function J(o, t, e) {
127
127
  console.log(n.gray(`---------------------------
128
128
  `));
129
129
  }
130
- function B(o, t) {
131
- const e = i("git", ["describe", "--tags", "--abbrev=0", "--match", `${t}${o}.*`], {
132
- stdio: "pipe",
133
- encoding: "utf-8"
134
- });
135
- return e.status === 0 && e.stdout ? e.stdout.toString().trim() : null;
136
- }
137
- function M() {
138
- const o = i("git", ["describe", "--tags", "--abbrev=0"], {
139
- stdio: "pipe",
140
- encoding: "utf-8"
141
- });
142
- return o.status === 0 && o.stdout ? o.stdout.toString().trim() : null;
143
- }
144
- function Y(o) {
145
- const t = ["package.json", "yarn.lock", "CHANGELOG.md"];
146
- for (const e of o)
147
- t.push(`${e.path}/package.json`), t.push(`${e.path}/CHANGELOG.md`);
148
- return t.filter((e) => N(e));
149
- }
150
- function q(o) {
151
- i("git", ["add", ...o], { stdio: "inherit" }).status !== 0 && (console.error(n.red(`
152
- Failed to stage changes
153
- `)), process.exit(1)), i("git", ["commit", "--amend", "--no-edit"], { stdio: "inherit" }).status !== 0 && (console.error(n.red(`
154
- Failed to amend commit
155
- `)), process.exit(1));
156
- }
157
- function z(o) {
158
- i("git", ["tag", "-f", "-a", o, "-m", o], { stdio: "inherit" }).status !== 0 && (console.error(n.red(`
159
- Failed to recreate tag
160
- `)), process.exit(1));
161
- }
162
- function K(o) {
163
- console.log(n.cyan(`
164
- Pushing changes to remote...
165
- `)), i("git", ["push", "origin", "HEAD", "--force-with-lease"], { stdio: "inherit" }).status !== 0 && (console.error(n.red(`
166
- Failed to push commit
167
- `)), process.exit(1)), i("git", ["push", "origin", o, "--force"], { stdio: "inherit" }).status !== 0 && (console.error(n.red(`
168
- Failed to push tag
169
- `)), process.exit(1));
170
- }
171
- async function re(o) {
130
+ async function re(t) {
172
131
  const {
173
- packages: t,
132
+ packages: o,
174
133
  tagVersionPrefix: e = "v",
175
134
  customHooks: s,
176
- updateRootVersion: a = !0
177
- } = o;
178
- if (t.length === 0)
135
+ updateRootVersion: i = !0
136
+ } = t;
137
+ if (o.length === 0)
179
138
  throw new Error("No packages to release");
180
- const l = !!c.dry;
181
- l && console.log(n.yellow(`
139
+ const a = !!l.dry;
140
+ a && console.log(n.yellow(`
182
141
  DRY RUN MODE - No git operations will be performed
183
142
  `));
184
- const { pkg: f } = v(t[0].path), h = f.version, k = h.split(".").slice(0, 2).join("."), P = B(k, e);
185
- J(e, k, P);
186
- const u = await F();
187
- if (!u) return d();
188
- const g = [];
189
- if (u === "auto")
190
- g.push("--conventional-commits");
191
- else if (u === "prerelease") {
192
- const r = await L(h);
193
- if (!r) return d();
194
- g.push(r.lernaVersionArg, ...r.lernaPreidArgs), c.tag || (c.tag = r.preid);
195
- } else if (u === "graduate")
196
- g.push("--conventional-graduate");
197
- else if (u === "custom") {
198
- const r = await j(h);
199
- if (!r) return d();
200
- g.push(r);
201
- const p = b(r);
202
- if (p && p.prerelease.length > 0 && !c.tag) {
203
- const w = p.prerelease[0];
204
- typeof w == "string" && (c.tag = w);
143
+ const { pkg: g } = v(o[0].path), m = g.version, k = m.split(".").slice(0, 2).join("."), P = T(k, e);
144
+ K(e, k, P);
145
+ const c = await F();
146
+ if (!c) return u();
147
+ const p = [];
148
+ if (c !== "auto") {
149
+ if (c === "prerelease") {
150
+ const r = await G(m);
151
+ if (!r) return u();
152
+ p.push(r.lernaVersionArg, ...r.lernaPreidArgs), l.tag || (l.tag = r.preid);
153
+ } else if (c === "graduate")
154
+ p.push("--conventional-graduate");
155
+ else if (c === "custom") {
156
+ const r = await H(m);
157
+ if (!r) return u();
158
+ p.push(r);
159
+ const h = b(r);
160
+ if (h && h.prerelease.length > 0 && !l.tag) {
161
+ const w = h.prerelease[0];
162
+ typeof w == "string" && (l.tag = w);
163
+ }
205
164
  }
206
165
  }
207
- if (!await G()) return d();
208
- const x = I(g, {
166
+ if (!await B()) return u();
167
+ const A = M(p, {
209
168
  tagVersionPrefix: e,
210
- isDryRun: l,
211
- forcePublish: !!c.force
212
- }), C = O(t);
213
- H(x);
214
- const y = U(t, C);
169
+ isDryRun: a,
170
+ forcePublish: !!l.force
171
+ }), C = q(o);
172
+ Y(A);
173
+ const y = z(o, C);
215
174
  if (!y) {
216
175
  console.log(n.yellow(`
217
176
  No packages were versioned. Nothing to release.
218
177
  `));
219
178
  return;
220
179
  }
221
- if (a && Q(y, l), s && (console.log(n.cyan(`
180
+ if (i && Q(y, a), s && (console.log(n.cyan(`
222
181
  Running post-version hooks...
223
- `)), await s(y)), !l) {
182
+ `)), await s(y)), !a) {
224
183
  console.log(n.cyan(`
225
184
  Updating yarn.lock with new package versions...
226
185
  `));
227
- const r = i("yarn", ["install"], { stdio: "inherit" });
186
+ const r = f("yarn", ["install"], { stdio: "inherit" });
228
187
  r.status !== 0 && (console.error(n.red(`
229
188
  Failed to update yarn.lock
230
189
  `)), process.exit(r.status || 1));
231
190
  }
232
- if (D(t, l), E({ packages: t }, l), l)
191
+ if (I(o, a), E(o, e, a), L(o, a), S({ packages: o }, a), a)
233
192
  console.log(n.yellow(`
234
193
  Dry run completed successfully!
235
194
  `)), console.log(n.cyan("Changes made:")), console.log(n.cyan(" - Updated package versions")), console.log(n.cyan(` - Generated/updated CHANGELOG.md files
@@ -237,24 +196,22 @@ Dry run completed successfully!
237
196
  `)), console.log(n.yellow("To revert all changes:")), console.log(n.cyan(` git checkout -- .
238
197
  `));
239
198
  else {
240
- const r = M();
199
+ const r = j();
241
200
  r || (console.error(n.red(`
242
201
  Could not determine the git tag created by Lerna
243
- `)), process.exit(1));
244
- const p = Y(t);
245
- q(p), z(r), K(r), console.log(n.green(`
202
+ `)), process.exit(1)), U(), J(r), O(r), console.log(n.green(`
246
203
  Release completed successfully!
247
204
  `)), console.log(n.cyan(`npmTag will be automatically determined from git tag in CI
248
205
  `));
249
206
  }
250
207
  }
251
- function Q(o, t) {
252
- const e = "package.json", s = JSON.parse(A(e, "utf-8"));
253
- s.version !== o && (s.version = o, t || $(e, JSON.stringify(s, null, 2) + `
254
- `, "utf-8"), console.log(n.gray(` Updated root package.json version: ${o}`)));
208
+ function Q(t, o) {
209
+ const e = "package.json", s = JSON.parse(V(e, "utf-8"));
210
+ s.version !== t && (s.version = t, o || x(e, JSON.stringify(s, null, 2) + `
211
+ `, "utf-8"), console.log(n.gray(` Updated root package.json version: ${t}`)));
255
212
  }
256
213
  export {
257
214
  le as generateInitialChangelogs,
258
- E as generateRootChangelog,
215
+ S as generateRootChangelog,
259
216
  re as release
260
217
  };
@@ -22,4 +22,19 @@ export declare function sortVersionsDescending(versions: string[]): string[];
22
22
  * grouped by version with sub-headings per package.
23
23
  */
24
24
  export declare function generateRootChangelog(options: RootChangelogOptions, dryRun?: boolean): void;
25
+ /**
26
+ * Scans package changelogs for "Version bump only" entries and fills them
27
+ * with actual conventional commit content from git history.
28
+ *
29
+ * Handles non-ancestor tags (after rebase/force-push) by resolving via merge-base.
30
+ * Deduplicates against commits already present in the changelog.
31
+ */
32
+ export declare function backfillEmptyVersions(packages: PackageConfig[], tagPrefix: string, dryRun?: boolean): void;
33
+ /**
34
+ * Removes duplicate commit entries across changelog versions.
35
+ * Each commit should only appear in the oldest version that contains it.
36
+ * This handles cases where Lerna attributes commits to a new version
37
+ * that were already recorded in backfilled older versions.
38
+ */
39
+ export declare function deduplicateChangelog(packages: PackageConfig[], dryRun?: boolean): void;
25
40
  //# sourceMappingURL=changelog.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"changelog.d.ts","sourceRoot":"","sources":["../../src/changelog.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAIjF;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAc7D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAK3D;AAID;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,aAAa,EAAE,EAAE,MAAM,UAAQ,GAAG,IAAI,CAgBxF;AA6DD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAOnE;AAID;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAQ,GAAG,IAAI,CAqFzF"}
1
+ {"version":3,"file":"changelog.d.ts","sourceRoot":"","sources":["../../src/changelog.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAYjF;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAc7D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAK3D;AAID;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,aAAa,EAAE,EAAE,MAAM,UAAQ,GAAG,IAAI,CAgBxF;AA6DD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAOnE;AAID;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAQ,GAAG,IAAI,CAqFzF;AA2DD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,aAAa,EAAE,EACzB,SAAS,EAAE,MAAM,EACjB,MAAM,UAAQ,GACb,IAAI,CAkEN;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,aAAa,EAAE,EAAE,MAAM,UAAQ,GAAG,IAAI,CA6EpF"}
package/dist/src/git.d.ts CHANGED
@@ -1,24 +1,47 @@
1
- import { PackageConfig } from './types';
2
-
3
1
  /**
4
2
  * Finds the last git tag matching `<prefix><majorMinor>.*`.
5
3
  * Returns the tag string or null if none found.
6
4
  */
7
5
  export declare function findLastMatchingTag(majorMinor: string, tagPrefix: string): string | null;
8
6
  /**
9
- * Gets the latest tag on current HEAD (created by Lerna).
7
+ * Gets the repo URL for changelog commit links.
10
8
  */
11
- export declare function getLatestTag(): string | null;
9
+ export declare function getRepoUrl(): string | null;
10
+ /**
11
+ * Checks if a git tag exists.
12
+ */
13
+ export declare function tagExists(tag: string): boolean;
14
+ /**
15
+ * Checks if a ref (tag/commit) is an ancestor of HEAD.
16
+ */
17
+ export declare function isAncestorOfHead(ref: string): boolean;
12
18
  /**
13
- * Returns paths that should be staged after post-lerna modifications.
14
- * Replaces the unsafe `git add -A` with targeted file staging.
19
+ * Gets the merge base between two refs.
15
20
  */
16
- export declare function getReleaseStagePaths(packages: PackageConfig[]): string[];
21
+ export declare function getMergeBase(ref1: string, ref2: string): string | null;
22
+ export interface ConventionalCommit {
23
+ hash: string;
24
+ shortHash: string;
25
+ type: string;
26
+ scope: string | null;
27
+ subject: string;
28
+ breaking: boolean;
29
+ }
30
+ /**
31
+ * Gets conventional commits in a range, optionally filtered by path.
32
+ */
33
+ export declare function getConventionalCommitsInRange(from: string, to: string, commitPath?: string): ConventionalCommit[];
34
+ /**
35
+ * Gets the latest tag on current HEAD (created by Lerna).
36
+ */
37
+ export declare function getLatestTag(): string | null;
17
38
  /**
18
- * Stages specified paths and amends the last commit (created by Lerna).
39
+ * Stages all modified tracked files and amends the last commit (created by Lerna).
40
+ * Uses `git add -u` to capture all release changes including custom hook modifications
41
+ * (e.g. boilerplate template versions, app dependency updates).
19
42
  * Exits on failure.
20
43
  */
21
- export declare function stageAndAmendCommit(paths: string[]): void;
44
+ export declare function stageAndAmendCommit(): void;
22
45
  /**
23
46
  * Deletes and recreates the tag as an annotated tag on the amended commit.
24
47
  */
@@ -1 +1 @@
1
- {"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/git.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUxF;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,GAAG,IAAI,CAU5C;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,MAAM,EAAE,CAOxE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAYzD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAMtD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAc9C"}
1
+ {"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/git.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUxF;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,MAAM,GAAG,IAAI,CAa1C;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAK9C;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAKrD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAStE;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,UAAU,CAAC,EAAE,MAAM,GAClB,kBAAkB,EAAE,CAsCtB;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,GAAG,IAAI,CAU5C;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAY1C;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAMtD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAc9C"}
@@ -1 +1 @@
1
- {"version":3,"file":"lerna.d.ts","sourceRoot":"","sources":["../../src/lerna.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,eAAe,EAAE,MAAM,EAAE,EACzB,OAAO,EAAE,mBAAmB,GAC3B,MAAM,EAAE,CAmBV;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAQpD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOvF;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,aAAa,EAAE,EACzB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACrC,MAAM,GAAG,IAAI,CAQf;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAqClG"}
1
+ {"version":3,"file":"lerna.d.ts","sourceRoot":"","sources":["../../src/lerna.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,eAAe,EAAE,MAAM,EAAE,EACzB,OAAO,EAAE,mBAAmB,GAC3B,MAAM,EAAE,CAsBV;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAQpD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOvF;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,aAAa,EAAE,EACzB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACrC,MAAM,GAAG,IAAI,CAQf;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAqClG"}
@@ -1 +1 @@
1
- {"version":3,"file":"release.d.ts","sourceRoot":"","sources":["../../src/release.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAyB3D;;;GAGG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAsIlE"}
1
+ {"version":3,"file":"release.d.ts","sourceRoot":"","sources":["../../src/release.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AA6B3D;;;GAGG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAuIlE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vc-shell/release-config",
3
- "version": "1.2.4-beta.5",
3
+ "version": "1.2.4-beta.6",
4
4
  "type": "module",
5
5
  "main": "dist/release-config.js",
6
6
  "types": "./dist/src/index.d.ts",
@@ -34,5 +34,5 @@
34
34
  "access": "public",
35
35
  "registry": "https://registry.npmjs.org/"
36
36
  },
37
- "gitHead": "4cc2527f06178114fd3db9f781b1d6fd868a7a61"
37
+ "gitHead": "86734c47306da89feb6b16685287744bb2855cc8"
38
38
  }
@@ -1,148 +0,0 @@
1
- import { sync as A } from "cross-spawn";
2
- import { existsSync as G, readFileSync as y, writeFileSync as N } from "node:fs";
3
- import d from "node:path";
4
- import i from "chalk";
5
- import { valid as v, rcompare as O } from "semver";
6
- function H(a) {
7
- let e = a;
8
- return e = e.replace(/^# CHANGELOG\s*\n/gm, ""), e = e.replace(/^# Change Log\s*\n/gm, ""), e = e.replace(
9
- /^All notable changes to this (project|package) will be documented in this file\.\s*\n/gm,
10
- ""
11
- ), e = e.replace(
12
- /^See \[Conventional Commits\]\(https:\/\/conventionalcommits\.org\) for commit guidelines\.\s*\n/gm,
13
- ""
14
- ), e = e.replace(/\n{3,}/g, `
15
-
16
- `), e;
17
- }
18
- function w(a) {
19
- return a.replace(
20
- /^(##\s+\[[^\]]+\][^\n]*\n)\n(##\s+\[|$)/gm,
21
- `$1
22
- **Note:** Version bump only for package
23
-
24
- $2`
25
- );
26
- }
27
- function W(a, e = !1) {
28
- console.log(i.cyan(`
29
- Enhancing changelogs...
30
- `));
31
- for (const s of a) {
32
- const c = d.join(s.path, "CHANGELOG.md");
33
- if (!G(c)) continue;
34
- let t = y(c, "utf-8");
35
- t = H(t), t = w(t), t = t.trim() + `
36
- `, e || N(c, t, "utf-8");
37
- }
38
- }
39
- function b(a) {
40
- const e = {}, s = {}, c = a.split(`
41
- `);
42
- let t = null, r = [];
43
- for (const n of c) {
44
- const f = n.match(/^##\s+(?:\[)?([\d.a-z-]+)(?:\])?(?:\s+\([^)]+\))?/i);
45
- f ? (t && r.length > 0 && (e[t] = r.join(`
46
- `).trim()), t = f[1], r = [], s[t] || (s[t] = n.replace(/^##\s+/, ""))) : t && n.trim() !== "" && !n.startsWith("# CHANGELOG") && !n.startsWith("# Change Log") && !n.startsWith("All notable changes") && !n.startsWith("See [Conventional Commits]") && r.push(n);
47
- }
48
- return t && r.length > 0 && (e[t] = r.join(`
49
- `).trim()), { versionContent: e, versionHeaders: s };
50
- }
51
- function L(a) {
52
- return [...a].sort((e, s) => v(e) && v(s) ? O(e, s) : s.localeCompare(e));
53
- }
54
- function E(a, e = !1) {
55
- const { packages: s, rootDir: c = process.cwd(), includeRootHeader: t = !1 } = a;
56
- console.log(i.cyan(`
57
- Generating root CHANGELOG with package grouping...
58
- `));
59
- const r = d.join(c, "CHANGELOG.md"), n = {}, f = {};
60
- for (const m of s) {
61
- const p = d.join(c, m.path, "CHANGELOG.md");
62
- if (!G(p)) continue;
63
- const k = y(p, "utf-8"), u = b(k);
64
- for (const [l, g] of Object.entries(u.versionContent))
65
- n[l] || (n[l] = {}), n[l][m.displayName] = g, !f[l] && u.versionHeaders[l] && (f[l] = u.versionHeaders[l]);
66
- }
67
- let o = "";
68
- t && (o = `# CHANGELOG
69
-
70
- All notable changes to this monorepo will be documented in this file.
71
-
72
- `);
73
- const C = L(Object.keys(n));
74
- for (const m of C) {
75
- const p = n[m], k = Object.values(p).some((g) => !g || !g.trim() ? !1 : g.replace(/\*\*Note:\*\*\s+Version bump only[^\n]*/gi, "").trim().length > 0), u = f[m] || m;
76
- if (o += `## ${u}
77
-
78
- `, !k) {
79
- o += `**Note:** Version bump only for package
80
-
81
- `;
82
- continue;
83
- }
84
- let l = !1;
85
- for (const g of s) {
86
- const h = p[g.displayName];
87
- h && h.trim() && h.replace(/\*\*Note:\*\*\s+Version bump only[^\n]*/gi, "").trim().length > 0 && (l = !0, o += `### ${g.displayName}
88
-
89
- `, o += `${h}
90
-
91
- `);
92
- }
93
- l || (o += `**Note:** Version bump only for package
94
-
95
- `);
96
- }
97
- o = o.replace(/\n{3,}/g, `
98
-
99
- `), o = o.trim() + `
100
- `, e ? console.log(i.yellow(` [dry-run] Would write root CHANGELOG.md (${C.length} versions)`)) : (N(r, o, "utf-8"), console.log(i.green(" Generated root CHANGELOG.md with package grouping")));
101
- }
102
- async function x(a) {
103
- const { packages: e, rootDir: s = process.cwd(), generateRoot: c = !0, includeRootHeader: t = !0 } = a;
104
- console.log(i.cyan(`
105
- Generating initial CHANGELOG.md files...
106
- `));
107
- for (const r of e) {
108
- const n = d.join(s, r.path, "CHANGELOG.md");
109
- if (G(n)) {
110
- const o = `${n}.backup`, C = y(n, "utf-8");
111
- N(o, C, "utf-8"), console.log(i.gray(` Backed up ${n} to ${o}`));
112
- }
113
- if (console.log(i.blue(`
114
- Generating changelog for ${r.name}...`)), A(
115
- "npx",
116
- [
117
- "conventional-changelog",
118
- "-p",
119
- "conventionalcommits",
120
- "-i",
121
- n,
122
- "-s",
123
- "-r",
124
- "0",
125
- "--commit-path",
126
- d.join(s, r.path)
127
- ],
128
- { stdio: "inherit", cwd: s }
129
- ).status === 0) {
130
- if (G(n)) {
131
- let o = y(n, "utf-8");
132
- o = H(o), o = w(o), o = o.trim() + `
133
- `, N(n, o, "utf-8");
134
- }
135
- console.log(i.green(` Generated ${n}`));
136
- } else
137
- console.log(i.red(` Failed to generate ${n}`));
138
- }
139
- c && await E({ packages: e, rootDir: s, includeRootHeader: t }), console.log(i.green(`
140
- Initial changelogs generated successfully!`)), console.log(i.cyan(`
141
- Next steps:`)), console.log(i.cyan(" 1. Review the generated CHANGELOG.md files")), console.log(i.cyan(" 2. Make any manual adjustments if needed")), console.log(i.cyan(` 3. Commit the changes
142
- `));
143
- }
144
- export {
145
- x as a,
146
- W as e,
147
- E as g
148
- };