-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
151 lines (128 loc) · 3.51 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
var gulp = require('gulp');
var Server = require('karma').Server;
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var path = require('path');
var plumber = require('gulp-plumber');
var runSequence = require('run-sequence');
var jshint = require('gulp-jshint');
var concatCss = require('gulp-concat-css');
var templateCache = require('gulp-angular-templatecache');
var eventStream = require('event-stream');
var webserver = require('gulp-webserver');
/**
* File patterns
**/
// Root directory
var rootDirectory = path.resolve('./');
// Source directory for build process
var sourceDirectory = path.join(rootDirectory, './modules');
var sourceFiles = [
// Make sure module files are handled first
path.join(sourceDirectory, '/**/*.module.js'),
// Then add all JavaScript files
path.join(sourceDirectory, '/**/*.js')
];
var stylesheets = [
path.join(sourceDirectory, '/**/*.css')
];
var templates = [
path.join(sourceDirectory, '/**/*.tpl.html')
];
var lintFiles = [
'gulpfile.js',
// Karma configuration
'karma-*.conf.js'
].concat(sourceFiles);
function getTemplateCache() {
return gulp.src(templates)
.pipe(plumber())
.pipe(templateCache({
module: 'angular-bubbletree.directives'
}));
}
gulp.task('build', function() {
return eventStream.merge(gulp.src(sourceFiles), getTemplateCache())
.pipe(plumber())
.pipe(concat('angular-bubbletree.js'))
.pipe(gulp.dest('./dist/'))
.pipe(uglify())
.pipe(rename('angular-bubbletree.min.js'))
.pipe(gulp.dest('./dist'));
});
gulp.task('build-stylesheets', function() {
return gulp.src(stylesheets)
.pipe(plumber())
.pipe(concatCss('angular-bubbletree.css'))
.pipe(gulp.dest('./dist'));
});
/**
* Process
*/
gulp.task('process-all', function(done) {
runSequence('jshint', 'test-src', 'build', done);
});
/**
* Watch task
*/
gulp.task('watch', function() {
// Watch JavaScript files
gulp.watch([sourceFiles, templates], ['process-all']);
gulp.watch([stylesheets], ['build-stylesheets']);
});
/**
* Validate source JavaScript
*/
gulp.task('jshint', function() {
gulp.src(lintFiles)
.pipe(plumber())
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});
/**
* Run test once and exit
*/
gulp.task('test-src', function(done) {
new Server({
configFile: __dirname + '/karma-src.conf.js',
singleRun: true
}, done).start();
});
/**
* Run test once and exit
*/
gulp.task('test-dist-concatenated', function(done) {
new Server({
configFile: __dirname + '/karma-dist-concatenated.conf.js',
singleRun: true
}, done).start();
});
/**
* Run test once and exit
*/
gulp.task('test-dist-minified', function(done) {
new Server({
configFile: __dirname + '/karma-dist-minified.conf.js',
singleRun: true
}, done).start();
// karma.start({
// configFile: __dirname + '/karma-dist-minified.conf.js',
// singleRun: true
// }, done);
});
gulp.task('webserver', function() {
gulp.src('./')
.pipe(webserver({
host: 'localhost',
port: 8000,
open: 'http://localhost:8000/example.html',
livereload: true,
directoryListing: true
// open: true
}));
});
gulp.task('default', function() {
runSequence('process-all', 'build-stylesheets', 'watch', 'webserver');
});