1- import { execSync } from 'node:child_process'
21import { promises as fsp } from 'node:fs'
32import { $fetch } from 'ofetch'
43import { 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'
77import { determineSemverChange , getGitDiff , loadChangelogConfig , parseCommits } from 'changelogen'
88
99export interface Dep {
@@ -27,7 +27,7 @@ export async function loadPackage (dir: string) {
2727 const dep : Dep = { name : e [ 0 ] , range : e [ 1 ] as string , type }
2828 delete data [ type ] [ dep . name ]
2929 const updated = reviver ( dep ) || dep
30- data [ updated . type ] = data [ updated . type ] || { }
30+ data [ updated . type ] ||= { }
3131 data [ updated . type ] [ updated . name ] = updated . range
3232 }
3333 }
@@ -43,7 +43,7 @@ export async function loadPackage (dir: string) {
4343
4444export async function loadWorkspace ( dir : string ) {
4545 const workspacePkg = await loadPackage ( dir )
46- const pkgDirs = ( await globby ( [ 'packages/*' ] , { onlyDirectories : true } ) ) . sort ( )
46+ const pkgDirs = ( await glob ( [ 'packages/*' ] , { onlyDirectories : true } ) ) . sort ( )
4747
4848 const packages : Package [ ] = [ ]
4949
@@ -103,32 +103,49 @@ export async function determineBumpType () {
103103 const config = await loadChangelogConfig ( process . cwd ( ) )
104104 const commits = await getLatestCommits ( )
105105
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+ }
107113
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
109125}
110126
111127export async function getLatestCommits ( ) {
112128 const config = await loadChangelogConfig ( process . cwd ( ) )
113- const latestTag = execaSync ( 'git' , [ 'describe' , '--tags' , '--abbrev=0' ] ) . stdout
129+ const latestTag = await getLatestTag ( )
114130
115131 return parseCommits ( await getGitDiff ( latestTag ) , config )
116132}
117133
118134export async function getContributors ( ) {
119135 const contributors = [ ] as Array < { name : string , username : string } >
120136 const emails = new Set < string > ( )
121- const latestTag = execSync ( 'git describe --tags --abbrev=0' ) . toString ( ) . trim ( )
137+ const latestTag = await getLatestTag ( )
122138 const rawCommits = await getGitDiff ( latestTag )
123139 for ( const commit of rawCommits ) {
124140 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 } ` , {
126142 headers : {
127- 'User-Agent' : 'CodeDredd/pinia-orm ' ,
143+ 'User-Agent' : 'nuxt/nuxt ' ,
128144 'Accept' : 'application/vnd.github.v3+json' ,
129145 'Authorization' : `token ${ process . env . GITHUB_TOKEN } ` ,
130146 } ,
131147 } )
148+ if ( ! author ) { continue }
132149 if ( ! contributors . some ( c => c . username === author . login ) ) {
133150 contributors . push ( { name : commit . author . name , username : author . login } )
134151 }
0 commit comments