feat: minimal logger for CI/Test environments

This commit is contained in:
Pooya Parsa 2018-03-21 01:41:30 +03:30
parent db1ee4bc31
commit 13d17d241e
7 changed files with 52 additions and 17 deletions

View File

@ -39,8 +39,9 @@ export default class Builder {
this.webpackHotMiddleware = null
this.filesWatcher = null
this.customFilesWatcher = null
this.spinner = createSpinner()
this.spinner.enabled = !this.options.test
this.spinner = createSpinner({
minimal: this.options.test || this.options.ci
})
// Mute stats on dev
this.webpackStats = this.options.dev ? false : this.options.build.stats

View File

@ -20,8 +20,9 @@ export default class Generator {
isUrl(this.options.build.publicPath) ? '' : this.options.build.publicPath
)
this.spinner = createSpinner()
this.spinner.enabled = !this.options.test
this.spinner = createSpinner({
minimal: this.options.test || this.options.ci
})
}
async generate({ build = true, init = true } = {}) {

View File

@ -132,11 +132,13 @@ export default function webpackBaseConfig({ name, isServer }) {
if (this.options.build.profile) {
config.plugins.push(new webpack.ProgressPlugin({ profile: true }))
} else {
config.plugins.push(new ProgressPlugin({
spinner: this.spinner,
name: isServer ? 'server' : 'client',
color: isServer ? 'green' : 'darkgreen'
}))
if (!(this.options.test || this.options.ci)) {
config.plugins.push(new ProgressPlugin({
spinner: this.spinner,
name: isServer ? 'server' : 'client',
color: isServer ? 'green' : 'darkgreen'
}))
}
}
}

View File

@ -1,20 +1,31 @@
import path from 'path'
import isCI from 'is-ci'
export default {
mode: 'universal',
// Information about running environment
dev: process.env.NODE_ENV !== 'production',
debug: undefined, // Will be equal to dev if not provided
test: process.env.NODE_ENV === 'test',
ci: Boolean(isCI),
// Mode
mode: 'universal',
// Dirs
buildDir: '.nuxt',
cacheDir: '.cache',
nuxtDir: path.resolve(__dirname, '../..'),
nuxtAppDir: path.resolve(__dirname, '../app'),
modulesDir: ['node_modules'], // ~> relative to options.rootDir
// Ignore
ignorePrefix: '-',
ignore: [
'**/*.test.*'
],
extensions: [],
build: {
analyze: false,
profile: process.argv.includes('--profile'),

View File

@ -26,12 +26,31 @@ export const fatalError = function () {
process.exit(1)
}
export const createSpinner = function () {
return new ORA({
color: 'green',
spinner: 'clock',
interval: 50
})
export const createSpinner = function ({ minimal = false }) {
// Use ORA by default
if (!minimal) {
return new ORA({
color: 'green',
spinner: 'clock',
interval: 50
})
}
// Creare a minimal fallback for test and CI environments
// eslint-disable-next-line no-console
const logger = (tag) => (...args) => console.log(
`[${(new Date().toISOString)()}]`,
_.padEnd(`[${tag}]`, 10),
...args
)
return {
start: logger('START'),
failed: logger('FAIL'),
succeed: logger('SUCCESS'),
info: logger('INFO')
}
}
export const encodeHtml = function encodeHtml(str) {

View File

@ -81,6 +81,7 @@
"html-minifier": "^3.5.12",
"html-webpack-inline-source-plugin": "^0.0.10",
"html-webpack-plugin": "^3.0.7",
"is-ci": "^1.1.0",
"launch-editor-middleware": "^2.2.1",
"lodash": "^4.17.5",
"lru-cache": "^4.1.2",

View File

@ -3522,7 +3522,7 @@ is-callable@^1.1.1, is-callable@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.3.tgz#86eb75392805ddc33af71c92a0eedf74ee7604b2"
is-ci@^1.0.10:
is-ci@^1.0.10, is-ci@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-1.1.0.tgz#247e4162e7860cebbdaf30b774d6b0ac7dcfe7a5"
dependencies: