'use strict' ; import * as uiflow from 'uiflow' ; import * as through2 from 'through2' ; export class CompileFormat { public static SVG = 'svg' ; public static PNG = 'png' ; public static JSON = 'json' ; public static DOT = 'dot' ; } export class Compiler { public buildWithCode ( fileName , code , format , errorHandler ) { return uiflow . buildWithCode ( fileName , code . replace ( /\r\n/g , '\n' ) , format , errorHandler ) ; } public compile ( fileName , code , format ) { let promise = new Promise < Buffer > ( ( resolve , rejected ) => { let buff = [ ] ; let output = through2 ( ( chunk , enc , callback ) => { buff . push ( chunk ) ; callback ( ) ; } ) ; let stream = this . buildWithCode ( fileName , code , format , e => { rejected ( e ) ; } ) ; stream . pipe ( output ) ; stream . on ( 'end' , ( ) => { let all = Buffer . concat ( buff ) ; resolve ( all ) ; output . end ( ) ; } ) ; } ) ; return promise ; } }