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

[docs] Improve documentation for plugin authors #4266

Closed
2 of 8 tasks
jlengstorf opened this issue Feb 27, 2018 · 16 comments
Closed
2 of 8 tasks

[docs] Improve documentation for plugin authors #4266

jlengstorf opened this issue Feb 27, 2018 · 16 comments
Labels
type: documentation An issue or pull request for improving or updating Gatsby's documentation

Comments

@jlengstorf
Copy link
Contributor

jlengstorf commented Feb 27, 2018

Currently, the documentation for plugin authors is pretty sparse. On the contributing page, there's a single paragraph, and the plugins section of the docs is super high-level.

What I'm proposing in the short term

The docs should be updated to:

  • Explain naming conventions for plugins (e.g. when should I use gatsby-plugin-* vs gatsby-transformer-*?)
  • Explicitly explain what files can be contained in a plugin, and which APIs are available to plugins
  • Create a boilerplate to create a consistent Gatsby plugin README experience

What I'm proposing in the medium term

  • Write tutorials for each of the plugin types to show real examples of using the plugin APIs
  • Add video tutorials to complement the written versions
  • Find a way to work plugin documentation into the new plugins page being created in Plugin Library build fixes #3906

What I'm proposing in the long term

  • Add a CLI tool that asks a few questions about the plugin you want to create and sets you up with the proper boilerplate
  • Add plugin validation to ensure that a plugin is compatible with your Gatsby install (e.g. no conflicts, versions are compatible)

Did I miss anything here? I can get started on the short-term updates right away — would love to get any feedback from other folks who've written plugins:

  • where did you get stuck?
  • what questions did you have trouble finding answers to?
  • how could Gatsby's docs make the plugin authoring experience more friendly?

This may need to be pulled into a project — "Improve the Plugin Discovery and Authoring Experience" — or maybe we can solve it all in a few issues.

What do you think?

@jlengstorf jlengstorf added the type: documentation An issue or pull request for improving or updating Gatsby's documentation label Feb 27, 2018
@KyleAMathews
Copy link
Contributor

This looks fantastic! Let me know how I can help!

@markmichon
Copy link
Contributor

Looks good! I was thinking about building a "gatsby-plugin-starter" repo, but haven't had the time. I like the idea of a CLI to handle that too.

jlengstorf added a commit to jlengstorf/gatsby that referenced this issue Feb 27, 2018
- Link to plugin docs
- Link to API spec

re gatsbyjs#4266
jlengstorf added a commit to jlengstorf/gatsby that referenced this issue Feb 27, 2018
@jlengstorf
Copy link
Contributor Author

@KyleAMathews I'll probably need your help double-checking the API/naming conventions write-ups to make sure I didn't miss anything.

@markmichon A starter repo would be fantastic, but I wonder if we'd need multiple versions? For example, a plugin to add third-party code (e.g. Google Analytics) is really different from a transformer or a data source plugin. 😕 (That's why I put this in the long term category. 😂)

@jlengstorf
Copy link
Contributor Author

I've got a PR started at #4272 to tackle the short-term changes. Any feedback is welcome as I work toward getting this done.

@jlengstorf
Copy link
Contributor Author

@KyleAMathews can a plugin provide a gatsby-config.js? If so, do docs exist on how that works (e.g. loading order, is that available site-wide or scoped to the plugin)?

@jlengstorf
Copy link
Contributor Author

When/how is index.js used? In the vast majority of plugins it's a no-op, but in a few places it appears to do things (e.g. https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-contentful/index.js). I'm not super clear on how this is being handled under the hood, so I could use some guidance and/or a link to the source where this gets picked up.

@jlengstorf
Copy link
Contributor Author

If I'm in the right place in the code, it looks like index.js isn't used in plugins, which is confusing given that gatsby-source-contentful exports one.

https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/bootstrap/load-plugins/validate.js#L94-L105

