From 374c0f3d65238882d5717d7fd2c4f4d48c59cce9 Mon Sep 17 00:00:00 2001 From: James Allen Date: Mon, 8 Sep 2014 14:23:47 +0100 Subject: [PATCH] Add existence check for modules dir --- services/web/Gruntfile.coffee | 69 ++++++++++--------- .../app/coffee/infrastructure/Modules.coffee | 13 ++++ 2 files changed, 48 insertions(+), 34 deletions(-) create mode 100644 services/web/app/coffee/infrastructure/Modules.coffee diff --git a/services/web/Gruntfile.coffee b/services/web/Gruntfile.coffee index 83caa02d2c..071a8cb1b5 100644 --- a/services/web/Gruntfile.coffee +++ b/services/web/Gruntfile.coffee @@ -162,40 +162,41 @@ module.exports = (grunt) -> moduleCompileServerTasks = [] moduleCompileUnitTestTasks = [] moduleUnitTestTasks = [] - for module in fs.readdirSync "./modules" - config.coffee["module_#{module}_server"] = { - expand: true, - flatten: false, - cwd: "modules/#{module}/app/coffee", - src: ['**/*.coffee'], - dest: "modules/#{module}/app/js", - ext: '.js' - } - config.coffee["module_#{module}_index"] = { - src: "modules/#{module}/index.coffee", - dest: "modules/#{module}/index.js" - } - - moduleCompileServerTasks.push "coffee:module_#{module}_server" - moduleCompileServerTasks.push "coffee:module_#{module}_index" - - config.coffee["module_#{module}_unit_tests"] = { - expand: true, - flatten: false, - cwd: "modules/#{module}/test/unit/coffee", - src: ['**/*.coffee'], - dest: "modules/#{module}/test/unit/js", - ext: '.js' - } - config.mochaTest["module_#{module}_unit"] = { - src: ["modules/#{module}/test/unit/js/*.js"] - options: - reporter: grunt.option('reporter') or 'spec' - grep: grunt.option("grep") - } - - moduleCompileUnitTestTasks.push "coffee:module_#{module}_unit_tests" - moduleUnitTestTasks.push "mochaTest:module_#{module}_unit" + if fs.existsSync "./modules" + for module in fs.readdirSync "./modules" + config.coffee["module_#{module}_server"] = { + expand: true, + flatten: false, + cwd: "modules/#{module}/app/coffee", + src: ['**/*.coffee'], + dest: "modules/#{module}/app/js", + ext: '.js' + } + config.coffee["module_#{module}_index"] = { + src: "modules/#{module}/index.coffee", + dest: "modules/#{module}/index.js" + } + + moduleCompileServerTasks.push "coffee:module_#{module}_server" + moduleCompileServerTasks.push "coffee:module_#{module}_index" + + config.coffee["module_#{module}_unit_tests"] = { + expand: true, + flatten: false, + cwd: "modules/#{module}/test/unit/coffee", + src: ['**/*.coffee'], + dest: "modules/#{module}/test/unit/js", + ext: '.js' + } + config.mochaTest["module_#{module}_unit"] = { + src: ["modules/#{module}/test/unit/js/*.js"] + options: + reporter: grunt.option('reporter') or 'spec' + grep: grunt.option("grep") + } + + moduleCompileUnitTestTasks.push "coffee:module_#{module}_unit_tests" + moduleUnitTestTasks.push "mochaTest:module_#{module}_unit" grunt.initConfig config diff --git a/services/web/app/coffee/infrastructure/Modules.coffee b/services/web/app/coffee/infrastructure/Modules.coffee new file mode 100644 index 0000000000..236d107178 --- /dev/null +++ b/services/web/app/coffee/infrastructure/Modules.coffee @@ -0,0 +1,13 @@ +fs = require "fs" +Path = require "path" + +MODULE_BASE_PATH = Path.resolve(__dirname + "/../../../modules") + +modules = [] +for mod in fs.readdirSync(MODULE_BASE_PATH) + modules.push require(Path.join(MODULE_BASE_PATH, mod, "index")) + +module.exports = Modules = + applyRouter: (app) -> + for module in modules + module.router?.apply(app) \ No newline at end of file