Permalink
Browse files

Fixes #12. Making line splitting completely optional.

  • Loading branch information...
1 parent c89e1fa commit f3d7009f3194daee593ab4b17e4ff9fca63e5b56 @GoalSmashers GoalSmashers committed Sep 6, 2012
Showing with 58 additions and 6 deletions.
  1. +9 −5 bin/assetspkg
  2. +37 −1 test/binary-test.js
  3. +2 −0 test/data/test-js/assets.yml
  4. +10 −0 test/data/test-js/public/javascripts/one.js
View
@@ -13,15 +13,15 @@ var fs = require('fs'),
AssetsExpander = require('assets-expander'),
existsSync = fs.existsSync || path.existsSync;
+var maxConcurrent = require('os').cpus().length;
+var isWindows = process.platform == 'win32';
+
// Taken from MooTools 1.3
var escapeRegExp = function(s) {
return s.replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1');
};
-var maxConcurrent = require('os').cpus().length;
-var isWindows = process.platform == 'win32';
-
-// Init optimist arguments parsing
+// Parsing arguments
var argv = require('optimist').argv;
var options = {
@@ -30,6 +30,7 @@ var options = {
config: path.join(process.cwd(), argv.c || argv.config || 'config/assets.yml'),
gzip: argv.g || argv.gzip || false,
indentLevel: argv.i || argv.indent || 0,
+ lineBreakAt: argv.l || argv['line-break-at'] || undefined,
noEmbedVersion: argv.n || argv.noembedversion || false,
noMinifyJS: argv.nm || argv.nominifyjs || false,
only: argv.o || argv.only || undefined,
@@ -67,6 +68,7 @@ if (argv.h || argv.help) {
util.puts(" -h, --help\t\tYou are staring at it!");
util.puts(" --nm, --nominifyjs\tOnly combine JS files, do not minify them (defaults to false).");
util.puts(" -i, --indent\t\tWhen using --nm, specify the indentation level in spaces.");
+ util.puts(" -l, --line-break-at\tNumber of characters per line in optimized JavaScript (defaults to off which means no line splitting).");
util.puts(" -o, --only\t\tPackage only given assets group (or groups if separated by comma).");
util.puts(" --pj, --js-path\tPath to JavaScript root directory (relative to --root option).");
util.puts(" --ps, --styles-path\tPath to Stylesheets root directory (relative to --root option).");
@@ -283,7 +285,9 @@ var processGroup = function(type, group, callback) {
ast = uglify.uglify.ast_mangle(ast);
ast = uglify.uglify.ast_squeeze(ast);
data = uglify.uglify.gen_code(ast);
- data = uglify.uglify.split_lines(data, 80);
+ data = options.lineBreakAt ?
+ uglify.uglify.split_lines(data, options.lineBreakAt) :
+ data;
}
if (options.cacheBoosters) {
View
@@ -606,7 +606,7 @@ exports.javascriptOptimizing = vows.describe('javascript optimizing').addBatch({
'data': function(error, data) {
if (error) throw error;
- assert.equal(["function factorial(a){return a==0?1:a*factorial(a-1)}for(var i=0,j=factorial(10).", "toString(),k=j.length;i<k;i++)console.log(j[i])"].join('\n'),
+ assert.equal("function factorial(a){return a==0?1:a*factorial(a-1)}for(var i=0,j=factorial(10).toString(),k=j.length;i<k;i++)console.log(j[i])",
data);
}
},
@@ -626,6 +626,42 @@ exports.javascriptOptimizing = vows.describe('javascript optimizing').addBatch({
}
}
}).addBatch({
+ 'no line breaking by default': {
+ topic: withOptions('-r data/test-js/public -c data/test-js/assets.yml'),
+ 'should not give error': function(error, stdout) {
+ assert.isNull(error);
+ },
+ 'should not break file at': {
+ topic: function() {
+ fs.readFile(fullPath('test/data/test-js/public/javascripts/bundled/all.js'), 'utf-8', this.callback);
+ },
+ 'any character': function(error, data) {
+ assert.equal("var a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0", data);
+ }
+ },
+ teardown: function() {
+ cleanBundles('test-js');
+ }
+ }
+}).addBatch({
+ 'correct line breaking': {
+ topic: withOptions('-r data/test-js/public -c data/test-js/assets.yml -l 10'),
+ 'should not give error': function(error, stdout) {
+ assert.isNull(error);
+ },
+ 'should break file at': {
+ topic: function() {
+ fs.readFile(fullPath('test/data/test-js/public/javascripts/bundled/all.js'), 'utf-8', this.callback);
+ },
+ '10 characters': function(error, data) {
+ assert.equal("var a=0,b=0\n,c=0,d=0,e=0\n,f=0,g=0,h=0\n,i=0,j=0", data);
+ }
+ },
+ teardown: function() {
+ cleanBundles('test-js');
+ }
+ }
+}).addBatch({
'no JS minification': {
topic: withOptions('-r data/test3/public --nm -i 2 -c data/test3/assets.yml'),
'for optimizations.js': {
@@ -0,0 +1,2 @@
+javascripts:
+ all: 'one'
@@ -0,0 +1,10 @@
+var a = 0,
+ b = 0,
+ c = 0,
+ d = 0,
+ e = 0,
+ f = 0,
+ g = 0,
+ h = 0,
+ i = 0,
+ j = 0;

0 comments on commit f3d7009

Please sign in to comment.