-
Notifications
You must be signed in to change notification settings - Fork 166
/
wip.Gulpfile.js
80 lines (67 loc) · 2.09 KB
/
wip.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
var gulp = require('gulp');
var es = require('event-stream');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var autoprefixer = require('gulp-autoprefixer');
var argv = require('yargs').option('version', {type: 'string'}).argv;
var postcss = require('gulp-postcss');
var mqpacker = require('css-mqpacker');
var browserSync = require('browser-sync');
var argv = require('yargs').argv
var themesDir = 'themes';
var workingDir = 'themes/base';
var sources = {
sass: workingDir + '/sass/snipcart.scss',
compiled: workingDir + '/snipcart.css'
};
var watch = {
sass: workingDir + '/sass/**/*.scss'
};
var getDistDir = function (output) {
var dir = './dist/themes';
if (argv.version) {
dir = "./dist/themes/" + argv.version;
}
if (output) {
dir += '/' + output;
}
return dir;
};
gulp.task('sass', function() {
gulp.src(sources.sass)
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({cascade: false, browsers: ['> 0.25%']}))
.pipe(gulp.dest(workingDir));
});
gulp.task('min', ['sass'], function() {
gulp.src(sources.compiled)
.pipe(postcss([mqpacker]))
.pipe(minifyCss())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(workingDir));
});
gulp.task('watch', function() {
gulp.watch([watch.sass], ['sass']);
});
gulp.task('sync', ['dev'], function() {
var proxy = argv.proxy ? argv.proxy : 'snipcart.client/';
var sync = browserSync.create(proxy);
sync.init({
port: 3006,
proxy: proxy,
cors: true,
serveStatic: ['.'],
ui: {
port: 3007
}
});
gulp.watch(sources.compiled).on('change', sync.reload);
});
gulp.task('dev', ['default', 'watch']);
gulp.task('default', ['sass']);
gulp.task('deploy', ['min'], function() {
gulp.src([themesDir + "/**/*", '!**/*.scss', '!**/sass', '!**/styles.css'])
.pipe(gulp.dest(getDistDir()))
});