This repository has been archived by the owner on Nov 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
203 lines (168 loc) · 5.74 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
console.debug = console.log;
var map = require('map-stream');
var gulp = require('gulp'),
gutil = require('gulp-util'),
sass = require('gulp-sass'),
concat = require('gulp-concat'),
embedlr = require('gulp-embedlr'),
refresh = require('gulp-livereload'),
lrserver = require('tiny-lr')(),
express = require('express'),
coffee = require('gulp-coffee'),
fs = require('fs'),
open = require('open'),
mocha = require('gulp-mocha'),
es = require('event-stream'),
webpack = require('webpack'),
WebpackDevServer = require('webpack-dev-server'),
filter = require('gulp-filter'),
clean = require('gulp-clean');
var
livereloadport = 35729,
serverport = 5000;
/** webpack **/
webpackConfig = require('./webpack.config.js');
gulp.task('clean', function() {
gulp.src(['dist','output'], {read: false})
.pipe(clean());
});
//Task for sass using libsass through gulp-sass
gulp.task('sass', function () {
return gulp.src('sass/*.scss')
.pipe(sass())
.pipe(gulp.dest('dist/static'))
.pipe(refresh(lrserver));
});
//Task for moving html-files to the build-dir
//added as a convenience to make sure this gulpfile works without much modification
gulp.task('html', function () {
return gulp.src('app/**/*.html')
.pipe(embedlr())
.pipe(gulp.dest('dist/static'))
.pipe(refresh(lrserver));
});
//Convenience task for running a one-off build
gulp.task('build', function () {
return gulp.run('html', 'sass');
});
gulp.task('server', function () {
return gulp.src('server/src/**/*.coffee')
.pipe(coffee()).on('error', gutil.log)
.pipe(gulp.dest('./dist/'));
});
gulp.task('watch-app', function () {
//Add watching on sass-files
gulp.watch('app/sass/*.scss', function () {
gulp.run('sass');
});
gulp.watch(['app/**/*.js','app/**/*.coffee'], function () {
gulp.src('app/**/*.html')
.pipe(refresh(lrserver));
});
});
gulp.task('watch-server', function () {
gulp.watch(['server/src/**/*.js', 'server/src/**/*.coffee'], function () {
gulp.run('server');
});
//Add watching on html-files
gulp.watch('app/**/*.html', function () {
gulp.run('html');
});
});
gulp.task('watch-server-test', function () {
gulp.watch(['server/**/*.js', 'server/**/*.coffee', 'server/test/**/*'], function () {
gulp.run('server-test');
});
});
function handleError(err) {
console.log(err.toString());
this.emit('end');
}
gulp.task('server-test', function () {
es = require("event-stream");
return es.concat(
gulp.src('server/src/**/*.coffee').pipe(coffee()).on('error', gutil.log),
gulp.src(['server/src/**/*.js', 'server/test/**/*']))
.pipe(filter('!index.js'))
.pipe(gulp.dest('output/testsrc'))
.pipe(mocha({reporter: 'nyan'})).on('error', handleError);
});
var nodemon = require('gulp-nodemon');
gulp.task('webpack:build', function (callback) {
var myConfig = Object.create(webpackConfig);
myConfig.plugins = myConfig.plugins.concat(
new webpack.DefinePlugin({
"process.env": {
"NODE_ENV": JSON.stringify("production")
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin()
);
// run webpack
webpack(myConfig, function (err, stats) {
if (err) throw new gutil.PluginError("webpack:build", err);
gutil.log("[webpack:build]", stats.toString({
colors: true
}));
callback();
});
});
gulp.task("webpack-dev-server", function (callback) {
// modify some webpack config options
var myConfig = Object.create(webpackConfig);
myConfig.devtool = "eval";
myConfig.watch = true;
myConfig.debug = true;
// Start a webpack-dev-server
new WebpackDevServer(webpack(myConfig), {
publicPath: "/" + myConfig.output.publicPath,
contentBase: "./app/",
noInfo: true,
stats: {
colors: true
}
}).listen(8080, "localhost", function (err) {
if (err) throw new gutil.PluginError("webpack-dev-server", err);
gutil.log("[webpack-dev-server]", "http://localhost:8080/webpack-dev-server/index.html");
});
open('http://localhost:8080/webpack-dev-server/index.html');
});
gulp.task("webpack-test-server", function (callback) {
// modify some webpack config options
var myConfig = Object.create(webpackConfig);
myConfig.devtool = "eval";
myConfig.watch = true;
myConfig.debug = true;
// Start a webpack-dev-server
new WebpackDevServer(webpack(myConfig), {
publicPath: "/" + myConfig.output.publicPath,
contentBase: "./app/test",
noInfo: true,
stats: {
colors: true
}
}).listen(8081, "localhost", function (err) {
if (err) throw new gutil.PluginError("webpack-dev-server", err);
gutil.log("[webpack-dev-server]", "http://localhost:8080/webpack-dev-server/index.html");
});
open('http://localhost:8081/webpack-dev-server/index.html');
});
gulp.task('serve',['build','server'], function () {
nodemon({ script: 'dist/index.js', env:{'NODE_ENV':'development', 'STATIC_ROOT':"./dist/static"}, options: '--watch dist/*.js --ignore dist/tests.js' }).on('start', 'nodemon-open');
console.log("Live reload server listening on port " + livereloadport);
lrserver.listen(livereloadport);
});
// We only want to open browser on first start
var localhost_open = false;
gulp.task('nodemon-open', function () {
!localhost_open && (localhost_open=true) && open('http://localhost:5000/');
});
gulp.task('dev', ['watch-server','webpack-dev-server', 'serve', 'watch-app', 'webpack-test-server', 'server-test','watch-server-test'], function () {
});
gulp.task('default', function () {
/*todo remove usage of run. */
gulp.run('build', 'serve', 'watch-server', 'open', 'server-test');
});
gulp.task('dist',['build','server','webpack:build'], function () {
});