-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.babel.js
247 lines (224 loc) · 10.8 KB
/
gulpfile.babel.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*------------------------------------------------------------------
Imports
------------------------------------------------------------------*/
const fs = require('fs');
const gulp = require('gulp');
const chalk = require('chalk');
const watchify = require('watchify');
const babelify = require('babelify');
const sass = require('gulp-sass');
const gutil = require('gulp-util');
const browserify = require('browserify');
const pixrem = require('gulp-pixrem');
const plumber = require('gulp-plumber');
const replace = require('gulp-replace');
const sourcemaps = require('gulp-sourcemaps');
const scsslint = require('gulp-scss-lint');
const spritesmith = require('gulp.spritesmith');
const autoprefixer = require('gulp-autoprefixer');
const realFavicon = require('gulp-real-favicon');
const source = require('vinyl-source-stream');
const bulkSass = require('gulp-sass-bulk-import');
/*------------------------------------------------------------------
Config
------------------------------------------------------------------*/
const root = `${__dirname}/themes/quicksilver/`;
const paths = {
styles : {
src : `${root}app/styles/**/*.scss`,
dest: `${root}dist/styles/`
},
scripts: {
src : `${root}app/js/**/*.js`,
dest: `${root}dist/js/`
},
sprites: {
standard: `${root}app/sprites/*@1x.png`,
retina : `${root}app/sprites/*@2x.png`
},
reg : {
root: new RegExp(root + 'app/', 'g'),
dist: new RegExp(root + 'dist/', 'g')
}
};
/*------------------------------------------------------------------
Styles
------------------------------------------------------------------*/
gulp.task('scss-lint', function () {
return gulp.src([
paths.styles.src,
`!${root}app/styles/Sprites`,
`!${root}app/styles/Elements/_OffCanvas.scss`,
`!${root}app/styles/Sprites/**`,
])
.pipe(scsslint({
'maxBuffer': 1000000,
'config' : 'scss_lint.yml'
}));
});
/*------------------------------------------------------------------
Styles
------------------------------------------------------------------*/
gulp.task('styles', () => {
return gulp.src(paths.styles.src)
.pipe(plumber(function (error) {
gutil.log(`${chalk['yellow'](error.file.toString().replace(paths.reg.root, ''))}`);
gutil.log(`${chalk['red'](error['messageOriginal'])}`);
this.emit('end');
}))
.pipe(bulkSass())
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'compressed' }))
.pipe(autoprefixer({ browsers: ['last 5 versions'] }))
.pipe(pixrem({ rootValue: '10px' }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(paths.styles.dest));
});
/*------------------------------------------------------------------
Flat CMS Theme
------------------------------------------------------------------*/
const cms = './flat-cms/';
gulp.task('cms', function () {
Message('scss', 'green');
return gulp.src([cms + 'styles/*.scss'])
.pipe(plumber(function (error) {
gutil.log(`${chalk['yellow'](error.file.toString().replace(paths.reg.root, ''))}`);
gutil.log(`${chalk['red'](error['messageOriginal'])}`);
this.emit('end');
}))
.pipe(bulkSass())
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'compressed' }))
.pipe(autoprefixer({ browsers: ['last 5 versions'] }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(cms + 'styles/css'))
});
gulp.task('flat', ['cms'], function () {
compileScripts(true);
gulp.watch([cms + 'styles/scss/*.scss'], ['cms']).on('change', function (evt) {
Message('scss', 'green');
gutil.log(chalk['green'](' => ') + chalk['blue'](evt.path.replace(/^.*\/(?=[^\/]*$)/, '')) + ' was ' + chalk['green'](evt.type));
});
});
/*------------------------------------------------------------------
Spritesheet Creation
------------------------------------------------------------------*/
gulp.task('sprites', () => {
let spriteData = gulp.src(paths.sprites.standard).pipe(spritesmith({
padding : 4,
imgName : 'sprites.png',
cssName : '_01-Sprites.scss',
cssTemplate: `${root}app/sprites/sprite_positions.styl.mustache`
}));
spriteData.img.pipe(gulp.dest(`${root}dist/images`));
spriteData.css.pipe(replace('@1x', '')).pipe(gulp.dest(`${root}app/styles/Sprites`));
let retinaSpriteData = gulp.src(paths.sprites.retina).pipe(spritesmith({
padding : 8,
imgName : 'sprites-retina.png',
cssName : '_02-Sprites-retina.scss',
cssTemplate: `${root}app/sprites/retina-sprite_positions.styl.mustache`
}));
retinaSpriteData.img.pipe(gulp.dest(`${root}dist/images`));
retinaSpriteData.css.pipe(replace('@2x', '')).pipe(gulp.dest(`${root}app/styles/Sprites`));
});
/*------------------------------------------------------------------
Scripts
------------------------------------------------------------------*/
function compileScripts(watch) {
let props = watchify.args;
props.entries = [`${root}/app/js/components/app.js`];
props.debug = true;
let bundler = watch ? watchify(browserify(props)) : browserify(props);
bundler.transform(babelify, { presets: ['es2015'] });
function rebundle() {
let stream = bundler.bundle();
return stream.on('error', function (error) {
gutil.log(`${chalk['yellow'](error.toString().replace(paths.reg.root, ''))}`);
gutil.log((error['codeFrame']));
this.emit('end');
})
.pipe(source('app.js'))
.pipe(gulp.dest(paths.scripts.dest));
}
bundler.on('update', function () {
rebundle();
});
return rebundle();
}
/*------------------------------------------------------------------
Favicon Generation
------------------------------------------------------------------*/
gulp.task('favicon', function (done) {
realFavicon.generateFavicon({
masterPicture: 'icon.png',
dest : `${root}favicons`,
iconsPath : '/',
design : {
ios : {
pictureAspect: 'noChange'
},
desktopBrowser : {},
windows : {
pictureAspect : 'noChange',
backgroundColor: '#e61b36',
onConflict : 'override'
},
androidChrome : {
pictureAspect: 'noChange',
themeColor : '#e61b36',
manifest : {
name : 'My App',
display : 'browser',
orientation: 'notSet',
onConflict : 'override',
declared : true
}
},
safariPinnedTab: {
pictureAspect: 'silhouette',
themeColor : '#e61b36'
}
},
settings : {
scalingAlgorithm : 'Mitchell',
errorOnImageTooSmall: false
},
markupFile : 'faviconData.json'
}, function () {
done();
});
});
/*------------------------------------------------------------------
Task Declaration
------------------------------------------------------------------*/
gulp.task('start', function () {
Message('start', 'green');
});
gulp.task('default', ['scss-lint', 'start', 'sprites', 'styles'], function () {
compileScripts(true);
gulp.watch([paths.styles.src], ['styles']).on('change', function (evt) {
Message('scss', 'green');
gutil.log(chalk['green'](' => ') + chalk['blue'](evt.path.replace(/^.*\/(?=[^\/]*$)/, '')) + ' was ' + chalk['green'](evt.type));
});
gulp.watch([`${root}/app/js/**/*.js`, `${root}/app/js/**/*.jsx`]).on('change', function (evt) {
Message('js', 'green');
gutil.log(chalk['green'](' => ') + chalk['blue'](evt.path.replace(/^.*\/(?=[^\/]*$)/, '')) + ' was ' + chalk['green'](evt.type));
});
});
/*------------------------------------------------------------------
Output Messages
------------------------------------------------------------------*/
function Message(message, col) {
let color = (col !== undefined) ? col : 'yellow';
gutil.log(chalk[color](Messages[message]));
}
const Messages = {
start: ' ██████╗ ██╗ ██╗██╗ ██████╗██╗ ██╗███████╗██╗██╗ ██╗ ██╗███████╗██████╗\n ██╔═══██╗██║ ██║██║██╔════╝██║ ██╔╝██╔════╝██║██║ ██║ ██║██╔════╝██╔══██╗\n ██║ ██║██║ ██║██║██║ █████╔╝ ███████╗██║██║ ██║ ██║█████╗ ██████╔╝\n ██║▄▄ ██║██║ ██║██║██║ ██╔═██╗ ╚════██║██║██║ ╚██╗ ██╔╝██╔══╝ ██╔══██╗\n ╚██████╔╝╚██████╔╝██║╚██████╗██║ ██╗███████║██║███████╗╚████╔╝ ███████╗██║ ██║\n ╚══▀▀═╝ ╚═════╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚══════╝╚═╝╚══════╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝',
scss : '╔═══════════════════════════╗\n ║ Sass compiled ║\n ╚═══════════════════════════╝',
js : '╔════════════════════════╗\n ║ JS bundled ║\n ╚════════════════════════╝',
error: '╔═══════════════════════╗\n ║ An error has occurred ║\n ╚═══════════════════════╝',
};
/*
npm install alertify.js combokeys fancybox gulp-scss-lint imagesloaded jquery jquery-bridget jquery-match-height lodash masonry-layout moment nprogress parsleyjs slick-carousel --save
npm install babel-preset-es2015 babelify browserify chalk fs gulp gulp-autoprefixer gulp-pixrem gulp-plumber gulp-real-favicon gulp-replace gulp-sass gulp-sass-bulk-import gulp-sourcemaps gulp-util gulp.spritesmith vinyl-source-stream watchify --save
*/