17
17
import { parseArgs } from "jsr:@std/cli/parse-args" ;
18
18
import { join } from "jsr:@std/path" ;
19
19
20
- async function load ( fp : string ) : Promise < string > {
20
+ async function load ( fp : string ) : Promise < { version : string } > {
21
21
const src = await Deno . readTextFile ( fp ) ;
22
- const { version } = JSON . parse ( src ) ;
23
- return version ;
22
+ return JSON . parse ( src ) ;
24
23
}
25
24
26
25
const argv = parseArgs (
@@ -29,8 +28,10 @@ const argv = parseArgs(
29
28
alias : {
30
29
"m" : [ "module" ] ,
31
30
"t" : [ "tag" ] ,
31
+ "f" : [ "fix" ] ,
32
32
} ,
33
33
string : [ "module" , "tag" ] ,
34
+ boolean : [ "fix" ] ,
34
35
} ,
35
36
) ;
36
37
@@ -46,8 +47,9 @@ if (module === null) {
46
47
let version : string ;
47
48
48
49
if ( module . startsWith ( "transport-" ) ) {
49
- let packageVersion : string = "" ;
50
- const versionFile = await load ( join ( module , "src" , "version.json" ) ) ;
50
+ let packageVersion : { version : string } | undefined ;
51
+ const versionFilePath = join ( module , "src" , "version.json" ) ;
52
+ let versionFile = await load ( versionFilePath ) ;
51
53
switch ( module ) {
52
54
case "transport-node" :
53
55
packageVersion = await load ( join ( module , "package.json" ) ) ;
@@ -68,24 +70,44 @@ if (module.startsWith("transport-")) {
68
70
) ;
69
71
Deno . exit ( 1 ) ;
70
72
}
71
- if ( packageVersion !== versionFile ) {
73
+ if ( packageVersion . version !== versionFile . version ) {
74
+ if ( argv . fix ) {
75
+ versionFile = { version : packageVersion . version } ;
76
+ await Deno . writeTextFile (
77
+ versionFilePath ,
78
+ JSON . stringify ( versionFile , null , 2 ) ,
79
+ ) ;
80
+ console . log (
81
+ `[OK] updated ${ versionFilePath } to ${ packageVersion . version } ` ,
82
+ ) ;
83
+ Deno . exit ( 0 ) ;
84
+ }
72
85
console . error (
73
- `[ERROR] expected versions to match - package: ${ packageVersion } src/version.json: ${ versionFile } ` ,
86
+ `[ERROR] expected versions to match - package: ${ packageVersion . version } src/version.json: ${ versionFile . version } ` ,
74
87
) ;
75
88
Deno . exit ( 1 ) ;
76
89
}
77
- version = versionFile ;
90
+ version = versionFile . version ;
78
91
} else {
79
92
const deno = await load ( join ( module , "deno.json" ) ) ;
80
- const node = await load ( join ( module , "package.json" ) ) ;
93
+ version = deno . version ;
94
+ const nodePackagePath = join ( module , "package.json" ) ;
95
+ const node = await load ( nodePackagePath ) ;
81
96
82
- if ( deno !== node ) {
83
- console . error (
84
- `[ERROR] expected versions to match - deno.json: ${ deno } package.json: ${ node } ` ,
85
- ) ;
86
- Deno . exit ( 1 ) ;
97
+ if ( deno . version !== node . version ) {
98
+ if ( argv . fix ) {
99
+ node . version = deno . version ;
100
+ await Deno . writeTextFile ( nodePackagePath , JSON . stringify ( node , null , 2 ) ) ;
101
+ console . log ( `[OK] updated ${ nodePackagePath } to ${ deno . version } ` ) ;
102
+ Deno . exit ( 0 ) ;
103
+ } else {
104
+ console . error (
105
+ `[ERROR] expected versions to match - deno.json: ${ deno . version } package.json: ${ node . version } ` ,
106
+ ) ;
107
+ Deno . exit ( 1 ) ;
108
+ }
87
109
}
88
- version = deno ;
110
+ node . version = deno . version ;
89
111
}
90
112
91
113
if ( argv . tag ) {
@@ -94,12 +116,12 @@ if (argv.tag) {
94
116
if ( tag . startsWith ( prefix ) ) {
95
117
tag = tag . substring ( prefix . length ) ;
96
118
}
97
- if ( tag !== version ) {
119
+ if ( tag !== version ! ) {
98
120
console . error (
99
- `[ERROR] expected tag version to match - bundle: ${ version } tag: ${ argv . tag } }` ,
121
+ `[ERROR] expected tag version to match - bundle: ${ version ! } tag: ${ argv . tag } }` ,
100
122
) ;
101
123
Deno . exit ( 1 ) ;
102
124
}
103
125
}
104
-
126
+ console . log ( `[OK] ${ module } version ${ version ! } ` ) ;
105
127
Deno . exit ( 0 ) ;
0 commit comments