-
Notifications
You must be signed in to change notification settings - Fork 10
/
gulpfile.js
161 lines (137 loc) · 3.75 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
'use strict';
var _ = require('lodash');
var gulp = require('gulp');
var path = require('path');
var http = require('http');
var connect = require('connect');
var serveStatic = require('serve-static');
var source = require('vinyl-source-stream');
var openPage = require('open');
var browserify = require('browserify');
var istanbulify = require('browserify-istanbul');
var watchify = require('watchify');
var babelify = require('babelify');
var exorcist = require('exorcist');
var gutil = require('gulp-util');
var less = require('gulp-less');
var mochaPhantomJS = require('gulp-mocha-phantomjs');
var uglify = require('gulp-uglify');
var csso = require('gulp-csso');
var rename = require('gulp-rename');
var sourcemaps = require('gulp-sourcemaps');
/*
* Dev
*/
var appArgs = {
ignore: 'sinon',
exclude: ['react'],
standalone: 'SprintlyUI',
debug: true,
verbose: true
};
var jsSrc = './src/';
var jsDest = './dist/js/';
var jsDist = 'sprintly-ui.js';
var jsMapDist = './dist/js/sprintly-ui.js.map';
function bundle(b) {
return b.transform(babelify)
.bundle()
.pipe(exorcist(jsMapDist))
.pipe(source(jsDist))
.pipe(gulp.dest(jsDest));
}
gulp.task('build', function() {
var bundler = browserify(jsSrc, appArgs);
return bundle(bundler);
});
gulp.task('less', function() {
gulp.src('./src/less/sprintly-ui.less')
.pipe(sourcemaps.init())
.pipe(less())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./dist/css/'));
});
gulp.task('watch', function() {
var bundler = watchify(browserify(jsSrc, _.extend({}, watchify.args, appArgs)));
bundle(bundler);
bundler.on('update', function() {
return bundle(bundler);
});
bundler.on('log', gutil.log);
gulp.watch('src/less/**/*.less', ['less']);
});
gulp.task('jsmin', ['build'], function() {
gulp.src('./dist/js/sprintly-ui.js')
.pipe(uglify())
.pipe(rename({extname: '.min.js'}))
.pipe(gulp.dest('./dist/js'));
});
gulp.task('cssmin', ['less'], function() {
gulp.src('./dist/css/sprintly-ui.css')
.pipe(csso())
.pipe(rename({extname: '.min.css'}))
.pipe(gulp.dest('./dist/css'));
});
gulp.task('dev-server', function() {
var tests = connect();
tests.use(serveStatic('./'));
http.createServer(tests).listen(8090);
openPage('http://localhost:8090/examples/');
});
/*
* Test
*/
var testArgs = {
debug: true,
verbose: true,
ignore: 'sinon'
};
var testSrc = './test/index.js';
var testDest = './test/';
var testDist = 'build.js';
var testMapDist = './test/build.js.map';
function bundleTests(b) {
return b.transform(babelify)
.transform(istanbulify({ignore: ["**/node_modules/**","**/test/**"]}))
.bundle()
.pipe(exorcist(testMapDist))
.pipe(source(testDist))
.pipe(gulp.dest(testDest));
}
gulp.task('build-test', function() {
var bundler = browserify(testSrc, testArgs);
return bundleTests(bundler);
});
gulp.task('watch-test', function() {
var bundler = watchify(browserify(testSrc, _.extend({}, watchify.args, testArgs)));
bundleTests(bundler);
bundler.on('update', function() {
return bundleTests(bundler);
});
});
gulp.task('test-server', function() {
var tests = connect();
tests.use(serveStatic('./'));
http.createServer(tests).listen(8080);
openPage('http://localhost:8080/test/');
});
gulp.task('test', ['build-test'], function() {
gulp.src('./test/index.html')
.pipe(mochaPhantomJS({
reporter: 'dot'
})).
on('error', function(err) {
console.log("There was an error running tests: ", err.message);
});
});
gulp.task('test-coverage', function() {
var root = path.resolve('./test');
gulp.src('./test/index.html')
.pipe(mochaPhantomJS({
path: root + 'index.html',
phantomjs: {
hooks: root + '/phantom_hooks'
}
}));
});
gulp.task('default', ['test']);