Jun 12, 2024

TSC to file checklist

When doing a big upgrade on a Typescript project, keeping track of your tsc output can be difficult. To get a list of files in a markdown checklist, you can dump your tsc output to a file, and run this script on that file, and it’ll give you a markdown list of the files you need to go through, one on one.

Notes:

  • This excludes any .spec files.
  • This is usable with vue-tsc or any other tsc extension
js
1const fs = require('fs') 2const errorsFile = '~/file-of-errors.txt' 3const outputFile = './errorFiles.md' 4const errorsString = fs.readFileSync(errorsFile, 'utf8') 5const errorsArrayExcludeStrings = ['>', 'spec', 'ELIFECYCLE'] 6const errorsArray = errorsString.split('\n').filter(error => !error.startsWith(' ') && error !== '' && !errorsArrayExcludeStrings.some(s => error.includes(s))) 7const duplicatedFilesArray = errorsArray.map((error) => { 8 const errorParts = error.split('(') 9 const output = `[ ] ${errorParts[0]}` 10 return output 11}) 12const files = [...new Set(duplicatedFilesArray)].sort().sort((a,_b) => a.endsWith('.ts') ? 1 : -1) 13fs.writeFileSync(outputFile, files.join('\n')) 14console.log(`${errorsArray.length} errors across ${files.length} files remaining. 15Output: ${outputFile}`)