11import { default as template } from 'boats/build/src/Template' ;
22import { default as bundlerSwaggerParse } from 'boats/build/src/bundlerSwaggerParse' ;
33import { BoatsRC } from 'boats/build/src/interfaces/BoatsRc' ;
4+ import { access , readFile } from 'fs/promises' ;
45import { dirname } from 'path' ;
56import pj from '../package.json' ;
7+ import { getBoatsRc } from '../src/templates/init' ;
68
79export type ErrorWithLogs = Error & { code : string ; logs : unknown [ ] } ;
810
@@ -12,14 +14,6 @@ type ConsoleMock = {
1214 unmock : ( ) => void ;
1315} ;
1416
15- export const defaultBoats : BoatsRC = {
16- nunjucksOptions : { tags : { } } ,
17- picomatchOptions : { bash : true } ,
18- permissionConfig : { globalPrefix : true } ,
19- paths : { } ,
20- fancyPluralization : true ,
21- } ;
22-
2317const mockConsoleLog = ( ) : ConsoleMock => {
2418 /* eslint-disable no-console */
2519 const olog = console . log ;
@@ -74,19 +68,31 @@ const overridePackageJsonReader = (): void => {
7468 } ;
7569} ;
7670
71+ const defaultBoatsRc = JSON . parse ( getBoatsRc ( ) ) as BoatsRC ;
72+
7773export const boats = async ( inFile : string , outFile : string , validate = true ) : Promise < string > => {
7874 const trim = dirname ( inFile ) + '/paths/' ;
75+ const customBoatsRcPath = dirname ( dirname ( inFile ) ) + '/.boatsrc' ;
76+ let boatsRc = defaultBoatsRc ;
77+ try {
78+ const hasBoatsRc = await access ( customBoatsRcPath )
79+ . then ( ( ) => true )
80+ . catch ( ( ) => false ) ;
81+ if ( hasBoatsRc ) {
82+ boatsRc = JSON . parse ( await readFile ( customBoatsRcPath , { encoding : 'utf8' } ) ) as BoatsRC ;
83+ }
84+ } catch ( _e : unknown ) { }
7985
8086 overridePackageJsonReader ( ) ;
8187 // overwrite console during testing - no debug output needed
8288 const con = mockConsoleLog ( ) ;
8389
8490 try {
85- const indexFile = template . directoryParse ( inFile , outFile , null as unknown as number , trim , [ ] , [ ] , defaultBoats , false ) ;
91+ const indexFile = template . directoryParse ( inFile , outFile , null as unknown as number , trim , [ ] , [ ] , boatsRc , false ) ;
8692 const outApiFile = await bundlerSwaggerParse ( {
8793 inputFile : indexFile ,
8894 outputFile : outFile ,
89- boatsRc : defaultBoats ,
95+ boatsRc,
9096 dereference : false ,
9197 doNotValidate : ! validate ,
9298 excludeVersion : false ,
0 commit comments