Skip to content

Commit

Permalink
feat(ui): Progress and Logs systems
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Mar 9, 2018
1 parent 61655b1 commit 9f0eece
Show file tree
Hide file tree
Showing 37 changed files with 1,138 additions and 265 deletions.
23 changes: 22 additions & 1 deletion packages/@vue/cli-shared-utils/lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
const chalk = require('chalk')
const readline = require('readline')
const padStart = require('string.prototype.padstart')
const EventEmitter = require('events')

exports.events = new EventEmitter()

function _log (type, tag, message) {
if (process.env.VUE_CLI_API_MODE && message) {
exports.events.emit('log', {
message,
type,
tag
})
}
}

const format = (label, msg) => {
return msg.split('\n').map((line, i) => {
Expand All @@ -12,24 +25,32 @@ const format = (label, msg) => {

const chalkTag = msg => chalk.bgBlackBright.white.dim(` ${msg} `)

exports.log = (msg = '', tag = null) => tag ? console.log(format(chalkTag(tag), msg)) : console.log(msg)
exports.log = (msg = '', tag = null) => {
tag ? console.log(format(chalkTag(tag), msg)) : console.log(msg)
_log('log', tag, msg)
}

exports.info = (msg, tag = null) => {
console.log(format(chalk.bgBlue.black(' INFO ') + (tag ? chalkTag(tag) : ''), msg))
_log('info', tag, msg)
}

exports.done = (msg, tag = null) => {
console.log(format(chalk.bgGreen.black(' DONE ') + (tag ? chalkTag(tag) : ''), msg))
_log('done', tag, msg)
}

exports.warn = (msg, tag = null) => {
console.warn(format(chalk.bgYellow.black(' WARN ') + (tag ? chalkTag(tag) : ''), chalk.yellow(msg)))
_log('warn', tag, msg)
}

exports.error = (msg, tag = null) => {
console.error(format(chalk.bgRed(' ERROR ') + (tag ? chalkTag(tag) : ''), chalk.red(msg)))
_log('error', tag, msg)
if (msg instanceof Error) {
console.error(msg.stack)
_log('error', tag, msg.stack)
}
}

Expand Down
4 changes: 3 additions & 1 deletion packages/@vue/cli-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@vue/cli-service": "^3.0.0-beta.3",
"@vue/eslint-config-standard": "^3.0.0-beta.3",
"@vue/ui": "^0.1.9",
"ansi_up": "^2.0.2",
"apollo-cache-inmemory": "^1.1.10",
"apollo-client": "^2.2.6",
"apollo-link": "^1.2.1",
Expand All @@ -38,7 +39,8 @@
"vue-apollo": "^3.0.0-alpha.1",
"vue-cli-plugin-apollo": "^0.4.1",
"vue-router": "^3.0.1",
"vue-template-compiler": "^2.5.13"
"vue-template-compiler": "^2.5.13",
"xterm": "^3.2.0"
},
"browserslist": [
"> 1%",
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default {
.app
display grid
grid-template-columns 1fr
grid-template-rows auto 28px
grid-template-rows 1fr auto
grid-template-areas "content" "status"
.content
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-ui/src/components/ListItemInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default {
justify-content center
.description
color lighten($vue-color-dark, 40%)
color $color-text-light
&.selected
.name
Expand Down
64 changes: 0 additions & 64 deletions packages/@vue/cli-ui/src/components/LoadingScreen.vue

This file was deleted.

105 changes: 105 additions & 0 deletions packages/@vue/cli-ui/src/components/LoggerMessage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<template>
<div
class="logger-message"
:class="[
`type-${message.type}`,
{
'has-type': message.type !== 'log',
'has-tag': message.tag,
pre
}
]"
>
<div v-if="message.type !== 'log'" class="type">{{ message.type }}</div>
<div v-if="message.tag" class="tag">{{ message.tag }}</div>
<div class="message" v-html="formattedMessage"/>
</div>
</template>

<script>
import AU from 'ansi_up'
const ansiUp = new AU()
ansiUp.use_classes = true
export default {
props: {
message: {
type: Object,
required: true
},
pre: {
type: Boolean,
default: false
}
},
computed: {
formattedMessage () {
return ansiUp.ansi_to_html(this.message.message)
}
}
}
</script>

<style lang="stylus" scoped>
@import "~@/style/imports"
.logger-message
h-box()
align-items baseline
font-family 'Roboto Mono', monospace
box-sizing border-box
padding 2px 4px
.type,
.tag
padding 2px 6px
border-radius $br
.type
text-transform uppercase
&.type-warn
.type
background $vue-color-warning
color $vue-color-light
&.type-error
.type
background $vue-color-danger
color $vue-color-light
&.type-info
.type
background $vue-color-info
color $vue-color-light
&.type-done
.type
background $vue-color-success
color $vue-color-light
.tag
background lighten($vue-color-dark, 60%)
&.has-type.has-tag
.type
border-top-right-radius 0
border-bottom-right-radius 0
.tag
border-top-left-radius 0
border-bottom-left-radius 0
.message
flex 100% 1 1
width 0
ellipsis()
&.has-type,
&.has-tag
.message
margin-left 12px
&.pre
.message
white-space pre-wrap
</style>
83 changes: 83 additions & 0 deletions packages/@vue/cli-ui/src/components/LoggerView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<template>
<div class="logger-view">
<ApolloQuery
:query="require('../graphql/consoleLogs.gql')"
fetch-policy="cache-and-network"
class="logs"
>
<ApolloSubscribeToMore
ref="logs"
:document="require('../graphql/consoleLogAdded.gql')"
:update-query="onConsoleLogAdded"
/>

<template slot-scope="{ result: { data } }">
<template v-if="data && data.consoleLogs">
<LoggerMessage
v-for="log of data.consoleLogs"
:key="log.id"
:message="log"
pre
/>
</template>
</template>
</ApolloQuery>
</div>
</template>

<script>
import LoggerMessage from './LoggerMessage'
export default {
components: {
LoggerMessage
},
methods: {
onConsoleLogAdded (previousResult, { subscriptionData }) {
this.scrollToBottom()
return {
consoleLogs: [
...previousResult.consoleLogs,
subscriptionData.data.consoleLogAdded
]
}
},
async scrollToBottom () {
await this.$nextTick()
const list = this.$refs.logs.$el
list.scrollTop = list.scrollHeight
console.log(list.scrollHeight)
},
clearLogs () {
// TODO
}
}
}
</script>

<style lang="stylus" scoped>
@import "~@/style/imports"
.logger-view
background $vue-color-light-neutral
padding $padding-item 0
height 160px
display grid
grid-template-columns 1fr
grid-template-rows 1fr
grid-template-areas "logs"
.logs
grid-area logs
padding 0 $padding-item
overflow-x hidden
overflow-y auto
font-size 12px
.logger-message
&:hover
background lighten(@background, 40%)
</style>
Loading

0 comments on commit 9f0eece

Please sign in to comment.