Skip to content

Commit f953678

Browse files
committed
correct injection of code in mani.js
1 parent e21941a commit f953678

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

generator/index.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,21 @@ module.exports = (api) => {
1616

1717
// add import
1818
api.injectImports(api.entryFile,
19-
`import VueExtensionpoints from 'vue-extensionpoints'`)
19+
`import Extensionpoints from 'vue-extensionpoints'`)
2020
}
2121

22-
// module.exports.hooks = (api) => {
23-
// api.afterInvoke(() => {
24-
// const fs = require('fs')
25-
// const contentMain = fs.readFileSync(api.entryFile, { encoding: 'utf-8' })
26-
// const lines = contentMain.split(/\r?\n/g)
27-
// })
28-
// }
22+
module.exports.hooks = (api) => {
23+
api.afterInvoke(() => {
24+
const { EOL } = require('os')
25+
const fs = require('fs')
26+
const contentMain = fs.readFileSync(api.entryFile, { encoding: 'utf-8' })
27+
const lines = contentMain.split(/\r?\n/g)
28+
29+
// if not already found, add Vue.use to file
30+
if(lines.findIndex(line => line.match(/Vue.use\(Extensionpoints\)/)) < 0) {
31+
const renderIndex = lines.findIndex(line => line.match(/new Vue/))
32+
lines[renderIndex] = `Vue.use(Extensionpoints)${EOL}${EOL}` + lines[renderIndex]
33+
fs.writeFileSync(api.entryFile, lines.join(EOL), { encoding: 'utf-8' })
34+
}
35+
})
36+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-cli-plugin-extensionpoints",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "Vue CLI plugin for adding extensionpoints",
55
"main": "index.js",
66
"author": "Christian González <[email protected]",

0 commit comments

Comments
 (0)