2014-02-12 05:21:20 -05:00
|
|
|
fs = require "fs"
|
|
|
|
spawn = require("child_process").spawn
|
2014-02-12 07:11:58 -05:00
|
|
|
rimraf = require "rimraf"
|
2014-02-12 07:15:47 -05:00
|
|
|
Path = require "path"
|
2014-02-12 05:21:20 -05:00
|
|
|
|
2014-02-12 06:18:25 -05:00
|
|
|
SERVICES = [{
|
|
|
|
name: "web"
|
|
|
|
repo: "git@github.com:sharelatex/web-sharelatex.git"
|
|
|
|
}, {
|
|
|
|
name: "document-updater"
|
|
|
|
repo: "git@github.com:sharelatex/document-updater-sharelatex.git"
|
2014-02-13 07:37:47 -05:00
|
|
|
}, {
|
|
|
|
name: "clsi"
|
|
|
|
repo: "git@github.com:sharelatex/clsi-sharelatex.git"
|
2014-02-14 12:30:43 -05:00
|
|
|
}, {
|
|
|
|
name: "filestore"
|
|
|
|
repo: "git@github.com:sharelatex/filestore-sharelatex.git"
|
2014-02-12 06:18:25 -05:00
|
|
|
}]
|
2014-02-12 05:21:20 -05:00
|
|
|
|
|
|
|
|
2014-02-08 09:44:47 -05:00
|
|
|
module.exports = (grunt) ->
|
|
|
|
grunt.loadNpmTasks 'grunt-bunyan'
|
|
|
|
grunt.loadNpmTasks 'grunt-execute'
|
|
|
|
grunt.loadNpmTasks 'grunt-available-tasks'
|
|
|
|
grunt.loadNpmTasks 'grunt-concurrent'
|
|
|
|
|
2014-02-13 07:37:47 -05:00
|
|
|
execute = {}
|
|
|
|
for service in SERVICES
|
|
|
|
execute[service.name] =
|
|
|
|
src: "#{service.name}/app.js"
|
|
|
|
|
2014-02-08 09:44:47 -05:00
|
|
|
grunt.initConfig
|
2014-02-13 07:37:47 -05:00
|
|
|
execute: execute
|
2014-02-08 09:44:47 -05:00
|
|
|
|
|
|
|
concurrent:
|
|
|
|
all:
|
2014-02-13 07:37:47 -05:00
|
|
|
tasks: ("run:#{service.name}" for service in SERVICES)
|
2014-02-08 09:44:47 -05:00
|
|
|
options:
|
2014-02-13 07:37:47 -05:00
|
|
|
limit: SERVICES.length
|
2014-02-08 09:44:47 -05:00
|
|
|
logConcurrentOutput: true
|
|
|
|
|
|
|
|
availabletasks:
|
|
|
|
tasks:
|
|
|
|
options:
|
2014-02-12 05:21:20 -05:00
|
|
|
filter: 'exclude',
|
|
|
|
tasks: [
|
|
|
|
'concurrent'
|
|
|
|
'execute'
|
|
|
|
'bunyan'
|
|
|
|
'availabletasks'
|
|
|
|
]
|
|
|
|
groups:
|
|
|
|
"Run tasks": [
|
|
|
|
"run"
|
|
|
|
"run:all"
|
|
|
|
"default"
|
2014-02-13 07:37:47 -05:00
|
|
|
].concat ("run:#{service.name}" for service in SERVICES)
|
2014-02-12 05:21:20 -05:00
|
|
|
"Misc": [
|
|
|
|
"help"
|
|
|
|
]
|
2014-02-12 07:11:58 -05:00
|
|
|
"Install tasks": ("install:#{service.name}" for service in SERVICES).concat(["install:all", "install"])
|
|
|
|
"Update tasks": ("update:#{service.name}" for service in SERVICES).concat(["update:all", "update"])
|
|
|
|
"Config tasks": ["install:config"]
|
2014-02-08 09:44:47 -05:00
|
|
|
|
2014-02-12 06:18:25 -05:00
|
|
|
for service in SERVICES
|
|
|
|
do (service) ->
|
|
|
|
grunt.registerTask "install:#{service.name}", "Download and set up the #{service.name} service", () ->
|
|
|
|
done = @async()
|
|
|
|
Helpers.installService(service.repo, service.name, done)
|
|
|
|
grunt.registerTask "update:#{service.name}", "Checkout and update the #{service.name} service", () ->
|
|
|
|
done = @async()
|
|
|
|
Helpers.updateService(service.name, done)
|
2014-02-12 07:15:47 -05:00
|
|
|
grunt.registerTask "run:#{service.name}", "Run the ShareLaTeX #{service.name} service", ["bunyan", "execute:#{service.name}"]
|
2014-02-12 06:18:25 -05:00
|
|
|
|
|
|
|
grunt.registerTask 'install:all', "Download and set up all ShareLaTeX services", ("install:#{service.name}" for service in SERVICES)
|
2014-02-12 06:24:13 -05:00
|
|
|
grunt.registerTask 'install', 'install:all'
|
2014-02-12 06:18:25 -05:00
|
|
|
grunt.registerTask 'update:all', "Checkout and update all ShareLaTeX services", ("update:#{service.name}" for service in SERVICES)
|
2014-02-12 06:24:13 -05:00
|
|
|
grunt.registerTask 'update', 'update:all'
|
2014-02-08 09:44:47 -05:00
|
|
|
grunt.registerTask 'run', "Run all of the sharelatex processes", ['concurrent:all']
|
2014-02-08 16:52:45 -05:00
|
|
|
grunt.registerTask 'run:all', 'run'
|
2014-02-08 09:44:47 -05:00
|
|
|
|
2014-02-12 07:11:58 -05:00
|
|
|
grunt.registerTask 'install:config', "Install a custom config from a git repository (set SHARELATEX_CONFIG_REPO to the repository location)", () ->
|
|
|
|
Helpers.installCustomConfig @async()
|
|
|
|
|
2014-02-12 06:24:13 -05:00
|
|
|
grunt.registerTask 'help', 'Display this help list', 'availabletasks'
|
2014-02-08 09:44:47 -05:00
|
|
|
grunt.registerTask 'default', 'run'
|
|
|
|
|
2014-02-12 05:21:20 -05:00
|
|
|
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()
|
2014-02-12 07:11:58 -05:00
|
|
|
|
|
|
|
installCustomConfig: (callback = (error) ->) ->
|
|
|
|
if !process.env.SHARELATEX_CONFIG_REPO?
|
|
|
|
return callback(new Error("Please set the SHARELATEX_CONFIG_REPO enviroment variable to point to a git repository."))
|
|
|
|
|
|
|
|
rimraf "config-local", (error) ->
|
|
|
|
Helpers.cloneGitRepo process.env.SHARELATEX_CONFIG_REPO, "config-local", (error) ->
|
|
|
|
return callback(error) if error?
|
|
|
|
for file in fs.readdirSync("config-local")
|
|
|
|
unless file == ".git"
|
2014-02-12 07:15:47 -05:00
|
|
|
fs.symlinkSync(Path.resolve("config-local/#{file}"), "config/#{file}")
|
2014-02-12 07:11:58 -05:00
|
|
|
callback()
|