forked from moode-player/moode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
575 lines (530 loc) · 23.4 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
/**
* moOde audio player (C) 2014 Tim Curtis
* http://moodeaudio.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
*
* Description: gulp buildscript for frontend
*
* Features:
* - provide automatic bundling of the javascripts files.
* - uses a cache for speed
* - provide sourcemaps for browser side debugging
* - patches files to use the bundles
* - easy way to deploy
* - webserver for frontend development (backup running on moode instance, webserver on desktop computer, uses proxy)
*
* Usage:
*
*
* Install:
* - install npm (apt-get npm, mac and windows download and running installers)
* - from the moode git repro directory run npm ci (installs the required npm modules)
* - call a build target
* - check if your environment is ok by running gulp -v .
* - if says 'command not found', run node_modules/.bin/gulp instead
* - now you can run commands like:
*
* Main build targets:
* gulp clean [--all] - Empties the build/build and build/distr directory, with the --all also the cache is flushed.
*
* gulp build [--force] - Build frontend from {app.src} and put output in {app.dest}
* gulp watch [--build] - Start web server with as root {app.src} with proxy to moode, used for local web development.
* [--force] When --build is given, also perform a build and use {app.dest} as web root
* gulp deploy [--test] - Deploys everything needed (inc php etc) {app.deploy}.
* [--force] With the option --test deploy to build/dist (app.dist).
* [--all] Also deploy moodeutl and the /var/local/www dir
*
* Deploy only copy/update, never removes files.
* When used to real don't forget to sudo first
*
* Default most task only update/use files that are changed (= is newer). With force the files are also updated.
*
* Sub build targets (are automaticly called by the main build targets on need):
* gulp cache - fill cache with files (basedon changed and index.html)
* gulp bundle - (re)bundle the files
* gulp listplugins - list available gulp plugins
*
* Generated Directory tree:
*
* moode
* |- build - directory used by the build scripts for temporary files, no need to checkin. maybe cache checkin for speed.
* |- cache - temporary cache with all individual minified js/css files
* |- css - stylesheets
* |- javascript - javascript
* |- maps - matching sourcemaps
* |- build - all build bundles, including enough files to run again a local js development server
* |- distr - result of a test deploy
*
*
* Inspiration taken from:
* - https://css-tricks.com/gulp-for-beginners/
* - https://nystudio107.com/blog/a-gulp-workflow-for-frontend-development-automation
*
*/
// package vars
const pkg = require("./package.json");
// gulp
const gulp = require("gulp");
var autoprefixer = require('autoprefixer');
var cssnano = require('cssnano');
const path = require('path');
// load all plugins in 'devDependencies' into the variable $
const $ = require('gulp-load-plugins')({
pattern: ['*'],
scope: ['devDependencies']
});
// Error checking; produce an error rather than crashing.
var onError = function(err) {
console.log(err.toString());
this.emit('end');
};
// banner used for generated js and css files
const banner = [
"/**",
" * <%= pkg.description %> (C) <%= pkg.copyright %> <%= pkg.author %>",
" * <%= pkg.homepage %>",
" *",
" * This Program is free software; you can redistribute it and/or modify",
" * it under the terms of the GNU General Public License as published by",
" * the Free Software Foundation; either version 3, or (at your option)",
" * any later version.",
" *",
" * This Program is distributed in the hope that it will be useful,",
" * but WITHOUT ANY WARRANTY; without even the implied warranty of",
" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the",
" * GNU General Public License for more details.",
" *",
" * You should have received a copy of the GNU General Public License",
" * along with this program. If not, see <http://www.gnu.org/licenses/>.",
" *",
" * @version <%= pkg.version %>",
" * @build " + $.moment().format("llll") + " ET",
// " * @release " + $.gitRevSync.long() + " [" + $.gitRevSync.branch() + "]",
" *",
" */",
""
].join("\n");
// banner used for generated html files
// const banner_html = [
// "<!--",
// "/**",
// " * <%= pkg.description %> (C) <%= pkg.copyright %> <%= pkg.author %>",
// " * <%= pkg.homepage %>",
// " *",
// " * @project <%= pkg.name %>",
// " * @version <%= pkg.version %>",
// " * @author <%= pkg.author %>",
// " * @build " + $.moment().format("llll") + " ET",
// // " * @release " + $.gitRevSync.long() + " [" + $.gitRevSync.branch() + "]",
// " * @copyright Copyright (c) <%= pkg.copyright %>",
// " *",
// " */",
// "-->",
// ""
// ].join("\n");
// shorthand date stamp
const CURRENT_DATE= $.moment().format("YYYY-MM-DD")
// used to automatic replace certain patterns in files
const REPLACEMENT_PATTERNS= [
{
match: '__CURRENTDATE__',
replacement: CURRENT_DATE
},
{
match: '__VERSION__',
replacement: pkg.version
},
{
match: '__COPYRIGHT__',
replacement: pkg.copyright
}
];
// used for remote deployment
var gulpSSH = new $.ssh({
ignoreErrors: false,
sshConfig: {
host: pkg.remote.host,
port: 22,
username: pkg.remote.user,
password: pkg.remote.password
}
});
// configure the gulp mode options
const mode = $.mode( { modes: ["build", "development", "test", "all", "force", "remote"],
default: "development",
verbose: false});
const DEPLOY_LOCATION = (mode.test() || mode.remote() ) ? pkg.app.dist: pkg.app.deploy;
/***************************************************************************
* GULP TASKS START HERE
***************************************************************************/
// only used to check the name of the gulp plugins
gulp.task('listplugins', function(done) {
console.log('List of available plugins:');
console.log($);
done();
});
gulp.task('sass', function(done) {
// while isn't installed don't use it
// install gulp-sass to enable support
if($.sass) {
return gulp.src('app/scss/**/*.scss') // Gets all files ending with .scss in app/scss
.pipe($.sass())
.pipe(gulp.dest('app/css'))
.on('end', done);
} else {
done();
}
});
// start an embedded webserver for local development, each call to backend requires proxy entry to handle it
gulp.task('browserSync', function(done) {
$.browserSync.init({
host: '0.0.0.0',
server: {
baseDir: mode.build() ? pkg.app.dest: pkg.app.src,
},
middleware: [
$.httpProxyMiddleware.createProxyMiddleware('/imagesw/thmcache', { target: pkg.server.proxy, changeOrigin: true }),
$.httpProxyMiddleware.createProxyMiddleware('/imagesw/radio-logos', { target: pkg.server.proxy, changeOrigin: true }),
$.httpProxyMiddleware.createProxyMiddleware('/imagesw/bgimage.jpg', { target: pkg.server.proxy, changeOrigin: true }),
$.httpProxyMiddleware.createProxyMiddleware('/command/', { target: pkg.server.proxy , changeOrigin: true}),
$.httpProxyMiddleware.createProxyMiddleware('/*.php', { target: pkg.server.proxy, changeOrigin: true }),
$.httpProxyMiddleware.createProxyMiddleware('/*.php/*', { target: pkg.server.proxy, changeOrigin: true })
]
});
done();
});
gulp.task('browserReload', function(done) {
$.browserSync.reload();
done();
});
function fileNameToMin(relpath) {
var dirname = path.dirname(relpath),
ext =path.extname(relpath),
basename =path.basename(relpath, ext);
if(ext === '.js' ||ext === '.css') {
ext = '.min'+ ext ;
}
var newrelpath= path.join(dirname, basename + ext);
return newrelpath;
}
/**
* Cache create from used js and css resources minified and sourcemaps files.
*
*/
gulp.task('cache', function(done){
var plugins=[
autoprefixer({cascade: false}),
cssnano()
];
return gulp.src(pkg.app.src+'/header.php')
.pipe($.rename(function (path) {
path.basename = 'index';
path.extname = '.html';
}))
.pipe($.replace(/[.]min[.]css\"/g, ".css\"")) // make sure no minified css is uses ass source
.pipe($.replace(/[.]min[.]js\"/g, ".js\"")) // make sure no minified js is uses ass source
.pipe($.replace(/.*BUNDLE_TAG.*/g, "")) // remove comment blocks to in clude everything
.pipe($.replace(/.*CONFIGBLOCKSECTION.*/g, ""))
.pipe($.replace(/.*GEN_DEV_INDEX_TAG.*/g, ""))
.pipe($.removeCode({USEBUNDLE:true, GENINDEXDEV:true, commentStart: "<!--", commentEnd:"-->"}))
.pipe($.useref({ noconcat: true
,allowEmpty: true } ))
.pipe($.if(!mode.force(), $.newer( { dest: pkg.app.cache, map: fileNameToMin}) ))
.pipe($.if('!*.html', $.sourcemaps.init({loadMaps: true})))
.pipe($.if('*.css', $.postcss(plugins) ))
.pipe($.if('*.js', $.uglifyEs.default({output: {comments:false} })))
.pipe($.rename(function (path) {
if(path.extname === '.js' || path.extname === '.css') {
path.basename += '.min';
} }))
.pipe($.sourcemaps.write('maps'))
.pipe($.if('!*.html', $.if(!mode.force(), $.size({showFiles: true, total: true}))))
.pipe($.if(['**/*.js','**/*.css', '**/*.map'], gulp.dest(pkg.app.cache)) )
// .pipe($.if('*.html',$.size({showFiles: true, total: true})))
// .pipe($.if('*.html', gulp.dest(pkg.app.cache)) )
.on('end', done);
});
gulp.task('maps', function (done) {
return gulp.src(pkg.app.cache+'/maps/**/*.map', {base:pkg.app.cache})
.pipe($.if(!mode.force(), $.newer( { dest: pkg.app.dest}) ))
// .pipe($.size({showFiles: true, total: true}))
.pipe(gulp.dest(pkg.app.dest));
});
/**
* Generate the bundle files for css and js, excluding the html file.
* It reuse the minified files in the cache
*/
gulp.task('bundle', gulp.series([`cache`, `maps`],function (done) {
return gulp.src(pkg.app.src+'/header.php')
.pipe($.rename(function (path) {
path.basename = 'index';
path.extname = '.html';
}))
.pipe($.replace(/[.]min[.]css\"/g, ".css\"")) // make sure no minified css is uses ass source
.pipe($.replace(/[.]min[.]js\"/g, ".js\"")) // make sure no minified js is uses ass source
.pipe($.replace(/.*BUNDLE_TAG.*/g, "")) // remove comment blocks to in clude everything
.pipe($.replace(/.*CONFIGBLOCKSECTION.*/g, ""))
.pipe($.replace(/.*GEN_DEV_INDEX_TAG.*/g, ""))
.pipe($.removeCode({USEBUNDLE:true, GENINDEXDEV:true, commentStart: "<!--", commentEnd:"-->"}))
.pipe($.useref( { // transform name to .min version
transformPath:fileNameToMin
// use add path the location with the min versions
,searchPath: pkg.app.cache
,allowEmpty: true }, $.lazypipe().pipe($.sourcemaps.init, { loadMaps: true })))
.pipe($.if(['**/*.min.js', '**/*.min.css'], $.header(banner, {pkg: pkg}) ))
.pipe($.size({showFiles: true, total: true}))
.pipe($.sourcemaps.write('maps'))
// don't write the patched html file
.pipe($.if('!*.html', gulp.dest(pkg.app.dest)))
.on('end', done);
}));
/**
* During frontend development based on gulp we cannot use index.php.
* An alternative index.html has to be generated. It should contain the content of:
* - header.php
* - templates/indextpl.html
* - footer.php
*
* It uses header.php with processing tage to create the src/index.html. This one includes the (parts of the ) resources.
*
*/
gulp.task('genindexdev', function(done){
return gulp.src(pkg.app.src+'/header.php')
.pipe($.rename(function (path) {
path.basename = 'index';
path.extname = '.html';
}))
.pipe($.replace(/[.]min[.]css\"/g, ".css\"")) // make sure no minified css is uses ass source
.pipe($.replace(/[.]min[.]js\"/g, ".js\"")) // make sure no minified js is uses ass source
.pipe($.replace(/.*BUNDLE_TAG.*/g, "")) // adds multiple jquery files instead of one jquery bundle
.pipe($.replace(/.*GEN_DEV_INDEX_TAG.*/g, "")) // make wellformed by adding cloding body and html
.pipe($.replace(/.*CONFIGBLOCKSECTION_BEGIN.*/g, "<!-- CONFIGBLOCKSECTION")) // adds multiple jquery files instead of one jquery bundle
.pipe($.replace(/.*CONFIGBLOCKSECTION_END.*/g, "CONFIGBLOCKSECTION -->")) // adds multiple jquery files instead of one jquery bundle
.pipe($.include({
hardFail: true,
separateInputs: true,
includePaths: [
__dirname + '/www'
]})) // include templates/indextpl.html and footer.php to create working index.html
.pipe($.removeCode({USEBUNDLE:true, GENINDEXDEV:true, commentStart: "<!--", commentEnd:"-->"}))
.pipe((gulp.dest(pkg.app.src) ))
.on('end', done);
});
/**
* Generates the develop index.html (uses the bundles)
*/
gulp.task('genindex', function(done){
return gulp.src(pkg.app.src+'/header.php')
.pipe($.rename(function (path) {
path.basename = 'index';
path.extname = '.html';
}))
.pipe($.if(!mode.force(), $.newer( { dest: pkg.app.dest})))
.pipe($.replace(/[.]min[.]css\"/g, ".css\"")) // make sure no minified css is uses ass source
.pipe($.replace(/[.]min[.]js\"/g, ".js\"")) // make sure no minified js is uses ass source
.pipe($.replace(/.*BUNDLE_TAG.*/g, "")) // adds multiple jquery files instead of one jquery bundle
.pipe($.replace(/.*GEN_DEV_INDEX_TAG.*/g, "")) // make wellformed by adding cloding body and html
.pipe($.replace(/.*CONFIGBLOCKSECTION_BEGIN.*/g, "<!-- CONFIGBLOCKSECTION")) // adds multiple jquery files instead of one jquery bundle
.pipe($.replace(/.*CONFIGBLOCKSECTION_END.*/g, "CONFIGBLOCKSECTION -->")) // adds multiple jquery files instead of one jquery bundle
.pipe($.include({
hardFail: true,
separateInputs: true,
includePaths: [
__dirname + '/www'
]})) // include templates/indextpl.html and footer.php to create working index.html
.pipe($.removeCode({USEBUNDLE:true, GENINDEXDEV:true, NOCONFIGSECTION:true, commentStart: "<!--", commentEnd:"-->"}))
.pipe($.useref({noAssets: true}))
.pipe($.replaceTask({ patterns: REPLACEMENT_PATTERNS }))
.pipe($.preprocess({ context: { STRIP_CONFIG: true } }))
.pipe($.size({showFiles: true, total: false}))
.pipe(($.if('index.html', gulp.dest(pkg.app.dest))) )
.on('end', done);
});
gulp.task('patchheader', function (done) {
return gulp.src(pkg.app.src+'/header.php')
//.pipe($.if(!mode.force(), $.newer( { dest: pkg.app.dist})))
.pipe($.replace(/[.]min[.]css\"/g, ".css\"")) // make sure no minified css is uses ass source
.pipe($.replace(/[.]min[.]js\"/g, ".js\"")) // make sure no minified js is uses ass source
.pipe($.replace(/.*BUNDLE_TAG.*/g, ""))
.pipe($.removeCode({ GENINDEXDEV: false, NOCONFIGSECTION: false, GENINDEXDEV: false, USEBUNDLE:true, commentStart: "<!--", commentEnd:"-->"}))
.pipe($.preprocess({ context: { STRIP_CONFIG: true } }))
.pipe($.useref({noAssets: true}))
.pipe($.size({showFiles: true, total: false}))
.pipe(gulp.dest(DEPLOY_LOCATION))
.on('end', done);
});
gulp.task('patchfooter', function (done) {
return gulp.src(pkg.app.src+'/footer.php')
//.pipe($.if(!mode.force(), $.newer( { dest: pkg.app.dist})))
.pipe($.removeCode({USEBUNDLE:true, commentStart: "<!--", commentEnd:"-->"}))
.pipe($.htmlmin({ collapseWhitespace: true,
ignoreCustomFragments: [ /<%[\s\S]*?%>/, /<\?[=|php]?[\s\S]*?\?>/ ]
}))
.pipe($.rename(function (path) {
path.basename += '.min';
}))
.pipe($.size({showFiles: true, total: false}))
.pipe(gulp.dest(DEPLOY_LOCATION))
.on('end', done);
});
gulp.task('patchindex', function (done) {
return gulp.src(pkg.app.src+'/index.php')
.pipe($.if(!mode.force(), $.newer( { dest: pkg.app.dist})))
.pipe($.replace(/indextpl[.]html/g, "indextpl.min.html"))
.pipe($.replace(/footer[.]php/g, "footer.min.php"))
.pipe($.size({showFiles: true, total: false}))
.pipe(gulp.dest(DEPLOY_LOCATION))
.on('end', done);
});
gulp.task('patchconfigs', function (done) {
return gulp.src(pkg.app.src+'/*-config.php')
.pipe($.if(!mode.force(), $.newer( { dest: pkg.app.dist})))
.pipe($.replace(/footer[.]php/g, "footer.min.php"))
.pipe($.size({showFiles: true, total: false}))
.pipe(gulp.dest(DEPLOY_LOCATION))
.on('end', done);
});
gulp.task('minifyhtml', function (done) {
return gulp.src(pkg.app.src+'/templates/indextpl.html')
.pipe($.if(!mode.force(), $.newer( { dest: pkg.app.dist})))
.pipe($.htmlmin({ collapseWhitespace: true,
ignoreCustomFragments: [ /<%[\s\S]*?%>/, /<\?[=|php]?[\s\S]*?\?>/ ]
}))
.pipe($.rename(function (path) {
path.basename += '.min';
}))
.pipe($.size({showFiles: true, total: false}))
.pipe(gulp.dest(DEPLOY_LOCATION+'/templates'))
.on('end', done);
});
gulp.task('artwork', function(done) {
gulp.src([ pkg.app.src+'/webfonts/**/*'
,pkg.app.src+'/fonts/**/*'
,pkg.app.src+'/images/**/*' ], {base:pkg.app.src})
.pipe($.if(!mode.force(), $.newer( { dest: pkg.app.dest})))
// .pipe($.size({showFiles: true, total: true}))
.pipe(gulp.dest(pkg.app.dest));
done();
});
gulp.task('clean', function(done) {
if(mode.all() )
return $.del([pkg.app.dest,pkg.app.dist, pkg.app.src+'/index.html', pkg.app.cache]);
else
return $.del([pkg.app.dest,pkg.app.dist, pkg.app.src+'/index.html']);
});
gulp.task('build', gulp.series( [`sass`, `genindexdev`, `genindex`, `bundle`, `artwork`], function (done) {
done();
}));
gulp.task('deploymoodeutl', function (done) {
return gulp.src([ pkg.app.src+'/../usr/local/bin/moodeutl' ])
.pipe($.size({showFiles: true, total: true}))
.pipe(gulp.dest(DEPLOY_LOCATION+'/../../usr/local/bin'))
.on('end', done);
});
gulp.task('deployvarlocalwww', function (done) {
return gulp.src([ pkg.app.src+'/../var/local/www/**' ])
.pipe($.size({showFiles: true, total: true}))
.pipe(gulp.dest(DEPLOY_LOCATION+'/../local/www'))
.on('end', done);
});
gulp.task('deployback', gulp.series(['patchheader','patchfooter', 'patchindex', 'patchconfigs', 'minifyhtml'], function (done) {
return gulp.src([ pkg.app.src+'/*.php'
,pkg.app.src+'/command/**/*'
,pkg.app.src+'/inc/**/*'
,pkg.app.src+'/templates/**/*'
,pkg.app.src+'/*'
// exclude generated content:
,'!'+pkg.app.src+'/index.html'
,'!'+pkg.app.src+'/templates/indextpl.min.html'
,'!'+pkg.app.src+'/templates/indextpl.html'
,'!'+pkg.app.src+'/header.php'
,'!'+pkg.app.src+'/footer.php'
,'!'+pkg.app.src+'/footer.min.php'
,'!'+pkg.app.src+'/index.php'
,'!'+pkg.app.src+'/*-config.php'
,pkg.app.src+'/css/shellinabox*.css'
],
{base: pkg.app.src})
// optional headers fields can be update and or added:
//.pipe( $.replaceTask({ patterns: REPLACEMENT_PATTERNS }))
//.pipe($.if('*.html', $.header(banner_html, {pkg: pkg}) ))
.pipe($.if(!(mode.test()||mode.remote()), $.chown('root','root')))
.pipe($.if(!mode.force(), $.newer( { dest: DEPLOY_LOCATION})))
//.pipe($.size({showFiles: true, total: true}))
.pipe($.if('*.html', $.replaceTask({ patterns: REPLACEMENT_PATTERNS})))
.pipe(gulp.dest(DEPLOY_LOCATION))
.on('end', done);
}));
gulp.task('deployfront', function (done) {
return gulp.src( [pkg.app.dest+'/**/*', '!'+pkg.app.dest+'/index.html'] )
.pipe($.if(!mode.force(), $.newer( { dest: DEPLOY_LOCATION})))
.pipe(gulp.dest(DEPLOY_LOCATION))
.on('end', done);
});
/**
* upload pkg.app.dist to a temp dir on target device
*/
gulp.task('upload2remote', function (done) {
return gulp.src(pkg.app.dist+'/**/*')
.pipe($.scp3({
host: pkg.remote.host,
username: pkg.remote.user,
password: pkg.remote.password,
dest: '/home/pi/www.deploy'}))
.on('error', function(err) {
console.log(err);
})
.on('end', done);
})
/**
* Move temp dir on target device to /var/www and activate it
*/
gulp.task('deploy2remote', function (done) {
return gulpSSH
.exec(['sudo rm -rf /var/www.prev',
'sudo mv /var/www/ /var/www.prev',
'sudo mv /home/pi/www.deploy /var/www',
'sudo chmod -R +x /var/www/command/*',
// required if uploaded from windows
process.platform === "win32" ? 'find /var/www/command/* -exec /usr/bin/dos2unix {} \\; 2>/dev/null': 'echo',
'/usr/local/bin/moodeutl -r'
], {filePath: 'commands.log'})
//.pipe(gulp.dest('logs'))
.on('end', done);
})
var deployTasks = ['deployfront', 'deployback'];
if ( mode.remote() == true ) {
deployTasks = ['deployfront', 'deployback', 'upload2remote', 'deploy2remote'];
}
else if (mode.all() ==true ){
deployTasks = ['deployfront', 'deployback', 'deploymoodeutl', 'deployvarlocalwww'];
}
gulp.task('deploy', gulp.series( deployTasks, function (done) {
done();
}));
var watchTasks = mode.build() ? ['build', 'browserSync']: ['sass', 'genindexdev', 'browserSync'],
triggerTasks = mode.build() ? ['build', 'browserReload']: ['sass', 'genindexdev', 'browserReload'];
gulp.task('watch', gulp.series( watchTasks, function (done){
gulp.watch(pkg.app.src+'/scss/**/*.scss', gulp.series(triggerTasks));
gulp.watch(pkg.app.src+'/css/**/*.css', gulp.series(triggerTasks));
//gulp.watch(pkg.app.src+'/*.html', gulp.series(triggerTasks));
gulp.watch(pkg.app.src+'/js/**/*.js', gulp.series(triggerTasks))
//gulp.watch(pkg.app.src+'/../gulpfile.js',
//gulp.watch(pkg.app.src+'/../package.json'));
done();
}));