4
4
import { existsSync , readdirSync , writeFileSync } from 'fs'
5
5
import path from 'path'
6
6
import colors from 'picocolors'
7
- import type { Options as ExecaOptions } from 'execa'
7
+ import type { Options as ExecaOptions , ExecaReturnValue } from 'execa'
8
8
import execa from 'execa'
9
9
import type { ReleaseType } from 'semver'
10
10
import semver from 'semver'
@@ -39,19 +39,26 @@ export const versionIncrements: ReleaseType[] = [
39
39
// 'prerelease'
40
40
]
41
41
42
- export function getPackageInfo ( pkgName : string ) {
42
+ interface Pkg {
43
+ name : string
44
+ version : string
45
+ private ?: boolean
46
+ }
47
+ export function getPackageInfo ( pkgName : string ) : {
48
+ pkg : Pkg
49
+ pkgName : string
50
+ pkgDir : string
51
+ pkgPath : string
52
+ currentVersion : string
53
+ } {
43
54
const pkgDir = path . resolve ( __dirname , '../packages/' + pkgName )
44
55
45
56
if ( ! existsSync ( pkgDir ) ) {
46
57
throw new Error ( `Package ${ pkgName } not found` )
47
58
}
48
59
49
60
const pkgPath = path . resolve ( pkgDir , 'package.json' )
50
- const pkg : {
51
- name : string
52
- version : string
53
- private ?: boolean
54
- } = require ( pkgPath )
61
+ const pkg : Pkg = require ( pkgPath )
55
62
const currentVersion = pkg . version
56
63
57
64
if ( pkg . private ) {
@@ -71,15 +78,15 @@ export async function run(
71
78
bin : string ,
72
79
args : string [ ] ,
73
80
opts : ExecaOptions < string > = { }
74
- ) {
81
+ ) : Promise < ExecaReturnValue < string > > {
75
82
return execa ( bin , args , { stdio : 'inherit' , ...opts } )
76
83
}
77
84
78
85
export async function dryRun (
79
86
bin : string ,
80
87
args : string [ ] ,
81
88
opts ?: ExecaOptions < string >
82
- ) {
89
+ ) : Promise < void > {
83
90
return console . log (
84
91
colors . blue ( `[dryrun] ${ bin } ${ args . join ( ' ' ) } ` ) ,
85
92
opts || ''
@@ -88,11 +95,15 @@ export async function dryRun(
88
95
89
96
export const runIfNotDry = isDryRun ? dryRun : run
90
97
91
- export function step ( msg : string ) {
98
+ export function step ( msg : string ) : void {
92
99
return console . log ( colors . cyan ( msg ) )
93
100
}
94
101
95
- export function getVersionChoices ( currentVersion : string ) {
102
+ interface VersionChoice {
103
+ title : string
104
+ value : string
105
+ }
106
+ export function getVersionChoices ( currentVersion : string ) : VersionChoice [ ] {
96
107
const currentBeta = currentVersion . includes ( 'beta' )
97
108
const currentAlpha = currentVersion . includes ( 'alpha' )
98
109
const isStable = ! currentBeta && ! currentAlpha
@@ -101,7 +112,7 @@ export function getVersionChoices(currentVersion: string) {
101
112
return semver . inc ( currentVersion , i , tag ) !
102
113
}
103
114
104
- let versionChoices = [
115
+ let versionChoices : VersionChoice [ ] = [
105
116
{
106
117
title : 'next' ,
107
118
value : inc ( isStable ? 'patch' : 'prerelease' )
@@ -175,7 +186,7 @@ export async function publishPackage(
175
186
} )
176
187
}
177
188
178
- export async function getLatestTag ( pkgName : string ) {
189
+ export async function getLatestTag ( pkgName : string ) : Promise < string > {
179
190
const tags = ( await run ( 'git' , [ 'tag' ] , { stdio : 'pipe' } ) ) . stdout
180
191
. split ( / \n / )
181
192
. filter ( Boolean )
@@ -186,7 +197,7 @@ export async function getLatestTag(pkgName: string) {
186
197
. reverse ( ) [ 0 ]
187
198
}
188
199
189
- export async function logRecentCommits ( pkgName : string ) {
200
+ export async function logRecentCommits ( pkgName : string ) : Promise < void > {
190
201
const tag = await getLatestTag ( pkgName )
191
202
if ( ! tag ) return
192
203
const sha = await run ( 'git' , [ 'rev-list' , '-n' , '1' , tag ] , {
@@ -214,7 +225,7 @@ export async function logRecentCommits(pkgName: string) {
214
225
console . log ( )
215
226
}
216
227
217
- export async function updateTemplateVersions ( ) {
228
+ export async function updateTemplateVersions ( ) : Promise < void > {
218
229
const viteVersion = ( await fs . readJSON ( '../packages/vite/package.json' ) )
219
230
. version
220
231
if ( / b e t a | a l p h a | r c / . test ( viteVersion ) ) return
0 commit comments