3

I have a TypeScript project that contains a couple other file types that I need to transpile as part of the build process. I can create an NPM script like tsc && other-tool, which works but once you have 3 or 4 tools setup like this the NPM script can start to become a bit complicated. I would like to step things up a bit and create an actual build script (e.g., build.js). I am not to the point where I need some heavyweight build infrastructure like gulp, just a simple .js script with a few lines.

However, I cannot figure out how to turn tsc at the command line (which uses a tsconfig.json for compilation) into a nodejs function call. How can I call tsc from within a nodejs script? I would strongly prefer to not just shell out to TSC CLI, as it seems crazy to me to shell out to a JS script from within a JS script instead of just calling the JS script directly.

Micah Zoltu
  • 6,764
  • 5
  • 44
  • 72
  • 2
    https://github.com/Microsoft/TypeScript/issues/6387 – Roberto Zvjerković Mar 22 '19 at 11:07
  • @ritaj It is unfortunate that it is that complicated, happen to have any idea to emulate the `--watch` option using that strategy? – Micah Zoltu Mar 24 '19 at 06:43
  • Maybe with [spawn](https://nodejs.org/docs/latest-v10.x/api/child_process.html#child_process_child_process_spawn_command_args_options) or [exec](https://nodejs.org/docs/latest-v10.x/api/child_process.html#child_process_child_process_exec_command_options_callback). Maybe it would be also possible to [fork](https://nodejs.org/docs/latest-v10.x/api/child_process.html#child_process_child_process_fork_modulepath_args_options), and to call: `require("typescript/lib/tsc.js")` in the child process. – Paleo Mar 24 '19 at 08:34

0 Answers0