forked from nimbleape/JsSIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
151 lines (129 loc) · 4 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
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
/* eslint-disable strict */
'use strict';
/* eslint-enable strict */
const fs = require('fs');
const path = require('path');
const exec = require('child_process').exec;
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const gulp = require('gulp');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const header = require('gulp-header');
const expect = require('gulp-expect-file');
const nodeunit = require('gulp-nodeunit-runner');
const eslint = require('gulp-eslint');
const plumber = require('gulp-plumber');
const log = require('fancy-log');
const colors = require('ansi-colors');
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
};
function logError(error)
{
log(colors.red(String(error)));
}
gulp.task('lint', function()
{
const src = [ 'gulpfile.js', '.eslintrc.js', 'lib/**/*.js', 'test/**/*.js' ];
return gulp.src(src)
.pipe(plumber())
.pipe(eslint())
.pipe(eslint.format());
});
gulp.task('babel', function()
{
return gulp
.src([ 'lib/**/*.js' ])
.pipe(babel())
.pipe(gulp.dest('lib-es5'));
});
gulp.task('browserify', function()
{
return browserify(
{
entries : PKG.main,
extensions : [ '.js' ],
// Required for sourcemaps (must be false otherwise).
debug : false,
// Required for watchify (not used here).
cache : null,
// Required for watchify (not used here).
packageCache : null,
// Required to be true only for watchify (not used here).
fullPaths : false,
standalone : PKG.title
})
.bundle()
.on('error', logError)
.pipe(source(`${PKG.name}.js`))
.pipe(buffer())
.pipe(rename(`${PKG.name}.js`))
.pipe(header(BANNER, BANNER_OPTIONS))
.pipe(gulp.dest('dist/'));
});
gulp.task('uglify', function()
{
const 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';
const src = [
'test/test-classes.js',
'test/test-normalizeTarget.js',
'test/test-parser.js',
'test/test-properties.js',
'test/test-UA-no-WebRTC.js',
'test/test-digestAuthentication.js'
];
return gulp.src(src)
.pipe(expect(EXPECT_OPTIONS, src))
.pipe(nodeunit({ reporter: 'default' }));
});
gulp.task('grammar', function(cb)
{
const local_pegjs = path.resolve('./node_modules/.bin/pegjs');
const Grammar_pegjs = path.resolve('lib/Grammar.pegjs');
const Grammar_js = path.resolve('lib/Grammar.js');
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));
}
log(`grammar: ${ colors.yellow('done')}`);
// Modify the generated Grammar.js file with custom changes.
log('grammar: applying custom changes to Grammar.js...');
const grammar = fs.readFileSync('lib/Grammar.js').toString();
let 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);
log(`grammar: ${ colors.yellow('done')}`);
cb();
}
);
});
gulp.task('devel', gulp.series('grammar'));
gulp.task('dist', gulp.series('lint', 'babel', 'test', 'browserify', 'uglify'));
gulp.task('default', gulp.series('dist'));