This repository has been archived by the owner on Apr 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
92 lines (84 loc) · 2.76 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
var gulp = require('gulp');
var exec = require('child_process').exec;
var browserSync = require('browser-sync').create();
let update = () => {
clearTimeout(timeoutHandle);
timeoutHandle = setTimeout(() => {
console.log('Component files changed. Repacking for demo...');
exec('npm run update-demo', function (err, _stdOut, _stdErr) {
if (err) {
console.log("Demo NPM package failed to update.", err);
return;
}
console.log("Demo NPM package updated.", _stdOut);
browserSync.reload();
});
}, 500);
}
var timeoutHandle;
var firstCompile = true;
gulp.task('compile', function (done) {
var tsc = exec("tsc --watch");
tsc.stderr.on('close', console.log);
tsc.stdout.on('data', o => {
//Prevent tsc from clearing the console with \033c
console.info(o.replace('\033c', ''));
if (o.indexOf('Watching for file changes') > -1) {
if (!firstCompile) {
update();
}
firstCompile = false;
}
})
});
gulp.task('serve', (done) => {
var serve = exec('polymer serve -p 8000 -v demo');
serve.stdout.on('data', o => {
console.log(o);
if (o.indexOf('Files in this directory are available under the following URLs') > -1) {
browserSync.init({
proxy: "localhost:8000",
startPath: "/",
snippetOptions: {
// just append the snippet to the end of the file
rule: {
match: /$/i,
fn: function (snippet, match) {
return snippet + match;
}
}
}
});
}
})
});
gulp.task('watch-demo', function () {
var directoriesToWatch = ["demo/*.html"]
directoriesToWatch.forEach(function (directory) {
console.log(`Listening for changes, ${directory}`);
gulp.watch(directory, {
read: false,
verbose: true
}).on('change', (_e) => {
browserSync.reload();
});
});
});
gulp.task('compile-demo', function (done) {
var tsc = exec("cd demo && tsc --watch");
tsc.stderr.on('close', console.log);
tsc.stdout.on('data', o => {
//Prevent tsc from clearing the console with \033c
console.info(o.replace('\033c', ''));
if (o.indexOf('Watching for file changes') > -1) {
if (!firstCompile) {
browserSync.reload();
}
firstCompile = false;
}
})
});
gulp.task('browser-sync', () => {
console.log('Start browser sync...');
});
gulp.task('default', ['compile', 'serve', 'watch-demo', 'compile-demo']);