This repository has been archived by the owner on Mar 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.coffee
95 lines (82 loc) · 2.55 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
gulp = require 'gulp'
rename = require 'gulp-rename'
webpack = require 'gulp-webpack'
stylus = require 'gulp-stylus'
plumber = require 'gulp-plumber'
named = require 'vinyl-named'
del = require 'del'
path = require 'path'
nib = require 'nib'
browserSync = require 'browser-sync'
{argv} = require 'yargs'
# config
project =
name: 'pastry'
dest: 'pastry/static'
build: 'build/assets'
webpack: require('./webpack.config')
scripts =
name: 'scripts'
exts: ['js', 'coffee']
stylesheets =
name: 'stylesheets'
exts: ['css', 'styl']
assets =
name: 'assets'
dirs: [scripts.name, stylesheets.name]
exts: [].concat(scripts.exts, stylesheets.exts)
glob: (bundle) ->
if bundle
"#{project.build}/#{bundle.name}/*/*.{#{bundle.exts.join(',')}}"
else
dirs = assets.dirs.join(',')
exts = assets.exts.join(',')
"#{project.name}/*/#{assets.name}/{#{dirs}}/**/*.{#{exts}}"
# tasks
gulp.task 'default', ['clean'], ->
gulp.start 'build'
gulp.task 'build', ['webpack', 'style']
gulp.task 'clean', ['clean:collect', 'clean:dist']
gulp.task 'watch', ['default'], ->
gulp.start 'browser-sync'
gulp.watch assets.glob(), ['build']
gulp.task 'collect', ->
gulp.src assets.glob()
.pipe rename((path) ->
dirs = assets.dirs.join('|')
pattern = new RegExp("([^/]+)/#{assets.name}/(#{dirs})(/[^/]+)?")
matched = pattern.exec(path.dirname)
path.dirname = "#{matched[2]}/#{matched[1]}#{matched[3] || ''}"
path)
.pipe gulp.dest(project.build)
gulp.task 'webpack', ['collect'], ->
gulp.src assets.glob(scripts)
.pipe plumber()
.pipe named((file) ->
dirname = path.basename(path.dirname(file.path))
filename = path.basename(file.path, path.extname(file.path))
path.join(dirname, filename))
.pipe webpack(project.webpack)
.pipe gulp.dest("#{project.dest}/#{scripts.name}")
gulp.task 'style', ['collect'], ->
options =
use: [nib()]
compress: not argv.debug
sourcemap: { inline: argv.debug } if argv.debug
gulp.src assets.glob(stylesheets)
.pipe plumber()
.pipe stylus(options)
.pipe gulp.dest("#{project.dest}/#{stylesheets.name}")
.pipe browserSync.reload(stream: true)
gulp.task 'browser-sync', ->
port = argv.port or process.env.PORT
proxy = argv.proxy or "localhost:#{port - 100}"
browserSync port: port, proxy: proxy, open: false
gulp.task 'clean:collect', (done) ->
del [
"#{project.build}/**/*.{#{assets.exts.join(',')}}"
], done
gulp.task 'clean:dist', (done) ->
del [
"#{project.dest}/**/*",
], done