-
Notifications
You must be signed in to change notification settings - Fork 78
/
grunt.js
106 lines (92 loc) · 2.29 KB
/
grunt.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* Resources
*
* https://gist.github.com/2489540
*
*/
/*jshint node: true */
/*global config:true, task:true, process:true*/
module.exports = function( grunt ) {
// readOptionalJSON
// by Ben Alman
// https://gist.github.com/2876125
function readOptionalJSON( filepath ) {
var data = {};
try {
data = grunt.file.readJSON( filepath );
grunt.verbose.write( "Reading " + filepath + "..." ).ok();
} catch(e) {}
return data;
}
function jshintrc( path ) {
return readOptionalJSON( ( path || "" ) + ".jshintrc" ) || {};
}
var distpaths = [
"dist/ajaxhooks.js",
"dist/ajaxhooks.min.js"
],
files = (function() {
var files = [ "build/intro.js" ];
grunt.file.recurse( "src", function( path ) {
if ( /\.js$/.test( path ) ) {
files.push( path );
}
});
files.push( "build/outro.js" );
return files;
})();
grunt.initConfig({
pkg: "<json:package.json>",
dst: "dist",
build: {
"dist/ajaxhooks.js": files
},
min: {
"dist/ajaxhooks.min.js": [ "dist/ajaxhooks.js" ]
},
lint: {
src: "src/*.js",
dist: "dist/ajaxhooks.js",
tests: "test/unit/*.js",
grunt: "grunt.js"
},
jshint: {
options: jshintrc(),
src: jshintrc( "src/" ),
dist: jshintrc( "src/" ),
tests: jshintrc( "test/" )
},
uglify: {}
});
grunt.loadNpmTasks("grunt-update-submodules");
grunt.registerTask( "default", "update_submodules build lint min" );
grunt.registerMultiTask(
"build",
"Concatenate source (include/exclude modules with +/- flags), embed date/version",
function() {
// Concat specified files.
var name = this.file.dest,
version = grunt.config( "pkg.version" ),
compiled = "";
// append commit id to version
if ( process.env.COMMIT ) {
version += "-" + process.env.COMMIT;
}
// conditionally concatenate source
this.file.src.forEach(function( filepath ) {
compiled += grunt.file.read( filepath );
});
// Embed Date
// Embed Version
compiled = compiled.replace( "@DATE", new Date() )
.replace( /@VERSION/g, version );
// Write concatenated source to file
grunt.file.write( name, compiled );
// Fail task if errors were logged.
if ( this.errorCount ) {
return false;
}
// Otherwise, print a success message.
grunt.log.writeln( "File '" + name + "' created." );
});
};