11const chalk = require ( 'chalk' )
2+ const execa = require ( 'execa' )
23const semver = require ( 'semver' )
34const getVersions = require ( './getVersions' )
4- const { clearConsole } = require ( '@vue/cli-shared-utils' )
5+ const { clearConsole, hasYarn, hasPnpm3OrLater } = require ( '@vue/cli-shared-utils' )
6+
7+ async function getInstallationCommand ( ) {
8+ if ( hasYarn ( ) ) {
9+ const { stdout : yarnGlobalDir } = await execa ( 'yarn' , [ 'global' , 'dir' ] )
10+ if ( __dirname . includes ( yarnGlobalDir ) ) {
11+ return 'yarn global add'
12+ }
13+ }
14+
15+ if ( hasPnpm3OrLater ( ) ) {
16+ const { stdout : pnpmGlobalPrefix } = await execa ( 'pnpm' , [ 'config' , 'get' , 'prefix' ] )
17+ if ( __dirname . includes ( pnpmGlobalPrefix ) && __dirname . includes ( 'pnpm-global' ) ) {
18+ return `pnpm i -g`
19+ }
20+ }
21+
22+ const { stdout : npmGlobalPrefix } = await execa ( 'npm' , [ 'config' , 'get' , 'prefix' ] )
23+ if ( __dirname . includes ( npmGlobalPrefix ) ) {
24+ return `npm i -g`
25+ }
26+ }
527
628exports . generateTitle = async function ( checkUpdate ) {
729 const { current, latest } = await getVersions ( )
@@ -16,12 +38,31 @@ exports.generateTitle = async function (checkUpdate) {
1638 }
1739 if ( checkUpdate && semver . gt ( latest , current ) ) {
1840 if ( process . env . VUE_CLI_API_MODE ) {
19- title += chalk . green ( ` 🌟️ Update available: ${ latest } ` )
41+ title += chalk . green ( ` 🌟️ New version available: ${ latest } ` )
2042 } else {
21- title += chalk . green ( `
22- ┌────────────────────${ `─` . repeat ( latest . length ) } ──┐
23- │ Update available: ${ latest } │
24- └────────────────────${ `─` . repeat ( latest . length ) } ──┘` )
43+ let upgradeMessage = `New version available ${ chalk . magenta ( current ) } → ${ chalk . green ( latest ) } `
44+
45+ try {
46+ const command = await getInstallationCommand ( )
47+ let name = require ( '../../package.json' ) . name
48+ if ( semver . prerelease ( latest ) ) {
49+ name += '@next'
50+ }
51+
52+ if ( command ) {
53+ upgradeMessage +=
54+ `\nRun ${ chalk . yellow ( `${ command } ${ name } ` ) } to update!`
55+ }
56+ } catch ( e ) { }
57+
58+ const upgradeBox = require ( 'boxen' ) ( upgradeMessage , {
59+ align : 'center' ,
60+ borderColor : 'green' ,
61+ dimBorder : true ,
62+ padding : 1
63+ } )
64+
65+ title += `\n${ upgradeBox } \n`
2566 }
2667 }
2768
0 commit comments