import { loadTSConfig , projectRoot } from "@zwave-js/maintenance" ; import * as path from "path" ; import ts from "typescript" ; export function checkCCToLogEntry ( ) { const tsConfig = loadTSConfig ( "zwave-js" ) ; const program = ts . createProgram ( tsConfig . fileNames , tsConfig . options ) ; const results = new Map < string , boolean | "empty" | "constructor" > ( ) ; for ( const sourceFile of program . getSourceFiles ( ) ) { const relativePath = path . relative ( projectRoot , sourceFile . fileName ) . replace ( /\\/g , "/" ) ; if ( relativePath . startsWith ( ".." ) ) continue ; if ( ! relativePath . includes ( "/commandclass/" ) ) { continue ; } if ( relativePath . endsWith ( ".test.ts" ) || relativePath . endsWith ( "index.ts" ) ) { continue ; } ts . forEachChild ( sourceFile , ( node ) => { if ( ts . isClassDeclaration ( node ) && node . name && node . name . text . includes ( "CC" ) && ! node . name . text . endsWith ( "CC" ) && ! node . name . text . endsWith ( "API" ) ) { if ( node . members . length === 0 ) { results . set ( node . name . text , "empty" ) ; } else if ( node . members . length === 1 && node . members [ 0 ] . kind === ts . SyntaxKind . Constructor ) { results . set ( node . name . text , "constructor" ) ; } else { const hasToLogEntry = node . members . some ( ( member ) => ts . isMethodDeclaration ( member ) && member . name . getText ( sourceFile ) === "toLogEntry" ) ; results . set ( node . name . text , hasToLogEntry ) ; } } } ) ; } const sortedCCs = [ ... results . keys ( ) ] . sort ( ) ; for ( const cc of sortedCCs ) { const checkResult = results . get ( cc ) ! ; console . error ( `- [${ checkResult !== false ? "x" : " " }] ${ cc }${ checkResult === "empty" ? " _(empty CC)_" : checkResult === "constructor" ? " **(constructor only)**" : "" }` ) ; } if ( [ ... results . values ( ) ] . every ( ( v ) => v !== false ) ) { console . error ( ) ; console . error ( "All CCs have a toLogEntry implementation :)" ) ; } } if ( require . main === module ) { checkCCToLogEntry ( ) ; process . exit ( 0 ) ; }