begin require 'bundler/setup' rescue LoadError puts 'You must `gem install bundler` and `bundle install` to run rake tasks' end require 'rdoc/task' RDoc::Task.new(:rdoc) do |rdoc| rdoc.rdoc_dir = 'rdoc' rdoc.title = 'Fiona7' rdoc.options << '--line-numbers' rdoc.rdoc_files.include('README.rdoc') rdoc.rdoc_files.include('lib/**/*.rb') end namespace "package" do desc "Package javascript" task "js" do puts "Transpiling javascript files" require 'babel/transpiler' Dir["app/**/*"].each do |fname| if /\.es6\.js$/ =~ fname nfname = ::File.join(::File.dirname(fname), ::File.basename(fname, '.es6.js') + '.js') puts "#{fname} -> #{nfname}" ::File.open(nfname, 'w') do |f| f.write Babel::Transpiler.transform(File.read(fname))["code"] end end end end end namespace "clean" do desc "Clean packaged javascript" task "js" do puts "Cleaning transpiled javascript files" Dir["app/**/*"].each do |fname| if /\.es6\.js$/ =~ fname nfname = ::File.join(::File.dirname(fname), ::File.basename(fname, '.es6.js') + '.js') puts "#{nfname}" ::FileUtils.rm(nfname) if ::File.exists?(nfname) end end end end task "build" => ["clean:js", "package:js"] do # dummy, needed for dependencies, the rest is added later by bundler end Bundler::GemHelper.install_tasks