From 50d351d4178297eba0c917fb3a1959a073127c44 Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Tue, 10 Dec 2019 17:40:22 -0500 Subject: restored updateSearch, changed log_execution behavior, changed search from singleton class instance to namespace --- src/server/ActionUtilities.ts | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/server/ActionUtilities.ts') diff --git a/src/server/ActionUtilities.ts b/src/server/ActionUtilities.ts index 94008e171..4667254d8 100644 --- a/src/server/ActionUtilities.ts +++ b/src/server/ActionUtilities.ts @@ -3,7 +3,7 @@ import { ExecOptions } from 'shelljs'; import { exec } from 'child_process'; import * as path from 'path'; import * as rimraf from "rimraf"; -import { yellow } from 'colors'; +import { yellow, Color } from 'colors'; export const command_line = (command: string, fromDirectory?: string) => { return new Promise((resolve, reject) => { @@ -29,18 +29,29 @@ export const write_text_file = (relativePath: string, contents: any) => { }); }; -export interface LogData { +export interface LogData { startMessage: string; endMessage: string; - action: () => void | Promise; + action: () => T | Promise; + color?: Color; } let current = Math.ceil(Math.random() * 20); -export async function log_execution({ startMessage, endMessage, action }: LogData) { - const color = `\x1b[${31 + current++ % 6}m%s\x1b[0m`; - console.log(color, `${startMessage}...`); - await action(); - console.log(color, endMessage); +export async function log_execution({ startMessage, endMessage, action, color }: LogData): Promise { + let result: T; + const formattedStart = `${startMessage}...`; + const formattedEnd = `${endMessage}.`; + if (color) { + console.log(color(formattedStart)); + result = await action(); + console.log(color(formattedEnd)); + } else { + const color = `\x1b[${31 + current++ % 6}m%s\x1b[0m`; + console.log(color, formattedStart); + result = await action(); + console.log(color, formattedEnd); + } + return result; } export function logPort(listener: string, port: number) { -- cgit v1.2.3-70-g09d2