简体   繁体   English

ternJS - 生成JSON类型定义文件

[英]ternJS - Generate JSON type definition file

ternJS have several. ternJS有几个。 JSON files defs which contains the definition of librarys. JSON文件defs包含librarys的定义。 Can someone explain to me how I can best generate my own to my javascript libraries / or only definition objects? 有人可以向我解释如何最好地生成我自己的javascript库/或只定义对象?

I can not see that there is no common procedure for this? 我看不出这个没有共同的程序?

There's a tool for this included in Tern. Tern中有一个工具。 See condense at http://ternjs.net/doc/manual.html#utils . 请参阅http://ternjs.net/doc/manual.html#utils上的 condense It runs Tern on your file and tries to output the types that it finds. 它在您的文件上运行Tern并尝试输出它找到的类型。 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. 对于具有复杂结构或接口的文件,您通常必须手写定义。

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? - http://ramkulkarni.com/blog/understanding-ast-created-by-mozilla-rhino-parser/ - 什么是JavaScript AST,如何玩它?

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. 您将基本上有一个表示特定库的树,然后您必须编写代码以您链接到的def格式存储它。

Getting a Documentation Generator and Modifying 获取文档生成器并进行修改

Another idea is to download the source code for a documentation generator, eg https://github.com/yui/yuidoc/ 另一个想法是下载文档生成器的源代码,例如https://github.com/yui/yuidoc/

By modifying the styling/output format you can generate "documentation" in the appropriate json format. 通过修改样式/输出格式,您可以生成适当的json格式的“文档”。

Converting Existing Documentation (HTML doc) into JSON 将现有文档(HTML doc)转换为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. 你可以创建一个采用标准文档格式的解析器(我敢肯定,因为Javadoc是java的一个,应该有一个用于javascript),并编写一个转换器,将相关信息和存储区分为JSON定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM