This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
forked from rcorral/mesos-tracing
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
162 lines (139 loc) · 4.24 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
152
153
154
155
156
157
158
159
160
161
162
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync');
var colorLighten = require("less-color-lighten");
var eslint = require('gulp-eslint');
var gulp = require('gulp');
var gulpif = require('gulp-if');
var gutil = require('gulp-util');
var imagemin = require('gulp-imagemin');
var less = require('gulp-less');
var minifyCSS = require('gulp-minify-css');
var replace = require('gulp-replace');
var spawn = require('child_process').spawn;
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var webpack = require('webpack');
var config = require('./configuration');
var packageInfo = require('./package');
var webpackConfig = require('./webpack.config.js');
var development = process.env.NODE_ENV === 'development';
gulp.task('browsersync', function () {
browserSync.init({
open: false,
port: 4201,
server: {
baseDir: config.dirs.dist
},
socket: {
domain: 'localhost:4201'
}
});
});
gulp.task('server', function () {
var childProcess;
function spawnChildren() {
// kill previous spawned process
if (childProcess) {
childProcess.kill();
}
// `spawn` a child `gulp` process linked to the parent `stdio`
childProcess = spawn('./bin/www', [], {
stdio: 'inherit',
env: {
DEBUG: 'debug,server,error',
NODE_PORT: 4200
}
});
}
// We need to kill the child process before exiting
process.on('exit', function() {
process.kill();
});
gulp.watch(['app/**/*.*'], spawnChildren);
spawnChildren();
});
gulp.task('eslint', function () {
return gulp.src([config.dirs.srcJS + '/**/*.js'])
.pipe(eslint())
.pipe(eslint.formatEach('stylish', process.stderr));
});
gulp.task('images', function () {
return gulp.src([
config.dirs.srcImg + '/**/*.*',
'!' + config.dirs.srcImg + '/**/_exports/**/*.*'
])
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}]
}))
.pipe(gulp.dest(config.dirs.distImg));
});
gulp.task('html', function () {
return gulp.src(config.files.srcHTML)
.pipe(gulp.dest(config.dirs.dist));
});
gulp.task('less', function () {
return gulp.src(config.files.srcCSS)
.pipe(gulpif(development, sourcemaps.init()))
.pipe(less({
paths: [config.dirs.cssSrc], // @import paths
plugins: [colorLighten]
}))
.pipe(autoprefixer())
.pipe(gulpif(development, sourcemaps.write()))
.pipe(gulp.dest(config.dirs.distCSS))
.pipe(gulpif(development, browserSync.stream()));
});
gulp.task('minify-css', ['less'], function () {
return gulp.src(config.files.distCSS)
.pipe(minifyCSS())
.pipe(gulp.dest(config.dirs.distCSS));
});
gulp.task('minify-js', ['replace-js-strings'], function () {
return gulp.src(config.files.distJS)
.pipe(uglify({
mangle: true,
compress: true
}))
.pipe(gulp.dest(config.dirs.distJS));
});
gulp.task('replace-js-strings', ['webpack'], function() {
return gulp.src(config.files.distJS)
.pipe(replace('@@VERSION', packageInfo.version))
.pipe(replace('@@ENV', process.env.NODE_ENV))
.pipe(gulp.dest(config.dirs.distJS));
});
gulp.task('watch', function () {
gulp.watch(config.files.srcHTML, ['html']);
gulp.watch(config.dirs.srcCSS + '/**/*.less', ['less']);
gulp.watch(config.dirs.srcJS + '/**/*.?(js|jsx)', ['webpack', 'replace-js-strings']);
gulp.watch(config.dirs.srcImg + '/**/*.*', ['images']);
});
// Use webpack to compile jsx into js,
gulp.task('webpack', ['eslint'], function (callback) {
// Extend options with source mapping
if (development) {
webpackConfig.devtool = 'source-map';
webpackConfig.module.preLoaders = [
{
test: /\.js$/,
loader: 'source-map-loader',
exclude: /node_modules/
}
];
}
// run webpack
webpack(webpackConfig, function (err) {
if (err) {
throw new gutil.PluginError('webpack', err);
}
if (development) {
browserSync.reload();
}
callback();
});
});
gulp.task('default', ['eslint', 'webpack', 'replace-js-strings', 'less', 'images', 'html']);
gulp.task('dist', ['default', 'minify-css', 'minify-js']);
gulp.task('serve', ['server', 'default', 'watch']);
gulp.task('livereload', ['server', 'default', 'browsersync', 'watch']);