|
| 1 | +// https://github.com/ariakit/ariakit/blob/main/.changeset/changelog.cjs |
| 2 | +// MIT License, Copyright (c) Diego Haz |
| 3 | + |
| 4 | +/** @type {import("@changesets/types").ChangelogFunctions["getDependencyReleaseLine"]} */ |
| 5 | +async function getDependencyReleaseLine(_, dependenciesUpdated) { |
| 6 | + if (dependenciesUpdated.length === 0) return ''; |
| 7 | + const updatedDepenenciesList = dependenciesUpdated.map( |
| 8 | + (dependency) => `\`${dependency.name}@${dependency.newVersion}\``, |
| 9 | + ); |
| 10 | + return `- Updated dependencies: ${updatedDepenenciesList.join(', ')}`; |
| 11 | +} |
| 12 | + |
| 13 | +/** @type {import("@changesets/types").ChangelogFunctions["getReleaseLine"]} */ |
| 14 | +async function getReleaseLine(changeset) { |
| 15 | + const [firstLine, ...nextLines] = changeset.summary.split('\n').map((l) => l.trimEnd()); |
| 16 | + |
| 17 | + if (!nextLines.length) return `- ${firstLine}`; |
| 18 | + |
| 19 | + return `### ${firstLine}\n${nextLines.join('\n')}`; |
| 20 | +} |
| 21 | + |
| 22 | +/** |
| 23 | + * @param {Array<Promise<string>} changelogLines |
| 24 | + */ |
| 25 | +async function getChangelogText(changelogLines) { |
| 26 | + const lines = await Promise.all(changelogLines); |
| 27 | + if (!lines.length) return ''; |
| 28 | + |
| 29 | + const isOverviewLine = (l) => l.startsWith('### Overview\n'); |
| 30 | + const isHeadingLine = (l) => l.startsWith('###'); |
| 31 | + const isOtherLine = (l) => !l.startsWith('###'); |
| 32 | + |
| 33 | + const headingLines = lines |
| 34 | + .filter(isHeadingLine) |
| 35 | + .sort((a, b) => { |
| 36 | + if (isOverviewLine(a)) return -1; |
| 37 | + if (isOverviewLine(b)) return 1; |
| 38 | + return 0; |
| 39 | + }) |
| 40 | + .map((l) => l.replace('### Overview\n\n', '')); |
| 41 | + |
| 42 | + const otherLines = lines.filter(isOtherLine); |
| 43 | + if (!headingLines.length && !otherLines.length) return ''; |
| 44 | + |
| 45 | + const other = otherLines.join('\n'); |
| 46 | + if (!headingLines.length) return other; |
| 47 | + |
| 48 | + const heading = headingLines.join('\n\n'); |
| 49 | + if (!otherLines.length) return heading; |
| 50 | + |
| 51 | + return `${heading}\n\n### Other updates\n\n${other}`; |
| 52 | +} |
| 53 | + |
| 54 | +/** |
| 55 | + * @param {import("@changesets/types").ModCompWithPackage} release |
| 56 | + * @param {Record<"major" | "minor" | "patch", Array<Promise<string>>} changelogLines |
| 57 | + */ |
| 58 | +async function getChangelogEntry(release, changelogLines) { |
| 59 | + // const date = new Date().toLocaleDateString("en-US", { |
| 60 | + // month: "long", |
| 61 | + // day: "numeric", |
| 62 | + // year: "numeric", |
| 63 | + // }); |
| 64 | + const text = await getChangelogText(Object.values(changelogLines).flat()); |
| 65 | + return `## ${release.newVersion}\n\n${text}`; |
| 66 | +} |
| 67 | + |
| 68 | +module.exports = { |
| 69 | + getDependencyReleaseLine, |
| 70 | + getReleaseLine, |
| 71 | + getChangelogEntry, |
| 72 | +}; |
0 commit comments