Gruntfile.coffee 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. fs = require "fs"
  2. exec = require("child_process").exec
  3. spawn = require("child_process").spawn
  4. SERVICES = [{
  5. name: "web"
  6. repo: "git@github.com:sharelatex/web-sharelatex.git"
  7. }, {
  8. name: "document-updater"
  9. repo: "git@github.com:sharelatex/document-updater-sharelatex.git"
  10. }]
  11. module.exports = (grunt) ->
  12. grunt.loadNpmTasks 'grunt-bunyan'
  13. grunt.loadNpmTasks 'grunt-execute'
  14. grunt.loadNpmTasks 'grunt-available-tasks'
  15. grunt.loadNpmTasks 'grunt-concurrent'
  16. grunt.initConfig
  17. execute:
  18. web:
  19. src: "web/app.js"
  20. 'document-updater':
  21. src: "document-updater/app.js"
  22. concurrent:
  23. all:
  24. tasks: ['run:web', 'run:document-updater']
  25. options:
  26. logConcurrentOutput: true
  27. availabletasks:
  28. tasks:
  29. options:
  30. filter: 'exclude',
  31. tasks: [
  32. 'concurrent'
  33. 'execute'
  34. 'bunyan'
  35. 'availabletasks'
  36. ]
  37. groups:
  38. "Run tasks": [
  39. "run"
  40. "run:all"
  41. "run:web"
  42. "run:document-updater"
  43. "default"
  44. ]
  45. "Misc": [
  46. "help"
  47. ]
  48. "Install tasks": ("install:#{service.name}" for service in SERVICES).concat("install:all")
  49. "Update tasks": ("update:#{service.name}" for service in SERVICES).concat("update:all")
  50. for service in SERVICES
  51. do (service) ->
  52. grunt.registerTask "install:#{service.name}", "Download and set up the #{service.name} service", () ->
  53. done = @async()
  54. Helpers.installService(service.repo, service.name, done)
  55. grunt.registerTask "update:#{service.name}", "Checkout and update the #{service.name} service", () ->
  56. done = @async()
  57. Helpers.updateService(service.name, done)
  58. grunt.registerTask 'install:all', "Download and set up all ShareLaTeX services", ("install:#{service.name}" for service in SERVICES)
  59. grunt.registerTask 'update:all', "Checkout and update all ShareLaTeX services", ("update:#{service.name}" for service in SERVICES)
  60. grunt.registerTask 'help', 'Display this help list', 'availabletasks'
  61. grunt.registerTask 'run:web', "Run web-sharelatex, the ShareLaTeX web server", ["bunyan", "execute:web"]
  62. grunt.registerTask 'run:document-updater', "Run document-updater-sharelatex, the real-time document server", ["bunyan", "execute:document-updater"]
  63. grunt.registerTask 'run', "Run all of the sharelatex processes", ['concurrent:all']
  64. grunt.registerTask 'run:all', 'run'
  65. grunt.registerTask 'default', 'run'
  66. Helpers =
  67. installService: (repo_src, dir, callback = (error) ->) ->
  68. Helpers.cloneGitRepo repo_src, dir, (error) ->
  69. return callback(error) if error?
  70. Helpers.installNpmModules dir, (error) ->
  71. return callback(error) if error?
  72. Helpers.runGruntInstall dir, (error) ->
  73. return callback(error) if error?
  74. callback()
  75. updateService: (dir, callback = (error) ->) ->
  76. Helpers.updateGitRepo dir, (error) ->
  77. return callback(error) if error?
  78. Helpers.installNpmModules dir, (error) ->
  79. return callback(error) if error?
  80. Helpers.runGruntInstall dir, (error) ->
  81. return callback(error) if error?
  82. callback()
  83. cloneGitRepo: (repo_src, dir, callback = (error) ->) ->
  84. if !fs.existsSync(dir)
  85. proc = spawn "git", ["clone", repo_src, dir], stdio: "inherit"
  86. proc.on "close", () ->
  87. callback()
  88. else
  89. console.log "#{dir} already installed, skipping."
  90. callback()
  91. updateGitRepo: (dir, callback = (error) ->) ->
  92. proc = spawn "git", ["checkout", "master"], cwd: dir, stdio: "inherit"
  93. proc.on "close", () ->
  94. proc = spawn "git", ["pull"], cwd: dir, stdio: "inherit"
  95. proc.on "close", () ->
  96. callback()
  97. installNpmModules: (dir, callback = (error) ->) ->
  98. proc = spawn "npm", ["install"], stdio: "inherit", cwd: dir
  99. proc.on "close", () ->
  100. callback()
  101. runGruntInstall: (dir, callback = (error) ->) ->
  102. proc = spawn "grunt", ["install"], stdio: "inherit", cwd: dir
  103. proc.on "close", () ->
  104. callback()