-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
102 lines (87 loc) · 3.09 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
const gulp = require('gulp')
const blok = require('gulp-blok')
const watch = require('gulp-watch')
const sass = require('gulp-sass')
const sassGlob = require('gulp-sass-glob')
const browserSync = require('browser-sync')
const reload = browserSync.reload
const config = require('./config.js')
const rename = require('gulp-rename')
const exec = require('child_process').exec
const portfinder = require('portfinder')
gulp.task('templates:cleanup', function (cb) {
config.blok.environment = 'live'
exec('storyblok delete-templates --space=' + config.blok.themeId + ' --env=' + config.blok.environment, function (err, stdout, stderr) {
console.log(stdout)
console.log(stderr)
cb(err)
})
})
gulp.task('deploy:dev', function () {
return gulp.src('./views/**/*')
.pipe(blok(config.blok))
})
gulp.task('deploy:live', function () {
config.blok.environment = 'live'
return gulp.src('./views/**/*')
.pipe(blok(config.blok))
})
gulp.task('styles:below', function () {
return gulp.src('source/scss/below.scss')
.pipe(sassGlob())
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest('./views/assets/css/'))
.pipe(browserSync.stream())
})
gulp.task('styles:above', function () {
return gulp.src('source/scss/above.scss')
.pipe(sassGlob())
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest('./views/assets/css/'))
.pipe(browserSync.stream())
.pipe(rename('_above_fold_css.liquid'))
.pipe(gulp.dest('./views/components/'))
})
gulp.task('vendor:scripts', function () {
return gulp.src('source/js/vendor/*')
.pipe(gulp.dest('views/assets/js/vendor'))
})
gulp.task('browsersync', function () {
portfinder.getPort({port: 4440}, function (err, port) {
console.log('Your project will be running on: localhost:' + port)
if (port != 4440) {
throw new Error('Address with port 4440 is already in use. Be sure to stop other services or Storyblok projects running on this port.')
}
browserSync({
port: 4440,
serveStatic: ['./views'],
proxy: {
target: 'http://' + config.blok.domain,
reqHeaders: function () {
return {
'accept-encoding': 'identity',
'agent': false,
'browsersyncblok': true,
'storyblokenv': config.blok.environment
}
}
},
reloadDelay: 500,
notify: true,
open: true,
logLevel: 'silent'
})
})
gulp.watch(['source/scss/_variables.scss'], ['styles:above', 'styles:below'])
gulp.watch(['source/scss/above.scss', 'source/scss/components/above/**/*.scss', 'source/scss/components/elements/**/*.scss'], ['styles:above'])
gulp.watch(['source/scss/below.scss', 'source/scss/components/below/**/*.scss'], ['styles:below'])
gulp.watch('source/js/vendor/*.js', ['vendor:scripts'])
gulp.watch('views/assets/js/**/*.js', function(event) {
browserSync.reload()
})
})
gulp.task('build', ['styles:above', 'styles:below'])
gulp.task('default', ['build', 'browsersync'], function () {
return watch('./views/**/*')
.pipe(blok(config.blok))
})