1
1
import { execSync } from 'node:child_process'
2
2
import process from 'node:process'
3
3
import { versionBump } from '@142vip/release-version'
4
- import { getLatestTagName } from './git'
4
+ import { getCommitLogs , getLatestTagName } from './git'
5
5
6
6
interface PackageJSON {
7
7
name : string
@@ -10,6 +10,15 @@ interface PackageJSON {
10
10
path : string
11
11
}
12
12
13
+ interface ValidatePkgJSON {
14
+ name : string
15
+ release : boolean
16
+ }
17
+ interface ValidateResponse {
18
+ release : boolean
19
+ packages : ValidatePkgJSON [ ]
20
+ }
21
+
13
22
/**
14
23
* 获取发布的包名
15
24
* 参考:
@@ -33,17 +42,15 @@ export function getReleasePkgJSON(filter?: string) {
33
42
* 提交git当前节点到上个tag的所有提交记录
34
43
* 分析、判断是否有公共模块,提醒及时对公共模块发布新的版本号
35
44
*/
36
- function validatePackage ( packageName : string , template ?: string ) {
45
+ function validatePackage ( packageNameInCommitScope : string , template ?: string ) {
37
46
const latestTag = getLatestTagName ( )
38
- const command = `git log --pretty=format:"%s" --date=short "${ latestTag } "..HEAD`
39
- const commitLogs = execSync ( command ) . toString ( ) . trim ( )
47
+ const commitLogs = getCommitLogs ( latestTag )
40
48
41
49
// 整理出git提交日志
42
- const logsByPackage = commitLogs . split ( '\n' )
43
- . filter ( commit => commit . includes ( `${ packageName } ` ) )
50
+ const logsByPackage = commitLogs . filter ( commit => commit . includes ( `(${ packageNameInCommitScope } )` ) )
44
51
45
52
// 判断是否需要发布新的版本
46
- return logsByPackage . length > 0 && ! logsByPackage [ 0 ] . includes ( template ?? `release(${ packageName } )` )
53
+ return logsByPackage . length > 0 && ! logsByPackage [ 0 ] . includes ( template ?? `release(${ packageNameInCommitScope } )` )
47
54
}
48
55
49
56
/**
@@ -57,8 +64,6 @@ export async function releaseMonorepoPackage(pkg: PackageJSON) {
57
64
const command = `pnpm --filter "${ pkg . name } " --shell-mode exec "${ rpCommand } "`
58
65
59
66
console . log ( '等价命令-->' , command )
60
- console . log ( pkg )
61
- console . log ( 'aaaa dir-->' , pkg . path )
62
67
63
68
await versionBump ( {
64
69
preid : 'alpha' ,
@@ -76,11 +81,14 @@ export async function releaseMonorepoPackage(pkg: PackageJSON) {
76
81
} )
77
82
}
78
83
79
- export function validateBeforeReleaseRoot ( ) {
84
+ /**
85
+ * 在发布根模块前线上进行校验
86
+ */
87
+ export function validateBeforeReleaseRoot ( ) : ValidateResponse {
80
88
const pkgJSON = getReleasePkgJSON ( )
81
89
const packageNames = pkgJSON . map ( pkg => pkg . name )
82
90
let isRootRelease = true
83
- const packages = [ ]
91
+ const packages : ValidatePkgJSON [ ] = [ ]
84
92
for ( const packageName of packageNames ) {
85
93
const isRelease = validatePackage ( packageName )
86
94
if ( ! isRelease ) {
0 commit comments