forked from dabeng/OrgChart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
133 lines (116 loc) · 3.63 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
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var mocha = require('gulp-mocha');
var uglify = require('gulp-uglify');
var rename = require("gulp-rename");
var del = require('del');
var eslint = require('gulp-eslint');
var merge = require('merge-stream');
var csslint = require('gulp-csslint');
var cleanCSS = require('gulp-clean-css');
var sourcemaps = require('gulp-sourcemaps');
var testcafe = require('gulp-testcafe');
var jest = require('gulp-jest').default;
var paths = {
src: 'src',
srcFiles: 'src/**/*',
srcHTML: 'src/**/*.html',
srcCSS: 'src/css/*.css',
srcJS: 'src/js/*.js',
demo: 'demo',
demoFiles: 'demo/**/*',
demoHTML: 'demo/**/*.html',
demoCSSFolder: 'demo/css',
demoCSS: 'demo/**/*.css',
demoJSFolder: 'demo/js',
demoJS: 'demo/**/*.js',
dist: 'dist',
distIndex: 'dist/index.html',
distCSS: 'dist/**/*.css',
distCSSFolder: 'dist/css',
distJS: 'dist/**/*.js',
distJSFolder: 'dist/js'
};
gulp.task('unit-tests', function () {
return gulp.src(['test/unit/*.js'], {read: false})
.pipe(mocha({reporter: 'spec'}));
});
gulp.task('integration-tests', gulp.series('unit-tests', function () {
return gulp.src(['test/integration/*.js'], {read: false})
.pipe(mocha({reporter: 'spec'}));
}));
gulp.task('addAssets', gulp.series('integration-tests', function () {
var jsFiles = gulp.src([
paths.srcJS,
'node_modules/jquery/dist/jquery.min.js',
'node_modules/jquery-mockjax/dist/jquery.mockjax.min.js',
'node_modules/html2canvas/dist/html2canvas.min.js',
'node_modules/jspdf/dist/jspdf.min.js'
])
.pipe(gulp.dest(paths.demoJSFolder));
var cssFiles = gulp.src(paths.srcCSS)
.pipe(gulp.dest(paths.demoCSSFolder));
return merge(jsFiles, cssFiles);
}));
gulp.task('visual-regression', function () {
return gulp.src('test').pipe(jest({
"testMatch": ['**/test/visual-regression/**/test.js']
}));
});
gulp.task('e2e-tests', gulp.series('addAssets', function () {
return gulp.src('test/e2e/**/test.js')
.pipe(testcafe({ browsers: ['chrome:headless', 'firefox:headless'] }));
}));
gulp.task('test', gulp.series('e2e-tests', 'visual-regression'));
gulp.task('cleanupJS', function() {
return del([paths.distJSFolder + '/**']);
});
gulp.task('eslint', function () {
return gulp.src(paths.srcJS)
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
gulp.task('js', gulp.series('cleanupJS', 'eslint', 'test', function () {
return gulp.src(paths.srcJS)
.pipe(gulp.dest(paths.distJSFolder))
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(rename('jquery.orgchart.min.js'))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(paths.distJSFolder));
}));
gulp.task('cleanupCSS', function() {
return del([paths.distCSSFolder + '/**']);
});
gulp.task('csslint', function() {
return gulp.src(paths.srcCSS)
.pipe(csslint({
'adjoining-classes': false,
'box-sizing': false,
'box-model': false,
'fallback-colors': false,
'order-alphabetical': false
}))
.pipe(csslint.formatter());
});
gulp.task('css', gulp.series('cleanupCSS', 'csslint', function () {
return gulp.src(paths.srcCSS)
.pipe(gulp.dest(paths.distCSSFolder))
.pipe(cleanCSS())
.pipe(rename('jquery.orgchart.min.css'))
.pipe(gulp.dest(paths.distCSSFolder));
}));
gulp.task('build', gulp.series('js', 'css'));
gulp.task('reload', function (done) {
browserSync.reload();
done();
});
gulp.task('serve', gulp.series('build', function () {
browserSync.init({
server: {
baseDir: paths.demo
}
});
gulp.watch(paths.srcFiles, gulp.series('build'));
gulp.watch(paths.demoFiles, gulp.series('reload'));
}));