• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

[Tools]APIExtractorSetupforTypescript

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

https://github.com/mike-north/professional-ts/blob/master/notes/04-mikes-ts-setup.md#api-surface-report--docs

Install:

yarn add -D @microsoft/api-extractor @microsoft/api-documenter   

 

Step1:

yarn api-extractor init

It creates api-extractor.json file.

 

Step2:

Since output build output folder is "dist". In api-extractor.json file:

"mainEntryPointFilePath": "<projectFolder>/dist/index.d.ts",

 

Step3:

Find "dtsRollup", enable:

  "dtsRollup": {
    /**
     * (REQUIRED) Whether to generate the .d.ts rollup file.
     */
    "enabled": true,

    /**
     * Specifies the output path for a .d.ts rollup file to be generated without any trimming.
     * This file will include all declarations that are exported by the main entry point.
     *
     * If the path is an empty string, then this file will not be written.
     *
     * The path is resolved relative to the folder of the config file that contains the setting; to change this,
     * prepend a folder token such as "<projectFolder>".
     *
     * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
     * DEFAULT VALUE: "<projectFolder>/dist/<unscopedPackageName>.d.ts"
     */
     "untrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>-private.d.ts",

    /**
     * Specifies the output path for a .d.ts rollup file to be generated with trimming for a "beta" release.
     * This file will include only declarations that are marked as "@public" or "@beta".
     *
     * The path is resolved relative to the folder of the config file that contains the setting; to change this,
     * prepend a folder token such as "<projectFolder>".
     *
     * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
     * DEFAULT VALUE: ""
     */
    "betaTrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>-beta.d.ts",

    /**
     * Specifies the output path for a .d.ts rollup file to be generated with trimming for a "public" release.
     * This file will include only declarations that are marked as "@public".
     *
     * If the path is an empty string, then this file will not be written.
     *
     * The path is resolved relative to the folder of the config file that contains the setting; to change this,
     * prepend a folder token such as "<projectFolder>".
     *
     * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
     * DEFAULT VALUE: ""
     */
    "publicTrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>.d.ts"

    /**
     * When a declaration is trimmed, by default it will be replaced by a code comment such as
     * "Excluded from this release type: exampleMember".  Set "omitTrimmingComments" to true to remove the
     * declaration completely.
     *
     * DEFAULT VALUE: false
     */
    // "omitTrimmingComments": true
  },

 

Step4:

mkdir etc

 

Step5: Build your typescript project:

src/index.ts:

/**
 * @packageDocumentation A small library for common math functions
 */

/**
 * Calculate the average of three numbers
 *
 * @param a - first number
 * @param b - second number
 * @param c - third number
 *
 * @public
 */
export function avg(a: number, b: number, c: number): number {
    return sum3(a, b, c) / 3;
  }

  /**
   * Calculate the sum of three numbers
   *
   * @param a - first number
   * @param b - second number
   * @param c - third number
   *
   * @beta
   */
  export function sum3(a: number, b: number, c: number): number {
    return sum2(a, sum2(b, c));
  }

  /**
   * Calculate the sum of two numbers
   *
   * @param a - first number
   * @param b - second number
   *
   * @internal
   */
  export function sum2(a: number, b: number): number {
    const sum = a + b;
    return sum;
  }

Run:

yarn build

 

Step6: Run

yarn api-extractor run --local

Difference between run with "--local" and without. 

When you run with "--local": it means I want to udpate all the definiations. It should be a new standard. 

When without "--lcoal", it compares "etc" folder, seeing whether anything has changed, if changed, throw error. Which aims to protect our API should be changed without notice. 

 

Step7: add 'temp' folder to .gitignore:

 

Step8: Run documenter:

yarn api-documenter markdown -i temp -o docs

 

Setp9: 

Setup Github docs:


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Vue+TypeScript学习发布时间:2022-07-18
下一篇:
为什么转向TypeScript发布时间:2022-07-18
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap