-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
55 lines (44 loc) · 1.33 KB
/
index.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
var gulp = require('gulp'),
aglio = require('gulp-aglio'),
changed = require('gulp-changed'),
path = require('path');
var tinylr;
var tinylr_port = 35729,
app_port = 4000,
root_cwd = process.cwd(),
output_dir = path.join(root_cwd,'docs');
gulp.task('livereload', function() {
tinylr = require('tiny-lr')();
tinylr.listen(tinylr_port);
});
gulp.task('express', function() {
var express = require('express');
var app = express();
app.use(require('connect-livereload')({port: tinylr_port}));
app.use(express.static(output_dir));
app.listen(app_port, '0.0.0.0');
});
gulp.task('apib', function() {
return gulp.src('apib/**/*.apib')
.pipe(aglio({tempalte: 'default'}))
.pipe(changed('docs'))
.pipe(gulp.dest('docs'));
});
gulp.task('watch', function() {
gulp.watch('apib/**/*.apib', ['apib']);
gulp.watch('docs/**/*.html', notifyLiveReload);
});
gulp.task('serve', ['express', 'livereload'], function(){});
gulp.task('default', ['apib', 'serve', 'watch'], function() {});
function notifyLiveReload(event) {
var file_name = require('path').relative(__dirname, event.path);
var normpath = path.normalize(file_name);
var relpath = path.join(root_cwd, normpath);
console.log('* Reloading:', relpath);
tinylr.changed({
body: {
files: [file_name]
}
});
}
module.exports = gulp;