Skip to content

Commit

Permalink
fix: stop spinner before logging writes
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 11, 2020
1 parent 8cd2354 commit 3d16951
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
15 changes: 15 additions & 0 deletions src/node/build/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path'
import fs from 'fs-extra'
import chalk from 'chalk'
import { Ora } from 'ora'
import resolve from 'resolve-from'
import { rollup as Rollup, RollupOutput, ExternalOption } from 'rollup'
import { createResolver, supportedExts } from '../resolver'
Expand Down Expand Up @@ -47,6 +48,7 @@ export async function build(options: BuildConfig = {}): Promise<BuildResult> {
})
}

const isTest = process.env.NODE_ENV === 'test'
process.env.NODE_ENV = 'production'
const start = Date.now()

Expand All @@ -72,6 +74,17 @@ export async function build(options: BuildConfig = {}): Promise<BuildResult> {
sourcemap = false
} = options

let spinner: Ora | undefined
const msg = 'Building for production...'
if (!silent) {
if (process.env.DEBUG || isTest) {
console.log(msg)
} else {
console.log(process.env.NODE_ENV)
spinner = require('ora')(msg + '\n').start()
}
}

const indexPath = path.resolve(root, 'index.html')
const publicBasePath = base.replace(/([^/])$/, '$1/') // ensure ending slash
const resolvedAssetsPath = path.join(outDir, assetsDir)
Expand Down Expand Up @@ -171,6 +184,8 @@ export async function build(options: BuildConfig = {}): Promise<BuildResult> {
...rollupOutputOptions
})

spinner && spinner.stop()

const indexHtml = emitIndex ? renderIndex(output, cssFileName) : ''

if (write) {
Expand Down
10 changes: 0 additions & 10 deletions src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ if (argv.debug) {

import os from 'os'
import chalk from 'chalk'
import { Ora } from 'ora'
import { UserConfig, resolveConfig } from './config'

function logHelp() {
Expand Down Expand Up @@ -144,19 +143,10 @@ async function runServe(
}

async function runBuild(options: UserConfig) {
let spinner: Ora | undefined
const msg = 'Building for production...'
if (process.env.DEBUG || process.env.NODE_ENV === 'test') {
console.log(msg)
} else {
spinner = require('ora')(msg + '\n').start()
}
try {
await require('../dist').build(options)
spinner && spinner.stop()
process.exit(0)
} catch (err) {
spinner && spinner.stop()
console.error(chalk.red(`[vite] Build errored out.`))
console.error(err)
process.exit(1)
Expand Down

0 comments on commit 3d16951

Please sign in to comment.