Skip to content

Commit b8d8ff6

Browse files
committed
Fix changelogs
1 parent eb58131 commit b8d8ff6

File tree

6 files changed

+8
-499
lines changed

6 files changed

+8
-499
lines changed

apps/website/changelog/cli.mjs

Lines changed: 7 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@ import glob from 'glob';
22
import { readFile, writeFile } from 'node:fs/promises';
33
import { promisify } from 'node:util';
44
import { markdown } from 'markdown';
5-
import { format } from 'prettier';
6-
import { NodeHtmlMarkdown } from 'node-html-markdown';
7-
import { parseSemVer, compareSemVer } from 'semver-parser';
85
import { resolve } from 'node:path';
96

10-
import { excludeTrashUpdates, groupByVersions } from './lib.mjs';
11-
127
const files = await promisify(glob)(
138
'../../{packages,deleted_packages}/*/CHANGELOG.md',
149
{
@@ -24,142 +19,18 @@ const changelogs = await Promise.all(
2419
)
2520
);
2621

27-
for (const [release, changelog] of mergeChangelogs(changelogs).entries()) {
28-
const md = await renderChangelog(changelog);
29-
30-
const releaseFile = release.replaceAll('.', '-');
31-
const filePath = resolve('docs/releases', `${releaseFile}.changelog.md`);
22+
for (const { name, content } of changelogs) {
23+
const filePath = resolve('docs', name, 'CHANGELOG.md');
3224

33-
await writeFile(filePath, md);
25+
await writeFile(filePath, content);
3426
}
3527

3628
// --- // ---
3729

38-
async function renderChangelog(tree) {
39-
return makeLinksOnCommits(
40-
await format(
41-
NodeHtmlMarkdown.translate(
42-
markdown.renderJsonML(markdown.toHTMLTree(tree))
43-
),
44-
{
45-
parser: 'markdown',
46-
}
47-
)
48-
);
49-
}
50-
51-
function mergeChangelogs(packages) {
52-
const releases = new Set(
53-
Object.values(packages)
54-
.flatMap(({ changes }) => Object.keys(changes))
55-
.map(getRelease)
56-
);
57-
58-
const log = new Map();
59-
60-
for (const release of releases) {
61-
const currentLog = [[]];
62-
63-
const relatedChanges = packages
64-
.map(({ name, changes }) => ({
65-
name,
66-
changes: Object.fromEntries(
67-
Object.entries(changes).filter(
68-
([version]) => getRelease(version) === release
69-
)
70-
),
71-
}))
72-
.filter(({ changes }) => Object.keys(changes).length > 0);
73-
74-
currentLog.push(['header', { level: 2 }, 'Full changelog']);
75-
for (const { version, packages } of groupByVersions(relatedChanges).sort(
76-
({ version: v1 }, { version: v2 }) => -compareSemVer(v1, v2)
77-
)) {
78-
const logForVersion = [];
79-
for (const { name: packageName, changes: packageChanges } of packages) {
80-
const pacakgeChangesEntries = Object.entries(packageChanges)
81-
.map(([type, items]) => [type, excludeTrashUpdates(items)])
82-
.filter(([, items]) => items.length > 0);
83-
84-
let hasChanges = pacakgeChangesEntries.length > 0;
85-
86-
if (!hasChanges) {
87-
continue;
88-
}
89-
90-
logForVersion.push(['para', `::: details ${packageName}`]);
91-
92-
for (const [type, items] of pacakgeChangesEntries) {
93-
logForVersion.push(['para', ['strong', type]], ...items);
94-
}
95-
96-
logForVersion.push(['para', ':::']);
97-
}
98-
99-
if (logForVersion.length > 0) {
100-
currentLog.push(['header', { level: 3 }, version]);
101-
currentLog.push(...logForVersion);
102-
}
103-
}
104-
105-
log.set(release, currentLog);
106-
}
107-
108-
return log;
109-
}
110-
111-
async function parseChangelog(md) {
112-
const [_1, header, ...rest] = markdown.parse(md);
30+
async function parseChangelog(content) {
31+
const [_1, header] = markdown.parse(content);
11332

114-
const name = header.at(2);
115-
116-
const versions = groupByLevel(2, rest);
117-
118-
const changes = {};
119-
for (const [version, content] of Object.entries(versions)) {
120-
changes[version] = groupByLevel(3, content);
121-
}
122-
123-
return { name, changes };
124-
}
125-
126-
function groupByLevel(targetLevel, data) {
127-
const groups = {};
128-
129-
let currentGroup;
130-
for (const item of data) {
131-
const { level } = item.at(1);
132-
133-
if (level === targetLevel) {
134-
const group = item.at(2);
135-
currentGroup = group;
136-
} else {
137-
if (!groups[currentGroup]) {
138-
continue;
139-
}
140-
groups[currentGroup].push(item);
141-
}
142-
}
143-
144-
return groups;
145-
}
146-
147-
function getRelease(version) {
148-
const { major, minor } = parseSemVer(version);
149-
150-
return `${major}.${minor}`;
151-
}
152-
153-
function makeLinksOnCommits(content) {
154-
function linkToCommit(commitHash) {
155-
return `[${commitHash}](https://github.com/igorkamyshev/farfetched/commit/${commitHash})`;
156-
}
157-
158-
function replacer(all, commitHash) {
159-
return all.replace(commitHash, linkToCommit(commitHash));
160-
}
33+
const name = header.at(2).replace('@withease/', '');
16134

162-
return content
163-
.replaceAll(/- ([0-9a-f]{7}):/gi, replacer)
164-
.replaceAll(/\\\[([0-9a-f]{7})\\\]/gi, replacer);
35+
return { name, content };
16536
}

apps/website/changelog/lib.mjs

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)