Gruntfile.coffee 5.5 KB

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