-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
169 lines (141 loc) · 4.26 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
//
// Define Gulp plugin config options
// --------------------------------------------
// Configure Auto Prefixer (https://github.com/sindresorhus/gulp-autoprefixer / https://github.com/ai/browserslist)
var autoprefixerOptions = {
browsers: ['IE 8', 'IE 9', 'last 2 versions']
};
// Configure Main Bower Files (https://github.com/ck86/main-bower-files)
var mainBowerFilesOptions = {
paths: {
bowerrrc: './'
}
};
// Sass Include Paths
// For example: When using Bootstrap, assign here to enable your libsass to easily include complex Bower component file paths
// '@import "bootstrap/variables";' rather than '@import "./bootstrap-sass/assets/stylesheets/bootstrap/variables";' without
var sassIncludePaths = [
'./src/vendor/bootstrap-sass/assets/stylesheets',
'./src/vendor/components-font-awesome/scss'
];
//
// Beginning of Gulp processes
// --------------------------------------------
// Include gulp
var gulp = require('gulp');
var es = require('event-stream');
var gutil = require('gulp-util');
// Include plugins
var plugins = require("gulp-load-plugins")({
pattern: ['gulp-*', 'gulp.*', 'main-bower-files'],
replaceString: /\bgulp[\-.]/
});
// Define config file
var config = require('./gulpconfig.json');
// Allows gulp --dev to be run for a more verbose output
var isProduction = true;
var sassStyle = 'compressed';
if (gutil.env.dev === true) {
isProduction = false;
sassStyle = 'expanded';
}
gulp.task('css', loadStyles());
gulp.task('js', loadScripts());
function loadStyles() {
var theme = gutil.env.type;
if (theme && config.styles[theme]) {
// requested theme
config.styles[theme].forEach(function(data) {
watchStyles(data);
});
} else {
// all
for (var theme in config.styles) {
config.styles[theme].forEach(function(data) {
watchStyles(data);
});
}
}
}
function buildStyles(data) {
var sassFiles = gulp.src(plugins.mainBowerFiles(mainBowerFilesOptions).concat(data.src))
.pipe(plugins.filter(['*.css', '*.scss']))
.pipe(plugins.plumber())
.pipe(isProduction ? gutil.noop() : plugins.sourcemaps.init()) // Init sourcemaps for debugging
.pipe(plugins.sass({
outputStyle: sassStyle,
precision: 8,
includePaths: sassIncludePaths
}));
var css = es.concat(sassFiles)
.pipe(plugins.concat(data.dest.filename))
.pipe(plugins.autoprefixer(autoprefixerOptions))
.pipe(isProduction ? plugins.minifyCss({advanced: false}) : gutil.noop())
.pipe(isProduction ? gutil.noop() : plugins.sourcemaps.write()) // Inline sourcemaps if not production
.pipe(plugins.size({showFiles:true,title:'Output'}));
// Output file to each destination in paths
if (typeof data.dest.paths === 'string') {
css.pipe(gulp.dest(data.dest.paths));
} else {
for (var i=0; i<data.dest.paths.length; i++) {
css.pipe(gulp.dest(data.dest.paths[i]));
}
}
// add blank line to aid output readability
gutil.log('');
return;
}
function watchStyles(data) {
gulp.watch(data.watch, ['css']).on('change', function(evt) {
buildStyles(data);
changeEvent(evt, data.src);
});
return;
}
function loadScripts() {
var theme = gutil.env.type;
if (theme && config.scripts[theme]) {
// requested theme
config.scripts[theme].forEach(function(data) {
watchScripts(data);
});
} else {
// all
for (var theme in config.scripts) {
config.scripts[theme].forEach(function(data) {
watchScripts(data);
});
}
}
return;
}
function watchScripts(data) {
gulp.watch(data.watch, ['js']).on('change', function(evt) {
buildScripts(data);
changeEvent(evt, data.src);
});
return;
}
function buildScripts(data) {
var js = gulp.src(plugins.mainBowerFiles(mainBowerFilesOptions).concat(data.src))
.pipe(plugins.filter('*.js'))
.pipe(plugins.concat(data.dest.filename))
.pipe(isProduction ? plugins.uglify() : gutil.noop())
.pipe(plugins.size({showFiles:true,title:'Output'}));
// Output file to each destination in paths
if (typeof data.dest.paths === 'string') {
js.pipe(gulp.dest(data.dest.paths));
} else {
for (var i=0; i<data.dest.paths.length; i++) {
js.pipe(gulp.dest(data.dest.paths[i]));
}
}
// add blank line to aid output readability
gutil.log('');
return;
}
var changeEvent = function(evt, src) {
gutil.log('File', gutil.colors.cyan(evt.path), 'was', gutil.colors.magenta(evt.type));
return;
};
gulp.task('default', ['css', 'js']);