From 7e915b044bdfec3c1a48dcf6dd3168b0b910bf89 Mon Sep 17 00:00:00 2001 From: Shihua Ma Date: Tue, 17 Dec 2013 11:03:32 +0800 Subject: [PATCH] Update loader.js Support for load coffee script file, So pomelo can support coffee --- lib/loader.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/loader.js b/lib/loader.js index efa6a14..afbc0f1 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -71,8 +71,8 @@ var loadPath = function(path, context) { fn = files[i]; fp = path + fn; - if(!isFile(fp) || !checkFileType(fn, '.js')) { - // only load js file type + if(!isFile(fp) || !(checkFileType(fn, '.js') || checkFileType(fn, '.coffee'))) { + // only load js or coffee file type continue; } @@ -82,7 +82,7 @@ var loadPath = function(path, context) { continue; } - var name = m.name || getFileName(fn, '.js'.length); + var name = m.name || getFileName(fn); res[name] = m; } @@ -117,16 +117,13 @@ var isDir = function(path) { return fs.statSync(path).isDirectory(); }; -var getFileName = function(fp, suffixLength) { +var getFileName = function(fp) { var fn = path.basename(fp); - if(fn.length > suffixLength) { - return fn.substring(0, fn.length - suffixLength); - } - - return fn; + var extname = path.extname(fp); + return fn.replace(extname, ''); }; var requireUncached = function(module){ delete require.cache[require.resolve(module)] return require(module) -} \ No newline at end of file +}