forked from zombeats/bloggy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.coffee
executable file
·125 lines (109 loc) · 3.69 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
# -- Dependencies --------------------------------------------------------------
gulp = require 'gulp'
gulpif = require 'gulp-if'
gutil = require 'gulp-util'
sass = require 'gulp-sass'
concat = require 'gulp-concat'
coffee = require 'gulp-coffee'
header = require 'gulp-header'
uglify = require 'gulp-uglify'
cssnano = require 'gulp-cssnano'
addsrc = require 'gulp-add-src'
changed = require 'gulp-changed'
pkg = require './package.json'
_s = require 'underscore.string'
prefix = require 'gulp-autoprefixer'
strip = require 'gulp-strip-css-comments'
browserSync = require 'browser-sync'
reload = browserSync.reload
isProduction = process.env.NODE_ENV is 'production'
CONST =
DEFAULT_LANG : 'en_US'
SUPPORTED_LANGS : [ 'en_ES' ]
PORT:
GHOST: 2368
BROWSERSYNC: 3000
# -- Files ---------------------------------------------------------------------
dist =
name : _s.slugify(pkg.name)
css : 'assets/css'
js : 'assets/js'
src =
sass:
main : 'assets/scss/bloggy.scss'
files : ['assets/scss/**/**']
js :
i18n :
main : 'assets/js/src/i18n/index.coffee'
languages :
path: 'assets/js/src/i18n'
main : [ 'assets/js/src/__init.coffee'
'assets/js/src/main.coffee' ]
vendor : ['assets/js/src/application.js'
'assets/js/src/jquery.smartresize.js'
'assets/js/src/prism.js'
'assets/vendor/fitvids/jquery.fitvids.js'
'assets/vendor/fastclick/lib/fastclick.js']
css :
main : 'assets/css/' + dist.name + '.css'
vendor : []
banner = [ "/**"
" * <%= pkg.name %> - <%= pkg.description %>"
" * @version <%= pkg.version %>"
" * @link <%= pkg.homepage %>"
" * @author <%= pkg.author.name %> (<%= pkg.author.url %>)"
" * @license <%= pkg.license %>"
" */"
"" ].join("\n")
gulp.task 'css', ->
gulp.src src.css.vendor
.pipe changed dist.css
.pipe addsrc src.sass.main
.pipe sass().on('error', sass.logError)
.pipe concat dist.name + '.css'
.pipe gulpif(isProduction, prefix())
.pipe gulpif(isProduction, strip all: true)
.pipe gulpif(isProduction, cssnano())
.pipe gulpif(isProduction, header banner, pkg: pkg)
.pipe gulp.dest dist.css
return
gulp.task 'js i18n', ->
CONST.SUPPORTED_LANGS.forEach (lang) ->
gulp.src src.js.main
.pipe addsrc "#{src.js.i18n.languages.path}/index.coffee"
.pipe addsrc "#{src.js.i18n.languages.path}/#{lang}.coffee"
.pipe changed dist.js
.pipe coffee().on 'error', gutil.log
.pipe addsrc src.js.vendor
.pipe concat dist.name + ".#{lang}.js"
.pipe gulpif(isProduction, uglify())
.pipe gulpif(isProduction, header banner, pkg: pkg)
.pipe gulp.dest dist.js
return
gulp.task 'js default', ->
gulp.src src.js.main
.pipe changed dist.js
.pipe coffee().on 'error', gutil.log
.pipe addsrc src.js.vendor
.pipe concat dist.name + ".#{CONST.DEFAULT_LANG}.js"
.pipe gulpif(isProduction, uglify())
.pipe gulpif(isProduction, header banner, pkg: pkg)
.pipe gulp.dest dist.js
return
gulp.task 'server', ->
browserSync.init null,
proxy: "http://127.0.0.1:#{CONST.PORT.GHOST}"
files: ["assets/**/*.*",
"*.hbs",
"partials/**/*.hbs"]
reloadDelay: 300
port: CONST.PORT.BROWSERSYNC
return
gulp.task 'build', ['css', 'js']
gulp.task 'js', ['js default', 'js i18n']
gulp.task 'watch', -> gulp.watch 'assets/js/src/i18n/**/*', ['js']
gulp.task "default", ->
gulp.start ["build", "watch", "server"]
gulp.watch src.sass.files, ["css"]
gulp.watch src.js.main, ["js"]
gulp.watch src.js.vendor, ["js"]