I'm trying to write a grunt
task in a Typescript project to measure some statistics of the source files. To do that, I have a function that takes a single source file, runs typescript.createSourceFile
from it, and does some stuff to the returned AST. The problem is finding all the files to iterate over: I'd like to get exactly the same list of files that tsc -p tsconfig.json
will compile later. The intention is to filter out some files from that list and then iterate over the filtered list.
I imagine I'd use the typescript
module to do this, but I can't find a function to do it. I found the place in the tsc
source that turns tsconfig into a list of files, and it seems to be using a function that's not exported.
The TypeScript compiler compiles these files and outputs the JavaScript with . js extension by keeping the same file name as the individual input file. The TypeScript compiler also preserves the original file path, hence the . js output file will be generated where the input file was in the directory structure.
Open a terminal and run tsc -w , it'll compile any . ts file in src directory into .
The tsc command envokes the TypeScript compiler. When no command-line options are present, this command looks for the tsconfig. json file. If no tsconfig.
TypeScript is available as a package on the npm registry available as "typescript" . You will need a copy of Node. js as an environment to run the package. Then you use a dependency manager like npm, yarn or pnpm to download TypeScript into your project.
tsc --listFiles --noEmit
This will list the files that tsc will compile based on the tsconfig.json
it uses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With