forked from versatica/JsSIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
117 lines (94 loc) · 3.16 KB
/
gulpfile.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
/**
* Dependencies.
*/
var browserify = require('browserify');
var vinyl_source_stream = require('vinyl-source-stream');
var vinyl_buffer = require('vinyl-buffer');
var gulp = require('gulp');
var gutil = require('gulp-util');
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var header = require('gulp-header');
var expect = require('gulp-expect-file');
var nodeunit = require('gulp-nodeunit-runner');
var fs = require('fs');
var path = require('path');
var exec = require('child_process').exec;
const PKG = require('./package.json');
// gulp-header.
const BANNER = fs.readFileSync('banner.txt').toString();
const BANNER_OPTIONS = {
pkg: PKG,
currentYear: (new Date()).getFullYear()
};
// gulp-expect-file options.
const EXPECT_OPTIONS = {
silent: true,
errorOnFailure: true,
checkRealFile: true
};
gulp.task('lint', function() {
var src = ['gulpfile.js', 'lib/**/*.js', 'test/**/*.js'];
return gulp.src(src)
.pipe(expect(EXPECT_OPTIONS, src))
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish', {verbose: true}))
.pipe(jshint.reporter('fail'));
});
gulp.task('browserify', function() {
return browserify([path.join(__dirname, PKG.main)], {
standalone: PKG.title
}).bundle()
.pipe(vinyl_source_stream(PKG.name + '.js'))
.pipe(vinyl_buffer())
.pipe(header(BANNER, BANNER_OPTIONS))
.pipe(gulp.dest('dist/'));
});
gulp.task('uglify', function() {
var src = 'dist/' + PKG.name + '.js';
return gulp.src(src)
.pipe(expect(EXPECT_OPTIONS, src))
.pipe(uglify())
.pipe(header(BANNER, BANNER_OPTIONS))
.pipe(rename(PKG.name + '.min.js'))
.pipe(gulp.dest('dist/'));
});
gulp.task('test', function() {
// var src = 'test/*.js';
var src = [
'test/test-classes.js',
'test/test-normalizeTarget.js',
'test/test-parser.js',
'test/test-properties.js'
// 'test/test-UA-no-WebRTC.js'
];
return gulp.src(src)
.pipe(expect(EXPECT_OPTIONS, src))
.pipe(nodeunit({reporter: 'default'}));
});
gulp.task('grammar', function(cb) {
var local_pegjs = path.resolve('./node_modules/.bin/pegjs');
var Grammar_pegjs = path.resolve('lib/Grammar.pegjs');
var Grammar_js = path.resolve('lib/Grammar.js');
gutil.log('grammar: compiling Grammar.pegjs into Grammar.js...');
exec(local_pegjs + ' ' + Grammar_pegjs + ' ' + Grammar_js,
function(error, stdout, stderr) {
if (error) {
cb(new Error(stderr));
}
gutil.log('grammar: ' + gutil.colors.yellow('done'));
// Modify the generated Grammar.js file with custom changes.
gutil.log('grammar: applying custom changes to Grammar.js...');
var grammar = fs.readFileSync('lib/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;');
modified_grammar = modified_grammar.replace(/\s+$/mg, '');
fs.writeFileSync('lib/Grammar.js', modified_grammar);
gutil.log('grammar: ' + gutil.colors.yellow('done'));
cb();
}
);
});
gulp.task('devel', gulp.series('grammar'));
gulp.task('dist', gulp.series('lint', 'test', 'browserify', 'uglify'));
gulp.task('default', gulp.series('dist'));