import Promise from "../utils/promise" ; import validateConfig from "./validateConfig" ; import CONFIG_FILES from "../constants/configFiles" ; param { Book } book return { Promise < Book > } function parseConfig ( book ) { const fs = book . getFS ( ) ; let config = book . getConfig ( ) ; return Promise . some ( CONFIG_FILES , ( filename ) => { if ( book . isFileIgnored ( filename ) ) { return ; } return fs . loadAsObject ( filename ) . then ( ( cfg ) => { return fs . statFile ( filename ) . then ( ( file ) => { return { file : file , values : cfg , } ; } ) ; } ) . fail ( ( err ) => { if ( err . code != "MODULE_NOT_FOUND" ) throw err ; else return Promise ( false ) ; } ) ; } ) . then ( ( result ) => { let values = result ? result . values : { } ; values = validateConfig ( values ) ; if ( result . file ) { config = config . setFile ( result . file ) ; } config = config . mergeValues ( values ) ; return book . setConfig ( config ) ; } ) ; } export default parseConfig ;