import { LayerGraph } from "./layerGraph" ; import { commonOptions , commonOptionString , parseOption } from "../common/commonOptions" ; import { Timer } from "../common/timer" ; import { getResolvedFluidRoot } from "../common/fluidUtils" ; import { writeFileAsync } from "../common/utils" ; import { FluidRepo } from "../common/fluidRepo" ; import path from "path" ; function printUsage ( ) { console . log ( `
Usage: fluid-layer-check <options>
Options:
     --dot <path>     Generate *.dot for GraphViz
     --info <path>    Path to the layer graph json file
     --md [<path>]    Generate PACKAGES.md file for human consumption at path relative to repo root (default: repo root)
${ commonOptionString }
` ) ; } const packagesMdFileName = "PACKAGES.md" ; let dotGraphFilePath ; let mdFilePath ; let layerInfoPath ; function parseOptions ( argv ) { let error = false ; for ( let i = 2 ; i < process . argv . length ; i ++ ) { const argParsed = parseOption ( argv , i ) ; if ( argParsed < 0 ) { error = true ; break ; } if ( argParsed > 0 ) { i += argParsed - 1 ; continue ; } const arg = process . argv [ i ] ; if ( arg === "-?" || arg === "--help" ) { printUsage ( ) ; process . exit ( 0 ) ; } if ( arg === "--dot" ) { if ( i !== process . argv . length - 1 ) { dotGraphFilePath = process . argv [ ++ i ] ; continue ; } console . error ( "ERROR: Missing argument for --dot" ) ; error = true ; break ; } if ( arg === "--md" ) { if ( i !== process . argv . length - 1 ) { mdFilePath = process . argv [ ++ i ] ; continue ; } mdFilePath = "." ; break ; } if ( arg === "--info" ) { if ( i !== process . argv . length - 1 ) { layerInfoPath = path . resolve ( process . argv [ ++ i ] ) ; continue ; } console . error ( "ERROR: Missing argument for --info" ) ; error = true ; break ; } console . error ( `ERROR: Invalid arguments ${ arg }` ) ; error = true ; break ; } if ( error ) { printUsage ( ) ; process . exit ( - 1 ) ; } } parseOptions ( process . argv ) ; async function main ( ) { const timer = new Timer ( commonOptions . timer ) ; const resolvedRoot = await getResolvedFluidRoot ( ) ; const packages = new FluidRepo ( resolvedRoot , false ) . packages ; timer . time ( "Package scan completed" ) ; try { const layerGraph = LayerGraph . load ( resolvedRoot , packages , layerInfoPath ) ; if ( mdFilePath ) { const packagesMdFilePath = path . join ( resolvedRoot , mdFilePath , packagesMdFileName ) ; await writeFileAsync ( packagesMdFilePath , layerGraph . generatePackageLayersMarkdown ( resolvedRoot ) ) ; } if ( dotGraphFilePath !== undefined ) { await writeFileAsync ( dotGraphFilePath , layerGraph . generateDotGraph ( ) ) ; } const success = layerGraph . verify ( ) ; timer . time ( "Layer check completed" ) ; if ( ! success ) { process . exit ( - 1 ) ; } console . log ( `Layer check passed (${ packages . packages . length } packages)` ) ; } catch ( e ) { console . error ( e . message ) ; process . exit ( - 2 ) ; } } main ( ) ;