Skip to content

Commit df33833

Browse files
committed
Use require() and browserify to organize dependencies and compilation.
1 parent e843db0 commit df33833

35 files changed

+134
-173
lines changed

Gruntfile.js

Lines changed: 33 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,8 @@
22

33
module.exports = function(grunt) {
44

5-
var srcFiles = [
6-
'src/SIP.js',
7-
'src/Utils.js',
8-
'src/LoggerFactory.js',
9-
'src/EventEmitter.js',
10-
'src/Constants.js',
11-
'src/Exceptions.js',
12-
'src/Timers.js',
13-
'src/Transport.js',
14-
'src/Parser.js',
15-
'src/SIPMessage.js',
16-
'src/URI.js',
17-
'src/NameAddrHeader.js',
18-
'src/Transactions.js',
19-
'src/Dialogs.js',
20-
'src/RequestSender.js',
21-
'src/RegisterContext.js',
22-
'src/MediaHandler.js',
23-
'src/ClientContext.js',
24-
'src/ServerContext.js',
25-
'src/Session.js',
26-
'src/Subscription.js',
27-
'src/WebRTC.js',
28-
'src/UA.js',
29-
'src/Hacks.js',
30-
'src/SanityCheck.js',
31-
'src/DigestAuthentication.js',
32-
'src/Grammar/dist/Grammar.js',
33-
'src/tail.js'
34-
];
35-
36-
// Project configuration.
37-
grunt.initConfig({
38-
pkg: grunt.file.readJSON('package.json'),
39-
meta: {
40-
banner: '\
5+
var pkg = grunt.file.readJSON('package.json');
6+
var banner = '\
417
/*\n\
428
* SIP version <%= pkg.version %>\n\
439
* Copyright (c) 2014-<%= grunt.template.today("yyyy") %> Junction Networks, Inc <http://www.onsip.com>\n\
@@ -69,45 +35,40 @@ module.exports = function(grunt) {
6935
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\
7036
*\n\
7137
* ~~~ end JsSIP license ~~~\n\
72-
*/\n\n\n'
38+
*/\n\n\n';
39+
40+
// Project configuration.
41+
grunt.initConfig({
42+
pkg: pkg,
43+
meta: {
44+
banner: banner
7345
},
74-
concat: {
75-
dist: {
76-
src: srcFiles,
77-
dest: 'dist/<%= pkg.name %>.js',
78-
options: {
79-
banner: '<%= meta.banner %>',
80-
separator: '\n\n',
81-
process: true
82-
},
83-
nonull: true
84-
},
46+
browserify: {
8547
devel: {
86-
src: srcFiles,
87-
dest: 'dist/<%= pkg.name %>-<%= pkg.version %>.js',
88-
options: {
89-
banner: '<%= meta.banner %>',
90-
separator: '\n\n',
91-
process: true
48+
src: 'src/SIP.js',
49+
dest: 'dist/<%= pkg.name %>-<%= pkg.version %>.js'
50+
},
51+
options: {
52+
bundleOptions: {
53+
standalone: 'SIP'
9254
},
93-
nonull: true
55+
postBundleCB: function (err, src, next) {
56+
// prepend the banner and fill in placeholders
57+
src = (banner + src).replace(/<%=(.*)%>/g, function (match, expr) {
58+
return eval(expr)
59+
});
60+
next(err, src);
61+
}
9462
}
9563
},
96-
includereplace: {
64+
copy: {
9765
dist: {
98-
files: {
99-
'dist': 'dist/<%= pkg.name %>.js'
100-
}
101-
},
102-
devel: {
103-
files: {
104-
'dist': 'dist/<%= pkg.name %>-<%= pkg.version %>.js'
105-
}
66+
src: 'dist/<%= pkg.name %>-<%= pkg.version %>.js',
67+
dest: 'dist/<%= pkg.name %>.js'
10668
}
10769
},
10870
jshint: {
109-
dist: 'dist/<%= pkg.name %>.js',
110-
devel: 'dist/<%= pkg.name %>-<%= pkg.version %>.js',
71+
src: 'src/**/*.js',
11172
options: {
11273
browser: true,
11374
curly: true,
@@ -125,7 +86,7 @@ module.exports = function(grunt) {
12586
supernew: true,
12687
globals: {
12788
module: true,
128-
define: true,
89+
require: true,
12990
global: true
13091
}
13192
}
@@ -162,7 +123,6 @@ module.exports = function(grunt) {
162123
src: 'src/Grammar/src/Grammar.pegjs',
163124
dest: 'src/Grammar/dist/Grammar.js',
164125
options: {
165-
exportVar: 'SIP.Grammar',
166126
optimize: 'size',
167127
allowedStartRules: [
168128
'Contact',
@@ -199,8 +159,8 @@ module.exports = function(grunt) {
199159

200160

201161
// Load Grunt plugins.
202-
grunt.loadNpmTasks('grunt-contrib-concat');
203-
grunt.loadNpmTasks('grunt-include-replace');
162+
grunt.loadNpmTasks('grunt-browserify');
163+
grunt.loadNpmTasks('grunt-contrib-copy');
204164
grunt.loadNpmTasks('grunt-contrib-uglify');
205165
grunt.loadNpmTasks('grunt-contrib-jshint');
206166
grunt.loadNpmTasks('grunt-contrib-jasmine');
@@ -232,12 +192,12 @@ module.exports = function(grunt) {
232192
// Task for building sip-devel.js (uncompressed), sip-X.Y.Z.js (uncompressed)
233193
// and sip-X.Y.Z.min.js (minified).
234194
// Both sip-devel.js and sip-X.Y.Z.js are the same file with different name.
235-
grunt.registerTask('build', ['concat:devel', 'includereplace:devel', 'jshint:devel', 'concat:dist', 'includereplace:dist', 'jshint:dist', 'uglify:dist', 'uglify:devel']);
195+
grunt.registerTask('build', ['devel', 'copy', 'uglify']);
236196

237197
// Task for building sip-devel.js (uncompressed).
238-
grunt.registerTask('devel', ['concat:devel', 'includereplace:devel', 'jshint:devel']);
198+
grunt.registerTask('devel', ['jshint', 'browserify']);
239199

240-
grunt.registerTask('quick', ['concat:dist', 'includereplace:dist']);
200+
grunt.registerTask('quick', ['browserify']);
241201

242202
// Test tasks.
243203
grunt.registerTask('test',['jasmine']);

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@
2424
"devDependencies": {
2525
"grunt": "~0.4.0",
2626
"grunt-cli": "~0.1.6",
27-
"grunt-contrib-concat": "~0.1.3",
28-
"grunt-include-replace": "~0.1.0",
27+
"grunt-contrib-copy": "^0.5.0",
2928
"grunt-contrib-uglify": "~0.2.0",
3029
"grunt-contrib-jshint": ">0.5.0",
3130
"grunt-contrib-jasmine": "~0.5.0",
31+
"browserify": "^4.1.8",
3232
"pegjs": "0.8.0",
33-
"node-minify": "~0.7.2",
34-
"browserify": "~2.36.0",
35-
"sdp-transform": "~0.4.0",
36-
"grunt-peg": "~1.3.1"
33+
"grunt-peg": "~1.3.1",
34+
"grunt-browserify": "^2.1.0"
3735
},
3836
"engines": {
3937
"node": ">=0.8"

src/ClientContext.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function (SIP) {
1+
module.exports = function (SIP) {
22
var ClientContext;
33

44
ClientContext = function (ua, method, target, options) {
@@ -111,4 +111,4 @@ ClientContext.prototype.onTransportError = function () {
111111
};
112112

113113
SIP.ClientContext = ClientContext;
114-
}(SIP));
114+
};

src/Constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @augments SIP
88
*/
99

10+
module.exports = function (SIP) {
1011
SIP.C= {
1112
USER_AGENT: SIP.name +'/'+ SIP.version,
1213

@@ -156,3 +157,4 @@ SIP.C= {
156157
606: 'Not Acceptable'
157158
}
158159
};
160+
};

src/Dialog/RequestSender.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @fileoverview in-Dialog Request Sender
1515
*/
1616

17-
(function(SIP) {
17+
module.exports = function (SIP) {
1818
var RequestSender;
1919

2020
RequestSender = function(dialog, applicant, request) {
@@ -90,4 +90,4 @@ RequestSender.prototype = {
9090
};
9191

9292
return RequestSender;
93-
}(SIP));
93+
};

src/Dialogs.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
* @param {Enum} type UAC / UAS
1111
* @param {Enum} state SIP.Dialog.C.STATUS_EARLY / SIP.Dialog.C.STATUS_CONFIRMED
1212
*/
13-
(function(SIP) {
14-
15-
// Load dependencies
16-
var RequestSender = @@include('../src/Dialog/RequestSender.js')
13+
module.exports = function (SIP, RequestSender) {
1714

1815
var Dialog,
1916
C = {
@@ -252,4 +249,4 @@ Dialog.prototype = {
252249

253250
Dialog.C = C;
254251
SIP.Dialog = Dialog;
255-
}(SIP));
252+
};

src/DigestAuthentication.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @function Digest Authentication
1010
* @param {SIP.UA} ua
1111
*/
12-
(function(SIP) {
12+
module.exports = function (SIP) {
1313
var DigestAuthentication;
1414

1515
DigestAuthentication = function(ua) {
@@ -165,4 +165,4 @@ DigestAuthentication.prototype.updateNcHex = function() {
165165
};
166166

167167
SIP.DigestAuthentication = DigestAuthentication;
168-
}(SIP));
168+
};

src/EventEmitter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @augments SIP
77
* @class Class creating an event emitter.
88
*/
9-
(function(SIP) {
9+
module.exports = function (SIP) {
1010
var
1111
EventEmitter,
1212
Event,
@@ -209,4 +209,4 @@ EventEmitter.C = C;
209209

210210
SIP.EventEmitter = EventEmitter;
211211
SIP.Event = Event;
212-
}(SIP));
212+
};

src/Exceptions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* SIP Exceptions.
77
* @augments SIP
88
*/
9-
(function(SIP) {
9+
module.exports = function (SIP) {
1010
var Exceptions;
1111

1212
Exceptions= {
@@ -55,4 +55,4 @@ Exceptions= {
5555
};
5656

5757
SIP.Exceptions = Exceptions;
58-
}(SIP));
58+
};

src/Grammar/dist/Grammar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* jshint ignore:start */
2-
SIP.Grammar = (function() {
2+
module.exports = (function() {
33
/*
44
* Generated by PEG.js 0.8.0.
55
*

0 commit comments

Comments
 (0)