generated from emm7494/gulp-flask-live
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·97 lines (84 loc) · 2.29 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
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var cache = require('gulp-cache');
var exec = require('child_process').exec;
var plumbError = require('gulp-plumber');
var notify = require('gulp-notify');
/* Global Function Declarations */
function plumbError() {
return plumber({
errorHandler: function (err) {
notify.onError({
templateOptions: {
date: new Date()
},
title: 'Gulp error in' + err.plugin,
message: err.toString()
})(err);
this.emit('end');
}
});
}
/* Run Flask Server */
function runFlask(done) {
var flaskProcess = exec('flask run');
flaskProcess.stdout.on('data', function (data) {
console.log(data);
});
flaskProcess.stderr.on('data', function (data) {
console.log(data);
});
done();
}
function runBSync(done) {
browserSync.init({
notify: true,
online: false,
ws: true,
// injectChanges: true,
//reloadOnRestart: false,
//watch: true,
// files: [ 'static/**/*.css', 'static/**/*.js' ],
proxy: 'http://0.0.0.0:5000'
});
done();
}
function watchFiles(params) {
gulp.watch('blogr/static/**/*.js').on('change', scripts);
gulp.watch('blogr/static/**/*.css').on('change', styles);
gulp.watch('blogr/templates/**/*.html').on('change', templates);
gulp.watch('**/*.py').on('change', pyfiles);
}
/* function templates(e) {
console.log(`${e}` + 'styles here...');
return gulp.src(`${e}`).pipe(browserSync.reload({ stream: true }));
} */
function pyfiles(e) {
console.log(e + ' pyfiles here... ' + e);
return gulp.src(e).pipe(plumbError()).pipe(browserSync.stream()); //.pipe(browserSync.reload({ stream: true }));
}
function templates(e) {
console.log(e + ' templates here... ' + e);
return gulp.src(e).pipe(plumbError()).pipe(browserSync.stream()); //.pipe(browserSync.reload({ stream: true }));
}
function styles(e) {
console.log(e + ' styles here...' + e);
return gulp.src(e).pipe(plumbError()).pipe(browserSync.stream());
}
function scripts(e) {
console.log(e + ' scripts here...' + e);
return gulp.src(e).pipe(plumbError()).pipe(browserSync.stream());
}
function clearCache() {
cache.clearAll();
}
function defaultTask(done) {
//gulp.series(runFlask, watch);
//runFlask();
//watch();
runFlask();
runBSync();
watchFiles();
done();
}
exports.default = gulp.series(runFlask, runBSync, watchFiles);