perf(changelog): improve generation time by ~2800 times (#23)
This commit is contained in:
@@ -51,63 +51,34 @@ const command = new Command("changelog")
|
||||
|
||||
for (const commit of commits) {
|
||||
const tag =
|
||||
sort((await simpleGit().tags([`--contains=${commit.hash}`])).all)[0]! ||
|
||||
unreleased;
|
||||
(commit.refs.match(/tag: (\S+)(?:,|$)/)?.[1] ?? lastTag) || unreleased;
|
||||
|
||||
const currentCommitStack = parsedCommitStacks.find(
|
||||
let currentCommitStackIndex = parsedCommitStacks.findIndex(
|
||||
(commitStack) => commitStack.version === tag,
|
||||
) || {
|
||||
);
|
||||
|
||||
if (currentCommitStackIndex === -1) {
|
||||
parsedCommitStacks.push({
|
||||
version: tag || unreleased,
|
||||
breaking: [],
|
||||
features: [],
|
||||
fixes: [],
|
||||
miscellaneous: [],
|
||||
};
|
||||
});
|
||||
|
||||
if (lastTag !== tag) {
|
||||
parsedCommitStacks = [currentCommitStack, ...parsedCommitStacks];
|
||||
currentCommitStackIndex = parsedCommitStacks.findIndex(
|
||||
(commitStack) => commitStack.version === tag,
|
||||
);
|
||||
}
|
||||
|
||||
if (commit.message.includes("!:")) {
|
||||
parsedCommitStacks = [
|
||||
{
|
||||
...currentCommitStack,
|
||||
breaking: [...currentCommitStack.breaking, commit],
|
||||
},
|
||||
...parsedCommitStacks.filter(
|
||||
(commitStack) => commitStack.version !== tag,
|
||||
),
|
||||
];
|
||||
parsedCommitStacks[currentCommitStackIndex].breaking.push(commit);
|
||||
} else if (commit.message.startsWith("feat")) {
|
||||
parsedCommitStacks = [
|
||||
{
|
||||
...currentCommitStack,
|
||||
features: [...currentCommitStack.features, commit],
|
||||
},
|
||||
...parsedCommitStacks.filter(
|
||||
(commitStack) => commitStack.version !== tag,
|
||||
),
|
||||
];
|
||||
parsedCommitStacks[currentCommitStackIndex].features.push(commit);
|
||||
} else if (commit.message.startsWith("fix")) {
|
||||
parsedCommitStacks = [
|
||||
{
|
||||
...currentCommitStack,
|
||||
fixes: [...currentCommitStack.fixes, commit],
|
||||
},
|
||||
...parsedCommitStacks.filter(
|
||||
(commitStack) => commitStack.version !== tag,
|
||||
),
|
||||
];
|
||||
parsedCommitStacks[currentCommitStackIndex].fixes.push(commit);
|
||||
} else {
|
||||
parsedCommitStacks = [
|
||||
{
|
||||
...currentCommitStack,
|
||||
miscellaneous: [...currentCommitStack.miscellaneous, commit],
|
||||
},
|
||||
...parsedCommitStacks.filter(
|
||||
(commitStack) => commitStack.version !== tag,
|
||||
),
|
||||
];
|
||||
parsedCommitStacks[currentCommitStackIndex].miscellaneous.push(commit);
|
||||
}
|
||||
|
||||
lastTag = tag;
|
||||
|
||||
Reference in New Issue
Block a user