@@ -2,12 +2,13 @@ import path from 'path'
2
2
import { existsSync } from 'fs'
3
3
import consola from 'consola'
4
4
import esm from 'esm'
5
+ import exit from 'exit'
5
6
import defaultsDeep from 'lodash/defaultsDeep'
6
7
import { defaultNuxtConfigFile , getDefaultNuxtConfig } from '@nuxt/config'
7
- import boxen from 'boxen'
8
8
import chalk from 'chalk'
9
9
import prettyBytes from 'pretty-bytes'
10
10
import env from 'std-env'
11
+ import { successBox , warningBox } from './formatting'
11
12
12
13
export const requireModule = process . env . NUXT_TS ? require : esm ( module , {
13
14
cache : false ,
@@ -87,37 +88,30 @@ export function showBanner(nuxt) {
87
88
return
88
89
}
89
90
90
- const lines = [ ]
91
+ const titleLines = [ ]
92
+ const messageLines = [ ]
91
93
92
94
// Name and version
93
- lines . push ( `${ chalk . green . bold ( 'Nuxt.js' ) } ${ nuxt . constructor . version } ` )
95
+ titleLines . push ( `${ chalk . green . bold ( 'Nuxt.js' ) } ${ nuxt . constructor . version } ` )
94
96
95
97
// Running mode
96
- lines . push ( `Running in ${ nuxt . options . dev ? chalk . bold . blue ( 'development' ) : chalk . bold . green ( 'production' ) } mode (${ chalk . bold ( nuxt . options . mode ) } )` )
98
+ titleLines . push ( `Running in ${ nuxt . options . dev ? chalk . bold . blue ( 'development' ) : chalk . bold . green ( 'production' ) } mode (${ chalk . bold ( nuxt . options . mode ) } )` )
97
99
98
100
// https://nodejs.org/api/process.html#process_process_memoryusage
99
101
const { heapUsed, rss } = process . memoryUsage ( )
100
- lines . push ( `Memory usage: ${ chalk . bold ( prettyBytes ( heapUsed ) ) } (RSS: ${ prettyBytes ( rss ) } )` )
102
+ titleLines . push ( `Memory usage: ${ chalk . bold ( prettyBytes ( heapUsed ) ) } (RSS: ${ prettyBytes ( rss ) } )` )
101
103
102
104
// Listeners
103
- lines . push ( '' )
104
105
for ( const listener of nuxt . server . listeners ) {
105
- lines . push ( chalk . bold ( 'Listening on: ' ) + chalk . underline . blue ( listener . url ) )
106
+ messageLines . push ( chalk . bold ( 'Listening on: ' ) + chalk . underline . blue ( listener . url ) )
106
107
}
107
108
108
109
// Add custom badge messages
109
110
if ( nuxt . options . cli . badgeMessages . length ) {
110
- lines . push ( '' , ...nuxt . options . cli . badgeMessages )
111
+ messageLines . push ( '' , ...nuxt . options . cli . badgeMessages )
111
112
}
112
113
113
- const box = boxen ( lines . join ( '\n' ) , {
114
- borderColor : 'green' ,
115
- borderStyle : 'round' ,
116
- padding : 1 ,
117
- margin : 1
118
- } )
119
-
120
- process . stdout . write ( box + '\n' )
114
+ process . stdout . write ( successBox ( messageLines . join ( '\n' ) , titleLines . join ( '\n' ) ) )
121
115
}
122
116
123
117
export function formatPath ( filePath ) {
@@ -144,3 +138,23 @@ export function normalizeArg(arg, defaultValue) {
144
138
}
145
139
return arg
146
140
}
141
+
142
+ export function forceExit ( cmdName , timeout ) {
143
+ if ( timeout ) {
144
+ const exitTimeout = setTimeout ( ( ) => {
145
+ const msg = `The command 'nuxt ${ cmdName } ' finished but did not exit after ${ timeout } s
146
+ This is most likely not caused by a bug in Nuxt.js\
147
+ Make sure to cleanup all timers and listeners you or your plugins/modules start.
148
+ Nuxt.js will now force exit
149
+
150
+ ${ chalk . bold ( 'DeprecationWarning: Starting with Nuxt version 3 this will be a fatal error' ) } `
151
+
152
+ // TODO: Change this to a fatal error in v3
153
+ process . stderr . write ( warningBox ( msg ) )
154
+ exit ( 0 )
155
+ } , timeout * 1000 )
156
+ exitTimeout . unref ( )
157
+ } else {
158
+ exit ( 0 )
159
+ }
160
+ }
0 commit comments