Skip to content

Commit d193501

Browse files
authored
Merge pull request #28 from kingscode/KCI-136
KCI-136 > build and lint (and package.json lint)
2 parents 6281a6b + 7018c2a commit d193501

10 files changed

Lines changed: 90 additions & 22 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ later in the `vue add vuetify` will be overwritten by vuetify, or the kings code
2222
### Vue:
2323
We'd recommend you to choose
2424
- babel
25+
- eslint (only the essential)
2526
- pwa
2627
- router
2728
- vuex
@@ -30,7 +31,7 @@ We'd recommend you to choose
3031
And then:
3132

3233
- history mode
33-
- dart sass (very important, vuetify wont work without it)
34+
- dart sass (very important, vuetify won't work without it)
3435

3536
The rest doesn't matter.
3637

@@ -42,7 +43,7 @@ This is our own scaffold, which you can use with our laravel API you can answer
4243
as you like in this plugins. The most important choices are:
4344

4445
- Do you want to use a crud system?
45-
- This installs our vuetify resource and creates an implementation for this so the vuetify
46+
- This installs our vuetify resource and creates an implementation for this, so the vuetify
4647
resource works with the connected laravel API
4748
- a example user resource
4849
- Do you want to use authorisation?

generator/index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ module.exports = (api, options) => {
1212
'qs': '^6.9.4',
1313
'vue-router': '3.3.4',
1414
'vue-i18n': '^8.21.0',
15-
15+
},
16+
scripts: {
17+
'lint': 'vue-cli-service lint',
1618
},
1719
});
1820
if (options.plugins.includes('fontawesomepro')) {
@@ -71,6 +73,22 @@ module.exports = (api, options) => {
7173
api.render('./templates/Plugins/analytics', options);
7274
}
7375

76+
if (options.useBuildAndLintAction) {
77+
if (fs.existsSync('./.eslintrc.js')) {
78+
fs.unlinkSync(api.resolve('./.eslintrc.js'));
79+
}
80+
api.extendPackage({
81+
dependencies: {
82+
'@vue/cli-plugin-eslint': '~4.4.0',
83+
'babel-eslint': '^10.1.0',
84+
'eslint': '^6.7.2',
85+
'eslint-plugin-import': '^2.22.1',
86+
'eslint-plugin-vue': '^6.2.2',
87+
},
88+
});
89+
api.render('./templates/ESLint', options);
90+
}
91+
7492
api.onCreateComplete(() => {
7593
if (fs.existsSync('src/store.js')) {
7694
fs.unlinkSync(api.resolve('src/store.js'));

generator/templates/Crud/src/components/Resource.vue

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export default {
132132
total,
133133
});
134134
})
135-
.catch(() => reject());
135+
.catch((e) => reject(e));
136136
137137
});
138138
},
@@ -161,10 +161,10 @@ export default {
161161
})
162162
.catch((error) => {
163163
this.errors = error.response.data.errors;
164-
reject();
164+
reject(error);
165165
});
166166
} else {
167-
reject();
167+
reject(new Error('(create)Form is invalid'));
168168
}
169169
});
170170
@@ -181,10 +181,10 @@ export default {
181181
.then(() => resolve())
182182
.catch((error) => {
183183
this.errors = error.response.data.errors;
184-
reject();
184+
reject(error);
185185
});
186186
} else {
187-
reject();
187+
reject(new Error('(update)Form is invalid'));
188188
}
189189
});
190190
});
@@ -201,7 +201,7 @@ export default {
201201
.then(() => {
202202
resolve();
203203
})
204-
.catch(() => reject());
204+
.catch((e) => reject(e));
205205
206206
});
207207
},
@@ -214,7 +214,8 @@ export default {
214214
this.beforeOpenCreate(selected);
215215
}
216216
if (this.modelType) {
217-
this.createForm.values = new this.modelType();
217+
const Model = this.modelType()
218+
this.createForm.values = new Model;
218219
}
219220
},
220221
beforeOpenUpdateHandler(selected) {
@@ -227,7 +228,9 @@ export default {
227228
return;
228229
}
229230
230-
this.updateForm.values = new this.modelType().mapResponse(selected[0]);
231+
const Model = this.modelType()
232+
const instance = new Model
233+
this.updateForm.values = instance.mapResponse(selected[0]);
231234
},
232235
},
233236
};

