import * as fs from 'fs' ; import path from 'path' ; import serialize from 'serialize-javascript' ; function saveConfig ( config , workflowPath = '/null' , { guards , actions } ) { const filename = workflowPath . replace ( '.ts' , '.config.js' ) ; console . log ( `Saving ${ filename }` ) ; fs . writeFile ( filename , `
const guards = ${ serialize ( guards || { } ) }
const customActions = ${ serialize ( actions || { } ) }
const config = ${ serialize ( config ) }
const machine = Machine(config, {guards, actions: customActions})
    ` , err => { if ( err ) throw err ; } ) ; } const workflowsDir = path . join ( __dirname , '..' , 'src' , 'workflows' ) ; const workflows = fs . readdirSync ( workflowsDir ) . filter ( f => f . endsWith ( '.ts' ) ) ; for ( const workflow of workflows ) { const workflowPath = path . join ( workflowsDir , workflow ) ; const { config , mockOptions } = require ( workflowPath ) ; saveConfig ( config , workflowPath , mockOptions || { } ) ; }