@@ -20,7 +20,6 @@ import {
2020 Garden ,
2121} from "./garden"
2222import { EntryStyle } from "./logger/types"
23- import { TaskResults } from "./task-graph"
2423import {
2524 PrimitiveMap ,
2625 validate ,
@@ -82,24 +81,13 @@ import {
8281 mapValues ,
8382 toPairs ,
8483 values ,
85- padEnd ,
8684 keyBy ,
8785 omit ,
88- flatten ,
8986} from "lodash"
90- import { Task } from "./types/task"
9187import {
92- getNames ,
9388 Omit ,
94- registerCleanupFunction ,
95- sleep ,
9689} from "./util"
9790import { TreeVersion } from "./vcs/base"
98- import {
99- autoReloadModules ,
100- computeAutoReloadDependants ,
101- FSWatcher ,
102- } from "./watch"
10391
10492export type PluginContextGuard = {
10593 readonly [ P in keyof ( PluginActionParams | ModuleActionParams < any > ) ] : ( ...args : any [ ] ) => Promise < any >
@@ -133,18 +121,6 @@ export type WrappedFromGarden = Pick<Garden,
133121 "addTask" |
134122 "processTasks" >
135123
136- export interface ProcessModulesParams {
137- modules : Module [ ] ,
138- watch : boolean ,
139- process : ( module : Module ) => Promise < Task [ ] > ,
140- }
141-
142- export interface ProcessServicesParams {
143- services : Service [ ] ,
144- watch : boolean ,
145- process : ( service : Service ) => Promise < Task [ ] > ,
146- }
147-
148124export interface PluginContext extends PluginContextGuard , WrappedFromGarden {
149125 getEnvironmentStatus : ( params : { } ) => Promise < EnvironmentStatusMap >
150126 configureEnvironment : ( params : { force ?: boolean } ) => Promise < EnvironmentStatusMap >
@@ -189,8 +165,6 @@ export interface PluginContext extends PluginContextGuard, WrappedFromGarden {
189165 getModuleVersion : ( module : Module , force ?: boolean ) => Promise < TreeVersion >
190166 stageBuild : ( moduleName : string ) => Promise < void >
191167 getStatus : ( ) => Promise < ContextStatus >
192- processModules : ( params : ProcessModulesParams ) => Promise < TaskResults >
193- processServices : ( params : ProcessServicesParams ) => Promise < TaskResults >
194168}
195169
196170export function createPluginContext ( garden : Garden ) : PluginContext {
@@ -524,83 +498,6 @@ export function createPluginContext(garden: Garden): PluginContext {
524498 }
525499 } ,
526500
527- processModules : async ( { modules, watch, process } : ProcessModulesParams ) => {
528- // TODO: log errors as they happen, instead of after processing all tasks
529- const logErrors = ( taskResults : TaskResults ) => {
530- for ( const result of values ( taskResults ) . filter ( r => ! ! r . error ) ) {
531- const divider = padEnd ( "" , 80 , "—" )
532-
533- ctx . log . error ( `\nFailed ${ result . description } . Here is the output:` )
534- ctx . log . error ( divider )
535- ctx . log . error ( result . error + "" )
536- ctx . log . error ( divider + "\n" )
537- }
538- }
539-
540- for ( const module of modules ) {
541- const tasks = await process ( module )
542- await Bluebird . map ( tasks , ctx . addTask )
543- }
544-
545- const results = await ctx . processTasks ( )
546- logErrors ( results )
547-
548- if ( ! watch ) {
549- return results
550- }
551-
552- const modulesToWatch = await autoReloadModules ( modules )
553- const autoReloadDependants = await computeAutoReloadDependants ( ctx )
554-
555- async function handleChanges ( module : Module ) {
556- const tasks = await process ( module )
557- await Bluebird . map ( tasks , ctx . addTask )
558-
559- const dependantsForModule = autoReloadDependants [ module . name ]
560- if ( ! dependantsForModule ) {
561- return
562- }
563-
564- for ( const dependant of dependantsForModule ) {
565- await handleChanges ( dependant )
566- }
567- }
568-
569- const watcher = new FSWatcher ( ctx )
570-
571- // TODO: should the prefix here be different or set explicitly per run?
572- await watcher . watchModules ( modulesToWatch , "addTasksForAutoReload/" ,
573- async ( changedModule ) => {
574- ctx . log . debug ( { msg : `Files changed for module ${ changedModule . name } ` } )
575- await handleChanges ( changedModule )
576- logErrors ( await ctx . processTasks ( ) )
577- } )
578-
579- registerCleanupFunction ( "clearAutoReloadWatches" , ( ) => {
580- watcher . end ( )
581- ctx . log . info ( { msg : "\nDone!" } )
582- } )
583-
584- while ( true ) {
585- await sleep ( 1000 )
586- }
587- } ,
588-
589- processServices : async ( { services, watch, process } : ProcessServicesParams ) => {
590- const serviceNames = getNames ( services )
591- const modules = Array . from ( new Set ( services . map ( s => s . module ) ) )
592-
593- return ctx . processModules ( {
594- modules,
595- watch,
596- process : async ( module ) => {
597- const moduleServices = await module . getServices ( )
598- const servicesToDeploy = moduleServices . filter ( s => serviceNames . includes ( s . name ) )
599- return flatten ( await Bluebird . map ( servicesToDeploy , process ) )
600- } ,
601- } )
602- } ,
603-
604501 //endregion
605502 }
606503
0 commit comments