import commander from "commander" ; import * as bedrock from "../../lib/bedrockYaml" ; import { build as buildCmd , exit as exitCmd } from "../../lib/commandBuilder" ; import { updateTriggerBranchesForServiceBuildAndUpdatePipeline } from "../../lib/fileutils" ; import { hasValue } from "../../lib/validator" ; import { logger } from "../../logger" ; import { BedrockFileInfo } from "../../types" ; import decorator from "./delete.decorator.json" ; import { build as buildError , log as logError } from "../../lib/errorBuilder" ; import { errorStatusCode } from "../../lib/errorStatusCode" ; param projectPath export const checkDependencies = ( projectPath ) : void => { const fileInfo = bedrock . fileInfo ( projectPath ) ; if ( fileInfo . exist === false ) { throw buildError ( errorStatusCode . VALIDATION_ERR , "ring-delete-cmd-err-dependency" ) ; } } ; param ringName param projectPath export const execute = async ( ringName , projectPath , exitFn ) : Promise < void > => { try { if ( ! hasValue ( ringName ) ) { throw buildError ( errorStatusCode . VALIDATION_ERR , "ring-delete-cmd-err-name-missing" ) ; } logger . info ( `Project path: ${ projectPath }` ) ; checkDependencies ( projectPath ) ; const bedrockConfig = bedrock . read ( projectPath ) ; const bedrockWithoutRing = bedrock . removeRing ( bedrockConfig , ringName ) ; bedrock . create ( projectPath , bedrockWithoutRing ) ; const ringBranches = Object . keys ( bedrockWithoutRing . rings ) ; for ( const { path : servicePath } of bedrockConfig . services ) { updateTriggerBranchesForServiceBuildAndUpdatePipeline ( ringBranches , servicePath ) ; } logger . info ( `Successfully deleted ring: ${ ringName } from this project!` ) ; await exitFn ( 0 ) ; } catch ( err ) { logError ( buildError ( errorStatusCode . EXE_FLOW_ERR , "ring-delete-cmd-failed" , err ) ) ; await exitFn ( 1 ) ; } } ; export const commandDecorator = ( command ) : void => { buildCmd ( command , decorator ) . action ( async ( ringName ) => { await execute ( ringName , process . cwd ( ) , async ( status ) => { await exitCmd ( logger , process . exit , status ) ; } ) ; } ) ; } ;