| 5 | const isPrismaInstalledGlobally = isCurrentBinInstalledGlobally() |
| 6 | |
| 7 | export function printUpdateMessage(checkResult: Check.Result | 0 | void): void { |
| 8 | const shouldHide = process.env.PRISMA_HIDE_UPDATE_MESSAGE |
| 9 | if (!checkResult || checkResult.status !== 'ok' || shouldHide || !checkResult.data.outdated) { |
| 10 | return |
| 11 | } |
| 12 | |
| 13 | let boxHeight = 4 |
| 14 | let majorText = '' |
| 15 | |
| 16 | const currentVersionInstalled = checkResult.data.previous_version |
| 17 | const latestVersionAvailable = checkResult.data.current_version |
| 18 | |
| 19 | const prismaCLICommand = makeInstallCommand(checkResult.data.package, checkResult.data.release_tag) |
| 20 | const prismaClientCommand = makeInstallCommand('@prisma/client', checkResult.data.release_tag, { |
| 21 | canBeGlobal: false, |
| 22 | canBeDev: false, |
| 23 | }) |
| 24 | |
| 25 | try { |
| 26 | const [majorInstalled] = currentVersionInstalled.split('.') |
| 27 | const [majorLatest] = latestVersionAvailable.split('.') |
| 28 | |
| 29 | if (majorInstalled < majorLatest) { |
| 30 | majorText = `\nThis is a major update - please follow the guide at\nhttps://pris.ly/d/major-version-upgrade\n\n` |
| 31 | boxHeight = boxHeight + 4 |
| 32 | } |
| 33 | } catch (e) {} |
| 34 | |
| 35 | const boxText = `\n${blue( |
| 36 | 'Update available', |
| 37 | )} ${currentVersionInstalled} -> ${latestVersionAvailable}\n${majorText}Run the following to update |
| 38 | ${bold(prismaCLICommand)} |
| 39 | ${bold(prismaClientCommand)}` |
| 40 | |
| 41 | const boxedMessage = drawBox({ |
| 42 | height: boxHeight, |
| 43 | width: 59, |
| 44 | str: boxText, |
| 45 | horizontalPadding: 2, |
| 46 | }) |
| 47 | |
| 48 | console.error(boxedMessage) |
| 49 | } |
| 50 | |
| 51 | function makeInstallCommand( |
| 52 | packageName: string, |