@@ -28,14 +28,8 @@ import { outputExtensions } from '../types.js';
2828import { exitWithError } from './error.js' ;
2929import { handleLintConfig } from '../commands/lint.js' ;
3030
31- import type {
32- Config ,
33- BundleOutputFormat ,
34- Oas3Definition ,
35- Oas2Definition ,
36- Exact ,
37- } from '@redocly/openapi-core' ;
38- import type { Totals , Entrypoint , OutputExtensions , CommandArgv } from '../types.js' ;
31+ import type { Config , Oas3Definition , Oas2Definition , Exact } from '@redocly/openapi-core' ;
32+ import type { Totals , Entrypoint , OutputExtension , CommandArgv } from '../types.js' ;
3933
4034const globPromise = promisify ( glob . glob ) ;
4135
@@ -185,7 +179,7 @@ export class CircularJSONNotSupportedError extends Error {
185179 }
186180}
187181
188- export function dumpBundle ( obj : any , format : BundleOutputFormat , dereference ?: boolean ) : string {
182+ export function dumpBundle ( obj : any , format : OutputExtension , dereference ?: boolean ) : string {
189183 if ( format === 'json' ) {
190184 try {
191185 return JSON . stringify ( obj , null , 2 ) ;
@@ -277,12 +271,10 @@ export function writeJson(data: unknown, filename: string) {
277271 fs . writeFileSync ( filename , content ) ;
278272}
279273
280- export function getAndValidateFileExtension ( fileName : string ) : NonNullable < OutputExtensions > {
274+ export function getAndValidateFileExtension ( fileName : string ) : NonNullable < OutputExtension > {
281275 const ext = fileName . split ( '.' ) . pop ( ) ;
282-
283- if ( [ 'yaml' , 'yml' , 'json' ] . includes ( ext ! ) ) {
284- // FIXME: ^ use one source of truth (2.0)
285- return ext as NonNullable < OutputExtensions > ;
276+ if ( outputExtensions . includes ( ext as OutputExtension ) ) {
277+ return ext as OutputExtension ;
286278 }
287279 logger . warn ( `Unsupported file extension: ${ ext } . Using yaml.\n` ) ;
288280 return 'yaml' ;
@@ -377,7 +369,7 @@ export function getOutputFileName({
377369 entrypoint : string ;
378370 output ?: string ;
379371 argvOutput ?: string ;
380- ext ?: BundleOutputFormat ;
372+ ext ?: OutputExtension ;
381373 entries : number ;
382374} ) {
383375 let outputFile = output || argvOutput ;
@@ -386,16 +378,16 @@ export function getOutputFileName({
386378 }
387379
388380 if ( entries > 1 && argvOutput ) {
389- ext = ext || ( extname ( entrypoint ) . substring ( 1 ) as BundleOutputFormat ) ;
381+ ext = ext || ( extname ( entrypoint ) . substring ( 1 ) as OutputExtension ) ;
390382 if ( ! outputExtensions . includes ( ext ) ) {
391383 throw new Error ( `Invalid file extension: ${ ext } .` ) ;
392384 }
393385 outputFile = join ( argvOutput , basename ( entrypoint , extname ( entrypoint ) ) ) + '.' + ext ;
394386 } else {
395387 ext =
396388 ext ||
397- ( extname ( outputFile ) . substring ( 1 ) as BundleOutputFormat ) ||
398- ( extname ( entrypoint ) . substring ( 1 ) as BundleOutputFormat ) ;
389+ ( extname ( outputFile ) . substring ( 1 ) as OutputExtension ) ||
390+ ( extname ( entrypoint ) . substring ( 1 ) as OutputExtension ) ;
399391 if ( ! outputExtensions . includes ( ext ) ) {
400392 throw new Error ( `Invalid file extension: ${ ext } .` ) ;
401393 }
@@ -556,3 +548,10 @@ export function formatPath(path: string) {
556548 }
557549 return relative ( process . cwd ( ) , path ) ;
558550}
551+
552+ export function capitalize ( s : string ) {
553+ if ( s ?. length > 0 ) {
554+ return s [ 0 ] . toUpperCase ( ) + s . slice ( 1 ) ;
555+ }
556+ return s ;
557+ }
0 commit comments