git-release-manager 0.0.0 → 0.0.3

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.
Files changed (38) hide show
  1. package/dist/src/config/defaultConfig.json +232 -0
  2. package/dist/src/config/index.js +86 -0
  3. package/dist/src/config/index.js.map +1 -0
  4. package/dist/src/config/types.js +3 -0
  5. package/dist/src/config/types.js.map +1 -0
  6. package/dist/src/core/app.js +218 -0
  7. package/dist/src/core/app.js.map +1 -0
  8. package/dist/src/core/types.js +3 -0
  9. package/dist/src/core/types.js.map +1 -0
  10. package/dist/src/git/commits.js +237 -0
  11. package/dist/src/git/commits.js.map +1 -0
  12. package/dist/src/git/context.js +95 -0
  13. package/dist/src/git/context.js.map +1 -0
  14. package/dist/src/index.js +89 -0
  15. package/dist/src/index.js.map +1 -0
  16. package/dist/src/main.js +22 -0
  17. package/dist/src/main.js.map +1 -0
  18. package/dist/src/output/writer.js +46 -0
  19. package/dist/src/output/writer.js.map +1 -0
  20. package/dist/src/sections/index.js +207 -0
  21. package/dist/src/sections/index.js.map +1 -0
  22. package/dist/src/templates/changelog.detailed.ejs +111 -0
  23. package/dist/src/templates/changelog.ejs +68 -0
  24. package/dist/src/templates/index.js +101 -0
  25. package/dist/src/templates/index.js.map +1 -0
  26. package/dist/src/utils/cli.js +3 -0
  27. package/dist/src/utils/cli.js.map +1 -0
  28. package/dist/src/utils/cmd.js +57 -0
  29. package/dist/src/utils/cmd.js.map +1 -0
  30. package/dist/src/utils/git-utils.js +278 -0
  31. package/dist/src/utils/git-utils.js.map +1 -0
  32. package/dist/src/utils/helpers.js +50 -0
  33. package/dist/src/utils/helpers.js.map +1 -0
  34. package/dist/test/config/loadConfigFile.test.js +94 -0
  35. package/dist/test/config/loadConfigFile.test.js.map +1 -0
  36. package/dist/test/config/readConfig.test.js +125 -0
  37. package/dist/test/config/readConfig.test.js.map +1 -0
  38. package/package.json +7 -7
