Gruntfile.coffee 5.7 KB

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