All Articles

A Note on a Makefile for Easily Running TypeScript Compilation and JS File Deletion in Bulk

This page has been machine-translated from the original page.

Have you ever wanted to compile all TypeScript files in a directory at once or delete the compiled JS files before pushing to GitHub?

This time, I am sharing a note on the Makefile script I use to achieve that.
The script I use is as follows.

clear is the script that deletes all JavaScript files under the src directory.
Also, ts_compile is the script that compiles all TypeScript files under the src directory.

SHELL=/bin/bash

clear:
-find src/ -name *.js -exec rm {} \;

ts_compile:
-find src/ -name *.ts -exec tsc {} \;

By having find pass the filenames it finds to exec, if no target files are found, the command is skipped without raising an error.

Summary

That is the Makefile script I use in a TypeScript environment.