From ad18c1d5a5c0ae16ead60325a8f493d730405539 Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 26 Feb 2014 16:17:15 +0000 Subject: [PATCH] Add Gruntfile --- services/track-changes/Gruntfile.coffee | 111 ++++++++++++++++++ services/track-changes/app.coffee | 10 +- services/track-changes/compressHistory.coffee | 20 ---- .../config/settings.development.coffee | 7 ++ .../config/settings.testing.coffee | 4 - services/track-changes/package.json | 22 +++- .../coffee/AppendingUpdatesTests.coffee | 2 +- 7 files changed, 140 insertions(+), 36 deletions(-) create mode 100644 services/track-changes/Gruntfile.coffee delete mode 100644 services/track-changes/compressHistory.coffee create mode 100755 services/track-changes/config/settings.development.coffee delete mode 100755 services/track-changes/config/settings.testing.coffee diff --git a/services/track-changes/Gruntfile.coffee b/services/track-changes/Gruntfile.coffee new file mode 100644 index 0000000000..eda137d969 --- /dev/null +++ b/services/track-changes/Gruntfile.coffee @@ -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= for individual tests)', ['compile:server', 'compile:unit_tests', 'mochaTest:unit'] + grunt.registerTask 'test:acceptance', 'Run the acceptance tests (use --grep= 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' + diff --git a/services/track-changes/app.coffee b/services/track-changes/app.coffee index ba2c2470ce..7334c95682 100644 --- a/services/track-changes/app.coffee +++ b/services/track-changes/app.coffee @@ -1,6 +1,6 @@ Settings = require "settings-sharelatex" logger = require "logger-sharelatex" -logger.initialize("history") +logger.initialize("track-changes") HttpController = require "./app/js/HttpController" express = require "express" @@ -14,11 +14,11 @@ app.use (error, req, res, next) -> logger.error err: error, "an internal error occured" res.send 500 -port = Settings.internal?.history?.port or 3014 -host = Settings.internal?.history?.host or "localhost" +port = Settings.internal?.trackchanges?.port or 3014 +host = Settings.internal?.trackchanges?.host or "localhost" app.listen port, host, (error) -> if error? - logger.error err: error, "could not start history server" + logger.error err: error, "could not start track-changes server" else - logger.log "history api listening on http://#{host}:#{port}" + logger.log "track changes api listening on http://#{host}:#{port}" diff --git a/services/track-changes/compressHistory.coffee b/services/track-changes/compressHistory.coffee deleted file mode 100644 index 1ce1dad1be..0000000000 --- a/services/track-changes/compressHistory.coffee +++ /dev/null @@ -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() - - diff --git a/services/track-changes/config/settings.development.coffee b/services/track-changes/config/settings.development.coffee new file mode 100755 index 0000000000..ee758aac0e --- /dev/null +++ b/services/track-changes/config/settings.development.coffee @@ -0,0 +1,7 @@ +module.exports = + mongo: + url: 'mongodb://127.0.0.1/sharelatex' + internal: + trackchanges: + port: 3014 + host: "localhost" diff --git a/services/track-changes/config/settings.testing.coffee b/services/track-changes/config/settings.testing.coffee deleted file mode 100755 index 0e4e181dfd..0000000000 --- a/services/track-changes/config/settings.testing.coffee +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = - mongo: - url: 'mongodb://127.0.0.1/sharelatexTesting' - port: 3014 diff --git a/services/track-changes/package.json b/services/track-changes/package.json index 23447e6102..0c2e13c3cb 100644 --- a/services/track-changes/package.json +++ b/services/track-changes/package.json @@ -2,15 +2,25 @@ "name": "history-sharelatex", "version": "0.0.1", "dependencies": { - "async": "", - "chai": "", + "async": "~0.2.10", "express": "3.3.5", - "sandboxed-module": "", - "sinon": "", "mongojs": "~0.9.11", - "settings": "git+ssh://git@bitbucket.org:sharelatex/settings-sharelatex.git#master", - "logger": "git+ssh://git@bitbucket.org:sharelatex/logger-sharelatex.git#bunyan", + "settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git#master", + "logger-sharelatex": "git+https://github.com/sharelatex/logger-sharelatex.git#master", "request": "~2.33.0", "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" } } diff --git a/services/track-changes/test/acceptance/coffee/AppendingUpdatesTests.coffee b/services/track-changes/test/acceptance/coffee/AppendingUpdatesTests.coffee index a1cd7c89b3..6867dd901b 100644 --- a/services/track-changes/test/acceptance/coffee/AppendingUpdatesTests.coffee +++ b/services/track-changes/test/acceptance/coffee/AppendingUpdatesTests.coffee @@ -11,7 +11,7 @@ rclient = require("redis").createClient() # Only works locally for now flushAndGetCompressedUpdates = (doc_id, callback = (error, updates) ->) -> request.post { - url: "http://localhost:#{Settings.port}/doc/#{doc_id}/flush" + url: "http://localhost:3014/doc/#{doc_id}/flush" }, (error, response, body) => response.statusCode.should.equal 204 db.docHistory