Skip to content

Commit e6c24ce

Browse files
committed
feat: also transform router and store files
1 parent 5aa04ca commit e6c24ce

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

generator/index.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const fs = require('fs')
2+
13
module.exports = (api) => {
24
api.extendPackage({
35
dependencies: {
@@ -93,5 +95,29 @@ module.exports = (api) => {
9395
// * Partial support of per-component navigation guards. No `beforeRouteEnter`
9496
}
9597

96-
api.transformScript(api.entryFile, require('./codemods/global-api'))
98+
const globalApiTransform = require('./codemods/global-api')
99+
api.transformScript(api.entryFile, globalApiTransform)
100+
101+
const resolveFile = (file) => {
102+
let filePath = api.resolve(file)
103+
if (fs.existsSync(filePath)) return filePath
104+
filePath = api.resolve(file.replace('.js', '.ts'))
105+
if (fs.existsSync(filePath)) return filePath
106+
filePath = api.resolve(path.join(file.replace('.js', ''), 'index.js'))
107+
if (fs.existsSync(filePath)) return filePath
108+
filePath = api.resolve(path.join(file.replace('.js', ''), 'index.ts'))
109+
if (fs.existsSync(filePath)) return filePath
110+
}
111+
112+
const routerPath = resolveFile('router')
113+
if (routerPath) {
114+
api.transformScript(routerPath, globalApiTransform)
115+
api.transformScript(routerPath, require('./codemods/router'))
116+
}
117+
118+
const storePath = resolveFile('store')
119+
if (storePath) {
120+
api.transformScript(storePath, globalApiTransform)
121+
api.transformScript(storePath, require('./codemods/vuex'))
122+
}
97123
}

0 commit comments

Comments
 (0)