0.1.1 • Published 4 years ago
@macdeluck/typescript-estree-cli v0.1.1
typescript-estree-cli
Cli tool for generating AST from typescript source files. Based on typescript-eslint.
Installation
npm install --save-dev @macdeluck/typescript-estree-clior install as global tool:
npm install -g @macdeluck/typescript-estree-clior 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.tsGenerating AST for all files *.ts from src directory and subdirectories
typescript-estree-cli src/**/*.tsOptions
--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.jsonNPM 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:astUsing NodeJS
node ./typescript-estree-cli.js path/to/your/file.ts --outDir=file.ast.jsonWindows
.\typescript-estree-cli.exe path/to/your/file.ts --outDir=file.ast.jsonLinux
./typescript-estree-cli path/to/your/file.ts --outDir=file.ast.jsonMacOS
./typescript-estree-cli path/to/your/file.ts --outDir=file.ast.json