mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
+ Help file
This commit is contained in:
parent
dbd280840a
commit
5cb47f3e76
1 changed files with 53 additions and 18 deletions
|
@ -1,5 +1,14 @@
|
|||
# specify --resetDB to reset the database and load latest dump
|
||||
# specify using --mongopath if not in path.
|
||||
return console.log '-------------------------------------------------
|
||||
Commandline utility written in Coffeescript to run all updates, download latest database and install it after you git pushed.
|
||||
Params:
|
||||
\t--skipupdates skips npm and bower update
|
||||
\t--dldb: download the latest database (Over 300 mb!)
|
||||
\t--resetdb: to reset the database and load dump from tmp. Will need a downloaded database or --dbdownload specified
|
||||
\t--mongopath <.path/to/mongo>: to specify mongodb folder if not set in PATH.
|
||||
\t--help: Yo fund this one already.
|
||||
|
||||
May need an initial npm install upfront if newly checked out.
|
||||
' if '--help' in path
|
||||
|
||||
dbDump = 'http://23.21.59.137/dump.tar.gz' # Don't change this unless you know what you're doing
|
||||
dbLocalPath = '../temp'
|
||||
|
@ -34,7 +43,7 @@ run = (proc, args) ->
|
|||
unless code is null
|
||||
deferred.reject code
|
||||
else
|
||||
deferred.resolve
|
||||
deferred.resolve()
|
||||
deferred.promise()
|
||||
|
||||
removeDir = (path) ->
|
||||
|
@ -47,12 +56,27 @@ removeDir = (path) ->
|
|||
fs.unlinkSync current
|
||||
fs.rmdirSync path
|
||||
|
||||
resetDB = () ->
|
||||
resetDB = ->
|
||||
deferred = Deferred()
|
||||
console.log "Dropping Database"
|
||||
mongodrop = run "mongo", ["coco", "--eval", "db.dropDatabase()"]
|
||||
mongodrop.fail -> console.error "Error occurred"
|
||||
mongodrop.always ->
|
||||
console.log "Restoring from dump."
|
||||
mongorestore = run "mongorestore", [dbLocalPath]
|
||||
mongorestore.always = deferred.resolve
|
||||
deferred.promise()
|
||||
|
||||
downloadDB = ->
|
||||
deferred = Deferred()
|
||||
#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 = response.pipe npm = if process.platform is "win32" then "npm.cmd" else "npm"
|
||||
npminstall = run npm, ['update']
|
||||
npminstall.done ->
|
||||
bowerinstall = run 'bower', ['update'](zlib.createGunzip()).pipe(tar.Extract(path: dbLocalPath))
|
||||
# Log download
|
||||
currentChunk = 0
|
||||
cur = 0
|
||||
|
@ -61,25 +85,36 @@ resetDB = () ->
|
|||
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"
|
||||
|
||||
unzip.on('data', -> console.log "Unpacking zip...")
|
||||
unzip.on('error', (err) -> console.log "An error occurred while downloading DB Dump: " + err)
|
||||
unzip.on 'end', ->
|
||||
console.log "Finished downloading. Dropping Database"
|
||||
mongodrop = run "mongo", ["coco", "--eval", "db.dropDatabase()"]
|
||||
mongodrop.fail -> console.error "Error occurred"
|
||||
mongodrop.always ->
|
||||
console.log "Restoring from dump."
|
||||
mongorestore = run "mongorestore", [dbLocalPath]
|
||||
mongorestore.done ->
|
||||
removeDir dbLocalPath
|
||||
console.log "Finished downloading."
|
||||
deferred.resolve()
|
||||
deferred.promise()
|
||||
|
||||
unless '--skipupdates' in process.argv
|
||||
installUpdates = ->
|
||||
deferred = Deferred()
|
||||
npm = if process.platform is "win32" then "npm.cmd" else "npm"
|
||||
npminstall = run npm, ['update']
|
||||
npminstall.done ->
|
||||
bowerinstall = run 'bower', ['update']
|
||||
deferred.resolve()
|
||||
deferred.promise()
|
||||
|
||||
if '--clean' in process.argv
|
||||
resetDB()
|
||||
# TODO: Could advice to start SCOCODE.bat et al. here
|
||||
cleanUpTmp = ->
|
||||
removeDir dbLocalPath
|
||||
|
||||
unless '--skipupdates' in process.argv
|
||||
installUpdates()
|
||||
|
||||
if '--resetdb' in process.argv
|
||||
if '--skipdownload' in process.argv
|
||||
resetDB().done ->
|
||||
cleanUpTmp() if '--cleanup' in process.argv
|
||||
else
|
||||
downloadDB().always ->
|
||||
resetDB().done ->
|
||||
cleanUpTmp() if '--cleanup' in process.argv
|
||||
|
||||
# TODO: Could advice to start SCOCODE.bat et al. here
|
||||
|
||||
|
|
Loading…
Reference in a new issue