Skip to content

Commit 1f14e3c

Browse files
authored
feat(@142vip/changelog): 使用loadCliConfig加载配置,脚手架增加ch命令入口 (#418)
1 parent cf94325 commit 1f14e3c

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

packages/changelog/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"module": "./dist/index.mjs",
4242
"types": "./dist/index.d.ts",
4343
"bin": {
44-
"changelog": "./cli.mjs"
44+
"changelog": "./cli.mjs",
45+
"ch": "./cli.mjs"
4546
},
4647
"files": [
4748
"*.mjs",

packages/changelog/src/config.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ChangelogCliOptions, ChangelogGenerateOptions } from './changelog.interface'
2-
import { VipGit, VipLodash } from '@142vip/utils'
2+
import { VipConfig, VipGit } from '@142vip/utils'
33

44
/**
55
* 默认配置
@@ -34,17 +34,25 @@ export const ChangelogDefaultConfig = {
3434
* 将用户自定义配置和默认配置合并
3535
*/
3636
export async function mergeConfig(cliOptions: ChangelogCliOptions): Promise<ChangelogGenerateOptions> {
37-
const { loadConfig } = await import('c12')
37+
// const { loadConfig } = await import('c12')
3838

3939
// 本地配置,形如:changelog.config.ts
40-
const changelogConfig = await loadConfig<ChangelogGenerateOptions>({
41-
// 配置文件名,eg: changelog.config.ts
42-
name: 'changelog',
40+
// const changelogConfig = await loadConfig<ChangelogGenerateOptions>({
41+
// // 配置文件名,eg: changelog.config.ts
42+
// name: 'changelog',
43+
// packageJson: true,
44+
// }).then(c => VipLodash.merge({}, ChangelogDefaultConfig, c.config))
45+
46+
// cli配置合并
47+
// const config = VipLodash.merge({}, changelogConfig, cliOptions) as ChangelogGenerateOptions
48+
49+
// 新写法
50+
const changelogConfig = await VipConfig.loadCliConfig<ChangelogGenerateOptions>('changelog', ChangelogDefaultConfig, {
4351
packageJson: true,
44-
}).then(c => VipLodash.merge({}, ChangelogDefaultConfig, c.config))
52+
})
4553

4654
// cli配置合并
47-
const config = VipLodash.merge({}, changelogConfig, cliOptions) as ChangelogGenerateOptions
55+
const config = VipConfig.mergeCommanderConfig<ChangelogGenerateOptions>(changelogConfig, cliOptions)
4856

4957
// 发布的版本
5058
if (config.to == null) {

0 commit comments

Comments
 (0)