Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jlieske/183507b305338559c95623b3d67e33a0 to your computer and use it in GitHub Desktop.

Select an option

Save jlieske/183507b305338559c95623b3d67e33a0 to your computer and use it in GitHub Desktop.
Script for BBEdit to perform check of JavaScript program using TypeScript compiler.
local theFileAlias, theFilePath, theDirectoryPath, runCheck, extractErrors, exportPath, bbresults
-- Get the file path of the front document.
tell application "BBEdit"
set theFileAlias to (file of active document of front window)
end tell
set theFilePath to POSIX path of theFileAlias
-- Run the check command from the document's directory.
set theDirectoryPath to do shell script "dirname " & quoted form of theFilePath
-- The command line to check syntax.
set runCheck to "/usr/local/bin/tsc --noEmit --allowJs --checkJs --target es2018 --module esnext " & (quoted form of theFilePath)
-- PCRE expression to extract file and line from error output.
set extractErrors to "(?P<file>.+?)\\((?P<line>\\d+),(?P<col>\\d+)\\):\\s+(?P<msg>.*)$"
-- Set up the path to find the node runner, needed by the tsc wrapper script.
set exportPath to "export PATH=\"$PATH:/usr/local/bin\""
set bbresults to "/usr/local/bin/bbresults -p '" & extractErrors & "'"
do shell script exportPath & "; cd " & (quoted form of theDirectoryPath) & " && " & runCheck & " 2>&1 | " & bbresults
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment