-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
137 lines (125 loc) · 3.99 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
(function() {
'use strict';
var gulp = require('gulp');
var browserify = require('gulp-browserify');
var uglify = require('gulp-uglify');
var uglifycss = require('gulp-uglifycss');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var sass = require('gulp-sass');
var stripCssComments = require('gulp-strip-css-comments');
var googleWebFonts = require('gulp-google-webfonts');
// Define distribution directory by determining if an environment
// variable has been set otherwise build in current project.
var dist = process.env.PYLON_HOME || './dist';
var imageFormats = '{gif,png,ico,svg}';
var fontFormats = '{ttf,woff,eof,svg,otf,eot}';
// Max lin length
var maxLineLength = 8000;
// Uglify optinos
var uglifyJsOptions = {
compress: {
drop_console: true
},
output: {
max_line_len: maxLineLength
}
};
var uglifyCssOptions = {
maxLineLength: maxLineLength,
uglyComments: true
};
/*----------------------------------------------------------------------------------------------
* TASKS
*--------------------------------------------------------------------------------------------*/
// Task for building the theme UI
gulp.task('theme', function() {
themeCss();
themeJs();
copyThemeImages();
copyThemeFonts();
});
// Task for building the theme JS
gulp.task('themeJs', function() {
themeJs();
});
// Task for building the theme CSS
gulp.task('themeCss', function() {
themeCss();
});
// Define task batch processes (a task that runs an array of tasks)
gulp.task('default', ['theme']);
gulp.task('js', ['themeJs']);
gulp.task('css', ['themeCss']);
gulp.task('fonts', function() {
buildFonts();
});
/*----------------------------------------------------------------------------------------------
* TASK HELPER FUNCTIONS
*--------------------------------------------------------------------------------------------*/
/**
* Builds the theme JS.
*/
function themeJs () {
// Build JS using browserify and minify
gulp.src('./src/theme/js/build.js')
.pipe(browserify({
insertGlobals : true
}))
.pipe(rename({
basename: 'application.min',
extname: '.js'
}))
.pipe(buffer()) // Convert from streaming to buffered vinyl file object
.pipe(uglify(uglifyJsOptions))
.pipe(gulp.dest(dist + '/src/main/webapp/assets/js'));
}
/**
* Builds the theme CSS.
*/
function themeCss() {
// Build CSS UI using SASS and minify
gulp.src('./src/theme/sass/build.scss')
.pipe(sass().on('error', sass.logError))
.pipe(rename({
basename: 'application.min',
extname: '.css'
}))
.pipe(stripCssComments({
'all': true // Strip all comments including: /*!
}))
.pipe(uglifycss(uglifyCssOptions))
.pipe(gulp.dest(dist + '/src/main/webapp/assets/css'));
}
/**
* Builds google web fonts
*/
function buildFonts() {
var options = {};
gulp.src('./src/theme/fonts/fonts.list')
.pipe(googleWebFonts(options))
.pipe(gulp.dest(dist + '/src/main/webapp/assets/fonts'));
}
/**
* Copies the theme fonts
*/
function copyThemeFonts() {
copy('./src/theme/fonts/**/*.' + fontFormats, dist + '/src/main/webapp/assets/fonts');
}
/**
* Copies the theme images
*/
function copyThemeImages() {
copy('./src/theme/img/**/*.' + imageFormats, dist + '/src/main/webapp/assets/img');
}
/**
* @param {String}
* @param {String}
*/
function copy(src, dest) {
gulp.src(src)
.pipe(gulp.dest(dest));
}
})();