|
| 1 | +const fs = require('fs') |
| 2 | + |
1 | 3 | module.exports = (api) => {
|
2 | 4 | api.extendPackage({
|
3 | 5 | dependencies: {
|
@@ -93,5 +95,29 @@ module.exports = (api) => {
|
93 | 95 | // * Partial support of per-component navigation guards. No `beforeRouteEnter`
|
94 | 96 | }
|
95 | 97 |
|
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 | + } |
97 | 123 | }
|
0 commit comments