Skip to content

Commit

Permalink
fix: update entry file to install vue-router-layout if vue 3
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsn committed Jan 6, 2021
1 parent 09bf274 commit 48d5e9b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ module.exports = (api, _options = {}, rootOptions = {}) => {
api.render('./template')

if (isVue3) {
api.injectImports(
api.entryFile,
`import VueRouterLayout from 'vue-router-layout'`
)
api.transformScript(api.entryFile, require('./inject-use-plugin'))

api.render('./template-vue3')
}

Expand Down
29 changes: 29 additions & 0 deletions generator/inject-use-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = (file, api) => {
const j = api.jscodeshift
const root = j(file.source)

const appRoots = root.find(j.CallExpression, (node) => {
if (j.Identifier.check(node.callee) && node.callee.name === 'createApp') {
return true
}

if (
j.MemberExpression.check(node.callee) &&
j.Identifier.check(node.callee.object) &&
node.callee.object.name === 'Vue' &&
j.Identifier.check(node.callee.property) &&
node.callee.property.name === 'createApp'
) {
return true
}
})

appRoots.replaceWith(({ node: createAppCall }) => {
return j.callExpression(
j.memberExpression(createAppCall, j.identifier('use')),
[j.identifier('VueRouterLayout')]
)
})

return root.toSource()
}

0 comments on commit 48d5e9b

Please sign in to comment.