-
Notifications
You must be signed in to change notification settings - Fork 5
/
generator.js
51 lines (42 loc) · 1.06 KB
/
generator.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
const fs = require('fs')
const removeFiles = (files = []) => {
files.forEach(path => {
if (fs.existsSync(path)) {
fs.unlinkSync(path)
}
})
}
const filesToRemove = [
'src/components/HelloWorld.vue',
'src/router.js',
'src/store.js'
]
const importsToRemove = [
`import store from './store'`,
`import router from './router'`
]
module.exports = (api, options, rootOptions) => {
const {
entryFile,
generator: { imports }
} = api
api.extendPackage({
dependencies: {
'element-ui': '^2.4.11',
'vuex-router-sync': '^5.0.0'
}
})
// api.injectImports(entryFile, `import './registerElementUI'`)
// Remove the default imports generated by vue-cli
if (imports[entryFile]) {
importsToRemove.forEach(itr => imports[entryFile].delete(itr))
}
// Remove the default files generated by vue-cli
api.render(function(files) {
filesToRemove.forEach(ftr => delete files[ftr])
})
api.render('./template/structure')
api.onCreateComplete(() => {
removeFiles(filesToRemove.map(ftr => api.resolve(ftr)))
})
}