|
| 1 | +/** |
| 2 | + * Custom semantic-release writer options for dev-rel friendly release notes. |
| 3 | + * |
| 4 | + * Replaces the spartan angular-preset output with: |
| 5 | + * - a hero banner that surfaces in the GitHub releases feed (OG-image style) |
| 6 | + * - emoji-grouped commit sections (✨ Features, 🐛 Bug Fixes, ⚡ Performance, …) |
| 7 | + * - install / update commands keyed to the published version |
| 8 | + * - community CTAs (Discord, docs, stars, issues) |
| 9 | + * |
| 10 | + * Used by release.config.mjs and tested in |
| 11 | + * tests/unit/scripts/release-notes-template.test.ts. |
| 12 | + * |
| 13 | + * The exported writerOpts is merged on top of conventional-changelog-angular's |
| 14 | + * writerOpts by @semantic-release/release-notes-generator, so we only override |
| 15 | + * the keys we care about (transform, headerPartial, footerPartial). |
| 16 | + */ |
| 17 | + |
| 18 | +const COMMIT_HASH_LENGTH = 7; |
| 19 | + |
| 20 | +const TYPE_LABELS = { |
| 21 | + feat: '✨ Features', |
| 22 | + fix: '🐛 Bug Fixes', |
| 23 | + perf: '⚡ Performance Improvements', |
| 24 | + revert: '⏪ Reverts', |
| 25 | + refactor: '♻️ Code Refactoring', |
| 26 | +}; |
| 27 | + |
| 28 | +// Display order for the grouped sections — features lead because they are |
| 29 | +// the most attention-worthy in the GitHub feed; emoji-unicode sorting alone |
| 30 | +// would surface ⚡ Performance ahead of ✨ Features. |
| 31 | +const TYPE_DISPLAY_ORDER = [ |
| 32 | + '✨ Features', |
| 33 | + '🐛 Bug Fixes', |
| 34 | + '⚡ Performance Improvements', |
| 35 | + '♻️ Code Refactoring', |
| 36 | + '⏪ Reverts', |
| 37 | +]; |
| 38 | + |
| 39 | +function commitGroupsSort(a, b) { |
| 40 | + const aIdx = TYPE_DISPLAY_ORDER.indexOf(a.title); |
| 41 | + const bIdx = TYPE_DISPLAY_ORDER.indexOf(b.title); |
| 42 | + const aRank = aIdx === -1 ? Number.MAX_SAFE_INTEGER : aIdx; |
| 43 | + const bRank = bIdx === -1 ? Number.MAX_SAFE_INTEGER : bIdx; |
| 44 | + if (aRank !== bRank) return aRank - bRank; |
| 45 | + return String(a.title).localeCompare(String(b.title)); |
| 46 | +} |
| 47 | + |
| 48 | +export function transform(commit, context) { |
| 49 | + let discard = true; |
| 50 | + const notes = commit.notes.map((note) => { |
| 51 | + discard = false; |
| 52 | + return { ...note, title: '🚨 Breaking Changes' }; |
| 53 | + }); |
| 54 | + |
| 55 | + let type = TYPE_LABELS[commit.type]; |
| 56 | + if (!type && commit.revert) type = TYPE_LABELS.revert; |
| 57 | + if (!type && discard) return undefined; |
| 58 | + if (!type) type = commit.type; |
| 59 | + |
| 60 | + const scope = commit.scope === '*' ? '' : commit.scope; |
| 61 | + const shortHash = |
| 62 | + typeof commit.hash === 'string' |
| 63 | + ? commit.hash.substring(0, COMMIT_HASH_LENGTH) |
| 64 | + : commit.shortHash; |
| 65 | + |
| 66 | + const issues = []; |
| 67 | + let { subject } = commit; |
| 68 | + |
| 69 | + if (typeof subject === 'string') { |
| 70 | + const baseUrl = context.repository |
| 71 | + ? `${context.host}/${context.owner}/${context.repository}` |
| 72 | + : context.repoUrl; |
| 73 | + |
| 74 | + if (baseUrl) { |
| 75 | + const issueUrl = `${baseUrl}/issues/`; |
| 76 | + subject = subject.replace(/#([0-9]+)/g, (_, issue) => { |
| 77 | + issues.push(issue); |
| 78 | + return `[#${issue}](${issueUrl}${issue})`; |
| 79 | + }); |
| 80 | + } |
| 81 | + |
| 82 | + if (context.host) { |
| 83 | + subject = subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => { |
| 84 | + if (username.includes('/')) return `@${username}`; |
| 85 | + return `[@${username}](${context.host}/${username})`; |
| 86 | + }); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + const references = commit.references.filter((ref) => !issues.includes(ref.issue)); |
| 91 | + |
| 92 | + return { notes, type, scope, shortHash, subject, references }; |
| 93 | +} |
| 94 | + |
| 95 | +export const headerPartial = `<p align="center"> |
| 96 | + <a href="https://github.com/shep-ai/shep"> |
| 97 | + <img src="https://raw.githubusercontent.com/shep-ai/shep/main/docs/screenshots/shep-card.jpg" alt="Shep — run multiple AI agents in parallel" width="720" /> |
| 98 | + </a> |
| 99 | +</p> |
| 100 | +
|
| 101 | +# 🚀 Shep {{#if @root.linkCompare~}}[v{{version}}]({{~@root.repoUrl}}/compare/{{previousTag}}...{{currentTag}}){{~else}}v{{version}}{{~/if}}{{~#if title}} · {{title}}{{~/if}}{{~#if date}} · _{{date}}_{{~/if}} |
| 102 | +
|
| 103 | +> Run multiple AI agents in parallel — each in its own worktree, branch, and PR. _Zero context-switching, zero merge chaos._ |
| 104 | +
|
| 105 | +`; |
| 106 | + |
| 107 | +export const footerPartial = `{{#if noteGroups}} |
| 108 | +{{#each noteGroups}} |
| 109 | +
|
| 110 | +### {{title}} |
| 111 | +
|
| 112 | +{{#each notes}} |
| 113 | +* {{#if commit.scope}}**{{commit.scope}}:** {{/if}}{{text}} |
| 114 | +{{/each}} |
| 115 | +{{/each}} |
| 116 | +
|
| 117 | +{{/if}} |
| 118 | +## 📦 Install or update |
| 119 | +
|
| 120 | +\`\`\`bash |
| 121 | +# upgrade an existing install |
| 122 | +npm i -g @shepai/cli@{{version}} |
| 123 | +
|
| 124 | +# or run instantly without installing |
| 125 | +npx @shepai/cli@latest |
| 126 | +\`\`\` |
| 127 | +
|
| 128 | +## 💬 Join the community |
| 129 | +
|
| 130 | +[💬 **Discord**](https://discord.gg/ES6tdVFfur) · [📖 **Docs**](https://github.com/shep-ai/shep#readme) · [⭐ **Star on GitHub**](https://github.com/shep-ai/shep) · [🐛 **Report an issue**](https://github.com/shep-ai/shep/issues) |
| 131 | +
|
| 132 | +--- |
| 133 | +
|
| 134 | +<sub>🤖 Released autonomously by Shep — built by parallel AI agents working in isolated git worktrees. Try it: \`npx @shepai/cli\`</sub> |
| 135 | +`; |
| 136 | + |
| 137 | +export const writerOpts = { |
| 138 | + transform, |
| 139 | + groupBy: 'type', |
| 140 | + commitGroupsSort, |
| 141 | + commitsSort: ['subject', 'scope'], |
| 142 | + noteGroupsSort: 'title', |
| 143 | + headerPartial, |
| 144 | + footerPartial, |
| 145 | +}; |
0 commit comments