vuejs / vue-cli

🛠️ webpack-based tooling for Vue.js Development
https://cli.vuejs.org/
MIT License
29.75k stars 6.33k forks source link

Let plugins add information to the Readme.md #3547

Open steveworkman opened 5 years ago

steveworkman commented 5 years ago

What problem does this feature solve?

Plugins and presets often need to add long-lasting generic information into a project, for example, a preset would add in deployment or configuration details to be done by developers outside of the Vue CLI.

What does the proposed API look like?

api.extendReadme(MarkDownFormattedString)

The readme would then generate a section based on the plugin/preset that inserted the string so that it can be included in the generated readme.md

repinel commented 5 years ago

Running hook after the README.md is generated would give developers more control over the changes. It would be possible to change the file using something like readFileSync.

marczych commented 5 years ago

Any update on this? I wrote a carefully crafted README in my template months ago and only today discovered that it is completely ignored! Or at least overwritten later.

I tried manually writing to it using fs in onCreateComplete() but it didn't take effect like other files that I'm modifying in that hook. I see that it prints out "Generating README.md..." - is there a hook for after that runs?

I have a super hacky workaround but I don't like it:

setTimeout(() => {
  // Update README.md.
}, 10000);
bodograumann commented 5 years ago

So the current situation is this:

There is a utility function for generating the readme file. It requires the final version of the package.json data in order to inspect what kind of npm scripts there are. Then it looks up the script names in a dictionary of script descriptions to add that information to the readme.

In order for it to pickup on all the scripts defined by the official plugins (e.g. eslint, jest, etc) it is only called after all the generators have been called.

To make the readme editable by other plugins, the creation process would have to be split.

  1. Create a most basic readme file.
  2. Call the generators
  3. Add the script descriptions for official plugins by modifiying the readme.

As a further improvement, the script descriptions should be added directly by the generators of the official plugins. This way any preset and other plugins can override all of the readme content.

QiuShuiBai commented 4 years ago

Now I'm using this method to solve it.

Writing the following code at API api.onCreateComplete

api.onCreateComplete(() => {
  process.env.VUE_CLI_SKIP_WRITE = true
})

Because the function writeFileTree of generating README.md use VUE_CLI_SKIP_WRITE to judge whether there is a need to do it.