import { ProcfileReconciler } from './ProcfileReconciler' ; import { CategoryReg , Entry } from '../domain' ; import { ServiceRepresentationChainModifier } from './ServiceRepresentationChainModifier' ; import { ProcessRepresentationChainModifier } from './ProcessRepresentationChainModifier' ; import { makeRequire } from 'pandora-dollar' ; import { ServiceUtils } from '../service/ServiceUtils' ; /**
 * Class ProcfileReconcilerAccessor
 * A easy way to access ProcfileReconciler
 */ export class ProcfileReconcilerAccessor { private procfileReconciler : ProcfileReconciler = null ; get dev ( ) { return process . env . PANDORA_DEV === 'true' ; } get appName ( ) { return this . procfileReconciler . appRepresentation . appName ; } get appDir ( ) { return this . procfileReconciler . appRepresentation . appDir ; } constructor ( procfileReconciler ) { this . procfileReconciler = procfileReconciler ; } defaultServiceCategory ( name ? ) { if ( ! name ) { return this . procfileReconciler . getDefaultServiceCategory ( ) ; } this . procfileReconciler . setDefaultServiceCategory ( name ) ; } param { Entry } entry environment ( entry ? ) { if ( ! entry ) { return this . procfileReconciler . getEnvironment ( ) ; } this . procfileReconciler . injectEnvironment ( entry ) ; } param processName return { ProcessRepresentationChainModifier } process ( processName ) { const savedRepresentation = this . procfileReconciler . getProcessByName ( processName ) ; if ( savedRepresentation ) { return new ProcessRepresentationChainModifier ( savedRepresentation , this . procfileReconciler ) ; } const representation = this . procfileReconciler . defineProcess ( { processName } ) ; return new ProcessRepresentationChainModifier ( representation , this . procfileReconciler ) ; } param processName param entryFile return { ProcessRepresentationChainModifier } fork ( processName , entryFile ? ) { const savedRepresentation = this . procfileReconciler . getProcessByName ( processName ) ; if ( savedRepresentation ) { return new ProcessRepresentationChainModifier ( savedRepresentation , this . procfileReconciler ) ; } const representation = this . procfileReconciler . defineProcess ( { entryFile , processName } ) ; return new ProcessRepresentationChainModifier ( representation , this . procfileReconciler ) ; } param serviceName param serviceEntry return { ServiceRepresentationChainModifier } service ( serviceName , serviceEntry ? ) { ServiceUtils . checkName ( serviceName ) ; const savedRepresentation = this . procfileReconciler . getServiceByName ( serviceName ) ; if ( savedRepresentation && serviceEntry ) { throw new Error ( `Service already exist! Use pandora.service('${ serviceName }').entry('a new place') to change the entry.` ) ; } if ( savedRepresentation ) { return new ServiceRepresentationChainModifier ( savedRepresentation , this . procfileReconciler ) ; } const representation = this . procfileReconciler . injectService ( { serviceName , serviceEntry } ) ; return new ServiceRepresentationChainModifier ( representation , this . procfileReconciler ) ; } private clusterCount = 0 ; param path return { ServiceRepresentationChainModifier } cluster ( path ) { const baseDir = this . procfileReconciler . procfileBasePath ; class ClusterService { static dependencies = [ 'all' ] ; async start ( ) { if ( baseDir ) { makeRequire ( baseDir ) ( path ) ; } else { require ( path ) ; } } } return this . service ( 'cluster' + this . clusterCount ++ , ClusterService ) ; } }