Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usemin without uglify plus non-ugly testification #153

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 98 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function(grunt) {
files: [{
expand: true,
cwd: 'test/fixtures',
src: ['usemin.html', 'usemin/*'],
src: ['usemin.html', 'useminUgly.html', 'usemin/*', 'useminUgly/*'],
dest: 'tmp/'
}]
}
Expand Down Expand Up @@ -47,13 +47,39 @@ module.exports = function(grunt) {
}
},
usemin: {
html: 'tmp/useminUgly.html'
},
useminWithoutUglify: {
html: 'tmp/usemin.html'
},
useminPrepare: {
html: 'test/fixtures/useminUgly.html',
options: {
dest: 'tmp',
staging: 'tmp',
flow: {
html: {
steps: {
js: ['concat', 'uglify'],
css: ['concat', 'cssmin']
}
}
}
}
},
useminPrepareWithoutUglify: {
html: 'test/fixtures/usemin.html',
options: {
dest: 'tmp',
staging: 'tmp'
staging: 'tmp',
flow: {
html: {
steps: {
js: ['concat'],
css: ['concat']
}
}
}
}
},
cssmin: {},
Expand Down Expand Up @@ -93,15 +119,15 @@ module.exports = function(grunt) {
src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
dest: 'tmp/custom_concat_usemin.js',
options: {
usemin: 'usemin/all.js'
usemin: 'useminUgly/all.js'
}
},

custom_usemin_not_found: {
src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
dest: 'tmp/custom_concat_usemin_not_found.js',
options: {
usemin: 'usemin/not_found.js'
usemin: 'useminUgly/not_found.js'
}
},

Expand Down Expand Up @@ -264,10 +290,62 @@ module.exports = function(grunt) {
regexp: {
src: 'test/fixtures/regexp.html',
dest: 'tmp/regexp.js'
},

usemin_no_uglify: {
src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
dest: 'tmp/custom_concat_usemin_no_uglify.js',
options: {
usemin: 'usemin/all.js'
}
}
}
});

grunt.registerTask('useminPrepareWithoutUglify', function () {
grunt.config.set('concat.generated', null);
grunt.config.set('uglify.generated', null);
var useminPrepareWithoutUglify = grunt.config('useminPrepareWithoutUglify');
grunt.config.set('useminPrepare', useminPrepareWithoutUglify);
grunt.task.run('useminPrepare');
});

grunt.registerTask('useminWithoutUglify', function () {
var useminWithoutUglify = grunt.config('useminWithoutUglify');
grunt.config.set('usemin', useminWithoutUglify);
grunt.task.run('usemin');
});

var prettyTemplates = [
'usemin_no_uglify'
];

grunt.registerTask('uglyTemplates', function(){
var templateKeys = Object.keys(grunt.config('ngtemplates'));
var tasks = [];

for(var i in templateKeys){
if(prettyTemplates.indexOf(templateKeys[i]) === -1){
tasks.push('ngtemplates:' + templateKeys[i]);
}
}

grunt.task.run(tasks);
});

grunt.registerTask('prettyTemplates', function(){
var templateKeys = Object.keys(grunt.config('ngtemplates'));
var tasks = [];

for(var i in templateKeys){
if(prettyTemplates.indexOf(templateKeys[i]) !== -1){
tasks.push('ngtemplates:' + templateKeys[i]);
}
}

grunt.task.run(tasks);
});

// Load local tasks.
grunt.loadTasks('tasks');
grunt.loadNpmTasks('grunt-contrib-clean');
Expand All @@ -279,5 +357,20 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-usemin');

