-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGruntfile.js
More file actions
158 lines (132 loc) · 3.96 KB
/
Copy pathGruntfile.js
File metadata and controls
158 lines (132 loc) · 3.96 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*global require, module */
/*jshint devel:true, latedef:false */
var execFile = require( 'child_process' ).execFile;
module.exports = function( grunt ) {
// Register Tasks
grunt.registerTask( 'default', [ 'jshint', 'build', 'jasmine' ] );
grunt.registerTask( 'build', [ 'concat:development', 'uglify:production' ] );
grunt.registerTask( 'doc', "Builds the documentation.", [ 'jshint', 'build', 'jsduck' ] );
// Plugins Configurations
grunt.loadNpmTasks( 'grunt-contrib-jshint' );
grunt.loadNpmTasks( 'grunt-contrib-jasmine' );
grunt.loadNpmTasks( 'grunt-contrib-concat' );
grunt.loadNpmTasks( 'grunt-contrib-uglify' );
grunt.loadNpmTasks( 'grunt-jsduck' );
// -----------------------------------
// Project Configuration
grunt.initConfig( {
pkg: grunt.file.readJSON( 'package.json' ),
jshint: {
files: {
src: [ 'Gruntfile.js', 'src/**/*.js', 'tests/spec/**/*.js' ]
}
},
jasmine: {
dist: {
options: {
specs: 'tests/**/*Spec.js'
},
src: 'dist/Class.min.js' // test the minified file
}
},
concat: {
'development' : {
options: {
banner : createBanner() + createDistFileHeader(),
footer : createDistFileFooter(),
nonull : true,
process : function( src, filepath ) {
return '\t' + src.replace( /\n/g, '\n\t' ); // indent each source file, which is placed inside the UMD block
}
},
src: [
'src/Class.js',
'src/ClassBuilder.js',
'src/Util.js'
],
dest: 'dist/Class.js'
}
},
uglify : {
'production' : {
options: {
preserveComments : 'some' // preserve license header comments
},
files : {
'dist/Class.min.js' : [ 'dist/Class.js' ]
}
}
},
jsduck: {
main: {
src: [
'src/**/*.js'
],
dest: 'docs', // output dir
options: {
'title': 'Class.js API Docs',
'warnings' : [ '-req_after_opt' ] // don't warn about optional method parameters coming before required ones
}
}
}
} );
// -----------------------------------
// Other Functions / Tasks
/**
* Creates the banner comment with license header that is placed over the concatenated/minified files.
*
* @private
* @return {String}
*/
function createBanner() {
return [
'/*!',
' * Class.js',
' * Version <%= pkg.version %>',
' *',
' * Copyright(c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %> <<%= pkg.author.email %>>',
' * <%= pkg.license %>',
' *',
' * <%= pkg.homepage %>',
' */\n'
].join( "\n" );
}
/**
* Creates the UMD (Universal Module Definition) header, which defines Class as one of the following when loaded:
*
* 1. An AMD module, if an AMD loader is available (such as RequireJS)
* 2. A CommonJS module, if a CommonJS module environment is available (such as Node.js), or
* 3. A global variable, `Class`, if the others are unavailable.
*
* This UMD header is combined with the UMD footer to create the distribution JavaScript file.
*
* @private
* @return {String}
*/
function createDistFileHeader() {
return [
";( function( root, factory ) {", // note: prefixed ';' if Class.js is concatenated after a library that does not end in a ';' itself
"\tif( typeof define === 'function' && define.amd ) {",
"\t\tdefine( factory ); // Define as AMD module if an AMD loader is present (ex: RequireJS).",
"\t} else if( typeof exports !== 'undefined' ) {",
"\t\tmodule.exports = factory(); // Define as CommonJS module for Node.js, if available.",
"\t} else {",
"\t\troot.Class = factory(); // Finally, define as a browser global if no module loader.",
"\t}",
"}( this, function() {\n\n"
].join( "\n" );
}
/**
* Creates the UMD (Universal Module Definition) footer. See {@link #createDistFileHeader} for details.
*
* @private
* @return {String}
*/
function createDistFileFooter() {
var umdEnd = [
'\n\n\treturn Class;\n',
'} ) );'
];
return umdEnd.join( "\n" );
}
};