From f61489cbb95f798c0e441bb5081cc33815afa8a6 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sat, 9 Jul 2016 12:12:16 +0800 Subject: [PATCH] fix --input-dir when --file-ext is specified (#687) fixes #686 --- cli.js | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/cli.js b/cli.js index 5483434..fd47798 100755 --- a/cli.js +++ b/cli.js @@ -107,7 +107,6 @@ var mainOptions = { customAttrSurround: ['Arrays of regex\'es that allow to support custom attribute surround expressions (e.g. )', parseJSONRegExpArray], customEventAttributes: ['Arrays of regex\'es that allow to support custom event attributes for minifyJS (e.g. ng-click)', parseJSONRegExpArray], decodeEntities: 'Use direct Unicode characters whenever possible', - html5: 'Parse input according to HTML5 specifications', ignoreCustomComments: ['Array of regex\'es that allow to ignore certain comments, when matched', parseJSONRegExpArray], ignoreCustomFragments: ['Array of regex\'es that allow to ignore certain fragments, when matched (e.g. , {{ ... }})', parseJSONRegExpArray], @@ -220,30 +219,35 @@ function processDirectory(inputDir, outputDir, fileExt) { files.forEach(function(file) { var inputFile = path.join(inputDir, file); var outputFile = path.join(outputDir, file); - if (fileExt ? path.extname(file) === '.' + fileExt : true) { - fs.readFile(inputFile, { encoding: 'utf8' }, function(err, data) { - if (!err) { - var minified; - try { - minified = minify(data, createOptions()); - } - catch (e) { - fatal('Minification error on ' + inputFile + '\n' + e.message); + fs.stat(inputFile, function(err, stat) { + if (err) { + fatal('Cannot read ' + inputFile + '\n' + err.message); + } + else if (stat.isDirectory()) { + processDirectory(inputFile, outputFile, fileExt); + } + else if (!fileExt || path.extname(file) === '.' + fileExt) { + fs.readFile(inputFile, { encoding: 'utf8' }, function(err, data) { + if (err) { + fatal('Cannot read ' + inputFile + '\n' + err.message); } - fs.writeFile(outputFile, minified, { encoding: 'utf8' }, function(err) { - if (err) { - fatal('Cannot write ' + outputFile + '\n' + err.message); + else { + var minified; + try { + minified = minify(data, createOptions()); } - }); - } - else if (err.code === 'EISDIR') { - processDirectory(inputFile, outputFile, fileExt); - } - else { - fatal('Cannot read ' + inputFile + '\n' + err.message); - } - }); - } + catch (e) { + fatal('Minification error on ' + inputFile + '\n' + e.message); + } + fs.writeFile(outputFile, minified, { encoding: 'utf8' }, function(err) { + if (err) { + fatal('Cannot write ' + outputFile + '\n' + err.message); + } + }); + } + }); + } + }); }); }); }); -- 2.34.1