refactor: add examples to lint

This commit is contained in:
Clark Du 2017-10-31 21:43:55 +08:00
parent b132decf9d
commit 3e637c5d83
No known key found for this signature in database
GPG Key ID: D0E5986AF78B86D9
94 changed files with 360 additions and 330 deletions

4
.eslintignore Normal file
View File

@ -0,0 +1,4 @@
app
node_modules
dist
.nuxt

View File

@ -12,7 +12,7 @@ const getPost = (slug) => ({
}) })
export default { export default {
beforeCreate () { beforeCreate() {
this.component = () => getPost(this.$route.params.slug) this.component = () => getPost(this.$route.params.slug)
} }
} }

View File

@ -12,7 +12,7 @@ module.exports = {
}, },
generate: { generate: {
routes: [ routes: [
'/posts/1', '/posts/1'
] ]
} }
} }

View File

@ -11,12 +11,12 @@
import axios from 'axios' import axios from 'axios'
export default { export default {
async asyncData ({ params }) { async asyncData({ params }) {
// We can use async/await ES6 feature // We can use async/await ES6 feature
let { data } = await axios.get(`https://jsonplaceholder.typicode.com/posts/${params.id}`) let { data } = await axios.get(`https://jsonplaceholder.typicode.com/posts/${params.id}`)
return { post: data } return { post: data }
}, },
head () { head() {
return { return {
title: this.post.title title: this.post.title
} }

View File

@ -15,7 +15,7 @@
import axios from 'axios' import axios from 'axios'
export default { export default {
asyncData ({ req, params }) { asyncData({ req, params }) {
// We can return a Promise instead of calling the callback // We can return a Promise instead of calling the callback
return axios.get('https://jsonplaceholder.typicode.com/posts') return axios.get('https://jsonplaceholder.typicode.com/posts')
.then((res) => { .then((res) => {

View File

@ -20,7 +20,7 @@
<script> <script>
export default { export default {
data () { data() {
return { return {
formError: null, formError: null,
formUsername: '', formUsername: '',
@ -28,7 +28,7 @@ export default {
} }
}, },
methods: { methods: {
async login () { async login() {
try { try {
await this.$store.dispatch('login', { await this.$store.dispatch('login', {
username: this.formUsername, username: this.formUsername,
@ -37,11 +37,11 @@ export default {
this.formUsername = '' this.formUsername = ''
this.formPassword = '' this.formPassword = ''
this.formError = null this.formError = null
} catch(e) { } catch (e) {
this.formError = e.message this.formError = e.message
} }
}, },
async logout () { async logout() {
try { try {
await this.$store.dispatch('logout') await this.$store.dispatch('logout')
} catch (e) { } catch (e) {

View File

@ -12,12 +12,12 @@ export const mutations = {
export const actions = { export const actions = {
// nuxtServerInit is called by Nuxt.js before server-rendering every page // nuxtServerInit is called by Nuxt.js before server-rendering every page
nuxtServerInit ({ commit }, { req }) { nuxtServerInit({ commit }, { req }) {
if (req.session && req.session.authUser) { if (req.session && req.session.authUser) {
commit('SET_USER', req.session.authUser) commit('SET_USER', req.session.authUser)
} }
}, },
async login ({ commit }, { username, password }) { async login({ commit }, { username, password }) {
try { try {
const { data } = await axios.post('/api/login', { username, password }) const { data } = await axios.post('/api/login', { username, password })
commit('SET_USER', data) commit('SET_USER', data)
@ -29,7 +29,7 @@ export const actions = {
} }
}, },
async logout ({ commit }) { async logout({ commit }) {
await axios.post('/api/logout') await axios.post('/api/logout')
commit('SET_USER', null) commit('SET_USER', null)
} }

View File

@ -9,7 +9,7 @@
export default { export default {
async asyncData ({ app }) { async asyncData({ app }) {
const { data: { message: dog } } = await app.$axios.get('/dog') const { data: { message: dog } } = await app.$axios.get('/dog')
return { dog } return { dog }
} }

View File

@ -9,11 +9,11 @@
<script> <script>
export default { export default {
name: 'date', name: 'date',
serverCacheKey () { serverCacheKey() {
// Will change every 10 secondes // Will change every 10 secondes
return Math.floor(Date.now() / 10000) return Math.floor(Date.now() / 10000)
}, },
data () { data() {
return { date: Date.now() } return { date: Date.now() }
} }
} }

View File

@ -7,7 +7,7 @@ module.exports = {
app: 'app.[chunkhash].js' // default: nuxt.bundle.[chunkhash].js app: 'app.[chunkhash].js' // default: nuxt.bundle.[chunkhash].js
}, },
vendor: ['lodash'], vendor: ['lodash'],
extend (config, { isDev }) { extend(config, { isDev }) {
if (isDev) { if (isDev) {
config.devtool = 'eval-source-map' config.devtool = 'eval-source-map'
} }

View File

@ -8,7 +8,7 @@
<script> <script>
export default { export default {
layout: 'dark', layout: 'dark',
asyncData ({ req }) { asyncData({ req }) {
return { return {
name: req ? 'server' : 'client' name: req ? 'server' : 'client'
} }

View File

@ -10,10 +10,10 @@ export default {
loading: false loading: false
}), }),
methods: { methods: {
start () { start() {
this.loading = true this.loading = true
}, },
finish () { finish() {
this.loading = false this.loading = false
} }
} }

View File

@ -7,7 +7,7 @@
<script> <script>
export default { export default {
asyncData () { asyncData() {
return new Promise((resolve) => { return new Promise((resolve) => {
setTimeout(function () { setTimeout(function () {
resolve({}) resolve({})

View File

@ -7,7 +7,7 @@
<script> <script>
export default { export default {
asyncData () { asyncData() {
return new Promise((resolve) => { return new Promise((resolve) => {
setTimeout(function () { setTimeout(function () {
resolve({ name: 'world' }) resolve({ name: 'world' })

View File

@ -13,7 +13,7 @@
import axios from 'axios' import axios from 'axios'
export default { export default {
async asyncData () { async asyncData() {
const { data } = await axios.get('https://jsonplaceholder.typicode.com/users') const { data } = await axios.get('https://jsonplaceholder.typicode.com/users')
return { users: data } return { users: data }
} }

View File

@ -11,10 +11,10 @@
import axios from 'axios' import axios from 'axios'
export default { export default {
validate ({ params }) { validate({ params }) {
return !isNaN(+params.id) return !isNaN(+params.id)
}, },
async asyncData ({ params, error }) { async asyncData({ params, error }) {
try { try {
const { data } = await axios.get(`https://jsonplaceholder.typicode.com/users/${+params.id}`) const { data } = await axios.get(`https://jsonplaceholder.typicode.com/users/${+params.id}`)
return data return data

View File

@ -1,7 +1,6 @@
{ {
"name": "nuxt-custom-server", "name": "nuxt-custom-server",
"dependencies": { "dependencies": {
"chalk": "^2.2.0",
"express": "^4.15.3", "express": "^4.15.3",
"nuxt": "latest" "nuxt": "latest"
}, },

View File

@ -1,6 +1,5 @@
const app = require('express')() const app = require('express')()
const { Nuxt, Builder } = require('nuxt') const { Nuxt, Builder } = require('nuxt')
const chalk = require('chalk')
const host = process.env.HOST || '127.0.0.1' const host = process.env.HOST || '127.0.0.1'
const port = process.env.PORT || 3000 const port = process.env.PORT || 3000
@ -22,4 +21,3 @@ app.use(nuxt.render)
// Start express server // Start express server
app.listen(port, host) app.listen(port, host)
console.log('\n' + chalk.bgGreen.black(' OPEN ') + chalk.green(` http://${host}:${port}`))

View File

@ -5,7 +5,7 @@ export default async () => {
return VueChart.Bar.extend({ return VueChart.Bar.extend({
props: ['data'], props: ['data'],
mounted () { mounted() {
this.renderChart(this.data) this.renderChart(this.data)
} }
}) })

View File

@ -13,12 +13,12 @@ export default {
data: () => ({ data: () => ({
loaded: false loaded: false
}), }),
beforeMount () { beforeMount() {
// Preload image // Preload image
const img = new Image() const img = new Image()
img.onload = () => { img.onload = () => {
this.loaded = true this.loaded = true
}; }
img.src = this.data img.src = this.data
} }
} }

View File

@ -18,7 +18,7 @@ export const messages = [
{ component: 'vText', data: 'End of demo 🎉' } { component: 'vText', data: 'End of demo 🎉' }
] ]
async function streamMessages (fn, i = 0) { async function streamMessages(fn, i = 0) {
if (i >= messages.length) return if (i >= messages.length) return
await fn(messages[i]) await fn(messages[i])
setTimeout(() => streamMessages(fn, i + 1), 1500) setTimeout(() => streamMessages(fn, i + 1), 1500)

View File

@ -23,7 +23,7 @@ export default {
data: () => ({ data: () => ({
messages: [] messages: []
}), }),
mounted () { mounted() {
// Listen for incoming messages // Listen for incoming messages
streamMessages(async (message) => { streamMessages(async (message) => {
// Wait for the component to load before displaying it // Wait for the component to load before displaying it

View File

@ -8,7 +8,7 @@
<script> <script>
export default { export default {
layout: ({ isMobile }) => isMobile ? 'mobile' : 'default', layout: ({ isMobile }) => isMobile ? 'mobile' : 'default',
asyncData ({ req }) { asyncData({ req }) {
return { return {
name: req ? 'server' : 'client' name: req ? 'server' : 'client'
} }

View File

@ -7,6 +7,6 @@
<script> <script>
export default { export default {
layout: ({ isMobile }) => isMobile ? 'mobile' : 'default', layout: ({ isMobile }) => isMobile ? 'mobile' : 'default'
} }
</script> </script>

View File

@ -1,11 +1,11 @@
<script> <script>
export default { export default {
asyncData ({ req }) { asyncData({ req }) {
return { return {
name: req ? 'server' : 'client' name: req ? 'server' : 'client'
} }
}, },
render (h) { render(h) {
return <div> return <div>
<p>Hi from {this.name}</p> <p>Hi from {this.name}</p>
<nuxt-link to="/">Home page</nuxt-link> <nuxt-link to="/">Home page</nuxt-link>

View File

@ -1,5 +1,5 @@
export default { export default {
render (h) { render(h) {
return <div> return <div>
<h1>Welcome !</h1> <h1>Welcome !</h1>
<nuxt-link to="/about">About page</nuxt-link> <nuxt-link to="/about">About page</nuxt-link>

View File

@ -7,7 +7,7 @@
<script> <script>
export default { export default {
asyncData () { asyncData() {
return { return {
name: process.static ? 'static' : (process.server ? 'server' : 'client') name: process.static ? 'static' : (process.server ? 'server' : 'client')
} }

View File

@ -26,7 +26,7 @@
<script> <script>
export default { export default {
methods: { methods: {
path (url) { path(url) {
return (this.$i18n.locale === 'en' ? url : '/' + this.$i18n.locale + url) return (this.$i18n.locale === 'en' ? url : '/' + this.$i18n.locale + url)
} }
} }

View File

@ -6,7 +6,7 @@ module.exports = {
router: { router: {
middleware: 'i18n' middleware: 'i18n'
}, },
plugins: ['~/plugins/i18n.js',], plugins: ['~/plugins/i18n.js'],
generate: { generate: {
routes: ['/', '/about', '/fr', '/fr/about'] routes: ['/', '/about', '/fr', '/fr/about']
} }

View File

@ -9,7 +9,7 @@
<script> <script>
export default { export default {
head () { head() {
return { title: this.$t('about.title') } return { title: this.$t('about.title') }
} }
} }

View File

@ -9,7 +9,7 @@
<script> <script>
export default { export default {
head () { head() {
return { title: this.$t('home.title') } return { title: this.$t('home.title') }
} }
} }

View File

@ -4,7 +4,7 @@ export const state = () => ({
}) })
export const mutations = { export const mutations = {
SET_LANG (state, locale) { SET_LANG(state, locale) {
if (state.locales.indexOf(locale) !== -1) { if (state.locales.indexOf(locale) !== -1) {
state.locale = locale state.locale = locale
} }

View File

@ -19,11 +19,11 @@
import axios from 'axios' import axios from 'axios'
export default { export default {
transition (to, from) { transition(to, from) {
if (!from) return 'slide-left' if (!from) return 'slide-left'
return +to.query.page < +from.query.page ? 'slide-right' : 'slide-left' return +to.query.page < +from.query.page ? 'slide-right' : 'slide-left'
}, },
async asyncData ({ query }) { async asyncData({ query }) {
const page = query.page || 1 const page = query.page || 1
const { data } = await axios.get(`https://reqres.in/api/users?page=${page}`) const { data } = await axios.get(`https://reqres.in/api/users?page=${page}`)
return { return {

View File

@ -12,7 +12,7 @@
<script> <script>
export default { export default {
data () { data() {
return { return {
model: 'I am index' model: 'I am index'
} }

View File

@ -9,7 +9,7 @@
<script> <script>
export default { export default {
data () { data() {
return { return {
model: 'I am pug' model: 'I am pug'
} }

View File

@ -7,12 +7,12 @@
<script> <script>
export default { export default {
computed: { computed: {
visits () { visits() {
return this.$store.state.visits.slice().reverse() return this.$store.state.visits.slice().reverse()
} }
}, },
filters: { filters: {
hours (date) { hours(date) {
return date.split('T')[1].split('.')[0] return date.split('T')[1].split('.')[0]
} }
} }

View File

@ -11,7 +11,7 @@
<script> <script>
export default { export default {
asyncData ({ store, route, userAgent }) { asyncData({ store, route, userAgent }) {
return { return {
userAgent, userAgent,
slugs: [ slugs: [

View File

@ -3,7 +3,7 @@ export const state = () => ({
}) })
export const mutations = { export const mutations = {
ADD_VISIT (state, path) { ADD_VISIT(state, path) {
state.visits.push({ state.visits.push({
path, path,
date: new Date().toJSON() date: new Date().toJSON()

View File

@ -16,7 +16,7 @@
<script> <script>
export default { export default {
asyncData ({ env }) { asyncData({ env }) {
return { users: env.users } return { users: env.users }
} }
} }

View File

@ -7,17 +7,17 @@
<script> <script>
export default { export default {
validate ({ params }) { validate({ params }) {
return !isNaN(+params.id) return !isNaN(+params.id)
}, },
asyncData ({ params, env, error }) { asyncData({ params, env, error }) {
const user = env.users.find((user) => String(user.id) === params.id) const user = env.users.find((user) => String(user.id) === params.id)
if (!user) { if (!user) {
return error({ message: 'User not found', statusCode: 404 }) return error({ message: 'User not found', statusCode: 404 })
} }
return user return user
}, },
head () { head() {
return { return {
title: this.name title: this.name
} }

View File

@ -9,7 +9,7 @@
import axios from 'axios' import axios from 'axios'
export default { export default {
asyncData () { asyncData() {
const nb = Math.max(1, Math.round(Math.random() * 10)) const nb = Math.max(1, Math.round(Math.random() * 10))
return axios.get(`https://jsonplaceholder.typicode.com/photos/${nb}`).then(res => res.data) return axios.get(`https://jsonplaceholder.typicode.com/photos/${nb}`).then(res => res.data)
} }

View File

@ -12,7 +12,7 @@ if (process.browser) {
} }
export default { export default {
mounted () { mounted() {
miniToastr.init() miniToastr.init()
}, },
notifications: { notifications: {

View File

@ -19,11 +19,11 @@
import axios from 'axios' import axios from 'axios'
export default { export default {
transition (to, from) { transition(to, from) {
if (!from) return 'slide-left' if (!from) return 'slide-left'
return +to.query.page < +from.query.page ? 'slide-right' : 'slide-left' return +to.query.page < +from.query.page ? 'slide-right' : 'slide-left'
}, },
async asyncData ({ query }) { async asyncData({ query }) {
const page = +query.page || 1 const page = +query.page || 1
const { data } = await axios.get(`https://reqres.in/api/users?page=${page}`) const { data } = await axios.get(`https://reqres.in/api/users?page=${page}`)
return { return {

View File

@ -7,7 +7,7 @@
<script> <script>
export default { export default {
asyncData () { asyncData() {
return { return {
name: (process.server ? 'server' : 'client') name: (process.server ? 'server' : 'client')
} }

View File

@ -9,7 +9,7 @@
<script> <script>
export default { export default {
asyncData ({ req }) { asyncData({ req }) {
return { return {
name: req ? 'server' : 'client' name: req ? 'server' : 'client'
} }

View File

@ -9,10 +9,10 @@
</template> </template>
// **PLEASE NOTE** All "Nuxt Class Components" require at minimum a script tag that exports a default object // **PLEASE NOTE** All "Nuxt Class Components" require at minimum a script tag that exports a default object
<script lang="ts"> <script lang="ts">
import Vue from "vue" import Vue from 'vue'
import Component from "nuxt-class-component" import Component from 'nuxt-class-component'
import { Prop } from 'vue-property-decorator' import { Prop } from 'vue-property-decorator'
import { Action } from "vuex-class" import { Action } from 'vuex-class'
@Component({}) @Component({})
export default class Card extends Vue { export default class Card extends Vue {

View File

@ -1,12 +1,12 @@
module.exports = function(options) { module.exports = function (options) {
// Extend build // Extend build
this.extendBuild(config => { this.extendBuild(config => {
const tsLoader = { const tsLoader = {
loader: "ts-loader", loader: 'ts-loader',
options: { options: {
appendTsSuffixTo: [/\.vue$/] appendTsSuffixTo: [/\.vue$/]
} }
}; }
// Add TypeScript loader // Add TypeScript loader
config.module.rules.push( config.module.rules.push(
Object.assign( Object.assign(
@ -15,12 +15,12 @@ module.exports = function(options) {
}, },
tsLoader tsLoader
) )
); )
// Add TypeScript loader for vue files // Add TypeScript loader for vue files
for (let rule of config.module.rules) { for (let rule of config.module.rules) {
if (rule.loader === "vue-loader") { if (rule.loader === 'vue-loader') {
rule.options.loaders.ts = tsLoader; rule.options.loaders.ts = tsLoader
} }
} }
}); })
}; }

View File

@ -14,10 +14,10 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import Vue from "vue"; import Vue from 'vue'
import Component from "nuxt-class-component" import Component from 'nuxt-class-component'
import Card from "~/components/Card" import Card from '~/components/Card'
import { State, Getter } from "vuex-class" import { State, Getter } from 'vuex-class'
@Component({ @Component({
components: { components: {

View File

@ -10,7 +10,7 @@
<script> <script>
export default { export default {
asyncData ({ req }) { asyncData({ req }) {
return { return {
name: req ? 'server' : 'client' name: req ? 'server' : 'client'
} }

View File

@ -2,4 +2,4 @@ import UIkit from 'uikit'
import Icons from 'uikit/dist/js/uikit-icons' import Icons from 'uikit/dist/js/uikit-icons'
// loads the Icon plugin // loads the Icon plugin
UIkit.use(Icons); UIkit.use(Icons)

View File

@ -30,7 +30,7 @@ export default {
return formatter.format(num) return formatter.format(num)
} }
}, },
head () { head() {
return { return {
title: (this.Car ? `${this.Car.make} ${this.Car.model}` : 'Loading') title: (this.Car ? `${this.Car.make} ${this.Car.model}` : 'Loading')
} }

View File

@ -2,7 +2,7 @@ import { Bar } from 'vue-chartjs'
export default Bar.extend({ export default Bar.extend({
props: ['data', 'options'], props: ['data', 'options'],
mounted () { mounted() {
this.renderChart(this.data, this.options) this.renderChart(this.data, this.options)
} }
}) })

View File

@ -2,7 +2,7 @@ import { Doughnut } from 'vue-chartjs'
export default Doughnut.extend({ export default Doughnut.extend({
props: ['data', 'options'], props: ['data', 'options'],
mounted () { mounted() {
this.renderChart(this.data, this.options) this.renderChart(this.data, this.options)
} }
}) })

View File

@ -7,15 +7,14 @@
<script> <script>
import DoughnutChart from '~/components/doughnut-chart' import DoughnutChart from '~/components/doughnut-chart'
import axios from 'axios' import axios from 'axios'
import moment from 'moment'
function getRandomColor() { function getRandomColor() {
var letters = '0123456789ABCDEF'; var letters = '0123456789ABCDEF'
var color = '#'; var color = '#'
for (var i = 0; i < 6; i++) { for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)]; color += letters[Math.floor(Math.random() * 16)]
} }
return color; return color
} }
export default { export default {

View File

@ -23,18 +23,18 @@ export default class Base extends Vue {
msg = 123 msg = 123
// lifecycle hook // lifecycle hook
mounted () { mounted() {
this.greet() this.greet()
} }
// computed // computed
get computedMsg () { get computedMsg() {
return 'computed ' + this.msg return 'computed ' + this.msg
} }
// method // method
greet () { greet() {
console.log('base greeting: ' + this.msg) console.log('base greeting: ' + this.msg) // eslint-disable-line no-console
} }
} }
</script> </script>

View File

@ -16,8 +16,8 @@ import Base from '@/components/Base'
@Component @Component
export default class Child extends Base { export default class Child extends Base {
// override parent method // override parent method
greet () { greet() {
console.log('child greeting: ' + this.msg) console.log('child greeting: ' + this.msg) // eslint-disable-line no-console
} }
} }
</script> </script>

View File

@ -11,7 +11,7 @@ import Child from '@/components/Child'
components: { Child } components: { Child }
}) })
export default class App extends Vue { export default class App extends Vue {
asyncData ({ req }) { asyncData({ req }) {
return { env: req ? 'server' : 'client' } return { env: req ? 'server' : 'client' }
} }
} }

View File

@ -23,14 +23,14 @@ import { mapState } from 'vuex'
export default { export default {
// fetch(context) is called by the server-side // fetch(context) is called by the server-side
// and before instantiating the component // and before instantiating the component
fetch ({ store }) { fetch({ store }) {
store.commit('increment') store.commit('increment')
}, },
computed: mapState([ computed: mapState([
'counter' 'counter'
]), ]),
methods: { methods: {
increment () { increment() {
this.$store.commit('increment') this.$store.commit('increment')
} }
} }

View File

@ -20,7 +20,7 @@ export default {
todos: 'todos/todos' todos: 'todos/todos'
}), }),
methods: { methods: {
addTodo (e) { addTodo(e) {
var text = e.target.value var text = e.target.value
if (text.trim()) { if (text.trim()) {
this.$store.commit('todos/add', { text }) this.$store.commit('todos/add', { text })

View File

@ -7,13 +7,13 @@ export const state = () => ({
}) })
export const mutations = { export const mutations = {
add (state, title) { add(state, title) {
state.list.push(title) state.list.push(title)
} }
} }
export const getters = { export const getters = {
get (state) { get(state) {
return state.list return state.list
} }
} }

View File

@ -7,13 +7,13 @@ export const state = () => ({
}) })
export const mutations = { export const mutations = {
add (state, title) { add(state, title) {
state.list.push(title) state.list.push(title)
} }
} }
export const getters = { export const getters = {
get (state) { get(state) {
return state.list return state.list
} }
} }

View File

@ -3,7 +3,7 @@ export const state = () => ({
}) })
export const mutations = { export const mutations = {
increment (state) { increment(state) {
state.counter++ state.counter++
} }
} }

View File

@ -3,20 +3,20 @@ export const state = () => ({
}) })
export const mutations = { export const mutations = {
add (state, { text }) { add(state, { text }) {
state.list.push({ state.list.push({
text, text,
done: false done: false
}) })
}, },
toggle (state, todo) { toggle(state, todo) {
todo.done = !todo.done todo.done = !todo.done
} }
} }
export const getters = { export const getters = {
todos (state) { todos(state) {
return state.list return state.list
} }
} }

View File

@ -13,14 +13,14 @@ import { mapState } from 'vuex'
export default { export default {
// fetch(context) is called by the server-side // fetch(context) is called by the server-side
// and nuxt before instantiating the component // and nuxt before instantiating the component
fetch ({ store }) { fetch({ store }) {
store.commit('increment') store.commit('increment')
}, },
computed: mapState([ computed: mapState([
'counter' 'counter'
]), ]),
methods: { methods: {
increment () { increment() {
this.$store.commit('increment') this.$store.commit('increment')
} }
} }

View File

@ -1,5 +1,5 @@
const mutations = { const mutations = {
increment (state) { increment(state) {
state.counter++ state.counter++
} }
} }

View File

@ -4,7 +4,7 @@
<script> <script>
export default { export default {
data () { data() {
return { name: 'world' } return { name: 'world' }
} }
} }

View File

@ -33,7 +33,7 @@ export default {
} }
}), }),
computed: { computed: {
cookies () { cookies() {
return this.$cookies.cookies return this.$cookies.cookies
} }
}, },

View File

@ -0,0 +1,36 @@
module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module'
},
env: {
browser: true,
node: true,
mocha: true
},
extends: 'standard',
// required to lint *.vue files
plugins: [
'html'
],
// add your custom rules here
rules: {
// allow paren-less arrow functions
'arrow-parens': 0,
// allow async-await
'generator-star-spacing': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
// do not allow console.logs etc...
'no-console': 2,
'space-before-function-paren': [
2,
{
anonymous: 'always',
named: 'never'
}
],
},
globals: {}
}

View File

@ -2,4 +2,4 @@ module.exports = {
loading: { loading: {
color: 'purple' color: 'purple'
} }
}; }

View File

@ -37,6 +37,7 @@
"winston": "^2.3.0" "winston": "^2.3.0"
}, },
"devDependencies": { "devDependencies": {
"eslint-plugin-mocha": "^4.11.0",
"jshint": "^2.9.4", "jshint": "^2.9.4",
"mocha": "^3.2.0", "mocha": "^3.2.0",
"nodemon": "^1.11.0", "nodemon": "^1.11.0",

View File

@ -7,7 +7,7 @@
<script> <script>
export default { export default {
asyncData () { asyncData() {
return { return {
name: process.server ? 'server' : 'client' name: process.server ? 'server' : 'client'
} }

View File

@ -1,30 +1,30 @@
'use strict'; 'use strict'
const path = require('path'); const path = require('path')
const compress = require('compression'); const compress = require('compression')
const cors = require('cors'); const cors = require('cors')
const feathers = require('feathers'); const feathers = require('feathers')
const configuration = require('feathers-configuration'); const configuration = require('feathers-configuration')
const hooks = require('feathers-hooks'); const hooks = require('feathers-hooks')
const rest = require('feathers-rest'); const rest = require('feathers-rest')
const bodyParser = require('body-parser'); const bodyParser = require('body-parser')
const socketio = require('feathers-socketio'); const socketio = require('feathers-socketio')
const middleware = require('./middleware'); const middleware = require('./middleware')
const services = require('./services'); const services = require('./services')
const app = feathers(); const app = feathers()
app.configure(configuration(path.join(__dirname, '..'))); app.configure(configuration(path.join(__dirname, '..')))
app.use(compress()) app.use(compress())
.options('*', cors()) .options('*', cors())
.use(cors()) .use(cors())
.use(bodyParser.json()) .use(bodyParser.json())
.use(bodyParser.urlencoded({ extended: true })) .use(bodyParser.urlencoded({ extended: true }))
.configure(hooks()) .configure(hooks())
.configure(rest()) .configure(rest())
.configure(socketio()) .configure(socketio())
.configure(services) .configure(services)
.configure(middleware); .configure(middleware)
module.exports = app; module.exports = app

View File

@ -1,4 +1,4 @@
'use strict'; 'use strict'
// Add any common hooks you want to share across services in here. // Add any common hooks you want to share across services in here.
// //
@ -6,8 +6,8 @@
// see http://docs.feathersjs.com/hooks/readme.html for more details // see http://docs.feathersjs.com/hooks/readme.html for more details
// on hooks. // on hooks.
exports.myHook = function(options) { exports.myHook = function (options) {
return function(hook) { return function (hook) {
console.log('My custom global hook ran. Feathers is awesome!'); console.log('My custom global hook ran. Feathers is awesome!') // eslint-disable-line no-console
}; }
}; }

View File

@ -1,15 +1,15 @@
'use strict'; 'use strict'
const app = require('./app'); const app = require('./app')
const port = app.get('port'); const port = app.get('port')
process.on('nuxt:build:done', (err) => { process.on('nuxt:build:done', (err) => {
if (err) { if (err) {
console.error(err); console.error(err) // eslint-disable-line no-console
process.exit(1); process.exit(1)
} }
const server = app.listen(port); const server = app.listen(port)
server.on('listening', () => server.on('listening', () =>
console.log(`Feathers application started on ${app.get('host')}:${port}`) console.log(`Feathers application started on ${app.get('host')}:${port}`) // eslint-disable-line no-console
); )
}); })

View File

@ -1,12 +1,12 @@
'use strict'; 'use strict'
const nuxt = require('./nuxt'); const nuxt = require('./nuxt')
module.exports = function() { module.exports = function () {
// Add your custom middleware here. Remember, that // Add your custom middleware here. Remember, that
// just like Express the order matters, so error // just like Express the order matters, so error
// handling middleware should go last. // handling middleware should go last.
const app = this; const app = this
app.use(nuxt); app.use(nuxt)
}; }

View File

@ -1,14 +1,11 @@
'use strict'; 'use strict'
const authentication = require('feathers-authentication'); const authentication = require('feathers-authentication')
module.exports = function () {
const app = this
module.exports = function() { let config = app.get('auth')
const app = this;
let config = app.get('auth'); app.configure(authentication(config))
}
app.configure(authentication(config));
};

View File

@ -1,11 +1,10 @@
'use strict'; 'use strict'
const authentication = require('./authentication'); const authentication = require('./authentication')
const user = require('./user'); const user = require('./user')
module.exports = function() { module.exports = function () {
const app = this; const app = this
app.configure(authentication)
app.configure(authentication); app.configure(user)
app.configure(user); }
};

View File

@ -1,8 +1,8 @@
'use strict'; 'use strict'
const globalHooks = require('../../../hooks'); require('../../../hooks')
const hooks = require('feathers-hooks'); const hooks = require('feathers-hooks')
const auth = require('feathers-authentication').hooks; const auth = require('feathers-authentication').hooks
exports.before = { exports.before = {
all: [], all: [],
@ -38,7 +38,7 @@ exports.before = {
auth.restrictToAuthenticated(), auth.restrictToAuthenticated(),
auth.restrictToOwner({ ownerField: '_id' }) auth.restrictToOwner({ ownerField: '_id' })
] ]
}; }
exports.after = { exports.after = {
all: [hooks.remove('password')], all: [hooks.remove('password')],
@ -48,4 +48,4 @@ exports.after = {
update: [], update: [],
patch: [], patch: [],
remove: [] remove: []
}; }

View File

@ -1,17 +1,17 @@
'use strict'; 'use strict'
const path = require('path'); const path = require('path')
const NeDB = require('nedb'); const NeDB = require('nedb')
const service = require('feathers-nedb'); const service = require('feathers-nedb')
const hooks = require('./hooks'); const hooks = require('./hooks')
module.exports = function(){ module.exports = function () {
const app = this; const app = this
const db = new NeDB({ const db = new NeDB({
filename: path.join(app.get('nedb'), 'users.db'), filename: path.join(app.get('nedb'), 'users.db'),
autoload: true autoload: true
}); })
let options = { let options = {
Model: db, Model: db,
@ -19,17 +19,17 @@ module.exports = function(){
default: 5, default: 5,
max: 25 max: 25
} }
}; }
// Initialize our service with any options it requires // Initialize our service with any options it requires
app.use('/users', service(options)); app.use('/users', service(options))
// Get our initialize service to that we can bind hooks // Get our initialize service to that we can bind hooks
const userService = app.service('/users'); const userService = app.service('/users')
// Set up our before hooks // Set up our before hooks
userService.before(hooks.before); userService.before(hooks.before)
// Set up our after hooks // Set up our after hooks
userService.after(hooks.after); userService.after(hooks.after)
}; }

View File

@ -1,38 +1,38 @@
'use strict'; 'use strict'
const assert = require('assert'); const assert = require('assert')
const request = require('request'); const request = require('request')
const app = require('../src/app'); const app = require('../src/app')
describe('Feathers application tests', function() { describe('Feathers application tests', function () {
before(function(done) { before(function (done) {
this.server = app.listen(3030); this.server = app.listen(3030)
this.server.once('listening', () => done()); this.server.once('listening', () => done())
}); })
after(function(done) { after(function (done) {
this.server.close(done); this.server.close(done)
}); })
it('starts and shows the index page', function(done) { it('starts and shows the index page', function (done) {
request('http://localhost:3030', function(err, res, body) { request('http://localhost:3030', function (err, res, body) {
assert.ok(body.indexOf('<h1>Welcome!</h1>') !== -1); assert.ok(body.indexOf('<h1>Welcome!</h1>') !== -1)
done(err); done(err)
}); })
}); })
describe('404', function() { describe('404', function () {
it('shows a 404 HTML page', function(done) { it('shows a 404 HTML page', function (done) {
request({ request({
url: 'http://localhost:3030/path/to/nowhere', url: 'http://localhost:3030/path/to/nowhere',
headers: { headers: {
'Accept': 'text/html' 'Accept': 'text/html'
} }
}, function(err, res, body) { }, function (err, res, body) {
assert.equal(res.statusCode, 404); assert.equal(res.statusCode, 404)
assert.ok(body.indexOf('This page could not be found.') !== -1); assert.ok(body.indexOf('This page could not be found.') !== -1)
done(err); done(err)
}); })
}); })
}); })
}); })

View File

@ -1,10 +1,10 @@
'use strict'; 'use strict'
const assert = require('assert'); const assert = require('assert')
const app = require('../../../src/app'); const app = require('../../../src/app')
describe('user service', function() { describe('user service', function () {
it('registered the users service', () => { it('registered the users service', () => {
assert.ok(app.service('users')); assert.ok(app.service('users'))
}); })
}); })

View File

@ -31,7 +31,7 @@
import axios from '~/plugins/axios' import axios from '~/plugins/axios'
export default { export default {
async asyncData () { async asyncData() {
const { data: users } = await axios.get('users.json') const { data: users } = await axios.get('users.json')
return { users } return { users }
} }

View File

@ -14,7 +14,7 @@
import axios from '~/plugins/axios' import axios from '~/plugins/axios'
export default { export default {
async asyncData ({ route }) { async asyncData({ route }) {
const { key } = route.params const { key } = route.params
const { data: user } = await axios.get(`users/${key}.json`) const { data: user } = await axios.get(`users/${key}.json`)
return { user } return { user }

View File

@ -23,4 +23,4 @@ module.exports = {
] ]
}, },
plugins: ['~/plugins/museui'] plugins: ['~/plugins/museui']
}; }

View File

@ -30,7 +30,7 @@
}, },
methods: { methods: {
toggle(flag) { toggle(flag) {
this.open = !this.open; this.open = !this.open
} }
} }
} }

View File

@ -1,4 +1,4 @@
import Vue from 'vue'; import Vue from 'vue'
import MuseUI from 'muse-ui'; import MuseUI from 'muse-ui'
Vue.use(MuseUI); Vue.use(MuseUI)

View File

@ -17,7 +17,7 @@
import socket from '~/plugins/socket.io.js' import socket from '~/plugins/socket.io.js'
export default { export default {
asyncData (context, callback) { asyncData(context, callback) {
socket.emit('last-messages', function (messages) { socket.emit('last-messages', function (messages) {
callback(null, { callback(null, {
messages, messages,
@ -28,16 +28,16 @@ export default {
watch: { watch: {
'messages': 'scrollToBottom' 'messages': 'scrollToBottom'
}, },
beforeMount () { beforeMount() {
socket.on('new-message', (message) => { socket.on('new-message', (message) => {
this.messages.push(message) this.messages.push(message)
}) })
}, },
mounted () { mounted() {
this.scrollToBottom() this.scrollToBottom()
}, },
methods: { methods: {
sendMessage () { sendMessage() {
if (!this.message.trim()) return if (!this.message.trim()) return
let message = { let message = {
date: new Date().toJSON(), date: new Date().toJSON(),
@ -47,7 +47,7 @@ export default {
this.message = '' this.message = ''
socket.emit('send-message', message) socket.emit('send-message', message)
}, },
scrollToBottom () { scrollToBottom() {
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.messages.scrollTop = this.$refs.messages.scrollHeight this.$refs.messages.scrollTop = this.$refs.messages.scrollHeight
}) })

View File

@ -1,6 +1,3 @@
const { join } = require('path')
module.exports = { module.exports = {
/* /*
** Head elements ** Head elements

View File

@ -49,7 +49,7 @@
"scripts": { "scripts": {
"test": "npm run lint && cross-env NODE_ENV=test npm run build:nuxt && nyc ava --verbose --serial test/ -- && nyc report --reporter=html", "test": "npm run lint && cross-env NODE_ENV=test npm run build:nuxt && nyc ava --verbose --serial test/ -- && nyc report --reporter=html",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov", "coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"lint": "eslint --ext .js,.vue bin/** lib/** test/** --ignore-pattern app --ignore-pattern node_modules --ignore-pattern dist/", "lint": "eslint --ext .js,.vue bin/** lib/** test/*.js examples/**",
"build": "rimraf dist/ && npm run build:nuxt && npm run build:core", "build": "rimraf dist/ && npm run build:nuxt && npm run build:core",
"build:nuxt": "rollup -c build/rollup.config.js --environment TARGET:nuxt", "build:nuxt": "rollup -c build/rollup.config.js --environment TARGET:nuxt",
"build:core": "rollup -c build/rollup.config.js --environment TARGET:core", "build:core": "rollup -c build/rollup.config.js --environment TARGET:core",