Clean and update build output more intelligently

Fixes #183.
I know in the TypeScript compiler's version of `getCommonDirectoryPath`, it normalizes the case before checking if it's a `.d.ts` file (i.e. it's a case-insensitive comparison), which was what made me think to do this generally.