-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
224 lines (205 loc) · 6.95 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
* Altair Admin (AngularJS)
* Automated tasks ( http://gulpjs.com/ )
*/
var gulp = require('gulp'),
plugins = require("gulp-load-plugins")({
pattern: ['gulp-*', 'gulp.*', '*'],
replaceString: /\bgulp[\-.]/
});
// browser sync
var bs_angular = require('browser-sync').create('altair_angular');
// chalk error
var chalk = require('chalk');
var chalk_error = chalk.bold.red;
// get altair version
var pjson = require('./package.json');
var version = pjson.version;
// 1. -------------------- MINIFY/CONCATENATE JS FILES --------------------
// commmon
gulp.task('common_js', function () {
return gulp.src([
"bower_components/jquery/dist/jquery.js",
"bower_components/modernizr/modernizr.js",
// moment
"bower_components/moment/moment.js",
// fastclick (touch devices)
"bower_components/fastclick/lib/fastclick.js",
// custom scrollbar
"bower_components/jquery.scrollbar/jquery.scrollbar.js",
// create easing functions from cubic-bezier co-ordinates
"bower_components/jquery-bez/jquery.bez.min.js",
// Get the actual width/height of invisible DOM elements with jQuery
"bower_components/jquery.actual/jquery.actual.js",
// waypoints
"bower_components/waypoints/lib/jquery.waypoints.js",
// velocityjs (animation)
"bower_components/velocity/velocity.js",
"bower_components/velocity/velocity.ui.js",
// advanced cross-browser ellipsis
"bower_components/jquery.dotdotdot/src/js/jquery.dotdotdot.js",
// hammerjs
"bower_components/hammerjs/hammer.js",
// scrollbar width
"assets/js/custom/jquery.scrollbarWidth.js",
// jquery.debouncedresize
"bower_components/jquery.debouncedresize/js/jquery.debouncedresize.js",
// screenfull
"bower_components/screenfull/dist/screenfull.js",
// waves
"bower_components/Waves/dist/waves.min.js"
])
.pipe(plugins.concat('common.js'))
.on('error', function(err) {
console.log(chalk_error(err.message));
this.emit('end');
})
.pipe(gulp.dest('assets/js/'))
.pipe(plugins.uglify({
mangle: true
}))
.pipe(plugins.rename('common.min.js'))
.pipe(plugins.size({
showFiles: true
}))
.pipe(gulp.dest('assets/js/'));
});
// custom uikit
gulp.task('uikit_js', function () {
return gulp.src([
// uikit core
"bower_components/uikit/js/uikit.js",
// uikit components
"bower_components/uikit/js/components/accordion.js",
"bower_components/uikit/js/components/autocomplete.js",
"assets/js/custom/uikit_datepicker.js",
"bower_components/uikit/js/components/form-password.js",
"bower_components/uikit/js/components/form-select.js",
"bower_components/uikit/js/components/grid.js",
"bower_components/uikit/js/components/lightbox.js",
"bower_components/uikit/js/components/nestable.js",
"bower_components/uikit/js/components/notify.js",
"bower_components/uikit/js/components/slideshow.js",
"bower_components/uikit/js/components/sortable.js",
"bower_components/uikit/js/components/sticky.js",
"bower_components/uikit/js/components/tooltip.js",
"assets/js/custom/uikit_timepicker.js",
"bower_components/uikit/js/components/upload.js",
"assets/js/custom/uikit_beforeready.js"
])
.pipe(plugins.concat('uikit_custom.js'))
.pipe(gulp.dest('assets/js/'))
.pipe(plugins.uglify({
mangle: true
}))
.pipe(plugins.rename('uikit_custom.min.js'))
.pipe(plugins.size({
showFiles: true
}))
.pipe(gulp.dest('assets/js/'));
});
// common/custom functions
gulp.task('custom_js_minify', function () {
return gulp.src([
'assets/js/custom/*.js',
'!assets/js/**/*.min.js'
])
.pipe(plugins.uglify({
mangle: true
}))
.pipe(plugins.rename({
extname: ".min.js"
}))
.pipe(gulp.dest(function(file) {
return file.base;
}));
});
// -------------------- LESS TO CSS --------------------
// main styles
gulp.task('less_main', function() {
return gulp.src('assets/less/main.less')
.pipe(plugins.less())
.on('error', function(err) {
console.log(chalk_error(err.message));
this.emit('end');
})
.pipe(plugins.autoprefixer({
browsers: ['> 5%','last 2 versions'],
cascade: false
}))
.pipe(gulp.dest('assets/css'))
.pipe(bs_angular.stream())
.pipe(plugins.minifyCss({
keepSpecialComments: 0,
advanced: false
}))
.pipe(plugins.rename('main.min.css'))
.pipe(gulp.dest('assets/css'));
});
// -------------------- MINIFY JSON --------------------
gulp.task('json_minify', function() {
return gulp.src([
'data/*.json',
'!data/*.min.json'
])
.pipe(plugins.jsonminify())
.on('error', function(err) {
console.log(chalk_error(err.message));
this.emit('end');
})
.pipe(plugins.rename({
extname: ".min.json"
}))
.pipe(gulp.dest('data/'));
});
// -------------------- BROWSER SYNC http://www.browsersync.io/docs/ --------------------
gulp.task('browser-sync', ['default'], function() {
bs_angular.init({
// http://www.browsersync.io/docs/options/#option-host
host: "10.0.0.188",
// http://www.browsersync.io/docs/options/#option-proxy
proxy: "altair_app.local",
// http://www.browsersync.io/docs/options/#option-port
port: 3022,
// http://www.browsersync.io/docs/options/#option-notify
notify: true,
ui: {
port: 3021
}
});
gulp.watch([
'assets/less/**/*.less',
],['less_main']);
gulp.watch([
'index.html',
'app/**/*',
'!app/**/*.min.js'
]).on('change', bs_angular.reload);
});
// -------------------- DEFAULT TASK ----------------------
gulp.task('default', function(callback) {
return plugins.runSequence(
['common_js','custom_js_minify','uikit_js','less_main','json_minify'],
callback
);
});
// generate user theme
gulp.task('less_my_theme', function() {
return gulp.src('assets/less/themes/my_theme.less')
.pipe(plugins.less())
.on('error', function(err) {
console.log(chalk_error(err.message));
this.emit('end');
})
.pipe(plugins.autoprefixer({
browsers: ['> 5%','last 2 versions'],
cascade: false
}))
.pipe(gulp.dest('assets/css/'))
.pipe(plugins.minifyCss({
keepSpecialComments: 0,
advanced: false
}))
.pipe(plugins.rename('my_theme.min.css'))
.pipe(gulp.dest('assets/css/'));
});