import { EventEmitter } from "events" ; import * as actions from "../actions" ; import * as activities from "../activities" ; import * as configuration from "../configuration/index" ; import * as events from "../events/index" ; import * as files from "../filesystem/index" ; import * as parsers from "../parsers" ; import { Command } from "./command" ; export class Unused implements Command { userConfig : configuration . APIData ; emitter : EventEmitter ; constructor ( userConfig ) { this . userConfig = userConfig ; this . emitter = new EventEmitter ( ) ; } emit ( name , payload ) { this . emitter . emit ( name , payload ) ; } async execute ( ) { const config = await configuration . addDefaults ( this . userConfig ) ; const filenames = await files . getFileNames ( config ) ; if ( filenames . length === 0 ) { this . emit ( "result" , { status : "warning" , message : "no Markdown files found" } ) ; return ; } const ASTs = await parsers . markdown . parse ( filenames , config . sourceDir ) ; const usedActivityNames = activities . extractDynamic ( ASTs , config . regionMarker ) . map ( activity => activity . actionName ) ; const definedActivityNames = ( await actions . Finder . load ( config . sourceDir ) ) . customActionNames ( ) ; const unusedActivityNames = definedActivityNames . filter ( definedActivityName => ! usedActivityNames . includes ( definedActivityName ) ) ; this . emit ( "output" , "Unused activities:" ) ; for ( const unusedActivityName of unusedActivityNames ) { this . emit ( "output" , `- ${ unusedActivityName }` ) ; } } on ( name , handler ) { this . emitter . on ( name , handler ) ; return this ; } }