flex-combo
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -41,3 +41,4 @@ var http = require('http') | ||
supportedFile: '\\.js|\\.css|\\.png|\\.gif|\\.jpg|\\.swf|\\.xml|\\.less', | ||
prjDir: '' | ||
prjDir: '', | ||
urlBasedCharset:{} | ||
}; | ||
@@ -65,12 +66,11 @@ | ||
} | ||
/* | ||
* 根据一个文件的全路径(如:/xxx/yyy/aa.js)从本地文件系统获取内容 | ||
* 根据传入的返回最长匹配的目录映射 | ||
*/ | ||
function readFromLocal (fullPath) { | ||
debug('local file:'+ fullPath); | ||
var map = param.urls, charset = param.charset; | ||
fullPath = filterUrl(fullPath); | ||
function longgestMatchedDir(fullPath) { | ||
var map = param.urls; | ||
var longestMatchNum = -1 , longestMatchPos = null; | ||
for(k in map){ | ||
if(fullPath.replace(/\\/g, '/').indexOf(k) === 0 && longestMatchNum < k.length){ | ||
for (k in map) { | ||
if (fullPath.replace(/\\/g, '/').indexOf(k) === 0 && longestMatchNum < k.length) { | ||
longestMatchNum = k.length; | ||
@@ -80,4 +80,17 @@ longestMatchPos = k; | ||
} | ||
return longestMatchPos; | ||
} | ||
/* | ||
* 根据一个文件的全路径(如:/xxx/yyy/aa.js)从本地文件系统获取内容 | ||
*/ | ||
function readFromLocal (fullPath) { | ||
debug('local file:'+ fullPath); | ||
fullPath = filterUrl(fullPath); | ||
var longestMatchPos = longgestMatchedDir(fullPath); | ||
if(!longestMatchPos){ return null } | ||
//找到最长匹配的配置,顺序遍历已定义好的目录。多个目录用逗号","分隔。 | ||
var map = param.urls; | ||
var dirs = map[longestMatchPos].split(','); | ||
@@ -87,3 +100,12 @@ for (var i = 0, len = dirs.length; i < len; i++){ | ||
var revPath = fullPath.slice(longestMatchPos.length, fullPath.length); | ||
var absPath = path.normalize(path.join(param.prjDir, dir, revPath)); | ||
var absPath = ''; | ||
//如果是绝对路径,直接使用 | ||
if(dir.indexOf('/') === 0 || /^\w{1}:\\.*$/.test(dir)){ | ||
absPath = path.normalize(path.join(dir, revPath)); | ||
} | ||
else{ | ||
absPath = path.normalize(path.join(param.prjDir, dir, revPath)); | ||
} | ||
debug('read file:'+ absPath); | ||
@@ -96,3 +118,10 @@ if(fs.existsSync(absPath)){ | ||
var charset = isUtf8(buff) ? 'utf8' : 'gbk'; | ||
return adaptCharset(buff, param.charset, charset); | ||
//允许为某个url特别指定编码 | ||
var outputCharset = param.charset; | ||
if(param.urlBasedCharset && param.urlBasedCharset[longestMatchPos]){ | ||
outputCharset = param.urlBasedCharset[longestMatchPos]; | ||
} | ||
return adaptCharset(buff, outputCharset, charset); | ||
} | ||
@@ -132,3 +161,12 @@ } | ||
var charset = isUtf8(buff) ? 'utf8' : 'gbk'; | ||
return adaptCharset(buff, param.charset, charset); | ||
fullPath = filterUrl(fullPath); | ||
var longestMatchPos = longgestMatchedDir(fullPath); | ||
if(!longestMatchPos){ return null } | ||
//允许为某个url特别指定编码 | ||
var outputCharset = param.charset; | ||
if(param.urlBasedCharset && param.urlBasedCharset[longestMatchPos]){ | ||
outputCharset = param.urlBasedCharset[longestMatchPos]; | ||
} | ||
return adaptCharset(buff, outputCharset, charset); | ||
} | ||
@@ -146,2 +184,5 @@ return null; | ||
if(!fs.existsSync(userConfigPath)){ | ||
if(!fs.existsSync(path.join(userHome,'.flex-combo'))){ | ||
mkdirp.sync(path.join(userHome,'.flex-combo')); | ||
} | ||
fs.writeFileSync(userConfigPath, beautify(JSON.stringify(param))); | ||
@@ -166,4 +207,2 @@ } | ||
var fileReg = new RegExp(param.supportedFile); | ||
@@ -177,2 +216,3 @@ return function(req, res, next) { | ||
var prefix = url.indexOf(param.servlet + '?'); | ||
//不包含combo的servlet,认为是单一文件 | ||
@@ -225,3 +265,13 @@ if(prefix === -1){ | ||
var charset = isUtf8(buff) ? 'utf8' : 'gbk'; | ||
var singleFileContent = adaptCharset(buff, param.charset, charset); | ||
var longestMatchPos = longgestMatchedDir(filteredUrl); | ||
//允许为某个url特别指定编码 | ||
var outputCharset = param.charset; | ||
if(longestMatchPos){ | ||
if(param.urlBasedCharset && param.urlBasedCharset[longestMatchPos]){ | ||
outputCharset = param.urlBasedCharset[longestMatchPos]; | ||
} | ||
} | ||
var singleFileContent = adaptCharset(buff, outputCharset, charset); | ||
cacheFile(url, buff, charset); | ||
@@ -238,4 +288,6 @@ res.end(singleFileContent ); | ||
prefix = url.substring(0, prefix); | ||
debug(prefix+'|'+param.servlet); | ||
var files = url.substring(prefix.length + param.servlet.length + 1, url.length); | ||
debug(files); | ||
@@ -242,0 +294,0 @@ files = files.split(param.seperator, 1000); |
{ | ||
"name": "flex-combo", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "The Flex-combo is combo tool designed for web front-end developer. It support various kinds of combo format by modify configuration(eg. yahoo combo).", | ||
@@ -17,3 +17,4 @@ "main": "flex-combo.js", | ||
"commander":"1.0.4", | ||
"mime":"1.2.7" | ||
"mime":"1.2.7", | ||
"debug":"0.7.0" | ||
}, | ||
@@ -20,0 +21,0 @@ "devDependencies": {}, |
@@ -1,1 +0,1 @@ | ||
jsfile1 | ||
中文jsfile1 |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
66286
1476
2
8
+ Addeddebug@0.7.0
+ Addeddebug@0.7.0(transitive)