import path from "path" ; import Promise from "../utils/promise" ; import PathUtils from "../utils/path" ; import fs from "../utils/fs" ; import Plugins from "../plugins" ; import deprecate from "./deprecate" ; import fileToURL from "../output/helper/fileToURL" ; import defaultBlocks from "../constants/defaultBlocks" ; import honkit from "../honkit" ; import parsers from "../parsers" ; import encodeConfig from "./encodeConfig" ; import encodeSummary from "./encodeSummary" ; import encodeNavigation from "./encodeNavigation" ; import encodePage from "./encodePage" ; param { Output } output return { Object } function encodeGlobal ( output ) { const book = output . getBook ( ) ; const bookFS = book . getContentFS ( ) ; const logger = output . getLogger ( ) ; const outputFolder = output . getRoot ( ) ; const plugins = output . getPlugins ( ) ; const blocks = Plugins . listBlocks ( plugins ) ; const result = { log : logger , config : encodeConfig ( output , book . getConfig ( ) ) , summary : encodeSummary ( output , book . getSummary ( ) ) , return { boolean } isMultilingual : function ( ) { return book . isMultilingual ( ) ; } , return { boolean } isLanguageBook : function ( ) { return book . isLanguageBook ( ) ; } , param { string } fileName return { Promise < Buffer > } readFile : function ( fileName ) { return bookFS . read ( fileName ) ; } , param { string } fileName return { Promise < String > } readFileAsString : function ( fileName ) { return bookFS . readAsString ( fileName ) ; } , param { string } fileName return { string } resolve : function ( fileName ) { return path . resolve ( book . getContentRoot ( ) , fileName ) ; } , param { string } filePath return { string } getPageByPath : function ( filePath ) { const page = output . getPage ( filePath ) ; if ( ! page ) return undefined ; return encodePage ( output , page ) ; } , param { string } type param { string } text return { Promise < String > } renderBlock : function ( type , text ) { const parser = parsers . get ( type ) ; return parser . parsePage ( text ) . get ( "content" ) ; } , param { string } type param { string } text return { Promise < String > } renderInline : function ( type , text ) { const parser = parsers . get ( type ) ; return parser . parseInline ( text ) . get ( "content" ) ; } , template : { param { string } name param { Object } blockData return { Promise | Object } applyBlock : function ( name , blockData ) { const block = blocks . get ( name ) || defaultBlocks . get ( name ) ; return Promise ( block . applyBlock ( blockData , result ) ) ; } , } , output : { /**
             Name of the generator being used
             {string}
             */ name : output . getGenerator ( ) , return { string } root : function ( ) { return outputFolder ; } , param { string } fileName return { string } resolve : function ( fileName ) { return path . resolve ( outputFolder , fileName ) ; } , return { string } toURL : function ( filePath ) { return fileToURL ( output , filePath ) ; } , param { string } fileName return { Promise } hasFile : function ( fileName , content ) { return Promise ( ) . then ( ( ) => { const filePath = PathUtils . resolveInRoot ( outputFolder , fileName ) ; return fs . exists ( filePath ) ; } ) ; } , param { string } fileName param { Buffer } content return { Promise } writeFile : function ( fileName , content ) { return Promise ( ) . then ( ( ) => { const filePath = PathUtils . resolveInRoot ( outputFolder , fileName ) ; return fs . ensureFile ( filePath ) . then ( ( ) => { return fs . writeFile ( filePath , content ) ; } ) ; } ) ; } , param { string } inputFile param { string } outputFile param { Buffer } content return { Promise } copyFile : function ( inputFile , outputFile , content ) { return Promise ( ) . then ( ( ) => { const outputFilePath = PathUtils . resolveInRoot ( outputFolder , outputFile ) ; return fs . ensureFile ( outputFilePath ) . then ( ( ) => { return fs . copy ( inputFile , outputFilePath ) ; } ) ; } ) ; } , } , gitbook : { version : honkit . version , } , honkit : { version : honkit . version , } , } ; deprecate . renamedMethod ( output , "this.isSubBook" , result , "isSubBook" , "isLanguageBook" ) ; deprecate . renamedMethod ( output , "this.contentLink" , result , "contentLink" , "output.toURL" ) ; deprecate . field ( output , "this.generator" , result , "generator" , output . getGenerator ( ) , '"this.generator" property is deprecated, use "this.output.name" instead' ) ; deprecate . field ( output , "this.navigation" , result , "navigation" , ( ) => { return encodeNavigation ( output ) ; } , '"navigation" property is deprecated' ) ; deprecate . field ( output , "this.book" , result , "book" , result , '"book" property is deprecated, use "this" directly instead' ) ; deprecate . field ( output , "this.options" , result , "options" , result . config . values , '"options" property is deprecated, use config.get(key) instead' ) ; return result ; } export default encodeGlobal ;