Gruntfile.coffee 5.5 KB

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