diff --git a/tools/tasks/changelog/generateModChanges.ts b/tools/tasks/changelog/generateModChanges.ts index ccf7476..2108e3d 100644 --- a/tools/tasks/changelog/generateModChanges.ts +++ b/tools/tasks/changelog/generateModChanges.ts @@ -7,6 +7,7 @@ import mustache from "mustache"; import { defaultIndentation, modChangesAllocations, repoLink } from "./definitions"; import ChangelogData from "./changelogData"; import { SpecialChangelogFormatting } from "../../types/changelogTypes"; +import { sortCommitListReverse } from "./pusher"; /** * Mod Changes special formatting @@ -83,6 +84,9 @@ export default async function generateModChanges(data: ChangelogData): Promise${data.releaseType} (${date})`, ""); + // noinspection HtmlDeprecatedAttribute + data.builder.push(`

${data.releaseType} (${date})

`, ""); } else { // noinspection HtmlUnknownAttribute data.builder.push(`

${data.releaseType} ${data.to}

`, ""); + data.builder.push("{{{ CF_REDIRECT }}}", ""); } - data.builder.push("{{{ CF_REDIRECT }}}", ""); data.builder.push(`# Changes Since ${data.since}`, ""); // Push Sections of Changelog @@ -107,7 +108,7 @@ function pushCategory(category: Category) { * Sorts a list that contains commit data * @param list A list of type T that contains commit data * @param transform A function to turn each element of type T into an element of type Commit - * @param backup A backup sort, to call when either element does not have a commit object, or when the commit objects' times are the same. Optional, if not set, will just return 0 (equal). + * @param backup A backup sort, to call when either element does not have a commit object, or when the commit objects' times are the same. Optional, if not set, will just return 0 (equal) or will compare commit messages. */ function sortCommitList(list: T[], transform: (obj: T) => Commit | undefined, backup?: (a: T, b: T) => number) { list.sort((a, b): number => { @@ -128,6 +129,20 @@ function sortCommitList(list: T[], transform: (obj: T) => Commit | undefined, }); } +/** + * Sorts a commits list so that newest commits are on the bottom. + * @param list The commit list. + */ +export function sortCommitListReverse(list: Commit[]) { + list.sort((a, b) => { + const dateA = new Date(a.date); + const dateB = new Date(b.date); + + if (dateB.getTime() - dateA.getTime() !== 0) return dateA.getTime() - dateB.getTime(); + return a.message.localeCompare(b.message); + }); +} + /** * Formats a Changelog Message * @param changelogMessage The message to format. @@ -154,7 +169,10 @@ function formatChangelogMessage(changelogMessage: ChangelogMessage, subMessage = if (changelogMessage.commitObject && !subMessage) { if (data.combineList.has(changelogMessage.commitObject.hash)) { const commits = data.combineList.get(changelogMessage.commitObject.hash); - commits.unshift(changelogMessage.commitObject); + commits.push(changelogMessage.commitObject); + + // Sort original array so newest commits appear at the end instead of start of commit string + sortCommitListReverse(commits); const formattedCommits: string[] = []; const authors: string[] = [];