@@ -0,0 +1,278 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isGitCommit = isGitCommit;
7
+ exports.isGitRef = isGitRef;
8
+ exports.isGitTag = isGitTag;
9
+ exports.isGitBranch = isGitBranch;
10
+ exports.resolveCommitId = resolveCommitId;
11
+ exports.getLog = getLog;
12
+ exports.resolveReference = resolveReference;
13
+ exports.getCommitCount = getCommitCount;
14
+ exports.getTags = getTags;
15
+ exports.getBranches = getBranches;
16
+ const simple_git_1 = __importDefault(require("simple-git"));
17
+ const helpers_1 = require("./helpers"); // Assuming you have this function exported from helpers
18
+ const child_process_1 = require("child_process");
19
+ const util_1 = __importDefault(require("util"));
20
+ const execPromise = util_1.default.promisify(child_process_1.exec);
21
+ const git = (0, simple_git_1.default)();
22
+ /**
23
+ * Checks if the given value is a valid Git commit.
24
+ *
25
+ * @param value - The value to check if it is a valid Git commit.
26
+ * @returns A promise that resolves to a boolean indicating whether the value is a valid Git commit.
27
+ */
28
+ async function isGitCommit(value) {
29
+ return revParse(value);
30
+ }
31
+ /**
32
+ * Checks if the given value is a valid Git reference.
33
+ *
34
+ * @param value - The string to check as a Git reference.
35
+ * @returns A promise that resolves to `true` if the value is a valid Git reference, otherwise `false`.
36
+ */
37
+ async function isGitRef(value) {
38
+ return revParse(value);
39
+ }
40
+ /**
41
+ * Checks if the given value is a valid Git tag.
42
+ *
43
+ * @param value - The value to check against the list of Git tags.
44
+ * @returns A promise that resolves to `true` if the value is a valid Git tag, otherwise `false`.
45
+ */
46
+ async function isGitTag(value) {
47
+ try {
48
+ const tags = await git.tags();
49
+ return tags.all.includes(value);
50
+ }
51
+ catch (_a) {
52
+ return false;
53
+ }
54
+ }
55
+ /**
56
+ * Checks if the given value is a local Git branch.
57
+ *
58
+ * @param value - The name of the branch to check.
59
+ * @returns A promise that resolves to `true` if the value is a local Git branch, otherwise `false`.
60
+ */
61
+ async function isGitBranch(value) {
62
+ try {
63
+ const branches = await git.branchLocal();
64
+ return branches.all.includes(value);
65
+ }
66
+ catch (_a) {
67
+ return false;
68
+ }
69
+ }
70
+ /**
71
+ * Asynchronously checks if a given Git reference exists.
72
+ *
73
+ * @param value - The Git reference to check (e.g., branch name, commit hash).
74
+ * @returns A promise that resolves to `true` if the reference exists, otherwise `false`.
75
+ */
76
+ async function revParse(value) {
77
+ try {
78
+ const result = await git.revparse([value]);
79
+ return !!result;
80
+ }
81
+ catch (_a) {
82
+ return false;
83
+ }
84
+ }
85
+ /**
86
+ * Resolves the commit ID for a given reference.
87
+ *
88
+ * @param value - The reference to resolve (e.g., branch name, tag, or commit hash).
89
+ * @returns A promise that resolves to the commit ID as a string, or null if the reference cannot be resolved.
90
+ */
91
+ async function resolveCommitId(value) {
92
+ try {
93
+ return await git.revparse([value]);
94
+ }
95
+ catch (_a) {
96
+ return null;
97
+ }
98
+ }
99
+ /**
100
+ * Retrieves the git log for the specified range.
101
+ *
102
+ * @param range - The range of commits to include in the log.
103
+ * @returns A promise that resolves to the git log for the specified range.
104
+ */
105
+ async function getLog(range) {
106
+ return git.log([range]);
107
+ }
108
+ /**
109
+ * Resolves a Git reference to its commit hash and associated metadata.
110
+ *
111
+ * @param value - The reference value to resolve. This can be a commit hash, branch name, tag name, or date.
112
+ * @param isStart - Optional flag indicating whether to resolve the reference as the start of a range.
113
+ * @returns A promise that resolves to a `GitReference` object containing the resolved reference details, or `null` if the reference could not be resolved.
114
+ *
115
+ * The function determines the type of the reference (commit, reference, date, tag, or branch) and resolves it accordingly.
116
+ * If the reference is `null`, it resolves to the first or last commit based on the `isStart` flag.
117
+ * If the reference is a date, it resolves to the first or last commit after or before the date, respectively.
118
+ * If the reference is a branch, it validates the branch and resolves to the first or last commit in the branch based on the `isStart` flag.
119
+ *
120
+ * @throws Will throw an error if the reference type is unsupported or if the reference could not be resolved.
121
+ */
122
+ async function resolveReference(value, isStart) {
123
+ let type;
124
+ let reference = null;
125
+ if (!value) {
126
+ type = helpers_1.referenceTypesEnum.commit;
127
+ value = null;
128
+ try {
129
+ if (isStart) {
130
+ const logs = await git.log(["--reverse"]);
131
+ reference = logs.all.length ? logs.all[0].hash : null;
132
+ }
133
+ else {
134
+ reference = await git.revparse(["HEAD"]);
135
+ }
136
+ }
137
+ catch (error) {
138
+ console.error("Error resolving first/last commit:", error);
139
+ throw error;
140
+ }
141
+ }
142
+ else {
143
+ type = await (0, helpers_1.determineType)(value);
144
+ try {
145
+ switch (type) {
146
+ case helpers_1.referenceTypesEnum.commit:
147
+ case helpers_1.referenceTypesEnum.ref:
148
+ reference = await git.revparse([value]);
149
+ break;
150
+ case helpers_1.referenceTypesEnum.date:
151
+ const formattedDate = (0, helpers_1.formatDateForGit)(value);
152
+ if (isStart) {
153
+ const logsAfter = await git.log([
154
+ "--after",
155
+ formattedDate,
156
+ "--reverse",
157
+ ]);
158
+ reference = logsAfter.all.length ? logsAfter.all[0].hash : null;
159
+ }
160
+ else {
161
+ const logsBefore = await git.log(["--before", formattedDate]);
162
+ reference = logsBefore.latest ? logsBefore.latest.hash : null;
163
+ }
164
+ break;
165
+ case helpers_1.referenceTypesEnum.tag:
166
+ reference = await git.revparse([value]);
167
+ break;
168
+ case helpers_1.referenceTypesEnum.branch:
169
+ const isValidBranch = await isGitBranch(value);
170
+ if (!isValidBranch) {
171
+ throw new Error(`Invalid branch: ${value}`);
172
+ }
173
+ if (isStart) {
174
+ const logsInBranch = await git.log([value]);
175
+ reference = logsInBranch.all.length
176
+ ? logsInBranch.all[logsInBranch.all.length - 1].hash
177
+ : null;
178
+ }
179
+ else {
180
+ reference = await git.revparse([value]);
181
+ }
182
+ break;
183
+ default:
184
+ throw new Error(`Unsupported reference type for: ${value}`);
185
+ }
186
+ if (!reference) {
187
+ throw new Error(`Could not resolve reference: ${value}`);
188
+ }
189
+ }
190
+ catch (error) {
191
+ console.error(`Error resolving reference: ${value}`, error);
192
+ throw error;
193
+ }
194
+ }
195
+ if (!reference) {
196
+ throw new Error("Commit ID is null");
197
+ }
198
+ const result = await git.raw(["show", "-s", "--format=%ci", reference]);
199
+ const date = formatISO8601(result.trim());
200
+ return {
201
+ value,
202
+ type,
203
+ reference,
204
+ date,
205
+ };
206
+ }
207
+ /**
208
+ * Converts a date string from the format 'YYYY-MM-DD HH:mm:ss ±HHMM' to ISO 8601 format.
209
+ *
210
+ * @param dateStr - The date string to be converted, e.g., '2025-01-07 16:57:38 +0300'.
211
+ * @returns The date string in ISO 8601 format, e.g., '2025-01-07T16:57:38+03:00'.
212
+ */
213
+ function formatISO8601(dateStr) {
214
+ const [datePart, timePart, offset] = dateStr.split(" ");
215
+ const parsedDate = new Date(`${datePart}T${timePart}${offset}`);
216
+ return parsedDate.toISOString();
217
+ }
218
+ async function getCommitCount(range) {
219
+ let commitCount = 0;
220
+ try {
221
+ const { stdout } = await execPromise(`git rev-list --count ${range}`);
222
+ commitCount = parseInt(stdout.trim(), 10);
223
+ return commitCount;
224
+ }
225
+ catch (error) {
226
+ console.error("Error counting commits in range:", error);
227
+ throw error;
228
+ }
229
+ }
230
+ async function getTags(range) {
231
+ try {
232
+ // Include the commit hash, tag name, and commit date in the format string
233
+ const logCommand = `git log --pretty=format:"%H %ci %D" ${range}`;
234
+ const { stdout } = await execPromise(logCommand);
235
+ const tagRegex = /^([a-f0-9]{40})\s([\d-]+\s[\d:]+\s[+-]\d{4})\s.*tag: ([^,\s]+)/gm;
236
+ const tagsWithRefs = [];
237
+ let match;
238
+ while ((match = tagRegex.exec(stdout.trim())) !== null) {
239
+ const commitHash = match[1];
240
+ const commitDate = formatISO8601(match[2]);
241
+ const tagName = match[3];
242
+ tagsWithRefs.push({ name: tagName, reference: commitHash, date: commitDate });
243
+ }
244
+ return tagsWithRefs;
245
+ }
246
+ catch (error) {
247
+ console.error("Error retrieving tags in range:", error);
248
+ throw error;
249
+ }
250
+ }
251
+ async function getBranches(range) {
252
+ try {
253
+ const logCommand = `git log --oneline --decorate=short ${range}`;
254
+ const { stdout } = await execPromise(logCommand);
255
+ // Extract branches
256
+ const branchRegex = /([a-f0-9]+)\s.*\(.*?([^,\s)]+)\)/g;
257
+ const branchesWithRefs = [];
258
+ let match;
259
+ while ((match = branchRegex.exec(stdout.trim())) !== null) {
260
+ if (!match[2].startsWith('tag:')) { // Ensures it's a branch
261
+ branchesWithRefs.push({ name: match[2], reference: match[1] });
262
+ }
263
+ }
264
+ // Use a Set to filter unique branches by name
265
+ const uniqueBranchesMap = new Map();
266
+ branchesWithRefs.forEach(branch => {
267
+ if (!uniqueBranchesMap.has(branch.name)) {
268
+ uniqueBranchesMap.set(branch.name, branch);
269
+ }
270
+ });
271
+ return Array.from(uniqueBranchesMap.values());
272
+ }
273
+ catch (error) {
274
+ console.error("Error retrieving branches in range:", error);
275
+ throw error;
276
+ }
277
+ }
278
+ //# sourceMappingURL=git-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-utils.js","sourceRoot":"","sources":["../../../src/utils/git-utils.ts"],"names":[],"mappings":";;;;;AAgCA,kCAEC;AAQD,4BAEC;AAQD,4BAOC;AAQD,kCAOC;AAuBD,0CAMC;AAQD,wBAEC;AAgBD,4CAuFC;AAeD,wCAWC;AAaD,0BAuBC;AAGD,kCA6BC;AAtTD,4DAAmC;AACnC,uCAAgF,CAAC,wDAAwD;AACzI,iDAAqC;AACrC,gDAAwB;AACxB,MAAM,WAAW,GAAG,cAAI,CAAC,SAAS,CAAC,oBAAI,CAAC,CAAC;AAEzC,MAAM,GAAG,GAAG,IAAA,oBAAS,GAAE,CAAC;AAoBxB;;;;;GAKG;AACI,KAAK,UAAU,WAAW,CAAC,KAAa;IAC7C,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,QAAQ,CAAC,KAAa;IAC1C,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,QAAQ,CAAC,KAAa;IAC1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AM,WAAW,GAAG,mCAAmC,CAAC;QACxD,MAAM,gBAAgB,GAAkB,EAAE,CAAC;QAC3C,IAAI,KAAK,CAAC;QACV,OAAO,CAAC,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YAC1D,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,wBAAwB;gBAC1D,gBAAgB,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACjE,CAAC;QACH,CAAC;QAED,8CAA8C;QAC9C,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAkB,CAAC;QACpD,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YAChC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;gBACxC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,CAAC,CAAC;IAEhD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAAC;QAC5D,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.referenceTypesEnum = void 0;
4
+ exports.determineType = determineType;
5
+ exports.parseRange = parseRange;
6
+ exports.formatDateForGit = formatDateForGit;
7
+ const git_utils_1 = require("./git-utils");
8
+ var referenceTypesEnum;
9
+ (function (referenceTypesEnum) {
10
+ referenceTypesEnum["commit"] = "commit";
11
+ referenceTypesEnum["date"] = "date";
12
+ referenceTypesEnum["tag"] = "tag";
13
+ referenceTypesEnum["branch"] = "branch";
14
+ referenceTypesEnum["ref"] = "ref";
15
+ })(referenceTypesEnum || (exports.referenceTypesEnum = referenceTypesEnum = {}));
16
+ async function determineType(value) {
17
+ const commitRegex = /^[a-f0-9]{7,40}$/i;
18
+ const dateRegex = /^(\d{4})-(\d{2})-(\d{2})[T\s](\d{2}):(\d{2}):(\d{2})(\.\d+)?(Z|([+-]\d{2}:\d{2}))?$/;
19
+ const semanticTagRegex = /^v?\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+(\.[a-zA-Z0-9.-]+)*)?$/;
20
+ const refRegex = /^(HEAD(~\d+)?|[a-zA-Z0-9._-]+)$/;
21
+ if (value.match(commitRegex) && await (0, git_utils_1.isGitCommit)(value)) {
22
+ return referenceTypesEnum.commit;
23
+ }
24
+ else if (value.match(dateRegex)) {
25
+ return referenceTypesEnum.date;
26
+ }
27
+ else if (semanticTagRegex.test(value) && await (0, git_utils_1.isGitTag)(value)) {
28
+ return referenceTypesEnum.tag;
29
+ }
30
+ else if (refRegex.test(value)) {
31
+ if (await (0, git_utils_1.isGitBranch)(value)) {
32
+ return referenceTypesEnum.branch;
33
+ }
34
+ if (await (0, git_utils_1.isGitTag)(value)) {
35
+ return referenceTypesEnum.tag;
36
+ }
37
+ return referenceTypesEnum.ref;
38
+ }
39
+ }
40
+ function parseRange(range) {
41
+ if (!range)
42
+ return { from: null, to: null };
43
+ const [from, to] = range.split('..');
44
+ return { from, to };
45
+ }
46
+ function formatDateForGit(dateStr) {
47
+ const date = new Date(dateStr);
48
+ return date.toISOString();
49
+ }
50
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/utils/helpers.ts"],"names":[],"mappings":";;;AASA,sCAqBC;AAED,gCAIC;AAED,4CAGC;AAzCD,2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AI,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IAC5C,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACrC,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AACtB,CAAC;AAED,SAAgB,gBAAgB,CAAC,OAAe;IAC9C,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/B,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const globals_1 = require("@jest/globals");
37
+ const fs = __importStar(require("fs"));
38
+ const config_1 = require("../../src/config");
39
+ globals_1.jest.mock("fs", () => ({
40
+ promises: {
41
+ readFile: globals_1.jest.fn(),
42
+ },
43
+ }));
44
+ describe("loadConfigFile", () => {
45
+ const mockPath = "/mock/path/config.json";
46
+ beforeEach(() => {
47
+ globals_1.jest.clearAllMocks();
48
+ });
49
+ it("should load and parse config file successfully", async () => {
50
+ var _a;
51
+ const mockConfig = {
52
+ appName: "sample-app",
53
+ helpers: {
54
+ formatCommit: "function(commit) { return commit.toUpperCase(); }",
55
+ },
56
+ };
57
+ const readFileMock = fs.promises.readFile;
58
+ readFileMock.mockResolvedValue(JSON.stringify(mockConfig));
59
+ const result = await (0, config_1.loadConfigFile)(mockPath);
60
+ // Use mockResult where needed in your test setup
61
+ expect(fs.promises.readFile).toHaveBeenCalledWith(mockPath, "utf-8");
62
+ expect(result).toHaveProperty("helpers");
63
+ expect(typeof ((_a = result.helpers) === null || _a === void 0 ? void 0 : _a.formatCommit)).toBe("function");
64
+ });
65
+ it("should return empty object when file does not exist", async () => {
66
+ const error = new Error("File not found");
67
+ error.code = "ENOENT";
68
+ const readFileMock = fs.promises.readFile;
69
+ readFileMock.mockRejectedValue(error);
70
+ const result = await (0, config_1.loadConfigFile)(mockPath);
71
+ expect(result).toEqual({});
72
+ });
73
+ it("should throw error for other file system errors", async () => {
74
+ const error = new Error("Permission denied");
75
+ const readFileMock = fs.promises.readFile;
76
+ readFileMock.mockRejectedValue(error);
77
+ await expect((0, config_1.loadConfigFile)(mockPath)).rejects.toThrow("Permission denied");
78
+ });
79
+ it("should handle config without helpers", async () => {
80
+ const mockConfig = {
81
+ someOtherProperty: "value",
82
+ };
83
+ const readFileMock = fs.promises.readFile;
84
+ readFileMock.mockResolvedValue(JSON.stringify(mockConfig));
85
+ const result = await (0, config_1.loadConfigFile)(mockPath);
86
+ expect(result).toEqual(mockConfig);
87
+ });
88
+ it("should handle invalid JSON", async () => {
89
+ const readFileMock = fs.promises.readFile;
90
+ readFileMock.mockResolvedValue("invalid json");
91
+ await expect((0, config_1.loadConfigFile)(mockPath)).rejects.toThrow(SyntaxError);
92
+ });
93
+ });
94
+ //# sourceMappingURL=loadConfigFile.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadConfigFile.test.js","sourceRoot":"","sources":["../../../test/config/loadConfigFile.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAqC;AACrC,uCAAyB;AAEzB,6CAAkD;AAElD,cAAI,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;IACrB,QAAQ,EAAE;QACR,QAAQ,EAAE,cAAI,CAAC,EAAE,EAAE;KACpB;CACF,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,MAAM,QAAQ,GAAG,wBAAwB,CAAC;IAE1C,UAAU,CAAC,GAAG,EAAE;QACd,cAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;;QAC9D,MAAM,UAAU,GAAG;YACjB,OAAO,EAAE,YAAY;YACrB,OAAO,EAAE;gBACP,YAAY,EAAE,mDAAmD;aAClE;SACF,CAAC;QAEF,MAAM,YAAY,GAAG,EAAE,CAAC,QAAQ,CAAC,QAEhC,CAAC;QACF,YAAY,CAAC,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;QAE3D,MAAM,MAAM,GAAG,MAAM,IAAA,uBAAc,EAAC,QAAQ,CAAC,CAAC;QAE9C,iDAAiD;QACjD,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,oBAAoB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACrE,MAAM,CAAC,MAAM,CAAC,CA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AE3D,MAAM,MAAM,GAAG,MAAM,IAAA,uBAAc,EAAC,QAAQ,CAAC,CAAC;QAE9C,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;QAC1C,MAAM,YAAY,GAAG,EAAE,CAAC,QAAQ,CAAC,QAEhC,CAAC;QACF,YAAY,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;QAE/C,MAAM,MAAM,CAAC,IAAA,uBAAc,EAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const globals_1 = require("@jest/globals");
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const config_1 = require("../../src/config");
40
+ globals_1.jest.mock("fs", () => ({
41
+ existsSync: globals_1.jest.fn(),
42
+ promises: {
43
+ readFile: globals_1.jest.fn(),
44
+ },
45
+ }));
46
+ globals_1.jest.mock("path", () => ({
47
+ resolve: globals_1.jest.fn((path) => path),
48
+ }));
49
+ function isPathLike(param) {
50
+ return typeof param === "string" || param instanceof Buffer;
51
+ }
52
+ describe("readConfig", () => {
53
+ beforeEach(() => {
54
+ globals_1.jest.clearAllMocks();
55
+ fs.existsSync.mockReturnValue(true);
56
+ });
57
+ it("should merge configs with correct priority", async () => {
58
+ const mockDefaultConfig = { prop1: "default", prop2: "default" };
59
+ const mockLocalConfig = { prop1: "local" };
60
+ const mockCustomConfig = { prop1: "custom" };
61
+ const customConfigPath = "/custom/path/config.json";
62
+ const readFileMock = fs.promises.readFile;
63
+ readFileMock
64
+ .mockResolvedValueOnce(JSON.stringify(mockDefaultConfig)) // Default config
65
+ .mockResolvedValueOnce(JSON.stringify(mockLocalConfig)) // Local config
66
+ .mockResolvedValueOnce(JSON.stringify(mockCustomConfig)); // Custom config
67
+ const result = await (0, config_1.readConfig)(customConfigPath);
68
+ expect(fs.promises.readFile).toHaveBeenCalledWith(customConfigPath, "utf-8");
69
+ expect(result).toEqual({
70
+ prop1: "default", //! validate custom config, not correct in test case? should validate "custom" for prop1
71
+ prop2: "default",
72
+ });
73
+ });
74
+ it("should handle environment-specific configs", async () => {
75
+ const mockDefaultConfig = { prop: "default" };
76
+ const mockEnvConfig = { prop: "production" };
77
+ const existsSyncMock = fs.existsSync;
78
+ // Apply the mock implementation
79
+ existsSyncMock.mockImplementation((path) => path.toString().includes(".production.json"));
80
+ const readFileMock = fs.promises.readFile;
81
+ readFileMock
82
+ .mockResolvedValueOnce(JSON.stringify(mockEnvConfig));
83
+ const result = await (0, config_1.readConfig)(null, "production");
84
+ expect(result).toEqual({
85
+ prop: "production",
86
+ });
87
+ });
88
+ it("should fall back to default config when env config does not exist", async () => {
89
+ const mockDefaultConfig = { prop: "default" };
90
+ fs.existsSync.mockReturnValue(false);
91
+ const readFileMock = fs.promises.readFile;
92
+ readFileMock.mockResolvedValue(JSON.stringify(mockDefaultConfig));
93
+ const result = await (0, config_1.readConfig)(null, "nonexistent");
94
+ expect(result).toEqual({
95
+ prop: "default",
96
+ });
97
+ });
98
+ it("should handle missing custom config path", async () => {
99
+ const mockDefaultConfig = { prop: "default" };
100
+ fs.existsSync.mockReturnValue(false);
101
+ const readFileMock = fs.promises.readFile;
102
+ readFileMock.mockResolvedValue(JSON.stringify(mockDefaultConfig));
103
+ const result = await (0, config_1.readConfig)();
104
+ expect(result).toEqual(mockDefaultConfig);
105
+ });
106
+ it("should handle file read errors", async () => {
107
+ const error = new Error("File not found");
108
+ error.code = "ENOENT";
109
+ const readFileMock = fs.promises.readFile;
110
+ readFileMock.mockRejectedValue(error);
111
+ const result = await (0, config_1.readConfig)();
112
+ expect(result).toEqual({});
113
+ });
114
+ it("should handle custom config with environment", async () => {
115
+ const mockCustomConfig = { prop: "custom-prod" };
116
+ const customPath = "/custom/path/config.production.json";
117
+ fs.existsSync.mockReturnValue(true);
118
+ const readFileMock = fs.promises.readFile;
119
+ readFileMock.mockResolvedValue(JSON.stringify(mockCustomConfig));
120
+ const result = await (0, config_1.readConfig)("/custom/path/config.json", "production");
121
+ expect(path.resolve).toHaveBeenCalledWith(customPath);
122
+ expect(result).toEqual(mockCustomConfig);
123
+ });
124
+ });
125
+ //# sourceMappingURL=readConfig.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readConfig.test.js","sourceRoot":"","sources":["../../../test/config/readConfig.test.ts"],"names":[],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CAAC,CAAC;QAEtC,MAAM,MAAM,GAAG,MAAM,IAAA,mBAAU,GAAE,CAAC;QAElC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,KAAK,IAAI,EAAE;QAC5D,MAAM,gBAAgB,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;QACjD,MAAM,UAAU,GAAG,qCAAqC,CAAC;QAExD,EAAE,CAAC,UAAwB,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAEnD,MAAM,YAAY,GAAG,EAAE,CAAC,QAAQ,CAAC,QAEhC,CAAC;QACF,YAAY,CAAC,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAEjE,MAAM,MAAM,GAAG,MAAM,IAAA,mBAAU,EAAC,0BAA0B,EAAE,YAAY,CAAC,CAAC;QAE1E,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;QACtD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "git-release-manager",
3
- "version": "0.0.0",
3
+ "version": "0.0.3",
4
4
  "description": "A tool to generate release notes from git commit history",
5
5
  "main": "index.ts",
6
6
  "scripts": {
7
7
  "build": "tsc && npm run copy-config && npm run copy-template",
8
- "start": "node dist/index.js changelog",
9
- "changelog": "node dist/index.js changelog",
10
- "dev": "tsc && node dist/index.js changelog",
11
- "copy-config": "copyfiles -u 1 ./src/config/defaultConfig.*json ./dist/",
12
- "copy-template": "copyfiles -u 1 ./src/templates/changelog.*ejs ./dist/",
8
+ "start": "node dist/src/index.js changelog",
9
+ "changelog": "node dist/src/index.js changelog",
10
+ "dev": "tsc && node dist/src/index.js changelog",
11
+ "copy-config": "copyfiles -u 1 ./src/config/defaultConfig.*json ./dist/src/",
12
+ "copy-template": "copyfiles -u 1 ./src/templates/changelog.*ejs ./dist/src/",
13
13
  "test": "jest"
14
14
  },
15
15
  "bin": {
16
- "grm": "./dist/index.js"
16
+ "grm": "./dist/src/index.js"
17
17
  },
18
18
  "files": [
19
19
  "dist"