Gruntfile.coffee 3.5 KB

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