This repository was archived by the owner on Feb 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
150 lines (125 loc) · 4.42 KB
/
Copy pathgulpfile.js
File metadata and controls
150 lines (125 loc) · 4.42 KB
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
// Platform to use for run/emulate
var testPlatform = 'android';
var gulp = require('gulp'),
fs = require('fs'),
mainBowerFiles = require('main-bower-files'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
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'),
plumber = require('gulp-plumber'),
watch = require('gulp-watch'),
argv = require('minimist')(process.argv.slice(2)),
karma = require('karma'),
buildConfig = require('./config/build.config'),
karmaConf = require('./config/karma.conf.js');
var cordova_lib = require('cordova-lib'),
path = require('path');
var cdv = cordova_lib.cordova.raw;
// path of cordova test project
var cordovaTestProjectDir = path.join(__dirname, 'demo');
gulp.task('build:bower', function() {
// take all bower includes and concatenate them,
// in a file to be included before others
return gulp.src(mainBowerFiles())
.pipe(concat(buildConfig.bowerAllIncludes))
.pipe(gulp.dest(buildConfig.dist));
});
gulp.task('build:src:nonotify', ['build:bower'], function() {
return gulp.src('src/**/*.js')
.pipe(concat(buildConfig.distFile))
.pipe(header(buildConfig.closureStart))
.pipe(footer(buildConfig.closureEnd))
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(header(fs.readFileSync(buildConfig.dist + buildConfig.bowerAllIncludes, 'utf8')))
.pipe(gulp.dest(buildConfig.dist))
.pipe(gulp.dest('demo/www/js/'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(header(buildConfig.banner))
.pipe(gulp.dest(buildConfig.dist));
});
gulp.task('build:src', ['build:src:nonotify'], function() {
notifier.notify({ title: "Build Success", message: 'Build StargateJS completed' });
});
// alternative build:src that lint source and fail with a message if it's not valid
function jsHintErrorAlert(error){
notify.onError({
title: "Build Error",
message: 'Error: <%= error.message %>',
sound: "Sosumi"}
)(error); //Error Notification
console.log(error.toString());//Prints Error to Console
this.emit("end"); //End function
};
// FIXME old build:src configuration
gulp.task('build:src:checkjs', ['build:bower'], function() {
return gulp.src('src/**/*.js')
.pipe(plumber({errorHandler: jsHintErrorAlert}))
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'))
.pipe(concat(buildConfig.distFile))
.pipe(gulp.dest(buildConfig.dist))
.pipe(gulp.dest('demo/www/js/'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest(buildConfig.dist))
.pipe(notify({ title: "Build Success", message: 'Build StargateJS completed' }));
});
gulp.task('demo:serve', function() {
gulp.src('demo/www/')
.pipe(webserver({
//path: 'demo/www/',
livereload: true,
fallback: 'index.html',
directoryListing: false,
open: true
}));
});
gulp.task('demo:clean', function () {
// delete platforms and plugins
return del([
'demo/platforms/',
'demo/plugins/'
])
.then(function() {
return process.chdir(cordovaTestProjectDir);
})
.then(function() {
// add platform and download again plugin specified by config.xml
return cdv.platform('add', [testPlatform])
});
});
gulp.task('lint:jshint', function() {
return gulp.src('src/**/*.js')
.pipe(concat(buildConfig.distFile + '.lint.tmp.js'))
.pipe(header(buildConfig.closureStart))
.pipe(footer(buildConfig.closureEnd))
.pipe(gulp.dest(buildConfig.dist))
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});
gulp.task('default', ['build:src'] );
gulp.task('build', ['build:src'] );
gulp.task('lint', ['lint:jshint'] );
gulp.task('test', ['karma'] );
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) {
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();
});