-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
128 lines (113 loc) · 3.07 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
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');
////////////////////
// build
////////////////////
gulp.task('build', ['compile-stylus', 'jshint']);
////////////////////
// default
////////////////////
gulp.task('default', $.taskListing.withFilters(null, 'default'));
////////////////////
// compile-stylus
////////////////////
gulp.task('compile-stylus', function() {
return gulp.src([__dirname + '/www/lib/onsen/stylus/*-theme.styl'])
.pipe(plumber())
.pipe($.stylus({errors: true, define: {mylighten: mylighten}}))
.pipe($.autoprefixer('> 1%', 'last 2 version', 'ff 12', 'ie 8', 'opera 12', 'chrome 12', 'safari 12', 'android 2'))
.pipe($.rename(function(path) {
path.dirname = '.';
path.basename = 'onsen-css-components-' + path.basename;
path.ext = 'css';
}))
.pipe(gulp.dest(__dirname + '/www/styles/'));
// needs for compile
function mylighten(param) {
if (param.rgba) {
var result = param.clone();
result.rgba.a = 0.2;
return result;
}
throw new Error('mylighten() first argument must be color.');
}
});
////////////////////
// jshint
////////////////////
gulp.task('jshint', function() {
return gulp.src([__dirname + '/www/*.js', __dirname + '/www/js/**/*.js'])
.pipe(plumber())
.pipe($.cached('jshint'))
.pipe($.jshint())
.pipe(jshintNotify())
.pipe($.jshint.reporter('jshint-stylish'));
});
////////////////////
// serve
////////////////////
gulp.task('serve', ['build', 'browser-sync'], function() {
gulp.watch(
[__dirname + '/www/lib/onsen/stylus/**/*.styl'],
{debounceDelay: 400},
['compile-stylus']
);
gulp.watch(
[__dirname + '/www/*.js', __dirname + '/www/js/**/*.js'],
{debounceDelay: 400},
['jshint']
);
gulp.watch(
[__dirname + '/www/**/*.*'],
{debounceDelay: 400},
['prepare-cordova']
);
});
////////////////////
// browser-sync
////////////////////
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: __dirname + '/www/',
directory: true
},
ghostMode: false,
notify: false,
debounce: 200,
port: 8901,
startPath: 'index.html'
});
gulp.watch([
__dirname + '/www/**/*.{js,html,css,svg,png,gif,jpg,jpeg}'
], {
debounceDelay: 400
}, function() {
browserSync.reload();
});
});
////////////////////
// prepare-cordova
////////////////////
gulp.task('prepare-cordova', function() {
return gulp.src('')
.pipe($.plumber())
.pipe($.shell(['cordova prepare'], {cwd: __dirname}));
});
// utils
function plumber() {
return $.plumber({errorHandler: $.notify.onError()});
}
function jshintNotify() {
return $.notify(function(file) {
if (file.jshint.success) {
return false;
}
var errors = file.jshint.results.map(function (data) {
return data.error ? '(' + data.error.line + ':' + data.error.character + ') ' + data.error.reason : '';
}).join('\n');
return file.relative + ' (' + file.jshint.results.length + ' errors)\n' + errors;
});
}