-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.coffee
executable file
·97 lines (83 loc) · 2.9 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
############
# Requires
############
gulp = require('gulp')
config = require('./config')
# Utils
gutil = require('gulp-util')
plumber = require('gulp-plumber')
sourcemaps = require('gulp-sourcemaps')
livereload = require('gulp-livereload')
del = require('del')
# Styles
stylus = require('gulp-stylus')
nib = require('nib')
csso = require('gulp-csso')
# JS
coffee = require('gulp-coffee')
uglify = require('gulp-uglify')
# Server
nodemon = require('gulp-nodemon')
############
# Environment
############
NODE_ENV = 'development'
if process.env?.NODE_ENV? and process.env.NODE_ENV in ['development', 'test', 'production'] then NODE_ENV = process.env.NODE_ENV
process.env.NODE_ENV = NODE_ENV # Submit environment if it was not provided on running
############
# Child tasks
############
gulp.task 'development-server', ()->
nodemon({ script: 'server/server.coffee', ext: 'coffee', watch: 'server'})
.on('change', [])
.on 'restart', ()->
console.log 'nodemon restarted!'
gulp.task 'development-style', ()->
# Stylesheet
gulp.src('./app/css/style.styl')
.pipe(plumber())
.pipe(stylus({use: [nib()], linenos: true, 'include css': true, url: {name: 'url', limit: 10000, paths: [__dirname + '/public/images']}}).on('error', gutil.log))
.pipe(gulp.dest('./public/css'))
.pipe(livereload({auto: false}))
gulp.task 'development-script', ()->
# Scripts
# Copy coffee files to view source in Chrome
gulp.src('./app/js/**/*.coffee')
.pipe(gulp.dest('./public/js'))
# Build sources
gulp.src('./app/js/*.coffee')
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(coffee({bare: true, join: true}).on('error', gutil.log))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./public/js'))
.pipe(livereload({auto: false}))
gulp.task 'development-watch', ()->
livereload.listen()
# Watch style changes
watcher_style = gulp.watch('./app/css/**/*.styl', ['development-style'])
watcher_style.on 'changed', (e)->
console.log e.type + '-' + e.path
# Watch script changes
watcher_script = gulp.watch ['./app/js/**/*.coffee'], ['development-script']
watcher_script.on 'changed', (e)->
console.log(e.type + '-' + e.path)
gulp.task 'build-clean', (cb)->
del ['./public/js/**/*.coffee'], cb
gulp.task 'build-style', ->
gulp.src('./app/css/style.styl')
.pipe(stylus({use: [nib()], 'include css': true, url: {name: 'url', limit: 10000, paths: [__dirname + '/public/images']}}))
.pipe(csso(false))
.pipe(gulp.dest('./public/css'))
gulp.task 'build-script', ->
# Scripts
gulp.src('./app/js/**/*.coffee')
.pipe(coffee({bare: true, join: true, 'include css': true}).on('error', gutil.log))
.pipe(uglify())
.pipe(gulp.dest('./public/js'))
############
# Main tasks
############
gulp.task 'default', ['dev']
gulp.task 'dev', ['development-style', 'development-script', 'development-watch', 'development-server']
gulp.task 'build', ['build-clean', 'build-style', 'build-script']