-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgulpfile.js
134 lines (118 loc) · 3.59 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
var gulp = require('gulp');
var gutil = require('gulp-util');
var less = require('gulp-less');
var mocha = require('gulp-mocha');
var uglify = require('gulp-uglify');
var babel = require('gulp-babel');
var webpackStream = require('webpack-stream');
var webpack = require('webpack');
var path = require('path');
/**
Set up paths for loading js and test files
**/
var pathConfig = {
jsSource: 'src/js/**/*.js',
jsTarget: 'target/js',
src: path.join(__dirname, '/src/js')
};
pathConfig.alljs = [
path.join(pathConfig.src, '**/*.js'),
'!**/__test__/**'
];
pathConfig.alltests = [
path.join(pathConfig.src, '**/test-*.js')
];
gulp.task('sync-js', function () {
console.log(pathConfig.src);
console.log(pathConfig.jsSource);
return gulp.src(pathConfig.jsSource)
.pipe(babel({ presets: ['es2015'] }))
.pipe(gulp.dest(pathConfig.jsTarget));
});
gulp.task('bundle-js', ['sync-js'], function() {
return gulp.src(pathConfig.jsTarget + '/GraphApp.js')
.pipe(webpackStream({
output: {
filename: "ets.js"
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
mangle: {
except: ['$super', '$', 'exports', 'require']
}
})
],
}, webpack))
.pipe(gulp.dest('tycho/static/js'));
});
gulp.task('bundle-js-dev', ['sync-js'], function() {
return gulp.src(pathConfig.jsTarget + '/GraphApp.js')
.pipe(webpackStream({
output: {
filename: "ets.js"
}
}))
.pipe(gulp.dest('tycho/static/js'));
});
gulp.task('uglify-js', ['bundle-js'], function () {
// should only run on full gulp build to avoid perf penalty while developing
var combined = combiner.obj([
gulp.src('zon/static/js/zon.js'),
uglify({
// code-renaming is not playing nice
mangle: false
}),
gulp.dest('zon/static/js')
]);
return combined;
});
gulp.task('compile-less', function () {
return gulp.src('src/less/**/*.less')
.pipe(less({
pathConfig: [ path.join(__dirname, 'target') ]
}))
.pipe(gulp.dest('tycho/static/css'));
});
gulp.task('build', [
'sync-js', 'bundle-js', 'compile-less'
]);
gulp.task('build-dev', [
'sync-js', 'bundle-js-dev', 'compile-less'
]);
gulp.task('watch', function () {
var jsxwatcher = gulp.watch([pathConfig.jsSource], ['build']);
var lesswatcher = gulp.watch(['src/less/**/*.less'], ['compile-less']);
jsxwatcher.on('change', function (event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
lesswatcher.on('change', function (event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
failOnError = false;
});
/**
* Run mocha unit tests
*/
gulp.task('test', function (cb) {
return gulp.src(pathConfig.alltests, {read: false})
.pipe(mocha({
reporter: 'spec'
}))
.on('error', function (err) {
if (!failOnError) {
// Eat the error
gutil.log('mocha-test', err);
this.emit('end');
}
});
});
/**
* Re-runs tests when changes are made to a unit test file (for development).
*/
gulp.task('watch-test', function () {
failOnError = false;
gulp.watch(pathConfig.alltests, ['test']);
});