-
Notifications
You must be signed in to change notification settings - Fork 74
/
gulpfile.js
57 lines (50 loc) · 1.64 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
/*jshint
esversion: 6,
node: true
*/
const gulp = require('gulp'),
php = require('gulp-connect-php'),
browserSync = require('browser-sync');
const path = require('path');
const fs = require('fs');
const { spawn } = require('node:child_process');
var reload = browserSync.reload;
// - gulp live - start a PHP web-server and browsersync for live-reload
gulp.task('php', function () {
const base = './examples';
php.server({ base, port: 8010, keepalive: true });
if (!fs.existsSync(path.join(base, 'vendor/autoload.php'))) {
setTimeout(() => {
console.log(`composer install...\n`);
const composerInstall = spawn('composer', ['install', '--optimize-autoloader'], { cwd: base });
const stderr = [];
composerInstall.stderr.on('data', (data) => {
stderr.push(data);
});
composerInstall.on('close', (code) => {
console.log(`composer install done, code=${code}`);
if (code && stderr.length) {
console.error(`composer install errors:\n${stderr.join('')}`);
}
});
}, 1e3);
}
});
gulp.task('browser-sync', gulp.parallel('php', function () {
browserSync({
proxy: '127.0.0.1:8010',
port: 8080,
open: true,
notify: false
});
}));
gulp.task('default', gulp.parallel('browser-sync', function () {
gulp.watch(['*.php', 'examples/*.php'])
.on('change', reload)
.on('add', reload)
.on('unlink', function (path, stats) {
reload();
watcher.unwatch(path);
})
;
}));