Skip to content

Commit ecbccc6

Browse files
akrawchykhaoqunjiang
authored andcommitted
docs: adjust plugin dev guide example to write modified contents, fixes #3655 (#3656)
1 parent b993030 commit ecbccc6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

docs/dev-guide/plugin-dev.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,18 +234,19 @@ api.onCreateComplete(() => {
234234

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

237-
```js{11}
237+
```js{2,11}
238238
// generator/index.js
239239
240240
api.onCreateComplete(() => {
241+
const { EOL } = require('os')
241242
const fs = require('fs')
242243
const contentMain = fs.readFileSync(api.entryFile, { encoding: 'utf-8' })
243244
const lines = contentMain.split(/\r?\n/g)
244245
245246
const renderIndex = lines.findIndex(line => line.match(/render/))
246-
lines[renderIndex] += `\n router,`
247+
lines[renderIndex] += `${EOL} router,`
247248
248-
fs.writeFileSync(api.entryFile, contentMain, { encoding: 'utf-8' })
249+
fs.writeFileSync(api.entryFile, lines.join(EOL), { encoding: 'utf-8' })
249250
})
250251
```
251252

0 commit comments

Comments
 (0)