1 |
|
2 | module.exports = (api, options, rootOptions, invoking) => {
|
3 | const isVue3 = rootOptions && rootOptions.vueVersion === '3'
|
4 |
|
5 | api.render('./template', {
|
6 | isVue3,
|
7 | hasTS: api.hasPlugin('typescript'),
|
8 | hasRouter: api.hasPlugin('router')
|
9 | })
|
10 |
|
11 | api.extendPackage({
|
12 | devDependencies: {
|
13 | '@vue/test-utils': isVue3 ? '^2.0.0-0' : '^1.1.3',
|
14 | 'chai': '^4.2.0'
|
15 | },
|
16 | scripts: {
|
17 | 'test:unit': 'vue-cli-service test:unit'
|
18 | }
|
19 | })
|
20 |
|
21 | if (api.hasPlugin('eslint')) {
|
22 | applyESLint(api)
|
23 | }
|
24 |
|
25 | if (api.hasPlugin('typescript')) {
|
26 | applyTS(api, invoking)
|
27 | }
|
28 | }
|
29 |
|
30 | const applyESLint = module.exports.applyESLint = api => {
|
31 | api.extendPackage({
|
32 | eslintConfig: {
|
33 | overrides: [
|
34 | {
|
35 | files: [
|
36 | '**/__tests__/*.{j,t}s?(x)',
|
37 | '**/tests/unit/**/*.spec.{j,t}s?(x)'
|
38 | ],
|
39 | env: {
|
40 | mocha: true
|
41 | }
|
42 | }
|
43 | ]
|
44 | }
|
45 | })
|
46 | }
|
47 |
|
48 | const applyTS = module.exports.applyTS = (api, invoking) => {
|
49 | const devDeps = require('../package.json').devDependencies
|
50 | api.extendPackage({
|
51 | devDependencies: {
|
52 | '@types/mocha': devDeps['@types/mocha'],
|
53 | '@types/chai': devDeps['@types/chai']
|
54 | }
|
55 | })
|
56 |
|
57 | if (invoking) {
|
58 | api.render(files => {
|
59 | const tsconfig = files['tsconfig.json']
|
60 | if (tsconfig) {
|
61 | const parsed = JSON.parse(tsconfig)
|
62 | const types = parsed.compilerOptions.types
|
63 | if (types) {
|
64 | if (!types.includes('mocha')) {
|
65 | types.push('mocha')
|
66 | }
|
67 | if (!types.includes('chai')) {
|
68 | types.push('chai')
|
69 | }
|
70 | }
|
71 | files['tsconfig.json'] = JSON.stringify(parsed, null, 2) + '\n'
|
72 | }
|
73 | })
|
74 | }
|
75 | }
|