<commit_before>require 'tempfile'
require 'compiler/compiler'
require 'childprocess'
require 'typescript'

module Compiler
  class TypeScript < Compiler
    BASE_DIR = File.expand_path(File.dirname(__FILE__))

    def compile(file_path)
      compile_with_child_process(file_path) # TODO: switch
    end

    private
    def compile_with_child_process(file_path)
      io_in, io_out = IO.pipe
      Process.waitpid(spawn(build_command(file_path), [:out, :err] => io_out))
      io_out.close
      {message: io_in.read, status: $?.exitstatus.zero? ? :success : :error}
    end
    def build_command(file_path)
      command = "tsc "
      command << case @options[:root_script]
                 when String
                   "#{@options.root_script} "
                 else
                   "#{file_path} "
                 end
      command << case @options[:out]
                 when String
                   "--out #{@options.out}"
                 else
                   ""
                 end<commit_msg>add compiler options to Guard's options<commit_after>require 'tempfile'
require 'compiler/compiler'
require 'childprocess'
require 'typescript'

module Compiler
  class TypeScript < Compiler
    BASE_DIR = File.expand_path(File.dirname(__FILE__))

    def compile(file_path)
      compile_with_child_process(file_path) # TODO: switch
    end

    private
    def compile_with_child_process(file_path)
      io_in, io_out = IO.pipe
      Process.waitpid(spawn(build_command(file_path), [:out, :err] => io_out))
      io_out.close
      {message: io_in.read, status: $?.exitstatus.zero? ? :success : :error}
    end
    def build_command(file_path)
      command = "tsc "
      command << case @options[:root_script]
                 when String
                   "#{@options.root_script} "
                 else
                   "#{file_path} "
                 end
      command << case @options[:out]
                 when String
                   "--out #{@options.out}"
                 else
                   ""
                 end
      command << " #{@options[:compile_options]}" if @options[:compile_options]
{'fraction_non_alphanumeric': 0.10299625468164794, 'fraction_numerical': 0.0, 'mean_word_length': 2.0098591549295777, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7289409', 'n_tokens_mistral': 618, 'n_tokens_neox': 606, 'n_words': 130}