-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
195 lines (180 loc) · 5.43 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
'use strict';
/*
Including Gulp and plugins
*/
var gulp = require('gulp');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var jade = require('gulp-jade');
var beautify = require('gulp-jsbeautifier');
var nano = require('gulp-cssnano');
var rename = require('gulp-rename');
var postcss = require('gulp-postcss');
var mqpacker = require('css-mqpacker');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
/*
Directory variables
*/
var sassSrcDir = './src/sass/';
var jadeSrcDir = './src/jade/';
var assetsDir = './assets/';
var compiledStylesDir = assetsDir + 'css/';
var libsDir = './libs/';
/*
Compiling sass, using sourcemaps
*/
gulp.task('sass', function () {
gulp.src([
sassSrcDir + 'react.scss',
sassSrcDir + 'linea/linea.scss'
])
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'expanded'
}).on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(gulp.dest(compiledStylesDir));
});
/*
Creating a styles build file consisted of all files specified in gulp.src
*/
gulp.task('build:css', function () {
return gulp.src([
libsDir + 'materialize/materialize.min.css',
libsDir + 'owl/owl.carousel.css',
compiledStylesDir + 'linea.css',
compiledStylesDir + 'react.css'
])
.pipe(concat('build.css'))
.pipe(postcss([mqpacker]))
.pipe(nano({
safe: true
}))
.pipe(rename('build.min.css'))
.pipe(gulp.dest(assetsDir + 'build'));
});
/*
Building compile jade, beautifying the output
*/
gulp.task('jade', function () {
gulp.src(
[
jadeSrcDir + 'ring-green.jade',
jadeSrcDir + 'ring-blue.jade',
jadeSrcDir + 'tunnel.jade',
jadeSrcDir + 'waves-light-blue.jade',
jadeSrcDir + 'waves-deep-purple.jade',
jadeSrcDir + 'fuzzy-hue.jade',
jadeSrcDir + 'fuzzy-saturation.jade',
jadeSrcDir + 'combustion-purple.jade',
jadeSrcDir + 'combustion-yellow.jade'
]
)
.pipe(jade())
.pipe(beautify({
html: {
indent_char: ' ',
indent_size: 4,
selector_separator_newline: true,
preserveNewlines: false,
indent_inner_html: true,
unformatted: ['span'],
extra_liners: ['section', 'footer'],
wrap_line_length: 0
}
}))
.pipe(gulp.dest('./'));
});
/*
Watching src files changes and running appropriate commands to compile them
*/
gulp.task('watch', function () {
gulp.watch([
sassSrcDir + '*.scss',
sassSrcDir + 'skins/*.scss'
], ['sass']);
gulp.watch([
jadeSrcDir + '*.jade',
jadeSrcDir + '**/*.jade'
], ['jade']);
});
/*
Creating a JavaScript build consisted of all the files specified in gulp.src
*/
gulp.task('build:scripts', function () {
return gulp.src([
libsDir + 'jquery-2.1.1.min.js',
libsDir + 'materialize/materialize.min.js',
libsDir + 'masonry/masonry.pkgd.min.js',
libsDir + 'owl/owl.carousel.min.js',
libsDir + 'ajaxchimp/jquery.ajaxchimp.min.js',
assetsDir + 'config/config.js',
assetsDir + 'js/app.js'
])
.pipe(concat('build.js'))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(assetsDir + 'build'));
});
/*
Creating minified versions of skin specific scripts, placed in assets/js/skins/min/ dir
*/
gulp.task('minify-skin-scripts', function () {
return gulp.src(assetsDir + 'js/skins/*.js')
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(assetsDir + 'js/skins/min'));
});
/*
Optimising the images
*/
gulp.task('imagemin', function () {
return gulp.src('./assets/images/**/*')
.pipe(imagemin({
progressive: true,
use: [pngquant()]
}))
.pipe(gulp.dest('./assets/images'));
});
/*
Building a zip for Themeforest. Feel free to remove this
*/
var zip = require('gulp-zip');
var replace = require('gulp-replace');
var tfDir = 'themeforest/';
gulp.task('themeforest:build', function () {
return gulp.src([
'**',
'!bower_components/**',
'!bower_components',
'!node_modules/**',
'!node_modules',
'!' + tfDir + '**',
'!' + tfDir,
'!mailer/config.php'
])
.pipe(gulp.dest(tfDir + 'build'));
});
gulp.task('themeforest:pixelate', function () {
return gulp.src(tfDir + 'pixelated-images/**/*')
.pipe(gulp.dest(tfDir + '/build/assets/images'));
});
gulp.task('themeforest:mailconfig', function () {
return gulp.src(['mailer/config.php'])
.pipe(replace(/(\$my_email = )'(.+)';/, '$1\'my@email.com\';'))
.pipe(replace(/('username' => )'(.+)'/, '$1\'user@gmail.com\''))
.pipe(replace(/('password' => )'(.+)'/, '$1\'password12345\''))
.pipe(gulp.dest(tfDir + 'build/mailer'));
});
gulp.task('themeforest', ['themeforest:build'], function () {
gulp.start(['themeforest:pixelate', 'themeforest:mailconfig']);
});
gulp.task('themeforest:zip', function () {
return gulp.src(tfDir + '/build/**/*')
.pipe(zip('react.build.zip'))
.pipe(rename('react.build.' + Date.now() + '.zip'))
.pipe(gulp.dest(tfDir));
});