2019-05-29 14:44:15 +00:00
|
|
|
<template>
|
|
|
|
<transition appear>
|
2019-06-06 08:09:28 +00:00
|
|
|
<div class="nuxt__build_indicator" :style="indicatorStyle" v-if="building">
|
2019-05-29 14:44:15 +00:00
|
|
|
<svg viewBox="0 0 96 72" version="1" xmlns="http://www.w3.org/2000/svg">
|
|
|
|
<g fill="none" fill-rule="evenodd">
|
|
|
|
<path d="M6 66h23l1-3 21-37L40 6 6 66zM79 66h11L62 17l-5 9 22 37v3zM54 31L35 66h38z"/>
|
|
|
|
<path d="M29 69v-1-2H6L40 6l11 20 3-6L44 3s-2-3-4-3-3 1-5 3L1 63c0 1-2 3 0 6 0 1 2 2 5 2h28c-3 0-4-1-5-2z" fill="#00C58E"/>
|
|
|
|
<path d="M95 63L67 14c0-1-2-3-5-3-1 0-3 0-4 3l-4 6 3 6 5-9 28 49H79a5 5 0 0 1 0 3c-2 2-5 2-5 2h16c1 0 4 0 5-2 1-1 2-3 0-6z" fill="#00C58E"/>
|
|
|
|
<path d="M79 69v-1-2-3L57 26l-3-6-3 6-21 37-1 3a5 5 0 0 0 0 3c1 1 2 2 5 2h40s3 0 5-2zM54 31l19 35H35l19-35z" fill="#FFF" fill-rule="nonzero"/>
|
|
|
|
</g>
|
|
|
|
</svg>
|
|
|
|
{{ animatedProgress }}%
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
name: 'nuxt-build-indicator',
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
building: false,
|
|
|
|
progress: 0,
|
|
|
|
animatedProgress: 0,
|
|
|
|
reconnectAttempts: 0,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
2019-08-05 15:45:34 +00:00
|
|
|
if (typeof EventSource === undefined) {
|
2019-05-29 14:44:15 +00:00
|
|
|
return // Unsupported
|
|
|
|
}
|
2019-08-05 15:45:34 +00:00
|
|
|
this.sseConnect()
|
2019-05-29 14:44:15 +00:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
2019-08-05 15:45:34 +00:00
|
|
|
this.sseClose()
|
2019-05-30 10:03:57 +00:00
|
|
|
clearInterval(this._progressAnimation)
|
|
|
|
},
|
|
|
|
computed: {
|
2019-06-06 08:09:28 +00:00
|
|
|
options: () => (<%= JSON.stringify(buildIndicator) %>),
|
|
|
|
indicatorStyle() {
|
|
|
|
const [ d1, d2 ] = this.options.position.split('-')
|
|
|
|
return {
|
|
|
|
[d1]: '20px',
|
|
|
|
[d2]: '20px',
|
|
|
|
'background-color': this.options.backgroundColor,
|
|
|
|
color: this.options.color,
|
|
|
|
}
|
2019-05-30 10:03:57 +00:00
|
|
|
}
|
2019-05-29 14:44:15 +00:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
progress(val, oldVal) {
|
|
|
|
// Average progress may decrease but ignore it!
|
|
|
|
if (val < oldVal) {
|
|
|
|
return
|
|
|
|
}
|
2019-05-30 10:03:57 +00:00
|
|
|
// Cancel old animation
|
|
|
|
clearInterval(this._progressAnimation)
|
|
|
|
// Jump to edge immediately
|
2019-05-29 14:44:15 +00:00
|
|
|
if (val < 10 || val > 90) {
|
|
|
|
this.animatedProgress = val
|
2019-05-30 10:03:57 +00:00
|
|
|
return
|
2019-05-29 14:44:15 +00:00
|
|
|
}
|
|
|
|
// Animate to value
|
|
|
|
this._progressAnimation = setInterval(() => {
|
|
|
|
const diff = this.progress - this.animatedProgress
|
|
|
|
if (diff > 0) {
|
|
|
|
this.animatedProgress++
|
|
|
|
} else {
|
|
|
|
clearInterval(this._progressAnimation)
|
|
|
|
}
|
|
|
|
}, 50)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2019-08-05 15:45:34 +00:00
|
|
|
sseConnect() {
|
2019-05-30 10:03:57 +00:00
|
|
|
if (this._connecting) {
|
|
|
|
return
|
2019-05-29 14:44:15 +00:00
|
|
|
}
|
2019-05-30 10:03:57 +00:00
|
|
|
this._connecting = true
|
2019-08-05 15:45:34 +00:00
|
|
|
this.sse = new EventSource('<%= router.base %>_loading/sse')
|
|
|
|
this.sse.addEventListener('message', (event) => this.onSseMessage(event))
|
2019-05-29 14:44:15 +00:00
|
|
|
},
|
2019-08-05 15:45:34 +00:00
|
|
|
onSseMessage(message) {
|
2019-05-30 10:03:57 +00:00
|
|
|
const data = JSON.parse(message.data)
|
2019-08-05 15:45:34 +00:00
|
|
|
if (!data.states) return
|
2019-05-29 14:44:15 +00:00
|
|
|
|
|
|
|
this.progress = Math.round(data.states.reduce((p, s) => p + s.progress, 0) / data.states.length)
|
2019-05-30 10:03:57 +00:00
|
|
|
|
2019-05-29 14:44:15 +00:00
|
|
|
if (!data.allDone) {
|
|
|
|
this.building = true
|
|
|
|
} else {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.building = false
|
|
|
|
this.animatedProgress = 0
|
|
|
|
this.progress = 0
|
|
|
|
clearInterval(this._progressAnimation)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-08-05 15:45:34 +00:00
|
|
|
sseClose() {
|
|
|
|
if (this.sse) {
|
|
|
|
this.sse.close()
|
|
|
|
delete this.sse
|
2019-05-29 14:44:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2019-05-30 11:27:41 +00:00
|
|
|
<style scoped>
|
2019-05-29 14:44:15 +00:00
|
|
|
.nuxt__build_indicator {
|
2019-05-30 11:27:41 +00:00
|
|
|
box-sizing: border-box;
|
2019-06-06 21:24:33 +00:00
|
|
|
position: fixed;
|
2019-05-29 14:44:15 +00:00
|
|
|
font-family: monospace;
|
|
|
|
padding: 5px 10px;
|
2019-05-30 11:27:41 +00:00
|
|
|
border-radius: 5px;
|
2019-05-29 14:44:15 +00:00
|
|
|
box-shadow: 1px 1px 2px 0px rgba(0,0,0,0.2);
|
2019-06-14 17:35:21 +00:00
|
|
|
width: 88px;
|
2019-05-30 11:27:41 +00:00
|
|
|
z-index: 2147483647;
|
2019-06-14 17:35:21 +00:00
|
|
|
font-size: 16px;
|
2019-08-20 16:15:36 +00:00
|
|
|
line-height: 1.2rem;
|
2019-05-29 14:44:15 +00:00
|
|
|
}
|
|
|
|
.v-enter-active, .v-leave-active {
|
|
|
|
transition-delay: 0.2s;
|
|
|
|
transition-property: all;
|
|
|
|
transition-duration: 0.3s;
|
|
|
|
}
|
|
|
|
.v-leave-to {
|
|
|
|
opacity: 0;
|
|
|
|
transform: translateY(20px);
|
|
|
|
}
|
|
|
|
svg {
|
2019-08-20 16:15:36 +00:00
|
|
|
display: inline-block;
|
|
|
|
vertical-align: baseline;
|
2019-05-29 14:44:15 +00:00
|
|
|
width: 1.1em;
|
|
|
|
position: relative;
|
|
|
|
top: 1px;
|
|
|
|
}
|
|
|
|
</style>
|