@@ -16,6 +16,7 @@ Options
16
16
--output, -o Specify output file (if not specified in redocly.yaml)
17
17
--enum Export true TS enums instead of unions
18
18
--enum-values Export enum values as arrays
19
+ --check Check that the generated types are up-to-date. (default: false)
19
20
--export-type, -t Export top-level \`type\` instead of \`interface\`
20
21
--immutable Generate readonly types
21
22
--additional-properties Treat schema objects as if \`additionalProperties: true\` is set
@@ -64,6 +65,7 @@ const flags = parser(args, {
64
65
"emptyObjectsUnknown" ,
65
66
"enum" ,
66
67
"enumValues" ,
68
+ "check" ,
67
69
"excludeDeprecated" ,
68
70
"exportType" ,
69
71
"help" ,
@@ -90,6 +92,23 @@ function normalizeOutput(output) {
90
92
return new URL ( output , CWD ) ;
91
93
}
92
94
95
+ /**
96
+ * Check if the generated types are up-to-date.
97
+ * @param {string } current - The current generated types.
98
+ * @param {URL } outputPath - The path to the output file.
99
+ */
100
+ function checkStaleOutput ( current , outputPath ) {
101
+ if ( flags . check ) {
102
+ const previous = fs . readFileSync ( outputPath , "utf8" ) ;
103
+ if ( current === previous ) {
104
+ process . exit ( 0 ) ;
105
+ } else {
106
+ error ( "Generated types are not up-to-date!" ) ;
107
+ process . exit ( 1 ) ;
108
+ }
109
+ }
110
+ }
111
+
93
112
/**
94
113
* @param {string | URL } schema
95
114
* @param {@type import('@redocly/openapi-core').Config } redocly
@@ -174,6 +193,7 @@ async function main() {
174
193
}
175
194
const result = await generateSchema ( new URL ( api . root , configRoot ) , { redocly } ) ;
176
195
const outFile = new URL ( api [ REDOC_CONFIG_KEY ] . output , configRoot ) ;
196
+ checkStaleOutput ( result , outFile ) ;
177
197
fs . mkdirSync ( new URL ( "." , outFile ) , { recursive : true } ) ;
178
198
fs . writeFileSync ( outFile , result , "utf8" ) ;
179
199
done ( name , api [ REDOC_CONFIG_KEY ] . output , performance . now ( ) - timeStart ) ;
@@ -192,6 +212,7 @@ async function main() {
192
212
process . stdout . write ( result ) ;
193
213
} else {
194
214
const outFile = normalizeOutput ( flags . output ) ;
215
+ checkStaleOutput ( result , outFile ) ;
195
216
fs . mkdirSync ( new URL ( "." , outFile ) , { recursive : true } ) ;
196
217
fs . writeFileSync ( outFile , result , "utf8" ) ;
197
218
done ( "stdin" , flags . output , performance . now ( ) - timeStart ) ;
@@ -215,6 +236,7 @@ async function main() {
215
236
process . stdout . write ( result ) ;
216
237
} else {
217
238
const outFile = normalizeOutput ( flags . output ) ;
239
+ checkStaleOutput ( result , outFile ) ;
218
240
fs . mkdirSync ( new URL ( "." , outFile ) , { recursive : true } ) ;
219
241
fs . writeFileSync ( outFile , result , "utf8" ) ;
220
242
done ( input , flags . output , performance . now ( ) - timeStart ) ;
0 commit comments