forked from vatesfr/xen-orchestra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
222 lines (185 loc) · 4.51 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
'use strict';
//====================================================================
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
//====================================================================
var options = require('minimist')(process.argv, {
boolean: ['production'],
default: {
production: false,
}
});
//====================================================================
var DIST_DIR = __dirname +'/dist';
var SRC_DIR = __dirname +'/app';
var BOWER_DIR = (function () {
var cfg;
try
{
cfg = JSON.parse(require('fs').readFileSync('./.bowerrc'));
}
catch (error)
{
cfg = {};
}
cfg.cwd || (cfg.cwd = __dirname);
cfg.directory || (cfg.directory = 'bower_components');
return cfg.cwd +'/'+ cfg.directory;
})();
var PRODUCTION = options.production;
var LIVERELOAD = 46417;
//--------------------------------------------------------------------
var pipe = function () {
pipe = require('event-stream').pipe;
return pipe.apply(this, arguments);
};
var concat = function () {
concat = require('event-stream').concat;
return concat.apply(this, arguments);
};
var gIf = function () {
gIf = $.if;
return gIf.apply(this, arguments);
};
var src = (function () {
if (PRODUCTION)
{
return function (pattern) {
return gulp.src(pattern, {
base: SRC_DIR,
cwd: SRC_DIR,
});
};
}
// gulp-plumber prevents streams from disconnecting when errors.
// See: https://gist.github.com/floatdrop/8269868#file-thoughts-md
return function (pattern) {
return gulp.src(pattern, {
base: SRC_DIR,
cwd: SRC_DIR,
}).pipe(
$.watch()
).pipe(
$.plumber({
errorHandler: console.error,
})
);
};
})();
var dest = (function () {
if (PRODUCTION)
{
return function () {
return gulp.dest(DIST_DIR);
};
}
return function () {
return pipe(
gulp.dest(DIST_DIR),
$.livereload(LIVERELOAD)
);
};
})();
//====================================================================
gulp.task('build-pages', function () {
// TODO: Add minification (gulp-htmlmin).
return concat(
src('index.html').pipe(
gIf(!PRODUCTION, $.embedlr({
port: LIVERELOAD,
}))
),
src(['views/**/*.jade', '!**/_*']).pipe($.jade()),
src('views/**/*.html')
).pipe(
dest()
);
});
gulp.task('build-scripts', function () {
return concat(
src('scripts/**/*.coffee').pipe($.coffee()),
src('scripts/**/*.js')
).pipe(
gIf(PRODUCTION, pipe(
$.ngmin(),
$.uglify()
))
).pipe(
dest()
);
});
gulp.task('build-styles', ['install-bower-components'], function () {
return src('styles/main.sass').pipe(
$.rubySass({
loadPath: [
BOWER_DIR,
// Bug in gulp-ruby-sass, local directory should be in the
// include path.
SRC_DIR +'/styles'
]
})
).pipe(dest());
});
gulp.task('copy-assets', ['install-bower-components'], function () {
return src('{favicon.ico,images/**/*}').pipe(
dest()
);
});
gulp.task('install-bower-components', function (done) {
require('bower').commands.install()
.on('error', done)
.on('end', function () {
done();
});
});
//--------------------------------------------------------------------
gulp.task('check-pages', function () {
// TODO: Handle Jade.
return gulp.src(SRC_DIR +'/**/*.html')
.pipe($.htmlhint({
'doctype-first': false, // Incorrect for partials.
'img-alt-require': true,
}))
.pipe($.htmlhint.reporter())
;
});
gulp.task('check-scripts', function () {
return concat(
gulp.src(SRC_DIR +'/**/*.coffee')
.pipe($.coffeelint())
.pipe($.coffeelint.reporter()),
gulp.src(SRC_DIR +'/**/*.js')
.pipe($.jsvalidate())
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
);
});
//--------------------------------------------------------------------
gulp.task('build', [
'build-pages',
'build-scripts',
'build-styles',
'copy-assets',
]);
gulp.task('check', [
'check-pages',
'check-scripts',
]);
gulp.task('clean', function () {
return gulp.src(DIST_DIR, {
read: false,
}).pipe($.clean());
});
gulp.task('distclean', ['clean'], function () {
return gulp.src(BOWER_DIR, {
read: false,
}).pipe($.clean());
});
gulp.task('test', function () {
return gulp.src(SRC_DIR +'/**/*.spec.js')
.pipe($.mocha({
reporter: 'spec'
}));
});
//------------------------------------------------------------------------------
gulp.task('default', ['build']);