From 338f27a0b3b215b04aa1c7233836f9075ad3d55a Mon Sep 17 00:00:00 2001 From: ZhangJan Date: Sun, 31 May 2015 10:51:01 +0800 Subject: [PATCH] roadmap.domain now support array config. Ref: https://github.com/fex-team/fis/issues/518 --- lib/file.js | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/lib/file.js b/lib/file.js index 7e0f79b..d24587a 100644 --- a/lib/file.js +++ b/lib/file.js @@ -43,22 +43,46 @@ function getDomainsByPath(path){ if(typeof domain === 'string'){ value = domain.split(/\s*,\s*/); } else if(fis.util.is(domain, 'Array')) { - value = domain; - } else { - fis.util.map(domain, function(pattern, domain){ - if((pattern === 'image' && fis.util.isImageFile(path)) || fis.util.glob(pattern, path)){ - if(typeof domain === 'string'){ - value = domain.split(/\s*,\s*/); - } else if(fis.util.is(domain, 'Array')){ - value = domain; + if(typeof domain[0] === 'string') { + value = domain; + } else { + var matched = domain.some(function(element, index, array) { + var reg = element.reg, url = element.url, matched; + if(fis.util.is(reg, 'RegExp')){ + if(reg.test(path)) { + if(typeof url === 'string'){ + value = url.split(/\s*,\s*/); + } else if(fis.util.is(url, 'Array')){ + value = url; + } else { + fis.log.warning('invalid domain [' + url + '] of [roadmap.domain.' + index + ']'); + } + return true; + } } else { - fis.log.warning('invalid domain [' + domain + '] of [roadmap.domain.' + pattern + ']'); + if(testPath(reg, url)) { + return true; + } } - return true; - } - }); + }); + } + } else { + fis.util.map(domain, testPath); } return value; + + function testPath(pattern, domain){ + if((pattern === 'image' && fis.util.isImageFile(path)) || fis.util.glob(pattern, path)){ + if(typeof domain === 'string'){ + value = domain.split(/\s*,\s*/); + } else if(fis.util.is(domain, 'Array')){ + value = domain; + } else { + fis.log.warning('invalid domain [' + domain + '] of [roadmap.domain.' + pattern + ']'); + } + return true; + } + } }