-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.coffee
156 lines (123 loc) · 3.77 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
149
150
151
152
153
154
path = require 'path'
basePath = __dirname
baseName = path.basename(basePath)
devHttpPath = "/#{baseName}"
# -------------------------------------------------
# プラグインロード
# -------------------------------------------------
# 基本
gulp = require 'gulp'
gutil = require 'gulp-util'
filter = require 'gulp-filter'
rename = require 'gulp-rename'
# watch関連
watch = require 'gulp-watch'
plumber = require 'gulp-plumber'
notify = require 'gulp-notify'
cached = require 'gulp-cached'
# Sass/Coffeeコンパイル関連
sass = require 'gulp-sass'
postcss = require 'gulp-postcss'
autoprefixer = require 'autoprefixer-core'
mqpacker = require 'css-mqpacker'
coffee = require 'gulp-coffee'
sourcemaps = require 'gulp-sourcemaps'
# タスクの逐次実行
runSequence = require 'run-sequence'
# bower_componentsの取得
mainBowerFiles = require 'main-bower-files'
# 外部プログラムの実行
exec = require 'gulp-exec'
# -------------------------------------------------
# SassとCoffeeを監視・コンパイルする
# -------------------------------------------------
gulp.task 'default', ['watch']
gulp.task 'watch', (callback)->
# 初回コンパイル実行
gulp.start 'sass'
gulp.start 'coffee'
# importされないscssのwatch
gulp
.watch ['sass/**/*.scss'], ['sass']
.on 'change', (event)->
console.log "#{event.type} - #{event.path}"
# coffeeのwatch
gulp
.watch 'coffee/**/*.coffee', ['coffee']
.on 'change', (event)->
console.log "#{event.type} - #{event.path}"
# -------------------------------------------------
# Sassコンパイル
# -------------------------------------------------
gulp.task 'scss', ['sass']
gulp.task 'sass', (path) ->
gulp
.src 'sass/**/*.scss'
.pipe plumber
errorHandler: notify.onError
title: 'Sass: <%= error.name %>'
message: '<%= error.message %>'
.pipe sourcemaps.init()
.pipe sass
imagePath: "#{devHttpPath}/img"
# 'compressed', 'expanded', 'compact', 'nested'
outputStyle: 'nested'
sourceComments: true
includePaths: ['sass', 'sass/lib']
.pipe postcss [
autoprefixer
browsers: ['> 1%', 'last 2 versions', 'IE 9', 'Firefox ESR', 'Opera 12.1']
mqpacker
]
.pipe sourcemaps.write()
.pipe gulp.dest 'css'
# -------------------------------------------------
# Coffeeコンパイル
# -------------------------------------------------
gulp.task 'coffee', ->
gulp
.src 'coffee/**/*.coffee'
.pipe cached 'coffee'
.pipe plumber
errorHandler: notify.onError
title: 'Coffee: <%= error.name %>'
message: '<%= error.message %>'
.pipe sourcemaps.init()
.pipe coffee
bare: true
.on 'error', gutil.log
.pipe sourcemaps.write()
.pipe gulp.dest 'js'
# -------------------------------------------------
# Bowerを使った初期化
# -------------------------------------------------
gulp.task 'initialize', ['init']
gulp.task 'init', (callback)->
runSequence(
'bowerInstall',
'exportLib',
callback
)
# -------------------------------------------------
# Bower installの実行
# -------------------------------------------------
gulp.task 'bower', ['bowerInstall']
gulp.task 'bowerInstall', ->
gulp
# ダミーストリーム
.src 'gulpfile.coffee'
.pipe exec 'bower install'
.pipe exec.reporter()
# -------------------------------------------------
# Bowerのexport
# -------------------------------------------------
gulp.task 'exportLib', ->
gulp
.src mainBowerFiles(),
base: 'bower_components'
.pipe filter ['**/*', '!**/*.scss']
.pipe rename (path)->
# 無駄なディレクトリ dist を除去する
path.dirname = path.dirname.replace(/[\\\/]dist/, '')
path
.pipe gulp.dest 'jslib'