0.1.1 • Published 3 years ago

@macdeluck/typescript-estree-cli v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

typescript-estree-cli

Cli tool for generating AST from typescript source files. Based on typescript-eslint.

Installation

npm install --save-dev @macdeluck/typescript-estree-cli

or install as global tool:

npm install -g @macdeluck/typescript-estree-cli

or use one of standalone downloads.

Example

Assuming having following src/file.ts file:

class Test {}

tool can generate following file.ts.json

// Note: Generated output is not pretty-formatted, it is rather single-line JSON
[
  {
    "sourceFileName": "src/file.ts",
    "body": [
      {
        "type": "ClassDeclaration",
        "id": {
          "type": "Identifier",
          "name": "Test"
        },
        "body": {
          "type": "ClassBody",
          "body": []
        },
        "superClass": null
      }
    ]
  }
]

Scenarios

Generating AST for single file (or multiple files)

typescript-estree-cli path/to/your/file.ts
typescript-estree-cli path/to/your/file1.ts path/to/your/file2.ts

Generating AST for all files *.ts from src directory and subdirectories

typescript-estree-cli src/**/*.ts

Options

  • --outFile - output all AST to specific file
  • --outDir - output AST to specific dir
  • --printOutput - prints generated file names to standard output

Usage

NPM global tool

typescript-estree-cli path/to/your/file.ts --outFile=file.ts.json

NPM package script

Add to package.json (scripts section):

{
  "scripts": {
    "build:ast": "typescript-estree-cli path/to/your/file.ts --outFile=file.ts.json"
  }
}

And run with:

npm run build:ast

Using NodeJS

node ./typescript-estree-cli.js path/to/your/file.ts --outDir=file.ast.json

Windows

.\typescript-estree-cli.exe path/to/your/file.ts --outDir=file.ast.json

Linux

./typescript-estree-cli path/to/your/file.ts --outDir=file.ast.json

MacOS

./typescript-estree-cli path/to/your/file.ts --outDir=file.ast.json