import { inject , injectable } from 'inversify' ; import { IGitCheckoutCommandHandler , IGitCherryPickCommandHandler , IGitCommitViewDetailsCommandHandler , IGitCompareCommandHandler , IGitMergeCommandHandler , IGitRebaseCommandHandler , IGitRevertCommandHandler , } from '../commandHandlers/types' ; import { CheckoutCommand } from '../commands/commit/checkout' ; import { CherryPickCommand } from '../commands/commit/cherryPick' ; import { CompareCommand } from '../commands/commit/compare' ; import { MergeCommand } from '../commands/commit/merge' ; import { RebaseCommand } from '../commands/commit/rebase' ; import { RevertCommand } from '../commands/commit/revert' ; import { SelectForComparison } from '../commands/commit/selectForComparion' ; import { ViewDetailsCommand } from '../commands/commit/viewDetails' ; import { CommitDetails , ICommand } from '../common/types' ; import { ICommitCommandFactory } from './types' ; @ injectable ( ) export class CommitCommandFactory implements ICommitCommandFactory { constructor ( @ inject ( IGitCherryPickCommandHandler ) private cherryPickHandler , @ inject ( IGitCheckoutCommandHandler ) private checkoutHandler , @ inject ( IGitCompareCommandHandler ) private compareHandler , @ inject ( IGitMergeCommandHandler ) private mergeHandler , @ inject ( IGitRebaseCommandHandler ) private rebaseHandler , @ inject ( IGitRevertCommandHandler ) private revertHandler , @ inject ( IGitCommitViewDetailsCommandHandler ) private viewChangeLogHandler ) { } public async createCommands ( commit ) { const commands = [ new CherryPickCommand ( commit , this . cherryPickHandler ) , new CheckoutCommand ( commit , this . checkoutHandler ) , new ViewDetailsCommand ( commit , this . viewChangeLogHandler ) , new SelectForComparison ( commit , this . compareHandler ) , new RevertCommand ( commit , this . revertHandler ) , new CompareCommand ( commit , this . compareHandler ) , new MergeCommand ( commit , this . mergeHandler ) , new RebaseCommand ( commit , this . rebaseHandler ) , ] ; return ( await Promise . all ( commands . map ( async ( cmd ) => { const result = cmd . preExecute ( ) ; const available = typeof result === 'boolean' ? result : await result ; return available ? cmd : undefined ; } ) ) ) . filter ( cmd => ! ! cmd ) . map ( cmd => cmd ! ) ; } }