import fs from "fs" ; import path from "path" ; import Immutable from "immutable" ; import parsePageFromString from "../parse/parsePageFromString" ; import Book from "./book" ; import LocationUtils from "../utils/location" ; import Page from "./page" ; import Logger from "../utils/logger" ; type Assets = Immutable . List < string > ; type State = Immutable . Map < any , any > ; type Options = Immutable . Map < any , any > ; class Output extends Immutable . Record ( { book : new Book ( ) , generator : String ( ) , plugins : Immutable . OrderedMap ( ) , pages : Immutable . OrderedMap ( ) , assets : Immutable . List ( ) , options : Immutable . Map ( ) , state : Immutable . Map ( ) , incrementalChangeFileSet : Immutable . Set ( ) , } ) { getBook ( ) { return this . get ( "book" ) ; } getGenerator ( ) { return this . get ( "generator" ) ; } getPlugins ( ) { return this . get ( "plugins" ) ; } getPages ( ) { return this . get ( "pages" ) ; } getOptions ( ) { return this . get ( "options" ) ; } getAssets ( ) { return this . get ( "assets" ) ; } getState ( ) { return this . get ( "state" ) ; } param { string } filePath return { Page | undefined } getPage ( filePath ) { filePath = LocationUtils . normalize ( filePath ) ; const pages = this . getPages ( ) ; return pages . get ( filePath ) ; } reloadPage ( contentRootDir , filePath ) { const relativePath = LocationUtils . normalize ( path . normalize ( path . relative ( contentRootDir , filePath ) ) ) ; const pages = this . getPages ( ) ; const page = pages . get ( relativePath ) ; if ( ! page ) { return this ; } const newPage = parsePageFromString ( page , fs . readFileSync ( filePath , "utf-8" ) ) ; return this . merge ( { pages : pages . set ( relativePath , newPage ) , } ) ; } return { string } getRoot ( ) { return this . getOptions ( ) . get ( "root" ) ; } param { Map } newState return { Output } setState ( newState ) { return this . set ( "state" , newState ) as Output ; } param { Map } newOptions return { Output } setOptions ( newOptions ) { return this . set ( "options" , newOptions ) as Output ; } return { Logger } getLogger ( ) { return this . getBook ( ) . getLogger ( ) ; } } export default Output ;