From 527eba5c478cf7ae577a49f7d161d3a476ef2868 Mon Sep 17 00:00:00 2001 From: Andrew Krawchyk <903716+akrawchyk@users.noreply.github.com> Date: Sun, 17 Mar 2019 22:13:20 -0400 Subject: [PATCH 1/2] adjust plugin dev guide example to write modified contents; fixes(#3655) --- docs/dev-guide/plugin-dev.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/dev-guide/plugin-dev.md b/docs/dev-guide/plugin-dev.md index 037bf78f10..c93dacbc5a 100644 --- a/docs/dev-guide/plugin-dev.md +++ b/docs/dev-guide/plugin-dev.md @@ -234,10 +234,11 @@ 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) @@ -245,7 +246,7 @@ api.onCreateComplete(() => { 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' }) }) ``` From 9bf186438094b35c641021fba2c7640bac06fd57 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 19 Mar 2019 12:53:41 -0400 Subject: [PATCH 2/2] Update docs/dev-guide/plugin-dev.md use `EOL` instead of `\n` Co-Authored-By: akrawchyk <903716+akrawchyk@users.noreply.github.com> --- docs/dev-guide/plugin-dev.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/dev-guide/plugin-dev.md b/docs/dev-guide/plugin-dev.md index c93dacbc5a..164b82bc1b 100644 --- a/docs/dev-guide/plugin-dev.md +++ b/docs/dev-guide/plugin-dev.md @@ -244,7 +244,7 @@ api.onCreateComplete(() => { 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, lines.join(EOL), { encoding: 'utf-8' }) })