-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
157 lines (129 loc) · 4.26 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
'use strict';
var gulp = require('gulp');
var less = require('gulp-less');
var sass = require('gulp-sass');
sass.compiler = require('node-sass');
var path = require('path');
// Create an electron-connect server to enable reloading
var server = require('electron-connect').server.create();
// { stopOnClose: true, // logLevel: 2 }
server.on('closed', function(){
console.log("Exit process on server side.");
//process.exit();
//server.stop();
});
/*var callback = function(electronProcState) {
console.log('electron process state: ' + electronProcState);
if (electronProcState == 'stopped') {
process.exit();
}
};*/
gulp.task('startServer', function(done){
server.start();
done();
})
gulp.task('less' ,function () {
return gulp.src('./less/*.less')
.pipe(less())
.pipe(gulp.dest('./public/css'));
});
/**
* Transpiling the .scss file of the Tagify module.
* Makes working easier. As the styling can be done by modifying variables
* directly in the scss code of Tagify module..
*/
gulp.task('transpileTagifySass', function(){
gulp.src('./node_modules/@yaireo/tagify/src/tagify.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./public/css'));
});
gulp.task('watch', function(){
gulp.watch('./less/*.less', { events: 'all' }, function(cb){
/* callback function and event object are async completion code so that
watch function not only exectutes once but on every event*/
gulp.src('./less/*.less')
.pipe(less())
.pipe(gulp.dest('./public/css'));
//server.reload();
//console.log("server: broadcast reload");
server.restart();
cb();
});
gulp.watch(['./*.js', './*.html'], { events: 'all' }, function(cb){
/* callback function and event object are async completion code so that
watch function not only exectutes once but on every event*/
server.restart();
cb();
});
gulp.watch(['./node_modules/@yaireo/tagify/src/tagify.scss'], { events: 'all'}, function(cb){
gulp.src('./node_modules/@yaireo/tagify/src/tagify.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./public/css'));
server.restart();
cb();
});
gulp.watch(['./scripts/*.*'], { events: 'all' }, function(cb){
server.restart();
cb();
});
gulp.watch(['./_views/*.*'], { events: 'all' }, function(cb){
server.restart();
cb();
});
gulp.watch(['./_controllers/*.*'], { events: 'all' }, function(cb){
server.restart();
cb();
});
gulp.watch(['./_models/*.*'], { events: 'all' }, function(cb){
server.restart();
cb();
});
gulp.watch(['./_app/*.*'], { events: 'all' }, function(cb){
server.restart();
cb();
});
gulp.watch(['./_app/*.*'], { events: 'all' }, function(cb){
server.restart();
cb();
});
gulp.watch(['./_app/commands/*.*'], { events: 'all' }, function(cb){
server.restart();
cb();
});
gulp.watch(['./_util/*.*'], { events: 'all' }, function(cb){
server.restart();
cb();
});
})
/* New way Gulp v4.. with parallel() and series()
Since wrapping the server start in a gulp task also solves
the problem with the zombie process. Why did I not see that.
*/
gulp.task('start', gulp.series('less', 'startServer', 'watch'));
//'lessWatch','appWatchBrowser','appWatchRenderer' )));
/**
* NOTE: For some reason I could not find out the
* reload function does not work. Even though it does
* broadcast the 'reload' event to the client, calling
* reload function on the BrowserWindow does not reload
* the page content (html, css) also clearing the cache
* has no effect.
* I DECIDED TO JUST RESTART THE APP on every change.
*
* Also important:
* Once the gulp script is terminated, one has to
* KILL THE LAST PROCESS from activity monitor.
*/
/* Obsolete from Gulp v3..
gulp.task('start', ()=>{
gulp.series('less');
console.log("============ Wrote .less to .css =============");
server.start();
//Watch js files and restart Electron if they change
gulp.parallel(["appWatchBrowser","appWatchRenderer",'lessWatch']);
//watch html
//gulp.watch(['./index.html'], electron.reload);
//gulp.series();
//watch css files, but only reload (no restart necessary)
//gulp.series();
});*/