import ignore , { Ignore } from "ignore" ; import prettier from "prettier" ; import * as templates from "../templates" ; import * as config from "." ; /** high-level queries of configuration data */ export class Reader { /** the configuration data */ readonly data : config . Data ; /** helps check whether a file path should be ignored */ private readonly ignore : Ignore ; constructor ( data , prettierIgnore ) { this . data = data ; this . ignore = ignore ( ) . add ( data . excludeFiles ) . add ( prettierIgnore ) ; } cannotPrettifyMessage ( args ) { return templates . render ( this . data . cannotPrettifyMessage , args ) ; } commitMessage ( args ) { return templates . render ( this . data . commitMessage , args ) ; } hasPrettifiedMessage ( ) { return this . data . prettifiedMessage !== "" ; } hasCannotPrettifyMessage ( ) { return this . data . cannotPrettifyMessage !== "" ; } prettifiedMessage ( args ) { return templates . render ( this . data . prettifiedMessage , args ) ; } /** Indicates whether the given branch should be ignored. */ shouldIgnoreBranch ( branchName ) { return this . data . excludeBranches . includes ( branchName ) ; } /** Indicates whether the given file should be prettified. */ async shouldPrettify ( filename ) { if ( this . ignore . ignores ( filename ) ) { return false ; } const result = await prettier . getFileInfo ( filename ) ; if ( result . ignored ) { return false ; } if ( ! result . inferredParser ) { return false ; } return true ; } }