1
- import { execSync } from 'node:child_process'
2
1
import { promises as fsp } from 'node:fs'
3
2
import { $fetch } from 'ofetch'
4
3
import { resolve } from 'pathe'
5
- import { globby } from 'globby'
6
- import { execaSync } from 'execa'
4
+ import { compare } from 'semver'
5
+ import { glob } from 'tinyglobby'
6
+ import { exec } from 'tinyexec'
7
7
import { determineSemverChange , getGitDiff , loadChangelogConfig , parseCommits } from 'changelogen'
8
8
9
9
export interface Dep {
@@ -27,7 +27,7 @@ export async function loadPackage (dir: string) {
27
27
const dep : Dep = { name : e [ 0 ] , range : e [ 1 ] as string , type }
28
28
delete data [ type ] [ dep . name ]
29
29
const updated = reviver ( dep ) || dep
30
- data [ updated . type ] = data [ updated . type ] || { }
30
+ data [ updated . type ] ||= { }
31
31
data [ updated . type ] [ updated . name ] = updated . range
32
32
}
33
33
}
@@ -43,7 +43,7 @@ export async function loadPackage (dir: string) {
43
43
44
44
export async function loadWorkspace ( dir : string ) {
45
45
const workspacePkg = await loadPackage ( dir )
46
- const pkgDirs = ( await globby ( [ 'packages/*' ] , { onlyDirectories : true } ) ) . sort ( )
46
+ const pkgDirs = ( await glob ( [ 'packages/*' ] , { onlyDirectories : true } ) ) . sort ( )
47
47
48
48
const packages : Package [ ] = [ ]
49
49
@@ -103,32 +103,49 @@ export async function determineBumpType () {
103
103
const config = await loadChangelogConfig ( process . cwd ( ) )
104
104
const commits = await getLatestCommits ( )
105
105
106
- const bumpType = determineSemverChange ( commits , config )
106
+ return determineSemverChange ( commits , config )
107
+ }
108
+
109
+ export async function getLatestTag ( ) {
110
+ const { stdout : latestTag } = await exec ( 'git' , [ 'describe' , '--tags' , '--abbrev=0' ] )
111
+ return latestTag . trim ( )
112
+ }
107
113
108
- return bumpType === 'major' ? 'minor' : bumpType
114
+ export async function getLatestReleasedTag ( ) {
115
+ const latestReleasedTag = await exec ( 'git' , [ 'tag' , '-l' ] ) . then ( r => r . stdout . trim ( ) . split ( '\n' ) . filter ( t => / v 2 \. \d + \. \d + / . test ( t ) ) . sort ( compare ) ) . then ( r => r . pop ( ) ! . trim ( ) )
116
+ return latestReleasedTag
117
+ }
118
+
119
+ export async function getPreviousReleasedCommits ( ) {
120
+ const config = await loadChangelogConfig ( process . cwd ( ) )
121
+ const latestTag = await getLatestTag ( )
122
+ const latestReleasedTag = await getLatestReleasedTag ( )
123
+ const commits = parseCommits ( await getGitDiff ( latestTag , latestReleasedTag ) , config )
124
+ return commits
109
125
}
110
126
111
127
export async function getLatestCommits ( ) {
112
128
const config = await loadChangelogConfig ( process . cwd ( ) )
113
- const latestTag = execaSync ( 'git' , [ 'describe' , '--tags' , '--abbrev=0' ] ) . stdout
129
+ const latestTag = await getLatestTag ( )
114
130
115
131
return parseCommits ( await getGitDiff ( latestTag ) , config )
116
132
}
117
133
118
134
export async function getContributors ( ) {
119
135
const contributors = [ ] as Array < { name : string , username : string } >
120
136
const emails = new Set < string > ( )
121
- const latestTag = execSync ( 'git describe --tags --abbrev=0' ) . toString ( ) . trim ( )
137
+ const latestTag = await getLatestTag ( )
122
138
const rawCommits = await getGitDiff ( latestTag )
123
139
for ( const commit of rawCommits ) {
124
140
if ( emails . has ( commit . author . email ) || commit . author . name === 'renovate[bot]' ) { continue }
125
- const { author } = await $fetch < { author : { login : string , email : string } } > ( `https://api.github.com/repos/CodeDredd/pinia-orm /commits/${ commit . shortHash } ` , {
141
+ const { author } = await $fetch < { author : { login : string , email : string } } > ( `https://api.github.com/repos/nuxt/nuxt /commits/${ commit . shortHash } ` , {
126
142
headers : {
127
- 'User-Agent' : 'CodeDredd/pinia-orm ' ,
143
+ 'User-Agent' : 'nuxt/nuxt ' ,
128
144
'Accept' : 'application/vnd.github.v3+json' ,
129
145
'Authorization' : `token ${ process . env . GITHUB_TOKEN } ` ,
130
146
} ,
131
147
} )
148
+ if ( ! author ) { continue }
132
149
if ( ! contributors . some ( c => c . username === author . login ) ) {
133
150
contributors . push ( { name : commit . author . name , username : author . login } )
134
151
}
0 commit comments