Skip to content

Instantly share code, notes, and snippets.

@nucleardreamer
Last active August 29, 2015 14:07
Show Gist options
  • Save nucleardreamer/d56f035870a3135a6f8e to your computer and use it in GitHub Desktop.
Save nucleardreamer/d56f035870a3135a6f8e to your computer and use it in GitHub Desktop.
var path = require('path'),
gulp = require('gulp'),
stylus = require('gulp-stylus'),
nib = require('nib'),
mincss = require('gulp-minify-css'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
watch = require('gulp-watch'),
clean = require('gulp-clean'),
nodemon = require('gulp-nodemon'),
debug = require('gulp-debug'),
clone = require('gulp-clone'),
rename = require("gulp-rename"),
es = require('event-stream'),
fs = require('fs'),
nconf = require('nconf');
// load settings
var publicSettings = path.join(__dirname, 'settings', 'settings.json');
if (fs.existsSync(publicSettings)) {
nconf.use('file', {
file: publicSettings
});
} else {
console.log('config does not exist')
}
nconf.load();
var site = process.env.RANKU_SITE || nconf.get('app:site');
gulp.task('build-sprites', function () {
var spriteData = gulp.src(path.join('client', site ,'sprites','*.png'))
.pipe(require('gulp.spritesmith')({
// path the css ultimatly links to
imgName: '/img/sprite.png',
cssName: 'sprite.styl'
}));
spriteData.img.pipe(gulp.dest(path.join(__dirname, 'public', site, 'img')));
spriteData.css.pipe(gulp.dest(path.join(__dirname, 'client', site, 'css')));
return spriteData
});
gulp.task('build-scripts', function() {
return gulp.src(path.join('client', site, 'js', 'user', '*.js'))
//.pipe(debug({verbose: true}))
.pipe(concat('user.js'))
.pipe(uglify({outSourceMap: true}))
.pipe(gulp.dest(path.join('public', site, 'build')));
});
gulp.task('build-stylus', function() {
var css = gulp.src([
path.join('public',site,'components','bootstrap','dist','css','bootstrap.css'),
path.join('client',site,'css','**','*.styl')
], { base: path.join('client', site) })
//.pipe(debug({verbose: true}))
.pipe(stylus({
use: [nib()]
}))
.pipe(concat('app.css'))
var min = css.pipe(clone())
.pipe(mincss({
keepSpecialComments: '0',
root: path.join('public', site)
}))
.pipe(rename('app.min.css'))
return es.merge(css, min).pipe(gulp.dest(path.join('public', site, 'build')));
});
gulp.task('clean',function() {
return gulp.src(['public/build'], {read: false})
.pipe(clean());
});
gulp.task('dev', function() {
nodemon({ script: 'app.js', ext: 'js', ignore: 'public/'})
.on('restart', ['default']);
gulp.start("default");
});
gulp.task('build', function() {
gulp.start("build-scripts");
gulp.start("build-stylus");
});
gulp.task('heroku:production', function() {
gulp.start("build");
});
gulp.task('heroku:development', function() {
gulp.start("build");
});
gulp.task('default', ['clean'],function(){
gulp.start("build");
watch({glob: "client/sprites/*.png"}, function() {
gulp.start("build-sprites");
});
watch({glob: path.join("client",site,"js","**","*.js")}, function() {
gulp.start("build-scripts");
});
watch({glob: path.join("client",site,"css","*.styl")}, function() {
gulp.start("build-stylus");
});
});
gulp.task('test', function(){
return;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment