Last active
August 29, 2015 14:21
-
-
Save Snugglepantz/6724ee63e59e447bc108 to your computer and use it in GitHub Desktop.
gulpfile
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
var gulp = require('gulp'); | |
var args = require('yargs').argv; | |
var del = require('del'); | |
var config = require('./gulp.config')(); | |
var $ = require('gulp-load-plugins')({lazy: true}); | |
/***************************************************************** | |
* Main | |
*****************************************************************/ | |
//Dev | |
gulp.task('default', ['inject', 'html', 'css', 'js', 'fonts', 'images', 'flash']); | |
//Dist | |
/***************************************************************** | |
* | |
* Clean | |
* | |
*****************************************************************/ | |
//Dev | |
gulp.task('clean', ['cleanDist', 'cleanTmp']); | |
gulp.task('cleanDist', function(done) { | |
var files = config.build; | |
clean(files, done); | |
}); | |
gulp.task('cleanTmp', function(done) { | |
var files = config.tmp; | |
clean(files, done); | |
}); | |
/***************************************************************** | |
* | |
* CSS | |
* | |
*****************************************************************/ | |
gulp.task('css', ['less', 'theme']); | |
//Less | |
gulp.task('less', ['clean'], function() { | |
log('Compiling Less --> CSS'); | |
return gulp | |
.src(config.css.less) | |
.pipe($.less()) | |
.pipe(gulp.dest(config.tmp)); | |
}); | |
gulp.task('theme', ['clean'], function() { | |
return gulp | |
.src(config.css.theme) | |
.pipe(gulp.dest(config.css.dest)) | |
}) | |
//Dist | |
/***************************************************************** | |
* | |
* JS | |
* | |
*****************************************************************/ | |
gulp.task('js', ['lint']); | |
//Lint | |
gulp.task('lint', function() { | |
log('Running JSHint'); | |
return gulp.src(config.js.src) | |
.pipe($.jshint()) | |
.pipe($.jshint.reporter('jshint-stylish', {verbose: true})) | |
.pipe($.jshint.reporter('fail')); | |
}); | |
//Dist | |
/***************************************************************** | |
* | |
* HTML | |
* | |
*****************************************************************/ | |
gulp.task('html', ['clean'], function() { | |
if (!args.prod) { | |
return gulp | |
.src(config.html, {base: 'src/'}) | |
.pipe(gulp.dest(config.build)); | |
} else { | |
return gulp | |
.src(config.html) | |
.pipe($.angularTemplatecache('templates.js', { | |
module: 'app.core', | |
standalone: false | |
})) | |
.pipe(gulp.dest(config.tmp)); | |
} | |
return; | |
}); | |
/***************************************************************** | |
* | |
* Fonts | |
* | |
*****************************************************************/ | |
//Dev | |
gulp.task('fonts', ['clean'], function() { | |
log('Copying Fonts'); | |
return gulp | |
.src(config.fonts.src) | |
.pipe($.flatten()) | |
.pipe(gulp.dest(config.fonts.dest)); | |
}); | |
/***************************************************************** | |
* | |
* Images | |
* | |
*****************************************************************/ | |
//Dev | |
gulp.task('images', ['clean'], function() { | |
log('Copying Images'); | |
return gulp | |
.src(config.images.src) | |
.pipe(gulp.dest(config.images.dest)); | |
}); | |
/***************************************************************** | |
* | |
* Flash(REALLY! YEAH THIS IS HERE) | |
* | |
*****************************************************************/ | |
//Dev | |
gulp.task('flash', ['clean'], function() { | |
log('Copying Flash'); | |
return gulp | |
.src(config.flash.src) | |
.pipe($.flatten()) | |
.pipe(gulp.dest(config.flash.dest)); | |
}); | |
/***************************************************************** | |
* | |
* Injection | |
* | |
*****************************************************************/ | |
//Dev | |
gulp.task('inject', ['js', 'css'], function() { | |
log('Injecting Dependencies into index.html'); | |
return gulp | |
.src(config.index) | |
//VendorJS | |
.pipe($.inject( | |
gulp.src(config.js.vendorSrc) | |
.pipe($.flatten()) | |
.pipe($.if(args.prod, $.concat(config.js.vendorFile))) | |
.pipe($.if(args.prod, $.uglify())) | |
.pipe(gulp.dest(config.js.vendorDest)), | |
config.injectBower)) | |
//VendorCSS | |
.pipe($.inject( | |
gulp.src(config.css.vendorSrc) | |
.pipe($.flatten()) | |
.pipe($.if(args.prod, $.concat(config.css.vendorFile))) | |
.pipe($.if(args.prod, $.minifyCss())) | |
.pipe(gulp.dest(config.css.vendorDest)), | |
config.injectBower)) | |
//AppJS | |
.pipe($.inject( | |
gulp.src(config.js.src, {base: 'src/'}) | |
.pipe($.if(args.prod, $.concat(config.js.appFile))) | |
.pipe($.if(args.prod, $.uglify())) | |
.pipe(gulp.dest(config.js.dest)), | |
config.injectOther)) | |
//AppCSS | |
.pipe($.inject( | |
gulp.src(config.css.css) | |
.pipe($.flatten()) | |
.pipe($.if(args.prod, $.concat(config.css.appFile))) | |
.pipe($.if(args.prod, $.minifyCss())) | |
.pipe(gulp.dest(config.css.dest)), | |
config.injectOther)) | |
.pipe(gulp.dest(config.build)) | |
}); | |
//Dist | |
/***************************************************************** | |
* | |
* Util | |
* | |
*****************************************************************/ | |
function clean(path, done) { | |
log('Cleaning: ' + $.util.colors.blue(path)); | |
del(path, done); | |
} | |
function log(msg) { | |
if (typeof (msg) === 'object') { | |
for (var item in msg) { | |
if (msg.hasOwnProperty(item)) { | |
$.util.log($.util.colors.blue(msg[item])); | |
} | |
} | |
} else { | |
$.util.log($.util.colors.blue(msg)); | |
} | |
} |
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
module.exports = function() { | |
var build = 'dist/'; | |
var vendorSrc = 'bower/lib/'; | |
var vendorCSSDest = build + 'vendorCSS/'; | |
var vendorJSDest = build + 'vendorJS/'; | |
var config = { | |
build: build, | |
tmp: './.tmp/', | |
index: 'src/index.html', | |
html: [ | |
'!src/index.html', | |
'src/**/*.html' | |
], | |
js: { | |
src: [ | |
'./src/**/*.module.js', | |
'./src/**/*.js', | |
'./.tmp/**/*.js' | |
], | |
dest: build, | |
vendorSrc: [ | |
vendorSrc + '**/jquery/**/*.js', | |
vendorSrc + '**/angular/**/*.js', | |
vendorSrc + '**/bootstrap/**/*.js', | |
vendorSrc + '**/*.js', | |
], | |
vendorDest: vendorJSDest, | |
vendorFile: 'vendor.min.js', | |
appFile: 'app.min.js' | |
}, | |
css: { | |
less: 'src/less/**/*.less', | |
css: [ | |
'src/content/**/*.css', | |
'!src/content/theme_darker.css', | |
'.tmp/**/*.css' | |
], | |
theme: 'src/content/theme_darker.css', | |
dest: build + 'css/', | |
vendorSrc: [ | |
vendorSrc + '**/bootstrap/*.css', | |
vendorSrc + '**/*.css' | |
], | |
vendorDest: vendorCSSDest, | |
vendorFile: 'vendor.min.css', | |
appFile: 'app.min.css' | |
}, | |
fonts: { | |
src: ['bower_components/bootstrap/fonts/*.*', | |
'bower_components/font-awesome/fonts/*.*', | |
'src/content/fonts/**/*.*'], | |
dest: build + 'fonts' | |
}, | |
images: { | |
src: 'src/content/images/**.*', | |
dest: build + 'content/images/' | |
}, | |
flash: { | |
src: vendorSrc + '**/*.swf', | |
dest: vendorJSDest | |
}, | |
injectOther: { | |
ignorePath: build, | |
addRootSlash: false | |
}, | |
injectBower: { | |
name: "bower", | |
ignorePath: build, | |
addRootSlash: false | |
} | |
}; | |
return config; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment