flex-combo
Advanced tools
Comparing version 0.7.3 to 0.7.4
56
api.js
@@ -52,4 +52,4 @@ var urlLib = require("url"); | ||
return { | ||
request: function (input) { | ||
utilLib.info("=> %a", input); | ||
request: function (host, files) { | ||
utilLib.info("=> %s %o", host, files); | ||
}, | ||
@@ -118,3 +118,3 @@ response: function (input) { | ||
var less = require("./engines/less"); | ||
return less.compile.call(this, xcssfile); | ||
return less.call(this, xcssfile); | ||
} | ||
@@ -125,3 +125,3 @@ | ||
var sass = require("./engines/sass"); | ||
return sass.compile.call(this, xcssfile); | ||
return sass.call(this, xcssfile); | ||
} | ||
@@ -135,4 +135,2 @@ | ||
this.param = require("./lib/param"); | ||
if (dir && (/^\//.test(dir) || /^\w{1}:[\\|\/].*$/.test(dir))) { | ||
@@ -150,3 +148,7 @@ this.confFile = pathLib.join(dir, "config.json"); | ||
if (!fsLib.existsSync(this.confFile)) { | ||
if (fsLib.existsSync(this.confFile)) { | ||
this.param = {}; | ||
} | ||
else { | ||
this.param = require("./lib/param"); | ||
fsLib.writeFileSync(this.confFile, JSON.stringify(this.param, null, 2), {encoding: "utf-8"}); | ||
@@ -214,3 +216,3 @@ } | ||
var jstpl = require("./engines/jstpl"); | ||
var content = jstpl.compile.call(this, htmlfile, url); | ||
var content = jstpl.call(this, htmlfile, url); | ||
if (content) { | ||
@@ -232,5 +234,7 @@ fsLib.writeFile(htmlfile, convert.call(this, content)); | ||
handle: function (req, res, next) { | ||
var urlObj = urlLib.parse(req.url); | ||
var url = urlObj.pathname || urlObj.path.replace(/\?(\w+)=(.+)$/, ''); | ||
var HOST = req.protocol + "://" + (req.hostname||req.host||req.headers.host); | ||
// 不用.pathname的原因是由于??combo形式的url,parse方法解析有问题 | ||
var URL = urlLib.parse(req.url).path.replace(/(.*)\?[^\?.]+$/, "$1"); | ||
var suffix = ["\\.phtml$","\\.js$","\\.css$","\\.png$","\\.gif$","\\.jpg$","\\.jpeg$","\\.ico$","\\.swf$","\\.xml$","\\.less$","\\.scss$","\\.svg$","\\.ttf$","\\.eot$","\\.woff$","\\.mp3$"]; | ||
@@ -247,6 +251,17 @@ if (this.param.supportedFile) { | ||
if (url.match(new RegExp(suffix.join('|')))) { | ||
var engines = this.param.engine; | ||
if (engines) { | ||
for (var k in engines) { | ||
suffix.push(k); | ||
if (URL.match(new RegExp(k))) { | ||
this.param.urls[pathLib.dirname(URL)] = pathLib.dirname(engines[k]); | ||
} | ||
this.addEngine(k, require(pathLib.join(process.cwd(), engines[k]))) | ||
} | ||
} | ||
if (URL.match(new RegExp(suffix.join('|')))) { | ||
res.writeHead(200, { | ||
"Access-Control-Allow-Origin": '*', | ||
"Content-Type": mime.lookup(url) + (isBinFile(url) ? '' : ";charset=" + this.param.charset), | ||
"Content-Type": mime.lookup(URL) + (isBinFile(URL) ? '' : ";charset=" + this.param.charset), | ||
"X-MiddleWare": "flex-combo" | ||
@@ -256,5 +271,6 @@ }); | ||
/* 获取待处理文件列表 */ | ||
var files = this.parser(url); | ||
var Q = new Array(files.length); | ||
Log.request(files); | ||
var files = this.parser(URL); | ||
var FLen = files.length; | ||
var Q = new Array(FLen); | ||
Log.request(HOST, files); | ||
@@ -270,3 +286,3 @@ /* 响应输出 */ | ||
res.end(utilLib.joinBuffer(Q)); | ||
!F && Log.response(req.url); | ||
!F && Log.response(HOST+req.url); | ||
} | ||
@@ -372,3 +388,3 @@ } | ||
if (isBinFile(absPath)) { | ||
return buff; | ||
return (typeof buff == "object" && Buffer.isBuffer(buff)) ? buff : new Buffer(buff); | ||
} | ||
@@ -383,3 +399,3 @@ return convert.call(this, buff, _url); | ||
function readFromCache(_url) { | ||
var absPath = pathLib.join(this.cacheDir, utilLib.MD5(_url)); | ||
var absPath = pathLib.join(this.cacheDir, utilLib.MD5(pathLib.join(HOST, _url))); | ||
if (fsLib.existsSync(absPath)) { | ||
@@ -402,3 +418,3 @@ var buff = fsLib.readFileSync(absPath); | ||
function cacheFile(_url, buff) { | ||
var absPath = pathLib.join(this.cacheDir, utilLib.MD5(_url)); | ||
var absPath = pathLib.join(this.cacheDir, utilLib.MD5(pathLib.join(HOST, _url))); | ||
if (!/[<>\*\?]+/g.test(absPath)) { | ||
@@ -450,3 +466,3 @@ fsLib.writeFile(absPath, buff); | ||
var F = false; | ||
for (var i = 0, len = files.length; i < len; i++) { | ||
for (var i = 0; i < FLen; i++) { | ||
var file = files[i]; | ||
@@ -453,0 +469,0 @@ |
@@ -34,3 +34,3 @@ var helper = require("../lib/util"); | ||
exports.compile = function (htmlfile, _url) { | ||
module.exports = function (htmlfile, _url) { | ||
htmlfile = htmlfile.replace(/\.js$/, ''); | ||
@@ -37,0 +37,0 @@ |
@@ -73,3 +73,3 @@ var helper = require("../lib/util"); | ||
exports.compile = function (xcssfile) { | ||
module.exports = function (xcssfile) { | ||
var loader = new Loader(); | ||
@@ -76,0 +76,0 @@ var lesstxt = loader.fetch(xcssfile); |
@@ -5,3 +5,3 @@ var helper = require("../lib/util"); | ||
var sass = require("node-sass"); | ||
exports.compile = function(xcssfile) { | ||
module.exports = function(xcssfile) { | ||
var sasstxt = helper.getUnicode(xcssfile); | ||
@@ -18,5 +18,5 @@ if (sasstxt) { | ||
catch(e) { | ||
exports.compile = function(xcssfile) { | ||
module.exports = function(xcssfile) { | ||
return "/* node-sass isn't installed\n *"+xcssfile+" ERROR!\n */"; | ||
}; | ||
} |
module.exports = { | ||
urls: {}, | ||
hosts: { | ||
@@ -17,2 +16,4 @@ "a.tbcdn.cn": "115.238.23.240", | ||
}, | ||
engine:{}, | ||
urls: {}, | ||
define: "KISSY.add", | ||
@@ -19,0 +20,0 @@ anonymous: false, |
{ | ||
"name": "flex-combo", | ||
"version": "0.7.3", | ||
"version": "0.7.4", | ||
"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).", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
42842
720
7