Gruntfile.coffee 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. config =
  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/ide/editor/sharejs/header.coffee"
  32. "public/coffee/ide/editor/sharejs/vendor/types/helpers.coffee"
  33. "public/coffee/ide/editor/sharejs/vendor/types/text.coffee"
  34. "public/coffee/ide/editor/sharejs/vendor/types/text-api.coffee"
  35. "public/coffee/ide/editor/sharejs/vendor/client/microevent.coffee"
  36. "public/coffee/ide/editor/sharejs/vendor/client/doc.coffee"
  37. "public/coffee/ide/editor/sharejs/vendor/client/ace.coffee"
  38. ]
  39. client:
  40. expand: true,
  41. flatten: false,
  42. cwd: 'public/coffee',
  43. src: ['**/*.coffee'],
  44. dest: 'public/js/',
  45. ext: '.js'
  46. smoke_tests:
  47. expand: true,
  48. flatten: false,
  49. cwd: 'test/smoke/coffee',
  50. src: ['**/*.coffee'],
  51. dest: 'test/smoke/js/',
  52. ext: '.js'
  53. unit_tests:
  54. expand: true,
  55. flatten: false,
  56. cwd: 'test/UnitTests/coffee',
  57. src: ['**/*.coffee'],
  58. dest: 'test/UnitTests/js/',
  59. ext: '.js'
  60. less:
  61. app:
  62. files:
  63. "public/stylesheets/style.css": "public/stylesheets/style.less"
  64. requirejs:
  65. compile:
  66. options:
  67. optimize:"uglify2"
  68. uglify2:
  69. mangle: false
  70. appDir: "public/js"
  71. baseUrl: "./"
  72. dir: "public/minjs"
  73. inlineText: false
  74. preserveLicenseComments: false
  75. paths:
  76. "moment": "libs/moment-2.7.0"
  77. "mathjax": "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"
  78. shim:
  79. "libs/pdfListView/PdfListView":
  80. deps: ["libs/pdf"]
  81. "libs/pdf":
  82. deps: ["libs/compatibility"]
  83. skipDirOptimize: true
  84. modules: [
  85. {
  86. name: "main",
  87. exclude: ["libs"]
  88. }, {
  89. name: "ide",
  90. exclude: ["libs", "libs/jquery-layout"]
  91. }, {
  92. name: "libs"
  93. }
  94. ]
  95. clean:
  96. app: ["app/js"]
  97. unit_tests: ["test/UnitTests/js"]
  98. mochaTest:
  99. unit:
  100. src: ["test/UnitTests/js/#{grunt.option('feature') or '**'}/*.js"]
  101. options:
  102. reporter: grunt.option('reporter') or 'spec'
  103. grep: grunt.option("grep")
  104. smoke:
  105. src: ['test/smoke/js/**/*.js']
  106. options:
  107. reporter: grunt.option('reporter') or 'spec'
  108. grep: grunt.option("grep")
  109. availabletasks:
  110. tasks:
  111. options:
  112. filter: 'exclude',
  113. tasks: [
  114. 'coffee'
  115. 'less'
  116. 'clean'
  117. 'mochaTest'
  118. 'availabletasks'
  119. 'wrap_sharejs'
  120. 'requirejs'
  121. 'execute'
  122. 'bunyan'
  123. ]
  124. groups:
  125. "Compile tasks": [
  126. "compile:server"
  127. "compile:client"
  128. "compile:tests"
  129. "compile"
  130. "compile:unit_tests"
  131. "compile:smoke_tests"
  132. "compile:css"
  133. "compile:minify"
  134. "install"
  135. ]
  136. "Test tasks": [
  137. "test:unit"
  138. ]
  139. "Run tasks": [
  140. "run"
  141. "default"
  142. ]
  143. "Misc": [
  144. "help"
  145. ]
  146. moduleCompileServerTasks = []
  147. moduleCompileUnitTestTasks = []
  148. moduleUnitTestTasks = []
  149. moduleCompileClientTasks = []
  150. moduleIdeClientSideIncludes = []
  151. if fs.existsSync "./modules"
  152. for module in fs.readdirSync "./modules"
  153. if fs.existsSync "./modules/#{module}/index.coffee"
  154. config.coffee["module_#{module}_server"] = {
  155. expand: true,
  156. flatten: false,
  157. cwd: "modules/#{module}/app/coffee",
  158. src: ['**/*.coffee'],
  159. dest: "modules/#{module}/app/js",
  160. ext: '.js'
  161. }
  162. config.coffee["module_#{module}_index"] = {
  163. src: "modules/#{module}/index.coffee",
  164. dest: "modules/#{module}/index.js"
  165. }
  166. moduleCompileServerTasks.push "coffee:module_#{module}_server"
  167. moduleCompileServerTasks.push "coffee:module_#{module}_index"
  168. config.coffee["module_#{module}_unit_tests"] = {
  169. expand: true,
  170. flatten: false,
  171. cwd: "modules/#{module}/test/unit/coffee",
  172. src: ['**/*.coffee'],
  173. dest: "modules/#{module}/test/unit/js",
  174. ext: '.js'
  175. }
  176. config.mochaTest["module_#{module}_unit"] = {
  177. src: ["modules/#{module}/test/unit/js/*.js"]
  178. options:
  179. reporter: grunt.option('reporter') or 'spec'
  180. grep: grunt.option("grep")
  181. }
  182. moduleCompileUnitTestTasks.push "coffee:module_#{module}_unit_tests"
  183. moduleUnitTestTasks.push "mochaTest:module_#{module}_unit"
  184. config.coffee["module_#{module}_client_ide"] = {
  185. expand: true,
  186. flatten: false,
  187. cwd: "modules/#{module}/public/coffee/ide",
  188. src: ['**/*.coffee'],
  189. dest: "public/js/ide/#{module}",
  190. ext: '.js'
  191. }
  192. moduleCompileClientTasks.push "coffee:module_#{module}_client_ide"
  193. moduleIdeClientSideIncludes.push "ide/#{module}/index"
  194. grunt.initConfig config
  195. grunt.registerTask 'wrap_sharejs', 'Wrap the compiled ShareJS code for AMD module loading', () ->
  196. content = fs.readFileSync "public/js/libs/sharejs.js"
  197. fs.writeFileSync "public/js/libs/sharejs.js", """
  198. define(["ace/ace"], function() {
  199. #{content}
  200. return window.sharejs;
  201. });
  202. """
  203. grunt.registerTask 'help', 'Display this help list', 'availabletasks'
  204. grunt.registerTask 'compile:modules:server', 'Compile all the modules', moduleCompileServerTasks
  205. grunt.registerTask 'compile:modules:unit_tests', 'Compile all the modules unit tests', moduleCompileUnitTestTasks
  206. grunt.registerTask 'compile:modules:client', 'Compile all the module client side code', moduleCompileClientTasks
  207. grunt.registerTask 'compile:modules:inject_clientside_includes', () ->
  208. content = fs.readFileSync("public/js/ide.js").toString()
  209. content = content.replace(/"__IDE_CLIENTSIDE_INCLUDES__"/g, moduleIdeClientSideIncludes.map((i) -> "\"#{i}\"").join(", "))
  210. fs.writeFileSync "public/js/ide.js", content
  211. grunt.registerTask 'compile:server', 'Compile the server side coffee script', ['clean:app', 'coffee:app', 'coffee:app_dir', 'compile:modules:server']
  212. grunt.registerTask 'compile:client', 'Compile the client side coffee script', ['coffee:client', 'coffee:sharejs', 'wrap_sharejs', "compile:modules:client", 'compile:modules:inject_clientside_includes']
  213. grunt.registerTask 'compile:css', 'Compile the less files to css', ['less']
  214. grunt.registerTask 'compile:minify', 'Concat and minify the client side js', ['requirejs']
  215. grunt.registerTask 'compile:unit_tests', 'Compile the unit tests', ['clean:unit_tests', 'coffee:unit_tests']
  216. grunt.registerTask 'compile:smoke_tests', 'Compile the smoke tests', ['coffee:smoke_tests']
  217. grunt.registerTask 'compile:tests', 'Compile all the tests', ['compile:smoke_tests', 'compile:unit_tests']
  218. grunt.registerTask 'compile', 'Compiles everything need to run web-sharelatex', ['compile:server', 'compile:client', 'compile:css']
  219. grunt.registerTask 'install', "Compile everything when installing as an npm module", ['compile']
  220. grunt.registerTask 'test:unit', 'Run the unit tests (use --grep=<regex> or --feature=<feature> for individual tests)', ['compile:server', 'compile:unit_tests', 'mochaTest:unit']
  221. grunt.registerTask 'test:smoke', 'Run the smoke tests', ['compile:smoke_tests', 'mochaTest:smoke']
  222. grunt.registerTask 'test:modules:unit', 'Run the unit tests for the modules', ['compile:modules:server', 'compile:modules:unit_tests'].concat(moduleUnitTestTasks)
  223. grunt.registerTask 'run', "Compile and run the web-sharelatex server", ['compile', 'bunyan', 'execute']
  224. grunt.registerTask 'default', 'run'