|
|
@@ -1,3 +1,11 @@
|
|
|
+fs = require "fs"
|
|
|
+exec = require("child_process").exec
|
|
|
+spawn = require("child_process").spawn
|
|
|
+
|
|
|
+WEB_REPO = "git@bitbucket.org:sharelatex/web-sharelatex.git"
|
|
|
+DOC_UPDATER_REPO = "git@bitbucket.org:sharelatex/documentupdater-sharelatex.git"
|
|
|
+
|
|
|
+
|
|
|
module.exports = (grunt) ->
|
|
|
grunt.loadNpmTasks 'grunt-bunyan'
|
|
|
grunt.loadNpmTasks 'grunt-execute'
|
|
|
@@ -7,9 +15,9 @@ module.exports = (grunt) ->
|
|
|
grunt.initConfig
|
|
|
execute:
|
|
|
web:
|
|
|
- src: "node_modules/web-sharelatex/app.js"
|
|
|
+ src: "web/app.js"
|
|
|
'document-updater':
|
|
|
- src: "node_modules/document-updater-sharelatex/app.js"
|
|
|
+ src: "document-updater/app.js"
|
|
|
|
|
|
concurrent:
|
|
|
all:
|
|
|
@@ -20,25 +28,39 @@ module.exports = (grunt) ->
|
|
|
availabletasks:
|
|
|
tasks:
|
|
|
options:
|
|
|
- filter: 'exclude',
|
|
|
- tasks: [
|
|
|
- 'concurrent'
|
|
|
- 'execute'
|
|
|
- 'bunyan'
|
|
|
- 'availabletasks'
|
|
|
- ]
|
|
|
- groups:
|
|
|
- "Run tasks": [
|
|
|
- "run"
|
|
|
- "run:all"
|
|
|
- "run:web"
|
|
|
- "run:document-updater"
|
|
|
- "default"
|
|
|
- ]
|
|
|
- "Misc": [
|
|
|
- "help"
|
|
|
- ]
|
|
|
+ filter: 'exclude',
|
|
|
+ tasks: [
|
|
|
+ 'concurrent'
|
|
|
+ 'execute'
|
|
|
+ 'bunyan'
|
|
|
+ 'availabletasks'
|
|
|
+ ]
|
|
|
+ groups:
|
|
|
+ "Run tasks": [
|
|
|
+ "run"
|
|
|
+ "run:all"
|
|
|
+ "run:web"
|
|
|
+ "run:document-updater"
|
|
|
+ "default"
|
|
|
+ ]
|
|
|
+ "Misc": [
|
|
|
+ "help"
|
|
|
+ ]
|
|
|
|
|
|
+ grunt.registerTask 'install:web', "Download and set up the web-sharelatex service", () ->
|
|
|
+ done = @async()
|
|
|
+ Helpers.installService(WEB_REPO, "web", done)
|
|
|
+ grunt.registerTask 'install:document-updater', "Download and set up the document-updater-sharelatex service", () ->
|
|
|
+ done = @async()
|
|
|
+ Helpers.installService(DOC_UPDATER_REPO, "document-updater", done)
|
|
|
+
|
|
|
+ grunt.registerTask 'update:web', "Checkout and update the web-sharelatex service", () ->
|
|
|
+ done = @async()
|
|
|
+ Helpers.updateService("web", done)
|
|
|
+ grunt.registerTask 'update:document-updater', "Checkout and update the document-updater-sharelatex service", () ->
|
|
|
+ done = @async()
|
|
|
+ Helpers.updateService("document-updater", done)
|
|
|
+
|
|
|
grunt.registerTask 'help', 'Display this help list', 'availabletasks'
|
|
|
|
|
|
grunt.registerTask 'run:web', "Run web-sharelatex, the ShareLaTeX web server", ["bunyan", "execute:web"]
|
|
|
@@ -49,3 +71,47 @@ module.exports = (grunt) ->
|
|
|
|
|
|
grunt.registerTask 'default', 'run'
|
|
|
|
|
|
+Helpers =
|
|
|
+ installService: (repo_src, dir, callback = (error) ->) ->
|
|
|
+ Helpers.cloneGitRepo repo_src, dir, (error) ->
|
|
|
+ return callback(error) if error?
|
|
|
+ Helpers.installNpmModules dir, (error) ->
|
|
|
+ return callback(error) if error?
|
|
|
+ Helpers.runGruntInstall dir, (error) ->
|
|
|
+ return callback(error) if error?
|
|
|
+ callback()
|
|
|
+
|
|
|
+ updateService: (dir, callback = (error) ->) ->
|
|
|
+ Helpers.updateGitRepo dir, (error) ->
|
|
|
+ return callback(error) if error?
|
|
|
+ Helpers.installNpmModules dir, (error) ->
|
|
|
+ return callback(error) if error?
|
|
|
+ Helpers.runGruntInstall dir, (error) ->
|
|
|
+ return callback(error) if error?
|
|
|
+ callback()
|
|
|
+
|
|
|
+ cloneGitRepo: (repo_src, dir, callback = (error) ->) ->
|
|
|
+ if !fs.existsSync(dir)
|
|
|
+ proc = spawn "git", ["clone", repo_src, dir], stdio: "inherit"
|
|
|
+ proc.on "close", () ->
|
|
|
+ callback()
|
|
|
+ else
|
|
|
+ console.log "#{dir} already installed, skipping."
|
|
|
+ callback()
|
|
|
+
|
|
|
+ updateGitRepo: (dir, callback = (error) ->) ->
|
|
|
+ proc = spawn "git", ["checkout", "master"], cwd: dir, stdio: "inherit"
|
|
|
+ proc.on "close", () ->
|
|
|
+ proc = spawn "git", ["pull"], cwd: dir, stdio: "inherit"
|
|
|
+ proc.on "close", () ->
|
|
|
+ callback()
|
|
|
+
|
|
|
+ installNpmModules: (dir, callback = (error) ->) ->
|
|
|
+ proc = spawn "npm", ["install"], stdio: "inherit", cwd: dir
|
|
|
+ proc.on "close", () ->
|
|
|
+ callback()
|
|
|
+
|
|
|
+ runGruntInstall: (dir, callback = (error) ->) ->
|
|
|
+ proc = spawn "grunt", ["install"], stdio: "inherit", cwd: dir
|
|
|
+ proc.on "close", () ->
|
|
|
+ callback()
|