引入
ts
import {
insertDocChangeLog,
parseChangelog,
filterStableVersions,
rebuildChangelog,
cleanChangelogFile,
resolveGlobPatterns,
cleanChangelogScript
} from 't-comm';
// 不支持 tree-shaking 的项目
import {
insertDocChangeLog,
parseChangelog,
filterStableVersions,
rebuildChangelog,
cleanChangelogFile,
resolveGlobPatterns,
cleanChangelogScript
} from 't-comm/lib/change-log/index';
// 只支持 ESM 的项目
import {
insertDocChangeLog,
parseChangelog,
filterStableVersions,
rebuildChangelog,
cleanChangelogFile,
resolveGlobPatterns,
cleanChangelogScript
} from 't-comm/es/change-log/index';insertDocChangeLog(params)
描述:
同步最新版本的更新日志
参数:
| 参数名 | 类型 | 描述 |
|---|---|---|
| params | object | 参数 |
| params.changelogPath | string | 源 change-log路径 |
| params.docChangelogPath | string | 文档 change-log 路径 |
| params.packageJsonPath | string | package.json 路径 |
示例
ts
const DOC_CHANGE_LOG_PATH = './docs/CHANGELOG.md';
const SOURCE_CHANGE_LOG_PATH = './CHANGELOG.md';
insertDocChangeLog({
changelogPath: SOURCE_CHANGE_LOG_PATH,
docChangeLog: DOC_CHANGE_LOG_PATH,
packageJsonPath: './package.json',
});parseChangelog(content)
描述:
解析 CHANGELOG 文件,将其分割为多个版本块
参数:
| 参数名 | 类型 |
|---|---|
| content | string |
filterStableVersions(sections)
描述:
过滤掉 alpha/beta 版本,只保留正式版本
参数:
| 参数名 | 类型 |
|---|---|
| sections | Array |
rebuildChangelog(preamble, sections)
描述:
将 sections 重新组合为 changelog 内容
参数:
| 参数名 | 类型 |
|---|---|
| preamble | Array<string> |
| sections | Array |
cleanChangelogFile(filePath, dryRun)
描述:
清理单个 CHANGELOG 文件
参数:
| 参数名 | 类型 |
|---|---|
| filePath | string |
| dryRun | boolean |
返回: boolean
是否成功
resolveGlobPatterns(pattern)
描述:
解析 glob 表达式,返回匹配的文件列表
参数:
| 参数名 | 类型 |
|---|---|
| pattern | string |
cleanChangelogScript()
描述:
主函数
参数: