@releasekit/notes 0.3.0-next.4 → 0.3.1

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,135 +0,0 @@
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, options) {
43
- const lines = [];
44
- const versionLabel = options?.includePackageName && context.packageName ? `${context.packageName}@${context.version}` : context.version;
45
- const versionHeader = context.previousVersion ? `## [${versionLabel}]` : `## ${versionLabel}`;
46
- lines.push(`${versionHeader} - ${context.date}`);
47
- lines.push("");
48
- if (context.compareUrl) {
49
- lines.push(`[Full Changelog](${context.compareUrl})`);
50
- lines.push("");
51
- }
52
- if (context.enhanced?.summary) {
53
- lines.push(context.enhanced.summary);
54
- lines.push("");
55
- }
56
- const grouped = groupEntriesByType(context.entries);
57
- for (const [type, entries] of grouped) {
58
- if (entries.length === 0) continue;
59
- lines.push(`### ${TYPE_LABELS[type]}`);
60
- for (const entry of entries) {
61
- lines.push(formatEntry(entry));
62
- }
63
- lines.push("");
64
- }
65
- return lines.join("\n");
66
- }
67
- function formatHeader() {
68
- return `# Changelog
69
-
70
- All notable changes to this project will be documented in this file.
71
-
72
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
73
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
74
-
75
- `;
76
- }
77
- function renderMarkdown(contexts, options) {
78
- const sections = [formatHeader()];
79
- for (const context of contexts) {
80
- sections.push(formatVersion(context, options));
81
- }
82
- return sections.join("\n");
83
- }
84
- function prependVersion(existingPath, context, options) {
85
- let existing = "";
86
- if (fs.existsSync(existingPath)) {
87
- existing = fs.readFileSync(existingPath, "utf-8");
88
- const headerEnd = existing.indexOf("\n## ");
89
- if (headerEnd >= 0) {
90
- const header = existing.slice(0, headerEnd);
91
- const body = existing.slice(headerEnd + 1);
92
- const newVersion = formatVersion(context, options);
93
- return `${header}
94
-
95
- ${newVersion}
96
- ${body}`;
97
- }
98
- }
99
- return renderMarkdown([context]);
100
- }
101
- function writeMarkdown(outputPath, contexts, config, dryRun) {
102
- const content = renderMarkdown(contexts);
103
- if (dryRun) {
104
- info(`Would write changelog to ${outputPath}`);
105
- debug("--- Changelog Preview ---");
106
- debug(content);
107
- debug("--- End Preview ---");
108
- return;
109
- }
110
- const dir = path.dirname(outputPath);
111
- if (!fs.existsSync(dir)) {
112
- fs.mkdirSync(dir, { recursive: true });
113
- }
114
- if (outputPath === "-") {
115
- process.stdout.write(content);
116
- return;
117
- }
118
- if (config.updateStrategy === "prepend" && fs.existsSync(outputPath) && contexts.length === 1) {
119
- const firstContext = contexts[0];
120
- if (firstContext) {
121
- const updated = prependVersion(outputPath, firstContext);
122
- fs.writeFileSync(outputPath, updated, "utf-8");
123
- }
124
- } else {
125
- fs.writeFileSync(outputPath, content, "utf-8");
126
- }
127
- success(`Changelog written to ${outputPath}`);
128
- }
129
-
130
- export {
131
- formatVersion,
132
- renderMarkdown,
133
- prependVersion,
134
- writeMarkdown
135
- };