1 | # ts-extractor
|
2 |
|
3 | [![NPM version](https://img.shields.io/npm/v/ts-extractor.svg)](https://www.npmjs.com/package/ts-extractor)
|
4 | [![Build Status](https://travis-ci.org/SimplrJS/ts-extractor.svg?branch=master)](https://travis-ci.org/SimplrJS/ts-extractor)
|
5 | [![Coverage Status](https://coveralls.io/repos/github/SimplrJS/ts-extractor/badge.svg?branch=master)](https://coveralls.io/github/SimplrJS/ts-extractor?branch=master)
|
6 | [![dependencies Status](https://david-dm.org/SimplrJS/ts-extractor/status.svg)](https://david-dm.org/SimplrJS/ts-extractor)
|
7 | [![devDependencies Status](https://david-dm.org/SimplrJS/ts-extractor/dev-status.svg)](https://david-dm.org/SimplrJS/ts-extractor?type=dev)
|
8 | [![devDependencies Status](https://img.shields.io/npm/l/ts-extractor.svg)](https://npmjs.org/package/ts-extractor)
|
9 |
|
10 | TypeScript AST extractor to useful JSON structure.
|
11 |
|
12 | The purpose of this package is to extract AST into flat JSON structures.
|
13 |
|
14 | Later on, it can be used for documentation generation tool, easier code analysis with without compiler, etc.
|
15 |
|
16 | ## Usage example
|
17 |
|
18 | ```ts
|
19 | import * as path from "path";
|
20 | import * as process from "process";
|
21 | import { Extractor, GetCompilerOptions } from "ts-extractor";
|
22 |
|
23 | async function Main(): Promise<void> {
|
24 | // Absolute path to projectDirectory
|
25 | const projectDirectory = process.cwd();
|
26 | const pathToTsconfig = path.join(projectDirectory, "./tsconfig.json");
|
27 |
|
28 | const compilerOptions = await GetCompilerOptions(pathToTsconfig);
|
29 |
|
30 | const extractor = new Extractor({
|
31 | CompilerOptions: compilerOptions,
|
32 | ProjectDirectory: projectDirectory
|
33 | });
|
34 |
|
35 | const extractedOutput = extractor.Extract(["./src/index.ts", "./src/another-entry-file.ts"]);
|
36 | console.log(extractedOutput);
|
37 | }
|
38 |
|
39 | Main();
|
40 | ```
|