-
Notifications
You must be signed in to change notification settings - Fork 5
/
build
executable file
·61 lines (45 loc) · 1.4 KB
/
build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#! /usr/bin/env ruby
require 'babel/transpiler'
require 'rake'
require 'optparse'
# A simple script to transpile our source ES6 in src/javascripts to standard ES5
# javascript in app/assets/javascripts/session_timeout_prompter.js
TARGET_JS_PATH = "#{File.dirname(__FILE__)}/app/assets/javascripts/session_timeout_prompter.js"
SRC_DIRECTORY = "#{File.dirname(__FILE__)}/src/javascripts"
options = {}
option_parser = OptionParser.new do |opts|
opts.banner = "Usage: build [options]"
opts.on("-j", "--jasmine", "Run Jasmine tests only") do |v|
options[:jasmine_only] = v
end
opts.on("-r", "--rspec", "Run RSpec tests only") do |v|
options[:rspec_only] = v
end
opts.on("-h", "--help", "Show help") do |v|
options[:help] = v
end
end
option_parser.parse!
if options[:help]
puts option_parser.help()
else
es6_files_to_transpile = Dir.glob("#{SRC_DIRECTORY}/**/*.es6")
File.open TARGET_JS_PATH, 'w' do |output_file|
es6_files_to_transpile.each do |es6_file_path|
puts "Transpiling #{es6_file_path}..."
transpiled_es6 = Babel::Transpiler.transform File.read(es6_file_path)
output_file.puts transpiled_es6['code']
end
end
app = Rake.application
app.init
app.load_rakefile
unless options[:rspec_only]
puts "Running Jasmine..."
app['jasmine:ci'].invoke
end
unless options[:jasmine_only]
puts "Running RSpec..."
app['spec'].invoke
end
end