-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
191 lines (147 loc) · 4.13 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
/* jshint node: true */
/* jshint es5: true */
'use strict';
// DEPENDENCIES =======================================================
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserSync = require('browser-sync');
var reload = browserSync.reload;
// FILE PATHS =========================================================
var theme = 'squarespace';
var source = {
styles: 'source/styles/**/*.scss',
scripts: 'source/scripts/*.js',
images: 'source/images/*.{png,jpg,gif}',
svgs: 'source/images/*.svg',
plugins: 'source/vendor'
};
var assets = {
styles: theme + '/styles',
scripts: theme + '/scripts',
images: theme + '/assets/images',
vendor: theme + '/assets/vendor'
};
var plugins = [
source.plugins + '/fastclick/lib/fastclick.js'
];
var vendor = [
// source.plugins + '/idangerous-swiper/dist/js/swiper.jquery.min.js',
// source.plugins + '/idangerous-swiper/dist/css/swiper.min.css',
];
// AUTOPREFIXER CONFIG ================================================
var AUTOPREFIXER_BROWSERS = [
'ie >= 9',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
];
// DEPLOY TO SQUARESPACE ==============================================
gulp.task( 'deploy', $.shell.task(
[
'git init',
'git checkout --orphan ' + theme,
'git add --all',
'git commit --quiet --message "Deploying to Squarespace"',
'git push --prune --force https://stormwarning-beta.squarespace.com/template.git ' + theme + ':master',
'rm -rf .git'
],
{
cwd: './squarespace'
}
));
// COMPILE STYLESHEETS ================================================
gulp.task('styles', function () {
return gulp.src('source/styles/*.scss')
.pipe($.changed('styles', {
extension: '.scss'
}))
.pipe($.sass({
precision: 10,
onError: console.error.bind(console, 'SASS error:')
}))
.pipe($.autoprefixer({
browsers: AUTOPREFIXER_BROWSERS
}))
.pipe($.csso())
.pipe(gulp.dest(assets.styles))
.pipe($.size({title: 'styles'}));
});
// LINT & CONCATENATE JS ==============================================
gulp.task('scripts', function () {
return gulp.src(source.scripts)
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.concat('main.js'))
.pipe($.uglify())
.pipe(gulp.dest(assets.scripts));
});
gulp.task('plugins', function () {
return gulp.src(plugins)
.pipe($.concat('plugins.js'))
.pipe($.uglify())
.pipe(gulp.dest(assets.scripts))
.pipe($.size({title: 'plugins'}));
});
gulp.task('modernizr', function () {
return gulp.src(source.scripts)
.pipe($.modernizr({
options: [
'setClasses'
],
tests: [
'flexbox',
'flexboxlegacy',
'flexboxtweener'
],
crawl: false
}))
.pipe($.uglify())
.pipe(gulp.dest(assets.scripts));
});
// COPY ONE-OFF VENDOR SCRIPTS ========================================
gulp.task('vendor', function () {
return gulp.src(vendor)
.pipe(gulp.dest(assets.vendor))
.pipe($.size({title: 'vendor'}));
});
// OPTIMISE IMAGES ====================================================
gulp.task('images', function () {
return gulp.src(source.images)
.pipe($.changed(assets.images))
.pipe($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
}))
.pipe(gulp.dest(assets.images));
});
// CREATE SVG SPRITE ==================================================
gulp.task('sprite', function () {
return gulp.src(source.svgs)
.pipe($.svgSprite({
mode: {
symbol: {
dest: './',
sprite: 'sprite.symbol.svg'
}
}
}))
.pipe(gulp.dest(assets.images));
});
// WATCH FOR CHANGES AND RELOAD =======================================
gulp.task('serve', ['styles'], function () {
browserSync({
notify: false,
logPrefix: '☸',
server: './'
});
gulp.watch([theme + '/**/*.{block,conf,region,list,preset}'], reload);
gulp.watch([source.styles], ['styles', reload]);
gulp.watch([source.scripts], ['scripts']);
gulp.watch([source.images], ['images', reload]);
});