forked from onsip/SIP.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGruntfile.js
246 lines (228 loc) · 7.94 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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*global module:false*/
module.exports = function(grunt) {
var srcFiles = [
'src/SIP.js',
'src/LoggerFactory.js',
'src/EventEmitter.js',
'src/Constants.js',
'src/Exceptions.js',
'src/Timers.js',
'src/Transport.js',
'src/Parser.js',
'src/SIPMessage.js',
'src/URI.js',
'src/NameAddrHeader.js',
'src/Transactions.js',
'src/Dialogs.js',
'src/RequestSender.js',
'src/RegisterContext.js',
'src/Message.js',
'src/ClientContext.js',
'src/ServerContext.js',
'src/Session.js',
'src/UA.js',
'src/Utils.js',
'src/SanityCheck.js',
'src/DigestAuthentication.js',
'src/WebRTC.js',
'src/tail.js'
];
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
meta: {
banner: '\
/*\n\
* SIP version <%= pkg.version %>\n\
* Copyright (c) 2014-<%= grunt.template.today("yyyy") %> Junction Networks, Inc <http://www.onsip.com>\n\
* Homepage: http://sipjs.com\n\
* License: http://sipjs.com/license/\n\
*\n\
*\n\
* ~~~SIP.js contains substantial portions of JsSIP under the following license~~~\n\
* Homepage: http://jssip.net\n\
* Copyright (c) 2012-2013 José Luis Millán - Versatica <http://www.versatica.com> \n\
*\n\
* Permission is hereby granted, free of charge, to any person obtaining\n\
* a copy of this software and associated documentation files (the\n\
* "Software"), to deal in the Software without restriction, including\n\
* without limitation the rights to use, copy, modify, merge, publish,\n\
* distribute, sublicense, and/or sell copies of the Software, and to\n\
* permit persons to whom the Software is furnished to do so, subject to\n\
* the following conditions:\n\
* \n\
* The above copyright notice and this permission notice shall be\n\
* included in all copies or substantial portions of the Software.\n\
* \n\
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\n\
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n\
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n\
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\n\
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n\
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\n\
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\
*\n\
* ~~~ end JsSIP license ~~~\n\
*/\n\n\n'
},
concat: {
dist: {
src: srcFiles,
dest: 'dist/<%= pkg.name %>-<%= pkg.version %>.js',
options: {
banner: '<%= meta.banner %>',
separator: '\n\n',
process: true
},
nonull: true
},
post_dist: {
src: [
'dist/<%= pkg.name %>-<%= pkg.version %>.js',
'src/Grammar/dist/Grammar.js',
'src/SDP/dist/SDP.js'
],
dest: 'dist/<%= pkg.name %>-<%= pkg.version %>.js',
nonull: true
},
devel: {
src: srcFiles,
dest: 'dist/<%= pkg.name %>-devel.js',
options: {
banner: '<%= meta.banner %>',
separator: '\n\n',
process: true
},
nonull: true
},
post_devel: {
src: [
'dist/<%= pkg.name %>-devel.js',
'src/Grammar/dist/Grammar.js',
'src/SDP/dist/SDP.js'
],
dest: 'dist/<%= pkg.name %>-devel.js',
nonull: true
}
},
includereplace: {
dist: {
files: {
'dist': 'dist/<%= pkg.name %>-<%= pkg.version %>.js'
}
},
devel: {
files: {
'dist': 'dist/<%= pkg.name %>-devel.js'
}
}
},
jshint: {
dist: 'dist/<%= pkg.name %>-<%= pkg.version %>.js',
devel: 'dist/<%= pkg.name %>-devel.js',
options: {
browser: true,
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: false,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
onecase: true,
unused: true,
supernew: true,
globals: {
module: true,
define: true
}
}
},
uglify: {
dist: {
files: {
'dist/<%= pkg.name %>-<%= pkg.version %>.min.js': ['dist/<%= pkg.name %>-<%= pkg.version %>.js']
}
},
options: {
banner: '<%= meta.banner %>'
}
},
jasmine: {
components: {
src: [
'dist/sip-devel.js'
],
options: {
specs: 'test/spec/*.js',
keepRunner : true,
helpers: 'test/helpers/*.js'
}
}
}
});
// Load Grunt plugins.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-include-replace');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-jasmine');
// Task for building SIP.js Grammar.js and Grammar.min.js files.
grunt.registerTask('grammar', function(){
var done = this.async(); // This is an async task.
var sys = require('sys');
var exec = require('child_process').exec;
var child;
// First compile SIP.js grammar with PEGjs.
console.log('"grammar" task: compiling SIP.js PEGjs grammar into Grammar.js ...');
child = exec('if [ -x "./node_modules/pegjs/bin/pegjs" ] ; then PEGJS="./node_modules/pegjs/bin/pegjs"; else PEGJS="pegjs" ; fi && $PEGJS -e SIP.Grammar src/Grammar/src/Grammar.pegjs src/Grammar/dist/Grammar.js', function(error, stdout, stderr) {
if (error) {
sys.print('ERROR: ' + stderr);
done(false); // Tell grunt that async task has failed.
}
console.log('OK');
// Then modify the generated Grammar.js file with custom changes.
console.log('"grammar" task: applying custom changes to Grammar.js ...');
var fs = require('fs');
var grammar = fs.readFileSync('src/Grammar/dist/Grammar.js').toString();
var modified_grammar = grammar.replace(/throw new this\.SyntaxError\(([\s\S]*?)\);([\s\S]*?)}([\s\S]*?)return result;/, 'new this.SyntaxError($1);\n return -1;$2}$3return data;');
fs.writeFileSync('src/Grammar/dist/Grammar.js', modified_grammar);
console.log('OK');
done(); // Tell grunt that async task has succeeded.
});
});
// Task for building SIP.js SDP.js and SDP.min.js files.
grunt.registerTask('sdp', function(){
var done = this.async(); // This is an async task.
var sys = require('sys');
var exec = require('child_process').exec;
var child;
// Build a bundle of 'sdp-transform' for the browser.
console.log('"sdp" task: getting SIP parser from "sdp-transform" ...');
child = exec('browserify src/SDP/main.js -o src/SDP/dist/SDP.js', function(error, stdout, stderr) {
if (error) {
sys.print('ERROR: ' + stderr);
done(false); // Tell grunt that async task has failed.
}
console.log('OK');
done(); // Tell grunt that async task has succeeded.
});
});
// Task for building sip-devel.js (uncompressed), sip-X.Y.Z.js (uncompressed)
// and sip-X.Y.Z.min.js (minified).
// Both sip-devel.js and sip-X.Y.Z.js are the same file with different name.
grunt.registerTask('build', ['concat:devel', 'includereplace:devel', 'jshint:devel', 'concat:post_devel', 'concat:dist', 'includereplace:dist', 'jshint:dist', 'concat:post_dist', 'uglify:dist']);
// Task for building sip-devel.js (uncompressed).
grunt.registerTask('devel', ['concat:devel', 'includereplace:devel', 'jshint:devel', 'concat:post_devel']);
// Test tasks.
grunt.registerTask('test',['jasmine']);
// Travis CI task.
// Doc: http://manuel.manuelles.nl/blog/2012/06/22/integrate-travis-ci-into-grunt/
grunt.registerTask('travis', ['grammar', 'devel', 'test']);
// Default task is an alias for 'build'.
// I know this is annoying... but you could always do grunt build. This encourages better code testing! --Eric Green
grunt.registerTask('default', ['build','test']);
};