rakefile.rb 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. namespace "run" do
  2. end
  3. namespace "test" do
  4. desc "Run the unit tests"
  5. task :unit => ["compile:unittests"] do
  6. puts "Running unit tests"
  7. featurePath = ENV['feature']
  8. puts featurePath
  9. if featurePath.nil?
  10. featurePath = ''
  11. elsif featurePath.include? '/'
  12. elsif !featurePath.include? '/'
  13. featurePath +='/'
  14. else
  15. featurePath = ''
  16. end
  17. runner = ENV['MOCHA_RUNNER'] || "spec"
  18. sh %{mocha -R #{runner} test/unit/js/#{featurePath}* --ignore-leaks} do |ok, res|
  19. if ! ok
  20. raise "error running unit tests : #{res}"
  21. end
  22. end
  23. end
  24. end
  25. namespace "compile" do
  26. desc "Compile server and client coffeescript files"
  27. task :app => ["compile:serverApp", "compile:clientApp"]
  28. desc "Compile the main serverside app folder"
  29. task :serverApp do
  30. puts "Compiling app"
  31. sh %{coffee -o app/js/ -c app/coffee/} do |ok, res|
  32. if ! ok
  33. raise "error compiling app folder: #{res}"
  34. end
  35. puts 'Finished server app compile'
  36. end
  37. sh %{coffee -c app.coffee} do |ok, res|
  38. if ! ok
  39. raise "error compiling app file: #{res}"
  40. end
  41. puts 'Finished app.coffee compile'
  42. end
  43. end
  44. desc "Compile the main client app folder"
  45. task :clientApp do
  46. puts "Compiling client app"
  47. sh %{coffee -o public/js/ -c public/coffee/} do |ok, res|
  48. if ! ok
  49. raise "error compiling client app folder: #{res}"
  50. end
  51. end
  52. sh %{mkdir -p public/js/html}
  53. sh %{mkdir -p public/js/css}
  54. sh %{jade < public/jade/templates.jade > public/js/html/templates.html} do |ok, res|
  55. if !ok
  56. raise "error compiling jade templates: #{res}"
  57. end
  58. end
  59. sh %{lessc - < public/less/chat.less > public/js/css/chat.css} do |ok, res|
  60. if !ok
  61. raise "error compiling css: #{res}"
  62. end
  63. end
  64. end
  65. desc "compress the js"
  66. task :compressAndCompileJs do
  67. sh %{node public/js/r.js -o public/app.build.js} do |ok, res|
  68. if ! ok
  69. raise "error compiling client app folder: #{res}"
  70. end
  71. end
  72. puts "Finished client app compile"
  73. end
  74. desc "Compile the unit tests folder"
  75. task :unittests => ["compile:serverApp"] do
  76. puts "Compiling Unit Tests to JS"
  77. sh %{coffee -c -o test/unit/js/ test/unit/coffee/} do |ok, res|
  78. if ! ok
  79. raise "error compiling Unit tests : #{res}"
  80. end
  81. end
  82. end
  83. end
  84. namespace 'bootstrap' do
  85. desc "Creates a new Feature and module, and corresponding test framework file"
  86. task :feature, :feature_name, :module_name do |task, args|
  87. feature_name = args[:feature_name]
  88. module_name = args[:module_name]
  89. FileUtils.mkdir_p("app/coffee/Features/#{feature_name}")
  90. File.open("app/coffee/Features/#{feature_name}/#{module_name}.coffee", "w") { |f|
  91. f.write(<<-EOS
  92. module.exports = #{module_name} =
  93. EOS
  94. )
  95. }
  96. FileUtils.mkdir_p("test/unit/coffee/#{feature_name}")
  97. File.open("test/unit/coffee/#{feature_name}/#{module_name}Tests.coffee", "w") { |f|
  98. f.write(<<-EOS
  99. sinon = require('sinon')
  100. chai = require('chai')
  101. should = chai.should()
  102. expect = chai.expect
  103. modulePath = "../../../../app/js/Features/#{feature_name}/#{module_name}.js"
  104. SandboxedModule = require('sandboxed-module')
  105. events = require "events"
  106. describe "#{module_name}", ->
  107. beforeEach ->
  108. @#{module_name} = SandboxedModule.require modulePath, requires:
  109. EOS
  110. )
  111. }
  112. end
  113. end