This also appears to answer my previous question about gatsby-config.js — it's not possible to add or modify the config from a plugin. (Please confirm this.) 😅

jlengstorf added a commit to jlengstorf/gatsby that referenced this issue Feb 27, 2018
- removes local plugin docs
- adds link to plugin authoring (where local plugin docs were moved)

re gatsbyjs#4266
jlengstorf added a commit to jlengstorf/gatsby that referenced this issue Feb 27, 2018
- add naming convention explanations and examples
- add core plugin concepts as bullet points
- add list of files Gatsby tries to find in a plugin
- explain local plugin development

re gatsbyjs#4266
@pieh
Copy link
Contributor

pieh commented Feb 27, 2018

index.js is used when plugin exports something that user (or other plugin) might want to import in their code via require/import - it doesn't use any of gatsby apis and isn't run by gatsby itself

in your gatsby-source-contentful this was added to reuse graphql types in plugin that is currently under development ( https://github.com/gatsbyjs/gatsby/pull/4205/files#diff-7629f8c5bcb62e07dc5b843af493a8e3R80 ) that want to reuse some of already defined types

gatsby-source-filesystem will export utility function that will create File nodes from remote urls (that will be used by other plugins - for example gatsby-source-wordpress

this is not gatsby specific - just normal module export

@jlengstorf
Copy link
Contributor Author

#4272 is ready for review. Only thing left to add is the boilerplate README, which might actually make more sense in a starter repo. It feels like it wouldn't fit on the docs page right now; would love some feedback on this.

@pieh
Copy link
Contributor

pieh commented Feb 28, 2018

Write tutorials for each of the plugin types to show real examples of using the plugin APIs

In #2586 in comments I tried to explain base concepts of data sourcing and how it ties into gatsby graphql layer ( #2586 (comment) ) and provided examples that use demo REST api ( https://jsonplaceholder.typicode.com/ - #2586 (comment) and #2586 (comment) ).

I think some of it (mostly examples as I'm not good writer) might be used to update Create a source plugin page with real live (ish) use of related APIs. What is missing there and I feel is important is fetching assets (for example images) from remote urls. Demo REST api I used there do have endpoint which point to images ( https://jsonplaceholder.typicode.com/photos ) and I can adjust examples to use /photos and /albums endpoints instead of /todos for that. Alternatively we can prepare static .json files that will mimic REST api modeled to represent something that will show capabilities of gatsby data store -> graphql layer, but I think using well known demo REST api is good idea as this removes additional barrier of getting familiar with new REST api to follow this guide.

jlengstorf added a commit to jlengstorf/gatsby that referenced this issue Feb 28, 2018
- Add link to “create a source plugin” docs
- Clarify optional vs. required files
- Clarify how `package.json` works and what default values are
- Clean up local plugin `gatsby-config.js` note
- Remove duplicate explanation of `package.json`

re gatsbyjs#4266
jlengstorf added a commit to jlengstorf/gatsby that referenced this issue Feb 28, 2018
- Clarify that plugins can run as npm packages or local files

re gatsbyjs#4266
@KyleAMathews
Copy link
Contributor

can a plugin provide a gatsby-config.js? If so, do docs exist on how that works (e.g. loading order, is that available site-wide or scoped to the plugin)?

No — plugins can have sub-plugins e.g. all the gatsby-remark-* plugins.

I thought about doing this but decided this would add a lot of complexity around issues like you mentioned.

We'll probably need this for themes though so will need to address this when we start work on them.

@KyleAMathews
Copy link
Contributor

When/how is index.js used? In the vast majority of plugins it's a no-op, but in a few places it appears to do things (e.g. https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-contentful/index.js). I'm not super clear on how this is being handled under the hood, so I could use some guidance and/or a link to the source where this gets picked up.

It's not. Node module resolution requires a directory to have an index.js or something in the main field of a package.json. Since Gatsby requires each JavaScript environment (node, ssr, browser) to have a seperate file (so the gatsby-* files), we decided to eschew index.js but to keep Node happy, we add blank ones there.

Plugins can have something in index.js like gatsby-source-contentful if you want to export helper functions for other plugins to use e.g. gatsby-source-filesystem does the same thing https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-filesystem/src/index.js

@KyleAMathews
Copy link
Contributor

oh, @pieh already answered these haha 😅

In the mouth of two or three witnesses...

jlengstorf added a commit to jlengstorf/gatsby that referenced this issue Feb 28, 2018
- remove reference to plugins being “easy”
- build off @robwierzbowski’s wording
- add examples of what plugins can do

re gatsbyjs#4266
jlengstorf added a commit to jlengstorf/gatsby that referenced this issue Feb 28, 2018
- update wording per @KyleAMathews feedback
- clarify transformer description
- link to example plugins
- fix grammar mistakes

re gatsbyjs#4266
jlengstorf added a commit to jlengstorf/gatsby that referenced this issue Feb 28, 2018
KyleAMathews pushed a commit that referenced this issue Mar 1, 2018
* docs: add links for plugin authors

- Link to plugin docs
- Link to API spec

re #4266

* docs: create a “plugin authoring” page

re #4266

* docs: move authoring docs to authoring page

- removes local plugin docs
- adds link to plugin authoring (where local plugin docs were moved)

re #4266

* docs: write plugin authoring docs

- add naming convention explanations and examples
- add core plugin concepts as bullet points
- add list of files Gatsby tries to find in a plugin
- explain local plugin development

re #4266

* docs: clean up plugin authoring docs

- Add link to “create a source plugin” docs
- Clarify optional vs. required files
- Clarify how `package.json` works and what default values are
- Clean up local plugin `gatsby-config.js` note
- Remove duplicate explanation of `package.json`

re #4266

* docs: clarify npm package core concept

- Clarify that plugins can run as npm packages or local files

re #4266

* Add missing word

* docs: improve opening paragraph

- remove reference to plugins being “easy”
- build off @robwierzbowski’s wording
- add examples of what plugins can do

re #4266

* docs: clarify and clean up

- update wording per @KyleAMathews feedback
- clarify transformer description
- link to example plugins
- fix grammar mistakes

re #4266

* docs: improve wording around plugin documentation

re #4266

* docs: minor tweaks

* Reverse order as extending far more common
@shannonbux
Copy link
Contributor

shannonbux commented Aug 31, 2018

Hi @jlengstorf just revisiting this. I was thinking of closing this issue and creating new issues that mirror the checklist you have above in [EPIC] v2.0 plugin library and [EPIC] v3.0 plugin library like so.

  • Create a boilerplate to create a consistent Gatsby plugin README experience

[EPIC] v2.0 plugin library

  • Create a boilerplate to create a consistent Gatsby plugin README experience
  • Write tutorials for each of the plugin types to show real examples of using the plugin APIs
  • Add plugin validation to ensure that a plugin is compatible with your Gatsby install (e.g. no conflicts, versions are compatible)

[EPIC] v3.0 plugin library

  • Add video tutorials to complement the written versions
  • Find a way to work plugin documentation into the new plugins page being created in Plugin Library build fixes #3906

And could this one get added to @ChristopherBiscardi's project?

  • Add a CLI tool that asks a few questions about the plugin you want to create and sets you up with the proper boilerplate

Let me know if you'd like the Peril issues to belong to a different epic instead, or any feedback you have on this proposed change.

@jlengstorf
Copy link
Contributor Author

@shannonbux The CLI stuff is captured in #6729, so I don't think that needs to be added to anyone's work.

The README template looks great. I think you can close that out.

I think the other organization you're suggesting looks good, too. Feel free to move things around and close this out. Thanks!

@shannonbux
Copy link
Contributor

Ok, all those suggestions are implemented now, @jlengstorf! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation An issue or pull request for improving or updating Gatsby's documentation
Projects
None yet
Development

No branches or pull requests

5 participants