import { AdobeAppName , BroadcastBuilder , BroadcastMessage , Config } from "./api" ; import { exec } from 'child_process' ; const broadcastMethods = new Map < AdobeAppName , ( cmd : string ) => string > ( [ [ AdobeAppName . Animate , ( cmd ) => `FLfile.runCommandLine("${ cmd }");` ] , [ AdobeAppName . Photoshop , ( cmd ) => `app.system("${ cmd }");` ] , [ AdobeAppName . Illustrator , ( cmd ) => `app.system("${ cmd }");` ] , ] ) ; const buildBroadcastCommand = ( host , port , message ) => `adobe-broadcast --host='${ host }' --port=${ port } --msg='${ message }'` ; export const newBroadcastBuilder = ( config ) : BroadcastBuilder => { return { build ( command ) { const payload = `{\\"command\\":\\"${ command }\\",\\"stdout\\":\\"" + __stdout + "\\", \\"stderr\\":\\"" + __stderr + "\\" }` ; const broadcast = broadcastMethods . get ( config . app . name ) ; const cmd = buildBroadcastCommand ( config . host , config . port , payload ) ; return broadcast ( cmd ) ; } } ; } ; export const broadcast = ( host , port , message ) => { const cmd = buildBroadcastCommand ( host , port , JSON . stringify ( message ) ) ; exec ( cmd ) ; } ;