import xmldom from "@xmldom/xmldom" ; import { Reporter } from "./Reporter" ; import { InfoData , LogEntry } from "../LogEntry" ; import { RunContext } from "../../types/RunContext" ; import { LogLevel } from "../LogLevel" ; export class DgmlReporter implements Reporter { constructor ( ) { } log ( entry ) { if ( entry . msg == "info" && entry . level == LogLevel . info && entry . data ) { const packageTasks = ( entry . data as InfoData ) . packageTasks ; if ( packageTasks ) { const dgmlDoc = new xmldom . DOMImplementation ( ) . createDocument ( "http://schemas.microsoft.com/vs/2009/dgml" , "DirectedGraph" ) ; const directedGraph = dgmlDoc . documentElement ! ; directedGraph . setAttribute ( "GraphDirection" , "LeftToRight" ) ; const nodes = dgmlDoc . createElement ( "Nodes" ) ; const links = dgmlDoc . createElement ( "Links" ) ; const categories = dgmlDoc . createElement ( "Categories" ) ; directedGraph . appendChild ( nodes ) ; directedGraph . appendChild ( links ) ; directedGraph . appendChild ( categories ) ; const visitedCategories = new Set < string > ( ) ; for ( var packageTask of packageTasks ) { const node = dgmlDoc . createElement ( "Node" ) ; node . setAttribute ( "Id" , packageTask . id ) ; node . setAttribute ( "Label" , packageTask . id ) ; nodes . appendChild ( node ) ; const category = dgmlDoc . createElement ( "Category" ) ; category . setAttribute ( "Ref" , packageTask . task ) ; node . appendChild ( category ) ; for ( var dependencyId of packageTask . dependencies ) { const link = dgmlDoc . createElement ( "Link" ) ; link . setAttribute ( "Source" , packageTask . id ) ; link . setAttribute ( "Target" , dependencyId ) ; links . appendChild ( link ) ; } if ( ! visitedCategories . has ( packageTask . task ) ) { visitedCategories . add ( packageTask . task ) ; const category = dgmlDoc . createElement ( "Category" ) ; category . setAttribute ( "Id" , packageTask . task ) ; category . setAttribute ( "Label" , packageTask . task ) ; categories . appendChild ( category ) ; } } const dgmlContents = new xmldom . XMLSerializer ( ) . serializeToString ( dgmlDoc ) ; console . log ( dgmlContents ) ; } } } summarize ( context ) { } }