forked from gregjacobs/Class.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGruntfile.js
More file actions
132 lines (100 loc) · 3.44 KB
/
Gruntfile.js
File metadata and controls
132 lines (100 loc) · 3.44 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
/*global require, module */
/*jshint devel:true, latedef:false */
var execFile = require( 'child_process' ).execFile;
module.exports = function( grunt ) {
// Register main tasks
grunt.registerTask( 'default', "Default task runs JSHint and then builds the project.", [ 'build' ] );
grunt.registerTask( 'build', "Builds the distribution JavaScript files (Class.js, and Class.min.js)",
[ 'jshint', 'concat:dist', 'uglify:dist' ] );
grunt.registerTask( 'doc', "Builds the JavaScript documentation.", [ 'build', 'compileDocs' ] );
// Register sub-tasks. These aren't meant to be called directly, but are used as part of the main tasks.
grunt.registerTask( 'compileDocs', compileDocsTask );
// -----------------------------------
// Plugin Configurations
var banner = [
'/*!',
' * <%= pkg.name %>',
' * Version <%= pkg.version %>',
' *',
' * Copyright(c) 2013 Gregory Jacobs.',
' * MIT Licensed. http://www.opensource.org/licenses/mit-license.php',
' *',
' * <%= pkg.homepage %>',
' */\n'
].join( '\n' );
// Project configuration
grunt.initConfig( {
pkg: grunt.file.readJSON( 'package.json' ),
jshint: {
files: [ 'Gruntfile.js', 'src/**/*.js', 'tests/spec/**/*.js' ],
options : {
'smarttabs' : true,
'undef' : true,
'browser' : true
}
},
concat : {
'dist' : {
options : {
banner: banner
},
src : [ 'src/Class.js' ], // simply adding the banner
dest : 'dist/Class.js' // to the output file
}
},
uglify : {
'dist' : {
options: {
preserveComments : 'some' // preserve license header comments
},
files : {
'dist/Class.min.js' : [ 'dist/Class.js' ]
}
}
}
} );
// These plugins provide the tasks.
grunt.loadNpmTasks( 'grunt-contrib-jshint' );
grunt.loadNpmTasks( 'grunt-contrib-concat' );
grunt.loadNpmTasks( 'grunt-contrib-uglify' );
// -----------------------------------
// Other Functions / Tasks
/**
* Compiles the JavaScript documentation JSDuck, as part of the 'doc' task.
*
* Unfortunately, we can't use the 'grunt-jsduck' plugin because installing the JSDuck gem on Windows
* using `gem install` first involves a long set of installation steps to install the developer build
* tools needed to be able to compile the Ruby extensions needed by JSDuck's dependent libraries.
*
* Hence, it is much easier for developers to get set up by not doing anything at all (i.e., simply
* running the packaged JSDuck executable in the repository).
*/
function compileDocsTask() {
var done = this.async();
var executable = 'vendor/jsduck/jsduck-4.4.1.exe';
var args = [
'--output=docs',
'--title=Class.js API Docs',
'src/'
];
execFile( executable, args, function( err, stdout, stderr ) {
if( stdout ) console.log( stdout );
if( stderr ) console.log( stderr );
if( err ) {
// JSDuck command itself failed
grunt.log.error( "Documentation generation failed: " + err );
done( false );
return;
}
if( stdout || stderr ) {
// JSDuck produced errors/warnings
grunt.log.error( "Documentation generation produced warnings/errors. Please fix them, and try again." );
done( false );
return;
}
grunt.log.writeln( "Documentation generated successfully." );
grunt.log.writeln( "To publish the docs on github, copy the /docs folder into a checkout of the gh-pages branch, commit, and push that branch." );
done();
} );
}
};