grunt.registerTask('default', ['jshint', 'clean', 'copy', 'useminPrepare', 'ngtemplates', 'concat', 'uglify', 'cssmin', 'usemin', 'nodeunit']);
grunt.registerTask('default', [
'jshint',
'clean',
'copy',
'useminPrepare',
'uglyTemplates',
'concat',
'uglify',
'cssmin',
'usemin',
'useminPrepareWithoutUglify',
'prettyTemplates',
'concat',
'useminWithoutUglify',
'nodeunit'
]);
};
11 changes: 8 additions & 3 deletions tasks/lib/appender.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,14 @@ var Appender = function(grunt) {
*/
this.concatUseminFiles = function(path, file) {
var config = grunt.config('uglify.generated');
var willUglify = !!config;

if (!config) {
grunt.log.warn('Usemin has not created ' + 'uglify.generated'.red + ' yet!');
config = grunt.config('concat.generated');
}

if (!config) {
grunt.log.warn('Usemin has not created ' + 'uglify.generated'.red + ' or ' + 'concat.generated'.red + ' yet!');

return false;
}
Expand Down Expand Up @@ -101,11 +106,11 @@ var Appender = function(grunt) {
grunt.log.warn('Multiple matches for ' + path.yellow + '. Using ' + match.dest);
}

var uglified = match.src.pop();
var target = willUglify ? match.src.pop() : match.dest;

// Finally, modify concat target sourced by matching uglify target
return this.concatFiles('generated', file, function(files) {
return uglified === files.dest;
return target === files.dest;
});
};

Expand Down
20 changes: 16 additions & 4 deletions test/angular-templates_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,22 @@ exports.ngtemplates = {
custom_usemin: function(test) {
test.expect(5);

test.equal(grunt.file.read('test/expected/useminUgly.html'), grunt.file.read('tmp/useminUgly.html'));
test.equal(grunt.file.read('test/expected/useminUgly/foo.js').slice(0, -1), grunt.file.read('tmp/useminUgly/foo.js'));
test.equal(grunt.file.read('test/expected/useminUgly/bar.js').slice(0, -1), grunt.file.read('tmp/useminUgly/bar.js'));
test.equal(grunt.file.read('test/expected/useminUgly/all.js').slice(0, -1), grunt.file.read('tmp/useminUgly/all.js'));
test.equal(grunt.file.read('test/expected/useminUgly/bar.css'), grunt.file.read('tmp/useminUgly/bar.css'));

test.done();
},

custom_usemin_no_uglify: function(test) {
test.expect(5);

test.equal(grunt.file.read('test/expected/usemin.html'), grunt.file.read('tmp/usemin.html'));
test.equal(grunt.file.read('test/expected/usemin/foo.js').slice(0, -1), grunt.file.read('tmp/usemin/foo.js'));
test.equal(grunt.file.read('test/expected/usemin/bar.js').slice(0, -1), grunt.file.read('tmp/usemin/bar.js'));
test.equal(grunt.file.read('test/expected/usemin/all.js').slice(0, -1), grunt.file.read('tmp/usemin/all.js'));
test.equal(grunt.file.read('test/expected/usemin/foo.js'), grunt.file.read('tmp/usemin/foo.js'));
test.equal(grunt.file.read('test/expected/usemin/bar.js'), grunt.file.read('tmp/usemin/bar.js'));
test.equal(grunt.file.read('test/expected/usemin/all.js'), grunt.file.read('tmp/usemin/all.js'));
test.equal(grunt.file.read('test/expected/usemin/bar.css'), grunt.file.read('tmp/usemin/bar.css'));

test.done();
Expand Down Expand Up @@ -240,5 +252,5 @@ exports.ngtemplates = {
test.equal(expected, actual);
test.done();
}

};
38 changes: 37 additions & 1 deletion test/expected/usemin/all.js
Original file line number Diff line number Diff line change
@@ -1 +1,37 @@
var Foo=function(){},Bar="bar";angular.module("custom_usemin").run(["$templateCache",function(a){"use strict";a.put("test/fixtures/one.html",'<h1>One</h1>\n\n<p class="">I am one.</p>\n\n<script type="text/javascript">\n // Test\n /* comments */\n var foo = \'bar\';\n</script>\n'),a.put("test/fixtures/two/two.html",'<h2>Two</h2>\n\n<!-- Comment for two -->\n\n<textarea readonly="readonly">We are two.</textarea>\n')}]);
/**
* foo.js
*/

var Foo = function() {};

/**
* bar.js
*/

var Bar = 'bar';

angular.module('usemin_no_uglify').run(['$templateCache', function($templateCache) {
'use strict';

$templateCache.put('test/fixtures/one.html',
"<h1>One</h1>\n" +
"\n" +
"<p class=\"\">I am one.</p>\n" +
"\n" +
"<script type=\"text/javascript\">\n" +
" // Test\n" +
" /* comments */\n" +
" var foo = 'bar';\n" +
"</script>\n"
);


$templateCache.put('test/fixtures/two/two.html',
"<h2>Two</h2>\n" +
"\n" +
"<!-- Comment for two -->\n" +
"\n" +
"<textarea readonly=\"readonly\">We are two.</textarea>\n"
);

}]);
9 changes: 8 additions & 1 deletion test/expected/usemin/bar.css
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
body{color:#000;background:#fff}
/**
* bar.css
*/

body {
color: #000;
background: #fff;
}
6 changes: 5 additions & 1 deletion test/expected/usemin/bar.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
var Bar="bar";
/**
* bar.js
*/

var Bar = 'bar';
6 changes: 5 additions & 1 deletion test/expected/usemin/foo.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
var Foo=function(){};
/**
* foo.js
*/

var Foo = function() {};
18 changes: 18 additions & 0 deletions test/expected/useminUgly.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="styles/main.css">
<script src="scripts/vendor/modernizr.min.js"></script>
</head>
<body>

<script src="useminUgly/foo.js"></script>

<script src="useminUgly/bar.js"></script>

<script src="useminUgly/all.js"></script>

<script src="duplicate/useminUgly/all.js"></script>

<link rel="stylesheet" href="useminUgly/bar.css">
</body>
</html>
1 change: 1 addition & 0 deletions test/expected/useminUgly/all.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/expected/useminUgly/bar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body{color:#000;background:#fff}
1 change: 1 addition & 0 deletions test/expected/useminUgly/bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var Bar="bar";
1 change: 1 addition & 0 deletions test/expected/useminUgly/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var Foo=function(){};
30 changes: 30 additions & 0 deletions test/fixtures/useminUgly.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="styles/main.css">
<script src="scripts/vendor/modernizr.min.js"></script>
</head>
<body>

<!-- build:js useminUgly/foo.js -->
<script src="useminUgly/foo.js"></script>
<!-- endbuild -->

<!-- build:js useminUgly/bar.js -->
<script src="useminUgly/bar.js"></script>
<!-- endbuild -->

<!-- build:js useminUgly/all.js -->
<script src="useminUgly/foo.js"></script>
<script src="useminUgly/bar.js"></script>
<!-- endbuild -->

<!-- build:js duplicate/useminUgly/all.js -->
<script src="useminUgly/foo.js"></script>
<script src="useminUgly/bar.js"></script>
<!-- endbuild -->

<!-- build:css useminUgly/bar.css -->
<script src="useminUgly/bar.css"></script>
<!-- endbuild -->
</body>
</html>
8 changes: 8 additions & 0 deletions test/fixtures/useminUgly/bar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* bar.css
*/

body {
color: #000;
background: #fff;
}
5 changes: 5 additions & 0 deletions test/fixtures/useminUgly/bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* bar.js
*/

var Bar = 'bar';
5 changes: 5 additions & 0 deletions test/fixtures/useminUgly/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* foo.js
*/

var Foo = function() {};