All files / src/functions find.command.action.ts

33.33% Statements 5/15
0% Branches 0/1
0% Functions 0/2
28.57% Lines 4/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29    1x 1x       1x                                       1x  
'use strict';
 
import {each, first} from 'lodash';
import {listSubfoldersFilesByFolderName} from '@owservable/folders';
 
import ActionAsCommandInterface from '../interfaces/action.as.command.interface';
 
export const findCommandAction = (root: string, cliCommand: string): ActionAsCommandInterface => {
	const actionPaths: string[] = listSubfoldersFilesByFolderName(root, 'actions');
 
	let action: ActionAsCommandInterface;
 
	each(actionPaths, (actionPath: string) => {
		console.log('[@owservable/actions] -> Initializing command action', actionPath);
		// tslint:disable-next-line:callable-types
		const ActionClass: {new (): ActionAsCommandInterface} = require(actionPath).default;
		const actionInstance = new ActionClass();
		const actionCommand = first(actionInstance.signature().split(' '));
 
		Iif (cliCommand === actionCommand) {
			action = actionInstance;
			return false;
		}
	});
 
	return action;
};
export default findCommandAction;