mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
56b1f81ace
* Remove usage of WebpackBar and Friendly Errors * Add new clearConsole helper * Add new simplified output for development mode * Add an explicit bootstrapping mode * Add missing returns * Use existing output style * Adjust first output to say Waiting on * Only print URL if present
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
import chalk from 'chalk'
|
|
import createStore from 'unistore'
|
|
|
|
import { clearConsole } from './clearConsole'
|
|
|
|
export type OutputState =
|
|
| { bootstrap: true; appUrl: string | null }
|
|
| ({ bootstrap: false; appUrl: string | null } & (
|
|
| { loading: true }
|
|
| {
|
|
loading: false
|
|
errors: string[] | null
|
|
warnings: string[] | null
|
|
}))
|
|
|
|
export const store = createStore<OutputState>({ appUrl: null, bootstrap: true })
|
|
|
|
store.subscribe(state => {
|
|
clearConsole()
|
|
|
|
if (state.bootstrap) {
|
|
console.log(chalk.cyan('Starting the development server ...'))
|
|
if (state.appUrl) {
|
|
console.log()
|
|
console.log(` > Waiting on ${state.appUrl!}`)
|
|
}
|
|
return
|
|
}
|
|
|
|
if (state.loading) {
|
|
console.log('Compiling ...')
|
|
return
|
|
}
|
|
|
|
if (state.errors) {
|
|
console.log(chalk.red('Failed to compile.'))
|
|
console.log()
|
|
console.log(state.errors[0])
|
|
return
|
|
}
|
|
|
|
if (state.warnings) {
|
|
console.log(chalk.yellow('Compiled with warnings.'))
|
|
console.log()
|
|
console.log(state.warnings.join('\n\n'))
|
|
return
|
|
}
|
|
|
|
console.log(chalk.green('Compiled successfully!'))
|
|
if (state.appUrl) {
|
|
console.log()
|
|
console.log(` > Ready on ${state.appUrl!}`)
|
|
}
|
|
console.log()
|
|
console.log('Note that pages will be compiled when you first load them.')
|
|
})
|