forked from OmarIthawi/arabic-mathjax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
110 lines (97 loc) · 2.96 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
var gulp = require('gulp');
var path = require('path');
var plumber = require('gulp-plumber');
var uglify = require('gulp-uglify');
var uglifycss = require('gulp-uglifycss');
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: __dirname
}
});
});
gulp.task('bs-reload', function () {
browserSync.reload();
});
gulp.task('scripts-concat', function () {
return gulp.src(path.join(__dirname, '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(path.join(__dirname, 'dist/unpacked/')));
});
gulp.task('scripts-pack', function () {
return gulp.src(path.join(__dirname, '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(path.join(__dirname, 'dist/')));
});
gulp.task('styles-concat', function () {
return gulp.src(path.join(__dirname, 'src/css/*.css'))
.pipe(plumber({
errorHandler: function (error) {
console.log(error.message);
this.emit('end');
}
}))
.pipe(concat('arabic.css'))
.pipe(gulp.dest(path.join(__dirname, 'dist/unpacked/')));
});
gulp.task('styles-pack', function () {
return gulp.src(path.join(__dirname, 'dist/unpacked/arabic.css'))
.pipe(plumber({
errorHandler: function (error) {
console.log(error.message);
this.emit('end');
}
}))
.pipe(uglifycss({
maxLineLen: 80
}))
.pipe(gulp.dest(path.join(__dirname, 'dist/')));
});
gulp.task('build-and-reload', function () {
runSequence(
'scripts-concat',
'scripts-pack',
'styles-concat',
'styles-pack',
'bs-reload'
);
});
gulp.task('default', ['build-and-reload', 'browser-sync'], function () {
gulp.watch(path.join(__dirname, 'src/**/*.{js,css}'), ['build-and-reload']);
gulp.watch(path.join(__dirname, 'testcases/**/*.{html,css,js,yml}'), ['build-and-reload']);
gulp.watch(path.join(__dirname, 'mathjax/unpacked/jax/input/TeX/**/*.js'), ['bs-reload']);
});