Support different versions of sharelatex repos

This commit is contained in:
James Allen 2014-08-19 13:14:47 +01:00
parent 009781c33b
commit 34ae84a5fa

View file

@ -11,30 +11,39 @@ async = require "async"
SERVICES = [{ SERVICES = [{
name: "web" name: "web"
repo: "https://github.com/sharelatex/web-sharelatex.git" repo: "https://github.com/sharelatex/web-sharelatex.git"
version: "master"
}, { }, {
name: "document-updater" name: "document-updater"
repo: "https://github.com/sharelatex/document-updater-sharelatex.git" repo: "https://github.com/sharelatex/document-updater-sharelatex.git"
version: "master"
}, { }, {
name: "clsi" name: "clsi"
repo: "https://github.com/sharelatex/clsi-sharelatex.git" repo: "https://github.com/sharelatex/clsi-sharelatex.git"
version: "master"
}, { }, {
name: "filestore" name: "filestore"
repo: "https://github.com/sharelatex/filestore-sharelatex.git" repo: "https://github.com/sharelatex/filestore-sharelatex.git"
version: "master"
}, { }, {
name: "track-changes" name: "track-changes"
repo: "https://github.com/sharelatex/track-changes-sharelatex.git" repo: "https://github.com/sharelatex/track-changes-sharelatex.git"
version: "master"
}, { }, {
name: "docstore" name: "docstore"
repo: "https://github.com/sharelatex/docstore-sharelatex.git" repo: "https://github.com/sharelatex/docstore-sharelatex.git"
version: "master"
}, { }, {
name: "chat" name: "chat"
repo: "https://github.com/sharelatex/chat-sharelatex.git" repo: "https://github.com/sharelatex/chat-sharelatex.git"
version: "master"
}, { }, {
name: "tags" name: "tags"
repo: "https://github.com/sharelatex/tags-sharelatex.git" repo: "https://github.com/sharelatex/tags-sharelatex.git"
version: "master"
}, { }, {
name: "spelling" name: "spelling"
repo: "https://github.com/sharelatex/spelling-sharelatex.git" repo: "https://github.com/sharelatex/spelling-sharelatex.git"
version: "master"
}] }]
module.exports = (grunt) -> module.exports = (grunt) ->
@ -86,10 +95,10 @@ module.exports = (grunt) ->
do (service) -> do (service) ->
grunt.registerTask "install:#{service.name}", "Download and set up the #{service.name} service", () -> grunt.registerTask "install:#{service.name}", "Download and set up the #{service.name} service", () ->
done = @async() done = @async()
Helpers.installService(service.repo, service.name, done) Helpers.installService(service, done)
grunt.registerTask "update:#{service.name}", "Checkout and update the #{service.name} service", () -> grunt.registerTask "update:#{service.name}", "Checkout and update the #{service.name} service", () ->
done = @async() done = @async()
Helpers.updateService(service.name, done) Helpers.updateService(service, done)
grunt.registerTask "run:#{service.name}", "Run the ShareLaTeX #{service.name} service", ["bunyan", "execute:#{service.name}"] grunt.registerTask "run:#{service.name}", "Run the ShareLaTeX #{service.name} service", ["bunyan", "execute:#{service.name}"]
grunt.registerTask 'install:config', "Copy the example config into the real config", () -> grunt.registerTask 'install:config', "Copy the example config into the real config", () ->
@ -133,41 +142,50 @@ module.exports = (grunt) ->
Helpers = Helpers =
installService: (repo_src, dir, callback = (error) ->) -> installService: (service, callback = (error) ->) ->
Helpers.cloneGitRepo repo_src, dir, (error) -> Helpers.cloneGitRepo service, (error) ->
return callback(error) if error? return callback(error) if error?
Helpers.installNpmModules dir, (error) -> Helpers.installNpmModules service, (error) ->
return callback(error) if error? return callback(error) if error?
Helpers.runGruntInstall dir, (error) -> Helpers.runGruntInstall service, (error) ->
return callback(error) if error? return callback(error) if error?
callback() callback()
updateService: (dir, callback = (error) ->) -> updateService: (service, callback = (error) ->) ->
Helpers.updateGitRepo dir, (error) -> Helpers.updateGitRepo service, (error) ->
return callback(error) if error? return callback(error) if error?
Helpers.installNpmModules dir, (error) -> Helpers.installNpmModules service, (error) ->
return callback(error) if error? return callback(error) if error?
Helpers.runGruntInstall dir, (error) -> Helpers.runGruntInstall service, (error) ->
return callback(error) if error? return callback(error) if error?
callback() callback()
cloneGitRepo: (repo_src, dir, callback = (error) ->) -> cloneGitRepo: (service, callback = (error) ->) ->
repo_src = service.repo
dir = service.name
if !fs.existsSync(dir) if !fs.existsSync(dir)
proc = spawn "git", ["clone", repo_src, dir], stdio: "inherit" proc = spawn "git", [
"clone",
"-b", service.version,
repo_src,
dir
], stdio: "inherit"
proc.on "close", () -> proc.on "close", () ->
callback() callback()
else else
console.log "#{dir} already installed, skipping." console.log "#{dir} already installed, skipping."
callback() callback()
updateGitRepo: (dir, callback = (error) ->) -> updateGitRepo: (service, callback = (error) ->) ->
proc = spawn "git", ["checkout", "master"], cwd: dir, stdio: "inherit" dir = service.name
proc = spawn "git", ["checkout", service.version], cwd: dir, stdio: "inherit"
proc.on "close", () -> proc.on "close", () ->
proc = spawn "git", ["pull"], cwd: dir, stdio: "inherit" proc = spawn "git", ["pull"], cwd: dir, stdio: "inherit"
proc.on "close", () -> proc.on "close", () ->
callback() callback()
installNpmModules: (dir, callback = (error) ->) -> installNpmModules: (service, callback = (error) ->) ->
dir = service.name
proc = spawn "npm", ["install"], stdio: "inherit", cwd: dir proc = spawn "npm", ["install"], stdio: "inherit", cwd: dir
proc.on "close", () -> proc.on "close", () ->
callback() callback()