forked from vuejs/vue-cli
/
index.js
108 lines (94 loc) · 2.57 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const pluginDevDeps = require('../package.json').devDependencies
module.exports = (api, {
classComponent,
tsLint,
lintOn = [],
skipLibCheck = true,
convertJsToTs,
allowJs
}, rootOptions, invoking) => {
if (typeof lintOn === 'string') {
lintOn = lintOn.split(',')
}
const isVue3 = rootOptions && rootOptions.vueVersion === '3'
api.extendPackage({
devDependencies: {
typescript: pluginDevDeps.typescript
}
})
if (classComponent) {
if (isVue3) {
api.extendPackage({
dependencies: {
'vue-class-component': '^8.0.0-0'
}
})
} else {
api.extendPackage({
dependencies: {
'vue-class-component': pluginDevDeps['vue-class-component'],
'vue-property-decorator': pluginDevDeps['vue-property-decorator']
}
})
}
}
if (tsLint) {
api.extendPackage({
scripts: {
lint: 'vue-cli-service lint'
}
})
if (!lintOn.includes('save')) {
api.extendPackage({
vue: {
lintOnSave: false
}
})
}
if (lintOn.includes('commit')) {
api.extendPackage({
devDependencies: {
'lint-staged': '^9.5.0'
},
gitHooks: {
'pre-commit': 'lint-staged'
},
'lint-staged': {
'*.ts': ['vue-cli-service lint', 'git add'],
'*.vue': ['vue-cli-service lint', 'git add']
}
})
}
// lint and fix files on creation complete
api.onCreateComplete(() => {
return require('../lib/tslint')({}, api, true)
})
}
// late invoke compat
if (invoking) {
if (api.hasPlugin('unit-mocha')) {
// eslint-disable-next-line node/no-extraneous-require
require('@vue/cli-plugin-unit-mocha/generator').applyTS(api)
}
if (api.hasPlugin('unit-jest')) {
// eslint-disable-next-line node/no-extraneous-require
require('@vue/cli-plugin-unit-jest/generator').applyTS(api)
}
if (api.hasPlugin('eslint')) {
// eslint-disable-next-line node/no-extraneous-require
require('@vue/cli-plugin-eslint/generator').applyTS(api)
}
}
api.render('./template', {
skipLibCheck,
hasMocha: api.hasPlugin('unit-mocha'),
hasJest: api.hasPlugin('unit-jest')
})
if (isVue3) {
api.render('./template-vue3')
// In Vue 3, TSX interface is defined in https://github.com/vuejs/vue-next/blob/master/packages/runtime-dom/types/jsx.d.ts
// So no need to manually add a shim.
api.render((files) => delete files['src/shims-tsx.d.ts'])
}
require('./convert')(api, { tsLint, convertJsToTs })
}