-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgulpfile.js
89 lines (74 loc) · 2.2 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
var gulp = require('gulp');
var plumber = require('gulp-plumber');
var uglify = require('gulp-uglify');
var browserSync = require('browser-sync');
var concat = require('gulp-concat');
var order = require('gulp-order');
var replace = require('gulp-replace');
var runSequence = require('run-sequence');
var unicodeEscapeArabicChars = function (match) {
// Replaces arabic chars with their unicode equivalent.
var hexCharCode = match.charCodeAt(0).toString(16);
var zeroPrefixed = ('0000' + hexCharCode).slice(-4);
return '\\u' + zeroPrefixed;
};
var arabicCharsRegExp = /[^\x00-\x7F]/g;
gulp.task('browser-sync', function () {
browserSync({
port: process.env.PORT || 3000,
server: {
baseDir: '/code/'
}
});
});
gulp.task('bs-reload', function () {
browserSync.reload();
});
gulp.task('scripts-concat', function () {
return gulp.src('/code/src/**/*.js')
.pipe(plumber({
errorHandler: function (error) {
console.log(error.message);
this.emit('end');
}
}))
.pipe(order([
'license.js',
'**/*.js'
]))
.pipe(concat('arabic.js'))
.pipe(replace(arabicCharsRegExp, unicodeEscapeArabicChars))
.pipe(gulp.dest('/code/dist/unpacked/'));
});
gulp.task('scripts-pack', function () {
return gulp.src('/code/dist/unpacked/arabic.js')
.pipe(plumber({
errorHandler: function (error) {
console.log(error.message);
this.emit('end');
}
}))
.pipe(uglify({
preserveComments: 'some'
}))
.pipe(replace(arabicCharsRegExp, unicodeEscapeArabicChars))
.pipe(replace('[arabic]/unpacked/arabic.js', '[arabic]/arabic.js'))
.pipe(gulp.dest('/code/dist/'));
});
gulp.task('scripts-dist', function () {
return gulp.src('/code/dist/**/*.{js,txt,md}')
.pipe(gulp.dest('/code/extensions/arabic/'));
});
gulp.task('scripts', function () {
runSequence(
'scripts-concat',
'scripts-pack',
'scripts-dist',
'bs-reload'
);
});
gulp.task('default', ['scripts', 'browser-sync'], function () {
gulp.watch('/code/src/**/*.js', ['scripts']);
gulp.watch('/code/testcases/**/*.{html,css,js,yml}', ['scripts']);
gulp.watch('/code/mathjax/unpacked/jax/input/TeX/**/*.js', ['bs-reload']);
});