typescript文档化工具——Typedoc

发布时间:2019-08-10 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了typescript文档化工具——Typedoc脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

TyPEdoc

简介:

Typedoc 是一个 TypeScript 语言的文档生成工具,类比 jsdoc。

构建出来的项目api网页样例:http://typedoc.org/api/global...

Typedoc 参考链接:
http://typedoc.org/
https://github.com/Microsoft/...
@L_360_5@

名称    作用    备注
@param    参数描述    仅供类、接口、方法注释时使用。同一个注释块可同时出现多个param描述。
@return    返回描述    仅供方法注释时使用。除void方法外其它所有方法必须有一个return描述。
@throws    异常描述    零到多个。
@exception    异常描述    零到多个。
@author    作者    类和接口注释中必须有。可有零到多个。
@version    版本描述    类和接口注释中必须有。零或一个。
@see    参考描述    可有零到多个。
@since    起始版本    只有一个。
@serial    序列化描述    或@serialField@serialData,可有多个
@dePRecated    废除标志    最多一个。

项目使用

这个可归属到
https://segmentfault.com/a/11...

1.安装模块

npm i -D gulp typedoc gulp-typedoc

2.创建 gulp配置文件

在项目根目录下创建 gulp配置文件gulpfile.js

VAR gulp = require('gulp');
var typedoc = require("gulp-typedoc");
 
gulp.task("typedoc", function() {
    return gulp
        .src(["src/**/*.ts"])
        .pipe(typedoc({
            exclude:["node_modules",
                    "**/*+(index|.worker|.e2e).ts"],
            // TypeScript options (see typescript docs)
            module: "commonjs",
            target: "ES5",
            includeDeclarations: false,
 
            // Output options (see typedoc docs)
            out: "./doc",
 
            // TypeDoc options (see typedoc docs)
            name: "my-project",
            ignoreCompilerErrors: false,
            version: true,
        }))
    ;
});

src :目标文件可以填写多个
exclude :排除一些文件
out:输出的doc文件存放位置
ignoreCompilerErrors:是否忽略错误

3.生成doc

写测试代码src/math/color.ts

export class color
{
    /**
     * r通道
     */
    r:number;
    /**
     * g通道
     */
    g:number;
    /**
     * b通道
     */
    b:number;
    /**
     * a通道
     */
    a:number;
    /**
     * 红色
     */
    static readonly @R_406_2903@_color=new color(1,0,0,1);

    constructor(r:number=1,g:number,b:number=1,a:number=1)
    {
        this.r=r;
        this.g=g;
        this.b=b;
        this.a=a;
    }
    /**
     * 复制 color
     * @param From clone from
     * @returns 返回 new instanced Color
     */
    public static clone(from: color): color
    {
        let ITem=new color(from[0],from[1],from[2],from[3]);
        return item;
    }

    /**
     * Copy the values from one color to another
     *
     * @param out the receiving vector
     * @param a the source vector
     * @returns out
     */
    public static copy(a: color,out: color): color{
        out[0] = a[0];
        out[1] = a[1];
        out[2] = a[2];
        out[3] = a[3];
        return out;
    }
}

执行指令 gulp typedoc即可在目标目录生成doc文件。

typedoc使用拓展

1.typescript使用装饰器

执行gulp typedoc会报错,并导致生成doc文件失败

 Experimental support for decorators is a feature that is subject to change in a Future release. Set the 'experimentalDecorators' option to remove this warning.

在tsconfig.json中,experimentalDecorators已经设置为true

{
    "compilerOptions": {
        "module": "es6",
        "target": "es5",
        "sourceMap": true,
        "declaration": true,
        "declarationDir": "./dist/typing",
        "experimentalDecorators": true,
        "lib": [
            "webworker",
            "es6",
            "es5",
            "dom"
          ]
    },
    
    "exclude": [
        "node_moudles",
        "dist"
    ]
}

修改gulpfile.js文件中ignoreCompilerErrors 为true,即可成功生成doc文件。
备注:虽然成功生成doc文件,但是上面的报错依旧存在,有人知道怎么解决,请可以留言。

var gulp = require('gulp');
var typedoc = require("gulp-typedoc");
 
gulp.task("typedoc", function() {
    return gulp
        .src(["src/**/*.ts"])
        .pipe(typedoc({
            exclude:["node_modules",
                    "**/*+(index|.worker|.e2e).ts"],
            // TypeScript options (see typescript docs)
            module: "commonjs",
            target: "es5",
            includeDeclarations: false,
 
            // Output options (see typedoc docs)
            out: "./doc",
 
            // TypeDoc options (see typedoc docs)
            name: "my-project",
            ignoreCompilerErrors: true,
            version: true,
        }))
    ;
});

2.给function写 指导代码

参考下面的写法

/**
 * 复制 color
 * @param from clone from
 * @returns 返回 new instanced Color
* ```
* let a_color=color.clone(color.Red);
* ```
 */
public static clone(from: color): color
{
    let item=new color(from[0],from[1],from[2],from[3]);
    return item;
}

脚本宝典总结

以上是脚本宝典为你收集整理的typescript文档化工具——Typedoc全部内容,希望文章能够帮你解决typescript文档化工具——Typedoc所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。