-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
/
Copy pathindex.js
75 lines (69 loc) · 1.66 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
70
71
72
73
74
75
module.exports = (api, _, __, invoking) => {
api.render('./template', {
hasTS: api.hasPlugin('typescript')
})
api.extendPackage({
scripts: {
'test:unit': 'vue-cli-service test:unit'
},
devDependencies: {
'@vue/test-utils': '^1.0.3'
},
jest: {
preset: api.hasPlugin('babel')
? '@vue/cli-plugin-unit-jest'
: '@vue/cli-plugin-unit-jest/presets/no-babel'
}
})
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: {
jest: true
}
}
]
}
})
}
const applyTS = (module.exports.applyTS = (api, invoking) => {
api.extendPackage({
jest: {
preset: api.hasPlugin('babel')
? '@vue/cli-plugin-unit-jest/presets/typescript-and-babel'
: '@vue/cli-plugin-unit-jest/presets/typescript'
},
devDependencies: {
'@types/jest': '^24.0.19'
}
})
if (invoking) {
// inject jest type to tsconfig.json
api.render(files => {
const tsconfig = files['tsconfig.json']
if (tsconfig) {
const parsed = JSON.parse(tsconfig)
if (
parsed.compilerOptions.types &&
!parsed.compilerOptions.types.includes('jest')
) {
parsed.compilerOptions.types.push('jest')
}
files['tsconfig.json'] = JSON.stringify(parsed, null, 2)
}
})
}
})