-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
144 lines (130 loc) · 3.34 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
'use strict';
const gulp = require('gulp');
const watch = require('gulp-watch');
const shell = require('gulp-shell')
const sass = require('gulp-sass');
const concat = require('gulp-concat');
const sourcemaps = require('gulp-sourcemaps');
const spawn = require('child_process').spawn;
const paths = {
/**
* paths to files that should restart app
*/
server_files: [
'models/**/*',
'routes/**/*',
'keystone.js',
'package.json',
'!routes/redux-render/**/*.jsx'
],
/**
* gulp-sass configuration
*/
style: {
watch_files: 'public/styles/src/**/*.scss',
src: './public/styles/src/**/*.scss',
dist: './public/styles/dist',
sourcemap_root: '../src'
},
/**
* webpack config and files to watch
*/
webpack: {
config: 'webpack.config.js',
watch_files: [
'public/js/src/**/*',
'webpack.config.js'
]
},
'webpack-server': {
config: 'webpack-server.config.js',
watch_files: [
'routes/redux-render/**/*.jsx',
'webpack-server.config.js'
]
},
};
/** starting and restarting keystone app **/
gulp.task('watch-app', done => {
// node process
let node_process;
//
const dest_path = `.`;
let restartServer = () => {
node_process.kill();
node_process = startServer();
}
let startServer = () => {
var local_node_process = spawn('node', ['keystone'], {cwd: dest_path});
local_node_process.on('close', (code, signal) => {
console.log(`-- Server process closed --`);
});
local_node_process.stdout.on('data', (data) => {
console.log(`${data}`);
});
local_node_process.stderr.on('data', (data) => {
console.log(`Error: ${data}`);
});
return local_node_process;
}
const watcher = gulp.watch(paths.server_files);
watcher.on('change', () => restartServer() )
// start the server process
node_process = startServer();
done();
});
/** sass **/
gulp.task('watch-sass', () => {
gulp.watch(paths.style.watch_files, ['sass']);
});
gulp.task('sass', () => {
gulp.src(paths.style.src)
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(sourcemaps.write('.', {
sourceRoot: paths.style.sourcemap_root
}))
.pipe(gulp.dest(paths.style.dist));
});
/** webpack **/
gulp.task('watch-webpack', () => {
gulp.watch(paths.webpack.watch_files, ['webpack']);
});
gulp.task('webpack', done => {
var webpack_process = spawn('./node_modules/.bin/webpack', [
'--config',
paths.webpack.config
]);
webpack_process.on('close', (code, signal) => {
done();
});
webpack_process.stdout.on('data', (data) => {
console.log(`${data}`);
});
webpack_process.stderr.on('data', (data) => {
console.log(`Error: ${data}`);
});
return webpack_process;
});
/** webpack-server **/
gulp.task('watch-webpack-server', () => {
gulp.watch(paths['webpack-server'].watch_files, ['webpack-server']);
});
gulp.task('webpack-server', done => {
var webpack_process = spawn('./node_modules/.bin/webpack', [
'--config',
paths['webpack-server'].config
]);
webpack_process.on('close', (code, signal) => {
done();
});
webpack_process.stdout.on('data', (data) => {
console.log(`${data}`);
});
webpack_process.stderr.on('data', (data) => {
console.log(`Error: ${data}`);
});
return webpack_process;
});
/** gulp task setup **/
gulp.task('default', ['watch-app', 'watch-sass', 'watch-webpack-server']);//, 'watch-webpack']);