Add eslint-plugin-vue

This commit is contained in:
KevinNThomas
2021-07-17 15:57:05 -07:00
parent 1871ea9eb7
commit 6479b32063
11 changed files with 4908 additions and 3394 deletions

11
.editorconfig Normal file
View File

@@ -0,0 +1,11 @@
[*.{js,jsx,ts,tsx,vue}]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
[*.{js,jsx,ts,tsx,vue}]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true

21
.eslintrc.js Normal file
View File

@@ -0,0 +1,21 @@
module.exports = {
root: true,
env: {
node: true
},
parserOptions: {
ecmaVersion: 2020
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
},
extends: [
'plugin:vue/essential',
'@vue/standard'
]
}

7819
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,86 +1,86 @@
{ {
"name": "noisedash", "name": "noisedash",
"version": "1.0.0", "version": "1.0.0",
"description": "Self-hosted web ambient noise generator", "private": true,
"author": "KevinThomas0 <me@kevinthomas.dev>", "description": "Self-hosted web ambient noise generator",
"private": true, "author": "KevinThomas0 <me@kevinthomas.dev>",
"scripts": { "scripts": {
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js", "build": "node build/build.js",
"start": "npm run dev", "lint": "vue-cli-service lint",
"unit": "jest --config test/unit/jest.conf.js --coverage", "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
"test": "npm run unit", "server": "node server/app",
"lint": "eslint --ext .js,.vue src test/unit", "start": "npm run dev",
"server": "node server/app", "test": "npm run unit",
"build": "node build/build.js" "unit": "jest --config test/unit/jest.conf.js --coverage"
}, },
"dependencies": { "dependencies": {
"axios": "^0.21.1", "axios": "^0.21.1",
"bcrypt": "^5.0.1", "bcrypt": "^5.0.1",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"sqlite3": "^5.0.2", "sqlite3": "^5.0.2",
"vue": "^2.5.2", "vue": "^2.5.2",
"vue-router": "^3.0.1" "vue-router": "^3.0.1"
}, },
"devDependencies": { "devDependencies": {
"autoprefixer": "^7.1.2", "@vue/cli-plugin-eslint": "^4.5.13",
"babel-core": "^6.22.1", "@vue/eslint-config-standard": "^5.1.2",
"babel-eslint": "^8.2.1", "autoprefixer": "^7.1.2",
"babel-helper-vue-jsx-merge-props": "^2.0.3", "babel-core": "^6.22.1",
"babel-jest": "^21.0.2", "babel-eslint": "^8.2.1",
"babel-loader": "^7.1.1", "babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-plugin-dynamic-import-node": "^1.2.0", "babel-jest": "^21.0.2",
"babel-plugin-syntax-jsx": "^6.18.0", "babel-loader": "^7.1.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0", "babel-plugin-dynamic-import-node": "^1.2.0",
"babel-plugin-transform-runtime": "^6.22.0", "babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-vue-jsx": "^3.5.0", "babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-preset-env": "^1.3.2", "babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-stage-2": "^6.22.0", "babel-plugin-transform-vue-jsx": "^3.5.0",
"chalk": "^2.0.1", "babel-preset-env": "^1.3.2",
"copy-webpack-plugin": "^4.0.1", "babel-preset-stage-2": "^6.22.0",
"css-loader": "^0.28.0", "chalk": "^2.0.1",
"eslint": "^4.15.0", "copy-webpack-plugin": "^4.0.1",
"eslint-config-standard": "^10.2.1", "css-loader": "^0.28.0",
"eslint-friendly-formatter": "^3.0.0", "eslint": "^6.7.2",
"eslint-loader": "^1.7.1", "eslint-friendly-formatter": "^4.0.1",
"eslint-plugin-import": "^2.7.0", "eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^5.2.0", "eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^3.4.0", "eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^3.0.1", "eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^4.0.0", "eslint-plugin-vue": "^6.2.2",
"extract-text-webpack-plugin": "^3.0.0", "extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^1.1.4", "file-loader": "^1.1.4",
"friendly-errors-webpack-plugin": "^1.6.1", "friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-plugin": "^2.30.1", "html-webpack-plugin": "^2.30.1",
"jest": "^22.0.4", "jest": "^22.0.4",
"jest-serializer-vue": "^0.3.0", "jest-serializer-vue": "^0.3.0",
"node-notifier": "^5.1.2", "node-notifier": "^5.1.2",
"optimize-css-assets-webpack-plugin": "^3.2.0", "optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "^1.2.0", "ora": "^1.2.0",
"portfinder": "^1.0.13", "portfinder": "^1.0.13",
"postcss-import": "^11.0.0", "postcss-import": "^11.0.0",
"postcss-loader": "^2.0.8", "postcss-loader": "^2.0.8",
"postcss-url": "^7.2.1", "postcss-url": "^7.2.1",
"rimraf": "^2.6.0", "rimraf": "^2.6.0",
"semver": "^5.3.0", "semver": "^5.3.0",
"shelljs": "^0.7.6", "shelljs": "^0.7.6",
"uglifyjs-webpack-plugin": "^1.1.1", "uglifyjs-webpack-plugin": "^1.1.1",
"url-loader": "^0.5.8", "url-loader": "^0.5.8",
"vue-jest": "^1.0.2", "vue-jest": "^1.0.2",
"vue-loader": "^13.3.0", "vue-loader": "^13.3.0",
"vue-style-loader": "^3.0.1", "vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.2", "vue-template-compiler": "^2.5.2",
"webpack": "^3.6.0", "webpack": "^3.6.0",
"webpack-bundle-analyzer": "^2.9.0", "webpack-bundle-analyzer": "^2.9.0",
"webpack-dev-server": "^2.9.1", "webpack-dev-server": "^2.9.1",
"webpack-merge": "^4.1.0" "webpack-merge": "^4.1.0"
}, },
"engines": { "browserslist": [
"node": ">= 6.0.0", "> 1%",
"npm": ">= 3.0.0" "last 2 versions",
}, "not ie <= 8"
"browserslist": [ ],
"> 1%", "engines": {
"last 2 versions", "node": ">= 6.0.0",
"not ie <= 8" "npm": ">= 3.0.0"
] }
} }

