-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
/
Copy pathindex.js
69 lines (64 loc) · 1.46 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module.exports = (api, _, __, invoking) => {
api.render('./template', {
hasTS: api.hasPlugin('typescript')
})
api.extendPackage({
devDependencies: {
'@vue/test-utils': '^1.0.3',
'chai': '^4.1.2'
},
scripts: {
'test:unit': 'vue-cli-service test:unit'
}
})
if (api.hasPlugin('eslint')) {
applyESLint(api)
}
if (api.hasPlugin('typescript')) {
applyTS(api, invoking)
}
}
const applyESLint = module.exports.applyESLint = api => {
api.extendPackage({
eslintConfig: {
overrides: [
{
files: [
'**/__tests__/*.{j,t}s?(x)',
'**/tests/unit/**/*.spec.{j,t}s?(x)'
],
env: {
mocha: true
}
}
]
}
})
}
const applyTS = module.exports.applyTS = (api, invoking) => {
api.extendPackage({
devDependencies: {
'@types/mocha': '^5.2.4',
'@types/chai': '^4.2.11'
}
})
// inject mocha/chai types to tsconfig.json
if (invoking) {
api.render(files => {
const tsconfig = files['tsconfig.json']
if (tsconfig) {
const parsed = JSON.parse(tsconfig)
const types = parsed.compilerOptions.types
if (types) {
if (!types.includes('mocha')) {
types.push('mocha')
}
if (!types.includes('chai')) {
types.push('chai')
}
}
files['tsconfig.json'] = JSON.stringify(parsed, null, 2)
}
})
}
}