44module . exports = function ( grunt ) {
55
66 var pkg = grunt . file . readJSON ( 'package.json' ) ;
7+ var year = new Date ( ) . getFullYear ( )
78 var banner = '\
89/*\n\
9- * SIP version <%= pkg.version %> \n\
10- * Copyright (c) 2014-<%= grunt.template.today("yyyy") %> Junction Networks, Inc <http://www.onsip.com>\n\
10+ * SIP version ' + pkg . version + ' \n\
11+ * Copyright (c) 2014-' + year + ' Junction Networks, Inc <http://www.onsip.com>\n\
1112 * Homepage: http://sipjs.com\n\
1213 * License: http://sipjs.com/license/\n\
1314 *\n\
@@ -23,10 +24,10 @@ module.exports = function(grunt) {
2324 * distribute, sublicense, and/or sell copies of the Software, and to\n\
2425 * permit persons to whom the Software is furnished to do so, subject to\n\
2526 * the following conditions:\n\
26- * \n\
27+ *\n\
2728 * The above copyright notice and this permission notice shall be\n\
2829 * included in all copies or substantial portions of the Software.\n\
29- * \n\
30+ *\n\
3031 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\n\
3132 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n\
3233 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n\
@@ -47,41 +48,36 @@ module.exports = function(grunt) {
4748 } ,
4849 browserify : {
4950 devel : {
50- src : 'src/SIP.js' ,
51+ src : pkg . main ,
5152 dest : 'dist/<%= name %>-<%= pkg.version %>.js'
5253 } ,
5354 options : {
5455 bundleOptions : {
5556 standalone : 'SIP'
5657 } ,
5758 postBundleCB : function ( err , src , next ) {
58- // prepend the banner and fill in placeholders
59- src = ( banner + src ) . replace ( / < % = ( .* ) % > / g, function ( match , expr ) {
60- // jshint evil:true
61- return eval ( expr ) ;
62- } ) ;
63- next ( err , src ) ;
59+ // prepend the banner
60+ next ( err , banner + src ) ;
6461 }
6562 }
6663 } ,
6764 copy : {
65+ min : {
66+ src : 'dist/<%= name %>-<%= pkg.version %>.min.js' ,
67+ dest : 'dist/<%= name %>.min.js'
68+ } ,
6869 dist : {
6970 src : 'dist/<%= name %>-<%= pkg.version %>.js' ,
7071 dest : 'dist/<%= name %>.js'
7172 }
7273 } ,
7374 jshint : {
74- src : 'src/**/*.js' ,
75+ src : [ 'src/**/*.js' , "!src/polyfills/**/*.js" , "!src/Grammar/dist/Grammar.js" ] ,
7576 options : {
7677 jshintrc : true
7778 }
7879 } ,
7980 uglify : {
80- dist : {
81- files : {
82- 'dist/<%= name %>.min.js' : [ 'dist/<%= name %>.js' ]
83- }
84- } ,
8581 devel : {
8682 files : {
8783 'dist/<%= name %>-<%= pkg.version %>.min.js' : [ 'dist/<%= name %>-<%= pkg.version %>.js' ]
@@ -102,6 +98,7 @@ module.exports = function(grunt) {
10298 options : {
10399 specs : 'test/spec/*.js' ,
104100 keepRunner : true ,
101+ vendor : 'test/polyfills/*.js' ,
105102 helpers : 'test/helpers/*.js'
106103 }
107104 }
@@ -110,38 +107,7 @@ module.exports = function(grunt) {
110107 grammar : {
111108 src : 'src/Grammar/src/Grammar.pegjs' ,
112109 dest : 'src/Grammar/dist/Grammar.js' ,
113- options : {
114- optimize : 'size' ,
115- allowedStartRules : [
116- 'Contact' ,
117- 'Name_Addr_Header' ,
118- 'Record_Route' ,
119- 'Request_Response' ,
120- 'SIP_URI' ,
121- 'Subscription_State' ,
122- 'Via' ,
123- 'absoluteURI' ,
124- 'Call_ID' ,
125- 'Content_Disposition' ,
126- 'Content_Length' ,
127- 'Content_Type' ,
128- 'CSeq' ,
129- 'displayName' ,
130- 'Event' ,
131- 'From' ,
132- 'host' ,
133- 'Max_Forwards' ,
134- 'Proxy_Authenticate' ,
135- 'quoted_string' ,
136- 'Refer_To' ,
137- 'stun_URI' ,
138- 'To' ,
139- 'turn_URI' ,
140- 'uuid' ,
141- 'WWW_Authenticate' ,
142- 'challenge'
143- ]
144- }
110+ options : require ( './src/Grammar/peg.json' )
145111 }
146112 } ,
147113 trimtrailingspaces : {
@@ -166,46 +132,24 @@ module.exports = function(grunt) {
166132 grunt . loadNpmTasks ( 'grunt-peg' ) ;
167133 grunt . loadNpmTasks ( 'grunt-trimtrailingspaces' ) ;
168134
169-
170- // Task for building SIP.js Grammar.js and Grammar.min.js files.
171- grunt . registerTask ( 'post_peg' , function ( ) {
172- // Modify the generated Grammar.js file with custom changes.
173- console . log ( '"grammar" task: applying custom changes to Grammar.js ...' ) ;
174- var fs = require ( 'fs' ) ;
175- var grammar = fs . readFileSync ( 'src/Grammar/dist/Grammar.js' ) . toString ( ) ;
176- var modified_grammar = grammar . replace ( / t h r o w p e g .* m a x F a i l P o s .* / , 'return -1;' ) ;
177- modified_grammar = modified_grammar . replace ( / r e t u r n p e g .* r e s u l t .* / , 'return data;' ) ;
178- modified_grammar = modified_grammar . replace ( / p a r s e : ( * ) p a r s e / , 'parse:$1function (input, startRule) {return parse(input, {startRule: startRule});}' ) ;
179- modified_grammar = modified_grammar . replace ( / \( f u n c t i o n \( \) / , 'function(SIP)' ) . replace ( / \} \) \( \) / , '}' ) ;
180-
181- // Don't jshint this big chunk of minified code
182- modified_grammar =
183- "/* jshint ignore:start */\n" +
184- modified_grammar +
185- "\n/* jshint ignore:end */\n" ;
186-
187- fs . writeFileSync ( 'src/Grammar/dist/Grammar.js' , modified_grammar ) ;
188- console . log ( 'OK' ) ;
189- } ) ;
190-
191- grunt . registerTask ( 'grammar' , [ 'peg' , 'post_peg' ] ) ;
135+ grunt . registerTask ( 'grammar' , [ 'peg' ] ) ;
192136
193137 // Task for building sip-devel.js (uncompressed), sip-X.Y.Z.js (uncompressed)
194138 // and sip-X.Y.Z.min.js (minified).
195139 // Both sip-devel.js and sip-X.Y.Z.js are the same file with different name.
196- grunt . registerTask ( 'build' , [ 'trimtrailingspaces:main' , 'devel' , 'copy ' , 'uglify ' ] ) ;
140+ grunt . registerTask ( 'build' , [ 'trimtrailingspaces:main' , 'devel' , 'uglify ' , 'copy ' ] ) ;
197141
198142 // Task for building sip-devel.js (uncompressed).
199- grunt . registerTask ( 'devel' , [ 'jshint' , 'browserify ' ] ) ;
143+ grunt . registerTask ( 'devel' , [ 'jshint' , 'quick ' ] ) ;
200144
201- grunt . registerTask ( 'quick' , [ 'browserify' ] ) ;
145+ grunt . registerTask ( 'quick' , [ 'grammar' , ' browserify'] ) ;
202146
203147 // Test tasks.
204148 grunt . registerTask ( 'test' , [ 'jasmine' ] ) ;
205149
206150 // Travis CI task.
207151 // Doc: http://manuel.manuelles.nl/blog/2012/06/22/integrate-travis-ci-into-grunt/
208- grunt . registerTask ( 'travis' , [ 'grammar' , ' devel', 'test' ] ) ;
152+ grunt . registerTask ( 'travis' , [ 'devel' , 'test' ] ) ;
209153
210154 // Default task is an alias for 'build'.
211155 // I know this is annoying... but you could always do grunt build. This encourages better code testing! --Eric Green
0 commit comments