How can I compile TypeScript within a JavaScript app?

I have a build.js file which, as you may have guessed, builds my project. This file aims to:

  • Compile .ts files and place them into a new directory.
  • Create an asar containing the compiled files.

Because typescript (tsc) is an NPM package, I figured I might be able to use it inside of a JavaScript file, in the same way I can use the asar package. I was right; I can use the typescript package as a regular Node.JS module, however, I do not know how to use it, and ESLint doesn’t help me out too much.

Here’s my current build.js:

const typescript = require("typescript");

I cannot find any documentation for this, all I want to do is replicate what tsc . would do.