3 function qunitVersion() {
4 var prepareStackTrace = Error.prepareStackTrace;
5 Error.prepareStackTrace = function() {
9 return require('qunit').version;
12 Error.prepareStackTrace = prepareStackTrace;
16 module.exports = function(grunt) {
17 // Force use of Unix newlines
18 grunt.util.linefeed = '\n';
21 pkg: grunt.file.readJSON('package.json'),
22 qunit_ver: qunitVersion(),
24 ' * HTMLMinifier v<%= pkg.version %> (<%= pkg.homepage %>)\n' +
25 ' * Copyright 2010-<%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
26 ' * Licensed under the <%= pkg.license %> license\n' +
32 banner: '<%= banner %>',
33 preBundleCB: function() {
34 var fs = require('fs');
35 var UglifyJS = require('uglify-js');
37 UglifyJS.FILES.forEach(function(file) {
38 files[file] = fs.readFileSync(file, 'utf8');
40 fs.writeFileSync('./dist/uglify.js', UglifyJS.minify(files, {
46 postBundleCB: function(err, src, next) {
47 require('fs').unlinkSync('./dist/uglify.js');
51 './dist/uglify.js:uglify-js',
52 './src/htmlminifier.js:html-minifier'
55 src: 'src/htmlminifier.js',
56 dest: 'dist/htmlminifier.js'
65 src: ['cli.js', 'src/**/*.js']
68 src: ['tests/*.js', 'test.js']
71 src: ['assets/master.js', 'assets/worker.js']
74 src: ['backtest.js', 'benchmark.js']
79 htmlminifier: ['./tests/minifier', 'tests/index.html']
84 /(<h1>.*?<span>).*?(<\/span><\/h1>)/,
85 '$1(v<%= pkg.version %>)$2'
87 './tests/index.html': [
88 /("[^"]+\/qunit-)[0-9.]+?(\.(?:css|js)")/g,
89 '$1<%= qunit_ver %>$2'
95 banner: '<%= banner %>',
98 preserveComments: false,
103 'dist/htmlminifier.min.js': '<%= browserify.src.dest %>'
109 grunt.loadNpmTasks('grunt-browserify');
110 grunt.loadNpmTasks('grunt-contrib-uglify');
111 grunt.loadNpmTasks('gruntify-eslint');
113 function report(type, details) {
114 grunt.log.writeln(type + ' completed in ' + details.runtime + 'ms');
115 details.failures.forEach(function(details) {
117 grunt.log.error(details.name + (details.message ? ' [' + details.message + ']' : ''));
118 grunt.log.error(details.source);
119 grunt.log.error('Actual:');
120 grunt.log.error(details.actual);
121 grunt.log.error('Expected:');
122 grunt.log.error(details.expected);
124 grunt.log[details.failed ? 'error' : 'ok'](details.passed + ' of ' + details.total + ' passed, ' + details.failed + ' failed');
125 return details.failed;
128 //var phantomjs = require('phantomjs-prebuilt').path;
129 //grunt.registerMultiTask('qunit', function() {
130 // var done = this.async();
133 // function run(testType, binPath, testPath) {
134 // grunt.util.spawn({
136 // args: ['test.js', testPath]
137 // }, function(error, result) {
139 // grunt.log.error(result.stderr);
140 // grunt.log.error(testType + ' test failed to load');
144 // var output = result.stdout;
145 // var index = output.lastIndexOf('\n');
146 // if (index !== -1) {
147 // // There's something before the report JSON
148 // // Log it to the console -- it's probably some debug output:
149 // console.log(output.slice(0, index));
150 // output = output.slice(index);
152 // errors.push(report(testType, JSON.parse(output)));
154 // if (errors.length === 2) {
155 // done(!errors[0] && !errors[1]);
160 // run('node', process.argv[0], this.data[0]);
161 // run('web', phantomjs, this.data[1]);
164 grunt.registerMultiTask('replace', function() {
165 var pattern = this.data[0];
166 var path = this.target;
167 var html = grunt.file.read(path);
168 html = html.replace(pattern, this.data[1]);
169 grunt.file.write(path, html);
172 grunt.registerTask('dist', [
178 //grunt.registerTask('test', [
184 //grunt.registerTask('default', 'test');