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

feat(@142vip/changelog): 移除@antfu/utils模块,采用原生ts实现函数功能 #53

Merged
merged 1 commit into from
Aug 9, 2024
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
1 change: 0 additions & 1 deletion packages/changelog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@antfu/utils": "^0.7.10",
"@esm2cjs/execa": "6.1.1-cjs.1",
"c12": "^1.11.1",
"changelogen": "0.5.5",
Expand Down
5 changes: 3 additions & 2 deletions packages/changelog/src/core/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { blue, bold, cyan, dim, red, yellow } from 'kolorist'
import { Command } from 'commander'
import type { GitCommit, RawGitCommit } from 'changelogen'
import { getGitDiff, parseGitCommit } from 'changelogen'
import { notNullish } from '@antfu/utils'
import { name as packageName, version as packageVersion } from '../../package.json'
import {
generateMarkdown,
Expand Down Expand Up @@ -71,7 +70,9 @@ async function resolveConfig(options: ChangelogOptions) {
* @param config
*/
function parseCommits(commits: RawGitCommit[], config: ChangelogEnOptions): GitCommit[] {
return commits.map(commit => parseGitCommit(commit, config)).filter(notNullish)
return commits
.map(commit => parseGitCommit(commit, config))
.filter(v => v != null)
}

/**
Expand Down
39 changes: 19 additions & 20 deletions packages/changelog/src/utils/github.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { $fetch } from 'ofetch'
import { cyan, green, red, yellow } from 'kolorist'
import { notNullish } from '@antfu/utils'
import qs from 'qs'
import type {
AuthorInfo,
ChangelogOptions,
Commit,
} from '../types/changelog.interface'
} from '../types'

export async function sendRelease(
options: ChangelogOptions,
Expand Down Expand Up @@ -37,7 +36,7 @@
prerelease: options.prerelease,
tag_name: options.to,
}
console.log(cyan(method === 'POST'

Check warning on line 39 in packages/changelog/src/utils/github.ts

View workflow job for this annotation

GitHub Actions / 基础编译构建

Unexpected console statement
? 'Creating release notes...'
: 'Updating release notes...'),
)
Expand All @@ -46,7 +45,7 @@
body: JSON.stringify(body),
headers,
})
console.log(green(`Released on ${res.html_url}`))

Check warning on line 48 in packages/changelog/src/utils/github.ts

View workflow job for this annotation

GitHub Actions / 基础编译构建

Unexpected console statement
}

function getHeaders(options: ChangelogOptions) {
Expand Down Expand Up @@ -92,30 +91,30 @@
export async function resolveAuthors(commits: Commit[], options: ChangelogOptions) {
const map = new Map<string, AuthorInfo>()
commits.forEach((commit) => {
commit.resolvedAuthors = commit.authors.map((a, idx) => {
if (!a.email || !a.name)
return null
if (!map.has(a.email)) {
map.set(a.email, {
commits: [],
name: a.name,
email: a.email,
})
}
const info = map.get(a.email)!

// record commits only for the first author
if (idx === 0)
info.commits.push(commit.shortHash)

return info
}).filter(notNullish)
commit.resolvedAuthors = commit.authors
.map((a, idx) => {
if (!a.email || !a.name)
return null
if (!map.has(a.email)) {
map.set(a.email, { commits: [], name: a.name, email: a.email })
}
const info = map.get(a.email)!

// record commits only for the first author
if (idx === 0)
info.commits.push(commit.shortHash)

return info
})
.filter(v => v != null)
})

const authors = Array.from(map.values())
const resolved = await Promise.all(authors.map(info => resolveAuthorInfo(options, info)))

const loginSet = new Set<string>()
const nameSet = new Set<string>()

return resolved
.sort((a, b) => (a.login || a.name).localeCompare(b.login || b.name))
.filter((i) => {
Expand Down
9 changes: 6 additions & 3 deletions packages/changelog/src/utils/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { existsSync, promises as fsp } from 'node:fs'
import { partition } from '@antfu/utils'
import type { Reference } from 'changelogen'
import { convert } from 'convert-gitmoji'
import dayjs from 'dayjs'
import type { Commit, ResolvedChangelogOptions } from '../types/changelog.interface'
import type { Commit, ResolvedChangelogOptions } from '../types'

const emojisRE = /([\u2700-\u27BF\uE000-\uF8FF\u2011-\u26FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|\uD83E[\uDD10-\uDDFF])/g

Expand Down Expand Up @@ -118,7 +117,8 @@
export async function generateMarkdown(commits: Commit[], options: ResolvedChangelogOptions) {
const lines: string[] = []

const [breaking, changes] = partition(commits, c => c.isBreaking)
const breaking = commits.filter(c => c.isBreaking)
const changes = commits.filter(c => !c.isBreaking)

const group = groupBy(changes, 'type')

Expand Down Expand Up @@ -164,11 +164,11 @@
export async function updateChangelog(outputPath: string, markdown: string, releaseVersionName: string) {
let changelogMD: string
if (existsSync(outputPath)) {
console.info(`Updating ${outputPath}`)

Check warning on line 167 in packages/changelog/src/utils/markdown.ts

View workflow job for this annotation

GitHub Actions / 基础编译构建

Unexpected console statement
changelogMD = await fsp.readFile(outputPath, 'utf8')
}
else {
console.info(`Creating ${outputPath}`)

Check warning on line 171 in packages/changelog/src/utils/markdown.ts

View workflow job for this annotation

GitHub Actions / 基础编译构建

Unexpected console statement
changelogMD = '# Changelog\n\nAll notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.\n'
}

Expand All @@ -187,6 +187,9 @@
await fsp.writeFile(outputPath, changelogMD, 'utf-8')
}

/**
* 分组
*/
function groupBy<T>(items: T[], key: string, groups: Record<string, T[]> = {}) {
for (const item of items) {
const v = (item as any)[key] as string
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading