Gruntfile.coffee 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. fs = require "fs"
  2. module.exports = (grunt) ->
  3. grunt.loadNpmTasks 'grunt-contrib-coffee'
  4. grunt.loadNpmTasks 'grunt-contrib-less'
  5. grunt.loadNpmTasks 'grunt-contrib-clean'
  6. grunt.loadNpmTasks 'grunt-mocha-test'
  7. grunt.loadNpmTasks 'grunt-available-tasks'
  8. grunt.loadNpmTasks 'grunt-contrib-requirejs'
  9. grunt.loadNpmTasks 'grunt-execute'
  10. grunt.loadNpmTasks 'grunt-bunyan'
  11. grunt.initConfig
  12. execute:
  13. app:
  14. src: "app.js"
  15. coffee:
  16. app_dir:
  17. expand: true,
  18. flatten: false,
  19. cwd: 'app/coffee',
  20. src: ['**/*.coffee'],
  21. dest: 'app/js/',
  22. ext: '.js'
  23. app:
  24. src: 'app.coffee'
  25. dest: 'app.js'
  26. sharejs:
  27. options:
  28. join: true
  29. files:
  30. "public/js/libs/sharejs.js": [
  31. "public/coffee/editor/ShareJSHeader.coffee"
  32. "public/coffee/editor/sharejs/types/helpers.coffee"
  33. "public/coffee/editor/sharejs/types/text.coffee"
  34. "public/coffee/editor/sharejs/types/text-api.coffee"
  35. "public/coffee/editor/sharejs/types/json.coffee"
  36. "public/coffee/editor/sharejs/types/json-api.coffee"
  37. "public/coffee/editor/sharejs/client/microevent.coffee"
  38. "public/coffee/editor/sharejs/client/doc.coffee"
  39. "public/coffee/editor/sharejs/client/ace.coffee"
  40. ]
  41. client:
  42. expand: true,
  43. flatten: false,
  44. cwd: 'public/coffee',
  45. src: ['**/*.coffee'],
  46. dest: 'public/js/',
  47. ext: '.js'
  48. smoke_tests:
  49. expand: true,
  50. flatten: false,
  51. cwd: 'test/smoke/coffee',
  52. src: ['**/*.coffee'],
  53. dest: 'test/smoke/js/',
  54. ext: '.js'
  55. unit_tests:
  56. expand: true,
  57. flatten: false,
  58. cwd: 'test/UnitTests/coffee',
  59. src: ['**/*.coffee'],
  60. dest: 'test/UnitTests/js/',
  61. ext: '.js'
  62. less:
  63. app:
  64. files:
  65. "public/stylesheets/mainStyle.css": "public/stylesheets/mainStyle.less"
  66. requirejs:
  67. compile:
  68. options:
  69. appDir: "public/js"
  70. baseUrl: "./"
  71. dir: "public/minjs"
  72. inlineText: false
  73. preserveLicenseComments: false
  74. paths:
  75. "underscore": "libs/underscore"
  76. "jquery": "libs/jquery"
  77. shim:
  78. "libs/backbone":
  79. deps: ["libs/underscore"]
  80. "libs/pdfListView/PdfListView":
  81. deps: ["libs/pdf"]
  82. "libs/pdf":
  83. deps: ["libs/compatibility"]
  84. skipDirOptimize: true
  85. modules: [
  86. {
  87. name: "main",
  88. exclude: ["jquery"]
  89. }, {
  90. name: "ide",
  91. exclude: ["jquery"]
  92. }, {
  93. name: "home",
  94. exclude: ["jquery"]
  95. }, {
  96. name: "list",
  97. exclude: ["jquery"]
  98. }
  99. ]
  100. clean:
  101. app: ["app/js"]
  102. unit_tests: ["test/UnitTests/js"]
  103. mochaTest:
  104. unit:
  105. src: ["test/UnitTests/js/#{grunt.option('feature') or '**'}/*.js"]
  106. options:
  107. reporter: grunt.option('reporter') or 'spec'
  108. grep: grunt.option("grep")
  109. smoke:
  110. src: ['test/smoke/js/**/*.js']
  111. options:
  112. reporter: grunt.option('reporter') or 'spec'
  113. grep: grunt.option("grep")
  114. availabletasks:
  115. tasks:
  116. options:
  117. filter: 'exclude',
  118. tasks: [
  119. 'coffee'
  120. 'less'
  121. 'clean'
  122. 'mochaTest'
  123. 'availabletasks'
  124. 'wrap_sharejs'
  125. 'requirejs'
  126. 'execute'
  127. 'bunyan'
  128. ]
  129. groups:
  130. "Compile tasks": [
  131. "compile:server"
  132. "compile:client"
  133. "compile:tests"
  134. "compile"
  135. "compile:unit_tests"
  136. "compile:smoke_tests"
  137. "compile:css"
  138. "compile:minify"
  139. "install"
  140. ]
  141. "Test tasks": [
  142. "test:unit"
  143. ]
  144. "Run tasks": [
  145. "run"
  146. "default"
  147. ]
  148. "Misc": [
  149. "help"
  150. ]
  151. grunt.registerTask 'wrap_sharejs', 'Wrap the compiled ShareJS code for AMD module loading', () ->
  152. content = fs.readFileSync "public/js/libs/sharejs.js"
  153. fs.writeFileSync "public/js/libs/sharejs.js", """
  154. define(["ace/range"], function() {
  155. #{content}
  156. return window.sharejs;
  157. });
  158. """
  159. grunt.registerTask 'help', 'Display this help list', 'availabletasks'
  160. grunt.registerTask 'compile:server', 'Compile the server side coffee script', ['clean:app', 'coffee:app', 'coffee:app_dir']
  161. grunt.registerTask 'compile:client', 'Compile the client side coffee script', ['coffee:client', 'coffee:sharejs', 'wrap_sharejs']
  162. grunt.registerTask 'compile:css', 'Compile the less files to css', ['less']
  163. grunt.registerTask 'compile:minify', 'Concat and minify the client side js', ['requirejs']
  164. grunt.registerTask 'compile:unit_tests', 'Compile the unit tests', ['clean:unit_tests', 'coffee:unit_tests']
  165. grunt.registerTask 'compile:smoke_tests', 'Compile the smoke tests', ['coffee:smoke_tests']
  166. grunt.registerTask 'compile:tests', 'Compile all the tests', ['compile:smoke_tests', 'compile:unit_tests']
  167. grunt.registerTask 'compile', 'Compiles everything need to run web-sharelatex', ['compile:server', 'compile:client', 'compile:css']
  168. grunt.registerTask 'install', "Compile everything when installing as an npm module", ['compile']
  169. grunt.registerTask 'test:unit', 'Run the unit tests (use --grep=<regex> or --feature=<feature> for individual tests)', ['compile:server', 'compile:unit_tests', 'mochaTest:unit']
  170. grunt.registerTask 'test:smoke', 'Run the smoke tests', ['compile:smoke_tests', 'mochaTest:smoke']
  171. grunt.registerTask 'run', "Compile and run the web-sharelatex server", ['compile', 'bunyan', 'execute']
  172. grunt.registerTask 'default', 'run'