@release-change/release-notes-generator 0.1.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.
Files changed (35) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/dist/create-changelog-file.d.ts +9 -0
  4. package/dist/create-changelog-file.d.ts.map +1 -0
  5. package/dist/create-changelog-file.js +14 -0
  6. package/dist/create-changelog-file.js.map +1 -0
  7. package/dist/create-release-notes.d.ts +9 -0
  8. package/dist/create-release-notes.d.ts.map +1 -0
  9. package/dist/create-release-notes.js +88 -0
  10. package/dist/create-release-notes.js.map +1 -0
  11. package/dist/format-list-item.d.ts +7 -0
  12. package/dist/format-list-item.d.ts.map +1 -0
  13. package/dist/format-list-item.js +7 -0
  14. package/dist/format-list-item.js.map +1 -0
  15. package/dist/format-release-notes-body.d.ts +15 -0
  16. package/dist/format-release-notes-body.d.ts.map +1 -0
  17. package/dist/format-release-notes-body.js +44 -0
  18. package/dist/format-release-notes-body.js.map +1 -0
  19. package/dist/index.d.ts +5 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +4 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/prepare-release-notes.d.ts +13 -0
  24. package/dist/prepare-release-notes.d.ts.map +1 -0
  25. package/dist/prepare-release-notes.js +136 -0
  26. package/dist/prepare-release-notes.js.map +1 -0
  27. package/dist/release-notes-generator.types.d.ts +13 -0
  28. package/dist/release-notes-generator.types.d.ts.map +1 -0
  29. package/dist/release-notes-generator.types.js +2 -0
  30. package/dist/release-notes-generator.types.js.map +1 -0
  31. package/dist/update-changelog-file.d.ts +12 -0
  32. package/dist/update-changelog-file.d.ts.map +1 -0
  33. package/dist/update-changelog-file.js +40 -0
  34. package/dist/update-changelog-file.js.map +1 -0
  35. package/package.json +41 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present Victor Brito
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @release-change/release-notes-generator
2
+
3
+ Functions used internally in release-change to prepare and generate release notes
4
+
5
+ ![License: MIT](https://img.shields.io/github/license/release-change/release-change)
6
+ [![ESM-only package](https://img.shields.io/badge/package-ESM--only-ffe536)](https://nodejs.org/api/esm.html)
7
+ [![Conventional Commits 1.0.0](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org)
8
+ [![Formatted with Biome](https://img.shields.io/badge/Formatted_with-Biome-60a5fa?style=flat&logo=biome)](https://biomejs.dev/)
9
+ ![NPM latest version](https://img.shields.io/npm/v/%40release-change%2Frelease-notes-generator/latest)
10
+ ![Node support](https://img.shields.io/node/v/%40release-change%2Frelease-notes-generator)
11
+ ![Build status](https://img.shields.io/github/actions/workflow/status/release-change/release-change/run-tests.yml)
12
+
13
+ ## Copyright & licence
14
+
15
+ © 2025-present Victor Brito — Released under the [MIT licence](./LICENSE).
@@ -0,0 +1,9 @@
1
+ import type { ReleaseNotes } from "./release-notes-generator.types.js";
2
+ /**
3
+ * Creates a `CHANGELOG.md` file.
4
+ * @param changelogFilePath - The path to the new changelog file.
5
+ * @param header - The changelog file header to use.
6
+ * @param releaseNotesBody - The release notes body to format.
7
+ */
8
+ export declare const createChangelogFile: (changelogFilePath: string, header: string, releaseNotesBody: ReleaseNotes["body"]) => void;
9
+ //# sourceMappingURL=create-changelog-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-changelog-file.d.ts","sourceRoot":"","sources":["../src/create-changelog-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAMvE;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAC9B,mBAAmB,MAAM,EACzB,QAAQ,MAAM,EACd,kBAAkB,YAAY,CAAC,MAAM,CAAC,KACrC,IAIF,CAAC"}
@@ -0,0 +1,14 @@
1
+ import fs from "node:fs";
2
+ import { formatReleaseNotesBody } from "./format-release-notes-body.js";
3
+ /**
4
+ * Creates a `CHANGELOG.md` file.
5
+ * @param changelogFilePath - The path to the new changelog file.
6
+ * @param header - The changelog file header to use.
7
+ * @param releaseNotesBody - The release notes body to format.
8
+ */
9
+ export const createChangelogFile = (changelogFilePath, header, releaseNotesBody) => {
10
+ const formattedReleaseNotesBody = formatReleaseNotesBody(releaseNotesBody, true);
11
+ const newFileData = header + formattedReleaseNotesBody;
12
+ fs.writeFileSync(changelogFilePath, newFileData);
13
+ };
14
+ //# sourceMappingURL=create-changelog-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-changelog-file.js","sourceRoot":"","sources":["../src/create-changelog-file.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAExE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,iBAAyB,EACzB,MAAc,EACd,gBAAsC,EAChC,EAAE;IACR,MAAM,yBAAyB,GAAG,sBAAsB,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;IACjF,MAAM,WAAW,GAAG,MAAM,GAAG,yBAAyB,CAAC;IACvD,EAAE,CAAC,aAAa,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC;AACnD,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { Context } from "@release-change/shared";
2
+ import type { ReleaseNotes } from "./release-notes-generator.types.js";
3
+ /**
4
+ * Creates release notes on GitHub from the prepared notes.
5
+ * @param releaseNotes - The prepared release notes to use.
6
+ * @param context - The context where the CLI is running.
7
+ */
8
+ export declare const createReleaseNotes: (releaseNotes: ReleaseNotes, context: Context) => Promise<void>;
9
+ //# sourceMappingURL=create-release-notes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-release-notes.d.ts","sourceRoot":"","sources":["../src/create-release-notes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAqB,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAWvE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAC7B,cAAc,YAAY,EAC1B,SAAS,OAAO,KACf,OAAO,CAAC,IAAI,CA4Ed,CAAC"}
@@ -0,0 +1,88 @@
1
+ import { inspect } from "node:util";
2
+ import { getReleaseToken } from "@release-change/ci";
3
+ import { getRepositoryRelatedEntryPoint } from "@release-change/github";
4
+ import { setLogger } from "@release-change/logger";
5
+ import { formatDetailedError } from "@release-change/shared";
6
+ import { formatReleaseNotesBody } from "./format-release-notes-body.js";
7
+ /**
8
+ * Creates release notes on GitHub from the prepared notes.
9
+ * @param releaseNotes - The prepared release notes to use.
10
+ * @param context - The context where the CLI is running.
11
+ */
12
+ export const createReleaseNotes = async (releaseNotes, context) => {
13
+ const { tagName, target, isPrerelease, body } = releaseNotes;
14
+ const { env, config } = context;
15
+ const { debug, repositoryUrl } = config;
16
+ const logger = setLogger(debug);
17
+ logger.setScope("release-notes-generator");
18
+ const releaseToken = getReleaseToken(env);
19
+ const uri = `${getRepositoryRelatedEntryPoint(repositoryUrl)}/releases`;
20
+ const requestBody = {
21
+ tag_name: tagName,
22
+ target_commitish: target,
23
+ name: tagName,
24
+ prerelease: isPrerelease,
25
+ make_latest: String(!isPrerelease),
26
+ body: formatReleaseNotesBody(body)
27
+ };
28
+ const releaseNotesResponse = await fetch(uri, {
29
+ method: "POST",
30
+ headers: {
31
+ Accept: "application/vnd.github+json",
32
+ Authorization: `Bearer ${releaseToken}`,
33
+ "Content-Type": "application/json",
34
+ "X-GitHub-Api-Version": "2022-11-28"
35
+ },
36
+ body: JSON.stringify(requestBody)
37
+ });
38
+ const { headers, status, statusText } = releaseNotesResponse;
39
+ const releaseNotesResponseData = releaseNotesResponse.json();
40
+ if (debug) {
41
+ logger.setDebugScope("release-notes-generator:create-release-notes");
42
+ logger.logDebug(`Release notes: ${inspect(releaseNotes, { depth: Number.POSITIVE_INFINITY })}`);
43
+ logger.logDebug(`API entry point: ${uri}`);
44
+ logger.logDebug(`Request body: ${inspect(requestBody, { depth: Number.POSITIVE_INFINITY })}`);
45
+ logger.logDebug(`Response status: ${status}`);
46
+ logger.logDebug(`Response status text: ${statusText}`);
47
+ logger.logDebug(`Response headers: ${inspect(headers, { depth: Number.POSITIVE_INFINITY })}`);
48
+ logger.logDebug(`Response JSON: ${inspect(await releaseNotesResponseData, { depth: Number.POSITIVE_INFINITY })}`);
49
+ }
50
+ if (status === 201) {
51
+ logger.logSuccess(`Created release notes for Git tag ${tagName}.`);
52
+ const releaseInfo = {
53
+ type: "github",
54
+ name: "GitHub release",
55
+ url: `${repositoryUrl.replace(".git", "")}/releases/tag/${tagName}`
56
+ };
57
+ context.releaseInfos.push(releaseInfo);
58
+ if (debug) {
59
+ logger.logDebug("context.releaseInfos:");
60
+ logger.logDebug(inspect(context.releaseInfos, { depth: Number.POSITIVE_INFINITY }));
61
+ }
62
+ }
63
+ else {
64
+ const responseError = await releaseNotesResponseData;
65
+ const { message, documentation_url: documentationUrl } = responseError;
66
+ const documentationReference = documentationUrl ? ` See ${documentationUrl}.` : "";
67
+ logger.logError(`Failed to create release notes for Git tag ${tagName}.`);
68
+ if (status === 404) {
69
+ process.exitCode = 404;
70
+ throw formatDetailedError({
71
+ title: "Failed to create the release notes",
72
+ message: `Failed to fetch URI ${uri}.`,
73
+ details: {
74
+ output: `status: ${status}`
75
+ }
76
+ });
77
+ }
78
+ process.exitCode = status;
79
+ throw formatDetailedError({
80
+ title: "Failed to create the release notes",
81
+ message: `${message}${documentationReference}`,
82
+ details: {
83
+ output: `status: ${status}`
84
+ }
85
+ });
86
+ }
87
+ };
88
+ //# sourceMappingURL=create-release-notes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-release-notes.js","sourceRoot":"","sources":["../src/create-release-notes.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAExE;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,YAA0B,EAC1B,OAAgB,EACD,EAAE;IACjB,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,YAAY,CAAC;IAC7D,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,EAAE,KAAK,EAAE,aAAa,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AG,gBAAgB,CAAC,CAAC,CAAC,QAAQ,gBAAgB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACnF,MAAM,CAAC,QAAQ,CAAC,8CAA8C,OAAO,GAAG,CAAC,CAAC;QAC1E,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACnB,OAAO,CAAC,QAAQ,GAAG,GAAG,CAAC;YACvB,MAAM,mBAAmB,CAAC;gBACxB,KAAK,EAAE,oCAAoC;gBAC3C,OAAO,EAAE,uBAAuB,GAAG,GAAG;gBACtC,OAAO,EAAE;oBACP,MAAM,EAAE,WAAW,MAAM,EAAE;iBAC5B;aACF,CAAC,CAAC;QACL,CAAC;QACD,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC;QAC1B,MAAM,mBAAmB,CAAC;YACxB,KAAK,EAAE,oCAAoC;YAC3C,OAAO,EAAE,GAAG,OAAO,GAAG,sBAAsB,EAAE;YAC9C,OAAO,EAAE;gBACP,MAAM,EAAE,WAAW,MAAM,EAAE;aAC5B;SACF,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Formats a list item in Markdown format from a string.
3
+ * @param item - The item to use.
4
+ * @return The item formatted as a list item in Markdown format.
5
+ */
6
+ export declare const formatListItem: (item: string) => string;
7
+ //# sourceMappingURL=format-list-item.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-list-item.d.ts","sourceRoot":"","sources":["../src/format-list-item.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,MAAqB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Formats a list item in Markdown format from a string.
3
+ * @param item - The item to use.
4
+ * @return The item formatted as a list item in Markdown format.
5
+ */
6
+ export const formatListItem = (item) => `- ${item}`;
7
+ //# sourceMappingURL=format-list-item.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-list-item.js","sourceRoot":"","sources":["../src/format-list-item.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { ReleaseNotes } from "./release-notes-generator.types.js";
2
+ /**
3
+ * Formats the release notes body in Markdown format.
4
+ *
5
+ * The release notes body should have at least one of the following properties to be formatted:
6
+ * - `major`,
7
+ * - `minor`,
8
+ * - `patch`,
9
+ * - `dependencies`.
10
+ * @param releaseNotesBody - The release notes body to format.
11
+ * @param [isReleaseNotesBodyForChangelog] - Whether the release notes body is for the `CHANGELOG.md` file or not.
12
+ * @return The formatted release notes body as a string.
13
+ */
14
+ export declare const formatReleaseNotesBody: (releaseNotesBody: ReleaseNotes["body"], isReleaseNotesBodyForChangelog?: boolean) => string;
15
+ //# sourceMappingURL=format-release-notes-body.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-release-notes-body.d.ts","sourceRoot":"","sources":["../src/format-release-notes-body.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAIvE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sBAAsB,GACjC,kBAAkB,YAAY,CAAC,MAAM,CAAC,EACtC,wCAAsC,KACrC,MA6BF,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { formatListItem } from "./format-list-item.js";
2
+ /**
3
+ * Formats the release notes body in Markdown format.
4
+ *
5
+ * The release notes body should have at least one of the following properties to be formatted:
6
+ * - `major`,
7
+ * - `minor`,
8
+ * - `patch`,
9
+ * - `dependencies`.
10
+ * @param releaseNotesBody - The release notes body to format.
11
+ * @param [isReleaseNotesBodyForChangelog] - Whether the release notes body is for the `CHANGELOG.md` file or not.
12
+ * @return The formatted release notes body as a string.
13
+ */
14
+ export const formatReleaseNotesBody = (releaseNotesBody, isReleaseNotesBodyForChangelog = false) => {
15
+ const { major, minor, patch, dependencies, changelog } = releaseNotesBody;
16
+ const hasChanges = major || minor || patch || dependencies;
17
+ if (hasChanges) {
18
+ const headingLevel = isReleaseNotesBodyForChangelog ? "###" : "##";
19
+ const majorChangesSection = major?.length
20
+ ? `${headingLevel} Major changes\n\n${major.map(formatListItem).join("\n")}\n`
21
+ : "";
22
+ const minorChangesSection = minor?.length
23
+ ? `${headingLevel} Minor changes\n\n${minor.map(formatListItem).join("\n")}\n`
24
+ : "";
25
+ const patchChangesSection = patch?.length
26
+ ? `${headingLevel} Patch changes\n\n${patch.map(formatListItem).join("\n")}\n`
27
+ : "";
28
+ const dependenciesUpdatesSection = dependencies?.length
29
+ ? `${headingLevel} Dependencies updates\n\n${dependencies.map(formatListItem).join("\n")}\n`
30
+ : "";
31
+ const fullChangelogSection = changelog ? `---\n\n${changelog}\n` : "";
32
+ return [
33
+ majorChangesSection,
34
+ minorChangesSection,
35
+ patchChangesSection,
36
+ dependenciesUpdatesSection,
37
+ fullChangelogSection
38
+ ]
39
+ .filter(Boolean)
40
+ .join("\n");
41
+ }
42
+ return "";
43
+ };
44
+ //# sourceMappingURL=format-release-notes-body.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-release-notes-body.js","sourceRoot":"","sources":["../src/format-release-notes-body.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,gBAAsC,EACtC,8BAA8B,GAAG,KAAK,EAC9B,EAAE;IACV,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC;IAC1E,MAAM,UAAU,GAAG,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,YAAY,CAAC;IAC3D,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,8BAA8B,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;QACnE,MAAM,mBAAmB,GAAG,KAAK,EAAE,MAAM;YACvC,CAAC,CAAC,GAAG,YAAY,qBAAqB,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;YAC9E,CAAC,CAAC,EAAE,CAAC;QACP,MAAM,mBAAmB,GAAG,KAAK,EAAE,MAAM;YACvC,CAAC,CAAC,GAAG,YAAY,qBAAqB,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;YAC9E,CAAC,CAAC,EAAE,CAAC;QACP,MAAM,mBAAmB,GAAG,KAAK,EAAE,MAAM;YACvC,CAAC,CAAC,GAAG,YAAY,qBAAqB,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;YAC9E,CAAC,CAAC,EAAE,CAAC;QACP,MAAM,0BAA0B,GAAG,YAAY,EAAE,MAAM;YACrD,CAAC,CAAC,GAAG,YAAY,4BAA4B,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;YAC5F,CAAC,CAAC,EAAE,CAAC;QACP,MAAM,oBAAoB,GAAG,SAAS,CAAC,CAAC,CAAC,UAAU,SAAS,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACtE,OAAO;YACL,mBAAmB;YACnB,mBAAmB;YACnB,mBAAmB;YACnB,0BAA0B;YAC1B,oBAAoB;SACrB;aACE,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export type { ReleaseNotes } from "./release-notes-generator.types.js";
2
+ export { createReleaseNotes } from "./create-release-notes.js";
3
+ export { prepareReleaseNotes } from "./prepare-release-notes.js";
4
+ export { updateChangelogFile } from "./update-changelog-file.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAEvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { createReleaseNotes } from "./create-release-notes.js";
2
+ export { prepareReleaseNotes } from "./prepare-release-notes.js";
3
+ export { updateChangelogFile } from "./update-changelog-file.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { Context, PackageNextRelease } from "@release-change/shared";
2
+ import type { ReleaseNotes } from "./release-notes-generator.types.js";
3
+ /**
4
+ * Prepares the release notes for a package.
5
+ *
6
+ * In a monorepo context, the release notes for the root package are prepared considering all other internal packages.
7
+ * @param packageNextRelease - The next release data to use.
8
+ * @param packageDependencies - The package internal dependencies.
9
+ * @param context - The context where the CLI is running.
10
+ * @return The release notes for the package.
11
+ */
12
+ export declare const prepareReleaseNotes: (packageNextRelease: PackageNextRelease, packageDependencies: string[] | null, context: Context) => ReleaseNotes;
13
+ //# sourceMappingURL=prepare-release-notes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare-release-notes.d.ts","sourceRoot":"","sources":["../src/prepare-release-notes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAQvE;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,GAC9B,oBAAoB,kBAAkB,EACtC,qBAAqB,MAAM,EAAE,GAAG,IAAI,EACpC,SAAS,OAAO,KACf,YA4HF,CAAC"}
@@ -0,0 +1,136 @@
1
+ import { inspect } from "node:util";
2
+ import { COMMIT_ABBREVIATED_SHA_LENGTH, COMMIT_MESSAGE } from "@release-change/commit-analyser";
3
+ import { setLogger } from "@release-change/logger";
4
+ import { formatDetailedError } from "@release-change/shared";
5
+ /**
6
+ * Prepares the release notes for a package.
7
+ *
8
+ * In a monorepo context, the release notes for the root package are prepared considering all other internal packages.
9
+ * @param packageNextRelease - The next release data to use.
10
+ * @param packageDependencies - The package internal dependencies.
11
+ * @param context - The context where the CLI is running.
12
+ * @return The release notes for the package.
13
+ */
14
+ export const prepareReleaseNotes = (packageNextRelease, packageDependencies, context) => {
15
+ const { pathname, name, gitTag } = packageNextRelease;
16
+ const { config, branch, lastRelease, nextRelease, commits } = context;
17
+ if (branch) {
18
+ const { debug, repositoryUrl, releaseType, isMonorepo } = config;
19
+ const logger = setLogger(debug);
20
+ const branchConfig = releaseType[branch];
21
+ if (branchConfig) {
22
+ const { prerelease } = branchConfig;
23
+ if (lastRelease) {
24
+ const packageLastRelease = lastRelease.packages.find(packageItem => packageItem.name === name);
25
+ if (packageLastRelease) {
26
+ if (commits) {
27
+ const majorChanges = [];
28
+ const minorChanges = [];
29
+ const patchChanges = [];
30
+ const dependenciesUpdates = [];
31
+ const { gitTag: lastGitTag } = packageLastRelease;
32
+ for (const commit of commits) {
33
+ const { isMergeCommit, sha, message, releaseType, modifiedFiles } = commit;
34
+ if (isMergeCommit ||
35
+ (isMonorepo &&
36
+ name &&
37
+ !modifiedFiles?.filter(file => file.startsWith(pathname)).length)) {
38
+ continue;
39
+ }
40
+ if (sha) {
41
+ const abbreviatedSha = sha?.slice(0, COMMIT_ABBREVIATED_SHA_LENGTH);
42
+ const [_, scope, description] = message.match(COMMIT_MESSAGE) ?? [];
43
+ const sanitisedDescription = description ?? "";
44
+ const changeItem = `${scope ? `**${scope}:** ${sanitisedDescription}` : sanitisedDescription} ([\`${abbreviatedSha}\`](${repositoryUrl.replace(".git", "")}/commit/${sha}))`;
45
+ switch (releaseType) {
46
+ case "major":
47
+ majorChanges.push(changeItem);
48
+ break;
49
+ case "minor": {
50
+ minorChanges.push(changeItem);
51
+ break;
52
+ }
53
+ case "patch":
54
+ patchChanges.push(changeItem);
55
+ break;
56
+ default:
57
+ break;
58
+ }
59
+ }
60
+ }
61
+ if (isMonorepo && name && packageDependencies && nextRelease) {
62
+ for (const packageDependency of packageDependencies) {
63
+ const packageNextRelease = nextRelease.find(packageItem => packageItem.name === packageDependency);
64
+ if (packageNextRelease) {
65
+ const updateItem = `${packageNextRelease.name}@${packageNextRelease.version}`;
66
+ dependenciesUpdates.push(updateItem);
67
+ }
68
+ }
69
+ }
70
+ const fullChangelog = lastGitTag
71
+ ? `**Full changelog:** [\`${lastGitTag}...${gitTag}\`](${repositoryUrl.replace(".git", "")}/compare/${lastGitTag}...${gitTag})`
72
+ : "";
73
+ const releaseNotesBody = {};
74
+ if (majorChanges.length)
75
+ releaseNotesBody.major = majorChanges;
76
+ if (minorChanges.length)
77
+ releaseNotesBody.minor = minorChanges;
78
+ if (patchChanges.length)
79
+ releaseNotesBody.patch = patchChanges;
80
+ if (dependenciesUpdates.length)
81
+ releaseNotesBody.dependencies = dependenciesUpdates;
82
+ if (fullChangelog)
83
+ releaseNotesBody.changelog = fullChangelog;
84
+ if (debug) {
85
+ logger.setDebugScope("release-notes-generator:prepare-release-notes");
86
+ logger.logDebug(`Release notes for ${name || "root"} package:`);
87
+ logger.logDebug(inspect(releaseNotesBody, { depth: Number.POSITIVE_INFINITY }));
88
+ }
89
+ return {
90
+ tagName: gitTag,
91
+ target: branch,
92
+ isPrerelease: Boolean(prerelease),
93
+ body: releaseNotesBody
94
+ };
95
+ }
96
+ throw formatDetailedError({
97
+ title: "Failed to prepare the release notes",
98
+ message: "No commits have been retrieved.",
99
+ details: {
100
+ output: "commits: undefined"
101
+ }
102
+ });
103
+ }
104
+ throw formatDetailedError({
105
+ title: "Failed to prepare the release notes",
106
+ message: `No last release found for ${name || "root"} package.`,
107
+ details: {
108
+ output: "packageLastRelease: undefined"
109
+ }
110
+ });
111
+ }
112
+ throw formatDetailedError({
113
+ title: "Failed to prepare the release notes",
114
+ message: "The last release is not defined.",
115
+ details: {
116
+ output: "lastRelease: undefined"
117
+ }
118
+ });
119
+ }
120
+ throw formatDetailedError({
121
+ title: "Failed to prepare the release notes",
122
+ message: `The branch ${branch} is not defined in the configuration.`,
123
+ details: {
124
+ output: "branchConfig: undefined"
125
+ }
126
+ });
127
+ }
128
+ throw formatDetailedError({
129
+ title: "Failed to prepare the release notes",
130
+ message: "The branch is not defined",
131
+ details: {
132
+ output: "branch: undefined"
133
+ }
134
+ });
135
+ };
136
+ //# sourceMappingURL=prepare-release-notes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare-release-notes.js","sourceRoot":"","sources":["../src/prepare-release-notes.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,6BAA6B,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,kBAAsC,EACtC,mBAAoC,EACpC,OAAgB,EACF,EAAE;IAChB,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,kBAAkB,CAAC;I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qBACF,CAAC,CAAC;gBACL,CAAC;gBACD,MAAM,mBAAmB,CAAC;oBACxB,KAAK,EAAE,qCAAqC;oBAC5C,OAAO,EAAE,6BAA6B,IAAI,IAAI,MAAM,WAAW;oBAC/D,OAAO,EAAE;wBACP,MAAM,EAAE,+BAA+B;qBACxC;iBACF,CAAC,CAAC;YACL,CAAC;YACD,MAAM,mBAAmB,CAAC;gBACxB,KAAK,EAAE,qCAAqC;gBAC5C,OAAO,EAAE,kCAAkC;gBAC3C,OAAO,EAAE;oBACP,MAAM,EAAE,wBAAwB;iBACjC;aACF,CAAC,CAAC;QACL,CAAC;QACD,MAAM,mBAAmB,CAAC;YACxB,KAAK,EAAE,qCAAqC;YAC5C,OAAO,EAAE,cAAc,MAAM,uCAAuC;YACpE,OAAO,EAAE;gBACP,MAAM,EAAE,yBAAyB;aAClC;SACF,CAAC,CAAC;IACL,CAAC;IACD,MAAM,mBAAmB,CAAC;QACxB,KAAK,EAAE,qCAAqC;QAC5C,OAAO,EAAE,2BAA2B;QACpC,OAAO,EAAE;YACP,MAAM,EAAE,mBAAmB;SAC5B;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ export type ReleaseNotes = {
2
+ tagName: string;
3
+ target: string;
4
+ isPrerelease: boolean;
5
+ body: {
6
+ major?: string[];
7
+ minor?: string[];
8
+ patch?: string[];
9
+ dependencies?: string[];
10
+ changelog?: string;
11
+ };
12
+ };
13
+ //# sourceMappingURL=release-notes-generator.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"release-notes-generator.types.d.ts","sourceRoot":"","sources":["../src/release-notes-generator.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,OAAO,CAAC;IACtB,IAAI,EAAE;QACJ,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QACjB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=release-notes-generator.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"release-notes-generator.types.js","sourceRoot":"","sources":["../src/release-notes-generator.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import type { PackageNextRelease } from "@release-change/shared";
2
+ import type { ReleaseNotes } from "./release-notes-generator.types.js";
3
+ /**
4
+ * Updates the package `CHANGELOG.md` file.
5
+ *
6
+ * In case the changelog file does not exist or is empty, it is filled without the full changelog section.
7
+ * @param packageNextRelease - The next release data to use.
8
+ * @param releaseNotesBody - The release notes body to format.
9
+ * @param cwd - The current working directory.
10
+ */
11
+ export declare const updateChangelogFile: (packageNextRelease: PackageNextRelease, releaseNotesBody: ReleaseNotes["body"], cwd: string) => void;
12
+ //# sourceMappingURL=update-changelog-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-changelog-file.d.ts","sourceRoot":"","sources":["../src/update-changelog-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAUvE;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,GAC9B,oBAAoB,kBAAkB,EACtC,kBAAkB,YAAY,CAAC,MAAM,CAAC,EACtC,KAAK,MAAM,SAyBZ,CAAC"}
@@ -0,0 +1,40 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { getPackageName } from "@release-change/get-packages";
4
+ import { createChangelogFile } from "./create-changelog-file.js";
5
+ import { formatReleaseNotesBody } from "./format-release-notes-body.js";
6
+ /**
7
+ * Updates the package `CHANGELOG.md` file.
8
+ *
9
+ * In case the changelog file does not exist or is empty, it is filled without the full changelog section.
10
+ * @param packageNextRelease - The next release data to use.
11
+ * @param releaseNotesBody - The release notes body to format.
12
+ * @param cwd - The current working directory.
13
+ */
14
+ export const updateChangelogFile = (packageNextRelease, releaseNotesBody, cwd) => {
15
+ const { name, pathname, version } = packageNextRelease;
16
+ const { major, minor, patch, dependencies } = releaseNotesBody;
17
+ const packageName = name || getPackageName(path.join(cwd, pathname, "package.json"));
18
+ const changelogFilePath = path.join(cwd, pathname, "CHANGELOG.md");
19
+ const versionHeader = `\n\n## ${version}\n\n`;
20
+ if (fs.existsSync(changelogFilePath)) {
21
+ const fileData = fs.readFileSync(changelogFilePath, "utf-8");
22
+ if (fileData) {
23
+ const formattedReleaseNotesBody = formatReleaseNotesBody(releaseNotesBody, true);
24
+ const blankLineIndex = fileData.indexOf("\n\n");
25
+ const updatedFileData = blankLineIndex === -1
26
+ ? `${fileData}\n\n${formattedReleaseNotesBody}`
27
+ : `${fileData.slice(0, blankLineIndex)}${versionHeader}${formattedReleaseNotesBody}${fileData.slice(blankLineIndex + 1)}`;
28
+ fs.writeFileSync(changelogFilePath, updatedFileData);
29
+ }
30
+ else {
31
+ const newFileHeader = `# ${packageName ?? "root package"}${versionHeader}`;
32
+ createChangelogFile(changelogFilePath, newFileHeader, { major, minor, patch, dependencies });
33
+ }
34
+ }
35
+ else {
36
+ const newFileHeader = `# ${packageName ?? "root package"}${versionHeader}`;
37
+ createChangelogFile(changelogFilePath, newFileHeader, { major, minor, patch, dependencies });
38
+ }
39
+ };
40
+ //# sourceMappingURL=update-changelog-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-changelog-file.js","sourceRoot":"","sources":["../src/update-changelog-file.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,cAAc,EAAE,MAAM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,EAAE,CAAC;YAC9H,EAAE,CAAC,aAAa,CAAC,iBAAiB,EAAE,eAAe,CAAC,CAAC;QACvD,CAAC;aAAM,CAAC;YACN,MAAM,aAAa,GAAG,KAAK,WAAW,IAAI,cAAc,GAAG,aAAa,EAAE,CAAC;YAC3E,mBAAmB,CAAC,iBAAiB,EAAE,aAAa,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC;QAC/F,CAAC;IACH,CAAC;SAAM,CAAC;QACN,MAAM,aAAa,GAAG,KAAK,WAAW,IAAI,cAAc,GAAG,aAAa,EAAE,CAAC;QAC3E,mBAAmB,CAAC,iBAAiB,EAAE,aAAa,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC;IAC/F,CAAC;AACH,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@release-change/release-notes-generator",
3
+ "version": "0.1.0",
4
+ "description": "Functions used internally in release-change to prepare and generate release notes",
5
+ "keywords": [],
6
+ "homepage": "https://github.com/release-change/release-change",
7
+ "bugs": {
8
+ "url": "https://github.com/release-change/release-change/issues"
9
+ },
10
+ "author": "Victor Brito (https://victor-brito.dev)",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/release-change/release-change.git"
14
+ },
15
+ "type": "module",
16
+ "license": "MIT",
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "exports": {
21
+ "import": "./dist/index.js",
22
+ "types": "./dist/index.d.ts"
23
+ },
24
+ "engines": {
25
+ "node": "^20.18.3 || ^22.12.0 || ^24.0.0",
26
+ "npm": ">=10.8.2",
27
+ "pnpm": ">=10.28.0"
28
+ },
29
+ "dependencies": {
30
+ "@release-change/ci": "0.1.0",
31
+ "@release-change/commit-analyser": "0.1.0",
32
+ "@release-change/get-packages": "0.1.0",
33
+ "@release-change/github": "0.1.0",
34
+ "@release-change/logger": "0.1.0",
35
+ "@release-change/shared": "0.1.0"
36
+ },
37
+ "scripts": {
38
+ "build": "tsc",
39
+ "dev": "tsc --watch --preserveWatchOutput & vitest"
40
+ }
41
+ }