Gruntfile.coffee 4.0 KB

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