-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
257 lines (221 loc) · 7.04 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var cleancss = require('gulp-cleancss');
var concat = require('gulp-concat');
var cssmin = require('gulp-cssmin');
var gulp = require('gulp');
var gulpif = require('gulp-if');
var inline = require('rework-plugin-inline');
var jshint = require('gulp-jshint');
var path = require('path');
var prefix = require('gulp-autoprefixer');
var rework = require('gulp-rework');
var source = require('vinyl-source-stream');
var sourcemaps = require('gulp-sourcemaps');
var suit = require('rework-suit');
var uglify = require('gulp-uglify');
var literalify = require('literalify');
var watchify = require('watchify');
var reactify = require('reactify');
var gutil = require('gulp-util');
var livereload = require('gulp-livereload');
var streamify = require('gulp-streamify');
var notify = require('gulp-notify');
var glob = require('glob');
var react = require("gulp-react");
// External dependencies you do not want to rebundle while developing,
// but include in your application deployment
var dependencies = [];
// Bower External dependencies
var bowerDependencies = {
// map module names with global objects
'jquery': 'window.$'
};
var browserifyTask = function (options) {
// Our app bundler
var appBundler = browserify({
entries: [options.src], // Only need initial file, browserify finds the rest
transform: [reactify], // We want to convert JSX to normal javascript
debug: options.development, // Gives us sourcemapping
cache: {}, packageCache: {}, fullPaths: options.development // Requirement of watchify
}).transform(literalify.configure(bowerDependencies));
// We set our dependencies as externals on our app bundler when developing
(options.development ? dependencies : []).forEach(function (dep) {
appBundler.external(dep);
});
// The rebundle process
var rebundle = function () {
var start = Date.now();
console.log('Building APP bundle');
appBundler.bundle()
.on('error', gutil.log)
.pipe(source('bundle.js'))
.pipe(gulpif(!options.development, streamify(uglify())))
.pipe(gulp.dest(options.dest))
.pipe(gulpif(options.development, livereload()))
.pipe(notify(function () {
console.log('APP bundle built in ' + (Date.now() - start) + 'ms');
}));
};
// Fire up Watchify when developing
if (options.development) {
appBundler = watchify(appBundler);
appBundler.on('update', rebundle);
}
rebundle();
// We create a separate bundle for our dependencies as they
// should not rebundle on file changes. This only happens when
// we develop. When deploying the dependencies will be included
// in the application bundle
if (options.development) {
var testFiles = glob.sync('./specs/**/*-spec.js');
var testBundler = browserify({
entries: testFiles,
debug: true, // Gives us sourcemapping
transform: [reactify],
cache: {}, packageCache: {}, fullPaths: true // Requirement of watchify
});
dependencies.forEach(function (dep) {
testBundler.external(dep);
});
var rebundleTests = function () {
var start = Date.now();
console.log('Building TEST bundle');
testBundler.bundle()
.on('error', gutil.log)
.pipe(source('specs.js'))
.pipe(gulp.dest(options.dest))
.pipe(livereload())
.pipe(notify(function () {
console.log('TEST bundle built in ' + (Date.now() - start) + 'ms');
}));
};
testBundler = watchify(testBundler);
testBundler.on('update', rebundleTests);
rebundleTests();
// Remove react-addons when deploying, as it is only for
// testing
if (!options.development) {
dependencies.splice(dependencies.indexOf('react-addons'), 1);
}
// Run the vendor bundle
var start = new Date();
console.log('Building VENDORS bundle');
gulp.src([
'./bower_components/jquery/dist/jquery.js',
'./assets/lib/jquery.legacy.min.js',
'./assets/lib/semantic.js',
'./assets/lib/plugins.js',
'./assets/lib/master.js',
])
.pipe(concat('vendors.js'))
//.pipe(uglify())
//.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./public/javascript'))
.pipe(notify(function () {
console.log('VENDORS bundle built in ' + (Date.now() - start) + 'ms');
}));
}
};
var cssTask = function (options) {
if (options.development) {
var run = function () {
console.log(arguments);
var start = new Date();
console.log('Building CSS bundle');
gulp.src(options.src)
.pipe(concat('main.css'))
.pipe(gulp.dest(options.dest))
.pipe(gulpif(options.development, livereload()))
.pipe(notify(function () {
console.log('CSS bundle built in ' + (Date.now() - start) + 'ms');
}));
};
run();
gulp.watch(options.src, run);
} else {
gulp.src(options.src)
.pipe(concat('main.css'))
.pipe(cssmin())
.pipe(gulp.dest(options.dest));
}
};
var htmlTask = function (options) {
var run = function () {
gulp.src(options.src)
.pipe(livereload());
};
gulp.watch(options.src, run);
};
gulp.task('images', function () {
gulp.src('./assets/images/**/*')
.pipe(gulp.dest('./public/images'));
});
// Fonts
gulp.task('fonts', function () {
// font-awesome
gulp.src([
'./bower_components/font-awesome/fonts/*.*'])
.pipe(gulp.dest('./public/fonts'));
// flat-ui
gulp.src([
'./bower_components/flat-ui/dist/fonts/**/*'])
.pipe(gulp.dest('./public/fonts'));
});
// copy
gulp.task('copy', function () {
// copy-flat-ui-css-map
gulp.task('copy-flat-ui-css-map', function () {
return gulp.src([
'./bower_components/flat-ui/dist/css/flat-ui.css.map'])
.pipe(gulp.dest('./public/css'));
});
// fix-ie
gulp.task('copy-fix-ie', function () {
return gulp.src([
'./assets/js/html5shiv.js',
'./assets/js/respond.min.js'])
.pipe(gulp.dest('./public/js'));
});
});
gulp.task('lint', function () {
return gulp.src([
'./gulpfile.js',
'./assets/javascript/**/*.js'
])
.pipe(react())
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
var doRun = function (development) {
//browserifyTask({
// development: development,
// src: './assets/javascript/index.js',
// dest: './public/javascript/'
//});
cssTask({
development: development,
src: [
'./bower_components/bootstrap/dist/css/bootstrap.css',
'./bower_components/flat-ui/dist/css/flat-ui.css',
'./assets/css/fix-flat-ui.css',
'./assets/css/style.css',
'./assets/css/style-*.css',
'./bower_components/font-awesome/css/font-awesome.css'
],
dest: './public/css'
});
htmlTask({
src: './templates/**/*'
});
};
// Starts our development workflow
//gulp.task('default', ['lint', 'fonts', 'images', 'semantic-theme'], function () {
// var development = true;
// doRun(development);
//});
gulp.task('build', ['fonts', 'images', 'copy'], function () {
var development = true;
doRun(development);
});