This repository has been archived by the owner on Oct 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.babel.js
101 lines (91 loc) · 2.68 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
const autoprefixer = require('gulp-autoprefixer')
const browserify = require('browserify')
const browserSync = require('browser-sync')
const buffer = require('vinyl-buffer')
const del = require('del')
const File = require('vinyl')
const fs = require('fs')
const globbing = require('gulp-css-globbing')
const gulp = require('gulp')
const gitrev = require('git-rev')
const notify = require('gulp-notify')
const plumber = require('gulp-plumber')
const php = require('gulp-connect-php')
const reload = browserSync.reload
const sass = require('gulp-sass')
const source = require('vinyl-source-stream')
gulp.task('clean', function () {
del.sync(['public']);
});
gulp.task('version', function () {
return gitrev.long(function (str) {
return string_src('version.cache', str).pipe(gulp.dest('public'))
})
})
gulp.task('content', function () {
return gulp.src('app/**/*.{xml,json,yml,php}')
.pipe(gulp.dest('public'))
})
gulp.task('scripts', function () {
return browserify({
entries: 'app/scripts/main.js'
})
.bundle()
.on('error', notify.onError(function (error) { return error.message; }))
.pipe(source('main.js'))
.pipe(gulp.dest('public/scripts/'))
.pipe(browserSync.stream())
})
gulp.task('styles', function () {
return gulp.src('app/styles/**/*.{sass,scss}')
.pipe(plumber())
.pipe(globbing({
extensions: ['.scss']
}))
.on('error', notify.onError(function (error) { return 'There is an error in your stylesheet.'; }))
.pipe(sass({
outputStyle: 'expanded'
}))
.on('error', notify.onError(function (error) { return error.message; }))
.pipe(autoprefixer())
.pipe(gulp.dest('public/styles'))
.pipe(browserSync.stream())
})
gulp.task('php', function () {
php.server({
hostname: '0.0.0.0',
base: 'public',
port: 4040,
open: false
})
})
gulp.task('default', ['clean', 'version', 'styles', 'scripts', 'content', 'php'], function () {
browserSync({
port: 4200,
proxy: {
target: 'http://localhost:4040',
reqHeaders: function (config) {
return {
'accept-encoding': 'identity',
'agent': false
}
}
},
reloadDelay: 1000,
notify: true,
open: true,
logLevel: 'silent'
})
gulp.watch('webapp/views/**/*', reload)
gulp.watch('app/styles/**/*', ['styles'])
gulp.watch('app/scripts/**/*', ['scripts'])
});
gulp.task('build', ['clean', 'version', 'styles', 'scripts', 'content']);
function string_src(filename, string) {
var src = require('stream').Readable({ objectMode: true });
src._read = function () {
this.push(new File({ cwd: "", base: "", path: filename, contents: new Buffer(string) }))
this.push(null)
}
return src;
}