@@ -31,6 +31,7 @@ var spawn = require('child_process').spawn,
3131 dbId = 0 ,
3232 plugins = [ ] ,
3333 recoveryMode = false , recoveryData = { 'input' : [ ] , 'outputs' : { } , 'settings' : { } } ,
34+ glob = require ( 'glob' ) ,
3435 wfDirFull ; // logged in the persistence journal
3536
3637var hfroot = pathtool . join ( require ( 'path' ) . dirname ( require . main . filename ) , ".." ) ;
@@ -132,6 +133,35 @@ function hflow_run() {
132133
133134 wfDirFull = pathtool . resolve ( wfpath ) ;
134135
136+ // Read workflow configuration files if exist
137+ // all files matching pattern `workflow.config[.name].json` will be matched
138+ // all config will be passed to workflow functions via `context.appConfig[.name]`
139+ var wfConfig = { } ;
140+ // 1. Look for main config file -- workflow.config.json
141+ var wfConfigFilePath = pathtool . join ( wfDirFull , "workflow.config.json" ) ;
142+ if ( fs . existsSync ( wfConfigFilePath ) ) {
143+ try {
144+ let rawdata = fs . readFileSync ( wfConfigFilePath ) ;
145+ wfConfig = JSON . parse ( rawdata ) ;
146+ } catch ( e ) {
147+ console . log ( "Error reading/parsing workflow config file:" , e ) ;
148+ }
149+ }
150+ // 2. Look for secondary config files -- workflow.config.{name}.json
151+ var configFiles = glob . sync ( "workflow.config.*.json" ) ;
152+ configFiles . forEach ( function ( file ) {
153+ try {
154+ let rawdata = fs . readFileSync ( file ) ;
155+ let secondaryConfig = JSON . parse ( rawdata ) ;
156+ let match = file . match ( / w o r k f l o w \. c o n f i g \. ( .* ) .j s o n / ) ;
157+ let name = match [ 1 ] ;
158+ wfConfig [ name ] = secondaryConfig ;
159+ } catch ( e ) {
160+ console . log ( "Error reading/parsing workflow config file " , file , e ) ;
161+ }
162+ } ) ;
163+ console . log ( wfConfig ) ;
164+
135165 var runWf = function ( wfId , wfName ) {
136166
137167 /*function makeId() {
@@ -144,7 +174,9 @@ function hflow_run() {
144174 return id.join("");
145175 }*/
146176
147- var config = { "emulate" :"false" , "workdir" : wfDirFull } ;
177+ var config = wfConfig ;
178+ config [ "emulate" ] = "false" ;
179+ config [ "workdir" ] = wfDirFull ;
148180
149181 if ( recoveryMode ) {
150182 config . recoveryData = recoveryData ;
0 commit comments