forked from joemfb/ml-search-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
150 lines (131 loc) · 3.59 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
/* jshint node: true */
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
var concat = require('gulp-concat');
var replace = require('gulp-replace');
var html2Js = require('gulp-ng-html2js');
var eslint = require('gulp-eslint');
var Server = require('karma').Server;
var minifyHtml = require('gulp-minify-html');
var less = require('gulp-less');
var path = require('path');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var rm = require('gulp-rm');
var ghpages = require('gulp-gh-pages');
var cp = require('child_process');
var coveralls = require('gulp-coveralls');
var version = require('./package.json').version;
// Command line option:
// --fatal=[warning|error|off]
var fatalLevel = require('yargs').argv.fatal || 'error';
var ERROR_LEVELS = ['error', 'warning'];
function handleError(level, error) {
gutil.log(error.message);
if ( ERROR_LEVELS.indexOf(level) <= ERROR_LEVELS.indexOf(fatalLevel) ) {
process.exit(1);
}
}
gulp.task('lint', function() {
return gulp.src([
'./gulpfile.js',
'./src/**/*.js'
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
.on('error', function(err) {
handleError('warning', err);
this.emit('end');
});
});
gulp.task('scripts', function() {
return gulp.src([
'./src/ml-search.js',
'./src/**/*.js'
])
.pipe(replace('@version', version))
.pipe(concat('ml-search-ng.js'))
.pipe(gulp.dest('dist'))
.pipe(rename('ml-search-ng.min.js'))
.pipe(uglify())
.pipe(gulp.dest('dist'));
});
gulp.task('styles', function() {
return gulp.src('./src/styles/*.less')
.pipe(concat('ml-search-ng-tpls.less'))
.pipe(gulp.dest('dist'))
.pipe(rename('ml-search-ng-tpls.css'))
.pipe(less())
.pipe(gulp.dest('dist'));
});
gulp.task('templates', function() {
return gulp.src([ './src/**/*.html' ])
.pipe(minifyHtml({
empty: true,
spare: true,
quotes: true
}))
// TODO: ? prefix: '/ml-search'
.pipe(html2Js({
moduleName: 'ml.search.tpls',
prefix: '/'
}))
.pipe(concat('ml-search-ng-tpls.js'))
.pipe(gulp.dest('dist'))
.pipe(rename('ml-search-ng-tpls.min.js'))
.pipe(uglify())
.pipe(gulp.dest('dist'));
});
function karmaResult(cb, result) {
var err = null;
if (result === 1) {
err = new Error('test failed');
}
cb(err);
}
gulp.task('test', ['templates', 'lint'], function(done) {
new Server({
configFile: path.join(__dirname, './karma.conf.js'),
singleRun: true,
autoWatch: false
}, karmaResult.bind(null, done))
.start();
});
gulp.task('autotest', function(done) {
new Server({
configFile: path.join(__dirname, './karma.conf.js'),
autoWatch: true
}, karmaResult.bind(null, done))
.start();
});
gulp.task('docs', function(done) {
cp.exec('./node_modules/.bin/jsdoc -c jsdoc.conf.json', function(err) {
if (err) {
return console.log(err);
}
gulp.src([
'./docs/generated/css/baseline.css',
'./docs/custom-styles.css'
])
.pipe(concat('baseline.css'))
.pipe(gulp.dest('./docs/generated/css'))
.on('end', function() {
done();
});
});
});
gulp.task('clean-docs', function() {
return gulp.src('./docs/generated/**/*', { read: false })
.pipe(rm({async: false}));
});
gulp.task('publish-docs', function() {
return gulp.src([ './docs/generated/**/*.*' ])
.pipe(ghpages());
});
gulp.task('coveralls', function() {
return gulp.src('coverage/**/lcov.info')
.pipe(coveralls());
});
gulp.task('default', ['lint', 'test', 'scripts', 'templates', 'styles']);