Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
adjust plugin dev guide example to write modified contents; fixes(#3655)
  • Loading branch information
akrawchyk committed Mar 18, 2019
commit 527eba5c478cf7ae577a49f7d161d3a476ef2868
5 changes: 3 additions & 2 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,`

fs.writeFileSync(api.entryFile, contentMain, { encoding: 'utf-8' })
fs.writeFileSync(api.entryFile, lines.join(EOL), { encoding: 'utf-8' })
})
```

Expand Down