-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
192 lines (148 loc) · 5.27 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
181
182
183
184
185
186
187
188
189
190
191
var gulp = require('gulp'),
fs = require('fs'),
mainBowerFiles = require('main-bower-files'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
gulpUtil = require('gulp-util'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
notifier = require('node-notifier'),
footer = require('gulp-footer'),
header = require('gulp-header'),
del = require('del'),
webserver = require('gulp-webserver'),
batch = require('gulp-batch'),
watch = require('gulp-watch'),
bower = require('gulp-bower'),
argv = require('minimist')(process.argv.slice(2)),
karma = require('karma'),
bump = require('gulp-bump'),
buildConfig = require('./config/build.config'),
karmaConf = require('./config/karma.conf.js'),
depsOrder = require('gulp-deps-order');
gulp.task('bower:install', function() {
return bower();
});
gulp.task('build:bower', ['bower:install'], function() {
// take all bower includes and concatenate them,
// in a file to be included before others
return gulp.src(buildConfig.bowerFileList)
.pipe(concat(buildConfig.bowerAllIncludes))
.pipe(gulp.dest(buildConfig.build));
});
gulp.task('build:src:nonotify', ['build:bower'], function() {
return gulp.src('src/**/*.js')
.pipe(depsOrder())
.pipe(concat(buildConfig.distFile))
.pipe(header(buildConfig.closureStart))
.pipe(footer(buildConfig.closureEnd))
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'))
// add bower include on top
.pipe(header(fs.readFileSync(buildConfig.build + buildConfig.bowerAllIncludes, 'utf8')))
// save non minified version to dist folder
.pipe(gulp.dest(buildConfig.dist))
// save also to demo folder
.pipe(gulp.dest('demo/www/js/'))
// save minified version
.pipe(rename({suffix: '.min'}))
.pipe(uglify().on('error', gulpUtil.log))
.pipe(header(buildConfig.banner))
.pipe(gulp.dest(buildConfig.dist));
});
gulp.task('build:bowerpackage', function() {
return gulp.src('src/**/*.js')
.pipe(depsOrder())
.pipe(concat(buildConfig.distFile))
.pipe(header(buildConfig.closureStart))
.pipe(footer(buildConfig.closureEnd))
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'))
// save non minified version to dist folder
.pipe(gulp.dest(buildConfig.distBower))
// save minified version
.pipe(rename({suffix: '.min'}))
.pipe(uglify().on('error', gulpUtil.log))
.pipe(header(buildConfig.banner))
.pipe(gulp.dest(buildConfig.distBower));
});
gulp.task('build:src', ['build:src:nonotify', 'build:bowerpackage'], function() {
notifier.notify({ title: "Build Success", message: 'Build StargateJS completed' });
});
gulp.task('watch', function () {
watch('src/**/*.js', batch(function (events, done) {
gulp.start('build', done);
}));
});
gulp.task('lint:jshint', function() {
return gulp.src('src/**/*.js')
// create temporary build for linting
.pipe(concat(buildConfig.distFile + '.lint.tmp.js'))
.pipe(header(buildConfig.closureStart))
.pipe(footer(buildConfig.closureEnd))
.pipe(gulp.dest(buildConfig.build))
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish', { verbose: true }))
.pipe(jshint.reporter('fail'));
});
gulp.task('watchSpec', function(){
watch("spec/modules/*.js", batch(function (events, done) {
gulp.start("copySpec", done);
}));
});
gulp.task('copySpec', function(){
return gulp.src("spec/modules/**/*.js")
.pipe(gulp.dest("./hello/www/jasmine/spec"));
});
gulp.task('watchSrc', function(){
watch("src/modules/**/*.js", batch(function (events, done) {
gulp.start("copySrc", done);
}));
});
gulp.task("copySrc", function(){
return gulp.src("src/modules/**/*.js")
.pipe(depsOrder())
.pipe(concat("modules.js"))
.pipe(gulp.dest("./hello/www/jasmine/src/"));
});
gulp.task('testondevice', ['watchSpec', 'watchSrc']);
gulp.task('default', ['build:src'] );
gulp.task('build', ['build:src'] );
gulp.task('lint', ['lint:jshint'] );
gulp.task('test', ['karma:singlerun'] );
/*
gulp.task('clean', ['demo:clean'] );
gulp.task('demo:run', ['build:src'], function(cb) {
process.chdir(cordovaTestProjectDir);
return cdv.run({platforms:[testPlatform], options:['--device']});
});
*/
gulp.task('karma', ['build'], function (done) {
// default to don't do single run
argv.singlerun && (karmaConf.singleRun = true);
argv.browsers && (karmaConf.browsers = argv.browsers.trim().split(','));
argv.reporters && (karmaConf.reporters = argv.reporters.trim().split(','));
new karma.Server(karmaConf, done).start();
});
gulp.task('karma:singlerun', ['build'], function (done) {
karmaConf.singleRun = true;
argv.browsers && (karmaConf.browsers = argv.browsers.trim().split(','));
argv.reporters && (karmaConf.reporters = argv.reporters.trim().split(','));
new karma.Server(karmaConf, done).start();
});
/**
* Change version in package.json used by build
* default: patch
* arg parameter --minor
*
*/
gulp.task('bump', function(){
var optsBump = {type:'patch'};
if (argv.minor) {
optsBump.type = "minor";
}
gulp.src('./package.json')
.pipe(bump(optsBump))
.pipe(gulp.dest('./'));
});