Comparing version 2.1.1 to 2.1.2
@@ -10,5 +10,3 @@ var alp = module.exports = {}; | ||
} | ||
alp.log = require('./lib/log.js'); | ||
alp._ = require('./lib/util.js'); | ||
@@ -15,0 +13,0 @@ |
@@ -41,2 +41,6 @@ var CONFIG = { | ||
}, | ||
error: 'throw', | ||
rewriteExt: { | ||
css: ['.scss', '.sass'] | ||
}, | ||
tmpl: { | ||
@@ -43,0 +47,0 @@ js: '<script type="text/javascript" src="{0}"></script>', |
@@ -15,2 +15,4 @@ var ParseJS = require('./parseJS.js'); | ||
}; | ||
function Dispatcher() { | ||
@@ -67,5 +69,4 @@ | ||
} | ||
storage[file.subpath] = file; | ||
if (!content.match(getRequireRegExp())) { | ||
if (file.isLikeJs && !content.match(getRequireRegExp())) { | ||
return false; | ||
@@ -81,4 +82,3 @@ } | ||
storage[file.subpath] = cacheFile; | ||
console.log(file.subpath); | ||
alp.log.error(e.message); | ||
alp.log.error(e); | ||
} | ||
@@ -96,13 +96,17 @@ if (!file.isLikeHtml) { | ||
if (result) { | ||
for (var k in storage) { | ||
if (result && !result._hasAdeps) { | ||
file = storage[k]; | ||
if (!file._hasAdeps) { | ||
result.aRequires = common.getADeps(result.subpath); | ||
result._hasAdeps = true; | ||
file.aRequires = common.getADeps(k); | ||
file._hasAdeps = true; | ||
} | ||
// for (var k in storage) { | ||
} | ||
// file = storage[k]; | ||
// if (!file._hasAdeps) { | ||
// file.aRequires = common.getADeps(k); | ||
// file._hasAdeps = true; | ||
// } | ||
// } | ||
} | ||
@@ -109,0 +113,0 @@ |
@@ -11,2 +11,3 @@ var _ = alp._; | ||
function File(url, based, isUseExists) { | ||
@@ -61,2 +62,3 @@ var root = config.get('root'), | ||
this.useCompile = _.filter1(absUrl, config.get('include'), config.get('exclude')); | ||
this.mtime = this.getMtime(); | ||
@@ -63,0 +65,0 @@ |
var colors = require('colors'); | ||
var ep = module.exports = {}; | ||
var util = require('util'); | ||
var eventEmitter = require('events').EventEmitter; | ||
// var ep = module.exports = {}; | ||
function AlpacaError (msg, loc) { | ||
Error.call(this); | ||
Error.captureStackTrace(this, arguments.callee); | ||
this.name = 'AlpacaError'; | ||
this.message = msg; | ||
} | ||
util.inherits(AlpacaError, Error); | ||
function LOG() { | ||
this.setMaxListeners(0); | ||
} | ||
util.inherits(LOG, eventEmitter); | ||
LOG.prototype.error = function(err, loc) { | ||
if (!(err instanceof Error)) { | ||
err = new Error(err.message || err); | ||
} | ||
log('error', err.message.red, loc || {}); | ||
process.exit(1); | ||
} | ||
LOG.prototype.warning = function(msg, loc) { | ||
this.log('warning', msg.yellow, loc); | ||
} | ||
LOG.prototype.log = function (type, msg, loc) { | ||
var error; | ||
if (type) { | ||
type = '\n[' + type.toLocaleUpperCase() + '][ALPACA-SM]'; | ||
} | ||
if (alp.config.get('error') == 'throw') { | ||
if (type == 'error') { | ||
throw new AlpacaError(msg, loc, type); | ||
} else { | ||
this.emit('warning', msg + this.getLine(loc), loc); | ||
} | ||
} else { | ||
process.stdout.write(type + msg + this.getLine(loc) + '\n'); | ||
} | ||
} | ||
LOG.prototype.getLine = function (loc) { | ||
if (loc && loc.start && loc.end) { | ||
if (loc.start.line == loc.end.line) { | ||
return '[' + loc.start.line + ':' + loc.start.column + ']'; | ||
} | ||
} | ||
return ''; | ||
}; | ||
function getLine(loc) { | ||
@@ -14,21 +72,34 @@ if (loc && loc.start && loc.end) { | ||
function log(type, msg, loc) { | ||
var error; | ||
if (type) { | ||
type = '\n[' + type.toLocaleUpperCase() + '][ALPACA-SM]'; | ||
} | ||
if (alp.config.get('error') == 'throw') { | ||
if (type == 'error') { | ||
throw new AlpacaError(msg, loc, type); | ||
} | ||
} else { | ||
} | ||
process.stdout.write(type + msg + getLine(loc) + '\n'); | ||
} | ||
ep.error = function(err, loc) { | ||
if (!(err instanceof Error)) { | ||
err = new Error(err.message || err); | ||
} | ||
// ep.error = function(err, loc) { | ||
// if (!(err instanceof Error)) { | ||
// err = new Error(err.message || err); | ||
// } | ||
log('error', err.message.red, loc || {}); | ||
process.exit(1); | ||
} | ||
// log('error', err.message.red, loc || {}); | ||
// process.exit(1); | ||
// } | ||
ep.warning = function(msg, loc) { | ||
log('waring', msg.yellow, loc); | ||
} | ||
// ep.warning = function(msg, loc) { | ||
// log('waring', msg.yellow, loc); | ||
// } | ||
ep.getLine = getLine; | ||
// ep.getLine = getLine; | ||
module.exports = new LOG(); | ||
@@ -134,3 +134,24 @@ var esprima = require('esprima'); | ||
function getRewritePath(pth) { | ||
var extname = path.extname(pth), | ||
ext = extname.replace('.', ''), | ||
dirname, | ||
_pth, | ||
basename, | ||
rewriteExt = config.get('rewriteExt'); | ||
if (ext in rewriteExt) { | ||
dirname = path.dirname(pth); | ||
basename = path.basename(pth, extname); | ||
for (var i = 0, list = rewriteExt[ext], len = list.length; i < len; i++) { | ||
_pth = dirname + '/' + basename + list[i]; | ||
if (_.exists(_pth)) { | ||
return _pth; | ||
} | ||
} | ||
} | ||
return pth; | ||
} | ||
function parse (file, source) { | ||
@@ -175,6 +196,6 @@ var ast, source, _this = this; | ||
} | ||
finishRequireValue = _tmpRequireValue || initRequireValue; | ||
finishRequireValue = getRewritePath(_tmpRequireValue || initRequireValue || ''); | ||
_absUrl = path.resolve(_.unix(config.get('fileBasedRoot') ? config.get('root') : file.dirname || config.get('root')), finishRequireValue); | ||
if (!_.exists(_absUrl)) { | ||
if (!_.exists(_absUrl)) { | ||
if (_tmpRequireValue) { | ||
@@ -181,0 +202,0 @@ alp.log.warning(file.realpath + '文件:require("' + initRequireValue + '") 中的文件不存在,或者将该文件加入黑名单,跳过对该文件的编译', node.loc); |
{ | ||
"name": "alpaca-sm", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "分析Html文件依赖的js文件和css文件", | ||
@@ -26,7 +26,7 @@ "main": "index.js", | ||
"dependencies": { | ||
"colors": "^1.1.2", | ||
"escodegen": "^1.8.0", | ||
"esprima": "^2.7.2", | ||
"estraverse": "4.1.0", | ||
"iconv-lite": "^0.4.13" | ||
"colors": "1.1.2", | ||
"escodegen": "1.8.0", | ||
"esprima": "2.7.2", | ||
"estraverse": "4.2.0", | ||
"iconv-lite": "0.4.13" | ||
}, | ||
@@ -54,4 +54,6 @@ "_shasum": "a14cfd4a4e3e5c58ced1507aa033b99d53ca678f", | ||
"_resolved": "http://registry.npm.taobao.org/alpaca-sm/download/alpaca-sm-1.1.9.tgz", | ||
"devDependencies": {}, | ||
"devDependencies": { | ||
"autod": "^2.5.2" | ||
}, | ||
"license": "MIT" | ||
} |
76076
22
1518
1
+ Addedamdefine@1.0.1(transitive)
+ Addedcolors@1.1.2(transitive)
+ Addedescodegen@1.8.0(transitive)
+ Addedesprima@2.7.2(transitive)
+ Addedestraverse@1.9.34.2.0(transitive)
+ Addediconv-lite@0.4.13(transitive)
+ Addedsource-map@0.2.0(transitive)
- Removedcolors@1.4.0(transitive)
- Removedescodegen@1.14.3(transitive)
- Removedesprima@2.7.34.0.1(transitive)
- Removedestraverse@4.1.04.3.0(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsource-map@0.6.1(transitive)
Updatedcolors@1.1.2
Updatedescodegen@1.8.0
Updatedesprima@2.7.2
Updatedestraverse@4.2.0
Updatediconv-lite@0.4.13