import { createError, MrBuildSpecBuilderCommandHandlerArgs, MrPackageBuilderCommandResults, shellExecCommandSettingsToCommandLine, } from '@cirrusct/mr-core'; import { shellExec, ShellExecError } from '@cirrusct/shell-exec'; import { StartCommandOptions } from '../../commands'; import { BuildSpecConfigSettings } from '../../config'; // import { startCommandSettingsToCommandLine } from '../../lib'; import { SpecBuilderCommandHandlerBase } from './SpecBuilderCommandHandlerBase'; export abstract class SpecBuilderStartCommandHandlerBase extends SpecBuilderCommandHandlerBase< StartCommandOptions, {}, BuildSpecConfigSettings > { protected constructor( args: MrBuildSpecBuilderCommandHandlerArgs ) { super(args); } public async run(): Promise { debugger; const cmdLine = shellExecCommandSettingsToCommandLine( this.buildSpecSettings.startCommand, this.mrPackage, this.logger, this.args.options, this.buildSpecSettings ); this.logger.debug( { isDev: !this.isProduction, cmdLine, }, 'Start Command' ); try { const results = await shellExec(cmdLine); return { exitCode: results.exitCode, }; } catch(e) { const shellExecErr: ShellExecError = e; const errorWrapperMsg = 'Start command failed to execute shell command'; this.logger.error({ exitCode: shellExecErr.exitCode, message: shellExecErr.message, shellCommand: shellExecErr.command, }, errorWrapperMsg); throw createError(errorWrapperMsg, e); } } }