-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.coffee
149 lines (133 loc) · 3.62 KB
/
gulpfile.coffee
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
gulp = require 'gulp'
$ = require('gulp-load-plugins')()
del = require('del')
path = require('path')
php = require('gulp-connect-php')
addsrc = require('gulp-add-src')
browserSync = require('browser-sync')
reload = browserSync.reload
global.browser_support = [
"ie >= 9"
"ie_mob >= 10"
"ff >= 30"
"chrome >= 34"
"safari >= 7"
"opera >= 23"
"ios >= 7"
"android >= 4.4"
"bb >= 10"
]
#
# == Variables
#
path = new (->
@root = './public'
@sass = @root + '/assets/sass'
@coffee = @root + '/assets/coffeescript'
@img = @root + '/assets/images'
@fonts = @root + '/assets/fonts'
@app = './app'
@config = './config'
@views = @app + '/views'
@partials = @views + '/partials'
@content = @views + '/content'
@layout = @views + '/layouts'
@dist_root = @root
@dist_css = @root + '/assets/css'
@dist_js = @root + '/assets/js'
@dist_img = @img
)
#
# == Server
#
gulp.task 'php', ['watchall'], ->
php.server {
base: path.root
port: 8015
keepalive: true
}, ->
browserSync
notify: false
port: 8080
open: false
ui: false
proxy: '127.0.0.1:8015'
return
#
# == Watcher
#
gulp.task 'watchall', ->
gulp.watch([
"#{path.app}/**/*.{php,yaml,yml}"
]).on 'change', ->
browserSync.reload()
return
gulp.watch ["#{path.sass}/**/*.sass", "#{path.sass}/**/*.scss"], ['sass', reload]
gulp.watch "#{path.coffee}/**/*.coffee", ['coffee', reload]
watcher = gulp.watch "#{path.img}/**/*.*", [reload]
# Sync deleted pictures on dist folder
watcher.on 'change', (event) ->
console.log event
if event.type == 'deleted'
filePathFromSrc = path.relative(path.resolve("#{path.img}"), event.path)
destFilePath = path.resolve("#{path.dist_img}", filePathFromSrc)
del.sync destFilePath
return
#
# == Sass task
#
gulp.task 'sass', ->
sass_task(["#{path.sass}/**/*.sass", "!#{path.sass}/**/noscript.sass", "!#{path.sass}/**/ie9.sass"], 'application.css')
sass_task(["#{path.sass}/**/noscript.sass"], 'noscript.css')
sass_task(["#{path.sass}/**/ie9.sass"], 'ie9.css')
#
# == Coffee task
#
gulp.task 'coffee', ->
gulp.src [
"#{path.coffee}/base/functions.coffee",
"#{path.coffee}/_mapbox_map.coffee",
"#{path.coffee}/_form_backup.coffee",
"#{path.coffee}/_responsive_menu.coffee",
"#{path.coffee}/_ajax_form.coffee",
# "#{path.coffee}/_vegas_gallery.coffee",
"#{path.coffee}/application.coffee"
]
.pipe $.plumber()
.pipe $.coffee
bare: true
.pipe addsrc.prepend [
'node_modules/jquery/dist/jquery.min.js',
#'node_modules/vegas/dist/vegas.min.js',
'node_modules/autosize/dist/autosize.js',
'node_modules/jquery-placeholder/jquery.placeholder.js',
'node_modules/foundation-sites/js/foundation.core.js',
'node_modules/foundation-sites/js/foundation.util.mediaQuery.js',
'node_modules/foundation-sites/js/foundation.util.triggers.js',
'node_modules/foundation-sites/js/foundation.abide.js'
]
.pipe $.babel()
.pipe $.concat('application.js')
.pipe $.uglify()
.pipe $.size()
.pipe gulp.dest path.dist_js
gulp.task 'fonts', ->
gulp.src 'node_modules/font-awesome/fonts/*'
.pipe gulp.dest path.fonts
#
# == Copy all assets and pages to the site folder
#
gulp.task 'dist', ['sass', 'coffee']
gulp.task 'default', ['php']
# Function to handle sass for various files
sass_task = (to_watch, dest) ->
gulp.src to_watch
.pipe $.plumber()
.pipe $.sass
indentedSyntax: true
onError: console.error.bind(console, 'SASS Error:')
.pipe $.autoprefixer(browsers: browser_support)
.pipe $.concatCss(dest)
.pipe $.cssnano()
.pipe $.size()
.pipe gulp.dest path.dist_css