generator/templates/Default/src/components/crud/fields/KDateField.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@ export default {
7878
},
7979
},
8080
created() {
81-
if (this.type === 'month') {
82-
return this.date = this.value || dayjs().format('MMM YYYY');
83-
}
84-
this.date = this.value || dayjs().format('YYYY-MM-DD');
81+
const format = this.type === 'month' ? 'MMM YYYY' : 'YYYY-MM-DD';
82+
this.date = this.value || dayjs().format(format);
8583
},
8684
computed: {
8785
formattedDate() {

generator/templates/Default/src/newmain.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import '@babel/polyfill'
21
import Vue from 'vue'
32
import { i18n, vuetify } from './plugins';
43
<%_ if (options.useCrud) { _%>

generator/templates/Deployment/_github/workflows/deploy.production.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- uses: actions/checkout@master
13+
- uses: actions/checkout@main
1414

1515
- name: setup server connections
1616
env:

generator/templates/Deployment/_github/workflows/deploy.test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ name: Deploy [test]
33
on:
44
push:
55
branches:
6-
- 'master'
6+
- 'main'
77

88
jobs:
99
deploy:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- uses: actions/checkout@master
13+
- uses: actions/checkout@main
1414

1515
- name: setup server connections
1616
env:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
node: true,
5+
},
6+
extends: [
7+
'plugin:vue/essential',
8+
],
9+
parserOptions: {
10+
parser: 'babel-eslint',
11+
},
12+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Build & Lint
2+
3+
on: pull_request
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@main
11+
12+
<%_ if (options.plugins.includes('fontawesomepro')) { _%>
13+
- name: build .npmrc
14+
env:
15+
FONT_AWESOME_TOKEN: ${{ secrets.font_awesome_token }}
16+
run: |
17+
echo "@fortawesome:registry=https://npm.fontawesome.com/" >> .npmrc
18+
echo "//npm.fontawesome.com/:_authToken=$FONT_AWESOME_TOKEN" >> .npmrc
19+
<%_ } _%>
20+
21+
- name: install
22+
run: |
23+
npm ci
24+
25+
- name: lint
26+
run: |
27+
npm run lint
28+
29+
- name: build
30+
run: |
31+
npm run build

prompts.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ module.exports = [
1717
message: 'Do you want to use github actions for deployments?',
1818
default: true,
1919
},
20+
{
21+
name: 'useBuildAndLintAction',
22+
type: 'confirm',
23+
message: 'Do you want to add a github workflow action which "build and lint" on every pull request? It is a fail-safe that you only deploy code which can build.',
24+
default: true,
25+
},
2026
{
2127
name: 'addRobotsFile',
2228
type: 'confirm',
23-
message: 'Do you want to disallow robots (SEO) to visit this applications (Y: robots.txt is placed in public folder, N: if you use github actions for deployment, in the test deployment a robots.txt is generated)',
29+
message: 'Do you want to disallow robots (SEO) to visit this applications (Y: robots.txt is placed in public folder, N: if you use github actions for deployment, in the test deployment a robots.txt is generated)?',
2430
default: false,
2531
},
2632
{
@@ -31,12 +37,12 @@ module.exports = [
3137
{
3238
value: 'Sentry',
3339
name: 'error logging with Sentry',
34-
checked: true,
40+
checked: false,
3541
},
3642
{
3743
value: 'analytics',
3844
name: 'Google Analytics with vue-analytics',
39-
checked: true,
45+
checked: false,
4046
},
4147
{
4248
value: 'fontawesomepro',

0 commit comments

Comments
 (0)