ai-release-notes 0.0.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.
- package/LICENSE +21 -0
- package/README.md +261 -0
- package/dist/bin/cli.d.ts +6 -0
- package/dist/bin/cli.d.ts.map +1 -0
- package/dist/bin/cli.js +723 -0
- package/dist/bin/cli.js.map +1 -0
- package/dist/config.d.ts +23 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +176 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +11 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +58 -0
- package/dist/context.js.map +1 -0
- package/dist/generator.d.ts +21 -0
- package/dist/generator.d.ts.map +1 -0
- package/dist/generator.js +258 -0
- package/dist/generator.js.map +1 -0
- package/dist/git.d.ts +28 -0
- package/dist/git.d.ts.map +1 -0
- package/dist/git.js +116 -0
- package/dist/git.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/llm.d.ts +23 -0
- package/dist/llm.d.ts.map +1 -0
- package/dist/llm.js +105 -0
- package/dist/llm.js.map +1 -0
- package/dist/output-index.d.ts +13 -0
- package/dist/output-index.d.ts.map +1 -0
- package/dist/output-index.js +53 -0
- package/dist/output-index.js.map +1 -0
- package/dist/prompts/builder.d.ts +26 -0
- package/dist/prompts/builder.d.ts.map +1 -0
- package/dist/prompts/builder.js +82 -0
- package/dist/prompts/builder.js.map +1 -0
- package/dist/prompts/translation-system.md +8 -0
- package/dist/release.d.ts +37 -0
- package/dist/release.d.ts.map +1 -0
- package/dist/release.js +288 -0
- package/dist/release.js.map +1 -0
- package/dist/types.d.ts +224 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +78 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +10 -0
- package/dist/version.js.map +1 -0
- package/package.json +63 -0
- package/prompts/release-notes-instructions.md +21 -0
- package/prompts/release-notes-system.md +7 -0
- package/prompts/release-notes-translation-system.md +20 -0
- package/templates/default-release-note.html +133 -0
- package/templates/default-release-note.md +8 -0
- package/templates/default-release-summary.html +126 -0
- package/templates/default-release-summary.md +11 -0
package/dist/bin/cli.js
ADDED
|
@@ -0,0 +1,723 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* CLI entry point
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
const commander_1 = require("commander");
|
|
11
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
12
|
+
const generator_js_1 = require("../generator.js");
|
|
13
|
+
const llm_js_1 = require("../llm.js");
|
|
14
|
+
const release_js_1 = require("../release.js");
|
|
15
|
+
const config_js_1 = require("../config.js");
|
|
16
|
+
const output_index_js_1 = require("../output-index.js");
|
|
17
|
+
const git_js_1 = require("../git.js");
|
|
18
|
+
const promises_1 = require("fs/promises");
|
|
19
|
+
const fs_1 = require("fs");
|
|
20
|
+
const path_1 = require("path");
|
|
21
|
+
const clipboardy_1 = __importDefault(require("clipboardy"));
|
|
22
|
+
const ora_1 = __importDefault(require("ora"));
|
|
23
|
+
const version_js_1 = require("../version.js");
|
|
24
|
+
const CLI_VERSION = version_js_1.AI_RELEASE_NOTES_VERSION;
|
|
25
|
+
const LANGUAGE_PATH_PLACEHOLDER = "aireleasenoteslanguageplaceholder";
|
|
26
|
+
const program = new commander_1.Command();
|
|
27
|
+
function printStatus(stdout, message) {
|
|
28
|
+
if (stdout) {
|
|
29
|
+
console.error(message);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
console.log(message);
|
|
33
|
+
}
|
|
34
|
+
function printVerboseGenerationDetails(stdout, config, result, dryRun) {
|
|
35
|
+
const languages = config.prompt?.languages || ["en"];
|
|
36
|
+
const instructions = config.prompt?.instructions;
|
|
37
|
+
const instructionSource = !instructions
|
|
38
|
+
? "built-in defaults"
|
|
39
|
+
: typeof instructions === "string"
|
|
40
|
+
? "inline configuration"
|
|
41
|
+
: `file ${instructions.file}`;
|
|
42
|
+
printStatus(stdout, chalk_1.default.gray("\n🧭 Generation details"));
|
|
43
|
+
printStatus(stdout, chalk_1.default.gray(` Main language: ${languages[0]}`));
|
|
44
|
+
printStatus(stdout, chalk_1.default.gray(` Instructions: ${instructionSource}`));
|
|
45
|
+
if (languages.length > 1) {
|
|
46
|
+
const mode = dryRun ? "configured" : "completed";
|
|
47
|
+
printStatus(stdout, chalk_1.default.gray(` Translations ${mode}: ${languages[0]} → ${languages.slice(1).join(", ")} (translation only; facts and structure are preserved)`));
|
|
48
|
+
}
|
|
49
|
+
printStatus(stdout, chalk_1.default.gray(` Provider: ${result.metadata.provider} | Model calls: ${result.metadata.usage.modelCalls}`));
|
|
50
|
+
}
|
|
51
|
+
function printGenerationSummary(stdout, result) {
|
|
52
|
+
const usage = result.metadata.usage;
|
|
53
|
+
printStatus(stdout, chalk_1.default.gray(`\n📊 ${result.metadata.commitCount} commits | ${result.metadata.provider} | ${result.metadata.date} | ${formatDuration(usage.durationMs)}`));
|
|
54
|
+
if (usage.modelCalls > 0) {
|
|
55
|
+
printStatus(stdout, chalk_1.default.gray(`🪙 Tokens: ${formatNumber(usage.inputTokens)} input + ${formatNumber(usage.outputTokens)} output = ${formatNumber(usage.totalTokens)} | ${usage.modelCalls} model call${usage.modelCalls === 1 ? "" : "s"}`));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
printStatus(stdout, chalk_1.default.gray("🪙 Tokens: no model tokens used (dry run)"));
|
|
59
|
+
}
|
|
60
|
+
if (result.metadata.contextFiles && result.metadata.contextFiles.length > 0) {
|
|
61
|
+
printStatus(stdout, chalk_1.default.gray(`📎 Context files: ${result.metadata.contextFiles.join(", ")}`));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function formatGenerationError(error, result, config, providerOverride) {
|
|
65
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
66
|
+
if (!/rate limit|too many requests|\b429\b|quota/i.test(message)) {
|
|
67
|
+
return message;
|
|
68
|
+
}
|
|
69
|
+
const provider = result?.metadata.provider || providerOverride;
|
|
70
|
+
const model = provider ? config?.providers[provider]?.model : undefined;
|
|
71
|
+
const target = [provider, model].filter(Boolean).join(" / ") || "the selected provider";
|
|
72
|
+
return [
|
|
73
|
+
`Rate limit reached for ${target}.`,
|
|
74
|
+
"The provider rejected another API request because the active API key/account exceeded a request-rate or token-throughput quota.",
|
|
75
|
+
"This is not a limit on the number of commits or context files in this release.",
|
|
76
|
+
"The provider did not include the exact quota or reset time in this error; wait briefly, reduce the prompt/context or number of generated languages, or use an API key/account with more capacity.",
|
|
77
|
+
`Provider error: ${message}`,
|
|
78
|
+
].join("\n");
|
|
79
|
+
}
|
|
80
|
+
program
|
|
81
|
+
.name("ai-release-notes")
|
|
82
|
+
.description("🤖 AI-powered release notes generator")
|
|
83
|
+
.version(CLI_VERSION);
|
|
84
|
+
// ── init ──
|
|
85
|
+
program
|
|
86
|
+
.command("init")
|
|
87
|
+
.description("Create a default configuration file")
|
|
88
|
+
.option("-g, --global", "Create in home directory (~/.ai-release-notes.yml)")
|
|
89
|
+
.option("-f, --force", "Overwrite existing file")
|
|
90
|
+
.action(async (opts) => {
|
|
91
|
+
const { homedir } = await import("os");
|
|
92
|
+
const { resolve } = await import("path");
|
|
93
|
+
const { existsSync } = await import("fs");
|
|
94
|
+
const targetPath = opts.global
|
|
95
|
+
? resolve(homedir(), ".ai-release-notes.yml")
|
|
96
|
+
: resolve(process.cwd(), ".ai-release-notes.yml");
|
|
97
|
+
if (existsSync(targetPath) && !opts.force) {
|
|
98
|
+
console.log(chalk_1.default.yellow("⚠️ Config file already exists. Use --force to overwrite."));
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
await (0, config_js_1.createDefaultConfig)(targetPath);
|
|
102
|
+
console.log(chalk_1.default.green(`✅ Created config: ${targetPath}`));
|
|
103
|
+
});
|
|
104
|
+
// ── generate ──
|
|
105
|
+
program
|
|
106
|
+
.command("generate")
|
|
107
|
+
.alias("gen")
|
|
108
|
+
.description("Generate release notes from git tags")
|
|
109
|
+
.option("--from <version>", "Previous version tag (e.g. v1.0.0)")
|
|
110
|
+
.option("--to <version>", "Current version tag (e.g. v1.1.0)")
|
|
111
|
+
.requiredOption("--env <environment>", "Environment: PROD, STAGING, DEV...")
|
|
112
|
+
.option("--release-date <value>", 'Release date: "now", "tag", or an ISO date (default: now)')
|
|
113
|
+
.option("--date <value>", 'Alias for --release-date ("now", "tag", or an ISO date)')
|
|
114
|
+
.option("--with <provider>", "LLM provider override (claude, gpt4, mistral, gemini, ollama)")
|
|
115
|
+
.option("--config <path>", "Path to config file")
|
|
116
|
+
.option("--output <path>", "Output file path (override config)")
|
|
117
|
+
.option("--output-dir <dir>", "Output directory (default: current dir)")
|
|
118
|
+
.option("--format <format>", "Output format: md or html")
|
|
119
|
+
.option("--template <path>", "Path to custom template file")
|
|
120
|
+
.option("--changelog <path>", "Path to a file containing raw changelog (skip git)")
|
|
121
|
+
.option("--context <paths...>", "Context files or directories (specs, models, etc.)")
|
|
122
|
+
.option("--dry-run", "Show prompts without calling LLM")
|
|
123
|
+
.option("-v, --verbose", "Show applied instructions and generation steps")
|
|
124
|
+
.option("--stdout", "Write generated release notes to the terminal without saving files")
|
|
125
|
+
.option("--clipboard", "Copy result to clipboard")
|
|
126
|
+
.action(async (opts) => {
|
|
127
|
+
let result;
|
|
128
|
+
let config;
|
|
129
|
+
let summaryPrinted = false;
|
|
130
|
+
try {
|
|
131
|
+
// Auto-detect tags if not provided
|
|
132
|
+
let fromVersion = opts.from;
|
|
133
|
+
let toVersion = opts.to;
|
|
134
|
+
if (!toVersion) {
|
|
135
|
+
toVersion = await (0, git_js_1.getLatestTag)();
|
|
136
|
+
if (!toVersion) {
|
|
137
|
+
console.error(chalk_1.default.red("❌ Could not detect current tag. Use --to <version>"));
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
printStatus(opts.stdout, chalk_1.default.blue(`📌 Detected current tag: ${toVersion}`));
|
|
141
|
+
}
|
|
142
|
+
if (!fromVersion) {
|
|
143
|
+
fromVersion = await (0, git_js_1.getPreviousTag)(toVersion);
|
|
144
|
+
if (!fromVersion) {
|
|
145
|
+
console.error(chalk_1.default.red("❌ Could not detect previous tag. Use --from <version>"));
|
|
146
|
+
process.exit(1);
|
|
147
|
+
}
|
|
148
|
+
printStatus(opts.stdout, chalk_1.default.blue(`📌 Detected previous tag: ${fromVersion}`));
|
|
149
|
+
}
|
|
150
|
+
const loadedConfig = await (0, config_js_1.loadConfig)(opts.config);
|
|
151
|
+
config = loadedConfig;
|
|
152
|
+
const spinner = (0, ora_1.default)("🤖 Generating release notes...").start();
|
|
153
|
+
const generatedResult = await (0, generator_js_1.generate)({
|
|
154
|
+
fromVersion,
|
|
155
|
+
toVersion,
|
|
156
|
+
environment: opts.env,
|
|
157
|
+
releaseDate: opts.releaseDate || opts.date,
|
|
158
|
+
provider: opts.with,
|
|
159
|
+
configPath: opts.config,
|
|
160
|
+
changelogFile: opts.changelog,
|
|
161
|
+
dryRun: opts.dryRun,
|
|
162
|
+
clipboard: opts.clipboard,
|
|
163
|
+
outputPath: opts.output,
|
|
164
|
+
outputDir: opts.outputDir,
|
|
165
|
+
format: opts.format,
|
|
166
|
+
template: opts.template,
|
|
167
|
+
context: opts.context,
|
|
168
|
+
});
|
|
169
|
+
result = generatedResult;
|
|
170
|
+
spinner.succeed("✅ Done!");
|
|
171
|
+
if (opts.verbose) {
|
|
172
|
+
printVerboseGenerationDetails(opts.stdout, loadedConfig, generatedResult, opts.dryRun);
|
|
173
|
+
}
|
|
174
|
+
if (opts.stdout) {
|
|
175
|
+
console.log(generatedResult.markdown);
|
|
176
|
+
}
|
|
177
|
+
// Determine output path
|
|
178
|
+
let outputTargets = !opts.stdout && opts.output
|
|
179
|
+
? [{ path: opts.output, markdown: generatedResult.markdown, html: generatedResult.html, format: opts.format }]
|
|
180
|
+
: [];
|
|
181
|
+
if (!opts.stdout && outputTargets.length === 0 && opts.outputDir) {
|
|
182
|
+
const ext = opts.format === "html" ? "html" : "md";
|
|
183
|
+
const filename = `RELEASE_NOTES_${toVersion.replace(/^v/, "")}.${ext}`;
|
|
184
|
+
outputTargets = [{ path: (0, path_1.join)((0, path_1.resolve)(opts.outputDir), filename), markdown: generatedResult.markdown, html: generatedResult.html, format: opts.format }];
|
|
185
|
+
}
|
|
186
|
+
if (!opts.stdout && outputTargets.length === 0) {
|
|
187
|
+
if (loadedConfig.output) {
|
|
188
|
+
const outputConfigs = Array.isArray(loadedConfig.output) ? loadedConfig.output : [loadedConfig.output];
|
|
189
|
+
outputTargets = outputConfigs.flatMap((output) => {
|
|
190
|
+
if (!output.saveTo)
|
|
191
|
+
return [];
|
|
192
|
+
const saveTo = Array.isArray(output.saveTo) ? output.saveTo : [output.saveTo];
|
|
193
|
+
return saveTo.flatMap((path) => path.includes("{lang}")
|
|
194
|
+
? generatedResult.localized.map((release) => ({
|
|
195
|
+
path: getOutputPath(path, opts.env, release.language, opts.from, opts.to),
|
|
196
|
+
markdown: release.markdown,
|
|
197
|
+
html: release.html,
|
|
198
|
+
format: output.format,
|
|
199
|
+
language: release.language,
|
|
200
|
+
}))
|
|
201
|
+
: [{
|
|
202
|
+
path: getOutputPath(path, opts.env, undefined, opts.from, opts.to),
|
|
203
|
+
markdown: generatedResult.markdown,
|
|
204
|
+
html: generatedResult.html,
|
|
205
|
+
format: output.format,
|
|
206
|
+
}]);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const outputIndexConfigs = loadedConfig.outputIndex
|
|
211
|
+
? (Array.isArray(loadedConfig.outputIndex) ? loadedConfig.outputIndex : [loadedConfig.outputIndex])
|
|
212
|
+
: [];
|
|
213
|
+
const outputIndexTargets = outputIndexConfigs.flatMap((outputIndex, groupId) => outputIndex.saveTo.includes("{lang}")
|
|
214
|
+
? generatedResult.localized.map((release) => ({
|
|
215
|
+
path: (0, path_1.resolve)(getOutputPath(outputIndex.saveTo, opts.env, release.language, opts.from, opts.to)),
|
|
216
|
+
groupId,
|
|
217
|
+
language: release.language,
|
|
218
|
+
format: outputIndex.format,
|
|
219
|
+
templatePath: outputIndex.template,
|
|
220
|
+
templateLanguage: outputIndex.templateLanguage,
|
|
221
|
+
}))
|
|
222
|
+
: [{
|
|
223
|
+
path: (0, path_1.resolve)(getOutputPath(outputIndex.saveTo, opts.env, undefined, opts.from, opts.to)),
|
|
224
|
+
groupId,
|
|
225
|
+
format: outputIndex.format,
|
|
226
|
+
templatePath: outputIndex.template,
|
|
227
|
+
templateLanguage: outputIndex.templateLanguage,
|
|
228
|
+
}]);
|
|
229
|
+
if (outputIndexTargets.some((index) => outputTargets.some((target) => (0, path_1.resolve)(target.path) === index.path))) {
|
|
230
|
+
throw new Error("outputIndex.saveTo must be different from every output.saveTo path");
|
|
231
|
+
}
|
|
232
|
+
const duplicateIndexPath = outputIndexTargets.find((target, index) => outputIndexTargets.findIndex((candidate) => candidate.path.toLowerCase() === target.path.toLowerCase()) !== index);
|
|
233
|
+
if (duplicateIndexPath) {
|
|
234
|
+
throw new Error(`outputIndex.saveTo resolves more than once to ${duplicateIndexPath.path}. ` +
|
|
235
|
+
`Use distinct paths and language values.`);
|
|
236
|
+
}
|
|
237
|
+
const outputIndexLanguageTargets = outputIndexTargets
|
|
238
|
+
.flatMap((target) => target.language ? [{ ...target, language: target.language }] : []);
|
|
239
|
+
for (const [groupId, outputIndex] of outputIndexConfigs.entries()) {
|
|
240
|
+
if (!outputIndex.saveTo.includes("{lang}"))
|
|
241
|
+
continue;
|
|
242
|
+
const patternPath = (0, path_1.resolve)(getOutputPath(outputIndex.saveTo, opts.env, LANGUAGE_PATH_PLACEHOLDER, opts.from, opts.to));
|
|
243
|
+
const discovered = await (0, output_index_js_1.discoverOutputIndexLanguages)(patternPath, LANGUAGE_PATH_PLACEHOLDER);
|
|
244
|
+
for (const existingIndex of discovered) {
|
|
245
|
+
const alreadyAvailable = outputIndexLanguageTargets.some((target) => target.groupId === groupId &&
|
|
246
|
+
target.path.toLowerCase() === existingIndex.path.toLowerCase());
|
|
247
|
+
if (!alreadyAvailable) {
|
|
248
|
+
outputIndexLanguageTargets.push({
|
|
249
|
+
...existingIndex,
|
|
250
|
+
groupId,
|
|
251
|
+
format: outputIndex.format,
|
|
252
|
+
templatePath: outputIndex.template,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
// Save to file
|
|
258
|
+
for (const target of outputTargets) {
|
|
259
|
+
const outputPath = target.path;
|
|
260
|
+
await (0, promises_1.mkdir)((0, path_1.dirname)((0, path_1.resolve)(outputPath)), { recursive: true });
|
|
261
|
+
const content = target.format === "html" && target.html
|
|
262
|
+
? target.html
|
|
263
|
+
: target.markdown;
|
|
264
|
+
const saved = await saveReleaseNotes((0, path_1.resolve)(outputPath), content, target.markdown);
|
|
265
|
+
if (saved === "skipped") {
|
|
266
|
+
console.log(chalk_1.default.yellow("ℹ️ Release " + fromVersion + " → " + toVersion + " is already in " + outputPath));
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
console.log(chalk_1.default.green("💾 Saved to " + outputPath));
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (outputIndexTargets.length > 0 && outputTargets.length > 0) {
|
|
273
|
+
const translatedCopyCache = new Map();
|
|
274
|
+
for (const index of outputIndexTargets) {
|
|
275
|
+
await (0, promises_1.mkdir)((0, path_1.dirname)(index.path), { recursive: true });
|
|
276
|
+
const releasePaths = getReleasePathsForIndex(index, outputTargets);
|
|
277
|
+
const languageLinks = getOutputIndexLanguageLinks(index, outputIndexLanguageTargets);
|
|
278
|
+
const outputIndexContent = await createOrUpdateOutputIndex({
|
|
279
|
+
outputPath: index.path,
|
|
280
|
+
format: index.format,
|
|
281
|
+
templatePath: index.templatePath,
|
|
282
|
+
translateTemplate: !opts.dryRun && shouldTranslateTemplate(index.templateLanguage, index.language)
|
|
283
|
+
? async (template) => {
|
|
284
|
+
const translated = await translateOutputIndexTemplate(template, index.language, generatedResult.metadata.provider, loadedConfig.providers[generatedResult.metadata.provider]);
|
|
285
|
+
addTemplateUsage(generatedResult.metadata.usage, translated.usage);
|
|
286
|
+
return translated.text;
|
|
287
|
+
}
|
|
288
|
+
: undefined,
|
|
289
|
+
translateCopy: !opts.dryRun && shouldTranslateOutputIndexCopy(index.language)
|
|
290
|
+
? () => {
|
|
291
|
+
const language = index.language;
|
|
292
|
+
const key = languageCode(language);
|
|
293
|
+
let translated = translatedCopyCache.get(key);
|
|
294
|
+
if (!translated) {
|
|
295
|
+
translated = translateOutputIndexCopy(language, generatedResult.metadata.provider, loadedConfig.providers[generatedResult.metadata.provider]).then(({ copy, usage }) => {
|
|
296
|
+
addTemplateUsage(generatedResult.metadata.usage, usage);
|
|
297
|
+
return copy;
|
|
298
|
+
});
|
|
299
|
+
translatedCopyCache.set(key, translated);
|
|
300
|
+
}
|
|
301
|
+
return translated;
|
|
302
|
+
}
|
|
303
|
+
: undefined,
|
|
304
|
+
projectName: loadedConfig.projectName,
|
|
305
|
+
environment: opts.env,
|
|
306
|
+
language: index.language,
|
|
307
|
+
fromVersion,
|
|
308
|
+
toVersion,
|
|
309
|
+
date: generatedResult.metadata.date,
|
|
310
|
+
releasePaths,
|
|
311
|
+
languageLinks,
|
|
312
|
+
});
|
|
313
|
+
await (0, promises_1.writeFile)(index.path, outputIndexContent, "utf-8");
|
|
314
|
+
console.log(chalk_1.default.green("📚 Updated output index " + index.path));
|
|
315
|
+
}
|
|
316
|
+
const currentIndexPaths = new Set(outputIndexTargets.map((target) => target.path.toLowerCase()));
|
|
317
|
+
for (const existingIndex of outputIndexLanguageTargets) {
|
|
318
|
+
if (currentIndexPaths.has(existingIndex.path.toLowerCase()))
|
|
319
|
+
continue;
|
|
320
|
+
const existing = await (0, promises_1.readFile)(existingIndex.path, "utf-8");
|
|
321
|
+
const languageLinks = getOutputIndexLanguageLinks(existingIndex, outputIndexLanguageTargets);
|
|
322
|
+
const languageSwitcher = (0, release_js_1.renderOutputIndexLanguageSwitcher)(existingIndex.format, languageLinks);
|
|
323
|
+
const hasLanguageSwitcher = (0, release_js_1.hasOutputIndexLanguageSwitcher)(existing);
|
|
324
|
+
let updated = (0, release_js_1.applyOutputIndexLanguageSwitcher)(existing, languageSwitcher);
|
|
325
|
+
if (!hasLanguageSwitcher &&
|
|
326
|
+
!existingIndex.templatePath &&
|
|
327
|
+
languageLinks.length > 1 &&
|
|
328
|
+
existing.includes(RELEASES_MARKER)) {
|
|
329
|
+
updated = existing.replace(RELEASES_MARKER, `${languageSwitcher}\n\n${RELEASES_MARKER}`);
|
|
330
|
+
}
|
|
331
|
+
if (updated !== existing) {
|
|
332
|
+
await (0, promises_1.writeFile)(existingIndex.path, updated, "utf-8");
|
|
333
|
+
console.log(chalk_1.default.green("🌐 Refreshed languages in " + existingIndex.path));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
// Clipboard
|
|
338
|
+
if (opts.clipboard) {
|
|
339
|
+
await clipboardy_1.default.write(generatedResult.markdown);
|
|
340
|
+
printStatus(opts.stdout, chalk_1.default.blue("📋 Copied to clipboard"));
|
|
341
|
+
}
|
|
342
|
+
// Metadata
|
|
343
|
+
printGenerationSummary(opts.stdout, generatedResult);
|
|
344
|
+
summaryPrinted = true;
|
|
345
|
+
}
|
|
346
|
+
catch (err) {
|
|
347
|
+
const partialResult = result || (err instanceof generator_js_1.GenerationError ? { metadata: err.metadata } : undefined);
|
|
348
|
+
if (partialResult && !summaryPrinted) {
|
|
349
|
+
printGenerationSummary(opts.stdout, partialResult);
|
|
350
|
+
}
|
|
351
|
+
const providerOverride = config
|
|
352
|
+
? (opts.with ? (0, config_js_1.resolveProviderAlias)(opts.with) : config.provider)
|
|
353
|
+
: undefined;
|
|
354
|
+
console.error(chalk_1.default.red("\n❌ Error:"), formatGenerationError(err, partialResult, config, providerOverride));
|
|
355
|
+
process.exit(1);
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
// ── providers ──
|
|
359
|
+
program
|
|
360
|
+
.command("providers")
|
|
361
|
+
.description("List supported LLM providers")
|
|
362
|
+
.action(() => {
|
|
363
|
+
console.log(chalk_1.default.cyan("Supported providers:\n"));
|
|
364
|
+
const providers = [
|
|
365
|
+
{ alias: "claude", name: "anthropic", desc: "Claude 3.5 Sonnet, Claude 3 Opus" },
|
|
366
|
+
{ alias: "gpt4", name: "openai", desc: "GPT-4o, GPT-4o-mini" },
|
|
367
|
+
{ alias: "mistral", name: "mistral", desc: "Mistral Large, Mistral Medium" },
|
|
368
|
+
{ alias: "gemini", name: "google", desc: "Gemini 1.5 Pro, Gemini 1.5 Flash" },
|
|
369
|
+
{ alias: "ollama", name: "ollama", desc: "Local models (Llama, Mistral, etc.)" },
|
|
370
|
+
{ alias: "azure", name: "azure-openai", desc: "Azure OpenAI Service" },
|
|
371
|
+
];
|
|
372
|
+
providers.forEach((p) => {
|
|
373
|
+
console.log(` ${chalk_1.default.green("●")} ${chalk_1.default.bold(p.alias.padEnd(10))} → ${p.name.padEnd(14)} ${chalk_1.default.gray(p.desc)}`);
|
|
374
|
+
});
|
|
375
|
+
console.log(chalk_1.default.gray("\nUse --with <alias> to override the default provider."));
|
|
376
|
+
});
|
|
377
|
+
program.parse();
|
|
378
|
+
function getOutputPath(saveTo, environment, language, fromVersion, toVersion) {
|
|
379
|
+
const normalizedEnvironment = environment.trim().toUpperCase().replace(/[^A-Z0-9]+/g, "_");
|
|
380
|
+
const normalizedLanguage = language?.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_");
|
|
381
|
+
return saveTo
|
|
382
|
+
.replaceAll("{env}", normalizedEnvironment)
|
|
383
|
+
.replaceAll("{lang}", normalizedLanguage || "{lang}")
|
|
384
|
+
.replaceAll("{from}", fromVersion || "start")
|
|
385
|
+
.replaceAll("{to}", toVersion || "end");
|
|
386
|
+
}
|
|
387
|
+
function getReleasePathsForIndex(index, outputTargets) {
|
|
388
|
+
const languageTargets = outputTargets.filter((target) => !index.language || !target.language || target.language === index.language);
|
|
389
|
+
const preferredFormat = index.format;
|
|
390
|
+
const preferredTargets = languageTargets.filter((target) => getOutputFormat(target) === preferredFormat);
|
|
391
|
+
const selectedTargets = preferredTargets.length > 0
|
|
392
|
+
? preferredTargets
|
|
393
|
+
: languageTargets.filter((target) => getOutputFormat(target) !== preferredFormat);
|
|
394
|
+
return [...new Set(selectedTargets.map((target) => (0, path_1.resolve)(target.path)))];
|
|
395
|
+
}
|
|
396
|
+
function getOutputFormat(target) {
|
|
397
|
+
return target.format === "html" ? "html" : "markdown";
|
|
398
|
+
}
|
|
399
|
+
function getOutputIndexLanguageLinks(index, targets) {
|
|
400
|
+
return targets
|
|
401
|
+
.filter((candidate) => candidate.groupId === index.groupId)
|
|
402
|
+
.map((candidate) => ({
|
|
403
|
+
language: candidate.language,
|
|
404
|
+
href: toRelativeLink(index.path, candidate.path),
|
|
405
|
+
active: candidate.path.toLowerCase() === index.path.toLowerCase(),
|
|
406
|
+
}));
|
|
407
|
+
}
|
|
408
|
+
const RELEASES_MARKER = "<!-- ai-release-notes:releases -->";
|
|
409
|
+
const RELEASES_END_MARKER = "<!-- ai-release-notes:/releases -->";
|
|
410
|
+
async function createOrUpdateOutputIndex(params) {
|
|
411
|
+
const copy = params.translateCopy
|
|
412
|
+
? await params.translateCopy()
|
|
413
|
+
: getOutputIndexCopy(params.language);
|
|
414
|
+
const localizedDate = localizeIndexDate(params.date, params.language);
|
|
415
|
+
const releaseId = [params.environment, params.fromVersion, params.toVersion]
|
|
416
|
+
.map((value) => encodeURIComponent(value))
|
|
417
|
+
.join("_");
|
|
418
|
+
const releaseEntry = buildOutputIndexEntry(params, releaseId, copy, localizedDate);
|
|
419
|
+
const indexTitle = `${params.projectName ? params.projectName + " · " : ""}${copy.releaseNotes}`;
|
|
420
|
+
const intro = copy.intro(params.environment);
|
|
421
|
+
const languageSwitcher = (0, release_js_1.renderOutputIndexLanguageSwitcher)(params.format, params.languageLinks);
|
|
422
|
+
if ((0, fs_1.existsSync)(params.outputPath)) {
|
|
423
|
+
const existing = await (0, promises_1.readFile)(params.outputPath, "utf-8");
|
|
424
|
+
const normalizedExisting = params.format === "html"
|
|
425
|
+
? unwrapHtmlDocumentCodeFence(existing)
|
|
426
|
+
: existing;
|
|
427
|
+
const boundedExisting = ensureOutputIndexReleaseBoundary(normalizedExisting, params.format);
|
|
428
|
+
const updated = (0, release_js_1.insertOrUpdateOutputIndexReleaseEntry)(localizeExistingIndexEntries(localizeExistingIndexChrome(boundedExisting, params.format, indexTitle, intro), params.format, copy), releaseEntry, releaseId);
|
|
429
|
+
const hasLanguageSwitcher = (0, release_js_1.hasOutputIndexLanguageSwitcher)(updated);
|
|
430
|
+
const withLanguageSwitcher = (0, release_js_1.applyOutputIndexLanguageSwitcher)(updated, languageSwitcher);
|
|
431
|
+
if (!params.templatePath && params.languageLinks.length > 1 && !hasLanguageSwitcher) {
|
|
432
|
+
return updated.replace(RELEASES_MARKER, `${languageSwitcher}\n\n${RELEASES_MARKER}`);
|
|
433
|
+
}
|
|
434
|
+
return withLanguageSwitcher;
|
|
435
|
+
}
|
|
436
|
+
const template = await loadOutputIndexTemplate(params.templatePath, params.format);
|
|
437
|
+
const localizedTemplate = params.translateTemplate
|
|
438
|
+
? await params.translateTemplate(template)
|
|
439
|
+
: template;
|
|
440
|
+
const rendered = renderOutputIndexTemplate(localizedTemplate, {
|
|
441
|
+
projectName: params.projectName || "Project",
|
|
442
|
+
environment: params.environment,
|
|
443
|
+
language: params.language || "",
|
|
444
|
+
date: localizedDate,
|
|
445
|
+
releases: releaseEntry,
|
|
446
|
+
languages: languageSwitcher,
|
|
447
|
+
version: CLI_VERSION,
|
|
448
|
+
});
|
|
449
|
+
if (params.format === "markdown") {
|
|
450
|
+
return rendered.trim() + "\n";
|
|
451
|
+
}
|
|
452
|
+
const isHtmlTemplate = !params.templatePath || /\.html?$/i.test(params.templatePath);
|
|
453
|
+
const html = isHtmlTemplate
|
|
454
|
+
? rendered
|
|
455
|
+
: (0, release_js_1.markdownToHtml)(rendered, "Release index");
|
|
456
|
+
return html;
|
|
457
|
+
}
|
|
458
|
+
function buildOutputIndexEntry(params, releaseId, copy, localizedDate) {
|
|
459
|
+
const releasePaths = [...new Set(params.releasePaths)];
|
|
460
|
+
const marker = `<!-- ai-release-notes:release ${releaseId} -->`;
|
|
461
|
+
const title = `${copy.release} ${params.toVersion}`;
|
|
462
|
+
const metadata = `${params.environment} · ${localizedDate} · ${copy.changesSince} ${params.fromVersion}`;
|
|
463
|
+
if (params.format === "html") {
|
|
464
|
+
const links = releasePaths
|
|
465
|
+
.map((path) => {
|
|
466
|
+
const href = escapeHtml(toRelativeLink(params.outputPath, path));
|
|
467
|
+
return `<a href="${href}">${escapeHtml(copy.readReleaseNotes)} <span aria-hidden="true">→</span></a>`;
|
|
468
|
+
})
|
|
469
|
+
.join("\n");
|
|
470
|
+
return `${marker}\n<section class="release-entry">\n<h2>${escapeHtml(title)}</h2>\n<p class="release-meta"><em>${escapeHtml(metadata)}</em></p>\n<p class="release-link">${links}</p>\n</section>`;
|
|
471
|
+
}
|
|
472
|
+
const links = releasePaths
|
|
473
|
+
.map((path) => `[${copy.readReleaseNotes} →](${toRelativeLink(params.outputPath, path)})`)
|
|
474
|
+
.join("\n");
|
|
475
|
+
return `${marker}\n## ${title}\n\n_${metadata}_\n\n${links}`;
|
|
476
|
+
}
|
|
477
|
+
async function loadOutputIndexTemplate(templatePath, format) {
|
|
478
|
+
if (!templatePath) {
|
|
479
|
+
const extension = format === "html" ? "html" : "md";
|
|
480
|
+
return (0, promises_1.readFile)((0, path_1.resolve)(__dirname, `../../templates/default-release-summary.${extension}`), "utf-8");
|
|
481
|
+
}
|
|
482
|
+
const resolvedTemplatePath = (0, path_1.resolve)(templatePath);
|
|
483
|
+
if (!(0, fs_1.existsSync)(resolvedTemplatePath)) {
|
|
484
|
+
throw new Error(`Output index template not found: ${resolvedTemplatePath}`);
|
|
485
|
+
}
|
|
486
|
+
return (0, promises_1.readFile)(resolvedTemplatePath, "utf-8");
|
|
487
|
+
}
|
|
488
|
+
function renderOutputIndexTemplate(template, values) {
|
|
489
|
+
const rendered = template
|
|
490
|
+
.replaceAll("{{projectName}}", values.projectName)
|
|
491
|
+
.replaceAll("{{environment}}", values.environment)
|
|
492
|
+
.replaceAll("{{language}}", values.language)
|
|
493
|
+
.replaceAll("{{date}}", values.date)
|
|
494
|
+
.replaceAll("{{releases}}", `${values.releases}\n${RELEASES_END_MARKER}`)
|
|
495
|
+
.replaceAll("{{version}}", values.version);
|
|
496
|
+
return (0, release_js_1.applyOutputIndexLanguageSwitcher)(rendered, values.languages);
|
|
497
|
+
}
|
|
498
|
+
function localizeExistingIndexEntries(content, format, copy) {
|
|
499
|
+
if (format === "markdown") {
|
|
500
|
+
return content
|
|
501
|
+
.replace(/(<!-- ai-release-notes:release [^>]+ -->\n## )(?:Release|Versión|Version)\s+/g, (_match, prefix) => `${prefix}${copy.release} `)
|
|
502
|
+
.replace(/(^_[^\n]*? · [^\n]*? · )(?:Changes since|Cambios desde|Changements depuis)\s+/gm, (_match, prefix) => `${prefix}${copy.changesSince} `)
|
|
503
|
+
.replace(/\[(?:Read release notes|Ver notas de la versión|Voir les notes de version) →\]/g, `[${copy.readReleaseNotes} →]`);
|
|
504
|
+
}
|
|
505
|
+
return content
|
|
506
|
+
.replace(/(<section class="release-entry">\n<h2>)(?:Release|Versión|Version)\s+/g, (_match, prefix) => `${prefix}${escapeHtml(copy.release)} `)
|
|
507
|
+
.replace(/(<p class="release-meta">.*? · .*? · )(?:Changes since|Cambios desde|Changements depuis)\s+/g, (_match, prefix) => `${prefix}${escapeHtml(copy.changesSince)} `)
|
|
508
|
+
.replace(/(<a href="[^"]+">)(?:Read release notes|Ver notas de la versión|Voir les notes de version)(?= <span aria-hidden="true">→<\/span><\/a>)/g, (_match, prefix) => `${prefix}${escapeHtml(copy.readReleaseNotes)}`)
|
|
509
|
+
.replace(/<p class="release-meta">(?!<em>)([\s\S]*?)<\/p>/g, (_match, metadata) => `<p class="release-meta"><em>${metadata}</em></p>`);
|
|
510
|
+
}
|
|
511
|
+
function localizeExistingIndexChrome(content, format, indexTitle, intro) {
|
|
512
|
+
if (format === "markdown") {
|
|
513
|
+
return content
|
|
514
|
+
.replace(/^# .*?(?:release notes|release index)\s*$/im, `# ${indexTitle}`)
|
|
515
|
+
.replace(/^A concise release history for .*?\. The newest release is listed first\.\s*$/im, intro);
|
|
516
|
+
}
|
|
517
|
+
return content
|
|
518
|
+
.replace(/<title>.*?(?:release notes|release index)<\/title>/i, `<title>${escapeHtml(indexTitle)}</title>`)
|
|
519
|
+
.replace(/<h1>.*?(?:release notes|release index)<\/h1>/i, `<h1>${escapeHtml(indexTitle)}</h1>`)
|
|
520
|
+
.replace(/<p class="intro">A concise release history for .*?\. The newest release is listed first\.<\/p>/i, `<p class="intro">${escapeHtml(intro)}</p>`);
|
|
521
|
+
}
|
|
522
|
+
function getOutputIndexCopy(language) {
|
|
523
|
+
const code = language ? languageCode(language) : undefined;
|
|
524
|
+
if (code === "es") {
|
|
525
|
+
return {
|
|
526
|
+
release: "Versión",
|
|
527
|
+
releaseNotes: "Notas de la versión",
|
|
528
|
+
intro: (environment) => `Un historial conciso de versiones para ${environment}. Las más recientes aparecen primero.`,
|
|
529
|
+
changesSince: "Cambios desde",
|
|
530
|
+
readReleaseNotes: "Ver notas de la versión",
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
if (code === "fr") {
|
|
534
|
+
return {
|
|
535
|
+
release: "Version",
|
|
536
|
+
releaseNotes: "Notes de version",
|
|
537
|
+
intro: (environment) => `Un historique concis des versions pour ${environment}. Les plus récentes apparaissent en premier.`,
|
|
538
|
+
changesSince: "Changements depuis",
|
|
539
|
+
readReleaseNotes: "Voir les notes de version",
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
return {
|
|
543
|
+
release: "Release",
|
|
544
|
+
releaseNotes: "Release notes",
|
|
545
|
+
intro: (environment) => `A concise release history for ${environment}. The newest release is listed first.`,
|
|
546
|
+
changesSince: "Changes since",
|
|
547
|
+
readReleaseNotes: "Read release notes",
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
function localizeIndexDate(date, language) {
|
|
551
|
+
if (!language)
|
|
552
|
+
return date;
|
|
553
|
+
const parsed = new Date(date);
|
|
554
|
+
if (Number.isNaN(parsed.getTime()))
|
|
555
|
+
return date;
|
|
556
|
+
return new Intl.DateTimeFormat(language, {
|
|
557
|
+
day: "numeric",
|
|
558
|
+
month: "long",
|
|
559
|
+
year: "numeric",
|
|
560
|
+
}).format(parsed);
|
|
561
|
+
}
|
|
562
|
+
function shouldTranslateTemplate(templateLanguage, outputLanguage) {
|
|
563
|
+
if (!outputLanguage)
|
|
564
|
+
return false;
|
|
565
|
+
return languageCode(templateLanguage) !== languageCode(outputLanguage);
|
|
566
|
+
}
|
|
567
|
+
function shouldTranslateOutputIndexCopy(language) {
|
|
568
|
+
return Boolean(language && languageCode(language) !== "en");
|
|
569
|
+
}
|
|
570
|
+
async function translateOutputIndexCopy(language, providerName, providerConfig) {
|
|
571
|
+
const result = await (0, llm_js_1.callLLM)(providerName, providerConfig, "You translate the labels used in a release-summary index. Return only valid JSON with these string keys: " +
|
|
572
|
+
"release, releaseNotes, intro, changesSince, readReleaseNotes. " +
|
|
573
|
+
"The intro value must preserve {{environment}} exactly. Do not include Markdown, HTML, or explanations.", `Target language: ${language}\n\nEnglish source:\n` +
|
|
574
|
+
JSON.stringify({
|
|
575
|
+
release: "Release",
|
|
576
|
+
releaseNotes: "Release notes",
|
|
577
|
+
intro: "A concise release history for {{environment}}. The newest release is listed first.",
|
|
578
|
+
changesSince: "Changes since",
|
|
579
|
+
readReleaseNotes: "Read release notes",
|
|
580
|
+
}));
|
|
581
|
+
const rawJson = result.text.trim().replace(/^```(?:json)?\s*/i, "").replace(/\s*```$/, "");
|
|
582
|
+
let translated;
|
|
583
|
+
try {
|
|
584
|
+
translated = JSON.parse(rawJson);
|
|
585
|
+
}
|
|
586
|
+
catch {
|
|
587
|
+
throw new Error("Could not parse translated output-index labels as JSON");
|
|
588
|
+
}
|
|
589
|
+
if (!isOutputIndexCopyTranslation(translated)) {
|
|
590
|
+
throw new Error("Translated output-index labels are incomplete");
|
|
591
|
+
}
|
|
592
|
+
return {
|
|
593
|
+
copy: {
|
|
594
|
+
release: translated.release,
|
|
595
|
+
releaseNotes: translated.releaseNotes,
|
|
596
|
+
intro: (environment) => translated.intro.replaceAll("{{environment}}", environment),
|
|
597
|
+
changesSince: translated.changesSince,
|
|
598
|
+
readReleaseNotes: translated.readReleaseNotes,
|
|
599
|
+
},
|
|
600
|
+
usage: result.usage,
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
function isOutputIndexCopyTranslation(value) {
|
|
604
|
+
if (!value || typeof value !== "object")
|
|
605
|
+
return false;
|
|
606
|
+
const candidate = value;
|
|
607
|
+
return ["release", "releaseNotes", "intro", "changesSince", "readReleaseNotes"]
|
|
608
|
+
.every((key) => typeof candidate[key] === "string" && candidate[key].trim().length > 0)
|
|
609
|
+
&& typeof candidate.intro === "string"
|
|
610
|
+
&& candidate.intro.includes("{{environment}}");
|
|
611
|
+
}
|
|
612
|
+
async function translateOutputIndexTemplate(template, language, providerName, providerConfig) {
|
|
613
|
+
const protectedTemplate = protectTemplateTokens(template);
|
|
614
|
+
const result = await (0, llm_js_1.callLLM)(providerName, providerConfig, "You translate release-summary templates. Return only the translated template. " +
|
|
615
|
+
"Translate every human-readable sentence into the requested language, but preserve all HTML, CSS, Markdown syntax, URLs, and protected tokens exactly.", `Target language: ${language}\n\nTemplate:\n${protectedTemplate.template}`);
|
|
616
|
+
const translated = unwrapHtmlDocumentCodeFence(restoreTemplateTokens(result.text, protectedTemplate.tokens));
|
|
617
|
+
if (!translated.includes(RELEASES_MARKER) || !translated.includes("{{releases}}")) {
|
|
618
|
+
throw new Error("Translated output-index template did not preserve the required releases marker or {{releases}} token");
|
|
619
|
+
}
|
|
620
|
+
return { text: translated, usage: result.usage };
|
|
621
|
+
}
|
|
622
|
+
/** Models occasionally wrap an HTML template in a Markdown code fence. */
|
|
623
|
+
function unwrapHtmlDocumentCodeFence(content) {
|
|
624
|
+
const openingFence = /^\s*```html?\s*\r?\n(?=\s*<!doctype html|\s*<html\b)/i;
|
|
625
|
+
if (!openingFence.test(content))
|
|
626
|
+
return content;
|
|
627
|
+
return content
|
|
628
|
+
.replace(openingFence, "")
|
|
629
|
+
.replace(/\r?\n```\s*$/, "");
|
|
630
|
+
}
|
|
631
|
+
function protectTemplateTokens(template) {
|
|
632
|
+
const values = [
|
|
633
|
+
RELEASES_MARKER,
|
|
634
|
+
"{{projectName}}",
|
|
635
|
+
"{{environment}}",
|
|
636
|
+
"{{language}}",
|
|
637
|
+
"{{languages}}",
|
|
638
|
+
"{{langages}}",
|
|
639
|
+
"{{date}}",
|
|
640
|
+
"{{releases}}",
|
|
641
|
+
"{{version}}",
|
|
642
|
+
];
|
|
643
|
+
const tokens = values.map((value, index) => [value, `__AI_RELEASE_TEMPLATE_TOKEN_${index}__`]);
|
|
644
|
+
return {
|
|
645
|
+
template: tokens.reduce((result, [value, token]) => result.replaceAll(value, token), template),
|
|
646
|
+
tokens,
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
function restoreTemplateTokens(template, tokens) {
|
|
650
|
+
return tokens.reduce((result, [value, token]) => result.replaceAll(token, value), template);
|
|
651
|
+
}
|
|
652
|
+
function addTemplateUsage(total, usage) {
|
|
653
|
+
total.inputTokens += usage.inputTokens;
|
|
654
|
+
total.outputTokens += usage.outputTokens;
|
|
655
|
+
total.totalTokens += usage.totalTokens;
|
|
656
|
+
total.modelCalls += 1;
|
|
657
|
+
}
|
|
658
|
+
function languageCode(language) {
|
|
659
|
+
return language.toLowerCase().split(/[-_]/, 1)[0];
|
|
660
|
+
}
|
|
661
|
+
function ensureOutputIndexReleaseBoundary(content, format) {
|
|
662
|
+
if (!content.includes(RELEASES_MARKER) || content.includes(RELEASES_END_MARKER)) {
|
|
663
|
+
return content;
|
|
664
|
+
}
|
|
665
|
+
const releasesStart = content.indexOf(RELEASES_MARKER) + RELEASES_MARKER.length;
|
|
666
|
+
const candidates = [content.indexOf("<!-- ai-release-notes:languages -->", releasesStart)];
|
|
667
|
+
candidates.push(format === "html"
|
|
668
|
+
? content.indexOf("</main>", releasesStart)
|
|
669
|
+
: content.indexOf("\n---\n", releasesStart));
|
|
670
|
+
const boundary = candidates.filter((index) => index >= 0).sort((a, b) => a - b)[0];
|
|
671
|
+
if (boundary === undefined) {
|
|
672
|
+
return `${content.trimEnd()}\n${RELEASES_END_MARKER}\n`;
|
|
673
|
+
}
|
|
674
|
+
return `${content.slice(0, boundary).trimEnd()}\n${RELEASES_END_MARKER}\n${content.slice(boundary).replace(/^\n/, "")}`;
|
|
675
|
+
}
|
|
676
|
+
function toRelativeLink(fromPath, toPath) {
|
|
677
|
+
return (0, path_1.relative)((0, path_1.dirname)(fromPath), toPath)
|
|
678
|
+
.replaceAll("\\", "/")
|
|
679
|
+
.split("/")
|
|
680
|
+
.map((segment) => segment === "." || segment === ".." ? segment : encodeURIComponent(segment))
|
|
681
|
+
.join("/");
|
|
682
|
+
}
|
|
683
|
+
function escapeHtml(value) {
|
|
684
|
+
return value
|
|
685
|
+
.replaceAll("&", "&")
|
|
686
|
+
.replaceAll("<", "<")
|
|
687
|
+
.replaceAll(">", ">")
|
|
688
|
+
.replaceAll('"', """);
|
|
689
|
+
}
|
|
690
|
+
function formatNumber(value) {
|
|
691
|
+
return new Intl.NumberFormat("en-US").format(value);
|
|
692
|
+
}
|
|
693
|
+
function formatDuration(durationMs) {
|
|
694
|
+
return `${(durationMs / 1000).toFixed(1)}s`;
|
|
695
|
+
}
|
|
696
|
+
async function saveReleaseNotes(outputPath, content, markdown) {
|
|
697
|
+
const header = markdown.split("\n", 1)[0];
|
|
698
|
+
const existing = (0, fs_1.existsSync)(outputPath) ? await (0, promises_1.readFile)(outputPath, "utf-8") : "";
|
|
699
|
+
if (existing.includes(header))
|
|
700
|
+
return "skipped";
|
|
701
|
+
const merged = outputPath.endsWith(".html")
|
|
702
|
+
? appendHtmlRelease(existing, content)
|
|
703
|
+
: existing.trim()
|
|
704
|
+
? content.trim() + "\n\n---\n\n" + existing.trim() + "\n"
|
|
705
|
+
: content.trim() + "\n";
|
|
706
|
+
await (0, promises_1.writeFile)(outputPath, merged, "utf-8");
|
|
707
|
+
return "saved";
|
|
708
|
+
}
|
|
709
|
+
function appendHtmlRelease(existing, content) {
|
|
710
|
+
if (!existing.trim())
|
|
711
|
+
return content;
|
|
712
|
+
const newBody = content
|
|
713
|
+
.replace(/^[\s\S]*?<body[^>]*>/i, "")
|
|
714
|
+
.replace(/<\/body>[\s\S]*$/i, "")
|
|
715
|
+
.replace(/^\s*<main[^>]*>/i, "")
|
|
716
|
+
.replace(/<\/main>\s*$/i, "")
|
|
717
|
+
.trim();
|
|
718
|
+
const entry = "<hr>\n<section class=\"release-entry\">\n" + newBody + "\n</section>\n";
|
|
719
|
+
return /<\/main>\s*<\/body>/i.test(existing)
|
|
720
|
+
? existing.replace(/<\/main>\s*<\/body>/i, entry + "</main>\n</body>")
|
|
721
|
+
: existing.replace(/<\/body>/i, entry + "</body>");
|
|
722
|
+
}
|
|
723
|
+
//# sourceMappingURL=cli.js.map
|