Skip to content

Instantly share code, notes, and snippets.



Last active Jul 20, 2017
What would you like to do?

Generating a Tern.js defs file for p5.js


p5 source code --> YUIDoc JSON --> Tern defs JSON


Because p5.js uses YUIDoc to generate documentation, I'm using @angelozerr's tern.yuidoc plugin to generate a Tern.js defs file for p5.js. Ultimately, this will be used to implement code hints and autocomplete in the p5.js web editor.

  1. Get the p5.js API JSON file from the p5 website, here. Learn more about the p5.js API JSON file here.
  2. Then, get the Tern defs generator. Clone @angelozerr's repo with $ git clone
  3. Skip to the second set of instructions, here.
  4. The output is a Tern defs file from YUIDoc's data.json file.

Errors in p5.js source that break the tern.yuidoc generator

This error required working with the p5 source code directly. If you end up here, you can make the needed changes to the source code and output the API JSON file yourself like this:

  1. Follow the steps for getting set up with p5 development here
  2. When you run grunt, the API JSON file will be one of the outputs. You can find it in p5.js/docs/reference; it's called data.json.

Errors with the generated defs file

The last two on this list were upstream problems with YUIDoc type definitions in the p5 source. If the p5 web editor loads but you get Tern defs-related errors in the console, YUIDoc type definitions seem to be the best place to start looking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment