@releasekit/notes 0.1.0 → 0.2.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 +87 -143
- package/dist/{chunk-GN5RQW3G.js → chunk-NHDLQLG2.js} +96 -27
- package/dist/cli.cjs +115 -32
- package/dist/cli.js +20 -6
- package/dist/index.cjs +96 -27
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +1 -1
- package/package.json +5 -5
- package/dist/chunk-7Y5Y5LY6.js +0 -1496
- package/dist/chunk-DZVNOAOX.js +0 -1447
- package/dist/chunk-NYHVW46L.js +0 -1516
- package/dist/chunk-R4KN5PKO.js +0 -1509
- package/dist/chunk-RKRG4VKL.js +0 -1281
- package/dist/chunk-RX6K7GTL.js +0 -1363
- package/dist/chunk-TQNHZXY7.js +0 -1279
- package/dist/chunk-WMYZTQDI.js +0 -1496
- package/dist/chunk-XRLAWPB3.js +0 -1410
package/dist/chunk-XRLAWPB3.js
DELETED
|
@@ -1,1410 +0,0 @@
|
|
|
1
|
-
// src/core/config.ts
|
|
2
|
-
import {
|
|
3
|
-
loadAuth,
|
|
4
|
-
loadNotesConfig as loadSharedNotesConfig,
|
|
5
|
-
saveAuth
|
|
6
|
-
} from "@releasekit/config";
|
|
7
|
-
function loadConfig(projectDir = process.cwd(), configFile) {
|
|
8
|
-
const options = { cwd: projectDir, configPath: configFile };
|
|
9
|
-
return loadSharedNotesConfig(options) ?? getDefaultConfig();
|
|
10
|
-
}
|
|
11
|
-
function getDefaultConfig() {
|
|
12
|
-
return {
|
|
13
|
-
output: [{ format: "markdown", file: "CHANGELOG.md" }],
|
|
14
|
-
updateStrategy: "prepend"
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// src/errors/index.ts
|
|
19
|
-
import { EXIT_CODES, ReleaseKitError } from "@releasekit/core";
|
|
20
|
-
import { EXIT_CODES as EXIT_CODES2 } from "@releasekit/core";
|
|
21
|
-
var NotesError = class extends ReleaseKitError {
|
|
22
|
-
};
|
|
23
|
-
var InputParseError = class extends NotesError {
|
|
24
|
-
code = "INPUT_PARSE_ERROR";
|
|
25
|
-
suggestions = [
|
|
26
|
-
"Ensure input is valid JSON",
|
|
27
|
-
"Check that input matches expected schema",
|
|
28
|
-
"Use --input-source to specify format"
|
|
29
|
-
];
|
|
30
|
-
};
|
|
31
|
-
var TemplateError = class extends NotesError {
|
|
32
|
-
code = "TEMPLATE_ERROR";
|
|
33
|
-
suggestions = [
|
|
34
|
-
"Check template syntax",
|
|
35
|
-
"Ensure all required files exist (document, version, entry)",
|
|
36
|
-
"Verify template engine matches file extension"
|
|
37
|
-
];
|
|
38
|
-
};
|
|
39
|
-
var LLMError = class extends NotesError {
|
|
40
|
-
code = "LLM_ERROR";
|
|
41
|
-
suggestions = [
|
|
42
|
-
"Check API key is configured",
|
|
43
|
-
"Verify model name is correct",
|
|
44
|
-
"Check network connectivity",
|
|
45
|
-
"Try with --no-llm to skip LLM processing"
|
|
46
|
-
];
|
|
47
|
-
};
|
|
48
|
-
var GitHubError = class extends NotesError {
|
|
49
|
-
code = "GITHUB_ERROR";
|
|
50
|
-
suggestions = [
|
|
51
|
-
"Ensure GITHUB_TOKEN is set",
|
|
52
|
-
"Check token has repo scope",
|
|
53
|
-
"Verify repository exists and is accessible"
|
|
54
|
-
];
|
|
55
|
-
};
|
|
56
|
-
var ConfigError = class extends NotesError {
|
|
57
|
-
code = "CONFIG_ERROR";
|
|
58
|
-
suggestions = [
|
|
59
|
-
"Check config file syntax",
|
|
60
|
-
"Verify all required fields are present",
|
|
61
|
-
"Run releasekit-notes init to create default config"
|
|
62
|
-
];
|
|
63
|
-
};
|
|
64
|
-
function getExitCode(error) {
|
|
65
|
-
switch (error.code) {
|
|
66
|
-
case "CONFIG_ERROR":
|
|
67
|
-
return EXIT_CODES.CONFIG_ERROR;
|
|
68
|
-
case "INPUT_PARSE_ERROR":
|
|
69
|
-
return EXIT_CODES.INPUT_ERROR;
|
|
70
|
-
case "TEMPLATE_ERROR":
|
|
71
|
-
return EXIT_CODES.TEMPLATE_ERROR;
|
|
72
|
-
case "LLM_ERROR":
|
|
73
|
-
return EXIT_CODES.LLM_ERROR;
|
|
74
|
-
case "GITHUB_ERROR":
|
|
75
|
-
return EXIT_CODES.GITHUB_ERROR;
|
|
76
|
-
default:
|
|
77
|
-
return EXIT_CODES.GENERAL_ERROR;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// src/input/package-versioner.ts
|
|
82
|
-
import * as fs from "fs";
|
|
83
|
-
function normalizeEntryType(type) {
|
|
84
|
-
const typeMap = {
|
|
85
|
-
added: "added",
|
|
86
|
-
feat: "added",
|
|
87
|
-
feature: "added",
|
|
88
|
-
changed: "changed",
|
|
89
|
-
update: "changed",
|
|
90
|
-
refactor: "changed",
|
|
91
|
-
deprecated: "deprecated",
|
|
92
|
-
removed: "removed",
|
|
93
|
-
fixed: "fixed",
|
|
94
|
-
fix: "fixed",
|
|
95
|
-
security: "security",
|
|
96
|
-
sec: "security"
|
|
97
|
-
};
|
|
98
|
-
return typeMap[type.toLowerCase()] ?? "changed";
|
|
99
|
-
}
|
|
100
|
-
function parsePackageVersioner(json) {
|
|
101
|
-
let data;
|
|
102
|
-
try {
|
|
103
|
-
data = JSON.parse(json);
|
|
104
|
-
} catch (error) {
|
|
105
|
-
throw new InputParseError(`Invalid JSON input: ${error instanceof Error ? error.message : String(error)}`);
|
|
106
|
-
}
|
|
107
|
-
if (!data.changelogs || !Array.isArray(data.changelogs)) {
|
|
108
|
-
throw new InputParseError('Input must contain a "changelogs" array');
|
|
109
|
-
}
|
|
110
|
-
const packages = data.changelogs.map((changelog) => ({
|
|
111
|
-
packageName: changelog.packageName,
|
|
112
|
-
version: changelog.version,
|
|
113
|
-
previousVersion: changelog.previousVersion,
|
|
114
|
-
revisionRange: changelog.revisionRange,
|
|
115
|
-
repoUrl: changelog.repoUrl,
|
|
116
|
-
date: (/* @__PURE__ */ new Date()).toISOString().split("T")[0] ?? "",
|
|
117
|
-
entries: changelog.entries.map((entry) => ({
|
|
118
|
-
type: normalizeEntryType(entry.type),
|
|
119
|
-
description: entry.description,
|
|
120
|
-
issueIds: entry.issueIds,
|
|
121
|
-
scope: entry.scope,
|
|
122
|
-
originalType: entry.originalType,
|
|
123
|
-
breaking: entry.originalType?.includes("!")
|
|
124
|
-
}))
|
|
125
|
-
}));
|
|
126
|
-
const repoUrl = packages[0]?.repoUrl ?? null;
|
|
127
|
-
return {
|
|
128
|
-
source: "package-versioner",
|
|
129
|
-
packages,
|
|
130
|
-
metadata: {
|
|
131
|
-
repoUrl: repoUrl ?? void 0
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
function parsePackageVersionerFile(filePath) {
|
|
136
|
-
const content = fs.readFileSync(filePath, "utf-8");
|
|
137
|
-
return parsePackageVersioner(content);
|
|
138
|
-
}
|
|
139
|
-
async function parsePackageVersionerStdin() {
|
|
140
|
-
const chunks = [];
|
|
141
|
-
for await (const chunk of process.stdin) {
|
|
142
|
-
chunks.push(chunk);
|
|
143
|
-
}
|
|
144
|
-
const content = chunks.join("");
|
|
145
|
-
return parsePackageVersioner(content);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// src/output/markdown.ts
|
|
149
|
-
import * as fs2 from "fs";
|
|
150
|
-
import * as path from "path";
|
|
151
|
-
import { info, success } from "@releasekit/core";
|
|
152
|
-
var TYPE_ORDER = ["added", "changed", "deprecated", "removed", "fixed", "security"];
|
|
153
|
-
var TYPE_LABELS = {
|
|
154
|
-
added: "Added",
|
|
155
|
-
changed: "Changed",
|
|
156
|
-
deprecated: "Deprecated",
|
|
157
|
-
removed: "Removed",
|
|
158
|
-
fixed: "Fixed",
|
|
159
|
-
security: "Security"
|
|
160
|
-
};
|
|
161
|
-
function groupEntriesByType(entries) {
|
|
162
|
-
const grouped = /* @__PURE__ */ new Map();
|
|
163
|
-
for (const type of TYPE_ORDER) {
|
|
164
|
-
grouped.set(type, []);
|
|
165
|
-
}
|
|
166
|
-
for (const entry of entries) {
|
|
167
|
-
const existing = grouped.get(entry.type) ?? [];
|
|
168
|
-
existing.push(entry);
|
|
169
|
-
grouped.set(entry.type, existing);
|
|
170
|
-
}
|
|
171
|
-
return grouped;
|
|
172
|
-
}
|
|
173
|
-
function formatEntry(entry) {
|
|
174
|
-
let line;
|
|
175
|
-
if (entry.breaking && entry.scope) {
|
|
176
|
-
line = `- **BREAKING** **${entry.scope}**: ${entry.description}`;
|
|
177
|
-
} else if (entry.breaking) {
|
|
178
|
-
line = `- **BREAKING** ${entry.description}`;
|
|
179
|
-
} else if (entry.scope) {
|
|
180
|
-
line = `- **${entry.scope}**: ${entry.description}`;
|
|
181
|
-
} else {
|
|
182
|
-
line = `- ${entry.description}`;
|
|
183
|
-
}
|
|
184
|
-
if (entry.issueIds && entry.issueIds.length > 0) {
|
|
185
|
-
line += ` (${entry.issueIds.join(", ")})`;
|
|
186
|
-
}
|
|
187
|
-
return line;
|
|
188
|
-
}
|
|
189
|
-
function formatVersion(context) {
|
|
190
|
-
const lines = [];
|
|
191
|
-
const versionHeader = context.previousVersion ? `## [${context.version}]` : `## ${context.version}`;
|
|
192
|
-
lines.push(`${versionHeader} - ${context.date}`);
|
|
193
|
-
lines.push("");
|
|
194
|
-
if (context.compareUrl) {
|
|
195
|
-
lines.push(`[Full Changelog](${context.compareUrl})`);
|
|
196
|
-
lines.push("");
|
|
197
|
-
}
|
|
198
|
-
const grouped = groupEntriesByType(context.entries);
|
|
199
|
-
for (const [type, entries] of grouped) {
|
|
200
|
-
if (entries.length === 0) continue;
|
|
201
|
-
lines.push(`### ${TYPE_LABELS[type]}`);
|
|
202
|
-
for (const entry of entries) {
|
|
203
|
-
lines.push(formatEntry(entry));
|
|
204
|
-
}
|
|
205
|
-
lines.push("");
|
|
206
|
-
}
|
|
207
|
-
return lines.join("\n");
|
|
208
|
-
}
|
|
209
|
-
function formatHeader() {
|
|
210
|
-
return `# Changelog
|
|
211
|
-
|
|
212
|
-
All notable changes to this project will be documented in this file.
|
|
213
|
-
|
|
214
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
215
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
216
|
-
|
|
217
|
-
`;
|
|
218
|
-
}
|
|
219
|
-
function renderMarkdown(contexts) {
|
|
220
|
-
const sections = [formatHeader()];
|
|
221
|
-
for (const context of contexts) {
|
|
222
|
-
sections.push(formatVersion(context));
|
|
223
|
-
}
|
|
224
|
-
return sections.join("\n");
|
|
225
|
-
}
|
|
226
|
-
function prependVersion(existingPath, context) {
|
|
227
|
-
let existing = "";
|
|
228
|
-
if (fs2.existsSync(existingPath)) {
|
|
229
|
-
existing = fs2.readFileSync(existingPath, "utf-8");
|
|
230
|
-
const headerEnd = existing.indexOf("\n## ");
|
|
231
|
-
if (headerEnd >= 0) {
|
|
232
|
-
const header = existing.slice(0, headerEnd);
|
|
233
|
-
const body = existing.slice(headerEnd + 1);
|
|
234
|
-
const newVersion = formatVersion(context);
|
|
235
|
-
return `${header}
|
|
236
|
-
|
|
237
|
-
${newVersion}
|
|
238
|
-
${body}`;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
return renderMarkdown([context]);
|
|
242
|
-
}
|
|
243
|
-
function writeMarkdown(outputPath, contexts, config, dryRun) {
|
|
244
|
-
const content = renderMarkdown(contexts);
|
|
245
|
-
if (dryRun) {
|
|
246
|
-
info("--- Changelog Preview ---");
|
|
247
|
-
console.log(content);
|
|
248
|
-
info("--- End Preview ---");
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
const dir = path.dirname(outputPath);
|
|
252
|
-
if (!fs2.existsSync(dir)) {
|
|
253
|
-
fs2.mkdirSync(dir, { recursive: true });
|
|
254
|
-
}
|
|
255
|
-
if (config.updateStrategy === "prepend" && fs2.existsSync(outputPath) && contexts.length === 1) {
|
|
256
|
-
const firstContext = contexts[0];
|
|
257
|
-
if (firstContext) {
|
|
258
|
-
const updated = prependVersion(outputPath, firstContext);
|
|
259
|
-
fs2.writeFileSync(outputPath, updated, "utf-8");
|
|
260
|
-
}
|
|
261
|
-
} else {
|
|
262
|
-
fs2.writeFileSync(outputPath, content, "utf-8");
|
|
263
|
-
}
|
|
264
|
-
success(`Changelog written to ${outputPath}`);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// src/output/json.ts
|
|
268
|
-
import * as fs3 from "fs";
|
|
269
|
-
import * as path2 from "path";
|
|
270
|
-
import { info as info2, success as success2 } from "@releasekit/core";
|
|
271
|
-
function renderJson(contexts) {
|
|
272
|
-
return JSON.stringify(
|
|
273
|
-
{
|
|
274
|
-
versions: contexts.map((ctx) => ({
|
|
275
|
-
packageName: ctx.packageName,
|
|
276
|
-
version: ctx.version,
|
|
277
|
-
previousVersion: ctx.previousVersion,
|
|
278
|
-
date: ctx.date,
|
|
279
|
-
entries: ctx.entries,
|
|
280
|
-
compareUrl: ctx.compareUrl
|
|
281
|
-
}))
|
|
282
|
-
},
|
|
283
|
-
null,
|
|
284
|
-
2
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
function writeJson(outputPath, contexts, dryRun) {
|
|
288
|
-
const content = renderJson(contexts);
|
|
289
|
-
if (dryRun) {
|
|
290
|
-
info2("--- JSON Output Preview ---");
|
|
291
|
-
console.log(content);
|
|
292
|
-
info2("--- End Preview ---");
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
const dir = path2.dirname(outputPath);
|
|
296
|
-
if (!fs3.existsSync(dir)) {
|
|
297
|
-
fs3.mkdirSync(dir, { recursive: true });
|
|
298
|
-
}
|
|
299
|
-
fs3.writeFileSync(outputPath, content, "utf-8");
|
|
300
|
-
success2(`JSON output written to ${outputPath}`);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// src/core/pipeline.ts
|
|
304
|
-
import * as fs8 from "fs";
|
|
305
|
-
import * as path6 from "path";
|
|
306
|
-
import { debug, info as info4, success as success4, warn as warn2 } from "@releasekit/core";
|
|
307
|
-
|
|
308
|
-
// src/llm/defaults.ts
|
|
309
|
-
var LLM_DEFAULTS = {
|
|
310
|
-
timeout: 6e4,
|
|
311
|
-
maxTokens: 2e3,
|
|
312
|
-
temperature: 0.7,
|
|
313
|
-
concurrency: 5,
|
|
314
|
-
retry: {
|
|
315
|
-
maxAttempts: 3,
|
|
316
|
-
initialDelay: 1e3,
|
|
317
|
-
maxDelay: 3e4,
|
|
318
|
-
backoffFactor: 2
|
|
319
|
-
},
|
|
320
|
-
models: {
|
|
321
|
-
openai: "gpt-4o-mini",
|
|
322
|
-
"openai-compatible": "gpt-4o-mini",
|
|
323
|
-
anthropic: "claude-3-5-haiku-latest",
|
|
324
|
-
ollama: "llama3.2"
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
// src/llm/anthropic.ts
|
|
329
|
-
import Anthropic from "@anthropic-ai/sdk";
|
|
330
|
-
|
|
331
|
-
// src/llm/base.ts
|
|
332
|
-
var BaseLLMProvider = class {
|
|
333
|
-
getTimeout(options) {
|
|
334
|
-
return options?.timeout ?? LLM_DEFAULTS.timeout;
|
|
335
|
-
}
|
|
336
|
-
getMaxTokens(options) {
|
|
337
|
-
return options?.maxTokens ?? LLM_DEFAULTS.maxTokens;
|
|
338
|
-
}
|
|
339
|
-
getTemperature(options) {
|
|
340
|
-
return options?.temperature ?? LLM_DEFAULTS.temperature;
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
// src/llm/anthropic.ts
|
|
345
|
-
var AnthropicProvider = class extends BaseLLMProvider {
|
|
346
|
-
name = "anthropic";
|
|
347
|
-
client;
|
|
348
|
-
model;
|
|
349
|
-
constructor(config = {}) {
|
|
350
|
-
super();
|
|
351
|
-
const apiKey = config.apiKey ?? process.env.ANTHROPIC_API_KEY;
|
|
352
|
-
if (!apiKey) {
|
|
353
|
-
throw new LLMError("Anthropic API key not configured. Set ANTHROPIC_API_KEY or use --llm-api-key");
|
|
354
|
-
}
|
|
355
|
-
this.client = new Anthropic({ apiKey });
|
|
356
|
-
this.model = config.model ?? LLM_DEFAULTS.models.anthropic;
|
|
357
|
-
}
|
|
358
|
-
async complete(prompt, options) {
|
|
359
|
-
try {
|
|
360
|
-
const response = await this.client.messages.create({
|
|
361
|
-
model: this.model,
|
|
362
|
-
max_tokens: this.getMaxTokens(options),
|
|
363
|
-
messages: [{ role: "user", content: prompt }]
|
|
364
|
-
});
|
|
365
|
-
const firstBlock = response.content[0];
|
|
366
|
-
if (!firstBlock || firstBlock.type !== "text") {
|
|
367
|
-
throw new LLMError("Unexpected response format from Anthropic");
|
|
368
|
-
}
|
|
369
|
-
return firstBlock.text;
|
|
370
|
-
} catch (error) {
|
|
371
|
-
if (error instanceof LLMError) throw error;
|
|
372
|
-
throw new LLMError(`Anthropic API error: ${error instanceof Error ? error.message : String(error)}`);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
// src/llm/ollama.ts
|
|
378
|
-
var OllamaProvider = class extends BaseLLMProvider {
|
|
379
|
-
name = "ollama";
|
|
380
|
-
baseURL;
|
|
381
|
-
model;
|
|
382
|
-
constructor(config = {}) {
|
|
383
|
-
super();
|
|
384
|
-
this.baseURL = config.baseURL ?? process.env.OLLAMA_BASE_URL ?? "http://localhost:11434";
|
|
385
|
-
this.model = config.model ?? LLM_DEFAULTS.models.ollama;
|
|
386
|
-
}
|
|
387
|
-
async complete(prompt, options) {
|
|
388
|
-
const requestBody = {
|
|
389
|
-
model: this.model,
|
|
390
|
-
prompt,
|
|
391
|
-
stream: false,
|
|
392
|
-
options: {
|
|
393
|
-
num_predict: this.getMaxTokens(options),
|
|
394
|
-
temperature: this.getTemperature(options)
|
|
395
|
-
}
|
|
396
|
-
};
|
|
397
|
-
try {
|
|
398
|
-
const response = await fetch(`${this.baseURL}/api/generate`, {
|
|
399
|
-
method: "POST",
|
|
400
|
-
headers: {
|
|
401
|
-
"Content-Type": "application/json"
|
|
402
|
-
},
|
|
403
|
-
body: JSON.stringify(requestBody)
|
|
404
|
-
});
|
|
405
|
-
if (!response.ok) {
|
|
406
|
-
const text = await response.text();
|
|
407
|
-
throw new LLMError(`Ollama request failed: ${response.status} ${text}`);
|
|
408
|
-
}
|
|
409
|
-
const data = await response.json();
|
|
410
|
-
if (!data.response) {
|
|
411
|
-
throw new LLMError("Empty response from Ollama");
|
|
412
|
-
}
|
|
413
|
-
return data.response;
|
|
414
|
-
} catch (error) {
|
|
415
|
-
if (error instanceof LLMError) throw error;
|
|
416
|
-
throw new LLMError(`Ollama error: ${error instanceof Error ? error.message : String(error)}`);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
|
|
421
|
-
// src/llm/openai.ts
|
|
422
|
-
import OpenAI from "openai";
|
|
423
|
-
var OpenAIProvider = class extends BaseLLMProvider {
|
|
424
|
-
name = "openai";
|
|
425
|
-
client;
|
|
426
|
-
model;
|
|
427
|
-
constructor(config = {}) {
|
|
428
|
-
super();
|
|
429
|
-
const apiKey = config.apiKey ?? process.env.OPENAI_API_KEY;
|
|
430
|
-
if (!apiKey) {
|
|
431
|
-
throw new LLMError("OpenAI API key not configured. Set OPENAI_API_KEY or use --llm-api-key");
|
|
432
|
-
}
|
|
433
|
-
this.client = new OpenAI({
|
|
434
|
-
apiKey,
|
|
435
|
-
baseURL: config.baseURL
|
|
436
|
-
});
|
|
437
|
-
this.model = config.model ?? LLM_DEFAULTS.models.openai;
|
|
438
|
-
}
|
|
439
|
-
async complete(prompt, options) {
|
|
440
|
-
try {
|
|
441
|
-
const response = await this.client.chat.completions.create({
|
|
442
|
-
model: this.model,
|
|
443
|
-
messages: [{ role: "user", content: prompt }],
|
|
444
|
-
max_tokens: this.getMaxTokens(options),
|
|
445
|
-
temperature: this.getTemperature(options)
|
|
446
|
-
});
|
|
447
|
-
const content = response.choices[0]?.message?.content;
|
|
448
|
-
if (!content) {
|
|
449
|
-
throw new LLMError("Empty response from OpenAI");
|
|
450
|
-
}
|
|
451
|
-
return content;
|
|
452
|
-
} catch (error) {
|
|
453
|
-
if (error instanceof LLMError) throw error;
|
|
454
|
-
throw new LLMError(`OpenAI API error: ${error instanceof Error ? error.message : String(error)}`);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
|
-
|
|
459
|
-
// src/llm/openai-compatible.ts
|
|
460
|
-
import OpenAI2 from "openai";
|
|
461
|
-
var OpenAICompatibleProvider = class extends BaseLLMProvider {
|
|
462
|
-
name = "openai-compatible";
|
|
463
|
-
client;
|
|
464
|
-
model;
|
|
465
|
-
constructor(config) {
|
|
466
|
-
super();
|
|
467
|
-
const apiKey = config.apiKey ?? process.env.OPENAI_API_KEY ?? "dummy";
|
|
468
|
-
this.client = new OpenAI2({
|
|
469
|
-
apiKey,
|
|
470
|
-
baseURL: config.baseURL
|
|
471
|
-
});
|
|
472
|
-
this.model = config.model ?? LLM_DEFAULTS.models["openai-compatible"];
|
|
473
|
-
}
|
|
474
|
-
async complete(prompt, options) {
|
|
475
|
-
try {
|
|
476
|
-
const response = await this.client.chat.completions.create({
|
|
477
|
-
model: this.model,
|
|
478
|
-
messages: [{ role: "user", content: prompt }],
|
|
479
|
-
max_tokens: this.getMaxTokens(options),
|
|
480
|
-
temperature: this.getTemperature(options)
|
|
481
|
-
});
|
|
482
|
-
const content = response.choices[0]?.message?.content;
|
|
483
|
-
if (!content) {
|
|
484
|
-
throw new LLMError("Empty response from LLM");
|
|
485
|
-
}
|
|
486
|
-
return content;
|
|
487
|
-
} catch (error) {
|
|
488
|
-
if (error instanceof LLMError) throw error;
|
|
489
|
-
throw new LLMError(`LLM API error: ${error instanceof Error ? error.message : String(error)}`);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
};
|
|
493
|
-
|
|
494
|
-
// src/llm/tasks/categorize.ts
|
|
495
|
-
import { warn } from "@releasekit/core";
|
|
496
|
-
var CATEGORIZE_PROMPT = `You are categorizing changelog entries for a software release.
|
|
497
|
-
|
|
498
|
-
Given the following entries, group them into meaningful categories (e.g., "Core", "UI", "API", "Performance", "Bug Fixes", "Documentation").
|
|
499
|
-
|
|
500
|
-
Output a JSON object where keys are category names and values are arrays of entry indices (0-based).
|
|
501
|
-
|
|
502
|
-
Entries:
|
|
503
|
-
{{entries}}
|
|
504
|
-
|
|
505
|
-
Output only valid JSON, nothing else:`;
|
|
506
|
-
async function categorizeEntries(provider, entries, _context) {
|
|
507
|
-
if (entries.length === 0) {
|
|
508
|
-
return [];
|
|
509
|
-
}
|
|
510
|
-
const entriesText = entries.map((e, i) => `${i}. [${e.type}]${e.scope ? ` (${e.scope})` : ""}: ${e.description}`).join("\n");
|
|
511
|
-
const prompt = CATEGORIZE_PROMPT.replace("{{entries}}", entriesText);
|
|
512
|
-
try {
|
|
513
|
-
const response = await provider.complete(prompt);
|
|
514
|
-
const cleaned = response.replace(/^```(?:json)?\n?/, "").replace(/\n?```$/, "").trim();
|
|
515
|
-
const parsed = JSON.parse(cleaned);
|
|
516
|
-
const result = [];
|
|
517
|
-
for (const [category, indices] of Object.entries(parsed)) {
|
|
518
|
-
const categoryEntries = indices.map((i) => entries[i]).filter((e) => e !== void 0);
|
|
519
|
-
if (categoryEntries.length > 0) {
|
|
520
|
-
result.push({
|
|
521
|
-
category,
|
|
522
|
-
entries: categoryEntries
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
return result;
|
|
527
|
-
} catch (error) {
|
|
528
|
-
warn(
|
|
529
|
-
`LLM categorization failed, falling back to General: ${error instanceof Error ? error.message : String(error)}`
|
|
530
|
-
);
|
|
531
|
-
return [{ category: "General", entries }];
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
// src/llm/tasks/enhance.ts
|
|
536
|
-
var ENHANCE_PROMPT = `You are improving changelog entries for a software project.
|
|
537
|
-
Given a technical commit message, rewrite it as a clear, user-friendly changelog entry.
|
|
538
|
-
|
|
539
|
-
Rules:
|
|
540
|
-
- Be concise (1-2 sentences max)
|
|
541
|
-
- Use present tense ("Add feature" not "Added feature")
|
|
542
|
-
- Focus on user impact, not implementation details
|
|
543
|
-
- Don't use technical jargon unless necessary
|
|
544
|
-
- Preserve the scope if mentioned (e.g., "core:", "api:")
|
|
545
|
-
|
|
546
|
-
Original entry:
|
|
547
|
-
Type: {{type}}
|
|
548
|
-
{{#if scope}}Scope: {{scope}}{{/if}}
|
|
549
|
-
Description: {{description}}
|
|
550
|
-
|
|
551
|
-
Rewritten description (only output the new description, nothing else):`;
|
|
552
|
-
async function enhanceEntry(provider, entry, _context) {
|
|
553
|
-
const prompt = ENHANCE_PROMPT.replace("{{type}}", entry.type).replace("{{#if scope}}Scope: {{scope}}{{/if}}", entry.scope ? `Scope: ${entry.scope}` : "").replace("{{description}}", entry.description);
|
|
554
|
-
const response = await provider.complete(prompt);
|
|
555
|
-
return response.trim();
|
|
556
|
-
}
|
|
557
|
-
async function enhanceEntries(provider, entries, context, concurrency = LLM_DEFAULTS.concurrency) {
|
|
558
|
-
const results = [];
|
|
559
|
-
for (let i = 0; i < entries.length; i += concurrency) {
|
|
560
|
-
const batch = entries.slice(i, i + concurrency);
|
|
561
|
-
const batchResults = await Promise.all(
|
|
562
|
-
batch.map(async (entry) => {
|
|
563
|
-
try {
|
|
564
|
-
const newDescription = await enhanceEntry(provider, entry, context);
|
|
565
|
-
return { ...entry, description: newDescription };
|
|
566
|
-
} catch {
|
|
567
|
-
return entry;
|
|
568
|
-
}
|
|
569
|
-
})
|
|
570
|
-
);
|
|
571
|
-
results.push(...batchResults);
|
|
572
|
-
}
|
|
573
|
-
return results;
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
// src/llm/tasks/release-notes.ts
|
|
577
|
-
var RELEASE_NOTES_PROMPT = `You are writing release notes for a software project.
|
|
578
|
-
|
|
579
|
-
Create engaging, user-friendly release notes for the following changes.
|
|
580
|
-
|
|
581
|
-
Rules:
|
|
582
|
-
- Start with a brief introduction (1-2 sentences)
|
|
583
|
-
- Group related changes into sections
|
|
584
|
-
- Use friendly, approachable language
|
|
585
|
-
- Highlight breaking changes prominently
|
|
586
|
-
- End with a brief conclusion or call to action
|
|
587
|
-
- Use markdown formatting
|
|
588
|
-
|
|
589
|
-
Version: {{version}}
|
|
590
|
-
{{#if previousVersion}}Previous version: {{previousVersion}}{{/if}}
|
|
591
|
-
Date: {{date}}
|
|
592
|
-
|
|
593
|
-
Changes:
|
|
594
|
-
{{entries}}
|
|
595
|
-
|
|
596
|
-
Release notes (output only the markdown content):`;
|
|
597
|
-
async function generateReleaseNotes(provider, entries, context) {
|
|
598
|
-
if (entries.length === 0) {
|
|
599
|
-
return `## Release ${context.version ?? "v1.0.0"}
|
|
600
|
-
|
|
601
|
-
No notable changes in this release.`;
|
|
602
|
-
}
|
|
603
|
-
const entriesText = entries.map((e) => {
|
|
604
|
-
let line = `- [${e.type}]`;
|
|
605
|
-
if (e.scope) line += ` (${e.scope})`;
|
|
606
|
-
line += `: ${e.description}`;
|
|
607
|
-
if (e.breaking) line += " **BREAKING**";
|
|
608
|
-
return line;
|
|
609
|
-
}).join("\n");
|
|
610
|
-
const prompt = RELEASE_NOTES_PROMPT.replace("{{version}}", context.version ?? "v1.0.0").replace(
|
|
611
|
-
"{{#if previousVersion}}Previous version: {{previousVersion}}{{/if}}",
|
|
612
|
-
context.previousVersion ? `Previous version: ${context.previousVersion}` : ""
|
|
613
|
-
).replace("{{date}}", context.date ?? (/* @__PURE__ */ new Date()).toISOString().split("T")[0] ?? "").replace("{{entries}}", entriesText);
|
|
614
|
-
const response = await provider.complete(prompt);
|
|
615
|
-
return response.trim();
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
// src/llm/tasks/summarize.ts
|
|
619
|
-
var SUMMARIZE_PROMPT = `You are creating a summary of changes for a software release.
|
|
620
|
-
|
|
621
|
-
Given the following changelog entries, create a brief summary (2-3 sentences) that captures the main themes of this release.
|
|
622
|
-
|
|
623
|
-
Entries:
|
|
624
|
-
{{entries}}
|
|
625
|
-
|
|
626
|
-
Summary (only output the summary, nothing else):`;
|
|
627
|
-
async function summarizeEntries(provider, entries, _context) {
|
|
628
|
-
if (entries.length === 0) {
|
|
629
|
-
return "";
|
|
630
|
-
}
|
|
631
|
-
const entriesText = entries.map((e) => `- [${e.type}]${e.scope ? ` (${e.scope})` : ""}: ${e.description}`).join("\n");
|
|
632
|
-
const prompt = SUMMARIZE_PROMPT.replace("{{entries}}", entriesText);
|
|
633
|
-
const response = await provider.complete(prompt);
|
|
634
|
-
return response.trim();
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
// src/llm/index.ts
|
|
638
|
-
function createProvider(config) {
|
|
639
|
-
const authKeys = loadAuth();
|
|
640
|
-
const apiKey = config.apiKey ?? authKeys[config.provider];
|
|
641
|
-
switch (config.provider) {
|
|
642
|
-
case "openai":
|
|
643
|
-
return new OpenAIProvider({
|
|
644
|
-
apiKey,
|
|
645
|
-
baseURL: config.baseURL,
|
|
646
|
-
model: config.model
|
|
647
|
-
});
|
|
648
|
-
case "anthropic":
|
|
649
|
-
return new AnthropicProvider({
|
|
650
|
-
apiKey,
|
|
651
|
-
model: config.model
|
|
652
|
-
});
|
|
653
|
-
case "ollama":
|
|
654
|
-
return new OllamaProvider({
|
|
655
|
-
baseURL: config.baseURL,
|
|
656
|
-
model: config.model
|
|
657
|
-
});
|
|
658
|
-
case "openai-compatible": {
|
|
659
|
-
if (!config.baseURL) {
|
|
660
|
-
throw new LLMError("openai-compatible provider requires baseURL");
|
|
661
|
-
}
|
|
662
|
-
return new OpenAICompatibleProvider({
|
|
663
|
-
apiKey,
|
|
664
|
-
baseURL: config.baseURL,
|
|
665
|
-
model: config.model
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
default:
|
|
669
|
-
throw new LLMError(`Unknown LLM provider: ${config.provider}`);
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
// src/output/github-release.ts
|
|
674
|
-
import { Octokit } from "@octokit/rest";
|
|
675
|
-
import { info as info3, success as success3 } from "@releasekit/core";
|
|
676
|
-
var GitHubClient = class {
|
|
677
|
-
octokit;
|
|
678
|
-
owner;
|
|
679
|
-
repo;
|
|
680
|
-
constructor(options) {
|
|
681
|
-
const token = options.token ?? process.env.GITHUB_TOKEN;
|
|
682
|
-
if (!token) {
|
|
683
|
-
throw new GitHubError("GITHUB_TOKEN not set. Set it as an environment variable.");
|
|
684
|
-
}
|
|
685
|
-
this.octokit = new Octokit({ auth: token });
|
|
686
|
-
this.owner = options.owner;
|
|
687
|
-
this.repo = options.repo;
|
|
688
|
-
}
|
|
689
|
-
async createRelease(context, options = {}) {
|
|
690
|
-
const tagName = `v${context.version}`;
|
|
691
|
-
let body;
|
|
692
|
-
if (context.enhanced?.releaseNotes) {
|
|
693
|
-
body = context.enhanced.releaseNotes;
|
|
694
|
-
} else {
|
|
695
|
-
body = renderMarkdown([context]);
|
|
696
|
-
}
|
|
697
|
-
info3(`Creating GitHub release for ${tagName}`);
|
|
698
|
-
try {
|
|
699
|
-
const response = await this.octokit.repos.createRelease({
|
|
700
|
-
owner: this.owner,
|
|
701
|
-
repo: this.repo,
|
|
702
|
-
tag_name: tagName,
|
|
703
|
-
name: tagName,
|
|
704
|
-
body,
|
|
705
|
-
draft: options.draft ?? false,
|
|
706
|
-
prerelease: options.prerelease ?? false,
|
|
707
|
-
generate_release_notes: options.generateNotes ?? false
|
|
708
|
-
});
|
|
709
|
-
success3(`Release created: ${response.data.html_url}`);
|
|
710
|
-
return {
|
|
711
|
-
id: response.data.id,
|
|
712
|
-
htmlUrl: response.data.html_url,
|
|
713
|
-
tagName
|
|
714
|
-
};
|
|
715
|
-
} catch (error) {
|
|
716
|
-
throw new GitHubError(`Failed to create release: ${error instanceof Error ? error.message : String(error)}`);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
async updateRelease(releaseId, context, options = {}) {
|
|
720
|
-
const tagName = `v${context.version}`;
|
|
721
|
-
let body;
|
|
722
|
-
if (context.enhanced?.releaseNotes) {
|
|
723
|
-
body = context.enhanced.releaseNotes;
|
|
724
|
-
} else {
|
|
725
|
-
body = renderMarkdown([context]);
|
|
726
|
-
}
|
|
727
|
-
info3(`Updating GitHub release ${releaseId}`);
|
|
728
|
-
try {
|
|
729
|
-
const response = await this.octokit.repos.updateRelease({
|
|
730
|
-
owner: this.owner,
|
|
731
|
-
repo: this.repo,
|
|
732
|
-
release_id: releaseId,
|
|
733
|
-
tag_name: tagName,
|
|
734
|
-
name: tagName,
|
|
735
|
-
body,
|
|
736
|
-
draft: options.draft ?? false,
|
|
737
|
-
prerelease: options.prerelease ?? false
|
|
738
|
-
});
|
|
739
|
-
success3(`Release updated: ${response.data.html_url}`);
|
|
740
|
-
return {
|
|
741
|
-
id: response.data.id,
|
|
742
|
-
htmlUrl: response.data.html_url,
|
|
743
|
-
tagName
|
|
744
|
-
};
|
|
745
|
-
} catch (error) {
|
|
746
|
-
throw new GitHubError(`Failed to update release: ${error instanceof Error ? error.message : String(error)}`);
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
async getReleaseByTag(tag) {
|
|
750
|
-
try {
|
|
751
|
-
const response = await this.octokit.repos.getReleaseByTag({
|
|
752
|
-
owner: this.owner,
|
|
753
|
-
repo: this.repo,
|
|
754
|
-
tag
|
|
755
|
-
});
|
|
756
|
-
return {
|
|
757
|
-
id: response.data.id,
|
|
758
|
-
htmlUrl: response.data.html_url,
|
|
759
|
-
tagName: response.data.tag_name
|
|
760
|
-
};
|
|
761
|
-
} catch {
|
|
762
|
-
return null;
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
};
|
|
766
|
-
function parseRepoUrl(repoUrl) {
|
|
767
|
-
const patterns = [
|
|
768
|
-
/^https:\/\/github\.com\/([^/]+)\/([^/]+)/,
|
|
769
|
-
/^git@github\.com:([^/]+)\/([^/]+)/,
|
|
770
|
-
/^github\.com\/([^/]+)\/([^/]+)/
|
|
771
|
-
];
|
|
772
|
-
for (const pattern of patterns) {
|
|
773
|
-
const match = repoUrl.match(pattern);
|
|
774
|
-
if (match?.[1] && match[2]) {
|
|
775
|
-
return {
|
|
776
|
-
owner: match[1],
|
|
777
|
-
repo: match[2].replace(/\.git$/, "")
|
|
778
|
-
};
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
return null;
|
|
782
|
-
}
|
|
783
|
-
async function createGitHubRelease(context, options) {
|
|
784
|
-
const client = new GitHubClient(options);
|
|
785
|
-
return client.createRelease(context, options);
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
// src/templates/ejs.ts
|
|
789
|
-
import * as fs4 from "fs";
|
|
790
|
-
import ejs from "ejs";
|
|
791
|
-
function renderEjs(template, context) {
|
|
792
|
-
try {
|
|
793
|
-
return ejs.render(template, context);
|
|
794
|
-
} catch (error) {
|
|
795
|
-
throw new TemplateError(`EJS render error: ${error instanceof Error ? error.message : String(error)}`);
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
function renderEjsFile(filePath, context) {
|
|
799
|
-
if (!fs4.existsSync(filePath)) {
|
|
800
|
-
throw new TemplateError(`Template file not found: ${filePath}`);
|
|
801
|
-
}
|
|
802
|
-
const template = fs4.readFileSync(filePath, "utf-8");
|
|
803
|
-
return renderEjs(template, context);
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
// src/templates/handlebars.ts
|
|
807
|
-
import * as fs5 from "fs";
|
|
808
|
-
import * as path3 from "path";
|
|
809
|
-
import Handlebars from "handlebars";
|
|
810
|
-
function registerHandlebarsHelpers() {
|
|
811
|
-
Handlebars.registerHelper("capitalize", (str) => {
|
|
812
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
813
|
-
});
|
|
814
|
-
Handlebars.registerHelper("eq", (a, b) => {
|
|
815
|
-
return a === b;
|
|
816
|
-
});
|
|
817
|
-
Handlebars.registerHelper("ne", (a, b) => {
|
|
818
|
-
return a !== b;
|
|
819
|
-
});
|
|
820
|
-
Handlebars.registerHelper("join", (arr, separator) => {
|
|
821
|
-
return Array.isArray(arr) ? arr.join(separator) : "";
|
|
822
|
-
});
|
|
823
|
-
}
|
|
824
|
-
function renderHandlebars(template, context) {
|
|
825
|
-
registerHandlebarsHelpers();
|
|
826
|
-
try {
|
|
827
|
-
const compiled = Handlebars.compile(template);
|
|
828
|
-
return compiled(context);
|
|
829
|
-
} catch (error) {
|
|
830
|
-
throw new TemplateError(`Handlebars render error: ${error instanceof Error ? error.message : String(error)}`);
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
function renderHandlebarsFile(filePath, context) {
|
|
834
|
-
if (!fs5.existsSync(filePath)) {
|
|
835
|
-
throw new TemplateError(`Template file not found: ${filePath}`);
|
|
836
|
-
}
|
|
837
|
-
const template = fs5.readFileSync(filePath, "utf-8");
|
|
838
|
-
return renderHandlebars(template, context);
|
|
839
|
-
}
|
|
840
|
-
function renderHandlebarsComposable(templateDir, context) {
|
|
841
|
-
registerHandlebarsHelpers();
|
|
842
|
-
const versionPath = path3.join(templateDir, "version.hbs");
|
|
843
|
-
const entryPath = path3.join(templateDir, "entry.hbs");
|
|
844
|
-
const documentPath = path3.join(templateDir, "document.hbs");
|
|
845
|
-
if (!fs5.existsSync(documentPath)) {
|
|
846
|
-
throw new TemplateError(`Document template not found: ${documentPath}`);
|
|
847
|
-
}
|
|
848
|
-
if (fs5.existsSync(versionPath)) {
|
|
849
|
-
Handlebars.registerPartial("version", fs5.readFileSync(versionPath, "utf-8"));
|
|
850
|
-
}
|
|
851
|
-
if (fs5.existsSync(entryPath)) {
|
|
852
|
-
Handlebars.registerPartial("entry", fs5.readFileSync(entryPath, "utf-8"));
|
|
853
|
-
}
|
|
854
|
-
try {
|
|
855
|
-
const compiled = Handlebars.compile(fs5.readFileSync(documentPath, "utf-8"));
|
|
856
|
-
return compiled(context);
|
|
857
|
-
} catch (error) {
|
|
858
|
-
throw new TemplateError(`Handlebars render error: ${error instanceof Error ? error.message : String(error)}`);
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
// src/templates/liquid.ts
|
|
863
|
-
import * as fs6 from "fs";
|
|
864
|
-
import * as path4 from "path";
|
|
865
|
-
import { Liquid } from "liquidjs";
|
|
866
|
-
function createLiquidEngine(root) {
|
|
867
|
-
return new Liquid({
|
|
868
|
-
root: root ? [root] : [],
|
|
869
|
-
extname: ".liquid",
|
|
870
|
-
cache: false
|
|
871
|
-
});
|
|
872
|
-
}
|
|
873
|
-
function renderLiquid(template, context) {
|
|
874
|
-
const engine = createLiquidEngine();
|
|
875
|
-
try {
|
|
876
|
-
return engine.renderSync(engine.parse(template), context);
|
|
877
|
-
} catch (error) {
|
|
878
|
-
throw new TemplateError(`Liquid render error: ${error instanceof Error ? error.message : String(error)}`);
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
function renderLiquidFile(filePath, context) {
|
|
882
|
-
if (!fs6.existsSync(filePath)) {
|
|
883
|
-
throw new TemplateError(`Template file not found: ${filePath}`);
|
|
884
|
-
}
|
|
885
|
-
const template = fs6.readFileSync(filePath, "utf-8");
|
|
886
|
-
return renderLiquid(template, context);
|
|
887
|
-
}
|
|
888
|
-
function renderLiquidComposable(templateDir, context) {
|
|
889
|
-
const documentPath = path4.join(templateDir, "document.liquid");
|
|
890
|
-
if (!fs6.existsSync(documentPath)) {
|
|
891
|
-
throw new TemplateError(`Document template not found: ${documentPath}`);
|
|
892
|
-
}
|
|
893
|
-
const engine = createLiquidEngine(templateDir);
|
|
894
|
-
try {
|
|
895
|
-
return engine.renderFileSync("document", context);
|
|
896
|
-
} catch (error) {
|
|
897
|
-
throw new TemplateError(`Liquid render error: ${error instanceof Error ? error.message : String(error)}`);
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
// src/templates/loader.ts
|
|
902
|
-
import * as fs7 from "fs";
|
|
903
|
-
import * as path5 from "path";
|
|
904
|
-
function getEngineFromFile(filePath) {
|
|
905
|
-
const ext = path5.extname(filePath).toLowerCase();
|
|
906
|
-
switch (ext) {
|
|
907
|
-
case ".liquid":
|
|
908
|
-
return "liquid";
|
|
909
|
-
case ".hbs":
|
|
910
|
-
case ".handlebars":
|
|
911
|
-
return "handlebars";
|
|
912
|
-
case ".ejs":
|
|
913
|
-
return "ejs";
|
|
914
|
-
default:
|
|
915
|
-
throw new TemplateError(`Unknown template extension: ${ext}`);
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
function getRenderFn(engine) {
|
|
919
|
-
switch (engine) {
|
|
920
|
-
case "liquid":
|
|
921
|
-
return renderLiquid;
|
|
922
|
-
case "handlebars":
|
|
923
|
-
return renderHandlebars;
|
|
924
|
-
case "ejs":
|
|
925
|
-
return renderEjs;
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
function getRenderFileFn(engine) {
|
|
929
|
-
switch (engine) {
|
|
930
|
-
case "liquid":
|
|
931
|
-
return renderLiquidFile;
|
|
932
|
-
case "handlebars":
|
|
933
|
-
return renderHandlebarsFile;
|
|
934
|
-
case "ejs":
|
|
935
|
-
return renderEjsFile;
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
function detectTemplateMode(templatePath) {
|
|
939
|
-
if (!fs7.existsSync(templatePath)) {
|
|
940
|
-
throw new TemplateError(`Template path not found: ${templatePath}`);
|
|
941
|
-
}
|
|
942
|
-
const stat = fs7.statSync(templatePath);
|
|
943
|
-
if (stat.isFile()) {
|
|
944
|
-
return "single";
|
|
945
|
-
}
|
|
946
|
-
if (stat.isDirectory()) {
|
|
947
|
-
return "composable";
|
|
948
|
-
}
|
|
949
|
-
throw new TemplateError(`Invalid template path: ${templatePath}`);
|
|
950
|
-
}
|
|
951
|
-
function renderSingleFile(templatePath, context, engine) {
|
|
952
|
-
const resolvedEngine = engine ?? getEngineFromFile(templatePath);
|
|
953
|
-
const renderFile = getRenderFileFn(resolvedEngine);
|
|
954
|
-
return {
|
|
955
|
-
content: renderFile(templatePath, context),
|
|
956
|
-
engine: resolvedEngine
|
|
957
|
-
};
|
|
958
|
-
}
|
|
959
|
-
function renderComposable(templateDir, context, engine) {
|
|
960
|
-
const files = fs7.readdirSync(templateDir);
|
|
961
|
-
const engineMap = {
|
|
962
|
-
liquid: { document: "document.liquid", version: "version.liquid", entry: "entry.liquid" },
|
|
963
|
-
handlebars: { document: "document.hbs", version: "version.hbs", entry: "entry.hbs" },
|
|
964
|
-
ejs: { document: "document.ejs", version: "version.ejs", entry: "entry.ejs" }
|
|
965
|
-
};
|
|
966
|
-
let resolvedEngine;
|
|
967
|
-
if (engine) {
|
|
968
|
-
resolvedEngine = engine;
|
|
969
|
-
} else {
|
|
970
|
-
const detected = detectEngineFromFiles(templateDir, files);
|
|
971
|
-
if (!detected) {
|
|
972
|
-
throw new TemplateError(`Could not detect template engine. Found files: ${files.join(", ")}`);
|
|
973
|
-
}
|
|
974
|
-
resolvedEngine = detected;
|
|
975
|
-
}
|
|
976
|
-
if (resolvedEngine === "liquid") {
|
|
977
|
-
return { content: renderLiquidComposable(templateDir, context), engine: resolvedEngine };
|
|
978
|
-
}
|
|
979
|
-
if (resolvedEngine === "handlebars") {
|
|
980
|
-
return { content: renderHandlebarsComposable(templateDir, context), engine: resolvedEngine };
|
|
981
|
-
}
|
|
982
|
-
const expectedFiles = engineMap[resolvedEngine];
|
|
983
|
-
const documentPath = path5.join(templateDir, expectedFiles.document);
|
|
984
|
-
if (!fs7.existsSync(documentPath)) {
|
|
985
|
-
throw new TemplateError(`Document template not found: ${expectedFiles.document}`);
|
|
986
|
-
}
|
|
987
|
-
const versionPath = path5.join(templateDir, expectedFiles.version);
|
|
988
|
-
const entryPath = path5.join(templateDir, expectedFiles.entry);
|
|
989
|
-
const render = getRenderFn(resolvedEngine);
|
|
990
|
-
const entryTemplate = fs7.existsSync(entryPath) ? fs7.readFileSync(entryPath, "utf-8") : null;
|
|
991
|
-
const versionTemplate = fs7.existsSync(versionPath) ? fs7.readFileSync(versionPath, "utf-8") : null;
|
|
992
|
-
if (entryTemplate && versionTemplate) {
|
|
993
|
-
const versionsWithEntries = context.versions.map((versionCtx) => {
|
|
994
|
-
const entries = versionCtx.entries.map((entry) => {
|
|
995
|
-
const entryCtx = { ...entry, packageName: versionCtx.packageName, version: versionCtx.version };
|
|
996
|
-
return render(entryTemplate, entryCtx);
|
|
997
|
-
});
|
|
998
|
-
return render(versionTemplate, { ...versionCtx, renderedEntries: entries });
|
|
999
|
-
});
|
|
1000
|
-
const docContext = { ...context, renderedVersions: versionsWithEntries };
|
|
1001
|
-
return {
|
|
1002
|
-
content: render(fs7.readFileSync(documentPath, "utf-8"), docContext),
|
|
1003
|
-
engine: resolvedEngine
|
|
1004
|
-
};
|
|
1005
|
-
}
|
|
1006
|
-
return renderSingleFile(documentPath, context, resolvedEngine);
|
|
1007
|
-
}
|
|
1008
|
-
function detectEngineFromFiles(_dir, files) {
|
|
1009
|
-
if (files.some((f) => f.endsWith(".liquid"))) return "liquid";
|
|
1010
|
-
if (files.some((f) => f.endsWith(".hbs") || f.endsWith(".handlebars"))) return "handlebars";
|
|
1011
|
-
if (files.some((f) => f.endsWith(".ejs"))) return "ejs";
|
|
1012
|
-
return null;
|
|
1013
|
-
}
|
|
1014
|
-
function validateDocumentContext(context, templatePath) {
|
|
1015
|
-
if (!context.project?.name) {
|
|
1016
|
-
throw new TemplateError(`${templatePath}: DocumentContext missing required field "project.name"`);
|
|
1017
|
-
}
|
|
1018
|
-
if (!Array.isArray(context.versions)) {
|
|
1019
|
-
throw new TemplateError(`${templatePath}: DocumentContext missing required field "versions" (must be an array)`);
|
|
1020
|
-
}
|
|
1021
|
-
const requiredVersionFields = ["packageName", "version", "date", "entries"];
|
|
1022
|
-
for (const [i, v] of context.versions.entries()) {
|
|
1023
|
-
for (const field of requiredVersionFields) {
|
|
1024
|
-
if (v[field] === void 0 || v[field] === null) {
|
|
1025
|
-
throw new TemplateError(`${templatePath}: versions[${i}] missing required field "${field}"`);
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
if (!Array.isArray(v.entries)) {
|
|
1029
|
-
throw new TemplateError(`${templatePath}: versions[${i}].entries must be an array`);
|
|
1030
|
-
}
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
function renderTemplate(templatePath, context, engine) {
|
|
1034
|
-
validateDocumentContext(context, templatePath);
|
|
1035
|
-
const mode = detectTemplateMode(templatePath);
|
|
1036
|
-
if (mode === "single") {
|
|
1037
|
-
return renderSingleFile(templatePath, context, engine);
|
|
1038
|
-
}
|
|
1039
|
-
return renderComposable(templatePath, context, engine);
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
// src/utils/retry.ts
|
|
1043
|
-
function sleep(ms) {
|
|
1044
|
-
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
1045
|
-
}
|
|
1046
|
-
async function withRetry(fn, options = {}) {
|
|
1047
|
-
const maxAttempts = options.maxAttempts ?? 3;
|
|
1048
|
-
const initialDelay = options.initialDelay ?? 1e3;
|
|
1049
|
-
const maxDelay = options.maxDelay ?? 3e4;
|
|
1050
|
-
const backoffFactor = options.backoffFactor ?? 2;
|
|
1051
|
-
let lastError;
|
|
1052
|
-
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
1053
|
-
try {
|
|
1054
|
-
return await fn();
|
|
1055
|
-
} catch (error) {
|
|
1056
|
-
lastError = error;
|
|
1057
|
-
if (attempt < maxAttempts - 1) {
|
|
1058
|
-
const base = Math.min(initialDelay * backoffFactor ** attempt, maxDelay);
|
|
1059
|
-
const jitter = base * 0.2 * (Math.random() * 2 - 1);
|
|
1060
|
-
await sleep(Math.max(0, base + jitter));
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
throw lastError;
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
// src/core/pipeline.ts
|
|
1068
|
-
function generateCompareUrl(repoUrl, from, to) {
|
|
1069
|
-
if (/gitlab\.com/i.test(repoUrl)) {
|
|
1070
|
-
return `${repoUrl}/-/compare/${from}...${to}`;
|
|
1071
|
-
}
|
|
1072
|
-
if (/bitbucket\.org/i.test(repoUrl)) {
|
|
1073
|
-
return `${repoUrl}/branches/compare/${from}..${to}`;
|
|
1074
|
-
}
|
|
1075
|
-
return `${repoUrl}/compare/${from}...${to}`;
|
|
1076
|
-
}
|
|
1077
|
-
function createTemplateContext(pkg) {
|
|
1078
|
-
const compareUrl = pkg.repoUrl && pkg.previousVersion ? generateCompareUrl(pkg.repoUrl, pkg.previousVersion, pkg.version) : void 0;
|
|
1079
|
-
return {
|
|
1080
|
-
packageName: pkg.packageName,
|
|
1081
|
-
version: pkg.version,
|
|
1082
|
-
previousVersion: pkg.previousVersion,
|
|
1083
|
-
date: pkg.date,
|
|
1084
|
-
repoUrl: pkg.repoUrl,
|
|
1085
|
-
entries: pkg.entries,
|
|
1086
|
-
compareUrl
|
|
1087
|
-
};
|
|
1088
|
-
}
|
|
1089
|
-
function createDocumentContext(contexts, repoUrl) {
|
|
1090
|
-
const compareUrls = {};
|
|
1091
|
-
for (const ctx of contexts) {
|
|
1092
|
-
if (ctx.compareUrl) {
|
|
1093
|
-
compareUrls[ctx.version] = ctx.compareUrl;
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
return {
|
|
1097
|
-
project: {
|
|
1098
|
-
name: contexts[0]?.packageName ?? "project",
|
|
1099
|
-
repoUrl
|
|
1100
|
-
},
|
|
1101
|
-
versions: contexts,
|
|
1102
|
-
compareUrls: Object.keys(compareUrls).length > 0 ? compareUrls : void 0
|
|
1103
|
-
};
|
|
1104
|
-
}
|
|
1105
|
-
async function processWithLLM(context, config) {
|
|
1106
|
-
if (!config.llm) {
|
|
1107
|
-
return context;
|
|
1108
|
-
}
|
|
1109
|
-
const tasks = config.llm.tasks ?? {};
|
|
1110
|
-
const llmContext = {
|
|
1111
|
-
packageName: context.packageName,
|
|
1112
|
-
version: context.version,
|
|
1113
|
-
previousVersion: context.previousVersion ?? void 0,
|
|
1114
|
-
date: context.date
|
|
1115
|
-
};
|
|
1116
|
-
const enhanced = {
|
|
1117
|
-
entries: context.entries
|
|
1118
|
-
};
|
|
1119
|
-
try {
|
|
1120
|
-
const rawProvider = createProvider(config.llm);
|
|
1121
|
-
const retryOpts = config.llm.retry ?? LLM_DEFAULTS.retry;
|
|
1122
|
-
const provider = {
|
|
1123
|
-
name: rawProvider.name,
|
|
1124
|
-
complete: (prompt, opts) => withRetry(() => rawProvider.complete(prompt, opts), retryOpts)
|
|
1125
|
-
};
|
|
1126
|
-
if (tasks.enhance) {
|
|
1127
|
-
debug("Enhancing entries with LLM");
|
|
1128
|
-
enhanced.entries = await enhanceEntries(provider, context.entries, llmContext, config.llm.concurrency);
|
|
1129
|
-
}
|
|
1130
|
-
if (tasks.summarize) {
|
|
1131
|
-
debug("Summarizing entries with LLM");
|
|
1132
|
-
enhanced.summary = await summarizeEntries(provider, enhanced.entries, llmContext);
|
|
1133
|
-
}
|
|
1134
|
-
if (tasks.categorize) {
|
|
1135
|
-
debug("Categorizing entries with LLM");
|
|
1136
|
-
const categorized = await categorizeEntries(provider, enhanced.entries, llmContext);
|
|
1137
|
-
enhanced.categories = {};
|
|
1138
|
-
for (const cat of categorized) {
|
|
1139
|
-
enhanced.categories[cat.category] = cat.entries;
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
if (tasks.releaseNotes) {
|
|
1143
|
-
debug("Generating release notes with LLM");
|
|
1144
|
-
enhanced.releaseNotes = await generateReleaseNotes(provider, enhanced.entries, llmContext);
|
|
1145
|
-
}
|
|
1146
|
-
return {
|
|
1147
|
-
...context,
|
|
1148
|
-
entries: enhanced.entries,
|
|
1149
|
-
enhanced
|
|
1150
|
-
};
|
|
1151
|
-
} catch (error) {
|
|
1152
|
-
warn2(`LLM processing failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1153
|
-
warn2("Falling back to raw entries");
|
|
1154
|
-
return context;
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
function getBuiltinTemplatePath(style) {
|
|
1158
|
-
let packageRoot;
|
|
1159
|
-
try {
|
|
1160
|
-
const currentUrl = import.meta.url;
|
|
1161
|
-
packageRoot = path6.dirname(new URL(currentUrl).pathname);
|
|
1162
|
-
packageRoot = path6.join(packageRoot, "..", "..");
|
|
1163
|
-
} catch {
|
|
1164
|
-
packageRoot = __dirname;
|
|
1165
|
-
}
|
|
1166
|
-
return path6.join(packageRoot, "templates", style);
|
|
1167
|
-
}
|
|
1168
|
-
async function generateWithTemplate(contexts, config, outputPath, dryRun) {
|
|
1169
|
-
let templatePath;
|
|
1170
|
-
if (config.templates?.path) {
|
|
1171
|
-
templatePath = path6.resolve(config.templates.path);
|
|
1172
|
-
} else {
|
|
1173
|
-
templatePath = getBuiltinTemplatePath("keep-a-changelog");
|
|
1174
|
-
}
|
|
1175
|
-
const documentContext = createDocumentContext(
|
|
1176
|
-
contexts,
|
|
1177
|
-
config.templates?.path ? void 0 : contexts[0]?.repoUrl ?? void 0
|
|
1178
|
-
);
|
|
1179
|
-
const result = renderTemplate(templatePath, documentContext, config.templates?.engine);
|
|
1180
|
-
if (dryRun) {
|
|
1181
|
-
info4("--- Changelog Preview ---");
|
|
1182
|
-
console.log(result.content);
|
|
1183
|
-
info4("--- End Preview ---");
|
|
1184
|
-
return;
|
|
1185
|
-
}
|
|
1186
|
-
const dir = path6.dirname(outputPath);
|
|
1187
|
-
if (!fs8.existsSync(dir)) {
|
|
1188
|
-
fs8.mkdirSync(dir, { recursive: true });
|
|
1189
|
-
}
|
|
1190
|
-
fs8.writeFileSync(outputPath, result.content, "utf-8");
|
|
1191
|
-
success4(`Changelog written to ${outputPath} (using ${result.engine} template)`);
|
|
1192
|
-
}
|
|
1193
|
-
async function runPipeline(input, config, dryRun) {
|
|
1194
|
-
debug(`Processing ${input.packages.length} package(s)`);
|
|
1195
|
-
let contexts = input.packages.map(createTemplateContext);
|
|
1196
|
-
if (config.llm && !process.env.CHANGELOG_NO_LLM && !dryRun) {
|
|
1197
|
-
info4("Processing with LLM enhancement");
|
|
1198
|
-
contexts = await Promise.all(contexts.map((ctx) => processWithLLM(ctx, config)));
|
|
1199
|
-
} else if (config.llm && dryRun) {
|
|
1200
|
-
info4("Skipping LLM processing in dry-run mode");
|
|
1201
|
-
}
|
|
1202
|
-
for (const output of config.output) {
|
|
1203
|
-
info4(`Generating ${output.format} output`);
|
|
1204
|
-
switch (output.format) {
|
|
1205
|
-
case "markdown": {
|
|
1206
|
-
const file = output.file ?? "CHANGELOG.md";
|
|
1207
|
-
if (config.templates?.path || output.options?.template) {
|
|
1208
|
-
await generateWithTemplate(contexts, config, file, dryRun);
|
|
1209
|
-
} else {
|
|
1210
|
-
writeMarkdown(file, contexts, config, dryRun);
|
|
1211
|
-
}
|
|
1212
|
-
break;
|
|
1213
|
-
}
|
|
1214
|
-
case "json": {
|
|
1215
|
-
const file = output.file ?? "changelog.json";
|
|
1216
|
-
writeJson(file, contexts, dryRun);
|
|
1217
|
-
break;
|
|
1218
|
-
}
|
|
1219
|
-
case "github-release": {
|
|
1220
|
-
if (dryRun) {
|
|
1221
|
-
info4("[DRY RUN] Would create GitHub release");
|
|
1222
|
-
break;
|
|
1223
|
-
}
|
|
1224
|
-
const firstContext = contexts[0];
|
|
1225
|
-
if (!firstContext) {
|
|
1226
|
-
warn2("No context available for GitHub release");
|
|
1227
|
-
break;
|
|
1228
|
-
}
|
|
1229
|
-
const repoUrl = firstContext.repoUrl;
|
|
1230
|
-
if (!repoUrl) {
|
|
1231
|
-
warn2("No repo URL available, cannot create GitHub release");
|
|
1232
|
-
break;
|
|
1233
|
-
}
|
|
1234
|
-
const parsed = parseRepoUrl(repoUrl);
|
|
1235
|
-
if (!parsed) {
|
|
1236
|
-
warn2(`Could not parse repo URL: ${repoUrl}`);
|
|
1237
|
-
break;
|
|
1238
|
-
}
|
|
1239
|
-
await createGitHubRelease(firstContext, {
|
|
1240
|
-
owner: parsed.owner,
|
|
1241
|
-
repo: parsed.repo,
|
|
1242
|
-
draft: output.options?.draft,
|
|
1243
|
-
prerelease: output.options?.prerelease
|
|
1244
|
-
});
|
|
1245
|
-
break;
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
async function processInput(inputJson, config, dryRun) {
|
|
1251
|
-
const input = parsePackageVersioner(inputJson);
|
|
1252
|
-
await runPipeline(input, config, dryRun);
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
|
-
// src/monorepo/aggregator.ts
|
|
1256
|
-
import * as fs9 from "fs";
|
|
1257
|
-
import * as path7 from "path";
|
|
1258
|
-
import { info as info5, success as success5 } from "@releasekit/core";
|
|
1259
|
-
|
|
1260
|
-
// src/monorepo/splitter.ts
|
|
1261
|
-
function splitByPackage(contexts) {
|
|
1262
|
-
const byPackage = /* @__PURE__ */ new Map();
|
|
1263
|
-
for (const ctx of contexts) {
|
|
1264
|
-
byPackage.set(ctx.packageName, ctx);
|
|
1265
|
-
}
|
|
1266
|
-
return byPackage;
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
// src/monorepo/aggregator.ts
|
|
1270
|
-
function writeFile(outputPath, content, dryRun) {
|
|
1271
|
-
if (dryRun) {
|
|
1272
|
-
info5(`[DRY RUN] Would write to ${outputPath}`);
|
|
1273
|
-
console.log(content);
|
|
1274
|
-
return;
|
|
1275
|
-
}
|
|
1276
|
-
const dir = path7.dirname(outputPath);
|
|
1277
|
-
if (!fs9.existsSync(dir)) {
|
|
1278
|
-
fs9.mkdirSync(dir, { recursive: true });
|
|
1279
|
-
}
|
|
1280
|
-
fs9.writeFileSync(outputPath, content, "utf-8");
|
|
1281
|
-
success5(`Changelog written to ${outputPath}`);
|
|
1282
|
-
}
|
|
1283
|
-
function aggregateToRoot(contexts) {
|
|
1284
|
-
const aggregated = {
|
|
1285
|
-
packageName: "monorepo",
|
|
1286
|
-
version: contexts[0]?.version ?? "0.0.0",
|
|
1287
|
-
previousVersion: contexts[0]?.previousVersion ?? null,
|
|
1288
|
-
date: (/* @__PURE__ */ new Date()).toISOString().split("T")[0] ?? "",
|
|
1289
|
-
repoUrl: contexts[0]?.repoUrl ?? null,
|
|
1290
|
-
entries: []
|
|
1291
|
-
};
|
|
1292
|
-
for (const ctx of contexts) {
|
|
1293
|
-
for (const entry of ctx.entries) {
|
|
1294
|
-
aggregated.entries.push({
|
|
1295
|
-
...entry,
|
|
1296
|
-
scope: entry.scope ? `${ctx.packageName}/${entry.scope}` : ctx.packageName
|
|
1297
|
-
});
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
return aggregated;
|
|
1301
|
-
}
|
|
1302
|
-
function writeMonorepoChangelogs(contexts, options, config, dryRun) {
|
|
1303
|
-
if (options.mode === "root" || options.mode === "both") {
|
|
1304
|
-
const aggregated = aggregateToRoot(contexts);
|
|
1305
|
-
const rootPath = path7.join(options.rootPath, "CHANGELOG.md");
|
|
1306
|
-
info5(`Writing root changelog to ${rootPath}`);
|
|
1307
|
-
const rootContent = config.updateStrategy === "prepend" && fs9.existsSync(rootPath) ? prependVersion(rootPath, aggregated) : renderMarkdown([aggregated]);
|
|
1308
|
-
writeFile(rootPath, rootContent, dryRun);
|
|
1309
|
-
}
|
|
1310
|
-
if (options.mode === "packages" || options.mode === "both") {
|
|
1311
|
-
const byPackage = splitByPackage(contexts);
|
|
1312
|
-
const packageDirMap = buildPackageDirMap(options.rootPath, options.packagesPath);
|
|
1313
|
-
for (const [packageName, ctx] of byPackage) {
|
|
1314
|
-
const simpleName = packageName.split("/").pop();
|
|
1315
|
-
const packageDir = packageDirMap.get(packageName) ?? (simpleName ? packageDirMap.get(simpleName) : void 0) ?? null;
|
|
1316
|
-
if (packageDir) {
|
|
1317
|
-
const changelogPath = path7.join(packageDir, "CHANGELOG.md");
|
|
1318
|
-
info5(`Writing changelog for ${packageName} to ${changelogPath}`);
|
|
1319
|
-
const pkgContent = config.updateStrategy === "prepend" && fs9.existsSync(changelogPath) ? prependVersion(changelogPath, ctx) : renderMarkdown([ctx]);
|
|
1320
|
-
writeFile(changelogPath, pkgContent, dryRun);
|
|
1321
|
-
} else {
|
|
1322
|
-
info5(`Could not find directory for package ${packageName}, skipping`);
|
|
1323
|
-
}
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
function buildPackageDirMap(rootPath, packagesPath) {
|
|
1328
|
-
const map = /* @__PURE__ */ new Map();
|
|
1329
|
-
const packagesDir = path7.join(rootPath, packagesPath);
|
|
1330
|
-
if (!fs9.existsSync(packagesDir)) {
|
|
1331
|
-
return map;
|
|
1332
|
-
}
|
|
1333
|
-
for (const entry of fs9.readdirSync(packagesDir, { withFileTypes: true })) {
|
|
1334
|
-
if (!entry.isDirectory()) continue;
|
|
1335
|
-
const dirPath = path7.join(packagesDir, entry.name);
|
|
1336
|
-
map.set(entry.name, dirPath);
|
|
1337
|
-
const packageJsonPath = path7.join(dirPath, "package.json");
|
|
1338
|
-
if (fs9.existsSync(packageJsonPath)) {
|
|
1339
|
-
try {
|
|
1340
|
-
const pkg = JSON.parse(fs9.readFileSync(packageJsonPath, "utf-8"));
|
|
1341
|
-
if (pkg.name) {
|
|
1342
|
-
map.set(pkg.name, dirPath);
|
|
1343
|
-
}
|
|
1344
|
-
} catch {
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
return map;
|
|
1349
|
-
}
|
|
1350
|
-
function detectMonorepo(cwd) {
|
|
1351
|
-
const pnpmWorkspacesPath = path7.join(cwd, "pnpm-workspace.yaml");
|
|
1352
|
-
const packageJsonPath = path7.join(cwd, "package.json");
|
|
1353
|
-
if (fs9.existsSync(pnpmWorkspacesPath)) {
|
|
1354
|
-
const content = fs9.readFileSync(pnpmWorkspacesPath, "utf-8");
|
|
1355
|
-
const packagesMatch = content.match(/packages:\s*\n\s*-\s*['"]([^'"]+)['"]/);
|
|
1356
|
-
if (packagesMatch?.[1]) {
|
|
1357
|
-
const packagesGlob = packagesMatch[1];
|
|
1358
|
-
const packagesPath = packagesGlob.replace(/\/?\*$/, "").replace(/\/\*\*$/, "");
|
|
1359
|
-
return { isMonorepo: true, packagesPath: packagesPath || "packages" };
|
|
1360
|
-
}
|
|
1361
|
-
return { isMonorepo: true, packagesPath: "packages" };
|
|
1362
|
-
}
|
|
1363
|
-
if (fs9.existsSync(packageJsonPath)) {
|
|
1364
|
-
try {
|
|
1365
|
-
const content = fs9.readFileSync(packageJsonPath, "utf-8");
|
|
1366
|
-
const pkg = JSON.parse(content);
|
|
1367
|
-
if (pkg.workspaces) {
|
|
1368
|
-
const workspaces = Array.isArray(pkg.workspaces) ? pkg.workspaces : pkg.workspaces.packages;
|
|
1369
|
-
if (workspaces?.length) {
|
|
1370
|
-
const firstWorkspace = workspaces[0];
|
|
1371
|
-
if (firstWorkspace) {
|
|
1372
|
-
const packagesPath = firstWorkspace.replace(/\/?\*$/, "").replace(/\/\*\*$/, "");
|
|
1373
|
-
return { isMonorepo: true, packagesPath: packagesPath || "packages" };
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
} catch {
|
|
1378
|
-
return { isMonorepo: false, packagesPath: "" };
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
1381
|
-
return { isMonorepo: false, packagesPath: "" };
|
|
1382
|
-
}
|
|
1383
|
-
|
|
1384
|
-
export {
|
|
1385
|
-
loadAuth,
|
|
1386
|
-
saveAuth,
|
|
1387
|
-
loadConfig,
|
|
1388
|
-
getDefaultConfig,
|
|
1389
|
-
NotesError,
|
|
1390
|
-
InputParseError,
|
|
1391
|
-
TemplateError,
|
|
1392
|
-
LLMError,
|
|
1393
|
-
GitHubError,
|
|
1394
|
-
ConfigError,
|
|
1395
|
-
getExitCode,
|
|
1396
|
-
EXIT_CODES2 as EXIT_CODES,
|
|
1397
|
-
parsePackageVersioner,
|
|
1398
|
-
parsePackageVersionerFile,
|
|
1399
|
-
parsePackageVersionerStdin,
|
|
1400
|
-
renderMarkdown,
|
|
1401
|
-
writeMarkdown,
|
|
1402
|
-
renderJson,
|
|
1403
|
-
writeJson,
|
|
1404
|
-
createTemplateContext,
|
|
1405
|
-
runPipeline,
|
|
1406
|
-
processInput,
|
|
1407
|
-
aggregateToRoot,
|
|
1408
|
-
writeMonorepoChangelogs,
|
|
1409
|
-
detectMonorepo
|
|
1410
|
-
};
|