tst-changelog 0.3.0 → 0.4.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/dist/index.d.ts +28 -1
- package/dist/index.js +232 -54
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -47,6 +47,12 @@ interface CommitInfo {
|
|
|
47
47
|
date: string;
|
|
48
48
|
body?: string;
|
|
49
49
|
}
|
|
50
|
+
type DateGroupedCommits = Map<string, CommitInfo[]>;
|
|
51
|
+
interface VersionedEntry {
|
|
52
|
+
version: string;
|
|
53
|
+
date: string;
|
|
54
|
+
generated: GeneratedChangelog;
|
|
55
|
+
}
|
|
50
56
|
interface StagedChanges {
|
|
51
57
|
files: string[];
|
|
52
58
|
diff: string;
|
|
@@ -70,6 +76,7 @@ interface CLIOptions {
|
|
|
70
76
|
dryRun?: boolean;
|
|
71
77
|
verbose?: boolean;
|
|
72
78
|
fromCommits?: number;
|
|
79
|
+
version?: string;
|
|
73
80
|
}
|
|
74
81
|
|
|
75
82
|
/**
|
|
@@ -156,6 +163,26 @@ declare class ChangelogService {
|
|
|
156
163
|
* Generate new changelog entry
|
|
157
164
|
*/
|
|
158
165
|
formatEntry(generated: GeneratedChangelog, version?: string, metadata?: ChangelogMetadata): string;
|
|
166
|
+
/**
|
|
167
|
+
* Format a simple entry with just version and date (no time, no author)
|
|
168
|
+
* Used for --from-commits mode with date grouping
|
|
169
|
+
*/
|
|
170
|
+
formatSimpleEntry(generated: GeneratedChangelog, version: string, date: string): string;
|
|
171
|
+
/**
|
|
172
|
+
* Format multiple versioned entries into changelog format
|
|
173
|
+
* Entries should already be sorted (newest first)
|
|
174
|
+
*/
|
|
175
|
+
formatMultipleEntries(entries: VersionedEntry[]): string;
|
|
176
|
+
/**
|
|
177
|
+
* Update changelog with multiple versioned entries (for --from-commits mode)
|
|
178
|
+
* Entries should be in order from newest to oldest (for display order)
|
|
179
|
+
*/
|
|
180
|
+
updateWithMultipleEntries(entries: VersionedEntry[]): string;
|
|
181
|
+
/**
|
|
182
|
+
* Update JSON changelog with multiple releases (for --from-commits mode)
|
|
183
|
+
* Entries should be in order from newest to oldest
|
|
184
|
+
*/
|
|
185
|
+
updateJsonWithMultipleEntries(entries: VersionedEntry[]): ChangelogJson;
|
|
159
186
|
private sortSections;
|
|
160
187
|
private formatSection;
|
|
161
188
|
/**
|
|
@@ -201,4 +228,4 @@ declare class ChangelogService {
|
|
|
201
228
|
writeJson(data: ChangelogJson): void;
|
|
202
229
|
}
|
|
203
230
|
|
|
204
|
-
export { type AIConfig, AIService, type CLIOptions, type ChangeType, type ChangelogConfig, type ChangelogEntry, type ChangelogJson, type ChangelogJsonRelease, type ChangelogMetadata, type ChangelogSection, ChangelogService, type CommitInfo, type Config, type GeneratedChangelog, type GitConfig, GitService, type InitResult, type StagedChanges, initConfig, loadConfig };
|
|
231
|
+
export { type AIConfig, AIService, type CLIOptions, type ChangeType, type ChangelogConfig, type ChangelogEntry, type ChangelogJson, type ChangelogJsonRelease, type ChangelogMetadata, type ChangelogSection, ChangelogService, type CommitInfo, type Config, type DateGroupedCommits, type GeneratedChangelog, type GitConfig, GitService, type InitResult, type StagedChanges, type VersionedEntry, initConfig, loadConfig };
|
package/dist/index.js
CHANGED
|
@@ -3,14 +3,29 @@
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import "dotenv/config";
|
|
5
5
|
import { Command } from "commander";
|
|
6
|
-
import { readFileSync as readFileSync3 } from "fs";
|
|
6
|
+
import { readFileSync as readFileSync3, existsSync as existsSync3 } from "fs";
|
|
7
7
|
import { fileURLToPath } from "url";
|
|
8
8
|
import { dirname, resolve as resolve3 } from "path";
|
|
9
9
|
|
|
10
10
|
// src/config.ts
|
|
11
11
|
import { readFileSync, existsSync, writeFileSync, appendFileSync } from "fs";
|
|
12
12
|
import { resolve } from "path";
|
|
13
|
+
import { execSync } from "child_process";
|
|
13
14
|
import { parse, stringify } from "yaml";
|
|
15
|
+
function getRepoUrlFromGit() {
|
|
16
|
+
try {
|
|
17
|
+
const url = execSync("git remote get-url --push origin", {
|
|
18
|
+
encoding: "utf-8",
|
|
19
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
20
|
+
}).trim();
|
|
21
|
+
if (url.startsWith("git@")) {
|
|
22
|
+
return url.replace(/^git@([^:]+):/, "https://$1/").replace(/\.git$/, "");
|
|
23
|
+
}
|
|
24
|
+
return url.replace(/\.git$/, "");
|
|
25
|
+
} catch {
|
|
26
|
+
return "";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
14
29
|
var DEFAULT_PROMPT = `You are a changelog generator. Your task is to analyze git commits and staged changes to generate changelog entries following the Keep a Changelog format.
|
|
15
30
|
|
|
16
31
|
Output Format:
|
|
@@ -113,18 +128,27 @@ function loadConfig(configPath) {
|
|
|
113
128
|
}
|
|
114
129
|
}
|
|
115
130
|
if (!filePath) {
|
|
116
|
-
|
|
131
|
+
const config2 = resolveConfigEnvVars(DEFAULT_CONFIG);
|
|
132
|
+
if (!config2.changelog.repoUrl) {
|
|
133
|
+
config2.changelog.repoUrl = getRepoUrlFromGit();
|
|
134
|
+
}
|
|
135
|
+
return config2;
|
|
117
136
|
}
|
|
118
137
|
const content = readFileSync(filePath, "utf-8");
|
|
119
138
|
const parsed = parse(content);
|
|
120
139
|
const merged = deepMerge(DEFAULT_CONFIG, parsed);
|
|
121
|
-
|
|
140
|
+
const config = resolveConfigEnvVars(merged);
|
|
141
|
+
if (!config.changelog.repoUrl) {
|
|
142
|
+
config.changelog.repoUrl = getRepoUrlFromGit();
|
|
143
|
+
}
|
|
144
|
+
return config;
|
|
122
145
|
}
|
|
123
146
|
function initConfig(fileName = "tst-changelog.yaml") {
|
|
124
147
|
const filePath = resolve(process.cwd(), fileName);
|
|
125
148
|
if (existsSync(filePath)) {
|
|
126
149
|
throw new Error(`Config file already exists: ${filePath}`);
|
|
127
150
|
}
|
|
151
|
+
const detectedRepoUrl = getRepoUrlFromGit();
|
|
128
152
|
const configTemplate = {
|
|
129
153
|
ai: {
|
|
130
154
|
provider: "openrouter",
|
|
@@ -140,7 +164,7 @@ function initConfig(fileName = "tst-changelog.yaml") {
|
|
|
140
164
|
includeTime: true,
|
|
141
165
|
includeAuthor: true,
|
|
142
166
|
includeCommitLink: true,
|
|
143
|
-
repoUrl:
|
|
167
|
+
repoUrl: detectedRepoUrl,
|
|
144
168
|
groupBy: "type"
|
|
145
169
|
},
|
|
146
170
|
git: {
|
|
@@ -479,6 +503,73 @@ var ChangelogService = class {
|
|
|
479
503
|
|
|
480
504
|
${sectionLines}`;
|
|
481
505
|
}
|
|
506
|
+
/**
|
|
507
|
+
* Format a simple entry with just version and date (no time, no author)
|
|
508
|
+
* Used for --from-commits mode with date grouping
|
|
509
|
+
*/
|
|
510
|
+
formatSimpleEntry(generated, version, date) {
|
|
511
|
+
const headerLine = `## [${version}] - ${date}`;
|
|
512
|
+
const sections = this.sortSections(generated.sections);
|
|
513
|
+
const sectionLines = sections.map((section) => this.formatSection(section)).join("\n\n");
|
|
514
|
+
return `${headerLine}
|
|
515
|
+
|
|
516
|
+
${sectionLines}`;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Format multiple versioned entries into changelog format
|
|
520
|
+
* Entries should already be sorted (newest first)
|
|
521
|
+
*/
|
|
522
|
+
formatMultipleEntries(entries) {
|
|
523
|
+
return entries.map((entry) => this.formatSimpleEntry(entry.generated, entry.version, entry.date)).join("\n\n");
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Update changelog with multiple versioned entries (for --from-commits mode)
|
|
527
|
+
* Entries should be in order from newest to oldest (for display order)
|
|
528
|
+
*/
|
|
529
|
+
updateWithMultipleEntries(entries) {
|
|
530
|
+
const existing = this.read();
|
|
531
|
+
const newContent = this.formatMultipleEntries(entries);
|
|
532
|
+
if (!existing) {
|
|
533
|
+
return KEEPACHANGELOG_HEADER + newContent + "\n";
|
|
534
|
+
}
|
|
535
|
+
const lines = existing.split("\n");
|
|
536
|
+
let insertIndex = -1;
|
|
537
|
+
for (let i = 0; i < lines.length; i++) {
|
|
538
|
+
const line = lines[i];
|
|
539
|
+
if (line.startsWith("## [")) {
|
|
540
|
+
insertIndex = i;
|
|
541
|
+
break;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
if (insertIndex === -1) {
|
|
545
|
+
return existing.trimEnd() + "\n\n" + newContent + "\n";
|
|
546
|
+
}
|
|
547
|
+
const before = lines.slice(0, insertIndex).join("\n");
|
|
548
|
+
const after = lines.slice(insertIndex).join("\n");
|
|
549
|
+
return before + (before.endsWith("\n") ? "" : "\n") + newContent + "\n\n" + after;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Update JSON changelog with multiple releases (for --from-commits mode)
|
|
553
|
+
* Entries should be in order from newest to oldest
|
|
554
|
+
*/
|
|
555
|
+
updateJsonWithMultipleEntries(entries) {
|
|
556
|
+
const existing = this.readJson();
|
|
557
|
+
const newReleases = entries.map((entry) => {
|
|
558
|
+
const sections = {};
|
|
559
|
+
for (const section of entry.generated.sections) {
|
|
560
|
+
sections[section.type] = section.items;
|
|
561
|
+
}
|
|
562
|
+
return {
|
|
563
|
+
version: entry.version,
|
|
564
|
+
date: entry.date,
|
|
565
|
+
sections
|
|
566
|
+
};
|
|
567
|
+
});
|
|
568
|
+
if (!existing) {
|
|
569
|
+
return { releases: newReleases };
|
|
570
|
+
}
|
|
571
|
+
return { releases: [...newReleases, ...existing.releases] };
|
|
572
|
+
}
|
|
482
573
|
sortSections(sections) {
|
|
483
574
|
return [...sections].sort((a, b) => {
|
|
484
575
|
const indexA = SECTION_ORDER.indexOf(a.type);
|
|
@@ -707,6 +798,33 @@ ${sectionLines}`;
|
|
|
707
798
|
// src/index.ts
|
|
708
799
|
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
709
800
|
var pkg = JSON.parse(readFileSync3(resolve3(__dirname, "../package.json"), "utf-8"));
|
|
801
|
+
function getBaseVersion() {
|
|
802
|
+
const pkgPath = resolve3(process.cwd(), "package.json");
|
|
803
|
+
if (!existsSync3(pkgPath)) {
|
|
804
|
+
return "0.0.0";
|
|
805
|
+
}
|
|
806
|
+
try {
|
|
807
|
+
const projectPkg = JSON.parse(readFileSync3(pkgPath, "utf-8"));
|
|
808
|
+
return projectPkg.version ?? "0.0.0";
|
|
809
|
+
} catch {
|
|
810
|
+
return "0.0.0";
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
function incrementMinorVersion(baseVersion, count) {
|
|
814
|
+
const [major] = baseVersion.split(".").map(Number);
|
|
815
|
+
return `${major}.${count}.0`;
|
|
816
|
+
}
|
|
817
|
+
function groupCommitsByDate(commits) {
|
|
818
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
819
|
+
for (const commit of commits) {
|
|
820
|
+
const date = commit.date.split("T")[0];
|
|
821
|
+
if (!grouped.has(date)) {
|
|
822
|
+
grouped.set(date, []);
|
|
823
|
+
}
|
|
824
|
+
grouped.get(date).push(commit);
|
|
825
|
+
}
|
|
826
|
+
return grouped;
|
|
827
|
+
}
|
|
710
828
|
var program = new Command();
|
|
711
829
|
program.name("tst-changelog").description("AI-powered changelog generator using OpenRouter").version(pkg.version);
|
|
712
830
|
program.command("init").description("Create a default configuration file").option("-f, --file <name>", "Config file name", "tst-changelog.yaml").action((options) => {
|
|
@@ -727,7 +845,7 @@ program.command("init").description("Create a default configuration file").optio
|
|
|
727
845
|
process.exit(1);
|
|
728
846
|
}
|
|
729
847
|
});
|
|
730
|
-
program.command("generate", { isDefault: true }).description("Generate changelog from staged changes or commit history").option("-c, --config <path>", "Path to config file").option("-d, --dry-run", "Preview without modifying files").option("-v, --verbose", "Enable verbose output").option("--from-commits <count>", "Generate from last N commits instead of staged changes", parseInt).action(run);
|
|
848
|
+
program.command("generate", { isDefault: true }).description("Generate changelog from staged changes or commit history").option("-c, --config <path>", "Path to config file").option("-d, --dry-run", "Preview without modifying files").option("-v, --verbose", "Enable verbose output").option("--from-commits <count>", "Generate from last N commits instead of staged changes", parseInt).option("--version <version>", 'Version label for the changelog entry (default: "Unreleased" or date for --from-commits)').action(run);
|
|
731
849
|
async function run(options) {
|
|
732
850
|
const verbose = options.verbose ?? false;
|
|
733
851
|
try {
|
|
@@ -741,20 +859,84 @@ async function run(options) {
|
|
|
741
859
|
console.error("Error: Not a git repository");
|
|
742
860
|
process.exit(1);
|
|
743
861
|
}
|
|
744
|
-
let commits;
|
|
745
|
-
let staged;
|
|
746
862
|
if (options.fromCommits) {
|
|
747
863
|
if (verbose) console.log(`Getting last ${options.fromCommits} commits...`);
|
|
748
|
-
commits = await git.getRecentCommits(options.fromCommits);
|
|
864
|
+
const commits = await git.getRecentCommits(options.fromCommits);
|
|
749
865
|
if (commits.length === 0) {
|
|
750
866
|
console.log("No commits found.");
|
|
751
867
|
process.exit(0);
|
|
752
868
|
}
|
|
753
869
|
if (verbose) console.log(`Found ${commits.length} commits`);
|
|
754
|
-
|
|
870
|
+
const groupedByDate = groupCommitsByDate(commits);
|
|
871
|
+
const sortedDates = [...groupedByDate.keys()].sort();
|
|
872
|
+
if (verbose) {
|
|
873
|
+
console.log(`Grouped into ${sortedDates.length} date(s):`);
|
|
874
|
+
for (const date of sortedDates) {
|
|
875
|
+
const dateCommits = groupedByDate.get(date);
|
|
876
|
+
console.log(` ${date}: ${dateCommits.length} commit(s)`);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
const baseVersion = getBaseVersion();
|
|
880
|
+
if (verbose) console.log(`Base version: ${baseVersion}`);
|
|
881
|
+
const entries = [];
|
|
882
|
+
const emptyStaged = { files: [], diff: "" };
|
|
883
|
+
for (let i = 0; i < sortedDates.length; i++) {
|
|
884
|
+
const date = sortedDates[i];
|
|
885
|
+
const dateCommits = groupedByDate.get(date);
|
|
886
|
+
const version = incrementMinorVersion(baseVersion, i + 1);
|
|
887
|
+
if (verbose) console.log(`
|
|
888
|
+
Generating changelog for ${date} (${version})...`);
|
|
889
|
+
console.log(`Generating changelog for ${date}...`);
|
|
890
|
+
const generated = await ai.generateChangelog(dateCommits, emptyStaged);
|
|
891
|
+
if (generated.sections.length === 0) {
|
|
892
|
+
if (verbose) console.log(` No entries generated for ${date}, skipping.`);
|
|
893
|
+
continue;
|
|
894
|
+
}
|
|
895
|
+
if (verbose) {
|
|
896
|
+
console.log(` Generated sections for ${date}:`);
|
|
897
|
+
for (const section of generated.sections) {
|
|
898
|
+
console.log(` ${section.type}:`);
|
|
899
|
+
for (const item of section.items) {
|
|
900
|
+
console.log(` - ${item}`);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
entries.push({ version, date, generated });
|
|
905
|
+
}
|
|
906
|
+
if (entries.length === 0) {
|
|
907
|
+
console.log("No changelog entries generated.");
|
|
908
|
+
process.exit(0);
|
|
909
|
+
}
|
|
910
|
+
entries.reverse();
|
|
911
|
+
if (options.dryRun) {
|
|
912
|
+
console.log("\n--- DRY RUN ---");
|
|
913
|
+
console.log("Would update changelog at:", changelog.getFilePath());
|
|
914
|
+
if (changelog.getJsonFilePath()) {
|
|
915
|
+
console.log("Would update JSON at:", changelog.getJsonFilePath());
|
|
916
|
+
}
|
|
917
|
+
console.log(`
|
|
918
|
+
--- ${entries.length} new entries (newest first) ---
|
|
919
|
+
`);
|
|
920
|
+
console.log(changelog.formatMultipleEntries(entries));
|
|
921
|
+
console.log("\n--- JSON releases ---");
|
|
922
|
+
for (const entry of entries) {
|
|
923
|
+
console.log(JSON.stringify({ version: entry.version, date: entry.date }, null, 2));
|
|
924
|
+
}
|
|
925
|
+
console.log("--- End ---\n");
|
|
926
|
+
process.exit(0);
|
|
927
|
+
}
|
|
928
|
+
const newContent = changelog.updateWithMultipleEntries(entries);
|
|
929
|
+
changelog.write(newContent);
|
|
930
|
+
console.log(`Updated: ${changelog.getFilePath()}`);
|
|
931
|
+
if (changelog.getJsonFilePath()) {
|
|
932
|
+
const jsonData = changelog.updateJsonWithMultipleEntries(entries);
|
|
933
|
+
changelog.writeJson(jsonData);
|
|
934
|
+
console.log(`Updated: ${changelog.getJsonFilePath()}`);
|
|
935
|
+
}
|
|
936
|
+
console.log(`Done! Created ${entries.length} version entries.`);
|
|
755
937
|
} else {
|
|
756
938
|
if (verbose) console.log("Getting staged changes...");
|
|
757
|
-
staged = await git.getStagedChanges();
|
|
939
|
+
const staged = await git.getStagedChanges();
|
|
758
940
|
if (staged.files.length === 0) {
|
|
759
941
|
console.log("No staged changes found. Stage some changes first.");
|
|
760
942
|
process.exit(0);
|
|
@@ -764,69 +946,65 @@ async function run(options) {
|
|
|
764
946
|
console.log(`Diff length: ${staged.diff.length} chars`);
|
|
765
947
|
}
|
|
766
948
|
if (verbose) console.log("Getting recent commits...");
|
|
767
|
-
commits = await git.getUnmergedCommits();
|
|
949
|
+
const commits = await git.getUnmergedCommits();
|
|
768
950
|
if (verbose) console.log(`Found ${commits.length} unmerged commits`);
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
951
|
+
console.log("Generating changelog with AI...");
|
|
952
|
+
const generated = await ai.generateChangelog(commits, staged);
|
|
953
|
+
if (generated.sections.length === 0) {
|
|
954
|
+
console.log("No changelog entries generated.");
|
|
955
|
+
if (verbose) console.log("Raw AI response:", generated.raw);
|
|
956
|
+
process.exit(0);
|
|
957
|
+
}
|
|
958
|
+
if (verbose) {
|
|
959
|
+
console.log("Generated sections:");
|
|
960
|
+
for (const section of generated.sections) {
|
|
961
|
+
console.log(` ${section.type}:`);
|
|
962
|
+
for (const item of section.items) {
|
|
963
|
+
console.log(` - ${item}`);
|
|
964
|
+
}
|
|
783
965
|
}
|
|
784
966
|
}
|
|
785
|
-
}
|
|
786
|
-
let metadata = { timestamp: /* @__PURE__ */ new Date() };
|
|
787
|
-
if (!options.fromCommits) {
|
|
788
967
|
const [author, commitHash] = await Promise.all([
|
|
789
968
|
git.getCurrentUser(),
|
|
790
969
|
git.getHeadCommit()
|
|
791
970
|
]);
|
|
792
|
-
metadata = {
|
|
971
|
+
const metadata = {
|
|
793
972
|
author: author || void 0,
|
|
794
973
|
commitHash: commitHash || void 0,
|
|
795
974
|
timestamp: /* @__PURE__ */ new Date()
|
|
796
975
|
};
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
976
|
+
if (verbose) {
|
|
977
|
+
console.log("Metadata:", metadata);
|
|
978
|
+
}
|
|
979
|
+
const version = options.version;
|
|
980
|
+
const newContent = changelog.update(generated, version, metadata);
|
|
981
|
+
const jsonData = changelog.updateJson(generated, version, metadata);
|
|
982
|
+
if (options.dryRun) {
|
|
983
|
+
console.log("\n--- DRY RUN ---");
|
|
984
|
+
console.log("Would update changelog at:", changelog.getFilePath());
|
|
985
|
+
if (changelog.getJsonFilePath()) {
|
|
986
|
+
console.log("Would update JSON at:", changelog.getJsonFilePath());
|
|
987
|
+
}
|
|
988
|
+
console.log("\n--- New MD entry ---");
|
|
989
|
+
console.log(changelog.formatEntry(generated, version, metadata));
|
|
990
|
+
console.log("\n--- New JSON entry ---");
|
|
991
|
+
console.log(JSON.stringify(jsonData.releases[0], null, 2));
|
|
992
|
+
console.log("--- End ---\n");
|
|
993
|
+
process.exit(0);
|
|
994
|
+
}
|
|
995
|
+
changelog.write(newContent);
|
|
996
|
+
console.log(`Updated: ${changelog.getFilePath()}`);
|
|
806
997
|
if (changelog.getJsonFilePath()) {
|
|
807
|
-
|
|
998
|
+
changelog.writeJson(jsonData);
|
|
999
|
+
console.log(`Updated: ${changelog.getJsonFilePath()}`);
|
|
808
1000
|
}
|
|
809
|
-
console.log("\n--- New MD entry ---");
|
|
810
|
-
console.log(changelog.formatEntry(generated, void 0, metadata));
|
|
811
|
-
console.log("\n--- New JSON entry ---");
|
|
812
|
-
console.log(JSON.stringify(jsonData.releases[0], null, 2));
|
|
813
|
-
console.log("--- End ---\n");
|
|
814
|
-
process.exit(0);
|
|
815
|
-
}
|
|
816
|
-
changelog.write(newContent);
|
|
817
|
-
console.log(`Updated: ${changelog.getFilePath()}`);
|
|
818
|
-
if (changelog.getJsonFilePath()) {
|
|
819
|
-
changelog.writeJson(jsonData);
|
|
820
|
-
console.log(`Updated: ${changelog.getJsonFilePath()}`);
|
|
821
|
-
}
|
|
822
|
-
if (!options.fromCommits) {
|
|
823
1001
|
await git.stageFile(config.changelog.file);
|
|
824
1002
|
if (config.changelog.jsonFile) {
|
|
825
1003
|
await git.stageFile(config.changelog.jsonFile);
|
|
826
1004
|
}
|
|
827
1005
|
console.log("Staged changelog files");
|
|
1006
|
+
console.log("Done!");
|
|
828
1007
|
}
|
|
829
|
-
console.log("Done!");
|
|
830
1008
|
} catch (error) {
|
|
831
1009
|
console.error("Error:", error instanceof Error ? error.message : error);
|
|
832
1010
|
if (verbose && error instanceof Error) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/config.ts","../src/git.ts","../src/ai.ts","../src/changelog.ts"],"sourcesContent":["import 'dotenv/config';\nimport { Command } from 'commander';\nimport { readFileSync } from 'node:fs';\nimport { fileURLToPath } from 'node:url';\nimport { dirname, resolve } from 'node:path';\nimport { loadConfig, initConfig } from './config.js';\nimport { GitService } from './git.js';\nimport { AIService } from './ai.js';\nimport { ChangelogService } from './changelog.js';\nimport type { CLIOptions, ChangelogMetadata } from './types.js';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\nconst pkg = JSON.parse(readFileSync(resolve(__dirname, '../package.json'), 'utf-8'));\n\nconst program = new Command();\n\nprogram\n .name('tst-changelog')\n .description('AI-powered changelog generator using OpenRouter')\n .version(pkg.version);\n\nprogram\n .command('init')\n .description('Create a default configuration file')\n .option('-f, --file <name>', 'Config file name', 'tst-changelog.yaml')\n .action((options: { file: string }) => {\n try {\n const result = initConfig(options.file);\n console.log(`Created config file: ${result.configPath}`);\n\n if (result.huskyConfigured) {\n console.log(`Configured husky hook: ${result.huskyHook}`);\n }\n\n console.log('\\nNext steps:');\n console.log('1. Set the OPENROUTER_API_KEY environment variable');\n console.log('2. Adjust settings in the config file as needed');\n if (!result.huskyConfigured) {\n console.log('3. Run: npx tst-changelog generate');\n }\n } catch (error) {\n console.error('Error:', error instanceof Error ? error.message : error);\n process.exit(1);\n }\n });\n\nprogram\n .command('generate', { isDefault: true })\n .description('Generate changelog from staged changes or commit history')\n .option('-c, --config <path>', 'Path to config file')\n .option('-d, --dry-run', 'Preview without modifying files')\n .option('-v, --verbose', 'Enable verbose output')\n .option('--from-commits <count>', 'Generate from last N commits instead of staged changes', parseInt)\n .action(run);\n\nasync function run(options: CLIOptions): Promise<void> {\n const verbose = options.verbose ?? false;\n\n try {\n // Load configuration\n if (verbose) console.log('Loading configuration...');\n const config = loadConfig(options.config);\n if (verbose) console.log('Config loaded:', JSON.stringify(config, null, 2));\n\n // Initialize services\n const git = new GitService(config.git);\n const ai = new AIService(config.ai);\n const changelog = new ChangelogService(config.changelog);\n\n // Check if we're in a git repo\n if (!(await git.isGitRepo())) {\n console.error('Error: Not a git repository');\n process.exit(1);\n }\n\n let commits;\n let staged;\n\n if (options.fromCommits) {\n // Generate from commit history\n if (verbose) console.log(`Getting last ${options.fromCommits} commits...`);\n commits = await git.getRecentCommits(options.fromCommits);\n\n if (commits.length === 0) {\n console.log('No commits found.');\n process.exit(0);\n }\n\n if (verbose) console.log(`Found ${commits.length} commits`);\n\n // Empty staged for history mode\n staged = { files: [], diff: '' };\n } else {\n // Get staged changes (default behavior)\n if (verbose) console.log('Getting staged changes...');\n staged = await git.getStagedChanges();\n\n if (staged.files.length === 0) {\n console.log('No staged changes found. Stage some changes first.');\n process.exit(0);\n }\n\n if (verbose) {\n console.log(`Staged files: ${staged.files.join(', ')}`);\n console.log(`Diff length: ${staged.diff.length} chars`);\n }\n\n // Get recent commits for context\n if (verbose) console.log('Getting recent commits...');\n commits = await git.getUnmergedCommits();\n if (verbose) console.log(`Found ${commits.length} unmerged commits`);\n }\n\n // Generate changelog using AI\n console.log('Generating changelog with AI...');\n const generated = await ai.generateChangelog(commits, staged);\n\n if (generated.sections.length === 0) {\n console.log('No changelog entries generated.');\n if (verbose) console.log('Raw AI response:', generated.raw);\n process.exit(0);\n }\n\n if (verbose) {\n console.log('Generated sections:');\n for (const section of generated.sections) {\n console.log(` ${section.type}:`);\n for (const item of section.items) {\n console.log(` - ${item}`);\n }\n }\n }\n\n // Collect metadata for changelog entry\n // Skip author/commit for --from-commits mode since it covers multiple commits\n let metadata: ChangelogMetadata = { timestamp: new Date() };\n\n if (!options.fromCommits) {\n const [author, commitHash] = await Promise.all([\n git.getCurrentUser(),\n git.getHeadCommit(),\n ]);\n metadata = {\n author: author || undefined,\n commitHash: commitHash || undefined,\n timestamp: new Date(),\n };\n }\n\n if (verbose) {\n console.log('Metadata:', metadata);\n }\n\n // Update changelog (MD)\n const newContent = changelog.update(generated, undefined, metadata);\n\n // Update changelog (JSON)\n const jsonData = changelog.updateJson(generated, undefined, metadata);\n\n if (options.dryRun) {\n console.log('\\n--- DRY RUN ---');\n console.log('Would update changelog at:', changelog.getFilePath());\n if (changelog.getJsonFilePath()) {\n console.log('Would update JSON at:', changelog.getJsonFilePath());\n }\n console.log('\\n--- New MD entry ---');\n console.log(changelog.formatEntry(generated, undefined, metadata));\n console.log('\\n--- New JSON entry ---');\n console.log(JSON.stringify(jsonData.releases[0], null, 2));\n console.log('--- End ---\\n');\n process.exit(0);\n }\n\n // Write changelog (MD)\n changelog.write(newContent);\n console.log(`Updated: ${changelog.getFilePath()}`);\n\n // Write changelog (JSON)\n if (changelog.getJsonFilePath()) {\n changelog.writeJson(jsonData);\n console.log(`Updated: ${changelog.getJsonFilePath()}`);\n }\n\n // Only auto-stage when using staged changes mode (not --from-commits)\n if (!options.fromCommits) {\n await git.stageFile(config.changelog.file);\n if (config.changelog.jsonFile) {\n await git.stageFile(config.changelog.jsonFile);\n }\n console.log('Staged changelog files');\n }\n\n console.log('Done!');\n } catch (error) {\n console.error('Error:', error instanceof Error ? error.message : error);\n if (verbose && error instanceof Error) {\n console.error(error.stack);\n }\n process.exit(1);\n }\n}\n\nprogram.parse();\n\n// Export for programmatic usage\nexport { loadConfig, initConfig, type InitResult } from './config.js';\nexport { GitService } from './git.js';\nexport { AIService } from './ai.js';\nexport { ChangelogService } from './changelog.js';\nexport * from './types.js';\n","import { readFileSync, existsSync, writeFileSync, appendFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { parse, stringify } from 'yaml';\nimport type { Config } from './types.js';\n\nconst DEFAULT_PROMPT = `You are a changelog generator. Your task is to analyze git commits and staged changes to generate changelog entries following the Keep a Changelog format.\n\nOutput Format:\nReturn ONLY a JSON object with the following structure:\n{\n \"sections\": [\n {\n \"type\": \"Added\" | \"Changed\" | \"Deprecated\" | \"Removed\" | \"Fixed\" | \"Security\",\n \"items\": [\"description (by Author, YYYY-MM-DD HH:MM, hash)\", \"description 2 (by Author, YYYY-MM-DD HH:MM, hash)\"]\n }\n ]\n}\n\nGuidelines:\n- Use present tense (e.g., \"Add feature\" not \"Added feature\")\n- Be concise but descriptive\n- Group related changes together\n- Focus on user-facing changes\n- Ignore merge commits and trivial changes\n- IMPORTANT: Each item MUST include author, datetime, and commit hash from the input in the format: \"description (by Author, YYYY-MM-DD HH:MM, hash)\"\n- If multiple commits contribute to the same change, list them: \"description (by Author1, datetime1, hash1; Author2, datetime2, hash2)\"\n- Parse conventional commits (feat:, fix:, etc.) into appropriate sections:\n - feat: -> Added\n - fix: -> Fixed\n - docs:, style:, refactor:, perf:, test:, chore: -> Changed\n - BREAKING CHANGE: -> Changed (mention breaking)\n - deprecate: -> Deprecated\n - remove: -> Removed\n - security: -> Security`;\n\nconst DEFAULT_CONFIG: Config = {\n ai: {\n provider: 'openrouter',\n model: 'anthropic/claude-sonnet-4.5',\n token: '${OPENROUTER_API_KEY}',\n prompt: DEFAULT_PROMPT,\n },\n changelog: {\n file: 'CHANGELOG.md',\n jsonFile: 'changelog.json',\n format: 'keepachangelog',\n includeDate: true,\n includeTime: true,\n includeAuthor: true,\n includeCommitLink: true,\n repoUrl: '',\n groupBy: 'type',\n },\n git: {\n baseBranch: 'main',\n analyzeDepth: 50,\n },\n};\n\n/**\n * Resolve environment variables in config values\n * Supports ${ENV_VAR} syntax\n */\nfunction resolveEnvVars(value: string): string {\n return value.replace(/\\$\\{([^}]+)\\}/g, (_, envVar) => {\n const envValue = process.env[envVar];\n if (!envValue) {\n throw new Error(`Environment variable ${envVar} is not set`);\n }\n return envValue;\n });\n}\n\n/**\n * Recursively resolve env vars in object\n */\nfunction resolveConfigEnvVars<T>(obj: T): T {\n if (typeof obj === 'string') {\n return resolveEnvVars(obj) as T;\n }\n if (Array.isArray(obj)) {\n return obj.map(resolveConfigEnvVars) as T;\n }\n if (obj && typeof obj === 'object') {\n const resolved: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n resolved[key] = resolveConfigEnvVars(value);\n }\n return resolved as T;\n }\n return obj;\n}\n\n/**\n * Deep merge two objects\n */\nfunction deepMerge(target: Config, source: Partial<Config>): Config {\n return {\n ai: { ...target.ai, ...source.ai },\n changelog: { ...target.changelog, ...source.changelog },\n git: { ...target.git, ...source.git },\n };\n}\n\n/**\n * Load configuration from yaml file\n */\nexport function loadConfig(configPath?: string): Config {\n const defaultPaths = ['tst-changelog.yaml', 'tst-changelog.yml', '.tst-changelog.yaml'];\n\n let filePath: string | undefined;\n\n if (configPath) {\n filePath = resolve(process.cwd(), configPath);\n if (!existsSync(filePath)) {\n throw new Error(`Config file not found: ${filePath}`);\n }\n } else {\n for (const p of defaultPaths) {\n const fullPath = resolve(process.cwd(), p);\n if (existsSync(fullPath)) {\n filePath = fullPath;\n break;\n }\n }\n }\n\n if (!filePath) {\n return resolveConfigEnvVars(DEFAULT_CONFIG);\n }\n\n const content = readFileSync(filePath, 'utf-8');\n const parsed = parse(content) as Partial<Config>;\n\n const merged = deepMerge(DEFAULT_CONFIG, parsed);\n return resolveConfigEnvVars(merged);\n}\n\nexport interface InitResult {\n configPath: string;\n huskyConfigured: boolean;\n huskyHook?: string;\n}\n\n/**\n * Initialize a new config file with defaults\n */\nexport function initConfig(fileName = 'tst-changelog.yaml'): InitResult {\n const filePath = resolve(process.cwd(), fileName);\n\n if (existsSync(filePath)) {\n throw new Error(`Config file already exists: ${filePath}`);\n }\n\n const configTemplate: Config = {\n ai: {\n provider: 'openrouter',\n model: 'anthropic/claude-sonnet-4.5',\n token: '${OPENROUTER_API_KEY}',\n prompt: DEFAULT_PROMPT,\n },\n changelog: {\n file: 'CHANGELOG.md',\n jsonFile: 'changelog.json',\n format: 'keepachangelog',\n includeDate: true,\n includeTime: true,\n includeAuthor: true,\n includeCommitLink: true,\n repoUrl: '',\n groupBy: 'type',\n },\n git: {\n baseBranch: 'main',\n analyzeDepth: 50,\n },\n };\n\n const content = stringify(configTemplate, { lineWidth: 0 });\n writeFileSync(filePath, content, 'utf-8');\n\n // Check for husky and configure hook\n const huskyResult = configureHusky();\n\n return {\n configPath: filePath,\n ...huskyResult,\n };\n}\n\n/**\n * Configure husky pre-commit hook if husky is present\n */\nfunction configureHusky(): { huskyConfigured: boolean; huskyHook?: string } {\n const huskyDir = resolve(process.cwd(), '.husky');\n\n if (!existsSync(huskyDir)) {\n return { huskyConfigured: false };\n }\n\n const preCommitPath = resolve(huskyDir, 'pre-commit');\n const commands = `npx tst-changelog generate\ngit add CHANGELOG.md changelog.json 2>/dev/null || true`;\n\n // Check if hook already exists\n if (existsSync(preCommitPath)) {\n const content = readFileSync(preCommitPath, 'utf-8');\n if (content.includes('tst-changelog')) {\n return { huskyConfigured: false }; // Already configured\n }\n // Append to existing hook\n appendFileSync(preCommitPath, `\\n${commands}\\n`);\n } else {\n // Create new hook\n writeFileSync(preCommitPath, `#!/usr/bin/env sh\\n. \"$(dirname -- \"$0\")/_/husky.sh\"\\n\\n${commands}\\n`, { mode: 0o755 });\n }\n\n return { huskyConfigured: true, huskyHook: preCommitPath };\n}\n","import simpleGit, { SimpleGit } from 'simple-git';\nimport type { CommitInfo, StagedChanges, GitConfig } from './types.js';\n\nexport class GitService {\n private git: SimpleGit;\n private config: GitConfig;\n\n constructor(config: GitConfig, cwd?: string) {\n this.git = simpleGit(cwd);\n this.config = config;\n }\n\n /**\n * Get list of staged files\n */\n async getStagedFiles(): Promise<string[]> {\n const status = await this.git.status();\n return status.staged;\n }\n\n /**\n * Get diff of staged changes\n */\n async getStagedDiff(): Promise<string> {\n const diff = await this.git.diff(['--cached']);\n return diff;\n }\n\n /**\n * Get staged changes (files + diff)\n */\n async getStagedChanges(): Promise<StagedChanges> {\n const [files, diff] = await Promise.all([\n this.getStagedFiles(),\n this.getStagedDiff(),\n ]);\n return { files, diff };\n }\n\n /**\n * Get recent commits from the base branch\n */\n async getRecentCommits(count?: number): Promise<CommitInfo[]> {\n const limit = count ?? this.config.analyzeDepth;\n const log = await this.git.log({\n maxCount: limit,\n format: {\n hash: '%H',\n message: '%s',\n author: '%an',\n date: '%aI',\n body: '%b',\n },\n });\n\n return log.all.map((commit) => ({\n hash: commit.hash,\n message: commit.message,\n author: commit.author,\n date: commit.date,\n body: commit.body?.trim() || undefined,\n }));\n }\n\n /**\n * Get commits not yet in base branch (for feature branches)\n */\n async getUnmergedCommits(): Promise<CommitInfo[]> {\n try {\n const log = await this.git.log({\n from: this.config.baseBranch,\n to: 'HEAD',\n format: {\n hash: '%H',\n message: '%s',\n author: '%an',\n date: '%aI',\n body: '%b',\n },\n });\n\n return log.all.map((commit) => ({\n hash: commit.hash,\n message: commit.message,\n author: commit.author,\n date: commit.date,\n body: commit.body?.trim() || undefined,\n }));\n } catch {\n // If base branch doesn't exist, return empty\n return [];\n }\n }\n\n /**\n * Get current branch name\n */\n async getCurrentBranch(): Promise<string> {\n const branch = await this.git.revparse(['--abbrev-ref', 'HEAD']);\n return branch.trim();\n }\n\n /**\n * Stage a file\n */\n async stageFile(filePath: string): Promise<void> {\n await this.git.add(filePath);\n }\n\n /**\n * Check if we're in a git repository\n */\n async isGitRepo(): Promise<boolean> {\n try {\n await this.git.revparse(['--git-dir']);\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * Get current git user name\n */\n async getCurrentUser(): Promise<string> {\n try {\n const name = await this.git.getConfig('user.name');\n return name.value ?? '';\n } catch {\n return '';\n }\n }\n\n /**\n * Get HEAD commit hash\n */\n async getHeadCommit(): Promise<string> {\n try {\n const hash = await this.git.revparse(['HEAD']);\n return hash.trim();\n } catch {\n return '';\n }\n }\n}\n","import type { AIConfig, CommitInfo, StagedChanges, GeneratedChangelog, ChangelogSection, ChangeType } from './types.js';\n\nconst OPENROUTER_API_URL = 'https://openrouter.ai/api/v1/chat/completions';\n\ninterface OpenRouterResponse {\n choices: Array<{\n message: {\n content: string;\n };\n }>;\n}\n\nexport class AIService {\n private config: AIConfig;\n\n constructor(config: AIConfig) {\n this.config = config;\n }\n\n /**\n * Generate changelog entries from commits and staged changes\n */\n async generateChangelog(\n commits: CommitInfo[],\n staged: StagedChanges\n ): Promise<GeneratedChangelog> {\n const userPrompt = this.buildPrompt(commits, staged);\n const response = await this.callOpenRouter(userPrompt);\n return this.parseResponse(response);\n }\n\n private buildPrompt(commits: CommitInfo[], staged: StagedChanges): string {\n const parts: string[] = [];\n\n if (commits.length > 0) {\n parts.push('## Recent Commits:');\n for (const commit of commits) {\n const shortHash = commit.hash.slice(0, 7);\n const [date, timePart] = commit.date.split('T');\n const time = timePart?.slice(0, 5) ?? ''; // HH:MM\n const datetime = time ? `${date} ${time}` : date;\n parts.push(`- [${shortHash}] (${commit.author}, ${datetime}) ${commit.message}`);\n if (commit.body) {\n parts.push(` ${commit.body}`);\n }\n }\n }\n\n if (staged.files.length > 0) {\n parts.push('\\n## Staged Files:');\n parts.push(staged.files.join('\\n'));\n }\n\n if (staged.diff) {\n // Limit diff size to avoid token limits\n const maxDiffLength = 4000;\n const truncatedDiff = staged.diff.length > maxDiffLength\n ? staged.diff.slice(0, maxDiffLength) + '\\n... (truncated)'\n : staged.diff;\n parts.push('\\n## Staged Diff:');\n parts.push('```diff');\n parts.push(truncatedDiff);\n parts.push('```');\n }\n\n parts.push('\\nGenerate changelog entries for these changes.');\n\n return parts.join('\\n');\n }\n\n private async callOpenRouter(prompt: string): Promise<string> {\n const response = await fetch(OPENROUTER_API_URL, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${this.config.token}`,\n 'HTTP-Referer': 'https://github.com/testudosrl/tst-libs',\n 'X-Title': 'tst-changelog',\n },\n body: JSON.stringify({\n model: this.config.model,\n messages: [\n { role: 'system', content: this.config.prompt ?? '' },\n { role: 'user', content: prompt },\n ],\n temperature: 0.3,\n max_tokens: 4000,\n }),\n });\n\n if (!response.ok) {\n const error = await response.text();\n throw new Error(`OpenRouter API error: ${response.status} - ${error}`);\n }\n\n const data = (await response.json()) as OpenRouterResponse;\n return data.choices[0]?.message?.content ?? '';\n }\n\n private parseResponse(response: string): GeneratedChangelog {\n try {\n // Extract JSON from response (handle markdown code blocks or raw JSON)\n let jsonStr = response;\n\n // Try markdown code block first\n const codeBlockMatch = response.match(/```(?:json)?\\s*([\\s\\S]*?)```/);\n if (codeBlockMatch) {\n jsonStr = codeBlockMatch[1];\n } else {\n // Try to find JSON object in the response\n const jsonObjectMatch = response.match(/\\{[\\s\\S]*\"sections\"[\\s\\S]*\\}/);\n if (jsonObjectMatch) {\n jsonStr = jsonObjectMatch[0];\n }\n }\n\n const parsed = JSON.parse(jsonStr.trim()) as { sections: ChangelogSection[] };\n\n // Validate and normalize sections\n const validTypes: ChangeType[] = ['Added', 'Changed', 'Deprecated', 'Removed', 'Fixed', 'Security'];\n const sections = parsed.sections\n .filter((s) => validTypes.includes(s.type))\n .map((s) => ({\n type: s.type,\n items: Array.isArray(s.items) ? s.items.filter((i) => typeof i === 'string') : [],\n }))\n .filter((s) => s.items.length > 0);\n\n return {\n raw: response,\n sections,\n };\n } catch (error) {\n console.error('Failed to parse AI response:', error);\n console.error('Raw response:', response);\n return {\n raw: response,\n sections: [],\n };\n }\n }\n}\n","import { readFileSync, writeFileSync, existsSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport type { ChangelogConfig, ChangelogSection, GeneratedChangelog, ChangelogMetadata, ChangelogJson, ChangelogJsonRelease } from './types.js';\n\nconst KEEPACHANGELOG_HEADER = `# Changelog\n\nAll notable changes to this project will be documented in this file.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),\nand this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n`;\n\nconst SECTION_ORDER = ['Added', 'Changed', 'Deprecated', 'Removed', 'Fixed', 'Security'] as const;\n\nexport class ChangelogService {\n private config: ChangelogConfig;\n private filePath: string;\n\n constructor(config: ChangelogConfig, cwd?: string) {\n this.config = config;\n this.filePath = resolve(cwd ?? process.cwd(), config.file);\n }\n\n /**\n * Read existing changelog content\n */\n read(): string | null {\n if (!existsSync(this.filePath)) {\n return null;\n }\n return readFileSync(this.filePath, 'utf-8');\n }\n\n /**\n * Generate new changelog entry\n */\n formatEntry(generated: GeneratedChangelog, version?: string, metadata?: ChangelogMetadata): string {\n const versionStr = version ?? 'Unreleased';\n const headerParts: string[] = [`## [${versionStr}]`];\n\n // Date and time\n if (this.config.includeDate) {\n const now = metadata?.timestamp ?? new Date();\n let dateStr = now.toISOString().split('T')[0];\n if (this.config.includeTime) {\n const timeStr = now.toTimeString().split(' ')[0].slice(0, 5); // HH:MM\n dateStr += ` ${timeStr}`;\n }\n headerParts.push(`- ${dateStr}`);\n }\n\n // Author\n if (this.config.includeAuthor && metadata?.author) {\n headerParts.push(`by ${metadata.author}`);\n }\n\n // Commit link\n if (this.config.includeCommitLink && metadata?.commitHash) {\n const shortHash = metadata.commitHash.slice(0, 7);\n if (this.config.repoUrl) {\n const commitUrl = `${this.config.repoUrl.replace(/\\/$/, '')}/commit/${metadata.commitHash}`;\n headerParts.push(`([${shortHash}](${commitUrl}))`);\n } else {\n headerParts.push(`(${shortHash})`);\n }\n }\n\n const headerLine = headerParts.join(' ');\n\n const sections = this.sortSections(generated.sections);\n const sectionLines = sections\n .map((section) => this.formatSection(section))\n .join('\\n\\n');\n\n return `${headerLine}\\n\\n${sectionLines}`;\n }\n\n private sortSections(sections: ChangelogSection[]): ChangelogSection[] {\n return [...sections].sort((a, b) => {\n const indexA = SECTION_ORDER.indexOf(a.type as typeof SECTION_ORDER[number]);\n const indexB = SECTION_ORDER.indexOf(b.type as typeof SECTION_ORDER[number]);\n return indexA - indexB;\n });\n }\n\n private formatSection(section: ChangelogSection): string {\n const items = section.items.map((item) => `- ${this.formatItemWithLinks(item)}`).join('\\n');\n return `### ${section.type}\\n\\n${items}`;\n }\n\n /**\n * Convert commit hashes in item to markdown links if repoUrl is configured\n */\n private formatItemWithLinks(item: string): string {\n if (!this.config.repoUrl) return item;\n\n const repoUrl = this.config.repoUrl.replace(/\\/$/, '');\n\n // Match patterns like \"abc1234\" or \"abc1234; def5678\" at the end of parentheses\n // Pattern: 7-char hex hash\n return item.replace(/\\b([a-f0-9]{7})\\b/g, (match) => {\n return `[${match}](${repoUrl}/commit/${match})`;\n });\n }\n\n /**\n * Update or create changelog with new entry\n */\n update(generated: GeneratedChangelog, version?: string, metadata?: ChangelogMetadata): string {\n const existing = this.read();\n\n if (!existing) {\n // Create new changelog\n const newEntry = this.formatEntry(generated, version, metadata);\n return KEEPACHANGELOG_HEADER + newEntry + '\\n';\n }\n\n // Find where to insert new entry (after header, before first version)\n const lines = existing.split('\\n');\n let insertIndex = -1;\n\n // Look for ## [Unreleased] or first ## [ section\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (line.startsWith('## [Unreleased]')) {\n // Merge with existing unreleased section\n const endIndex = this.findSectionEnd(lines, i + 1);\n const existingSectionLines = lines.slice(i, endIndex);\n const mergedSection = this.mergeUnreleasedSection(existingSectionLines, generated, metadata);\n const before = lines.slice(0, i).join('\\n');\n const after = lines.slice(endIndex).join('\\n');\n return before + (before.endsWith('\\n') ? '' : '\\n') + mergedSection + '\\n' + after;\n }\n if (line.startsWith('## [') && insertIndex === -1) {\n insertIndex = i;\n break;\n }\n }\n\n const newEntry = this.formatEntry(generated, version, metadata);\n\n if (insertIndex === -1) {\n // No version sections found, append after header\n return existing.trimEnd() + '\\n\\n' + newEntry + '\\n';\n }\n\n // Insert before first version\n const before = lines.slice(0, insertIndex).join('\\n');\n const after = lines.slice(insertIndex).join('\\n');\n return before + (before.endsWith('\\n') ? '' : '\\n') + newEntry + '\\n\\n' + after;\n }\n\n /**\n * Merge new entries into existing Unreleased section\n */\n private mergeUnreleasedSection(\n existingLines: string[],\n generated: GeneratedChangelog,\n metadata?: ChangelogMetadata\n ): string {\n // Parse existing sections\n const existingSections: Map<string, string[]> = new Map();\n let currentSection: string | null = null;\n\n for (const line of existingLines) {\n if (line.startsWith('### ')) {\n currentSection = line.slice(4).trim();\n if (!existingSections.has(currentSection)) {\n existingSections.set(currentSection, []);\n }\n } else if (currentSection && line.startsWith('- ')) {\n existingSections.get(currentSection)!.push(line.slice(2));\n }\n }\n\n // Merge new sections\n for (const section of generated.sections) {\n const existing = existingSections.get(section.type) ?? [];\n // Add new items that don't already exist\n for (const item of section.items) {\n if (!existing.includes(item)) {\n existing.push(item);\n }\n }\n existingSections.set(section.type, existing);\n }\n\n // Build merged entry\n const versionStr = 'Unreleased';\n const headerParts: string[] = [`## [${versionStr}]`];\n\n if (this.config.includeDate) {\n const now = metadata?.timestamp ?? new Date();\n let dateStr = now.toISOString().split('T')[0];\n if (this.config.includeTime) {\n const timeStr = now.toTimeString().split(' ')[0].slice(0, 5);\n dateStr += ` ${timeStr}`;\n }\n headerParts.push(`- ${dateStr}`);\n }\n\n if (this.config.includeAuthor && metadata?.author) {\n headerParts.push(`by ${metadata.author}`);\n }\n\n if (this.config.includeCommitLink && metadata?.commitHash) {\n const shortHash = metadata.commitHash.slice(0, 7);\n if (this.config.repoUrl) {\n const commitUrl = `${this.config.repoUrl.replace(/\\/$/, '')}/commit/${metadata.commitHash}`;\n headerParts.push(`([${shortHash}](${commitUrl}))`);\n } else {\n headerParts.push(`(${shortHash})`);\n }\n }\n\n const headerLine = headerParts.join(' ');\n\n // Sort and format sections\n const sortedSections: ChangelogSection[] = [];\n for (const type of SECTION_ORDER) {\n const items = existingSections.get(type);\n if (items && items.length > 0) {\n sortedSections.push({ type, items });\n }\n }\n\n const sectionLines = sortedSections\n .map((section) => this.formatSection(section))\n .join('\\n\\n');\n\n return `${headerLine}\\n\\n${sectionLines}`;\n }\n\n private findSectionEnd(lines: string[], startIndex: number): number {\n for (let i = startIndex; i < lines.length; i++) {\n if (lines[i].startsWith('## [')) {\n return i;\n }\n }\n return lines.length;\n }\n\n /**\n * Write changelog to file\n */\n write(content: string): void {\n writeFileSync(this.filePath, content, 'utf-8');\n }\n\n /**\n * Get the file path\n */\n getFilePath(): string {\n return this.filePath;\n }\n\n /**\n * Get JSON file path if configured\n */\n getJsonFilePath(): string | null {\n if (!this.config.jsonFile) return null;\n return resolve(process.cwd(), this.config.jsonFile);\n }\n\n /**\n * Read existing JSON changelog\n */\n readJson(): ChangelogJson | null {\n const jsonPath = this.getJsonFilePath();\n if (!jsonPath || !existsSync(jsonPath)) {\n return null;\n }\n try {\n const content = readFileSync(jsonPath, 'utf-8');\n return JSON.parse(content) as ChangelogJson;\n } catch {\n return null;\n }\n }\n\n /**\n * Create a JSON release entry from generated changelog\n */\n createJsonRelease(generated: GeneratedChangelog, version?: string, metadata?: ChangelogMetadata): ChangelogJsonRelease {\n const now = metadata?.timestamp ?? new Date();\n const sections: Record<string, string[]> = {};\n\n for (const section of generated.sections) {\n sections[section.type] = section.items;\n }\n\n const release: ChangelogJsonRelease = {\n version: version ?? 'Unreleased',\n date: now.toISOString().split('T')[0],\n sections,\n };\n\n if (this.config.includeTime) {\n release.time = now.toTimeString().split(' ')[0].slice(0, 5);\n }\n\n if (this.config.includeAuthor && metadata?.author) {\n release.author = metadata.author;\n }\n\n if (this.config.includeCommitLink && metadata?.commitHash) {\n release.commitHash = metadata.commitHash;\n }\n\n return release;\n }\n\n /**\n * Update JSON changelog with new release\n */\n updateJson(generated: GeneratedChangelog, version?: string, metadata?: ChangelogMetadata): ChangelogJson {\n const newRelease = this.createJsonRelease(generated, version, metadata);\n const existing = this.readJson();\n\n if (!existing) {\n return { releases: [newRelease] };\n }\n\n // Find and merge or prepend\n const unreleasedIndex = existing.releases.findIndex(r => r.version === 'Unreleased');\n\n if (unreleasedIndex >= 0 && newRelease.version === 'Unreleased') {\n // Merge with existing unreleased\n const existingRelease = existing.releases[unreleasedIndex];\n for (const [type, items] of Object.entries(newRelease.sections)) {\n const existingItems = existingRelease.sections[type] ?? [];\n for (const item of items) {\n if (!existingItems.includes(item)) {\n existingItems.push(item);\n }\n }\n existingRelease.sections[type] = existingItems;\n }\n // Update metadata to latest\n existingRelease.date = newRelease.date;\n if (newRelease.time) existingRelease.time = newRelease.time;\n if (newRelease.author) existingRelease.author = newRelease.author;\n if (newRelease.commitHash) existingRelease.commitHash = newRelease.commitHash;\n } else {\n // Prepend new release\n existing.releases.unshift(newRelease);\n }\n\n return existing;\n }\n\n /**\n * Write JSON changelog to file\n */\n writeJson(data: ChangelogJson): void {\n const jsonPath = this.getJsonFilePath();\n if (!jsonPath) return;\n writeFileSync(jsonPath, JSON.stringify(data, null, 2), 'utf-8');\n }\n}\n"],"mappings":";;;AAAA,OAAO;AACP,SAAS,eAAe;AACxB,SAAS,gBAAAA,qBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,SAAS,WAAAC,gBAAe;;;ACJjC,SAAS,cAAc,YAAY,eAAe,sBAAsB;AACxE,SAAS,eAAe;AACxB,SAAS,OAAO,iBAAiB;AAGjC,IAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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AK;AAAA,IAC3B;AACA,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;AAEA,QAAQ,MAAM;","names":["readFileSync","resolve","readFileSync","writeFileSync","existsSync","resolve","newEntry","before","after","readFileSync","resolve"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/config.ts","../src/git.ts","../src/ai.ts","../src/changelog.ts"],"sourcesContent":["import 'dotenv/config';\nimport { Command } from 'commander';\nimport { readFileSync, existsSync } from 'node:fs';\nimport { fileURLToPath } from 'node:url';\nimport { dirname, resolve } from 'node:path';\nimport { loadConfig, initConfig } from './config.js';\nimport { GitService } from './git.js';\nimport { AIService } from './ai.js';\nimport { ChangelogService } from './changelog.js';\nimport type { CLIOptions, ChangelogMetadata, CommitInfo, DateGroupedCommits, VersionedEntry } from './types.js';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\nconst pkg = JSON.parse(readFileSync(resolve(__dirname, '../package.json'), 'utf-8'));\n\n/**\n * Read version from project's package.json and increment minor version\n * e.g., 1.2.3 -> 1.3.0\n * Falls back to the provided date if no package.json found\n */\nfunction getNextMinorVersion(fallbackDate?: string): string {\n const pkgPath = resolve(process.cwd(), 'package.json');\n\n if (!existsSync(pkgPath)) {\n return fallbackDate ?? new Date().toISOString().split('T')[0];\n }\n\n try {\n const projectPkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));\n const currentVersion = projectPkg.version ?? '0.0.0';\n const [major, minor] = currentVersion.split('.').map(Number);\n return `${major}.${(minor || 0) + 1}.0`;\n } catch {\n return fallbackDate ?? new Date().toISOString().split('T')[0];\n }\n}\n\n/**\n * Get base version from package.json (e.g., \"0.0.0\")\n */\nfunction getBaseVersion(): string {\n const pkgPath = resolve(process.cwd(), 'package.json');\n\n if (!existsSync(pkgPath)) {\n return '0.0.0';\n }\n\n try {\n const projectPkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));\n return projectPkg.version ?? '0.0.0';\n } catch {\n return '0.0.0';\n }\n}\n\n/**\n * Increment minor version from base by a given count\n * e.g., base \"0.0.0\", count 1 => \"0.1.0\"\n * base \"0.0.0\", count 3 => \"0.3.0\"\n */\nfunction incrementMinorVersion(baseVersion: string, count: number): string {\n const [major] = baseVersion.split('.').map(Number);\n return `${major}.${count}.0`;\n}\n\n/**\n * Group commits by their date (YYYY-MM-DD)\n */\nfunction groupCommitsByDate(commits: CommitInfo[]): DateGroupedCommits {\n const grouped: DateGroupedCommits = new Map();\n\n for (const commit of commits) {\n // Extract date part (YYYY-MM-DD) from ISO date string\n const date = commit.date.split('T')[0];\n\n if (!grouped.has(date)) {\n grouped.set(date, []);\n }\n grouped.get(date)!.push(commit);\n }\n\n return grouped;\n}\n\nconst program = new Command();\n\nprogram\n .name('tst-changelog')\n .description('AI-powered changelog generator using OpenRouter')\n .version(pkg.version);\n\nprogram\n .command('init')\n .description('Create a default configuration file')\n .option('-f, --file <name>', 'Config file name', 'tst-changelog.yaml')\n .action((options: { file: string }) => {\n try {\n const result = initConfig(options.file);\n console.log(`Created config file: ${result.configPath}`);\n\n if (result.huskyConfigured) {\n console.log(`Configured husky hook: ${result.huskyHook}`);\n }\n\n console.log('\\nNext steps:');\n console.log('1. Set the OPENROUTER_API_KEY environment variable');\n console.log('2. Adjust settings in the config file as needed');\n if (!result.huskyConfigured) {\n console.log('3. Run: npx tst-changelog generate');\n }\n } catch (error) {\n console.error('Error:', error instanceof Error ? error.message : error);\n process.exit(1);\n }\n });\n\nprogram\n .command('generate', { isDefault: true })\n .description('Generate changelog from staged changes or commit history')\n .option('-c, --config <path>', 'Path to config file')\n .option('-d, --dry-run', 'Preview without modifying files')\n .option('-v, --verbose', 'Enable verbose output')\n .option('--from-commits <count>', 'Generate from last N commits instead of staged changes', parseInt)\n .option('--version <version>', 'Version label for the changelog entry (default: \"Unreleased\" or date for --from-commits)')\n .action(run);\n\nasync function run(options: CLIOptions): Promise<void> {\n const verbose = options.verbose ?? false;\n\n try {\n // Load configuration\n if (verbose) console.log('Loading configuration...');\n const config = loadConfig(options.config);\n if (verbose) console.log('Config loaded:', JSON.stringify(config, null, 2));\n\n // Initialize services\n const git = new GitService(config.git);\n const ai = new AIService(config.ai);\n const changelog = new ChangelogService(config.changelog);\n\n // Check if we're in a git repo\n if (!(await git.isGitRepo())) {\n console.error('Error: Not a git repository');\n process.exit(1);\n }\n\n if (options.fromCommits) {\n // === FROM COMMITS MODE: Group by date, generate per-date entries ===\n if (verbose) console.log(`Getting last ${options.fromCommits} commits...`);\n const commits = await git.getRecentCommits(options.fromCommits);\n\n if (commits.length === 0) {\n console.log('No commits found.');\n process.exit(0);\n }\n\n if (verbose) console.log(`Found ${commits.length} commits`);\n\n // Group commits by date\n const groupedByDate = groupCommitsByDate(commits);\n const sortedDates = [...groupedByDate.keys()].sort(); // ascending (oldest first)\n\n if (verbose) {\n console.log(`Grouped into ${sortedDates.length} date(s):`);\n for (const date of sortedDates) {\n const dateCommits = groupedByDate.get(date)!;\n console.log(` ${date}: ${dateCommits.length} commit(s)`);\n }\n }\n\n // Get base version from package.json\n const baseVersion = getBaseVersion();\n if (verbose) console.log(`Base version: ${baseVersion}`);\n\n // Generate changelog entries for each date (oldest to newest)\n const entries: VersionedEntry[] = [];\n const emptyStaged = { files: [], diff: '' };\n\n for (let i = 0; i < sortedDates.length; i++) {\n const date = sortedDates[i];\n const dateCommits = groupedByDate.get(date)!;\n const version = incrementMinorVersion(baseVersion, i + 1);\n\n if (verbose) console.log(`\\nGenerating changelog for ${date} (${version})...`);\n console.log(`Generating changelog for ${date}...`);\n\n const generated = await ai.generateChangelog(dateCommits, emptyStaged);\n\n if (generated.sections.length === 0) {\n if (verbose) console.log(` No entries generated for ${date}, skipping.`);\n continue;\n }\n\n if (verbose) {\n console.log(` Generated sections for ${date}:`);\n for (const section of generated.sections) {\n console.log(` ${section.type}:`);\n for (const item of section.items) {\n console.log(` - ${item}`);\n }\n }\n }\n\n entries.push({ version, date, generated });\n }\n\n if (entries.length === 0) {\n console.log('No changelog entries generated.');\n process.exit(0);\n }\n\n // Reverse for changelog (newest first)\n entries.reverse();\n\n if (options.dryRun) {\n console.log('\\n--- DRY RUN ---');\n console.log('Would update changelog at:', changelog.getFilePath());\n if (changelog.getJsonFilePath()) {\n console.log('Would update JSON at:', changelog.getJsonFilePath());\n }\n console.log(`\\n--- ${entries.length} new entries (newest first) ---\\n`);\n console.log(changelog.formatMultipleEntries(entries));\n console.log('\\n--- JSON releases ---');\n for (const entry of entries) {\n console.log(JSON.stringify({ version: entry.version, date: entry.date }, null, 2));\n }\n console.log('--- End ---\\n');\n process.exit(0);\n }\n\n // Update changelog (MD) with multiple entries\n const newContent = changelog.updateWithMultipleEntries(entries);\n changelog.write(newContent);\n console.log(`Updated: ${changelog.getFilePath()}`);\n\n // Update changelog (JSON) with multiple entries\n if (changelog.getJsonFilePath()) {\n const jsonData = changelog.updateJsonWithMultipleEntries(entries);\n changelog.writeJson(jsonData);\n console.log(`Updated: ${changelog.getJsonFilePath()}`);\n }\n\n console.log(`Done! Created ${entries.length} version entries.`);\n\n } else {\n // === STAGED CHANGES MODE: Original behavior ===\n if (verbose) console.log('Getting staged changes...');\n const staged = await git.getStagedChanges();\n\n if (staged.files.length === 0) {\n console.log('No staged changes found. Stage some changes first.');\n process.exit(0);\n }\n\n if (verbose) {\n console.log(`Staged files: ${staged.files.join(', ')}`);\n console.log(`Diff length: ${staged.diff.length} chars`);\n }\n\n // Get recent commits for context\n if (verbose) console.log('Getting recent commits...');\n const commits = await git.getUnmergedCommits();\n if (verbose) console.log(`Found ${commits.length} unmerged commits`);\n\n // Generate changelog using AI\n console.log('Generating changelog with AI...');\n const generated = await ai.generateChangelog(commits, staged);\n\n if (generated.sections.length === 0) {\n console.log('No changelog entries generated.');\n if (verbose) console.log('Raw AI response:', generated.raw);\n process.exit(0);\n }\n\n if (verbose) {\n console.log('Generated sections:');\n for (const section of generated.sections) {\n console.log(` ${section.type}:`);\n for (const item of section.items) {\n console.log(` - ${item}`);\n }\n }\n }\n\n // Collect metadata for changelog entry\n const [author, commitHash] = await Promise.all([\n git.getCurrentUser(),\n git.getHeadCommit(),\n ]);\n const metadata: ChangelogMetadata = {\n author: author || undefined,\n commitHash: commitHash || undefined,\n timestamp: new Date(),\n };\n\n if (verbose) {\n console.log('Metadata:', metadata);\n }\n\n // Determine version label\n const version = options.version; // undefined -> \"Unreleased\"\n\n // Update changelog (MD)\n const newContent = changelog.update(generated, version, metadata);\n\n // Update changelog (JSON)\n const jsonData = changelog.updateJson(generated, version, metadata);\n\n if (options.dryRun) {\n console.log('\\n--- DRY RUN ---');\n console.log('Would update changelog at:', changelog.getFilePath());\n if (changelog.getJsonFilePath()) {\n console.log('Would update JSON at:', changelog.getJsonFilePath());\n }\n console.log('\\n--- New MD entry ---');\n console.log(changelog.formatEntry(generated, version, metadata));\n console.log('\\n--- New JSON entry ---');\n console.log(JSON.stringify(jsonData.releases[0], null, 2));\n console.log('--- End ---\\n');\n process.exit(0);\n }\n\n // Write changelog (MD)\n changelog.write(newContent);\n console.log(`Updated: ${changelog.getFilePath()}`);\n\n // Write changelog (JSON)\n if (changelog.getJsonFilePath()) {\n changelog.writeJson(jsonData);\n console.log(`Updated: ${changelog.getJsonFilePath()}`);\n }\n\n // Auto-stage changelog files\n await git.stageFile(config.changelog.file);\n if (config.changelog.jsonFile) {\n await git.stageFile(config.changelog.jsonFile);\n }\n console.log('Staged changelog files');\n\n console.log('Done!');\n }\n } catch (error) {\n console.error('Error:', error instanceof Error ? error.message : error);\n if (verbose && error instanceof Error) {\n console.error(error.stack);\n }\n process.exit(1);\n }\n}\n\nprogram.parse();\n\n// Export for programmatic usage\nexport { loadConfig, initConfig, type InitResult } from './config.js';\nexport { GitService } from './git.js';\nexport { AIService } from './ai.js';\nexport { ChangelogService } from './changelog.js';\nexport * from './types.js';\n","import { readFileSync, existsSync, writeFileSync, appendFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { execSync } from 'node:child_process';\nimport { parse, stringify } from 'yaml';\nimport type { Config } from './types.js';\n\n/**\n * Get repository URL from git remote origin\n * Normalizes SSH URLs to HTTPS for web links\n */\nfunction getRepoUrlFromGit(): string {\n try {\n const url = execSync('git remote get-url --push origin', {\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n\n // Normalize SSH format (git@github.com:user/repo.git) to HTTPS\n if (url.startsWith('git@')) {\n return url.replace(/^git@([^:]+):/, 'https://$1/').replace(/\\.git$/, '');\n }\n\n // Remove .git suffix from HTTPS URLs\n return url.replace(/\\.git$/, '');\n } catch {\n return '';\n }\n}\n\nconst DEFAULT_PROMPT = `You are a changelog generator. Your task is to analyze git commits and staged changes to generate changelog entries following the Keep a Changelog format.\n\nOutput Format:\nReturn ONLY a JSON object with the following structure:\n{\n \"sections\": [\n {\n \"type\": \"Added\" | \"Changed\" | \"Deprecated\" | \"Removed\" | \"Fixed\" | \"Security\",\n \"items\": [\"description (by Author, YYYY-MM-DD HH:MM, hash)\", \"description 2 (by Author, YYYY-MM-DD HH:MM, hash)\"]\n }\n ]\n}\n\nGuidelines:\n- Use present tense (e.g., \"Add feature\" not \"Added feature\")\n- Be concise but descriptive\n- Group related changes together\n- Focus on user-facing changes\n- Ignore merge commits and trivial changes\n- IMPORTANT: Each item MUST include author, datetime, and commit hash from the input in the format: \"description (by Author, YYYY-MM-DD HH:MM, hash)\"\n- If multiple commits contribute to the same change, list them: \"description (by Author1, datetime1, hash1; Author2, datetime2, hash2)\"\n- Parse conventional commits (feat:, fix:, etc.) into appropriate sections:\n - feat: -> Added\n - fix: -> Fixed\n - docs:, style:, refactor:, perf:, test:, chore: -> Changed\n - BREAKING CHANGE: -> Changed (mention breaking)\n - deprecate: -> Deprecated\n - remove: -> Removed\n - security: -> Security`;\n\nconst DEFAULT_CONFIG: Config = {\n ai: {\n provider: 'openrouter',\n model: 'anthropic/claude-sonnet-4.5',\n token: '${OPENROUTER_API_KEY}',\n prompt: DEFAULT_PROMPT,\n },\n changelog: {\n file: 'CHANGELOG.md',\n jsonFile: 'changelog.json',\n format: 'keepachangelog',\n includeDate: true,\n includeTime: true,\n includeAuthor: true,\n includeCommitLink: true,\n repoUrl: '',\n groupBy: 'type',\n },\n git: {\n baseBranch: 'main',\n analyzeDepth: 50,\n },\n};\n\n/**\n * Resolve environment variables in config values\n * Supports ${ENV_VAR} syntax\n */\nfunction resolveEnvVars(value: string): string {\n return value.replace(/\\$\\{([^}]+)\\}/g, (_, envVar) => {\n const envValue = process.env[envVar];\n if (!envValue) {\n throw new Error(`Environment variable ${envVar} is not set`);\n }\n return envValue;\n });\n}\n\n/**\n * Recursively resolve env vars in object\n */\nfunction resolveConfigEnvVars<T>(obj: T): T {\n if (typeof obj === 'string') {\n return resolveEnvVars(obj) as T;\n }\n if (Array.isArray(obj)) {\n return obj.map(resolveConfigEnvVars) as T;\n }\n if (obj && typeof obj === 'object') {\n const resolved: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n resolved[key] = resolveConfigEnvVars(value);\n }\n return resolved as T;\n }\n return obj;\n}\n\n/**\n * Deep merge two objects\n */\nfunction deepMerge(target: Config, source: Partial<Config>): Config {\n return {\n ai: { ...target.ai, ...source.ai },\n changelog: { ...target.changelog, ...source.changelog },\n git: { ...target.git, ...source.git },\n };\n}\n\n/**\n * Load configuration from yaml file\n */\nexport function loadConfig(configPath?: string): Config {\n const defaultPaths = ['tst-changelog.yaml', 'tst-changelog.yml', '.tst-changelog.yaml'];\n\n let filePath: string | undefined;\n\n if (configPath) {\n filePath = resolve(process.cwd(), configPath);\n if (!existsSync(filePath)) {\n throw new Error(`Config file not found: ${filePath}`);\n }\n } else {\n for (const p of defaultPaths) {\n const fullPath = resolve(process.cwd(), p);\n if (existsSync(fullPath)) {\n filePath = fullPath;\n break;\n }\n }\n }\n\n if (!filePath) {\n const config = resolveConfigEnvVars(DEFAULT_CONFIG);\n // Auto-detect repoUrl from git if not configured\n if (!config.changelog.repoUrl) {\n config.changelog.repoUrl = getRepoUrlFromGit();\n }\n return config;\n }\n\n const content = readFileSync(filePath, 'utf-8');\n const parsed = parse(content) as Partial<Config>;\n\n const merged = deepMerge(DEFAULT_CONFIG, parsed);\n const config = resolveConfigEnvVars(merged);\n\n // Auto-detect repoUrl from git if not configured\n if (!config.changelog.repoUrl) {\n config.changelog.repoUrl = getRepoUrlFromGit();\n }\n\n return config;\n}\n\nexport interface InitResult {\n configPath: string;\n huskyConfigured: boolean;\n huskyHook?: string;\n}\n\n/**\n * Initialize a new config file with defaults\n */\nexport function initConfig(fileName = 'tst-changelog.yaml'): InitResult {\n const filePath = resolve(process.cwd(), fileName);\n\n if (existsSync(filePath)) {\n throw new Error(`Config file already exists: ${filePath}`);\n }\n\n // Auto-detect repoUrl from git remote\n const detectedRepoUrl = getRepoUrlFromGit();\n\n const configTemplate: Config = {\n ai: {\n provider: 'openrouter',\n model: 'anthropic/claude-sonnet-4.5',\n token: '${OPENROUTER_API_KEY}',\n prompt: DEFAULT_PROMPT,\n },\n changelog: {\n file: 'CHANGELOG.md',\n jsonFile: 'changelog.json',\n format: 'keepachangelog',\n includeDate: true,\n includeTime: true,\n includeAuthor: true,\n includeCommitLink: true,\n repoUrl: detectedRepoUrl,\n groupBy: 'type',\n },\n git: {\n baseBranch: 'main',\n analyzeDepth: 50,\n },\n };\n\n const content = stringify(configTemplate, { lineWidth: 0 });\n writeFileSync(filePath, content, 'utf-8');\n\n // Check for husky and configure hook\n const huskyResult = configureHusky();\n\n return {\n configPath: filePath,\n ...huskyResult,\n };\n}\n\n/**\n * Configure husky pre-commit hook if husky is present\n */\nfunction configureHusky(): { huskyConfigured: boolean; huskyHook?: string } {\n const huskyDir = resolve(process.cwd(), '.husky');\n\n if (!existsSync(huskyDir)) {\n return { huskyConfigured: false };\n }\n\n const preCommitPath = resolve(huskyDir, 'pre-commit');\n const commands = `npx tst-changelog generate\ngit add CHANGELOG.md changelog.json 2>/dev/null || true`;\n\n // Check if hook already exists\n if (existsSync(preCommitPath)) {\n const content = readFileSync(preCommitPath, 'utf-8');\n if (content.includes('tst-changelog')) {\n return { huskyConfigured: false }; // Already configured\n }\n // Append to existing hook\n appendFileSync(preCommitPath, `\\n${commands}\\n`);\n } else {\n // Create new hook\n writeFileSync(preCommitPath, `#!/usr/bin/env sh\\n. \"$(dirname -- \"$0\")/_/husky.sh\"\\n\\n${commands}\\n`, { mode: 0o755 });\n }\n\n return { huskyConfigured: true, huskyHook: preCommitPath };\n}\n","import simpleGit, { SimpleGit } from 'simple-git';\nimport type { CommitInfo, StagedChanges, GitConfig } from './types.js';\n\nexport class GitService {\n private git: SimpleGit;\n private config: GitConfig;\n\n constructor(config: GitConfig, cwd?: string) {\n this.git = simpleGit(cwd);\n this.config = config;\n }\n\n /**\n * Get list of staged files\n */\n async getStagedFiles(): Promise<string[]> {\n const status = await this.git.status();\n return status.staged;\n }\n\n /**\n * Get diff of staged changes\n */\n async getStagedDiff(): Promise<string> {\n const diff = await this.git.diff(['--cached']);\n return diff;\n }\n\n /**\n * Get staged changes (files + diff)\n */\n async getStagedChanges(): Promise<StagedChanges> {\n const [files, diff] = await Promise.all([\n this.getStagedFiles(),\n this.getStagedDiff(),\n ]);\n return { files, diff };\n }\n\n /**\n * Get recent commits from the base branch\n */\n async getRecentCommits(count?: number): Promise<CommitInfo[]> {\n const limit = count ?? this.config.analyzeDepth;\n const log = await this.git.log({\n maxCount: limit,\n format: {\n hash: '%H',\n message: '%s',\n author: '%an',\n date: '%aI',\n body: '%b',\n },\n });\n\n return log.all.map((commit) => ({\n hash: commit.hash,\n message: commit.message,\n author: commit.author,\n date: commit.date,\n body: commit.body?.trim() || undefined,\n }));\n }\n\n /**\n * Get commits not yet in base branch (for feature branches)\n */\n async getUnmergedCommits(): Promise<CommitInfo[]> {\n try {\n const log = await this.git.log({\n from: this.config.baseBranch,\n to: 'HEAD',\n format: {\n hash: '%H',\n message: '%s',\n author: '%an',\n date: '%aI',\n body: '%b',\n },\n });\n\n return log.all.map((commit) => ({\n hash: commit.hash,\n message: commit.message,\n author: commit.author,\n date: commit.date,\n body: commit.body?.trim() || undefined,\n }));\n } catch {\n // If base branch doesn't exist, return empty\n return [];\n }\n }\n\n /**\n * Get current branch name\n */\n async getCurrentBranch(): Promise<string> {\n const branch = await this.git.revparse(['--abbrev-ref', 'HEAD']);\n return branch.trim();\n }\n\n /**\n * Stage a file\n */\n async stageFile(filePath: string): Promise<void> {\n await this.git.add(filePath);\n }\n\n /**\n * Check if we're in a git repository\n */\n async isGitRepo(): Promise<boolean> {\n try {\n await this.git.revparse(['--git-dir']);\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * Get current git user name\n */\n async getCurrentUser(): Promise<string> {\n try {\n const name = await this.git.getConfig('user.name');\n return name.value ?? '';\n } catch {\n return '';\n }\n }\n\n /**\n * Get HEAD commit hash\n */\n async getHeadCommit(): Promise<string> {\n try {\n const hash = await this.git.revparse(['HEAD']);\n return hash.trim();\n } catch {\n return '';\n }\n }\n}\n","import type { AIConfig, CommitInfo, StagedChanges, GeneratedChangelog, ChangelogSection, ChangeType } from './types.js';\n\nconst OPENROUTER_API_URL = 'https://openrouter.ai/api/v1/chat/completions';\n\ninterface OpenRouterResponse {\n choices: Array<{\n message: {\n content: string;\n };\n }>;\n}\n\nexport class AIService {\n private config: AIConfig;\n\n constructor(config: AIConfig) {\n this.config = config;\n }\n\n /**\n * Generate changelog entries from commits and staged changes\n */\n async generateChangelog(\n commits: CommitInfo[],\n staged: StagedChanges\n ): Promise<GeneratedChangelog> {\n const userPrompt = this.buildPrompt(commits, staged);\n const response = await this.callOpenRouter(userPrompt);\n return this.parseResponse(response);\n }\n\n private buildPrompt(commits: CommitInfo[], staged: StagedChanges): string {\n const parts: string[] = [];\n\n if (commits.length > 0) {\n parts.push('## Recent Commits:');\n for (const commit of commits) {\n const shortHash = commit.hash.slice(0, 7);\n const [date, timePart] = commit.date.split('T');\n const time = timePart?.slice(0, 5) ?? ''; // HH:MM\n const datetime = time ? `${date} ${time}` : date;\n parts.push(`- [${shortHash}] (${commit.author}, ${datetime}) ${commit.message}`);\n if (commit.body) {\n parts.push(` ${commit.body}`);\n }\n }\n }\n\n if (staged.files.length > 0) {\n parts.push('\\n## Staged Files:');\n parts.push(staged.files.join('\\n'));\n }\n\n if (staged.diff) {\n // Limit diff size to avoid token limits\n const maxDiffLength = 4000;\n const truncatedDiff = staged.diff.length > maxDiffLength\n ? staged.diff.slice(0, maxDiffLength) + '\\n... (truncated)'\n : staged.diff;\n parts.push('\\n## Staged Diff:');\n parts.push('```diff');\n parts.push(truncatedDiff);\n parts.push('```');\n }\n\n parts.push('\\nGenerate changelog entries for these changes.');\n\n return parts.join('\\n');\n }\n\n private async callOpenRouter(prompt: string): Promise<string> {\n const response = await fetch(OPENROUTER_API_URL, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${this.config.token}`,\n 'HTTP-Referer': 'https://github.com/testudosrl/tst-libs',\n 'X-Title': 'tst-changelog',\n },\n body: JSON.stringify({\n model: this.config.model,\n messages: [\n { role: 'system', content: this.config.prompt ?? '' },\n { role: 'user', content: prompt },\n ],\n temperature: 0.3,\n max_tokens: 4000,\n }),\n });\n\n if (!response.ok) {\n const error = await response.text();\n throw new Error(`OpenRouter API error: ${response.status} - ${error}`);\n }\n\n const data = (await response.json()) as OpenRouterResponse;\n return data.choices[0]?.message?.content ?? '';\n }\n\n private parseResponse(response: string): GeneratedChangelog {\n try {\n // Extract JSON from response (handle markdown code blocks or raw JSON)\n let jsonStr = response;\n\n // Try markdown code block first\n const codeBlockMatch = response.match(/```(?:json)?\\s*([\\s\\S]*?)```/);\n if (codeBlockMatch) {\n jsonStr = codeBlockMatch[1];\n } else {\n // Try to find JSON object in the response\n const jsonObjectMatch = response.match(/\\{[\\s\\S]*\"sections\"[\\s\\S]*\\}/);\n if (jsonObjectMatch) {\n jsonStr = jsonObjectMatch[0];\n }\n }\n\n const parsed = JSON.parse(jsonStr.trim()) as { sections: ChangelogSection[] };\n\n // Validate and normalize sections\n const validTypes: ChangeType[] = ['Added', 'Changed', 'Deprecated', 'Removed', 'Fixed', 'Security'];\n const sections = parsed.sections\n .filter((s) => validTypes.includes(s.type))\n .map((s) => ({\n type: s.type,\n items: Array.isArray(s.items) ? s.items.filter((i) => typeof i === 'string') : [],\n }))\n .filter((s) => s.items.length > 0);\n\n return {\n raw: response,\n sections,\n };\n } catch (error) {\n console.error('Failed to parse AI response:', error);\n console.error('Raw response:', response);\n return {\n raw: response,\n sections: [],\n };\n }\n }\n}\n","import { readFileSync, writeFileSync, existsSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport type { ChangelogConfig, ChangelogSection, GeneratedChangelog, ChangelogMetadata, ChangelogJson, ChangelogJsonRelease, VersionedEntry } from './types.js';\n\nconst KEEPACHANGELOG_HEADER = `# Changelog\n\nAll notable changes to this project will be documented in this file.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),\nand this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n`;\n\nconst SECTION_ORDER = ['Added', 'Changed', 'Deprecated', 'Removed', 'Fixed', 'Security'] as const;\n\nexport class ChangelogService {\n private config: ChangelogConfig;\n private filePath: string;\n\n constructor(config: ChangelogConfig, cwd?: string) {\n this.config = config;\n this.filePath = resolve(cwd ?? process.cwd(), config.file);\n }\n\n /**\n * Read existing changelog content\n */\n read(): string | null {\n if (!existsSync(this.filePath)) {\n return null;\n }\n return readFileSync(this.filePath, 'utf-8');\n }\n\n /**\n * Generate new changelog entry\n */\n formatEntry(generated: GeneratedChangelog, version?: string, metadata?: ChangelogMetadata): string {\n const versionStr = version ?? 'Unreleased';\n const headerParts: string[] = [`## [${versionStr}]`];\n\n // Date and time\n if (this.config.includeDate) {\n const now = metadata?.timestamp ?? new Date();\n let dateStr = now.toISOString().split('T')[0];\n if (this.config.includeTime) {\n const timeStr = now.toTimeString().split(' ')[0].slice(0, 5); // HH:MM\n dateStr += ` ${timeStr}`;\n }\n headerParts.push(`- ${dateStr}`);\n }\n\n // Author\n if (this.config.includeAuthor && metadata?.author) {\n headerParts.push(`by ${metadata.author}`);\n }\n\n // Commit link\n if (this.config.includeCommitLink && metadata?.commitHash) {\n const shortHash = metadata.commitHash.slice(0, 7);\n if (this.config.repoUrl) {\n const commitUrl = `${this.config.repoUrl.replace(/\\/$/, '')}/commit/${metadata.commitHash}`;\n headerParts.push(`([${shortHash}](${commitUrl}))`);\n } else {\n headerParts.push(`(${shortHash})`);\n }\n }\n\n const headerLine = headerParts.join(' ');\n\n const sections = this.sortSections(generated.sections);\n const sectionLines = sections\n .map((section) => this.formatSection(section))\n .join('\\n\\n');\n\n return `${headerLine}\\n\\n${sectionLines}`;\n }\n\n /**\n * Format a simple entry with just version and date (no time, no author)\n * Used for --from-commits mode with date grouping\n */\n formatSimpleEntry(generated: GeneratedChangelog, version: string, date: string): string {\n const headerLine = `## [${version}] - ${date}`;\n\n const sections = this.sortSections(generated.sections);\n const sectionLines = sections\n .map((section) => this.formatSection(section))\n .join('\\n\\n');\n\n return `${headerLine}\\n\\n${sectionLines}`;\n }\n\n /**\n * Format multiple versioned entries into changelog format\n * Entries should already be sorted (newest first)\n */\n formatMultipleEntries(entries: VersionedEntry[]): string {\n return entries\n .map((entry) => this.formatSimpleEntry(entry.generated, entry.version, entry.date))\n .join('\\n\\n');\n }\n\n /**\n * Update changelog with multiple versioned entries (for --from-commits mode)\n * Entries should be in order from newest to oldest (for display order)\n */\n updateWithMultipleEntries(entries: VersionedEntry[]): string {\n const existing = this.read();\n const newContent = this.formatMultipleEntries(entries);\n\n if (!existing) {\n // Create new changelog\n return KEEPACHANGELOG_HEADER + newContent + '\\n';\n }\n\n // Find where to insert new entries (after header, before first version)\n const lines = existing.split('\\n');\n let insertIndex = -1;\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (line.startsWith('## [')) {\n insertIndex = i;\n break;\n }\n }\n\n if (insertIndex === -1) {\n // No version sections found, append after header\n return existing.trimEnd() + '\\n\\n' + newContent + '\\n';\n }\n\n // Insert before first version\n const before = lines.slice(0, insertIndex).join('\\n');\n const after = lines.slice(insertIndex).join('\\n');\n return before + (before.endsWith('\\n') ? '' : '\\n') + newContent + '\\n\\n' + after;\n }\n\n /**\n * Update JSON changelog with multiple releases (for --from-commits mode)\n * Entries should be in order from newest to oldest\n */\n updateJsonWithMultipleEntries(entries: VersionedEntry[]): ChangelogJson {\n const existing = this.readJson();\n\n const newReleases: ChangelogJsonRelease[] = entries.map((entry) => {\n const sections: Record<string, string[]> = {};\n for (const section of entry.generated.sections) {\n sections[section.type] = section.items;\n }\n return {\n version: entry.version,\n date: entry.date,\n sections,\n };\n });\n\n if (!existing) {\n return { releases: newReleases };\n }\n\n // Prepend new releases\n return { releases: [...newReleases, ...existing.releases] };\n }\n\n private sortSections(sections: ChangelogSection[]): ChangelogSection[] {\n return [...sections].sort((a, b) => {\n const indexA = SECTION_ORDER.indexOf(a.type as typeof SECTION_ORDER[number]);\n const indexB = SECTION_ORDER.indexOf(b.type as typeof SECTION_ORDER[number]);\n return indexA - indexB;\n });\n }\n\n private formatSection(section: ChangelogSection): string {\n const items = section.items.map((item) => `- ${this.formatItemWithLinks(item)}`).join('\\n');\n return `### ${section.type}\\n\\n${items}`;\n }\n\n /**\n * Convert commit hashes in item to markdown links if repoUrl is configured\n */\n private formatItemWithLinks(item: string): string {\n if (!this.config.repoUrl) return item;\n\n const repoUrl = this.config.repoUrl.replace(/\\/$/, '');\n\n // Match patterns like \"abc1234\" or \"abc1234; def5678\" at the end of parentheses\n // Pattern: 7-char hex hash\n return item.replace(/\\b([a-f0-9]{7})\\b/g, (match) => {\n return `[${match}](${repoUrl}/commit/${match})`;\n });\n }\n\n /**\n * Update or create changelog with new entry\n */\n update(generated: GeneratedChangelog, version?: string, metadata?: ChangelogMetadata): string {\n const existing = this.read();\n\n if (!existing) {\n // Create new changelog\n const newEntry = this.formatEntry(generated, version, metadata);\n return KEEPACHANGELOG_HEADER + newEntry + '\\n';\n }\n\n // Find where to insert new entry (after header, before first version)\n const lines = existing.split('\\n');\n let insertIndex = -1;\n\n // Look for ## [Unreleased] or first ## [ section\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (line.startsWith('## [Unreleased]')) {\n // Merge with existing unreleased section\n const endIndex = this.findSectionEnd(lines, i + 1);\n const existingSectionLines = lines.slice(i, endIndex);\n const mergedSection = this.mergeUnreleasedSection(existingSectionLines, generated, metadata);\n const before = lines.slice(0, i).join('\\n');\n const after = lines.slice(endIndex).join('\\n');\n return before + (before.endsWith('\\n') ? '' : '\\n') + mergedSection + '\\n' + after;\n }\n if (line.startsWith('## [') && insertIndex === -1) {\n insertIndex = i;\n break;\n }\n }\n\n const newEntry = this.formatEntry(generated, version, metadata);\n\n if (insertIndex === -1) {\n // No version sections found, append after header\n return existing.trimEnd() + '\\n\\n' + newEntry + '\\n';\n }\n\n // Insert before first version\n const before = lines.slice(0, insertIndex).join('\\n');\n const after = lines.slice(insertIndex).join('\\n');\n return before + (before.endsWith('\\n') ? '' : '\\n') + newEntry + '\\n\\n' + after;\n }\n\n /**\n * Merge new entries into existing Unreleased section\n */\n private mergeUnreleasedSection(\n existingLines: string[],\n generated: GeneratedChangelog,\n metadata?: ChangelogMetadata\n ): string {\n // Parse existing sections\n const existingSections: Map<string, string[]> = new Map();\n let currentSection: string | null = null;\n\n for (const line of existingLines) {\n if (line.startsWith('### ')) {\n currentSection = line.slice(4).trim();\n if (!existingSections.has(currentSection)) {\n existingSections.set(currentSection, []);\n }\n } else if (currentSection && line.startsWith('- ')) {\n existingSections.get(currentSection)!.push(line.slice(2));\n }\n }\n\n // Merge new sections\n for (const section of generated.sections) {\n const existing = existingSections.get(section.type) ?? [];\n // Add new items that don't already exist\n for (const item of section.items) {\n if (!existing.includes(item)) {\n existing.push(item);\n }\n }\n existingSections.set(section.type, existing);\n }\n\n // Build merged entry\n const versionStr = 'Unreleased';\n const headerParts: string[] = [`## [${versionStr}]`];\n\n if (this.config.includeDate) {\n const now = metadata?.timestamp ?? new Date();\n let dateStr = now.toISOString().split('T')[0];\n if (this.config.includeTime) {\n const timeStr = now.toTimeString().split(' ')[0].slice(0, 5);\n dateStr += ` ${timeStr}`;\n }\n headerParts.push(`- ${dateStr}`);\n }\n\n if (this.config.includeAuthor && metadata?.author) {\n headerParts.push(`by ${metadata.author}`);\n }\n\n if (this.config.includeCommitLink && metadata?.commitHash) {\n const shortHash = metadata.commitHash.slice(0, 7);\n if (this.config.repoUrl) {\n const commitUrl = `${this.config.repoUrl.replace(/\\/$/, '')}/commit/${metadata.commitHash}`;\n headerParts.push(`([${shortHash}](${commitUrl}))`);\n } else {\n headerParts.push(`(${shortHash})`);\n }\n }\n\n const headerLine = headerParts.join(' ');\n\n // Sort and format sections\n const sortedSections: ChangelogSection[] = [];\n for (const type of SECTION_ORDER) {\n const items = existingSections.get(type);\n if (items && items.length > 0) {\n sortedSections.push({ type, items });\n }\n }\n\n const sectionLines = sortedSections\n .map((section) => this.formatSection(section))\n .join('\\n\\n');\n\n return `${headerLine}\\n\\n${sectionLines}`;\n }\n\n private findSectionEnd(lines: string[], startIndex: number): number {\n for (let i = startIndex; i < lines.length; i++) {\n if (lines[i].startsWith('## [')) {\n return i;\n }\n }\n return lines.length;\n }\n\n /**\n * Write changelog to file\n */\n write(content: string): void {\n writeFileSync(this.filePath, content, 'utf-8');\n }\n\n /**\n * Get the file path\n */\n getFilePath(): string {\n return this.filePath;\n }\n\n /**\n * Get JSON file path if configured\n */\n getJsonFilePath(): string | null {\n if (!this.config.jsonFile) return null;\n return resolve(process.cwd(), this.config.jsonFile);\n }\n\n /**\n * Read existing JSON changelog\n */\n readJson(): ChangelogJson | null {\n const jsonPath = this.getJsonFilePath();\n if (!jsonPath || !existsSync(jsonPath)) {\n return null;\n }\n try {\n const content = readFileSync(jsonPath, 'utf-8');\n return JSON.parse(content) as ChangelogJson;\n } catch {\n return null;\n }\n }\n\n /**\n * Create a JSON release entry from generated changelog\n */\n createJsonRelease(generated: GeneratedChangelog, version?: string, metadata?: ChangelogMetadata): ChangelogJsonRelease {\n const now = metadata?.timestamp ?? new Date();\n const sections: Record<string, string[]> = {};\n\n for (const section of generated.sections) {\n sections[section.type] = section.items;\n }\n\n const release: ChangelogJsonRelease = {\n version: version ?? 'Unreleased',\n date: now.toISOString().split('T')[0],\n sections,\n };\n\n if (this.config.includeTime) {\n release.time = now.toTimeString().split(' ')[0].slice(0, 5);\n }\n\n if (this.config.includeAuthor && metadata?.author) {\n release.author = metadata.author;\n }\n\n if (this.config.includeCommitLink && metadata?.commitHash) {\n release.commitHash = metadata.commitHash;\n }\n\n return release;\n }\n\n /**\n * Update JSON changelog with new release\n */\n updateJson(generated: GeneratedChangelog, version?: string, metadata?: ChangelogMetadata): ChangelogJson {\n const newRelease = this.createJsonRelease(generated, version, metadata);\n const existing = this.readJson();\n\n if (!existing) {\n return { releases: [newRelease] };\n }\n\n // Find and merge or prepend\n const unreleasedIndex = existing.releases.findIndex(r => r.version === 'Unreleased');\n\n if (unreleasedIndex >= 0 && newRelease.version === 'Unreleased') {\n // Merge with existing unreleased\n const existingRelease = existing.releases[unreleasedIndex];\n for (const [type, items] of Object.entries(newRelease.sections)) {\n const existingItems = existingRelease.sections[type] ?? [];\n for (const item of items) {\n if (!existingItems.includes(item)) {\n existingItems.push(item);\n }\n }\n existingRelease.sections[type] = existingItems;\n }\n // Update metadata to latest\n existingRelease.date = newRelease.date;\n if (newRelease.time) existingRelease.time = newRelease.time;\n if (newRelease.author) existingRelease.author = newRelease.author;\n if (newRelease.commitHash) existingRelease.commitHash = newRelease.commitHash;\n } else {\n // Prepend new release\n existing.releases.unshift(newRelease);\n }\n\n return existing;\n }\n\n /**\n * Write JSON changelog to file\n */\n writeJson(data: ChangelogJson): void {\n const jsonPath = this.getJsonFilePath();\n if (!jsonPath) return;\n writeFileSync(jsonPath, JSON.stringify(data, null, 2), 'utf-8');\n }\n}\n"],"mappings":";;;AAAA,OAAO;AACP,SAAS,eAAe;AACxB,SAAS,gBAAAA,eAAc,cAAAC,mBAAkB;AACzC,SAAS,qBAAqB;AAC9B,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UAAU,OAAO,UAAU,IAAI;AACzC,UAAI,OAAO,UAAU,UAAU;AAC7B,cAAM,IAAI,UAAU,OAAO,UAAU,QAAQ;AAAA,MAC/C;AACA,cAAQ,IAAI,wBAAwB;AAEpC,cAAQ,IAAI,OAAO;AAAA,IACrB;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,KAAK;AACtE,QAAI,WAAW,iBAAiB,OAAO;AACrC,cAAQ,MAAM,MAAM,KAAK;AAAA,IAC3B;AACA,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;AAEA,QAAQ,MAAM;","names":["readFileSync","existsSync","resolve","config","readFileSync","writeFileSync","existsSync","resolve","newEntry","before","after","readFileSync","resolve","resolve","existsSync","readFileSync"]}
|