forked from waste-not/waste-not
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
84 lines (72 loc) · 2.18 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
'use strict';
const gulp = require('gulp');
const eslint = require('gulp-eslint');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
const sass = require('gulp-sass');
const mocha = require('gulp-mocha');
const scripts = ['server.js', 'lib/**/*.js', 'models/**/*.js', 'routes/**/*.js',
'client/**/*.js', '!**/*bundle.js', 'test/**/*.js'];
const clientScripts = ['client/**/*.js'];
const staticFiles = ['client/**/*.html', 'client/**/*.png', 'client/**/*.jpg',
'client/**/*.csv'];
const serverSpecs = ['test/backend/**/*spec.js'];
gulp.task('static:dev', () => {
return gulp.src(staticFiles, { 'base': 'client' })
.pipe(gulp.dest('dist/'));
});
gulp.task('webfonts:dev', () => {
return gulp.src('client/webfonts/**/*')
.pipe(gulp.dest('dist/webfonts'));
});
gulp.task('sass:dev', () => {
return gulp.src('client/sass/main.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./dist'));
});
gulp.task('build:dev', () => {
webpackStream({
entry: ['./client/index.js'],
output: {
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader'
}
]
},
plugins: [
new webpack.DefinePlugin({
__BASEURL__: JSON.stringify(process.env.SERVER_ENV === 'production' ?
`http://${process.env.HEROKU_APP_NAME}.herokuapp.com` :
'http://localhost:3000')
})
],
devtool: 'source-map'
})
.pipe(gulp.dest('dist/'));
});
gulp.task('lint', () => {
return gulp.src(scripts)
.pipe(eslint())
.pipe(eslint.format());
});
gulp.task('watch', () => {
gulp.watch(scripts, ['lint']);
gulp.watch(clientScripts, ['build:dev']);
gulp.watch(staticFiles, ['static:dev']);
gulp.watch('client/sass/*.sass', ['sass:dev']);
});
gulp.task('build', ['static:dev', 'build:dev', 'sass:dev', 'webfonts:dev']);
gulp.task('dev', ['watch', 'build']);
gulp.task('style:dev', ['static:dev', 'sass:dev', 'webfonts:dev']);
gulp.task('test:mocha', () => {
return gulp.src(serverSpecs, { read: false })
.pipe(mocha())
.once('end', process.exit);
});
gulp.task('default', ['dev', 'lint']);