Просмотр исходного кода

Add existence check for modules dir

James Allen 12 лет назад
Родитель
Сommit
374c0f3d65
2 измененных файлов с 48 добавлено и 34 удалено
  1. 35 34
      services/web/Gruntfile.coffee
  2. 13 0
      services/web/app/coffee/infrastructure/Modules.coffee

+ 35 - 34
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
 

+ 13 - 0
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)