forked from angular-ui/ui-layout
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
180 lines (141 loc) · 4.82 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
'use strict';
var gulp = require('gulp');
//////////////////////////////////////////////////////////////////////////////
// TASK
//////////////////////////////////////////////////////////////////////////////
gulp.task('default', ['jshint', 'karma']);
gulp.task('serve', ['dist', 'continuousMode']);
gulp.task('dist', ['clean:dist', 'uglify'], function(){
return gulp.src('*.css', { cwd: './src' })
.pipe(gulp.dest('./dist'));
});
//////////////////////////////////////////////////////////////////////////////
// MORE
//////////////////////////////////////////////////////////////////////////////
var karmaHelper = require('node-karma-wrapper');
var lodash = {};
lodash.assign = require('lodash.assign');
lodash.after = require('lodash.after');
//
// ACCESS TO THE ANGULAR-UI-PUBLISHER
// inspired by https://github.com/angular-ui/angular-ui-publisher
function targetTask(){
var spawn = require('child_process').spawn;
return function(done){
// I'm using the global gulp "" ci ""
spawn('gulp', process.argv.slice(2), {
cwd : './node_modules/angular-ui-publisher',
stdio: 'inherit'
}).on('close', done);
}
}
gulp.task('build', targetTask('build'));
gulp.task('publish', targetTask('publish'));
//
//
//////////////////////////////////////////////////////////////////////////////
// KARMA
//////////////////////////////////////////////////////////////////////////////
var kwjQlite = karmaHelper( testConfig( './test/karma-jqlite.conf.js' ));
var kwjQuery = karmaHelper( testConfig( './test/karma-jquery.conf.js' ));
function testConfig(configFile, customOptions){
var options = { configFile: configFile };
var travisOptions = process.env.TRAVIS && { browsers: [ 'Firefox', 'PhantomJS'], reporters: ['dots'], singleRun: true };
return lodash.assign(options, customOptions, travisOptions);
}
gulp.task('karma', function(cb){
var done = lodash.after(2, cb);
kwjQuery.simpleRun(done);
kwjQlite.simpleRun(done);
});
gulp.task('karma:jqlite:unit', kwjQlite.simpleRun);
gulp.task('karma:jqlite:watch', function(){
kwjQlite.inBackground();
gulp.watch('./test/**', function(){
kwjQlite.run();
});
});
gulp.task('karma:jquery:unit', kwjQuery.simpleRun);
gulp.task('karma:jquery:watch', function(){
kwjQuery.inBackground();
gulp.watch('./test/**', function(){
kwjQuery.run();
});
});
//////////////////////////////////////////////////////////////////////////////
// OTHER
//////////////////////////////////////////////////////////////////////////////
// load plugins
var $ = require('gulp-load-plugins')();
gulp.task('clean:dist', function () {
return gulp.src('./dist')
.pipe($.rimraf());
});
gulp.task('ngmin', function () {
var options = {
remove: true,
add: true,
single_quotes: true
};
return gulp.src('*.js', { cwd: './src' })
.pipe($.ngAnnotate(options))
.pipe(gulp.dest('./dist'));
});
//////////////////////////////////////////////////////////////////////////////
// LINTING
//////////////////////////////////////////////////////////////////////////////
gulp.task('jshint:src', function(done){
return gulp.src('./src/*.js')
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.jshint.reporter('fail'));
});
gulp.task('jshint:test', function(done){
return gulp.src('./test/*.spec.js')
.pipe($.jshint({
globals: {
"angular" : false,
"inject" : false,
"_jQuery" : false,
"jasmine" : false,
"it" : false,
"iit" : false,
"xit" : false,
"describe" : false,
"ddescribe" : false,
"xdescribe" : false,
"dump" : false,
"beforeEach" : false,
"afterEach" : false,
"expect" : false,
"spyOn" : false
}
}))
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.jshint.reporter('fail'));
});
gulp.task('jshint', ['jshint:src', 'jshint:test']);
//////////////////////////////////////////////////////////////////////////////
// MINIFYING
//////////////////////////////////////////////////////////////////////////////
gulp.task('uglify', ['ngmin'], function () {
return gulp.src('./dist/*.js')
.pipe($.rename({ suffix: '.min'}))
.pipe($.uglify({mangle: false}))
.pipe(gulp.dest('./dist'));
});
//////////////////////////////////////////////////////////////////////////////
// CONTINUOUS MODE
//////////////////////////////////////////////////////////////////////////////
gulp.task('continuousMode', function(){
kwjQuery.inBackground();
kwjQlite.inBackground();
gulp.task('_continuousMode:runTests', function(cb){
var done = lodash.after(2, cb);
kwjQuery.run(done);
kwjQlite.run(done);
});
// watch the tests
gulp.watch('./test/**', ['jshint:test', '_continuousMode:runTests']);
gulp.watch('./src/**', ['jshint:src', '_continuousMode:runTests']);
});