Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 7c0f4d1e9b
Fetching contributors…

Cannot retrieve contributors at this time

file 115 lines (85 sloc) 2.847 kb
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
require 'rake'
require 'rake/clean'
require 'rake/rdoctask'
require 'rake/testtask'

CLEAN.include 'test/unit/tmp'
CLOBBER.include 'dist'
CLOBBER.include 'doc'

WYSIHAT_ROOT = File.expand_path(File.dirname(__FILE__))
WYSIHAT_SRC_DIR = File.join(WYSIHAT_ROOT, 'src')


# Distribution

file 'dist/prototype.js' => :sprockets do |t|
  prototype_src_dir = "#{WYSIHAT_ROOT}/vendor/prototype/src"

  secretary = Sprockets::Secretary.new(
    :root => prototype_src_dir,
    :load_path => [prototype_src_dir],
    :source_files => ["prototype.js"]
  )

  FileUtils.mkdir_p File.dirname(t.name)
  secretary.concatenation.save_to(t.name)
end

file 'dist/wysihat.js' => Dir['src/**/*'] + [:sprockets] do |t|
  secretary = Sprockets::Secretary.new(
    :root => WYSIHAT_SRC_DIR,
    :load_path => [WYSIHAT_SRC_DIR],
    :source_files => ["wysihat.js"]
  )

  FileUtils.mkdir_p File.dirname(t.name)
  secretary.concatenation.save_to(t.name)
end

task :default => :dist

desc "Builds the distribution."
task :dist => ['dist/prototype.js', 'dist/wysihat.js']


# Documentation

desc "Builds the documentation."
file 'doc' => Dir['src/**/*'] + [:sprockets, :pdoc] do
  require 'tempfile'

  Tempfile.open('pdoc') do |temp|
    secretary = Sprockets::Secretary.new(
      :root => WYSIHAT_SRC_DIR,
      :load_path => [WYSIHAT_SRC_DIR],
      :source_files => ["wysihat.js"],
      :strip_comments => false
    )

    secretary.concatenation.save_to(temp.path)
    PDoc::Runner.new(temp.path, :destination => "#{WYSIHAT_ROOT}/doc").run
  end
end


# Tests

file 'test/unit/tmp/tests' => Dir['test/unit/*.js'] + [:unittest_js, :dist] do
  FileUtils.mkdir_p File.dirname('test/unit/tmp/tests')

  builder = UnittestJS::Builder::SuiteBuilder.new({
    :input_dir => "#{WYSIHAT_ROOT}/test/unit",
    :assets_dir => "#{WYSIHAT_ROOT}/dist"
  })
  builder.collect
  builder.render
end

desc "Builds the distribution, runs the JavaScript unit tests and collects their results."
task :test => 'test/unit/tmp/tests'


# Vendored libs

task :sprockets => 'vendor/sprockets/lib/sprockets.rb' do
  $:.unshift File.expand_path('vendor/sprockets/lib', WYSIHAT_ROOT)
  require 'sprockets'
end

task :pdoc => 'vendor/pdoc/lib/pdoc.rb' do
  $:.unshift File.expand_path('vendor/pdoc/lib', WYSIHAT_ROOT)
  require 'pdoc'
end

task :unittest_js => 'vendor/unittest_js/lib/unittest_js.rb' do
  $:.unshift File.expand_path('vendor/unittest_js/lib', WYSIHAT_ROOT)
  require 'unittest_js'
end

file 'vendor/pdoc/lib/pdoc.rb' do
  Rake::Task['update_submodules'].invoke
end

file 'vendor/sprockets/lib/sprockets.rb' do
  Rake::Task['update_submodules'].invoke
end

file 'vendor/unittest_js/lib/unittest_js.rb' do
  Rake::Task['update_submodules'].invoke
end

task :update_submodules do
  system "git submodule init"
  system "git submodule update"
end
Something went wrong with that request. Please try again.