-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
144 lines (130 loc) · 3.47 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
/*jshint node: true */
'use strict';
var gulp = require('gulp'),
concat = require('gulp-concat'),
less = require('gulp-less'),
minifyHtml = require('gulp-minify-html'),
html2Js = require('gulp-ng-html2js'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
jshint = require('gulp-jshint'),
templateCache = require('gulp-angular-templatecache'),
del = require('del');
gulp.task('jshint', function() {
gulp.src([
'./gulpfile.js',
'./src/**/*.js'
])
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('scripts', function() {
return gulp.src([
'./src/ml-visjs-graph-ng.js',
'./src/**/*.module.js',
'./src/**/*.service.js',
'./src/**/*.directive.js',
'./src/**/*.js'
])
.pipe(concat('ml-visjs-graph-ng.js'))
.pipe(gulp.dest('dist'))
.pipe(rename('ml-visjs-graph-ng.min.js'))
.pipe(uglify({mangle: false}))
.pipe(gulp.dest('dist'));
});
gulp.task('styles', function() {
return gulp.src(['./src/styles/*.less', './src/styles/*.css'])
.pipe(concat('ml-visjs-graph-ng.less'))
.pipe(gulp.dest('dist'))
.pipe(rename('ml-visjs-graph-ng.css'))
.pipe(less())
.pipe(gulp.dest('dist'));
});
gulp.task('templates', function() {
return gulp.src([ './src/**/*.html' ])
.pipe(minifyHtml({
empty: true,
spare: true,
quotes: true
}))
.pipe(html2Js({
moduleName: 'ml.visjsGraph',
prefix: '/'
}))
.pipe(concat('ml-visjs-graph-ng-templates.js'))
.pipe(gulp.dest('dist'))
.pipe(rename('ml-visjs-graph-ng-templates.min.js'))
.pipe(uglify())
.pipe(gulp.dest('dist'));
});
gulp.task('images', function() {
return gulp.src(['./src/images/*'])
.pipe(gulp.dest('dist/images'));
});
/**
* Run specs once and exit
* To start servers and run midway specs as well:
* gulp test --startServers
* @param {Function} done - callback when complete
*/
gulp.task('test', ['jshint', 'templatecache'], function(done) {
startTests(true /*singleRun*/, done);
});
/**
* Create $templateCache from the html templates
* @return {Stream}
*/
gulp.task('templatecache', ['clean-code'], function() {
return gulp
.src('src/**/*.html')
.pipe(templateCache(
'templates.js',
{
module: 'ml.visjsGraph',
transformUrl: function (url) {return '/' + url;}
}
))
.pipe(gulp.dest('./.tmp/'));
});
/**
* Remove all js and html from the build and temp folders
* @return {Stream}
*/
gulp.task('clean-code', function() {
var files = [].concat(
'./.tmp/**/*.js'
);
return del(files);
});
/**
* Run specs and wait.
* Watch for file changes and re-run tests on each change
* To start servers and run midway specs as well:
* gulp autotest --startServers
* @param {Function} done - callback when complete
*/
gulp.task('autotest', function(done) {
startTests(false /*singleRun*/, done);
});
function startTests(singleRun, done) {
var child;
var excludeFiles = [];
var Server = require('karma').Server;
new Server({
configFile: __dirname + '/karma.conf.js',
exclude: excludeFiles,
singleRun: !!singleRun
}, karmaCompleted).start();
////////////////
function karmaCompleted(karmaResult) {
if (child) {
child.kill();
}
if (karmaResult === 1) {
done(new Error('karma: tests failed with code ' + karmaResult));
} else {
done();
}
}
}
gulp.task('default', ['jshint', 'test', 'scripts', 'templates', 'styles', 'images']);