项目作者: chialab

项目描述 :
A d.ts and documentation generator for TypeScript and JavaScript projects.
高级语言: TypeScript
项目地址: git://github.com/chialab/dts-apigen.git
创建时间: 2019-04-05T15:50:40Z
项目社区:https://github.com/chialab/dts-apigen

开源协议:MIT License

下载


DTS ApiGen



Source link


Authors link


NPM


License

A .d.ts and documentation generator for TypeScript and JavaScript projects.

⚠️ Please note that DTS ApiGen is still in beta and not production ready.

Why

TypeScript is a powerful tool, but at the moment of writing, it prevents declaration files generation for JavaScript files.

This tool aims to offer a set of utils to generate .d.ts files starting from JS modules using JSDoc (checkout the supported tags list) to fill typings informations. It also provides a method to generate a single bundled declaration, useful for JS libraries and Api documentation.

Usage

Via CLI

DTS ApiGen is available as a CLI tool installing the module via NPM or Yarn:

  1. $ npm install -g dts-apigen
  2. # OR
  3. $ yarn global add dts-apigen
  1. $ dts-apigen --help
  2. Usage: dts-apigen [options] [command]
  3. Options:
  4. -V, --version output the version number
  5. -h, --help output usage information
  6. Commands:
  7. generate [options] <file> Generate declaration files
  8. bundle [options] <file> Bundle all declaration files into a single .d.ts file
  9. documentate [options] <file> Generate an API documentation markdown file

The generate command creates declaration files along your source files, unless a declarationDir has been specified in the tsconfig.json or the --out option has been used:

  1. $ dts-apigen generate src/index.js --out types/

You can also build a single .d.ts file running:

  1. $ dts-apigen bundle src/index.js --out typings.d.ts

The documentate command generates a bundle of the project on the fly and passes the typescript SourceFile result to a template function (by default it uses the built-in markdown generator):

  1. $ dts-apign documentate src/index.js --out docs/API.md

Via Node

Install the package as Node dependency to use it programmatically:

  1. $ npm install dts-apigen -D
  2. # OR
  3. $ yarn add dts-apigen -D

DTS ApiGen extends the TypeScript createProgram method and accepts all its options, as well as other custom transformers.

  1. const { generate, bundle } = require('dts-apigen');
  2. const { writeFileSync } = require('fs');
  3. const { createPrinter } = require('typescript');
  4. const result = generate(['src/index.js'], {
  5. declarationDir: 'types',
  6. });
  7. console.log(result.diagnostic);
  8. // generate the bundle file
  9. const sourceFile = bundle('src/index.js');
  10. const code = createPrinter().printFile(resultFile);
  11. writeFileSync('bundle.d.ts', code);

You can find the API documentation (generated with dts-apigen, of course) in the API.md file.

Supported tags

Partially supported tags


License

DTS ApiGen is released under the MIT license.