import commander from "commander" ; import { build as buildCmd , exit as exitCmd } from "../../lib/commandBuilder" ; import { generateDefaultHldComponentYaml , generateGitIgnoreFile , generateHldAzurePipelinesYaml , } from "../../lib/fileutils" ; import { checkoutCommitPushCreatePRLink } from "../../lib/gitpr" ; import { hasValue } from "../../lib/validator" ; import { logger } from "../../logger" ; import decorator from "./init.decorator.json" ; import { build as buildError , log as logError } from "../../lib/errorBuilder" ; import { errorStatusCode } from "../../lib/errorStatusCode" ; import { CLI_LOG_FILENAME } from "../../lib/constants" ; interface CommandOptions { defaultComponentGit : string ; defaultComponentName : string ; defaultComponentPath : string ; gitPush : boolean ; } export const initialize = async ( hldRepoPath , gitPush , componentGit , componentName , componentPath ) : Promise < void > => { logger . info ( "Initializing bedrock HLD repository." ) ; generateHldAzurePipelinesYaml ( hldRepoPath ) ; generateDefaultHldComponentYaml ( hldRepoPath , componentGit , componentName , componentPath ) ; generateGitIgnoreFile ( hldRepoPath , [ CLI_LOG_FILENAME ] ) ; if ( gitPush ) { const newBranchName = "bedrock-hld-init" ; const directory = "." ; await checkoutCommitPushCreatePRLink ( newBranchName , directory ) ; } } ; export const execute = async ( hldRepoPath , gitPush , componentGit , componentName , componentPath , exitFn ) : Promise < void > => { try { if ( ! hasValue ( hldRepoPath ) ) { throw buildError ( errorStatusCode . VALIDATION_ERR , "hld-init-cmd-project-path-missing" ) ; } await initialize ( hldRepoPath , gitPush , componentGit , componentName , componentPath ) ; await exitFn ( 0 ) ; } catch ( err ) { logError ( buildError ( errorStatusCode . CMD_EXE_ERR , "hld-init-cmd-failed" , err ) ) ; await exitFn ( 1 ) ; } } ; export const commandDecorator = ( command ) : void => { buildCmd ( command , decorator ) . action ( async ( opts ) => { const hldRepoPath = process . cwd ( ) ; await execute ( hldRepoPath , opts . gitPush , opts . defaultComponentGit , opts . defaultComponentName , opts . defaultComponentPath , async ( status ) => { await exitCmd ( logger , process . exit , status ) ; } ) ; } ) ; } ;