Last active
August 29, 2015 14:23
Revisions
-
orzFly revised this gist
Jun 28, 2015 . 1 changed file with 19 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,29 +1,14 @@ _ = require 'lodash' fs = require 'fs' class Config # Singleton constructor: (env) -> env || = process.env.NODE_ENV env || = 'development' @current = @load(env) @env = env @onInit() load: (env = @env) -> config = {} @@ -41,11 +26,25 @@ class Config # Singleton config.env = env config._mergedParts = mergedParts @onLoad config onLoad: (config) -> winston = require 'winston' winston.level = config.debugLevel winston.info "配置加载完成" for i in config._mergedParts winston.info "配置文件包含 #{i}" config onInit: () -> Q = require 'bluebird-q' if @current.longStackSupport Q.longStackSupport = true process.env.BLUEBIRD_DEBUG = 1 default: require './config.default.coffee' local: require './config.local.coffee' if fs.existsSync('./config.local.coffee') module.exports = new Config() -
orzFly revised this gist
Jun 28, 2015 . 2 changed files with 38 additions and 38 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,47 +4,47 @@ fs = require 'fs' winston = require 'winston' class Config # Singleton init: (env) -> return @current if @env env || = process.env.NODE_ENV env || = 'development' @current = @load(env) @env = env if @current.longStackSupport Q.longStackSupport = true process.env.BLUEBIRD_DEBUG = 1 winston.level = @current.debugLevel winston.info "配置加载完成" for i in @current._mergedParts winston.info "配置文件包含 #{i}" @current load: (env = @env) -> config = {} mergedParts = [] mergePart = (name, part) -> return unless part config = _.merge config, part mergedParts.push name mergePart "config.default.base", @default.base mergePart "config.default.override.#{env}", @default.override?[env] mergePart "config.local.base", @local?.base mergePart "config.local.override.#{env}", @local?.override?[env] config.env = env config._mergedParts = mergedParts config default: require './config.default.coffee' local: require './config.local.coffee' if fs.existsSync('./config.local.coffee') module.exports = instance = new Config() This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ module.exports = base: # 不要用 env 这个 key,因为他会被覆盖为当前配置的名字。 debugLevel: 'debug' longStackSupport: true override: production: debugLevel: 'info' longStackSupport: false -
orzFly revised this gist
Jun 28, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ class Config # Singleton init: (env) -> return @current if @env env || = process.env.NODE_ENV env || = 'development' @current = @load(env) -
orzFly revised this gist
Jun 28, 2015 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ module.exports = base: # 不要用 env 这个 key,因为他会被覆盖为当前配置的名字。 debugLevel: 'debug' longStackSupport: true override: production: debugLevel: 'info' longStackSupport: false -
orzFly created this gist
Jun 28, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ _ = require 'lodash' Q = require 'bluebird-q' fs = require 'fs' winston = require 'winston' class Config # Singleton init: (env) -> return @current if @env env || = process.env.UJS_ELECTRIC_PROXY_ENV env || = 'development' @current = @load(env) @env = env if @current.longStackSupport Q.longStackSupport = true process.env.BLUEBIRD_DEBUG = 1 winston.level = @current.debugLevel winston.info "配置加载完成" for i in @current._mergedParts winston.info "配置文件包含 #{i}" @current load: (env = @env) -> config = {} mergedParts = [] mergePart = (name, part) -> return unless part config = _.merge config, part mergedParts.push name mergePart "config.default.base", @default.base mergePart "config.default.override.#{env}", @default.override?[env] mergePart "config.local.base", @local?.base mergePart "config.local.override.#{env}", @local?.override?[env] config.env = env config._mergedParts = mergedParts config default: require './config.default.coffee' local: require './config.local.coffee' if fs.existsSync('./config.local.coffee') module.exports = instance = new Config() instance.init()