Created
April 3, 2014 19:42
-
-
Save xjackk/9961459 to your computer and use it in GitHub Desktop.
gulpfile coffee, less, compile, watch + clean&build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gulp = require 'gulp' | |
runSequence = require 'run-sequence' | |
gutil = require 'gulp-util' | |
coffee = require 'gulp-coffee' | |
coffeelint = require 'gulp-coffeelint' | |
less = require 'gulp-less' | |
clean = require 'gulp-clean' | |
uglify = require 'gulp-uglify' | |
concat = require 'gulp-concat' | |
minifyCSS = require 'gulp-minify-css' | |
# config | |
build= | |
client: 'build' | |
server: 'lib' | |
src= | |
client: 'src/client/**/*.coffee' | |
server: 'src/server/**/*.coffee' | |
dist= | |
client: 'build/js' | |
css: 'build/css' | |
server: 'lib' | |
# this will run in THIS ORDER | |
# build-clean | |
# copy tasks cpy* will run in parallel | |
# compile task compile* will run in parallel | |
gulp.task "build", (callback) -> | |
runSequence "build-clean", [ | |
"cpyrequire" | |
"cpytemplates" | |
"cpyfonts" | |
"cpycomponents" | |
"cpyless_fa" | |
"cpyless_bssocial" | |
"cpyless_bs" | |
], [ | |
"compile-less" | |
"compile-coffee-client" | |
"compile-coffee-server" | |
], callback | |
return | |
# CLEAN TASK | |
# delete build folders for client and server projects | |
gulp.task "build-clean", -> | |
gulp.src [build.client, build.server], read: false | |
.pipe clean() | |
# COPY TASKS | |
gulp.task 'cpyrequire', -> | |
gulp.src 'bower_components/requirejs/require.js' | |
.pipe uglify() | |
.pipe gulp.dest 'build/js' | |
gulp.task 'cpytemplates', -> | |
#templates | |
gulp.src 'src/client/**/*.htm' | |
.pipe gulp.dest 'build/js/' | |
gulp.task 'cpyfonts', -> | |
#fonts | |
gulp.src ['bower_components/bootstrap/dist/fonts/**','bower_components/font-awesome/fonts/**' ] | |
.pipe gulp.dest 'build/fonts/' | |
gulp.task 'cpycomponents', -> | |
#all client dependencies | |
gulp.src 'bower_components/**/*' | |
.pipe gulp.dest 'build/bower_components/' | |
# COPY LESS libs to src/client/less for proper @imports in main.less | |
gulp.task 'cpyless_fa', -> | |
gulp.src 'bower_components/font-awesome/less/*.less' | |
.pipe gulp.dest 'src/client/less/font-awesome' | |
gulp.task 'cpyless_bssocial', -> | |
gulp.src 'bower_components/bootstrap-social/bootstrap-social.less' | |
.pipe gulp.dest 'src/client/less/bootstrap-social' | |
gulp.task 'cpyless_bs', -> | |
gulp.src 'bower_components/bootstrap/less/*.less' | |
.pipe gulp.dest 'src/client/less/bootstrap' | |
# COMPILE TASKS | |
#less to css + minifyCSS | |
gulp.task 'compile-less', -> | |
gulp.src 'src/client/less/main.less' | |
.pipe less() | |
.pipe minifyCSS() | |
.pipe gulp.dest 'build/css' | |
gulp.task 'compile-coffee-server', -> | |
# bare true for server/nodejs modules | |
gulp.src src.server | |
.pipe coffee bare: true | |
.pipe uglify() | |
.on 'error', gutil.log | |
.pipe gulp.dest dist.server | |
gulp.task 'compile-coffee-client', -> | |
# bare false for AMD client modules wraps modules | |
gulp.src src.client | |
.pipe coffee bare: false # wrap js modules | |
.on 'error', gutil.log | |
.pipe gulp.dest dist.client | |
gulp.task 'coffee-lint', -> | |
#gutil.log "=> linting COFFEE source" | |
gulp.src [src.client, src.server] | |
.pipe coffeelint() | |
# Define the default task as a sequence of the above tasks | |
gulp.task "default", ['build'], -> | |
gutil.log "=> WATCHING..." | |
watcher = gulp.watch(src.client, ['compile-coffee-client']) | |
watcher.on 'change', (event) -> | |
console.log "File: " + event.path + ": " + event.type + "=>COFFEE cli" | |
swatcher = gulp.watch(src.server, ['compile-compile-server']) | |
swatcher.on 'change', (event) -> | |
console.log "File: " + event.path + ": " + event.type + "=>COFFEE srv" | |
twatcher = gulp.watch('src/client/**/*.htm', ['cpytemplates']) | |
twatcher.on 'change', (event) -> | |
console.log "File: " + event.path + ": " + event.type + "=>CPY tmpl" | |
lwatcher = gulp.watch('src/client/less/**/*.less', ['compile-less']) | |
lwatcher.on 'change', (event) -> | |
console.log "File: " + event.path + ": " + event.type + "=>COMPILE LESS" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('coffee-script/register'); | |
require('./gulpfile.coffee'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment