Skip to content

Commit

Permalink
Merge multiple log statements (#35310)
Browse files Browse the repository at this point in the history
* Merge multiple log statements

It is inefficient to use multiple console.log satements, and if something is logged to the console in the middle of execution, it will be in the center of the text, making it hard to read.
This pull request merges multiple console.logs into one.

In addition, it reduces the bundle size.

* ensure formatting matches

* update test

Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
Exortions and ijjk authored May 22, 2022
1 parent b3c636d commit cfe8132
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,14 @@ async function run(): Promise<void> {
}

if (!projectPath) {
console.log()
console.log('Please specify the project directory:')
console.log(
` ${chalk.cyan(program.name())} ${chalk.green('<project-directory>')}`
)
console.log()
console.log('For example:')
console.log(` ${chalk.cyan(program.name())} ${chalk.green('my-next-app')}`)
console.log()
console.log(
`Run ${chalk.cyan(`${program.name()} --help`)} to see all options.`
'\nPlease specify the project directory:\n' +
` ${chalk.cyan(program.name())} ${chalk.green(
'<project-directory>'
)}\n` +
'For example:\n' +
` ${chalk.cyan(program.name())} ${chalk.green('my-next-app')}\n\n` +
`Run ${chalk.cyan(`${program.name()} --help`)} to see all options.`
)
process.exit(1)
}
Expand Down Expand Up @@ -172,20 +169,17 @@ async function notifyUpdate(): Promise<void> {
const res = await update
if (res?.latest) {
const pkgManager = getPkgManager()

console.log()
console.log(
chalk.yellow.bold('A new version of `create-next-app` is available!')
)
console.log(
'You can update by running: ' +
chalk.yellow.bold('A new version of `create-next-app` is available!') +
'\n' +
'You can update by running: ' +
chalk.cyan(
pkgManager === 'yarn'
? 'yarn global add create-next-app'
: `${pkgManager} install --global create-next-app`
)
) +
'\n'
)
console.log()
}
process.exit()
} catch {
Expand All @@ -201,8 +195,10 @@ run()
if (reason.command) {
console.log(` ${chalk.cyan(reason.command)} has failed.`)
} else {
console.log(chalk.red('Unexpected error. Please report it as a bug:'))
console.log(reason)
console.log(
chalk.red('Unexpected error. Please report it as a bug:') + '\n',
reason
)
}
console.log()

Expand Down

0 comments on commit cfe8132

Please sign in to comment.