Skip to content

Instantly share code, notes, and snippets.

@dreamineering
Forked from MoOx/gulpfile.js
Created January 27, 2014 20:22
Show Gist options
  • Select an option

  • Save dreamineering/8656478 to your computer and use it in GitHub Desktop.

Select an option

Save dreamineering/8656478 to your computer and use it in GitHub Desktop.
///
var pkg = require("./package.json")
, gulp = require("gulp")
, gutil = require("gulp-util")
, concat = require("gulp-concat")
///
// HTML (Jade)
///
var jade = require("gulp-jade")
, htmlFiles = ["./src/html/**/*.jade"]
gulp.task("html", function() {
gulp.src(htmlFiles)
.pipe(jade({
data: pkg
, pretty: true
}))
.pipe(gulp.dest("./dist/"))
.pipe(livereload(livereloadServer))
})
///
// Static server
///
var connect = require("connect")
, livereloadServer = require("tiny-lr")()
, livereload = require("gulp-livereload")
, serverAddress = "http://" + pkg.gulp.server.host + ":" + pkg.gulp.server.port + "/"
gulp.task("server", function() {
connect()
.use(require("connect-livereload")({
port: pkg.gulp.livereloadServer.port
}))
.use(connect.static("./dist"))
.listen(pkg.gulp.server.port)
gutil.log("Connect server running at " + serverAddress)
})
gulp.task("server.open", function() {
// src is needed, but not used, cause of gulp way.
gulp.src("./package.json")
.pipe(require("gulp-open")("", {url: serverAddress}))
})
///
// Lint JS
///
var jshint = require("gulp-jshint")
, jscs = require("gulp-jscs")
, jsFiles = [
"*.js"
, "*.json"
, ".jshintrc"
, ".csslintrc"
, "./src/js/**/*.js"
]
gulp.task("lint-scripts", function() {
gulp.src(jsFiles)
.pipe(jscs())
// .pipe(jshint(".jshintrc"))
// .pipe(jshint.reporter("jshint-stylish"))
})
///
// JS
///
var browserify = require("gulp-browserify")
, browserifyTransform = [
"jadeify"
, "debowerify"
, "decomponentify"
, "deamdify"
, "deglobalify"
, "es6ify"
]
if (gulp.env.production) {
browserifyTransform.push("uglifyify")
}
gulp.task("scripts", function() {
// just grab files that are at the root
// others files are considered as module
gulp.src(["./src/js/index.js"])
.pipe(jshint())
.pipe(browserify({
transform: browserifyTransform
//, insertGlobals : true
, debug: gulp.env.production !== undefined
}))
.pipe(concat("index.js"))
.pipe(gulp.dest("./dist/js/"))
.pipe(livereload(livereloadServer))
gulp.run("lint-scripts")
})
///
// CSS
///
var rework = require("gulp-rework")
, reworkPlugins = {
imprt: require("rework-import")
, parent: require("rework-parent")
, breakpoints: require("rework-breakpoints")
, vars: require("rework-vars")
, calc: require("rework-calc")
, clearfix: require("rework-clearfix")
}
, autoprefixer = require("gulp-autoprefixer")
, csso = require("gulp-csso")
gulp.task("styles", function() {
gulp.src("./src/css/*.css")
.pipe(
rework(
// enhancements
rework.colors()
, rework.references()
, reworkPlugins.imprt("./src/css")
, reworkPlugins.parent
, reworkPlugins.breakpoints
, reworkPlugins.vars()
, reworkPlugins.calc
, reworkPlugins.clearfix
, {
sourcemap: true
}
)
)
.pipe(autoprefixer())
.pipe(gulp.env.production ? csso() : gutil.noop())
.pipe(gulp.dest("./dist/css/"))
.pipe(livereload(livereloadServer))
gulp.run("lint-styles")
})
///
// Lint CSS
///
var csslint = require("gulp-csslint")
gulp.task("lint-styles", function() {
gulp.src("./dist/css/**/*.css")
.pipe(csslint(".csslintrc"))
.pipe(csslint.reporter())
})
///
// Tasks
///
gulp.task("install", function() {
gulp.run("scripts")
gulp.run("styles")
gulp.run("html")
})
gulp.task("dev", function() {
gulp.run("install")
gulp.run("server")
gulp.run("server.open")
livereloadServer.listen(pkg.gulp.livereloadServer.port, function(err) {
if (err) { return gutil.log(err) }
gulp.watch(jsFiles, function(event) {
gulp.run("scripts")
})
gulp.watch("./src/css/*.css", function(event) {
gulp.run("styles")
})
gulp.watch(htmlFiles, function(event) {
gulp.run("html")
})
})
})
gulp.task("default", function() {
// remove that task when `gulp --tasks` works
if (gulp.env.tasks) {
gutil.log(Object.keys(gulp.tasks))
return
}
gulp.run("dev")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment