-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
112 lines (91 loc) · 2.83 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
'use strict';
var path = require('path');
var gulp = require('gulp');
var clean = require('gulp-clean');
var webpack = require('gulp-webpack');
var nodemon = require('gulp-nodemon');
var sass = require('gulp-sass');
var Server = require('karma').Server;
var clientPath = path.join(__dirname, 'app');
var paths = {
client: {
mainScript: path.join(clientPath, 'main.js'),
mainStyle: path.join(clientPath, 'styles.scss'),
mainView: path.join(clientPath, 'index.html'),
dest: path.join(__dirname, 'public')
},
server: {
mainScript: path.join(__dirname, 'server.js')
},
karma: path.join(__dirname, 'karma.config.js')
};
var webpackConfig = {
context: __dirname,
entry: paths.client.mainScript,
output: {
path: paths.client.dest,
filename: '[name].js'
},
module: {
loaders: [{ test: /\.html$/, loader: 'html' }]
},
devtool: 'source-map',
resolve: { root: clientPath }
};
gulp.task('default', ['serve', 'watch-client']);
gulp.task('serve', ['build-client'], function () {
return nodemon({
script: paths.server.mainScript,
ignore: ['public/']
});
});
// build tasks
gulp.task('build-client', ['clean-client', 'build-js', 'build-html', 'build-scss']);
gulp.task('build-js', ['clean-js'], function () {
return gulp.src(webpackConfig.entry)
.pipe(webpack(webpackConfig))
.pipe(gulp.dest(webpackConfig.output.path));
});
gulp.task('build-scss', ['clean-scss'], function () {
return gulp.src(paths.client.mainStyle)
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(paths.client.dest));
});
gulp.task('build-html', ['clean-html'], function () {
return gulp.src(paths.client.mainView)
.pipe(gulp.dest(paths.client.dest));
});
// clean tasks
gulp.task('clean-client', ['clean-js', 'clean-scss', 'clean-html']);
gulp.task('clean-js', function () {
return cleanByExtension('js');
});
gulp.task('clean-scss', function () {
return cleanByExtension('css');
});
gulp.task('clean-html', function () {
return cleanByExtension('html');
});
function cleanByExtension (ext) {
return gulp.src(paths.client.dest + '/*.' + ext, { read: false })
.pipe(clean());
}
// watch tasks
gulp.task('watch-client', ['watch-js', 'watch-html', 'watch-scss']);
gulp.task('watch-js', function () {
// TODO exclude spec.js files
gulp.watch([clientPath + '/**/*.js', clientPath + '/components/**/*.html'], ['build-js']);
});
gulp.task('watch-scss', ['build-scss'], function () {
gulp.watch(clientPath + '/**/*.scss', ['build-scss']);
});
gulp.task('watch-html', function () {
gulp.watch(clientPath + '/index.html', ['build-html']);
});
// test tasks
gulp.task('test', function (done) {
new Server({
configFile: paths.karma,
singleRun: true
}, done).start();
});