-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgulpfile.js
142 lines (115 loc) · 3.16 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
var gulp = require('gulp');
var gutil = require('gulp-util');
var open = require('gulp-open');
var watch = require('gulp-watch');
var sys = require('sys');
var exec = require('child_process').exec;
// var livereload = require('gulp-livereload');
// var filter = require('gulp-filter');
// =============================================================================
var EXPRESS_PORT = 8080;
var EXPRESS_ROOT = __dirname;
var LIVERELOAD_PORT = 35729;
var APP_ROOT = 'public';
var lr_files = [
APP_ROOT + '/**/*.html',
APP_ROOT + '/**/*.js',
APP_ROOT + '/**/*.css',
'!' + APP_ROOT + '/libs/**',
APP_ROOT + '/libs/browsercast/**',
];
function shellCmd(error, stdout, stderr) { sys.puts(stdout); }
/**
* Gulp tasks
*/
gulp.task('default', ['server', 'watch', 'open'], function() {});
gulp.task('node', ['watch', 'open'], function() {});
gulp.task('open', function() {
var options = {
url: 'http://localhost:' + EXPRESS_PORT,
app: 'firefox'
};
gulp.src(APP_ROOT + '/index.html').pipe(open('', options));
});
gulp.task('server', function() {
var express = require('express');
var app = express();
app.use(require('connect-livereload')({
port: LIVERELOAD_PORT
}));
app.use(express.static(__dirname + '/' + APP_ROOT));
app.listen(EXPRESS_PORT);
});
gulp.task('livereload', function() {
lr = require('tiny-lr')();
lr.listen(LIVERELOAD_PORT);
});
gulp.task('watch', ['livereload'], function() {
exec("gulp templates", shellCmd);
gulp.watch(lr_files, notifyLivereload);
});
/**
* Compile Templates
*/
var handlebars = require('gulp-handlebars');
var defineModule = require('gulp-define-module');
var declare = require('gulp-declare');
var concat = require('gulp-concat');
gulp.task('templates', function() {
var files = [
APP_ROOT + '/**/templates/*.html',
APP_ROOT + '/demo/reveal/*'];
function compile() {
gulp.src(files)
.pipe(handlebars())
.pipe(defineModule('plain'))
.pipe(declare({
namespace: 'AppTemplate'
}))
.pipe(concat('templates.js'))
.pipe(gulp.dest(APP_ROOT + '/js'));
};
watch({glob: files}, compile);
});
/**
* Prepare export zip
*/
var AdmZip = require('adm-zip');
gulp.task('buildZip', function() {
var zip = new AdmZip();
zip.addLocalFile(APP_ROOT + '/js/reveal/export/init.js', 'reveal/js');
zip.addLocalFolder(APP_ROOT + '/libs/browsercast', 'reveal/js/browsercast');
zip.addLocalFolder(APP_ROOT + '/libs/reveal', 'reveal/js/reveal');
zip.writeZip(APP_ROOT + '/js/reveal/reveal.zip');
});
/**
* Build deploy
*/
gulp.task('build', ['buildZip'], function() {
gutil.log('Build end:', gutil.colors.cyan('Now Deploy!'));
});
gulp.task('dev', function() {
var ncp = require('ncp').ncp;
ncp(APP_ROOT + '/libs/browsercast', APP_ROOT + '/demo/reveal/js/browsercast', function (err) {
if (err) {
return console.error(err);
}
gutil.log('copy:', gutil.colors.cyan('done!'));
});
});
/**
* Functions
*/
function notifyLivereload2(event) {
gulp.src(event.path, {read: false})
.pipe(livereload(lr));
}
function notifyLivereload(event) {
var fileName = require('path').relative(EXPRESS_ROOT, event.path);
lr.changed({
body: {
files: [fileName]
}
});
gutil.log('file changed:', gutil.colors.cyan(fileName));
}