import * as vscode from 'vscode' ; import { RenderTask , } from '../renders/interfaces' ; import { Diagram } from '../diagram/diagram' ; import { localize } from '../common' ; import { appliedRender } from './appliedRender' ; import { ChildProcess } from 'child_process' ; import * as path from 'path' ; import { config } from '../config' ; param diagram param format param savePath param bar returns export function exportDiagram ( diagram , format , savePath , bar ) { if ( bar ) { bar . show ( ) ; bar . text = localize ( 7 , null , diagram . name + "." + format . split ( ":" ) [ 0 ] ) ; } let renderTask = appliedRender ( diagram . parentUri ) . render ( diagram , format , savePath ) ; if ( ! config . exportMapFile ( diagram . parentUri ) || ! savePath ) return renderTask ; let bsName = path . basename ( savePath ) ; let ext = path . extname ( savePath ) ; let cmapx = path . join ( path . dirname ( savePath ) , bsName . substr ( 0 , bsName . length - ext . length ) + ".cmapx" ) ; let mapTask = appliedRender ( diagram . parentUri ) . getMapData ( diagram , cmapx ) ; return combine ( renderTask , mapTask ) ; } function combine ( taskA , taskB ) { let processes = [ ] ; processes . push ( ... taskA . processes , ... taskB . processes ) ; let pms = new Promise ( ( resolve , reject ) => { Promise . all ( [ taskA . promise , taskB . promise ] ) . then ( results => { let buffs = [ ] ; buffs = buffs . concat ( ... results ) ; resolve ( buffs ) ; } , error => { reject ( error ) ; } ) ; } ) ; return < RenderTask > { processes : processes , promise : pms , canceled : false } ; }