Add Gruntfile

This commit is contained in:
James Allen 2014-02-26 16:17:15 +00:00
parent a21f8a8004
commit ad18c1d5a5
7 changed files with 140 additions and 36 deletions

View file

@ -0,0 +1,111 @@
module.exports = (grunt) ->
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-clean'
grunt.loadNpmTasks 'grunt-mocha-test'
grunt.loadNpmTasks 'grunt-available-tasks'
grunt.loadNpmTasks 'grunt-execute'
grunt.loadNpmTasks 'grunt-bunyan'
grunt.initConfig
execute:
app:
src: "app.js"
bunyan:
strict: false
coffee:
app_dir:
expand: true,
flatten: false,
cwd: 'app/coffee',
src: ['**/*.coffee'],
dest: 'app/js/',
ext: '.js'
app:
src: 'app.coffee'
dest: 'app.js'
acceptance_tests:
expand: true,
flatten: false,
cwd: 'test/acceptance/coffee',
src: ['**/*.coffee'],
dest: 'test/acceptance/js/',
ext: '.js'
unit_tests:
expand: true,
flatten: false,
cwd: 'test/unit/coffee',
src: ['**/*.coffee'],
dest: 'test/unit/js/',
ext: '.js'
clean:
app: ["app/js"]
acceptance_tests: ["test/acceptance/js"]
mochaTest:
unit:
src: ['test/unit/js/**/*.js']
options:
reporter: grunt.option('reporter') or 'spec'
grep: grunt.option("grep")
acceptance:
src: ['test/acceptance/js/**/*.js']
options:
reporter: grunt.option('reporter') or 'spec'
grep: grunt.option("grep")
timeout: 10000
availabletasks:
tasks:
options:
filter: 'exclude',
tasks: [
'coffee'
'clean'
'mochaTest'
'availabletasks'
'execute'
'bunyan'
]
groups:
"Compile tasks": [
"compile:server"
"compile:tests"
"compile"
"compile:unit_tests"
"compile:acceptance_tests"
"install"
]
"Test tasks": [
"test:unit"
"test:acceptance"
]
"Run tasks": [
"run"
"default"
]
"Misc": [
"help"
]
grunt.registerTask 'help', 'Display this help list', 'availabletasks'
grunt.registerTask 'compile:server', 'Compile the server side coffee script', ['clean:app', 'coffee:app', 'coffee:app_dir']
grunt.registerTask 'compile:unit_tests', 'Compile the unit tests', ['coffee:unit_tests']
grunt.registerTask 'compile:acceptance_tests', 'Compile the acceptance tests', ['clean:acceptance_tests', 'coffee:acceptance_tests']
grunt.registerTask 'compile:tests', 'Compile all the tests', ['compile:acceptance_tests', 'compile:unit_tests']
grunt.registerTask 'compile', 'Compiles everything need to run track-changes-sharelatex', ['compile:server']
grunt.registerTask 'install', "Compile everything when installing as an npm module", ['compile']
grunt.registerTask 'test:unit', 'Run the unit tests (use --grep=<regex> for individual tests)', ['compile:server', 'compile:unit_tests', 'mochaTest:unit']
grunt.registerTask 'test:acceptance', 'Run the acceptance tests (use --grep=<regex> for individual tests)', ['compile:acceptance_tests', 'mochaTest:acceptance']
grunt.registerTask 'run', "Compile and run the track-changes-sharelatex server", ['compile', 'bunyan', 'execute']
grunt.registerTask 'default', 'run'

View file

@ -1,6 +1,6 @@
Settings = require "settings-sharelatex" Settings = require "settings-sharelatex"
logger = require "logger-sharelatex" logger = require "logger-sharelatex"
logger.initialize("history") logger.initialize("track-changes")
HttpController = require "./app/js/HttpController" HttpController = require "./app/js/HttpController"
express = require "express" express = require "express"
@ -14,11 +14,11 @@ app.use (error, req, res, next) ->
logger.error err: error, "an internal error occured" logger.error err: error, "an internal error occured"
res.send 500 res.send 500
port = Settings.internal?.history?.port or 3014 port = Settings.internal?.trackchanges?.port or 3014
host = Settings.internal?.history?.host or "localhost" host = Settings.internal?.trackchanges?.host or "localhost"
app.listen port, host, (error) -> app.listen port, host, (error) ->
if error? if error?
logger.error err: error, "could not start history server" logger.error err: error, "could not start track-changes server"
else else
logger.log "history api listening on http://#{host}:#{port}" logger.log "track changes api listening on http://#{host}:#{port}"

View file

@ -1,20 +0,0 @@
{db, ObjectId} = require "./app/coffee/mongojs"
ConversionManager = require "./app/coffee/ConversionManager"
async = require "async"
db.docOps.find { }, { doc_id: true }, (error, docs) ->
throw error if error?
jobs = []
for doc in docs
do (doc) ->
jobs.push (callback) ->
doc_id = doc.doc_id.toString()
ConversionManager.convertOldRawUpdates doc_id, (error) ->
return callback(error) if error?
console.log doc_id, "DONE"
callback()
async.series jobs, (error) ->
throw error if error?
process.exit()

View file

@ -0,0 +1,7 @@
module.exports =
mongo:
url: 'mongodb://127.0.0.1/sharelatex'
internal:
trackchanges:
port: 3014
host: "localhost"

View file

@ -1,4 +0,0 @@
module.exports =
mongo:
url: 'mongodb://127.0.0.1/sharelatexTesting'
port: 3014

View file

@ -2,15 +2,25 @@
"name": "history-sharelatex", "name": "history-sharelatex",
"version": "0.0.1", "version": "0.0.1",
"dependencies": { "dependencies": {
"async": "", "async": "~0.2.10",
"chai": "",
"express": "3.3.5", "express": "3.3.5",
"sandboxed-module": "",
"sinon": "",
"mongojs": "~0.9.11", "mongojs": "~0.9.11",
"settings": "git+ssh://git@bitbucket.org:sharelatex/settings-sharelatex.git#master", "settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git#master",
"logger": "git+ssh://git@bitbucket.org:sharelatex/logger-sharelatex.git#bunyan", "logger-sharelatex": "git+https://github.com/sharelatex/logger-sharelatex.git#master",
"request": "~2.33.0", "request": "~2.33.0",
"redis": "~0.10.1" "redis": "~0.10.1"
},
"devDependencies": {
"chai": "~1.9.0",
"sinon": "~1.8.2",
"sandboxed-module": "~0.3.0",
"grunt-execute": "~0.1.5",
"grunt-contrib-clean": "~0.5.0",
"grunt-mocha-test": "~0.9.3",
"grunt": "~0.4.2",
"grunt-available-tasks": "~0.4.2",
"grunt-contrib-coffee": "~0.10.1",
"bunyan": "~0.22.1",
"grunt-bunyan": "~0.5.0"
} }
} }

View file

@ -11,7 +11,7 @@ rclient = require("redis").createClient() # Only works locally for now
flushAndGetCompressedUpdates = (doc_id, callback = (error, updates) ->) -> flushAndGetCompressedUpdates = (doc_id, callback = (error, updates) ->) ->
request.post { request.post {
url: "http://localhost:#{Settings.port}/doc/#{doc_id}/flush" url: "http://localhost:3014/doc/#{doc_id}/flush"
}, (error, response, body) => }, (error, response, body) =>
response.statusCode.should.equal 204 response.statusCode.should.equal 204
db.docHistory db.docHistory