I have a build.js file which, as you may have guessed, builds my project. This file aims to:
.ts files and place them into a new directory.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.
EDIT: I do not want to use child_process, because it creates new issues, especially when it comes to cross-compatibility and safety.
You can use child process to spawn a shell and run the tsc command or use the exec() to spawn the shell first then run the command
https://www.geeksforgeeks.org/node-js-child-process/
You can achieve this with something like
const { exec } = require('child_process');
exec('tsc', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(stdout);
if (stderr!= "")
console.error(`stderr: ${stderr}`);
});