-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
109 lines (99 loc) · 3.05 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
var gulp = require('gulp');
var shell = require('gulp-shell');
var path = require('path');
var nodemon = require('gulp-nodemon');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync').create();
/*
* Basic task that init nodemon with proper options and run some tasks before application is restarted.
* See {@link https://github.com/JacksonGariety/gulp-nodemon gulp-nodemon) for more details.
* */
gulp.task('start', function () {
nodemon({
script: 'app.js',
watch: [
"./api",
"./config"
],
delay: '100ms',
ext: 'js json',
/*
* If you need to run some gulp tasks before nodemon restart your app,
* you can add tasks as follows.
* */
//tasks: function (changedFiles) {
// var tasks = ['beforeNodemonRestart'];
//
// changedFiles.forEach(function (file) {
// if (/^frontend/.test(file)) {
// tasks.push('enb');
// }
// });
//
// return tasks
//},
env: {'NODE_ENV': 'development'}
})
.on('restart', function (changedFiles) {
var shouldReload = true;
/*
* As argument we get list of changed files with absolute urls.
* We can define any logic we want and run any gulp tasks, using runSequence.
* */
//changedFiles.forEach(function (file) {
// file = path.relative(process.cwd(), file);
// if (!shouldReload && ['.css', '.styl'].indexOf(path.extname(file)) === -1) {
// shouldReload = true;
// }
//});
//todo rethink this timeout logic. Try to bind to started app event, if possible.
if (shouldReload) {
setTimeout(function () {
runSequence('browser-reload');
}, 3000)
}
});
});
/*
* Watch frontend files and rebuild frontend ith enb if changed.
* */
gulp.task('watch', function() {
gulp.watch(['frontend/**/*.{css,stylus,bemtree,bemhtml}', '!frontend/static/*'], ['enb']);
});
/*
* Rebuild frontend using enb compiler
* */
gulp.task('enb', shell.task([
"./node_modules/.bin/enb make -d frontend",
'npm run copy-views'
]));
/*
* Sync browser when any static files changed
* */
gulp.task('browser-sync', function () {
var files = [
"./frontend/static/**/*"
],
options = {
files: files,
notify: true,
open: false,
ghostMode: false,
injectChanges: true,
logLevel: 'debug',
minify: false,
codeSync: true,
port: 8080,
proxy: "127.0.0.1:1337"
};
browserSync.init(options, function (err, inj) {
if (err) {
throw Error(err);
}
});
});
/*
* You can manually reload browser, using this task.
* */
gulp.task('browser-reload', browserSync.reload);
gulp.task('default', ['start', 'browser-sync', 'watch']);