Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin Development guide example doesn't update file content #3655

Closed
akrawchyk opened this issue Mar 18, 2019 · 0 comments
Closed

Plugin Development guide example doesn't update file content #3655

akrawchyk opened this issue Mar 18, 2019 · 0 comments

Comments

@akrawchyk
Copy link
Contributor

akrawchyk commented Mar 18, 2019

Version

3.5.1

Environment info


Environment Info:

  System:
    OS: macOS 10.14.3
    CPU: (4) x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
  Binaries:
    Node: 8.15.0 - ~/.nvm/versions/node/v8.15.0/bin/node
    Yarn: 1.15.2 - /usr/local/bin/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v8.15.0/bin/npm
  Browsers:
    Chrome: 72.0.3626.121
    Firefox: 64.0
    Safari: 12.0.3
  npmPackages:
    @optoro/vue-cli-plugin-optics: * => 0.0.18 
    @vue/babel-helper-vue-jsx-merge-props:  1.0.0-beta.2 
    @vue/babel-plugin-transform-vue-jsx:  1.0.0-beta.2 
    @vue/babel-preset-app:  3.5.1 
    @vue/babel-preset-jsx:  1.0.0-beta.2 
    @vue/babel-sugar-functional-vue:  1.0.0-beta.2 
    @vue/babel-sugar-inject-h:  1.0.0-beta.2 
    @vue/babel-sugar-v-model:  1.0.0-beta.2 
    @vue/babel-sugar-v-on:  1.0.0-beta.2 
    @vue/cli-overlay:  3.5.1 
    @vue/cli-plugin-babel: ^3.5.0 => 3.5.1 
    @vue/cli-plugin-eslint: ^3.5.0 => 3.5.1 
    @vue/cli-plugin-unit-jest: ^3.5.0 => 3.5.1 
    @vue/cli-service: ^3.5.0 => 3.5.1 
    @vue/cli-shared-utils:  3.5.1 
    @vue/component-compiler-utils:  2.6.0 
    @vue/eslint-config-standard: ^4.0.0 => 4.0.0 
    @vue/preload-webpack-plugin:  1.1.0 
    @vue/test-utils: 1.0.0-beta.29 => 1.0.0-beta.29 
    @vue/web-component-wrapper:  1.2.0 
    eslint-plugin-vue: ^5.0.0 => 5.2.2 
    jest-serializer-vue:  2.0.2 
    vue: ^2.6.6 => 2.6.9 
    vue-eslint-parser:  2.0.3 
    vue-hot-reload-api:  2.3.3 
    vue-jest:  3.0.4 
    vue-loader:  15.7.0 
    vue-router: ^3.0.1 => 3.0.2 
    vue-style-loader:  4.1.2 
    vue-template-compiler: ^2.5.21 => 2.6.9 
    vue-template-es2015-compiler:  1.9.1 
    vuex: ^3.0.1 => 3.1.0 
  npmGlobalPackages:
    @vue/cli: 3.5.1


Steps to reproduce

Render the docs

What is expected?

Correct information

What is actually happening?

Incorrect information


This is just an issue with the Plugin Development guide docs.

https://github.com/vuejs/vue-cli/blob/dev/docs/dev-guide/plugin-dev.md#changing-main-file

Notice the example for generator/index.js writes the same content that is read from the file instead of writing the modified contents:

// generator/index.js

api.onCreateComplete(() => {
  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' }) // XXX NO! This should render the modified `lines`
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants