Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: changeset release #1627

Merged
merged 4 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .changeset/modern-buckets-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
'@milkdown/components': minor
'@milkdown/core': minor
'@milkdown/crepe': minor
'@milkdown/ctx': minor
'@milkdown/exception': minor
'@milkdown/react': minor
'@milkdown/vue': minor
'@milkdown/kit': minor
'@milkdown/plugin-automd': minor
'@milkdown/plugin-block': minor
'@milkdown/plugin-clipboard': minor
'@milkdown/plugin-collab': minor
'@milkdown/plugin-cursor': minor
'@milkdown/plugin-diagram': minor
'@milkdown/plugin-emoji': minor
'@milkdown/plugin-history': minor
'@milkdown/plugin-indent': minor
'@milkdown/plugin-listener': minor
'@milkdown/plugin-prism': minor
'@milkdown/plugin-slash': minor
'@milkdown/plugin-tooltip': minor
'@milkdown/plugin-trailing': minor
'@milkdown/plugin-upload': minor
'@milkdown/preset-commonmark': minor
'@milkdown/preset-gfm': minor
'@milkdown/theme-nord': minor
'@milkdown/prose': minor
'@milkdown/transformer': minor
'@milkdown/utils': minor
---

Minor version release for milkdown.

## Feat

- feat: 🎸 add `on` api for crepe (#1622)
- feat: add markdown inspector in storybook (#1619)
- feat: add latex feature for crepe (#1613)

## Chore

- chore: use kit in integrations (#1626)
- chore: bump prosemirror versions (#1621)
- chore: remove math plugin since we provides latex in crepe (#1617)
- chore: remove husky install since it's deprecated (#1616)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"ci:publish": "pnpm build:packs && pnpm publish --access public -r --no-git-checks --tag latest",
"graph": "nx dep-graph",
"clear": "rimraf 'packages/*/{lib,tsconfig.tsbuildinfo,node_modules,.rollup.cache}' && rimraf node_modules",
"changeset": "changeset",
"changeset": "changeset && node scripts/changelog.mjs",
"release": "changeset publish",
"commit": "git-cz",
"prepare": "husky",
Expand Down
121 changes: 121 additions & 0 deletions scripts/changelog.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/* oxlint-disable no-console */
import { execSync } from 'child_process'
import { appendFileSync, readdirSync, existsSync } from 'fs'
import { join, basename } from 'path'

const commitTypes = [
'feat',
'fix',
'chore',
'docs',
'style',
'refactor',
'perf',
'test',
'build',
'ci',
'other',
]

const commits = {}
commitTypes.forEach((type) => {
commits[type] = []
})

const processLogChunk = (log) => {
const logLines = log.split('\n')

for (const line of logLines) {
if (line.includes('chore: version packages')) {
return false
}

const match = line.match(/^(\w+)(?:\(.+\))?:\s/)

if (match && commitTypes.includes(match[1])) {
commits[match[1]].push(line)
} else {
commits['other'].push(line)
}
}

return true
}

const readGitLogInChunks = async (chunkSize = 20) => {
let skip = 0
let moreLogs = true

while (moreLogs) {
const logChunk = execSync(
`git --no-pager log --pretty=format:"%s" --skip=${skip} -n ${chunkSize}`,
{
encoding: 'utf-8',
}
)

if (!logChunk) {
break
}

moreLogs = processLogChunk(logChunk)
skip += chunkSize
}
}

const generateMarkdown = (commitGroups) => {
let markdown = ''

for (const [type, messages] of Object.entries(commitGroups)) {
if (messages.length > 0) {
const capitalizedType = type.charAt(0).toUpperCase() + type.slice(1)
markdown += `## ${capitalizedType}\n\n`
messages.forEach((msg) => {
markdown += `- ${msg}\n`
})
markdown += '\n'
}
}

return markdown
}

const getChangesetFile = () => {
const filePattern = /^[a-z]+-[a-z]+-[a-z]+\.md$/
const gitRoot = execSync('git rev-parse --show-toplevel', {
encoding: 'utf-8',
}).trim()
const changesetDir = join(gitRoot, '.changeset')

if (!existsSync(changesetDir)) {
console.error('The .changeset directory does not exist.')
process.exit(1)
}

const files = readdirSync(changesetDir)
const targetFile = files.find((file) => filePattern.test(file))

return targetFile ? join(changesetDir, targetFile) : null
}

readGitLogInChunks()
.then(() => {
const changesetFilePath = getChangesetFile()
const markdownContent = generateMarkdown(commits)

if (!changesetFilePath) {
console.warn('No changeset file found. Outputting to console instead.')
console.log(markdownContent)
process.exit(1)
} else {
appendFileSync(changesetFilePath, markdownContent)

console.log(
`Changelog has been appended to ${basename(changesetFilePath)}`
)
}
})
.catch((err) => {
console.error('An error occurred while processing the git log.', err)
process.exit(1)
})
Loading