Module: Ronin::Payloads::Mixins::TypeScript

Defined in:
lib/ronin/payloads/mixins/typescript.rb

Overview

A mixin for compiling TypeScript into JavaScript.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(payload_class) ⇒ Object

Adds the tsc param to the payload class.

Parameters:



46
47
48
49
50
# File 'lib/ronin/payloads/mixins/typescript.rb', line 46

def self.included(payload_class)
  payload_class.param :tsc, required: true,
                            default:  -> { tsc },
                            desc:     'The TypeScript compiler to use'
end

.tscString

The default tsc compiler.

Returns:

  • (String)


36
37
38
# File 'lib/ronin/payloads/mixins/typescript.rb', line 36

def self.tsc
  ENV['TSC'] || 'tsc'
end

Instance Method Details

#compile_ts(*source_files) ⇒ Object Also known as: compile

Compiles one or more source files.

Parameters:

  • source_files (Array<String>)

    The source files to compile.

Raises:

  • (BuildFailed)

    The tsc command failed or is not installed.

Since:

  • 0.2.0



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ronin/payloads/mixins/typescript.rb', line 63

def compile_ts(*source_files)
  args = [params[:tsc]]
  args.concat(source_files)

  case system(*args)
  when false
    raise(BuildFailed,"tsc command failed: #{args.join(' ')}")
  when nil
    raise(BuildFailed,"tsc command not installed")
  end
end