-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
155 lines (123 loc) · 3.92 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
(function() {
var bd, browserSync, browserify, clean, coffeeify, data, fs, gulp, jade, less, path, r, rename, runSequence, source, watchify, yaml, zopfli;
path = require('path');
fs = require('fs');
gulp = require('gulp');
r = require('request');
yaml = require('js-yaml');
browserSync = require('browser-sync');
browserify = require('browserify');
watchify = require('watchify');
coffeeify = require('coffeeify');
bd = require('browserify-data');
source = require('vinyl-source-stream');
jade = require('gulp-jade');
less = require('gulp-less');
clean = require('gulp-clean');
zopfli = require('gulp-zopfli');
rename = require('gulp-rename');
runSequence = require('run-sequence');
data = yaml.safeLoad(fs.readFileSync('data.yaml', 'utf8'));
gulp.task("browser-sync", function() {
browserSync.init("public/**", {
server: {
baseDir: "public"
},
injectChanges: false,
logConnections: true,
ghostMode: {
clicks: true,
scroll: true,
location: true
}
});
});
gulp.task("templates", function() {
gulp.src("templates/*.jade").pipe(jade({
locals: data
})).pipe(gulp.dest("./public/"));
});
gulp.task('copy', function() {
return gulp.src('./images/**').pipe(gulp.dest('./public/images/'));
});
gulp.task('styles', function() {
return gulp.src(["styles/app.less", 'styles/print.less', 'styles/iefix.less']).pipe(less({
paths: [path.join(__dirname, "less", "includes")]
})).pipe(gulp.dest("./public"));
});
gulp.task('compile', function() {
var bundle, opts, w;
opts = watchify.args;
opts.extensions = ['.coffee', '.json'];
w = watchify(browserify('./app/index.coffee', opts));
w.transform(coffeeify);
w.transform(bd);
bundle = function() {
return w.bundle().pipe(source('app.js')).pipe(gulp.dest('./public/'));
};
w.on('update', bundle);
bundle();
});
gulp.task("default", ['compile', 'styles', 'templates', 'browser-sync', 'copy'], function() {
gulp.watch("templates/*.jade", ["templates"]);
gulp.watch("styles/*.less", ["styles"]);
gulp.watch('images/**', ['copy']);
});
gulp.task('set_sha', function(cb) {
var r_ops;
r_ops = {
uri: 'https://api.github.com/repos/ookb/rg-client-app/branches/master',
json: true,
headers: {
'user-agent': 'request.js'
}
};
r(r_ops, function(err, response, body) {
if (err) {
throw err;
}
global.sha = body.commit.sha;
return cb();
});
});
gulp.task('prod_clean', function() {
return gulp.src('./prod', {
read: false
}).pipe(clean());
});
gulp.task('prod_compile', function(cb) {
var bundler, opts;
opts = {
debug: true,
extensions: ['.coffee', '.json']
};
bundler = browserify(opts);
bundler.transform(coffeeify);
bundler.transform(bd);
bundler.add('./app/index.coffee');
bundler.plugin('minifyify', {
map: 'script.map.json',
output: './prod/script.map.json'
});
bundler.bundle({
debug: true
}).pipe(source(global.sha + '.js')).pipe(gulp.dest('./prod/')).on('end', cb);
});
gulp.task('prod_template', function() {
data.sha = global.sha;
return gulp.src("templates/*.jade").pipe(jade({
locals: data
})).pipe(gulp.dest("./prod/"));
});
gulp.task('copy_css', ['styles'], function() {
gulp.src('./public/app.css').pipe(rename(global.sha + '.css')).pipe(gulp.dest('./prod'));
gulp.src('./public/print.css', './public/iefix.css').pipe(gulp.dest('./prod'));
return gulp.src('./images/**').pipe(gulp.dest('./prod/images/'));
});
gulp.task('compress', function() {
return gulp.src("./prod/**").pipe(zopfli()).pipe(gulp.dest("./prod"));
});
gulp.task('prod', function(cb) {
runSequence(['prod_clean', 'set_sha'], ['prod_template', 'copy_css', 'prod_compile'], 'compress', cb);
});
}).call(this);