1
- // @ts -check
2
-
3
1
/**
4
2
* modified from https://github.com/vuejs/vue-next/blob/master/scripts/release.js
5
3
*/
6
- const execa = require ( 'execa' )
7
- const path = require ( 'path' )
8
- const fs = require ( 'fs' )
4
+ import chalk from 'chalk'
5
+ import type { ExecaChildProcess , Options as ExecaOptions } from 'execa'
6
+ import execa from 'execa'
7
+ import { readFileSync , writeFileSync } from 'fs'
8
+ import path from 'path'
9
+ import prompts from 'prompts'
10
+ import type { ReleaseType } from 'semver'
11
+ import semver from 'semver'
12
+
9
13
const args = require ( 'minimist' ) ( process . argv . slice ( 2 ) )
10
- const semver = require ( 'semver' )
11
- const chalk = require ( 'chalk' )
12
- const prompts = require ( 'prompts' )
13
14
14
15
const pkgDir = process . cwd ( )
15
16
const pkgPath = path . resolve ( pkgDir , 'package.json' )
16
- /**
17
- * @type {{ name: string, version: string } }
18
- */
19
- const pkg = require ( pkgPath )
17
+ const pkg : { name : string ; version : string } = require ( pkgPath )
20
18
const pkgName = pkg . name . replace ( / ^ @ v i t e j s \/ / , '' )
21
19
const currentVersion = pkg . version
22
- /**
23
- * @type {boolean }
24
- */
25
- const isDryRun = args . dry
26
- /**
27
- * @type {boolean }
28
- */
29
- const skipBuild = args . skipBuild
20
+ const isDryRun : boolean = args . dry
21
+ const skipBuild : boolean = args . skipBuild
30
22
31
- /**
32
- * @type {import('semver').ReleaseType[] }
33
- */
34
- const versionIncrements = [
23
+ const versionIncrements : ReleaseType [ ] = [
35
24
'patch' ,
36
25
'minor' ,
37
26
'major' ,
@@ -41,43 +30,33 @@ const versionIncrements = [
41
30
'prerelease'
42
31
]
43
32
44
- /**
45
- * @param {import('semver').ReleaseType } i
46
- */
47
- const inc = ( i ) => semver . inc ( currentVersion , i , 'beta' )
33
+ const inc : ( i : ReleaseType ) => string = ( i ) =>
34
+ semver . inc ( currentVersion , i , 'beta' )
48
35
49
- /**
50
- * @param {string } bin
51
- * @param {string[] } args
52
- * @param {object } opts
53
- */
54
- const run = ( bin , args , opts = { } ) =>
36
+ type RunFn = (
37
+ bin : string ,
38
+ args : string [ ] ,
39
+ opts ?: ExecaOptions < string >
40
+ ) => ExecaChildProcess < string >
41
+
42
+ const run : RunFn = ( bin , args , opts = { } ) =>
55
43
execa ( bin , args , { stdio : 'inherit' , ...opts } )
56
44
57
- /**
58
- * @param {string } bin
59
- * @param {string[] } args
60
- * @param {object } opts
61
- */
62
- const dryRun = ( bin , args , opts = { } ) =>
45
+ type DryRunFn = ( bin : string , args : string [ ] , opts ?: any ) => void
46
+
47
+ const dryRun : DryRunFn = ( bin , args , opts : any ) =>
63
48
console . log ( chalk . blue ( `[dryrun] ${ bin } ${ args . join ( ' ' ) } ` ) , opts )
64
49
65
50
const runIfNotDry = isDryRun ? dryRun : run
66
51
67
- /**
68
- * @param {string } msg
69
- */
70
- const step = ( msg ) => console . log ( chalk . cyan ( msg ) )
52
+ const step : ( msg : string ) => void = ( msg ) => console . log ( chalk . cyan ( msg ) )
71
53
72
- async function main ( ) {
73
- let targetVersion = args . _ [ 0 ]
54
+ async function main ( ) : Promise < void > {
55
+ let targetVersion : string | undefined = args . _ [ 0 ]
74
56
75
57
if ( ! targetVersion ) {
76
58
// no explicit version, offer suggestions
77
- /**
78
- * @type {{ release: string } }
79
- */
80
- const { release } = await prompts ( {
59
+ const { release } : { release : string } = await prompts ( {
81
60
type : 'select' ,
82
61
name : 'release' ,
83
62
message : 'Select release type' ,
@@ -88,10 +67,7 @@ async function main() {
88
67
} )
89
68
90
69
if ( release === 'custom' ) {
91
- /**
92
- * @type {{ version: string } }
93
- */
94
- const res = await prompts ( {
70
+ const res : { version : string } = await prompts ( {
95
71
type : 'text' ,
96
72
name : 'version' ,
97
73
message : 'Input custom version' ,
@@ -111,10 +87,7 @@ async function main() {
111
87
pkgName === 'vite' ? `v${ targetVersion } ` : `${ pkgName } @${ targetVersion } `
112
88
113
89
if ( targetVersion . includes ( 'beta' ) && ! args . tag ) {
114
- /**
115
- * @type {{ tagBeta: boolean } }
116
- */
117
- const { tagBeta } = await prompts ( {
90
+ const { tagBeta } : { tagBeta : boolean } = await prompts ( {
118
91
type : 'confirm' ,
119
92
name : 'tagBeta' ,
120
93
message : `Publish under dist-tag "beta"?`
@@ -123,10 +96,7 @@ async function main() {
123
96
if ( tagBeta ) args . tag = 'beta'
124
97
}
125
98
126
- /**
127
- * @type {{ yes: boolean } }
128
- */
129
- const { yes } = await prompts ( {
99
+ const { yes } : { yes : boolean } = await prompts ( {
130
100
type : 'confirm' ,
131
101
name : 'yes' ,
132
102
message : `Releasing ${ tag } . Confirm?`
@@ -173,20 +143,16 @@ async function main() {
173
143
console . log ( )
174
144
}
175
145
176
- /**
177
- * @param {string } version
178
- */
179
- function updateVersion ( version ) {
180
- const pkg = JSON . parse ( fs . readFileSync ( pkgPath , 'utf-8' ) )
146
+ function updateVersion ( version : string ) : void {
147
+ const pkg = JSON . parse ( readFileSync ( pkgPath , 'utf-8' ) )
181
148
pkg . version = version
182
- fs . writeFileSync ( pkgPath , JSON . stringify ( pkg , null , 2 ) + '\n' )
149
+ writeFileSync ( pkgPath , JSON . stringify ( pkg , null , 2 ) + '\n' )
183
150
}
184
151
185
- /**
186
- * @param {string } version
187
- * @param {Function } runIfNotDry
188
- */
189
- async function publishPackage ( version , runIfNotDry ) {
152
+ async function publishPackage (
153
+ version : string ,
154
+ runIfNotDry : RunFn | DryRunFn
155
+ ) : Promise < void > {
190
156
const publicArgs = [
191
157
'publish' ,
192
158
'--no-git-tag-version' ,
0 commit comments