-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
109 lines (94 loc) · 2.69 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
'use strict';
var gulp = require('gulp');
var eslint = require('gulp-eslint');
var bower = require('gulp-bower');
var vowFs = require('vow-fs');
var del = require('del');
var path = require('path');
var MakePlatform = require('enb/lib/make');
var runSequence = require('run-sequence');
var paths = {
rebuild: [],
lintServer: [
'.enb/*.js',
'controllers/**/*.js',
'models/**/*.js',
'middlewares/**/*.js',
'index.js'
],
lintClient: [
'blocks/**/*.js',
'bundles/*/blocks/**/*.js',
],
test: [
'test/*.js'
],
coverage: [
'controllers/**/*.js',
'lib/**/*.js',
// 'middleware/**/*.js',
'models/**/*.js',
'*.js'
],
vendors: 'vendors'
};
gulp.task('eslint-server', function () {
return gulp.src(paths.lintServer)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('eslint-client', function () {
return gulp.src(paths.lintClient)
.pipe(eslint('./.eslintrc-client'))
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('lint', ['eslint-server', 'eslint-client']);
// Vendors
gulp.task('vendors', function () {
return bower(paths.vendors);
});
// Build
// TODO: publish to npm as gulp-clean-bembundles
gulp.task('clean', function () {
return vowFs.glob('bundles/*')
.then(function (bundles) {
var clearBundles = bundles.map(function (bundle) {
return cleanBundle(bundle);
});
return Promise.all(clearBundles);
});
function cleanBundle(bundle) {
var bundleName = bundle.split('/').pop();
var bemdeclPath = path.join(bundle, bundleName + '.server.bemdecl.js');
return vowFs.exists(bemdeclPath)
.then(function (isBemdeclExist) {
if (isBemdeclExist) {
// Clean the bundle
return del([
path.join(bundle, '*'),
'!' + bemdeclPath,
'!' + path.join(bundle, 'blocks')
]);
}
// remove the bundle if it hasn't a `.bemdecl.js` file
return vowFs.removeDir(bundle);
});
}
});
gulp.task('rebuild', function () {
var make = new MakePlatform();
return make.init(process.cwd())
.then(function () {
make.loadCache();
return make.build([]);
})
.then(function () {
make.saveCache();
make.destruct();
});
});
gulp.task('build', function (done) {
runSequence('clean', 'vendors', 'rebuild', done);
});