This repository has been archived by the owner on Jun 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.coffee
195 lines (167 loc) · 4.54 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
'use strict'
# Include gulp
gulp = require 'gulp'
Server = require('karma').Server
# Include Our Plugins
cleanDest = require 'gulp-clean-dest'
concat = require 'gulp-concat'
uglify = require 'gulp-uglify'
html2js = require 'gulp-ng-html2js'
coffee = require 'gulp-coffee'
coffeelint = require 'gulp-coffeelint'
gutil = require 'gulp-util'
rename = require 'gulp-rename'
less = require 'gulp-less'
minifyCSS = require 'gulp-minify-css'
inject = require 'gulp-inject'
bowerFiles = require 'main-bower-files'
imagemin = require 'gulp-imagemin'
runSequence = require 'run-sequence'
browserSync = require 'browser-sync'
wiredep = require 'wiredep'
### Variables ###
name = 'sc-toggle-switch'
paths =
src: 'src'
dist: 'dist'
demo: 'demo'
release: 'release'
test: 'test'
tmp: '.tmp'
src =
scripts: "#{paths.src}/**/*.coffee"
stylesheets: "#{paths.src}/**/*.less"
templates: "#{paths.src}/**/*_template.html"
index: "#{paths.demo}/index.html"
demo: "#{paths.demo}/*.js"
dest =
all: "#{paths.dist}/**/*.*"
scripts: "#{paths.dist}/js"
stylesheets: "#{paths.dist}/css"
tmp:
scripts: "#{paths.tmp}/js"
templates: "#{paths.tmp}/templates"
tmp =
scripts: [
"#{dest.tmp.scripts}/**/*.js"
"#{dest.tmp.templates}/**/*.js"
]
config =
port: "9000"
baseDevUrl: "http://localhost"
uri: "http://localhost:9000"
# Watch Files For Changes
gulp.task 'watch', ->
gulp.watch src.scripts, ['scripts']
gulp.watch src.templates, ['scripts']
gulp.watch src.stylesheets, ['stylesheets']
gulp.watch src.index, ['index']
gulp.watch src.demo, ['demo']
gulp.watch dest.all
.on 'change', browserSync.reload
# Run a webserver
gulp.task 'connect', ->
browserSync.init(
ui: false
server: {
baseDir: paths.dist
index: "index.html"
routes: {
"/bower_components": "bower_components"
"/dist": "dist"
}
}
port: config.port
open: "local"
browser: "chromium-browser"
)
# Compile CoffeeScript files
gulp.task 'coffee', ->
gulp
.src src.scripts
.pipe cleanDest(dest.tmp.scripts)
.pipe coffeelint()
.pipe coffeelint.reporter('default')
.pipe coffee()
.pipe gulp.dest dest.tmp.scripts
.on('error', gutil.log)
# Converting AngularJS templates to JavaScript
gulp.task 'html2js', ->
gulp
.src src.templates
.pipe cleanDest(dest.tmp.templates)
.pipe html2js(
moduleName: (file) ->
pathParts = file.path.split('/')
folder = pathParts[pathParts.length - 1]
folder.replace('_template.html', 'Template')
)
.pipe concat 'templates.js'
.pipe gulp.dest dest.tmp.templates
.on('error', gutil.log)
# Concatenate & Minify Javascript files
gulp.task 'scripts', ['coffee', 'html2js'], ->
gulp
.src tmp.scripts
.pipe cleanDest(dest.scripts)
.pipe concat "#{name}.js"
.pipe rename "#{name}.min.js"
.pipe uglify({
# Specify mangle false to prevent changes to your variable and function names
mangle: false
})
.pipe gulp.dest dest.scripts
.on('error', gutil.log)
# Concatenate & Minify CSS files
gulp.task 'stylesheets', ->
gulp
.src src.stylesheets
.pipe cleanDest(dest.stylesheets)
.pipe less()
.pipe minifyCSS()
.pipe concat "#{name}.css"
.pipe rename "#{name}.min.css"
.pipe gulp.dest dest.stylesheets
.on('error', gutil.log)
# Injecting all files for development
gulp.task 'index', ->
wiredepOptions =
directory: 'bower_components'
gulp
.src src.index
.pipe inject gulp.src(bowerFiles(), {read: false}), {addRootSlash: false, name: 'bower'}
.pipe inject gulp.src(["#{dest.scripts}/#{name}.min.js", "#{dest.stylesheets}/#{name}.min.css"], {read: false}), {addRootSlash: false}
.pipe gulp.dest paths.dist
.on('error', gutil.log)
# Copy demonstration files
gulp.task 'demo', ->
gulp
.src src.demo
.pipe gulp.dest paths.dist
# Populate release folder
gulp.task 'release', ->
gulp
.src ["#{dest.scripts}/#{name}.min.js", "#{dest.stylesheets}/#{name}.min.css"]
.pipe gulp.dest paths.release
### Testing Tasks ###
# Unit Testing with Karma
gulp.task 'unit-test', (done) ->
new Server({
configFile: __dirname + "/#{paths.test}/karma_conf.coffee",
singleRun: true
}, done).start()
### Tasks ###
gulp.task 'build', ->
runSequence ['scripts', 'stylesheets']
gulp.task 'build-release', ->
runSequence ['scripts', 'stylesheets'], 'release'
# This will run in this order:
# scripts and stylesheets in parallel
# index and demo in parallel
# connect and watch in parallel
gulp.task 'serve', ->
runSequence ['scripts', 'stylesheets'], ['index', 'demo'], ['connect', 'watch']
gulp.task 'default', [
'build'
'watch'
]