+ running npm and bower updates

+ starting download
This commit is contained in:
Dominik Maier 2014-06-17 01:57:26 +02:00
parent 3d2bee3256
commit d5e712eabd
4 changed files with 118 additions and 0 deletions

2
.gitignore vendored
View file

@ -86,4 +86,6 @@ login.coffee
# debugging
*.heapsnapshot
temp/
### If you add something here, copy it to the end of .npmignore, too. ###

View file

@ -95,6 +95,8 @@ bin/mongo/
# Karma coverage
coverage/
temp/
# local settings
login.coffee

31
runAfterGit.coffee Normal file
View file

@ -0,0 +1,31 @@
config = require 'server_config'
#TODO: Could kill current coco server here.
requrie('')
npm = require "npm"
npm.load npm.config, (err) ->
if err
console.log "Loading npm failed:",err
return
npm.commands.install ["ffi"], (er, data) ->
# log the error or data
npm.on "log", (message) ->
# log the progress of the installation
console.log message
return
if '--clean' in process.argv
# TODO: What if mongo is not running?
require('server\commons\databse').connect()
mongoose = require 'mongoose'
mongoose.connection.db.dropDatabase()
# TODO: Could advice to start SCOCODE.bat et al. here

View file

@ -0,0 +1,83 @@
# specify --resetDB to reset the database and load latest dump
# specify using --mongopath if not in path.
dbDump = 'http://23.21.59.137/dump.tar.gz' # Don't change this unless you know what you're doing
dbLocalPath = '../temp'
fs = require 'fs'
tar = require 'tar'
spawn = require('child_process').spawn
http = require 'http'
fs = require 'fs'
zlib = require 'zlib'
Deferred = require 'JQDeferred'
#config = require '../server_config'
#TODO: Could kill current coco server here.
mongopath = ''
useNext = false
for path in process.argv
if useNext
mongopath = path
break
useNext = path == '--mongopath'
mongopath += '/bin/' if mongopath.length
mongopath += 'mongodb' # mongodb is in path.
run = (proc, args) ->
deferred = Deferred()
spawned = spawn proc, args
spawned.stdout.on "data", (data) -> process.stdout.write data
spawned.stderr.on "data", (data) -> process.stderr.write data
spawned.on "exit", (code) ->
console.log proc + " exited with code " + code
unless code is null
deferred.reject code
else
deferred.resolve
deferred.promise()
removeDir = (path) ->
if fs.existsSync(path)
fs.readdirSync(path).forEach (file) ->
current = path + "/" + file
if fs.lstatSync(current).isDirectory() # recurse
removeDir current
else # delete file
fs.unlinkSync current
fs.rmdirSync path
resetDB = () ->
#mongoose = require 'mongoose'
# TODO: What if mongo is not running?
console.log "Downloading Database dump. It's big. This may take a while..."
request = http.get dbDump, (response)->
unzip = response.pipe(zlib.createGunzip()).pipe(tar.Extract(path: dbLocalPath))
unzip.on('error', (err) -> console.log "An error occurred while downloading DB Dump: " + err)
unzip.on 'end', ->
mongoose = require 'mongoose'
require('../server/commons/database').connect()
mongoose.connection.db.dropDatabase()
mongorestore = run 'mongorestore', ['dbLocalPath']
mongorestore.always ->
removeDir dbLocalPath
currentChunk = 0
cur = 0
len = parseInt(response.headers['content-length'], 10)
total = len / 1048576 #1048576 - bytes in 1Megabyte
response.on 'data', (chunk) ->
cur += chunk.length
console.log 'DB dump download received chunk ' + currentChunk++ + ", " + (100.0 * cur / len).toFixed(2) + "% finished of " + total.toFixed(0) + " mb"
unless '--skipupdate' in process.argv
npm = if process.platform is "win32" then "npm.cmd" else "npm"
npminstall = run npm, ['update']
npminstall.done ->
bowerinstall = run 'bower', ['update']
if '--clean' in process.argv
resetDB()
# TODO: Could advice to start SCOCODE.bat et al. here