Skip to content

Commit

Permalink
docs: adjust plugin dev guide example to write modified contents, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
akrawchyk authored and haoqunjiang committed Mar 20, 2019
1 parent b993030 commit ecbccc6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions docs/dev-guide/plugin-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,19 @@ api.onCreateComplete(() => {

Finally, you need to write the content back to the main file:

```js{11}
```js{2,11}
// generator/index.js
api.onCreateComplete(() => {
const { EOL } = require('os')
const fs = require('fs')
const contentMain = fs.readFileSync(api.entryFile, { encoding: 'utf-8' })
const lines = contentMain.split(/\r?\n/g)
const renderIndex = lines.findIndex(line => line.match(/render/))
lines[renderIndex] += `\n router,`
lines[renderIndex] += `${EOL} router,`
fs.writeFileSync(api.entryFile, contentMain, { encoding: 'utf-8' })
fs.writeFileSync(api.entryFile, lines.join(EOL), { encoding: 'utf-8' })
})
```

Expand Down

0 comments on commit ecbccc6

Please sign in to comment.