forked from unjs/changelogen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.ts
122 lines (111 loc) · 3.07 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { resolve } from 'node:path'
import { loadConfig, setupDotenv } from 'c12'
import { getCurrentGitRef, getLastGitTag } from './git'
import { getRepoConfig, resolveRepoConfig } from './repo'
import type { SemverBumpType } from './semver'
import type { RepoConfig, RepoProvider } from './repo'
export interface ChangelogConfig {
cwd: string
types: Record<string, { title: string, semver?: SemverBumpType }>
scopeMap: Record<string, string>
repo?: RepoConfig | string
tokens: Partial<Record<RepoProvider, string>>
from: string
to: string
newVersion?: string
output: string | boolean
publish: {
args?: string[]
tag?: string
private?: boolean
}
templates: {
commitMessage?: string
tagMessage?: string
tagBody?: string
}
excludeAuthors: string[]
}
export type ResolvedChangelogConfig = Omit<ChangelogConfig, 'repo'> & {
repo: RepoConfig
}
const defaultOutput = 'CHANGELOG.md'
function getDefaultConfig() {
return <ChangelogConfig>{
types: {
feat: { title: '🚀 Enhancements', semver: 'minor' },
perf: { title: '🔥 Performance', semver: 'patch' },
fix: { title: '🩹 Fixes', semver: 'patch' },
refactor: { title: '💅 Refactors', semver: 'patch' },
docs: { title: '📖 Documentation', semver: 'patch' },
build: { title: '📦 Build', semver: 'patch' },
types: { title: '🌊 Types', semver: 'patch' },
chore: { title: '🏡 Chore' },
examples: { title: '🏀 Examples' },
test: { title: '✅ Tests' },
style: { title: '🎨 Styles' },
ci: { title: '🤖 CI' },
},
cwd: null,
from: '',
to: '',
output: defaultOutput,
scopeMap: {},
tokens: {
github:
process.env.CHANGELOGEN_TOKENS_GITHUB
|| process.env.GITHUB_TOKEN
|| process.env.GH_TOKEN,
},
publish: {
private: false,
tag: 'latest',
args: [],
},
templates: {
commitMessage: 'chore(release): v{{newVersion}}',
tagMessage: 'v{{newVersion}}',
tagBody: 'v{{newVersion}}',
},
excludeAuthors: [],
}
}
export async function loadChangelogConfig(
cwd: string,
overrides?: Partial<ChangelogConfig>,
): Promise<ResolvedChangelogConfig> {
await setupDotenv({ cwd })
const defaults = getDefaultConfig()
const { config } = await loadConfig<ChangelogConfig>({
cwd,
name: 'changelog',
packageJson: true,
defaults,
overrides: {
cwd,
...(overrides as ChangelogConfig),
},
})
return await resolveChangelogConfig(config, cwd)
}
export async function resolveChangelogConfig(
config: ChangelogConfig,
cwd: string,
) {
if (!config.from)
config.from = await getLastGitTag()
if (!config.to)
config.to = await getCurrentGitRef()
if (config.output) {
config.output
= config.output === true ? defaultOutput : resolve(cwd, config.output)
}
else {
config.output = false
}
if (!config.repo)
config.repo = await resolveRepoConfig(cwd)
if (typeof config.repo === 'string')
config.repo = getRepoConfig(config.repo)
return config as ResolvedChangelogConfig
}