improve spinner

This commit is contained in:
Pooya Parsa 2018-03-16 09:56:23 +03:30
parent 1080dfdbd6
commit f2b3e780e0
4 changed files with 18 additions and 8 deletions

View File

@ -12,12 +12,11 @@ const webpackDevMiddleware = require('webpack-dev-middleware')
const webpackHotMiddleware = require('webpack-hot-middleware')
const Debug = require('debug')
const Glob = require('glob')
const { r, wp, wChunk, createRoutes, parallel, relativeTo, waitFor } = require('../common/utils')
const { r, wp, wChunk, createRoutes, parallel, relativeTo, waitFor, createSpinner } = require('../common/utils')
const { Options } = require('../common')
const clientWebpackConfig = require('./webpack/client.config.js')
const serverWebpackConfig = require('./webpack/server.config.js')
const upath = require('upath')
const ORA = require('ora')
const debug = Debug('nuxt:build')
debug.color = 2 // Force green color
@ -37,8 +36,7 @@ module.exports = class Builder {
this.webpackHotMiddleware = null
this.filesWatcher = null
this.customFilesWatcher = null
this.spinner = new ORA()
this.spinner.color = 'green'
this.spinner = createSpinner()
// Mute stats on dev
this.webpackStats = this.options.dev ? false : this.options.build.stats
@ -120,6 +118,8 @@ module.exports = class Builder {
}
}
this.spinner.succeed('Builder initialized')
this.spinner.start(`Generating nuxt files...`)
debug(`App root: ${this.options.srcDir}`)
@ -134,6 +134,8 @@ module.exports = class Builder {
// Generate routes and interpret the template files
await this.generateRoutesAndFiles()
this.spinner.succeed('Nuxt files generated')
this.spinner.start('Compiling...')
// Start webpack build

View File

@ -10,8 +10,7 @@ const _ = require('lodash')
const { resolve, join, dirname, sep } = require('path')
const { minify } = require('html-minifier')
const Chalk = require('chalk')
const ORA = require('ora')
const { printWarn } = require('../common/utils')
const { printWarn, createSpinner } = require('../common/utils')
const {
isUrl,
@ -36,7 +35,7 @@ module.exports = class Generator {
isUrl(this.options.build.publicPath) ? '' : this.options.build.publicPath
)
this.spinner = new ORA()
this.spinner = createSpinner()
}
async generate({ build = true, init = true } = {}) {

View File

@ -136,7 +136,7 @@ module.exports = function webpackBaseConfig({ name, isServer }) {
config.plugins.push(new ProgressPlugin({
spinner: this.spinner,
name: isServer ? 'server' : 'client',
color: isServer ? 'orange' : 'green'
color: isServer ? 'green' : 'darkgreen'
}))
}

View File

@ -2,6 +2,7 @@ const { resolve, relative, sep } = require('path')
const _ = require('lodash')
const PrettyError = require('pretty-error')
const Chalk = require('chalk')
const ORA = require('ora')
exports.pe = new PrettyError()
@ -28,6 +29,14 @@ exports.fatalError = function () {
process.exit(1)
}
exports.createSpinner = function () {
return new ORA({
color: 'green',
spinner: 'clock',
interval: 50
})
}
exports.encodeHtml = function encodeHtml(str) {
return str.replace(/</g, '&lt;').replace(/>/g, '&gt;')
}