This repository has been archived by the owner on Jun 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
138 lines (123 loc) · 4.17 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
var gulp = require('gulp');
var path = require('path');
var open = require('open');
var csso = require('gulp-csso');
var express = require('express');
var lr = require('tiny-lr');
var es = require('event-stream');
var extend = require('extend');
var replace = require('gulp-replace');
var rjs = require('requirejs');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var recess = require('gulp-recess');
var bump = require('gulp-bump');
var deploy = require('gulp-gh-pages');
var server = lr();
var app = express();
var APP_ROOT = __dirname + '/source';
var APP_PORT = 4000;
// Opens a browser with the application path.
gulp.task('open', ['serve'], function() {
open('http://localhost:' + APP_PORT);
});
// Statically serves files and adds the LiveReload script.
gulp.task('serve', function() {
app.use(require('connect-livereload')());
app.use(express.static(APP_ROOT));
app.listen(APP_PORT);
});
// Watches for file changes and reloads browser pages.
gulp.task('watch', function() {
server.listen(35729, function(err) {
if (err) {
return console.log(err);
}
gulp.watch([
'source/index.html',
'source/assets/**/*',
'source/js/**/*'
], function(evt) {
server.changed({
body: {
files: [path.relative(APP_ROOT, evt.path)]
}
});
});
});
});
// Builds the project for production.
gulp.task('build', ['compile'], function() {
return es.concat(
// Build main sources.
gulp.src(['source/index.html'])
.pipe(replace('vendor/requirejs/', 'js/'))
.pipe(replace("require(['./js/main.js'])", "require(['./js/main.js'], function () { require(['main']); })"))
.pipe(replace('vendor/bootstrap/dist', 'assets'))
.pipe(gulp.dest('build')),
gulp.src(['source/js/config-require.js'])
.pipe(uglify())
.pipe(gulp.dest('build/js')),
// Build assets.
gulp.src(['source/favicon.ico'])
.pipe(gulp.dest('build')),
gulp.src(['source/CNAME'])
.pipe(gulp.dest('build')),
gulp.src(['source/assets/css/*'])
.pipe(csso())
.pipe(gulp.dest('build/assets/css')),
gulp.src(['source/assets/fonts/*'])
.pipe(gulp.dest('build/assets/fonts')),
gulp.src(['source/assets/images/*'])
.pipe(gulp.dest('build/assets/images')),
// Build vendor files.
gulp.src(['source/vendor/bootstrap/dist/css/bootstrap.min.css'])
.pipe(gulp.dest('build/assets/css')),
gulp.src(['source/vendor/bootstrap/dist/fonts/*'])
.pipe(gulp.dest('build/assets/fonts')),
gulp.src(['source/vendor/angular-perfect-scrollbar/dependencies/perfect-scrollbar.css'])
.pipe(csso())
.pipe(gulp.dest('build/assets/css')),
gulp.src(['source/vendor/requirejs/require.js'])
.pipe(uglify())
.pipe(gulp.dest('build/js'))
);
});
// Compiles with RequireJS' r.js.
gulp.task('compile', function() {
var config = {
baseUrl: 'source/js',
name: 'main',
optimize: 'uglify2',
out: 'build/js/main.js',
wrap: true,
stubModules: ['text']
};
extend(config, require('./source/js/config-require.js'));
return rjs.optimize(config);
});
// Asserts code quality with various static code analysis tools.
gulp.task('lint', function() {
return es.concat(
gulp.src('source/js/**/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter(stylish)),
gulp.src('source/assets/css/*')
.pipe(recess())
);
});
// Bumps version number.
gulp.task('bump', function() {
gulp.src(['./bower.json', './package.json'])
.pipe(bump({type: 'minor'}))
.pipe(gulp.dest('./'));
});
// Deploys to GitHub Pages.
gulp.task('deploy', function () {
gulp.src('build/**/*')
.pipe(deploy('[email protected]:FlipFlopWeekly/zori.git', 'origin'));
});
// Default developer working task.
gulp.task('work', ['watch', 'open']);
gulp.task('default', ['work']);