Question

ternJS have several. JSON files defs which contains the definition of librarys. Can someone explain to me how I can best generate my own to my javascript libraries / or only definition objects?

I can not see that there is no common procedure for this?

Was it helpful?

Solution

There's a tool for this included in Tern. See condense at http://ternjs.net/doc/manual.html#utils . It runs Tern on your file and tries to output the types that it finds. It's far from flawless, but for simple programs it works well. For files with a complicated structure or interface, you'll often have to hand-write the definitions.

OTHER TIPS

There are three ways I have thought about to solve your problem:

Using Abstract Syntax Tree Parser and Visitor

One way to solve your problem would be to use abstract syntax tree parser and visitor in order to automate the task of scanning through the code and documenting it.

The resources here will be of help:

-http://ramkulkarni.com/blog/understanding-ast-created-by-mozilla-rhino-parser/ -What is JavaScript AST, how to play with it?

You usually use a parser to retrieve a tree, and then use a visitor to visit all the nodes and do your work within there.

You will essentially have a tree representing the specific library and then you must write the code to store this in the def format you link to.

Getting a Documentation Generator and Modifying

Another idea is to download the source code for a documentation generator, e.g. https://github.com/yui/yuidoc/

By modifying the styling/output format you can generate "documentation" in the appropriate json format.

Converting Existing Documentation (HTML doc) into JSON

You can make a parser that takes a standard documentation format (I'm sure as Javadoc is one for java there should be one for javascript), and write a converter that exctracts the relevant information and stores in a JSON definition.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top