You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a fairly complex build process which I've written using Node scripts, and somewhere in there I need to run the TypeScript compiler. Almost all of my build tools have a JS API which mean I can run them easily, e.g:
var uglify = require("uglify-js");
uglify.minify(...);
But I'm struggling to do the same for TypeScript. Is there a way to do this? I'm using tsconfig.json files so I only want to do the equivalent of (ran from the command line):
tsc -p my-project
I did have some luck with getting this working with child_process.spawn but this seems to rely on me having a global install of TypeScript, and I'd rather not to make that assumption...
Mohamed Hegazy (@mhegazy) - Thanks, but I'm strugging to see how to run this and have it act in the same way as the tsconfig.json-driven tsc tool. I'm hoping to just do the equivalent of giving it the '-p' argument - i.e. the directory with my tsconfig.json file, and then just have the compiler do it's thing. Is that possible?
Activity
davidreher commentedon Jan 7, 2016
What we are doing in our project is simply calling the tsc from node_modules/.bin folder or create an npm script (which implicitly works inside the node_modules/.bin folder) and call that
mhegazy commentedon Jan 7, 2016
you can use the typescript compiler api, just like you use uglify today.
var ts = require("typescript");. here is more information on the API https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-APIarfmann commentedon Jan 7, 2016
Mohamed Hegazy (@mhegazy) - Thanks, but I'm strugging to see how to run this and have it act in the same way as the tsconfig.json-driven
tsctool. I'm hoping to just do the equivalent of giving it the '-p' argument - i.e. the directory with my tsconfig.json file, and then just have the compiler do it's thing. Is that possible?mhegazy commentedon Jan 7, 2016
here you go:
to run this:
arfmann commentedon Jan 7, 2016
This is incredibly useful! Thanks very much.
I'm stuck using plain [node-friendly] JavaScript for this, so I've converted it in case anyone else happens to be in the same boat.
leftyftw commentedon Feb 10, 2017
arfmann Did you adapt this yourself for free use by others? I'd like to use it in a project, but have to ensure copyright compliance.
jamiewinder commentedon Feb 10, 2017
Jaime Torres (@leftyftw) - yes, it's a straight adaptation of what mhegazy posted, and I don't claim any rights to it. :)