-
Notifications
You must be signed in to change notification settings - Fork 14
/
gulpfile.js
213 lines (186 loc) · 5.85 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
var gulp = require('gulp'),
gutil = require('gulp-util'),
path = require('path'),
plumber = require('gulp-plumber'),
less = require('gulp-less'),
uglify = require('gulp-uglify'),
jshint = require('gulp-jshint'),
concat = require('gulp-concat'),
merge = require('merge-stream'),
handlebars = require('gulp-handlebars'),
wrap = require('gulp-wrap'),
declare = require('gulp-declare'),
watch = require('gulp-watch'),
mocha = require('gulp-mocha'),
spawnmocha = require('gulp-spawn-mocha'),
config = require('./lib/config')();
var mochaOpts = {
reporter: path.join(__dirname, 'lib', 'mochawesome'),
timeout: 30000,
slow: 1,
'no-exit': true
};
var watchFiles = [
path.join(config.srcLessDir, '*.less'),
path.join(config.srcJsDir, '*.js'),
path.join('!', config.srcJsDir, 'hbsHelpers.js'),
path.join(config.srcHbsDir, '*.mu')
];
var testPaths = {
basic: ['./test/basic/test.js'],
mem: ['./test/basic/mem-test.js'],
recursive: ['./test/basic'],
fiveby: [
'./test/fiveby/*.js',
'./test/fiveby/**/*.js'
]
};
var lintPaths = {
server: './.jshintrc',
client: './client.jshintrc',
lint: [
'./lib/*.js',
'!./lib/templates.js'
],
felint: [
path.join(config.srcJsDir, '*.js'),
path.join('!'+config.srcJsDir, 'lodash.custom.js')
]
};
function onWatchFileChanged(file) {
var ext = file.path.slice(file.path.lastIndexOf('.') + 1);
gutil.log(gutil.colors.yellow('Change detected in ' + file.path.replace(file.cwd, '')));
if (ext === 'less') {
return gulp.start('styles');
}
if (ext === 'js') {
return gulp.start('clientScripts');
}
if (ext === 'mu') {
return gulp.start('templates');
}
}
// Build Tasks
gulp.task('fonts', function () {
return gulp.src(path.join(config.srcFontsDir, '*'))
.pipe(gulp.dest(config.buildFontsDir));
});
gulp.task('styles', function () {
return gulp.src(path.join(config.srcLessDir, '[^_]*.less'))
.pipe(plumber({errorHandler: gutil.log}))
.pipe(less({
paths: [config.srcLessDir, config.bsLessDir, config.faLessDir],
compress: true
}))
.pipe(plumber({errorHandler: gutil.log}))
.pipe(gulp.dest(config.buildCssDir));
});
gulp.task('vendorScripts', function () {
return gulp.src(config.vendorJsFiles)
.pipe(concat('vendor.js'))
.pipe(uglify())
.pipe(gulp.dest(config.buildJsDir));
});
gulp.task('clientScripts', ['lint'], function () {
return gulp.src(config.clientJsFiles)
.pipe(concat('mochawesome.js'))
.pipe(uglify())
.pipe(gulp.dest(config.buildJsDir));
});
gulp.task('templates', function () {
var partials = gulp.src(path.join(config.srcHbsDir, '_*.mu'))
.pipe(handlebars({
handlebars: require('handlebars'),
compilerOptions: {
preventIndent: true
}
}))
.pipe(wrap('Handlebars.registerPartial(<%= processPartialName(file.relative) %>, Handlebars.template(<%= contents %>));', {}, {
imports: {
processPartialName: function(fileName) {
// Strip the extension
// Escape the output with JSON.stringify
return JSON.stringify(path.basename(fileName, '.js'));
}
}
}));
var templates = gulp.src(path.join(config.srcHbsDir, '[^_]*.mu'))
.pipe(handlebars())
.pipe(wrap('Handlebars.template(<%= contents %>)'))
.pipe(declare({
root: 'exports',
noRedeclare: true, // Avoid duplicate declarations
processName: function(filePath) {
return declare.processNameByPath(filePath.replace('src/templates/'.replace(/\//g, path.sep), ''));
}
}));
var helpers = gulp.src(path.join(config.srcJsDir, 'hbsHelpers.js'));
return merge(partials, templates, helpers)
.pipe(concat('templates.js'))
.pipe(wrap('var Handlebars = require("handlebars");\n <%= contents %>'))
.pipe(gulp.dest(config.libDir));
});
// Linting
gulp.task('svrlint', function () {
return gulp.src(lintPaths.lint)
.pipe(jshint(lintPaths.server))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});
gulp.task('felint', function () {
return gulp.src(lintPaths.felint)
.pipe(jshint(lintPaths.client))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});
// Watch Tasks
gulp.task('watch', function () {
watch(watchFiles, onWatchFileChanged);
});
// Test Tasks
gulp.task('fiveby', function () {
return gulp.src(testPaths.fiveby)
.pipe(spawnmocha(mochaOpts))
.on('error', console.warn.bind(console));
});
gulp.task('test', function () {
return gulp.src(testPaths.basic)
.pipe(mocha(mochaOpts))
.on('error', console.warn.bind(console));
});
gulp.task('mem-test', function () {
return gulp.src(testPaths.mem)
.pipe(mocha(mochaOpts))
.on('error', console.warn.bind(console));
});
gulp.task('test-recursive', function () {
mochaOpts.recursive = true;
return gulp.src(testPaths.recursive)
.pipe(mocha(mochaOpts))
.on('error', console.warn.bind(console));
});
gulp.task('testOpts', function () {
mochaOpts.reporterOptions = {
reportDir: 'customDir',
reportName: 'customName',
reportTitle: 'customTitle',
inlineAssets: true,
autoOpen: true
};
return gulp.src(testPaths.basic)
.pipe(mocha(mochaOpts))
.on('error', console.warn.bind(console));
});
gulp.task('testOpts2', function () {
mochaOpts.reporterOptions = 'reportDir=customDir,reportName=customName,reportTitle=customTitle,inlineAssets=true,autoOpen=true';
return gulp.src(testPaths.basic)
.pipe(spawnmocha(mochaOpts))
.on('error', console.warn.bind(console));
});
// Default/Combo Tasks
gulp.task('build', ['lint'], function () {
return gulp.start('assemble');
});
gulp.task('lint', ['svrlint', 'felint']);
gulp.task('assemble', ['fonts', 'styles', 'clientScripts', 'vendorScripts', 'templates']);
gulp.task('default', ['test']);