npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

brighterscript-jsdocs-plugin

v0.7.3

Published

Plugin For JSDoc that converts Brighterscript files into comments compatible with JSDoc

Downloads

369

Readme

What is this?

Plugin For JSDoc that converts Roku's BrightScriptDoc comments into comments compatible with JSDoc.

Especially designed to work with both Brightscript and Brighterscript.

Automatically pulls in function/sub name and param and return types. Can be overridden with more info as desired (description, param type override or param description). Automatically bases module off of file name but can be changed and used to combine multiple files into one module. Module is automatically applied to each sub/function in that file.

How To View Example Docs

git clone https://github.com/markwpearce/brighterscript-jsdocs-plugin.git
cd brighterscript-jsdocs-plugin
npm install
npm run docs

Docs are output in docs folder.

Installation

  1. Install via NPM
npm install brighterscript-jsdocs-plugin --save-dev

I recommend using a custom template. I like https://github.com/braintree/jsdoc-template:

npm install braintree-jsdoc-template --save-dev
  1. Configure

Create a ./jsdoc.json configuration file - https://jsdoc.app/about-configuring-jsdoc.html.

Example:

{
    "plugins": [
        "plugins/markdown",
        "./node_modules/brighterscript-jsdocs-plugin/convert-brighterscript-docs.js"
    ],
    "source": {
        "include": [
            "src" // directories with .bs/.brs files
        ],
        "includePattern": ".+\\.br?s$"
    },
    "opts": {
        "recurse": true,
        "template": "node_modules/clean-jsdoc-theme", // or whatever template you've chosen - see below
        "brighterscript-jsdocs-plugin": {
            "addModule": true, // true by default - should we generate module names based on the file names?
            "escapeHTMLCharacters": true // true by default - should we escape html characters (<>/&") in comments?
        }
    }
}

Note: If you are using Brighterscript Namespaces, they override any @module setting in the code.

  1. Add a script to package.json like:
  "scripts": {
    "docs": "./node_modules/.bin/jsdoc -c jsdoc.json -d docs"
  }

Options

You can add these options to the jsdoc.json file under opts.brighterscript-jsdocs-plugin

addModule : Boolean (true/false) - Should we generate module names based on the file names? - defaults to true

escapeHTMLCharacters : Boolean (true/false) - Should we escape html characters (<>/&"') in comments? - defaults to true

Generating Documentation

Run the script to generate documentation! (Documentation is put in the ./docs/ folder)

npm run docs

Templates

The default JSDocs template may not meet your needs. Here's a good list of templates that are available:

https://cancerberosgx.github.io/jsdoc-templates-demo/demo/

I recommend clean-jsdoc-theme

Brightscript and Brighterscript

Internally, this plugin uses the Brighterscript parser. Brighterscript is a superset of Roku's Brightscript language, so plain old .brs files should be parsed properly.

Writing Documentation

If you have used BrightScriptDoc formatting for documentation, most comments should be parsed properly

Basic tags for functions and classes should work: @param, @return, etc. As this is a plugin for jsdoc, other tags that are included in the comments are passed through to jsdoc for interpretation.

It is not necessary to wrap BrightScript comments in javascript style comments, but the plugin should handle either situation.

These comments will be parsed the same:

' Give the maximum of two numbers
' @param {integer} x - the first number
' @param {integer} y - the second number
' @return {integer} the max of x and y
function maxBrsStyle(x, y)
  if x > y
    return x
  end if
  return y
end function

' /**
'  * Give the maximum of two numbers
'  * @param {integer} x - the first number
'  * @param {integer} y - the second number
'  * @return {integer} the max of x and y
' */
function maxJsStyle(x, y)
  if x > y
    return x
  end if
  return y
end function

Example

' Namespace for testing
namespace TestBsDoc

  ' Test Brighterscript class
  class TestBsKlass

    prop as float = 1

    ' I like eating pie
    someField as float = 3.14

    ' Constructor
    '@param {string} name for this Class
    function new(name as string) as void
      m.name = name
    end function

    ' Capitalizes a word
    ' @param {string} the word to capitalize
    ' @return the capitalized word
    function capitalize(word as string) as string
      return ucase(word)
    end function

    ' Says hi to the given name
    function sayHello() as string
      return "hi " + m.name
    end function
  end class

end namespace