Gruntfile.coffee 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. plans:
  67. files:
  68. "public/stylesheets/plans.css": "public/stylesheets/less/plans.less"
  69. requirejs:
  70. compile:
  71. options:
  72. appDir: "public/js"
  73. baseUrl: "./"
  74. dir: "public/minjs"
  75. inlineText: false
  76. preserveLicenseComments: false
  77. paths:
  78. "underscore": "libs/underscore"
  79. "jquery": "libs/jquery"
  80. shim:
  81. "libs/backbone":
  82. deps: ["libs/underscore"]
  83. "libs/pdfListView/PdfListView":
  84. deps: ["libs/pdf"]
  85. "libs/pdf":
  86. deps: ["libs/compatibility"]
  87. skipDirOptimize: true
  88. modules: [
  89. {
  90. name: "main",
  91. exclude: ["jquery"]
  92. }, {
  93. name: "ide",
  94. exclude: ["jquery"]
  95. }, {
  96. name: "home",
  97. exclude: ["jquery"]
  98. }, {
  99. name: "list",
  100. exclude: ["jquery"]
  101. }
  102. ]
  103. clean:
  104. app: ["app/js"]
  105. unit_tests: ["test/UnitTests/js"]
  106. mochaTest:
  107. unit:
  108. src: ["test/UnitTests/js/#{grunt.option('feature') or '**'}/*.js"]
  109. options:
  110. reporter: grunt.option('reporter') or 'spec'
  111. grep: grunt.option("grep")
  112. smoke:
  113. src: ['test/smoke/js/**/*.js']
  114. options:
  115. reporter: grunt.option('reporter') or 'spec'
  116. grep: grunt.option("grep")
  117. availabletasks:
  118. tasks:
  119. options:
  120. filter: 'exclude',
  121. tasks: [
  122. 'coffee'
  123. 'less'
  124. 'clean'
  125. 'mochaTest'
  126. 'availabletasks'
  127. 'wrap_sharejs'
  128. 'requirejs'
  129. 'execute'
  130. 'bunyan'
  131. ]
  132. groups:
  133. "Compile tasks": [
  134. "compile:server"
  135. "compile:client"
  136. "compile:tests"
  137. "compile"
  138. "compile:unit_tests"
  139. "compile:smoke_tests"
  140. "compile:css"
  141. "compile:minify"
  142. "install"
  143. ]
  144. "Test tasks": [
  145. "test:unit"
  146. ]
  147. "Run tasks": [
  148. "run"
  149. "default"
  150. ]
  151. "Misc": [
  152. "help"
  153. ]
  154. grunt.registerTask 'wrap_sharejs', 'Wrap the compiled ShareJS code for AMD module loading', () ->
  155. content = fs.readFileSync "public/js/libs/sharejs.js"
  156. fs.writeFileSync "public/js/libs/sharejs.js", """
  157. define(["ace/range"], function() {
  158. #{content}
  159. return window.sharejs;
  160. });
  161. """
  162. grunt.registerTask 'help', 'Display this help list', 'availabletasks'
  163. grunt.registerTask 'compile:server', 'Compile the server side coffee script', ['clean:app', 'coffee:app', 'coffee:app_dir']
  164. grunt.registerTask 'compile:client', 'Compile the client side coffee script', ['coffee:client', 'coffee:sharejs', 'wrap_sharejs']
  165. grunt.registerTask 'compile:css', 'Compile the less files to css', ['less']
  166. grunt.registerTask 'compile:minify', 'Concat and minify the client side js', ['requirejs']
  167. grunt.registerTask 'compile:unit_tests', 'Compile the unit tests', ['clean:unit_tests', 'coffee:unit_tests']
  168. grunt.registerTask 'compile:smoke_tests', 'Compile the smoke tests', ['coffee:smoke_tests']
  169. grunt.registerTask 'compile:tests', 'Compile all the tests', ['compile:smoke_tests', 'compile:unit_tests']
  170. grunt.registerTask 'compile', 'Compiles everything need to run web-sharelatex', ['compile:server', 'compile:client', 'compile:css']
  171. grunt.registerTask 'install', "Compile everything when installing as an npm module", ['compile']
  172. grunt.registerTask 'test:unit', 'Run the unit tests (use --grep=<regex> or --feature=<feature> for individual tests)', ['compile:server', 'compile:unit_tests', 'mochaTest:unit']
  173. grunt.registerTask 'test:smoke', 'Run the smoke tests', ['compile:smoke_tests', 'mochaTest:smoke']
  174. grunt.registerTask 'run', "Compile and run the web-sharelatex server", ['compile', 'bunyan', 'execute']
  175. grunt.registerTask 'default', 'run'