-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
133 lines (109 loc) · 2.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
const path = require('path');
const del = require('del');
const gulp = require('gulp');
const gutil = require('gulp-util');
const coffeelint = require('gulp-coffeelint');
const coffee = require('gulp-coffee');
const header = require('gulp-header');
const sourcemaps = require('gulp-sourcemaps');
const connect = require('gulp-connect');
const gulpNSP = require('gulp-nsp');
const karma = require('karma');
const pkg = require('./package.json');
const paths = {
src: 'src',
dist: 'build',
example: 'example',
demo: 'docs'
};
const banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %> - <%= date %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''
].join('\n');
function clean() {
return del([`./${paths.dist}`]);
}
function buildCoffee(dest) {
gulp.src(`./${paths.src}/*.coffee`)
.pipe(coffeelint())
.pipe(coffeelint.reporter())
.pipe(sourcemaps.init())
.pipe(coffee({
bare: false
}).on('error', gutil.log))
.pipe(header(banner, {
pkg: pkg,
date: new Date()
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest(dest));
}
function build() {
buildCoffee(`./${paths.dist}/`);
}
function runTests(singleRun, done) {
const localConfig = {
configFile: path.join(__dirname, './karma.conf.coffee'),
singleRun: singleRun,
autoWatch: !singleRun
};
const server = new karma.Server(localConfig, function(failCount) {
done(failCount ? new Error(`Failed ${failCount} tests.`) : null);
});
server.start();
}
function nsp(cb) {
gulpNSP({
package: __dirname + '/package.json'
}, cb);
}
gulp.task('nsp', nsp);
gulp.task('test', function(done) {
runTests(true, done);
});
gulp.task('test:auto', function(done) {
runTests(false, done);
});
gulp.task('build', build);
gulp.task('clean', clean);
gulp.task('default', ['nsp', 'clean', 'build']);
/**
* section: Example build and run
*/
function buildExample() {
buildCoffee(`./${paths.example}/lib/`);
}
function cleanExample() {
return del([`./${paths.example}/lib`]);
}
gulp.task('connect', function() {
connect.server({
root: paths.example,
livereload: true
});
});
gulp.task('html', function() {
gulp.src(`./${paths.example}/*.html`)
.pipe(connect.reload());
});
gulp.task('watch', function() {
gulp.watch([`./${paths.example}/*.html`], ['html']);
});
gulp.task('example:clean', cleanExample);
gulp.task('example:build', ['example:clean'], buildExample);
gulp.task('example', ['example:build', 'connect', 'watch']);
/**
* section: Demo build
*/
function buildDemo() {
buildCoffee(`./${paths.demo}/lib/`);
}
function cleanDemo() {
return del([`./${paths.demo}/lib`]);
}
gulp.task('demo:clean', cleanDemo);
gulp.task('demo', ['demo:clean'], buildDemo);