@releasekit/notes 0.2.0 → 0.3.0-next.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @releasekit/notes
2
2
 
3
- Changelog generation from conventional commits with LLM-powered enhancement and flexible templating
3
+ Release notes and changelog generation from conventional commits with LLM-powered enhancement and flexible templating
4
4
 
5
5
  ## Features
6
6
 
@@ -0,0 +1,13 @@
1
+ import {
2
+ aggregateToRoot,
3
+ detectMonorepo,
4
+ splitByPackage,
5
+ writeMonorepoChangelogs
6
+ } from "./chunk-O4VCGEZT.js";
7
+ import "./chunk-H7G2HRHI.js";
8
+ export {
9
+ aggregateToRoot,
10
+ detectMonorepo,
11
+ splitByPackage,
12
+ writeMonorepoChangelogs
13
+ };
@@ -0,0 +1,134 @@
1
+ // src/output/markdown.ts
2
+ import * as fs from "fs";
3
+ import * as path from "path";
4
+ import { debug, info, success } from "@releasekit/core";
5
+ var TYPE_ORDER = ["added", "changed", "deprecated", "removed", "fixed", "security"];
6
+ var TYPE_LABELS = {
7
+ added: "Added",
8
+ changed: "Changed",
9
+ deprecated: "Deprecated",
10
+ removed: "Removed",
11
+ fixed: "Fixed",
12
+ security: "Security"
13
+ };
14
+ function groupEntriesByType(entries) {
15
+ const grouped = /* @__PURE__ */ new Map();
16
+ for (const type of TYPE_ORDER) {
17
+ grouped.set(type, []);
18
+ }
19
+ for (const entry of entries) {
20
+ const existing = grouped.get(entry.type) ?? [];
21
+ existing.push(entry);
22
+ grouped.set(entry.type, existing);
23
+ }
24
+ return grouped;
25
+ }
26
+ function formatEntry(entry) {
27
+ let line;
28
+ if (entry.breaking && entry.scope) {
29
+ line = `- **BREAKING** **${entry.scope}**: ${entry.description}`;
30
+ } else if (entry.breaking) {
31
+ line = `- **BREAKING** ${entry.description}`;
32
+ } else if (entry.scope) {
33
+ line = `- **${entry.scope}**: ${entry.description}`;
34
+ } else {
35
+ line = `- ${entry.description}`;
36
+ }
37
+ if (entry.issueIds && entry.issueIds.length > 0) {
38
+ line += ` (${entry.issueIds.join(", ")})`;
39
+ }
40
+ return line;
41
+ }
42
+ function formatVersion(context) {
43
+ const lines = [];
44
+ const versionHeader = context.previousVersion ? `## [${context.version}]` : `## ${context.version}`;
45
+ lines.push(`${versionHeader} - ${context.date}`);
46
+ lines.push("");
47
+ if (context.compareUrl) {
48
+ lines.push(`[Full Changelog](${context.compareUrl})`);
49
+ lines.push("");
50
+ }
51
+ if (context.enhanced?.summary) {
52
+ lines.push(context.enhanced.summary);
53
+ lines.push("");
54
+ }
55
+ const grouped = groupEntriesByType(context.entries);
56
+ for (const [type, entries] of grouped) {
57
+ if (entries.length === 0) continue;
58
+ lines.push(`### ${TYPE_LABELS[type]}`);
59
+ for (const entry of entries) {
60
+ lines.push(formatEntry(entry));
61
+ }
62
+ lines.push("");
63
+ }
64
+ return lines.join("\n");
65
+ }
66
+ function formatHeader() {
67
+ return `# Changelog
68
+
69
+ All notable changes to this project will be documented in this file.
70
+
71
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
72
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
73
+
74
+ `;
75
+ }
76
+ function renderMarkdown(contexts) {
77
+ const sections = [formatHeader()];
78
+ for (const context of contexts) {
79
+ sections.push(formatVersion(context));
80
+ }
81
+ return sections.join("\n");
82
+ }
83
+ function prependVersion(existingPath, context) {
84
+ let existing = "";
85
+ if (fs.existsSync(existingPath)) {
86
+ existing = fs.readFileSync(existingPath, "utf-8");
87
+ const headerEnd = existing.indexOf("\n## ");
88
+ if (headerEnd >= 0) {
89
+ const header = existing.slice(0, headerEnd);
90
+ const body = existing.slice(headerEnd + 1);
91
+ const newVersion = formatVersion(context);
92
+ return `${header}
93
+
94
+ ${newVersion}
95
+ ${body}`;
96
+ }
97
+ }
98
+ return renderMarkdown([context]);
99
+ }
100
+ function writeMarkdown(outputPath, contexts, config, dryRun) {
101
+ const content = renderMarkdown(contexts);
102
+ if (dryRun) {
103
+ info(`Would write changelog to ${outputPath}`);
104
+ debug("--- Changelog Preview ---");
105
+ debug(content);
106
+ debug("--- End Preview ---");
107
+ return;
108
+ }
109
+ const dir = path.dirname(outputPath);
110
+ if (!fs.existsSync(dir)) {
111
+ fs.mkdirSync(dir, { recursive: true });
112
+ }
113
+ if (outputPath === "-") {
114
+ process.stdout.write(content);
115
+ return;
116
+ }
117
+ if (config.updateStrategy === "prepend" && fs.existsSync(outputPath) && contexts.length === 1) {
118
+ const firstContext = contexts[0];
119
+ if (firstContext) {
120
+ const updated = prependVersion(outputPath, firstContext);
121
+ fs.writeFileSync(outputPath, updated, "utf-8");
122
+ }
123
+ } else {
124
+ fs.writeFileSync(outputPath, content, "utf-8");
125
+ }
126
+ success(`Changelog written to ${outputPath}`);
127
+ }
128
+
129
+ export {
130
+ formatVersion,
131
+ renderMarkdown,
132
+ prependVersion,
133
+ writeMarkdown
134
+ };
@@ -0,0 +1,147 @@
1
+ import {
2
+ prependVersion,
3
+ renderMarkdown
4
+ } from "./chunk-H7G2HRHI.js";
5
+
6
+ // src/monorepo/aggregator.ts
7
+ import * as fs from "fs";
8
+ import * as path from "path";
9
+ import { debug, info, success } from "@releasekit/core";
10
+
11
+ // src/monorepo/splitter.ts
12
+ function splitByPackage(contexts) {
13
+ const byPackage = /* @__PURE__ */ new Map();
14
+ for (const ctx of contexts) {
15
+ byPackage.set(ctx.packageName, ctx);
16
+ }
17
+ return byPackage;
18
+ }
19
+
20
+ // src/monorepo/aggregator.ts
21
+ function writeFile(outputPath, content, dryRun) {
22
+ if (dryRun) {
23
+ info(`Would write to ${outputPath}`);
24
+ debug(content);
25
+ return false;
26
+ }
27
+ const dir = path.dirname(outputPath);
28
+ if (!fs.existsSync(dir)) {
29
+ fs.mkdirSync(dir, { recursive: true });
30
+ }
31
+ fs.writeFileSync(outputPath, content, "utf-8");
32
+ success(`Changelog written to ${outputPath}`);
33
+ return true;
34
+ }
35
+ function aggregateToRoot(contexts) {
36
+ const aggregated = {
37
+ packageName: "monorepo",
38
+ version: contexts[0]?.version ?? "0.0.0",
39
+ previousVersion: contexts[0]?.previousVersion ?? null,
40
+ date: (/* @__PURE__ */ new Date()).toISOString().split("T")[0] ?? "",
41
+ repoUrl: contexts[0]?.repoUrl ?? null,
42
+ entries: []
43
+ };
44
+ for (const ctx of contexts) {
45
+ for (const entry of ctx.entries) {
46
+ aggregated.entries.push({
47
+ ...entry,
48
+ scope: entry.scope ? `${ctx.packageName}/${entry.scope}` : ctx.packageName
49
+ });
50
+ }
51
+ }
52
+ return aggregated;
53
+ }
54
+ function writeMonorepoChangelogs(contexts, options, config, dryRun) {
55
+ const files = [];
56
+ if (options.mode === "root" || options.mode === "both") {
57
+ const aggregated = aggregateToRoot(contexts);
58
+ const rootPath = path.join(options.rootPath, "CHANGELOG.md");
59
+ info(`Writing root changelog to ${rootPath}`);
60
+ const rootContent = config.updateStrategy === "prepend" && fs.existsSync(rootPath) ? prependVersion(rootPath, aggregated) : renderMarkdown([aggregated]);
61
+ if (writeFile(rootPath, rootContent, dryRun)) {
62
+ files.push(rootPath);
63
+ }
64
+ }
65
+ if (options.mode === "packages" || options.mode === "both") {
66
+ const byPackage = splitByPackage(contexts);
67
+ const packageDirMap = buildPackageDirMap(options.rootPath, options.packagesPath);
68
+ for (const [packageName, ctx] of byPackage) {
69
+ const simpleName = packageName.split("/").pop();
70
+ const packageDir = packageDirMap.get(packageName) ?? (simpleName ? packageDirMap.get(simpleName) : void 0) ?? null;
71
+ if (packageDir) {
72
+ const changelogPath = path.join(packageDir, "CHANGELOG.md");
73
+ info(`Writing changelog for ${packageName} to ${changelogPath}`);
74
+ const pkgContent = config.updateStrategy === "prepend" && fs.existsSync(changelogPath) ? prependVersion(changelogPath, ctx) : renderMarkdown([ctx]);
75
+ if (writeFile(changelogPath, pkgContent, dryRun)) {
76
+ files.push(changelogPath);
77
+ }
78
+ } else {
79
+ info(`Could not find directory for package ${packageName}, skipping`);
80
+ }
81
+ }
82
+ }
83
+ return files;
84
+ }
85
+ function buildPackageDirMap(rootPath, packagesPath) {
86
+ const map = /* @__PURE__ */ new Map();
87
+ const packagesDir = path.join(rootPath, packagesPath);
88
+ if (!fs.existsSync(packagesDir)) {
89
+ return map;
90
+ }
91
+ for (const entry of fs.readdirSync(packagesDir, { withFileTypes: true })) {
92
+ if (!entry.isDirectory()) continue;
93
+ const dirPath = path.join(packagesDir, entry.name);
94
+ map.set(entry.name, dirPath);
95
+ const packageJsonPath = path.join(dirPath, "package.json");
96
+ if (fs.existsSync(packageJsonPath)) {
97
+ try {
98
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
99
+ if (pkg.name) {
100
+ map.set(pkg.name, dirPath);
101
+ }
102
+ } catch {
103
+ }
104
+ }
105
+ }
106
+ return map;
107
+ }
108
+ function detectMonorepo(cwd) {
109
+ const pnpmWorkspacesPath = path.join(cwd, "pnpm-workspace.yaml");
110
+ const packageJsonPath = path.join(cwd, "package.json");
111
+ if (fs.existsSync(pnpmWorkspacesPath)) {
112
+ const content = fs.readFileSync(pnpmWorkspacesPath, "utf-8");
113
+ const packagesMatch = content.match(/packages:\s*\n\s*-\s*['"]([^'"]+)['"]/);
114
+ if (packagesMatch?.[1]) {
115
+ const packagesGlob = packagesMatch[1];
116
+ const packagesPath = packagesGlob.replace(/\/?\*$/, "").replace(/\/\*\*$/, "");
117
+ return { isMonorepo: true, packagesPath: packagesPath || "packages" };
118
+ }
119
+ return { isMonorepo: true, packagesPath: "packages" };
120
+ }
121
+ if (fs.existsSync(packageJsonPath)) {
122
+ try {
123
+ const content = fs.readFileSync(packageJsonPath, "utf-8");
124
+ const pkg = JSON.parse(content);
125
+ if (pkg.workspaces) {
126
+ const workspaces = Array.isArray(pkg.workspaces) ? pkg.workspaces : pkg.workspaces.packages;
127
+ if (workspaces?.length) {
128
+ const firstWorkspace = workspaces[0];
129
+ if (firstWorkspace) {
130
+ const packagesPath = firstWorkspace.replace(/\/?\*$/, "").replace(/\/\*\*$/, "");
131
+ return { isMonorepo: true, packagesPath: packagesPath || "packages" };
132
+ }
133
+ }
134
+ }
135
+ } catch {
136
+ return { isMonorepo: false, packagesPath: "" };
137
+ }
138
+ }
139
+ return { isMonorepo: false, packagesPath: "" };
140
+ }
141
+
142
+ export {
143
+ splitByPackage,
144
+ aggregateToRoot,
145
+ writeMonorepoChangelogs,
146
+ detectMonorepo
147
+ };