forked from krux/postscribe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
92 lines (80 loc) · 2.45 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*jshint node:true*/
module.exports = function(grunt) {
var pkg = grunt.file.readJSON('package.json');
// Autoload grunt plugins.
var _ = require('lodash');
_.filter(_.keys(pkg.devDependencies), function (key) {
return (/^grunt-/).test(key) && key !== 'grunt-cli';
}).forEach(grunt.loadNpmTasks);
// Project configuration.
grunt.initConfig({
pkg: pkg,
meta: {
banner: '/* <%= pkg.description %>, v<%= pkg.version %> <%= pkg.homepage %>\n' +
'Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>, MIT license ' +
'<%= pkg.licenses[0].url %> */'
},
jshint: {
// Grr, plugin keeps trying to iterate this...
jshintrc: './.jshintrc',
// Just for the 'node' src files
node: {
src: ['Gruntfile.js', 'test/generate_expected.phantom.js']
},
// Just for the 'browser' src files
browser: {
src: ['postscribe.js', 'htmlParser/htmlParser.js', 'test/test.js']
}
},
concat: {
options: {
banner: '<%= meta.banner %>'
},
dist: {
src: ['<%= meta.banner %>', 'htmlParser/htmlParser.js', 'postscribe.js'],
dest: 'dist/postscribe.js'
}
},
// Minify postscribe src to postscribe.min.js, prepending a banner
uglify: {
options: {
banner: '<%= meta.banner %>'
},
dist: {
files: {
'dist/postscribe.min.js': ['dist/postscribe.js']
}
}
},
qunit: {
files: ['test/test.html']
},
watch: {
files: ['postscribe.js', 'test/*'],
tasks: 'jshint qunit'
},
generate_expected: {
dest: 'test/expected.js',
index: '<%= qunit.files %>',
phantom: 'test/generate_expected.phantom.js'
}
});
grunt.registerTask('generate_expected', 'Generate Files', function() {
var done = this.async();
var data = grunt.config('generate_expected');
var args = [data.phantom, _.first(data.index), data.dest];
console.info(args);
grunt.util.spawn({cmd: './node_modules/.bin/phantomjs', args: args}, function(error, result) {
console.info('Done.');
if(error) {
console.error(result.stderr);
}
done(!error);
});
});
// Alias test
grunt.registerTask('test', ['generate_expected', 'qunit']);
grunt.registerTask('min', ['concat', 'uglify']);
// This is what gets run when you don't specify an argument for grunt.
grunt.registerTask('default', ['jshint', 'test']);
};