import * as os from "os" ; import { exec , ChildProcess , execFile , ExecException } from "child_process" ; import { AdobeProcessOptions , AdobeAppProcess } from "./api" ; import { existsSync } from 'fs' ; const newAdobeAppProcess = ( appPath , closeCallback , options ? ) : AdobeAppProcess => { let process ; const timeoutCallback = options . timeoutCallback ; const processTimeout = options . timeout || 0 ; const openCmd = os . platform ( ) === "win32" ? "start" : "open -a" ; const createCallback = ( execTime ) => ( error , stdout , stderr ) => { let becauseOfTimeout = Date . now ( ) - execTime >= processTimeout && processTimeout > 0 ; if ( becauseOfTimeout && timeoutCallback ) { timeoutCallback ( error ) ; } else { closeCallback ( stdout ) ; } } ; return { create : ( openAppScript ) : void => { const execFileCallback = createCallback ( Date . now ( ) ) ; if ( ! existsSync ( appPath ) ) { throw new Error ( 'Wrong app path' ) ; } process = execFile ( appPath , [ openAppScript ] , { timeout : processTimeout } , execFileCallback ) ; } , kill : ( ) : void => { process . kill ( ) ; } , run : ( commandPath ) : void => { exec ( `${ openCmd } ${ appPath . replace ( / /g , "\\ " ) } ${ commandPath . replace ( / /g , "\\ " ) }` ) ; } } ; } ; export default newAdobeAppProcess ;