From 2ad3c4ec6fd52bbb97e95d2d18a0da1d2fad3661 Mon Sep 17 00:00:00 2001 From: Colin Mackie Date: Fri, 15 May 2015 16:23:30 -0700 Subject: [PATCH 1/4] Add minfolder option to put any minified files into different folder, e.g. #option minfolder:js/minified --- src/bundler.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/bundler.js b/src/bundler.js index a3603831..563783a5 100644 --- a/src/bundler.js +++ b/src/bundler.js @@ -267,7 +267,7 @@ function processJsBundle(options, jsBundle, bundleDir, jsFiles, bundleName, cb) var filePath = path.join(bundleDir, file), jsPath = path.join(bundleDir, jsFile), - minJsPath = getMinFileName(jsPath); + minJsPath = path.join(bundleDir, options.minfolder || ".", path.dirname(jsFile), getMinFileName(path.basename(jsFile))); var i = index++; pending++; @@ -357,7 +357,7 @@ function processCssBundle(options, cssBundle, bundleDir, cssFiles, bundleName, c var filePath = path.join(bundleDir, file), cssPath = path.join(bundleDir, cssFile), - minCssPath = getMinFileName(cssPath); + minCssPath = path.join(bundleDir, options.minfolder || ".", path.dirname(cssFile), getMinFileName(path.basename(cssFile))); var i = index++; pending++; @@ -489,9 +489,11 @@ function compileAsync(options, mode, compileFn /*compileFn(text, textPath, cb(co if (options.outputbundleonly) { cb(minText); } else { - fs.writeFile(compileTextPath, minText, 'utf-8', function(_) { - cb(minText); - }); + fs.mkdirp(path.dirname(compileTextPath), null, function(_) { + fs.writeFile(compileTextPath, minText, 'utf-8', function(_) { + cb(minText); + }); + }); } }; compileFn(text, textPath, onAfterCompiled); @@ -544,3 +546,13 @@ function readTextFile(filePath, cb) { cb(stripBOM(fileContents)); }); } + +fs.mkdirp = function(dirpath, mode, callback) { + fs.mkdir(dirpath, mode, function(error) { + if (error && error.errno === 34) { + fs.mkdirp(path.dirname(dirpath), mode, callback); + fs.mkdirp(dirpath, mode, callback); + } + callback && callback(error); + }); +}; From b4eada006e43b5a3f61f2db93dcf34474a0dcede Mon Sep 17 00:00:00 2001 From: Colin Mackie Date: Sat, 16 May 2015 08:33:58 -0700 Subject: [PATCH 2/4] Split change into two code paths --- src/bundler.js | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/bundler.js b/src/bundler.js index 563783a5..09400d4c 100644 --- a/src/bundler.js +++ b/src/bundler.js @@ -261,13 +261,15 @@ function processJsBundle(options, jsBundle, bundleDir, jsFiles, bundleName, cb) var isLiveScript = file.endsWith(".ls"); var jsFile = isCoffee ? file.replace(".coffee", ".js") - : isLiveScript ? + : isLiveScript ? file.replace(".ls", ".js") : file; var filePath = path.join(bundleDir, file), jsPath = path.join(bundleDir, jsFile), - minJsPath = path.join(bundleDir, options.minfolder || ".", path.dirname(jsFile), getMinFileName(path.basename(jsFile))); + minJsPath = options.minfolder + ? path.join(bundleDir, options.minfolder, path.dirname(jsFile), getMinFileName(path.basename(jsFile))) + : getMinFileName(jsPath); var i = index++; pending++; @@ -357,7 +359,9 @@ function processCssBundle(options, cssBundle, bundleDir, cssFiles, bundleName, c var filePath = path.join(bundleDir, file), cssPath = path.join(bundleDir, cssFile), - minCssPath = path.join(bundleDir, options.minfolder || ".", path.dirname(cssFile), getMinFileName(path.basename(cssFile))); + minCssPath = options.minfolder + ? path.join(bundleDir, options.minfolder, path.dirname(cssFile), getMinFileName(path.basename(cssFile))) + : getMinFileName(cssPath); var i = index++; pending++; @@ -372,10 +376,10 @@ function processCssBundle(options, cssBundle, bundleDir, cssFiles, bundleName, c readTextFile(filePath, function (sassText) { getOrCreateSassCss(options, sassText, filePath, cssPath, next); }); - } else if (isStylus){ - readTextFile(filePath, function (stylusText) { - getOrCreateStylusCss(options, stylusText, filePath, cssPath, next); - }); + } else if (isStylus){ + readTextFile(filePath, function (stylusText) { + getOrCreateStylusCss(options, stylusText, filePath, cssPath, next); + }); } else { readTextFile(cssPath, next); } @@ -447,15 +451,15 @@ function getOrCreateSassCss(options, sassText, sassPath, cssPath, cb /*cb(sass)* function getOrCreateStylusCss(options, stylusText, stylusPath, cssPath, cb /*cb(css)*/) { compileAsync(options, "compiling", function (stylusText, stylusPath, cb) { stylus(stylusText) - .set('filename', stylusPath) - .use(nib()) - .render(function(err, css){ - if(err){ - throw new Error(err); - } - - cb(css); - }); + .set('filename', stylusPath) + .use(nib()) + .render(function(err, css){ + if(err){ + throw new Error(err); + } + + cb(css); + }); }, stylusText, stylusPath, cssPath, cb); } @@ -493,7 +497,7 @@ function compileAsync(options, mode, compileFn /*compileFn(text, textPath, cb(co fs.writeFile(compileTextPath, minText, 'utf-8', function(_) { cb(minText); }); - }); + }); } }; compileFn(text, textPath, onAfterCompiled); From 57d2882c1174376c78766e9019162a2aee5d269c Mon Sep 17 00:00:00 2001 From: Colin Mackie Date: Sat, 16 May 2015 08:38:15 -0700 Subject: [PATCH 3/4] Reverted whitespace changes --- src/bundler.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/bundler.js b/src/bundler.js index 09400d4c..40ce60ac 100644 --- a/src/bundler.js +++ b/src/bundler.js @@ -261,7 +261,7 @@ function processJsBundle(options, jsBundle, bundleDir, jsFiles, bundleName, cb) var isLiveScript = file.endsWith(".ls"); var jsFile = isCoffee ? file.replace(".coffee", ".js") - : isLiveScript ? + : isLiveScript ? file.replace(".ls", ".js") : file; @@ -376,10 +376,10 @@ function processCssBundle(options, cssBundle, bundleDir, cssFiles, bundleName, c readTextFile(filePath, function (sassText) { getOrCreateSassCss(options, sassText, filePath, cssPath, next); }); - } else if (isStylus){ - readTextFile(filePath, function (stylusText) { - getOrCreateStylusCss(options, stylusText, filePath, cssPath, next); - }); + } else if (isStylus){ + readTextFile(filePath, function (stylusText) { + getOrCreateStylusCss(options, stylusText, filePath, cssPath, next); + }); } else { readTextFile(cssPath, next); } @@ -451,15 +451,15 @@ function getOrCreateSassCss(options, sassText, sassPath, cssPath, cb /*cb(sass)* function getOrCreateStylusCss(options, stylusText, stylusPath, cssPath, cb /*cb(css)*/) { compileAsync(options, "compiling", function (stylusText, stylusPath, cb) { stylus(stylusText) - .set('filename', stylusPath) - .use(nib()) - .render(function(err, css){ - if(err){ - throw new Error(err); - } - - cb(css); - }); + .set('filename', stylusPath) + .use(nib()) + .render(function(err, css){ + if(err){ + throw new Error(err); + } + + cb(css); + }); }, stylusText, stylusPath, cssPath, cb); } @@ -497,7 +497,7 @@ function compileAsync(options, mode, compileFn /*compileFn(text, textPath, cb(co fs.writeFile(compileTextPath, minText, 'utf-8', function(_) { cb(minText); }); - }); + }); } }; compileFn(text, textPath, onAfterCompiled); From 50b79bc818c63e2fd25d2f765c079a469f27fd08 Mon Sep 17 00:00:00 2001 From: Colin Mackie Date: Sat, 16 May 2015 08:38:15 -0700 Subject: [PATCH 4/4] Reverted whitespace changes --- src/bundler.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/bundler.js b/src/bundler.js index 09400d4c..40ce60ac 100644 --- a/src/bundler.js +++ b/src/bundler.js @@ -261,7 +261,7 @@ function processJsBundle(options, jsBundle, bundleDir, jsFiles, bundleName, cb) var isLiveScript = file.endsWith(".ls"); var jsFile = isCoffee ? file.replace(".coffee", ".js") - : isLiveScript ? + : isLiveScript ? file.replace(".ls", ".js") : file; @@ -376,10 +376,10 @@ function processCssBundle(options, cssBundle, bundleDir, cssFiles, bundleName, c readTextFile(filePath, function (sassText) { getOrCreateSassCss(options, sassText, filePath, cssPath, next); }); - } else if (isStylus){ - readTextFile(filePath, function (stylusText) { - getOrCreateStylusCss(options, stylusText, filePath, cssPath, next); - }); + } else if (isStylus){ + readTextFile(filePath, function (stylusText) { + getOrCreateStylusCss(options, stylusText, filePath, cssPath, next); + }); } else { readTextFile(cssPath, next); } @@ -451,15 +451,15 @@ function getOrCreateSassCss(options, sassText, sassPath, cssPath, cb /*cb(sass)* function getOrCreateStylusCss(options, stylusText, stylusPath, cssPath, cb /*cb(css)*/) { compileAsync(options, "compiling", function (stylusText, stylusPath, cb) { stylus(stylusText) - .set('filename', stylusPath) - .use(nib()) - .render(function(err, css){ - if(err){ - throw new Error(err); - } - - cb(css); - }); + .set('filename', stylusPath) + .use(nib()) + .render(function(err, css){ + if(err){ + throw new Error(err); + } + + cb(css); + }); }, stylusText, stylusPath, cssPath, cb); } @@ -497,7 +497,7 @@ function compileAsync(options, mode, compileFn /*compileFn(text, textPath, cb(co fs.writeFile(compileTextPath, minText, 'utf-8', function(_) { cb(minText); }); - }); + }); } }; compileFn(text, textPath, onAfterCompiled);