View File

@@ -7,12 +7,12 @@
<script> <script>
export default { export default {
data() { data () {
return { return {
msg: "The superheros", msg: 'The superheros'
}; }
}, }
}; }
</script> </script>
<style scoped> <style scoped>
h1, h1,
@@ -30,4 +30,4 @@ li {
a { a {
color: #42b983; color: #42b983;
} }
</style> </style>

View File

@@ -7,12 +7,12 @@
<script> <script>
export default { export default {
data() { data () {
return { return {
msg: "Hello World!", msg: 'Hello World!'
}; }
}, }
}; }
</script> </script>
<!-- Add "scoped" attribute to limit CSS to this component only --> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped> <style scoped>

View File

@@ -21,44 +21,44 @@
<script> <script>
export default { export default {
data() { data () {
return { return {
email: "", email: '',
password: "", password: ''
}; }
}, },
methods: { methods: {
handleSubmit(e) { handleSubmit (e) {
e.preventDefault(); e.preventDefault()
if (this.password.length > 0) { if (this.password.length > 0) {
this.$http this.$http
.post("http://localhost:3000/login", { .post('http://localhost:3000/login', {
email: this.email, email: this.email,
password: this.password, password: this.password
}) })
.then((response) => { .then((response) => {
let is_admin = response.data.user.is_admin; const isAdmin = response.data.user.isAdmin
localStorage.setItem("user", JSON.stringify(response.data.user)); localStorage.setItem('user', JSON.stringify(response.data.user))
localStorage.setItem("jwt", response.data.token); localStorage.setItem('jwt', response.data.token)
if (localStorage.getItem("jwt") != null) { if (localStorage.getItem('jwt') != null) {
this.$emit("loggedIn"); this.$emit('loggedIn')
if (this.$route.params.nextUrl != null) { if (this.$route.params.nextUrl != null) {
this.$router.push(this.$route.params.nextUrl); this.$router.push(this.$route.params.nextUrl)
} else { } else {
if (is_admin == 1) { if (isAdmin === 1) {
this.$router.push("admin"); this.$router.push('admin')
} else { } else {
this.$router.push("dashboard"); this.$router.push('dashboard')
} }
} }
} }
}) })
.catch(function (error) { .catch(function (error) {
console.error(error.response); console.error(error.response)
}); })
} }
}, }
}, }
}; }
</script> </script>

View File

@@ -29,7 +29,7 @@
<label for="password-confirm">Is this an administrator account?</label> <label for="password-confirm">Is this an administrator account?</label>
<div> <div>
<select v-model="is_admin"> <select v-model="isAdmin">
<option value="1">Yes</option> <option value="1">Yes</option>
<option value="0">No</option> <option value="0">No</option>
</select> </select>
@@ -44,57 +44,58 @@
<script> <script>
export default { export default {
props: ["nextUrl"], props: ['nextUrl'],
data() { data () {
return { return {
name: "", name: '',
email: "", email: '',
password: "", password: '',
password_confirmation: "", password_confirmation: '',
is_admin: null, isAdmin: null
}; }
}, },
methods: { methods: {
handleSubmit(e) { handleSubmit (e) {
e.preventDefault(); e.preventDefault()
if ( if (
this.password === this.password_confirmation && this.password === this.password_confirmation &&
this.password.length > 0 this.password.length > 0
) { ) {
let url = "http://localhost:3000/register"; let url = 'http://localhost:3000/register'
if (this.is_admin != null || this.is_admin == 1) if (this.isAdmin != null || this.isAdmin === 1) {
url = "http://localhost:3000/register-admin"; url = 'http://localhost:3000/register-admin'
}
this.$http this.$http
.post(url, { .post(url, {
name: this.name, name: this.name,
email: this.email, email: this.email,
password: this.password, password: this.password,
is_admin: this.is_admin, isAdmin: this.isAdmin
}) })
.then((response) => { .then((response) => {
localStorage.setItem("user", JSON.stringify(response.data.user)); localStorage.setItem('user', JSON.stringify(response.data.user))
localStorage.setItem("jwt", response.data.token); localStorage.setItem('jwt', response.data.token)
if (localStorage.getItem("jwt") != null) { if (localStorage.getItem('jwt') != null) {
this.$emit("loggedIn"); this.$emit('loggedIn')
if (this.$route.params.nextUrl != null) { if (this.$route.params.nextUrl != null) {
this.$router.push(this.$route.params.nextUrl); this.$router.push(this.$route.params.nextUrl)
} else { } else {
this.$router.push("/"); this.$router.push('/')
} }
} }
}) })
.catch((error) => { .catch((error) => {
console.error(error); console.error(error)
}); })
} else { } else {
this.password = ""; this.password = ''
this.passwordConfirm = ""; this.passwordConfirm = ''
return alert("Passwords do not match"); return alert('Passwords do not match')
} }
}, }
}, }
}; }
</script> </script>

View File

@@ -7,12 +7,12 @@
<script> <script>
export default { export default {
data() { data () {
return { return {
msg: "The commoners", msg: 'The commoners'
}; }
}, }
}; }
</script> </script>
<!-- Add "scoped" attribute to limit CSS to this component only --> <!-- Add "scoped" attribute to limit CSS to this component only -->
@@ -32,4 +32,4 @@ li {
a { a {
color: #42b983; color: #42b983;
} }
</style> </style>

View File

@@ -5,14 +5,14 @@ import App from './App'
import router from './router' import router from './router'
import Axios from 'axios' import Axios from 'axios'
Vue.prototype.$http = Axios; Vue.prototype.$http = Axios
Vue.config.productionTip = false Vue.config.productionTip = false
/* eslint-disable no-new */ /* eslint-disable no-new */
new Vue({ new Vue({
el: '#app', el: '#app',
router, router,
components: { App }, components: { App },
template: '<App/>' template: '<App/>'
}) })

View File

@@ -8,80 +8,78 @@ import Admin from '@/components/Admin'
Vue.use(Router) Vue.use(Router)
let router = new Router({ const router = new Router({
mode: 'history', mode: 'history',
routes: [ routes: [
{ {
path: '/', path: '/',
name: 'HelloWorld', name: 'HelloWorld',
component: HelloWorld component: HelloWorld
}, },
{ {
path: '/login', path: '/login',
name: 'login', name: 'login',
component: Login, component: Login,
meta: { meta: {
guest: true guest: true
} }
}, },
{ {
path: '/register', path: '/register',
name: 'register', name: 'register',
component: Register, component: Register,
meta: { meta: {
guest: true guest: true
} }
}, },
{ {
path: '/dashboard', path: '/dashboard',
name: 'userboard', name: 'userboard',
component: UserBoard, component: UserBoard,
meta: { meta: {
requiresAuth: true requiresAuth: true
} }
}, },
{ {
path: '/admin', path: '/admin',
name: 'admin', name: 'admin',
component: Admin, component: Admin,
meta: { meta: {
requiresAuth: true, requiresAuth: true,
is_admin: true isAdmin: true
} }
}, }
] ]
}) })
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requiresAuth)) { if (to.matched.some(record => record.meta.requiresAuth)) {
if (localStorage.getItem('jwt') == null) { if (localStorage.getItem('jwt') == null) {
next({ next({
path: '/login', path: '/login',
params: { nextUrl: to.fullPath } params: { nextUrl: to.fullPath }
}) })
} else {
let user = JSON.parse(localStorage.getItem('user'))
if (to.matched.some(record => record.meta.is_admin)) {
if (user.is_admin == 1) {
next()
}
else {
next({ name: 'userboard' })
}
} else {
next()
}
}
} else if (to.matched.some(record => record.meta.guest)) {
if (localStorage.getItem('jwt') == null) {
next()
}
else {
next({ name: 'userboard' })
}
} else { } else {
const user = JSON.parse(localStorage.getItem('user'))
if (to.matched.some(record => record.meta.isAdmin)) {
if (user.isAdmin === 1) {
next()
} else {
next({ name: 'userboard' })
}
} else {
next() next()
}
} }
} else if (to.matched.some(record => record.meta.guest)) {
if (localStorage.getItem('jwt') == null) {
next()
} else {
next({ name: 'userboard' })
}
} else {
next()
}
}) })
export default router export default router