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) {
|
for (const commit of commits) {
|
||||||
const tag =
|
const tag =
|
||||||
sort((await simpleGit().tags([`--contains=${commit.hash}`])).all)[0]! ||
|
(commit.refs.match(/tag: (\S+)(?:,|$)/)?.[1] ?? lastTag) || unreleased;
|
||||||
unreleased;
|
|
||||||
|
|
||||||
const currentCommitStack = parsedCommitStacks.find(
|
let currentCommitStackIndex = parsedCommitStacks.findIndex(
|
||||||
(commitStack) => commitStack.version === tag,
|
(commitStack) => commitStack.version === tag,
|
||||||
) || {
|
);
|
||||||
|
|
||||||
|
if (currentCommitStackIndex === -1) {
|
||||||
|
parsedCommitStacks.push({
|
||||||
version: tag || unreleased,
|
version: tag || unreleased,
|
||||||
breaking: [],
|
breaking: [],
|
||||||
features: [],
|
features: [],
|
||||||
fixes: [],
|
fixes: [],
|
||||||
miscellaneous: [],
|
miscellaneous: [],
|
||||||
};
|
});
|
||||||
|
|
||||||
if (lastTag !== tag) {
|
currentCommitStackIndex = parsedCommitStacks.findIndex(
|
||||||
parsedCommitStacks = [currentCommitStack, ...parsedCommitStacks];
|
(commitStack) => commitStack.version === tag,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commit.message.includes("!:")) {
|
if (commit.message.includes("!:")) {
|
||||||
parsedCommitStacks = [
|
parsedCommitStacks[currentCommitStackIndex].breaking.push(commit);
|
||||||
{
|
|
||||||
...currentCommitStack,
|
|
||||||
breaking: [...currentCommitStack.breaking, commit],
|
|
||||||
},
|
|
||||||
...parsedCommitStacks.filter(
|
|
||||||
(commitStack) => commitStack.version !== tag,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
} else if (commit.message.startsWith("feat")) {
|
} else if (commit.message.startsWith("feat")) {
|
||||||
parsedCommitStacks = [
|
parsedCommitStacks[currentCommitStackIndex].features.push(commit);
|
||||||
{
|
|
||||||
...currentCommitStack,
|
|
||||||
features: [...currentCommitStack.features, commit],
|
|
||||||
},
|
|
||||||
...parsedCommitStacks.filter(
|
|
||||||
(commitStack) => commitStack.version !== tag,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
} else if (commit.message.startsWith("fix")) {
|
} else if (commit.message.startsWith("fix")) {
|
||||||
parsedCommitStacks = [
|
parsedCommitStacks[currentCommitStackIndex].fixes.push(commit);
|
||||||
{
|
|
||||||
...currentCommitStack,
|
|
||||||
fixes: [...currentCommitStack.fixes, commit],
|
|
||||||
},
|
|
||||||
...parsedCommitStacks.filter(
|
|
||||||
(commitStack) => commitStack.version !== tag,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
} else {
|
} else {
|
||||||
parsedCommitStacks = [
|
parsedCommitStacks[currentCommitStackIndex].miscellaneous.push(commit);
|
||||||
{
|
|
||||||
...currentCommitStack,
|
|
||||||
miscellaneous: [...currentCommitStack.miscellaneous, commit],
|
|
||||||
},
|
|
||||||
...parsedCommitStacks.filter(
|
|
||||||
(commitStack) => commitStack.version !== tag,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lastTag = tag;
|
lastTag = tag;
|
||||||
|
|||||||
Reference in New Issue
Block a user