-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
69 lines (55 loc) · 1.52 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
var gulp = require('gulp');
var cp = require('child_process');
var del = require('del');
var webpack = require('webpack-stream');
var webpackConfig = require('./webpack.config.js');
var nodemon = require('gulp-nodemon');
var rename = require('gulp-rename');
var path = require('path');
/**
* Build (Webpack)
*/
gulp.task('clean:build', function() {
del('./public/js/*')
})
gulp.task('build', ['clean:build'], function() {
return gulp.src('./app/app.js')
.pipe(webpack(webpackConfig))
.on('error', function handleError() {
this.emit('end'); // Recover from errors
})
.pipe(gulp.dest('./'));
});
gulp.task('watch:build', function() {
return gulp.watch('./app/**/*', ['build']);
});
/**
* API Server (Database)
*/
gulp.task('restore-database', function() {
return gulp.src('./data/restore.json')
.pipe(rename('db.json'))
.pipe(gulp.dest('./data'));
});
gulp.task('serve:api', ['restore-database'], function(done) {
var serverPath = path.join(__dirname, 'node_modules/.bin/json-server');
cp.exec(serverPath + ' --watch ./data/db.json --port 3001', {stdio: 'inherit'})
.on('close', done);
});
/**
* Node Server (Express)
*/
gulp.task('serve:node', function(done) {
var babelPath = path.join(__dirname, 'node_modules/.bin/babel-node');
nodemon({
exec: babelPath + ' ./server.js',
watch: ['server.js'],
ext: 'js html'
});
});
/**
* Main tasks
*/
gulp.task('serve', ['serve:node', 'serve:api']);
gulp.task('watch', ['build', 'watch:build']);
gulp.task('default', ['serve']);