Skip to content

Commit f08bb6f

Browse files
author
Walker Leite
committed
feat(template): add extended option
1 parent 0ed26bd commit f08bb6f

37 files changed

+1206
-49
lines changed

meta.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const path = require('path');
33

44
module.exports = {
55
"prompts": {
6-
76
"name": {
87
"type": "string",
98
"required": true,
@@ -19,26 +18,25 @@ module.exports = {
1918
"type": "string",
2019
"message": "Author"
2120
},
22-
"build": {
23-
"type": "list",
24-
"message": "Vue build",
25-
"choices": [
26-
{
27-
"name": "Runtime + Compiler: recommended for most users",
28-
"value": "standalone",
29-
"short": "standalone"
30-
},
31-
{
32-
"name": "Runtime-only: about 6KB lighter min+gzip, but templates (or any Vue-specific HTML) are ONLY allowed in .vue files - render functions are required elsewhere",
33-
"value": "runtime",
34-
"short": "runtime"
35-
}
36-
]
37-
},
38-
"router": {
21+
"extended": {
3922
"type": "confirm",
40-
"message": "Install vue-router?"
41-
},
23+
"message": "Add basic Login and Admin views with Vuex, Vue-router and Bootstrap-vue?"
24+
}
25+
},
26+
"filters": {
27+
"client/router.js": "extended",
28+
"client/static/main.css": "extended === false",
29+
"client/static/images/**/*": "extended",
30+
"client/components/**/*": "extended",
31+
"client/services/**/*": "extended",
32+
"client/store/**/*": "extended",
33+
"client/style/**/*": "extended",
34+
"client/view/**/*": "extended",
35+
"server/boot/add-initial-data.js": "extended",
36+
"server/boot/create-admin.js": "extended",
37+
"server/initial-data/**/*": "extended",
38+
"server/models/**/*": "extended",
39+
"test/server/account.test.js": "extended",
4240
},
4341
"complete": function(data, {logger}) {
4442
logger.log("To get started:");

template/.babelrc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
{
2-
"presets": ["es2015"]
2+
"presets": ["es2015"],
3+
"plugins": [
4+
[
5+
"babel-plugin-root-import", [{
6+
"rootPathPrefix": "~",
7+
"rootPathSuffix": "."
8+
}, {
9+
"rootPathPrefix": "@",
10+
"rootPathSuffix": "client"
11+
}
12+
]
13+
]
14+
]
315
}

template/.eslintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"sourceType": "module"
77
},
88
"globals": {
9-
"require": true
9+
"expect": true,
10+
"assert": true,
11+
"require": true,
12+
"request": true
1013
}
1114
}

template/.gitlab-ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Official framework image. Look for the different tagged releases at:
2+
# https://hub.docker.com/r/library/node/tags/
3+
image: node:latest
4+
5+
before_script:
6+
- npm install
7+
8+
# This folder is cached between builds
9+
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
10+
cache:
11+
paths:
12+
- node_modules/
13+
14+
test:lint:
15+
script:
16+
- npm run lint
17+
18+
test:vulnerabilities:
19+
script:
20+
- npm run vulnerabilities
21+
22+
test:node:latest:
23+
script:
24+
- npm run test

template/client/App.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
<template lang="html">
2-
<h1>\{{ hello }}</h1>
2+
{{#extended}}
3+
<router-view id="app"></router-view>
4+
{{else}}
5+
<h1>\{{ hello }}</h1>
6+
{{/extended}}
37
</template>
48

59
<script>
610
export default {
11+
{{#unless extended}}
712
data: () => ({
813
hello: 'Hello World!',
914
}),
15+
{{/unless}}
1016
}
1117
</script>
1218

13-
<style lang="css">
19+
<style {{#extended}}lang="scss"{{else}}lang="css"{{/extended}}>
1420
</style>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<slot>Hello World! This content is restricted</slot>
3+
</template>
4+
5+
<script>
6+
export default {
7+
8+
}
9+
</script>

template/client/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
<head>
44
<meta charset="utf-8">
55
<title>{{name}}</title>
6+
{{#extended}}
7+
<meta name="viewport" content="width=device-width, user-scalable=no">
8+
{{/extended}}
69
</head>
710
<body>
811
<div id="app"></div>

template/client/main.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,42 @@
1+
{{#extended}}
2+
/* Required by BootstrapVue */
3+
import 'babel-polyfill';
4+
5+
{{/extended}}
6+
/* Global Components */
17
import Vue from 'vue';
8+
{{#extended}}
9+
import {sync} from 'vuex-router-sync';
10+
import 'bootstrap-vue/dist/bootstrap-vue.css';
11+
import BootstrapVue from 'bootstrap-vue';
12+
// import 'vue-awesome/icons';
13+
import Icon from 'vue-awesome';
14+
15+
Vue.use(BootstrapVue);
16+
17+
Vue.component('icon', Icon);
18+
19+
{{/extended}}
20+
/* Local Components and modules */
221
import App from './App.vue';
22+
{{#extended}}
23+
import router from './router.js';
24+
import store from './store';
25+
26+
// Add router state to store
27+
sync(store, router);
28+
{{/extended}}
329

30+
{{unless extended}}
431
import './static/main.css';
32+
{{/unless}}
533

34+
// Instance Application
635
new Vue({
736
el: '#app',
837
render: (r) => r(App),
38+
{{#extended}}
39+
router,
40+
store,
41+
{{/extended}}
942
});

template/client/router.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import Vue from 'vue';
2+
import VueRouter from 'vue-router';
3+
import store from '@/store';
4+
import Login from './view/Login.vue';
5+
import Dashboard from './view/Dashboard.vue';
6+
import Profile from './view/Profile.vue';
7+
8+
Vue.use(VueRouter);
9+
10+
const router = new VueRouter({
11+
mode: 'history',
12+
routes: [
13+
{
14+
path: '/',
15+
name: 'home',
16+
redirect: {name: 'dashboard'},
17+
}, {
18+
path: '/dashboard',
19+
name: 'dashboard',
20+
component: Dashboard,
21+
meta: {requiresAuth: true},
22+
}, {
23+
path: '/login',
24+
name: 'login',
25+
component: Login,
26+
}, {
27+
path: '/profile',
28+
name: 'profile',
29+
component: Profile,
30+
// eslint-disable-next-line camelcase
31+
props: route => ({access_token: route.query.access_token}),
32+
meta: {requiresAuth: true},
33+
},
34+
],
35+
});
36+
37+
router.beforeEach((to, from, next) => {
38+
if (to.matched.some(record => record.meta.requiresAuth)) {
39+
// this route requires auth, check if logged in
40+
// if not, redirect to login page (except when it's profile route and
41+
// there is an access_token).
42+
if (to.name === 'profile' && to.query.access_token) {
43+
next();
44+
} else if (!store.state.auth.access_token) {
45+
next({
46+
name: 'login',
47+
});
48+
} else {
49+
next();
50+
}
51+
} else {
52+
next(); // make sure to always call next()!
53+
}
54+
});
55+
56+
export default router;

template/client/services/loopback.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {host, restApiRoot, port} from '~/server/config.json';
2+
import axios from 'axios';
3+
4+
const http = axios.create({
5+
baseURL: 'http://' + host + ':' + port + restApiRoot,
6+
});
7+
8+
http.setToken = token => {
9+
http.defaults.headers.common['Authorization'] = token;
10+
};
11+
12+
http.removeToken = () => {
13+
delete http.defaults.headers.common.Authorization;
14+
};
15+
16+
http.find = (endpoint, filter) => http.get(endpoint, {params: {filter}});
17+
18+
const interceptErrors = err => {
19+
try {
20+
err = Object.assign(new Error(), err.response.data.error);
21+
} catch (e) {
22+
// Will return err if something goes wrong
23+
}
24+
return Promise.reject(err);
25+
};
26+
const interceptResponse = res => {
27+
try {
28+
return res.data;
29+
} catch (e) {
30+
return res;
31+
}
32+
};
33+
http.interceptors.response.use(interceptResponse, interceptErrors);
34+
35+
export default http;
36+
37+
// Documentation: https://github.com/axios/axios

0 commit comments

Comments
 (0)