forked from StackStorm/st2web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
169 lines (147 loc) · 4.21 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
/* jshint node: true */
'use strict';
var gulp = require('gulp')
, jshint = require('gulp-jshint')
, path = require('path')
, es = require('event-stream')
, less = require('gulp-less')
, concat = require('gulp-concat')
, util = require('gulp-util')
, prefix = require('gulp-autoprefixer')
, fontelloUpdate = require('fontello-update')
, protractor = require('gulp-protractor').protractor
, plumber = require('gulp-plumber')
, htmlreplace = require('gulp-html-replace')
, bowerFiles = require('main-bower-files')
, glob = require('glob')
, csscomb = require('gulp-csscomb')
;
var express = require('express')
, http = require('http')
, app = express();
app.use(express.static(__dirname));
var settings = {
port: 3000,
dev: '.',
js: ['main.js', 'modules/**/*.js', 'apps/**/*.js'],
styles: {
src: ['./less/style.less', './apps/**/*.less', './modules/**/*.less'],
includes: 'less/',
dest: 'css'
},
html: 'index.html'
};
var debug = function () {
return es.through(function write(data) {
console.log('WRITE:', data);
//console.log(data ? data.contents.toString() : '');
this.emit('data', data);
}, function end(data) {
console.log('END:', data);
//console.log(data ? data.contents.toString() : '');
this.emit('end', data);
});
};
debug();
gulp.task('gulphint', function () {
return gulp.src('gulpfile.js')
.pipe(plumber())
.pipe(jshint())
.pipe(jshint.reporter('default'))
;
});
gulp.task('scripts', function () {
return gulp.src(settings.js, { cwd: settings.dev })
.pipe(plumber())
.pipe(jshint())
.pipe(jshint.reporter('default'))
;
});
gulp.task('font', function () {
return fontelloUpdate({
config: 'fontello.json',
fonts: 'font',
css: 'font'
});
});
gulp.task('comb', function() {
return gulp.src(settings.styles.src, { base: settings.dev })
.pipe(plumber())
.pipe(csscomb())
.pipe(gulp.dest(settings.dev));
});
gulp.task('styles', ['font'], function () {
return gulp.src(settings.styles.src, { cwd: settings.dev })
.pipe(plumber())
.pipe(less({ paths: [path.join(settings.dev, settings.styles.includes)] }))
.pipe(concat('style.css'))
.pipe(prefix())
.pipe(gulp.dest(path.join(settings.dev, settings.styles.dest)))
;
});
gulp.task('html', ['scripts'], function () {
// Gather a list of all bower components installed.
// We are only interested in JS files since we intend to import all the css files manually through
// less import.
var components = bowerFiles({
filter: /\.js/
}).map(function (file) {
return path.relative('.', file);
});
// Gathering a list of all the modules we have.
var modules = settings.js.map(function (pattern) {
return glob.sync(pattern);
}).reduce(function(a, b) {
return a.concat(b);
});
return gulp.src('index.html')
.pipe(plumber())
.pipe(htmlreplace({
components: components,
modules: modules
}, {
// Keep blocks in place to be able to reuse the same filename over and over.
keepUnassigned: true,
keepBlockTags: true
}))
.pipe(gulp.dest('.'))
;
});
gulp.task('serve', ['build'], function (cb) {
http
.createServer(app)
.listen(settings.port, function () {
util.log('Server started on', settings.port, 'port');
cb();
})
.on('error', function (err) {
if (err.code === 'EADDRINUSE') {
util.log('Port', settings.port, 'is already taken by another process');
cb();
} else {
cb(err);
}
})
.unref();
});
gulp.task('test', ['build', 'serve'], function (cb) {
gulp.src(['./tests/*.js'])
.pipe(protractor({
configFile: 'protractor.js',
args: ['--baseUrl', 'http://localhost:' + settings.port]
}))
.on('error', function (e) {
util.log('E2E test failed:', e.message);
cb(e);
})
.on('end', function () {
util.log('E2E test finished successfully');
cb();
});
});
gulp.task('watch', function () {
gulp.watch(settings.js, ['scripts', 'html']);
gulp.watch(settings.styles.src.concat(settings.styles.includes), ['comb', 'styles']);
});
gulp.task('build', ['gulphint', 'scripts', 'font', 'styles', 'html']);
gulp.task('default', ['build', 'watch', 'serve']);