import { drawBox , isCurrentBinInstalledGlobally , logger } from '@prisma/sdk' ; import chalk from 'chalk' ; import type { Check } from 'checkpoint-client' ; const isPrismaInstalledGlobally = isCurrentBinInstalledGlobally ( ) ; export function printUpdateMessage ( checkResult ) { let boxHeight = 4 ; let majorText = '' ; const currentVersionInstalled = checkResult . data . previous_version ; const latestVersionAvailable = checkResult . data . current_version ; const prismaCLICommand = makeInstallCommand ( checkResult . data . package , checkResult . data . release_tag ) ; const prismaClientCommand = makeInstallCommand ( '@prisma/client' , checkResult . data . release_tag , { canBeGlobal : false , canBeDev : false , } ) ; try { const [ majorInstalled ] = currentVersionInstalled . split ( '.' ) ; const [ majorLatest ] = latestVersionAvailable . split ( '.' ) ; if ( majorInstalled < majorLatest ) { majorText = `\nThis is a major update - please follow the guide at\nhttps://pris.ly/d/major-version-upgrade\n\n` ; boxHeight = boxHeight + 4 ; } } catch ( e ) { } const boxText = `\n${ chalk . blue ( 'Update available' ) } ${ currentVersionInstalled } -> ${ latestVersionAvailable }\n${ majorText }Run the following to update
  ${ chalk . bold ( prismaCLICommand ) }
  ${ chalk . bold ( prismaClientCommand ) }` ; const boxedMessage = drawBox ( { height : boxHeight , width : 59 , str : boxText , horizontalPadding : 2 , } ) ; console . error ( boxedMessage ) ; } function makeInstallCommand ( packageName , tag , options = { canBeGlobal : true , canBeDev : true , } ) { const yarnUsed = process . env . npm_config_user_agent ?. includes ( 'yarn' ) ; let command = '' ; if ( isPrismaInstalledGlobally === 'yarn' && options . canBeGlobal ) { command = `yarn global add ${ packageName }` ; } else if ( isPrismaInstalledGlobally === 'npm' && options . canBeGlobal ) { command = `npm i -g ${ packageName }` ; } else if ( yarnUsed && options . canBeDev ) { command = `yarn add --dev ${ packageName }` ; } else if ( options . canBeDev ) { command = `npm i --save-dev ${ packageName }` ; } else if ( yarnUsed ) { command = `yarn add ${ packageName }` ; } else { command = `npm i ${ packageName }` ; } command += `@${ tag }` ; return command ; }