Created
July 4, 2015 12:11
-
-
Save jcarley/6d36f45c867a3e1f16e2 to your computer and use it in GitHub Desktop.
Gulp for a coffeescript dev workflow
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
{ | |
"name": "todo", | |
"version": "0.1.0", | |
"description": "example todo app", | |
"authors": [ | |
"Jefferson Carley" | |
], | |
"license": "MIT", | |
"homepage": "none", | |
"ignore": [ | |
"test", | |
"tests", | |
"**/.*", | |
"node_modules", | |
"bower_components" | |
], | |
"dependencies": { | |
"jquery": "~2.1.4", | |
"bootstrap": "~3.3.5", | |
"angular": "~1.4.1", | |
"angular-sanitize": "~1.4.1", | |
"font-awesome": "~4.3.0", | |
"moment": "~2.10.3", | |
"angular-ui-router": "~0.2.15", | |
"toastr": "~2.1.1", | |
"angular-animate": "~1.4.1" | |
}, | |
"devDependencies": { | |
"karma": "~0.4.6" | |
}, | |
"overrides":{ | |
"bootstrap":{ | |
"main":[ | |
"dist/css/bootstrap.css", | |
"dist/js/bootstrap.js" | |
] | |
} | |
} | |
} |
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
'use strict'; | |
var path = require('path'); | |
var config = {}; | |
config.PROJECT_ROOT = __dirname + '/'; | |
config.PROJECT_SRC = path.join(config.PROJECT_ROOT, 'src/'); | |
config.PROJECT_BUILD = path.join(config.PROJECT_ROOT, 'build/'); | |
config.DIST = path.join(config.PROJECT_ROOT, 'dist'); | |
config.index = { | |
src: config.PROJECT_SRC + 'index.html', | |
dest: config.PROJECT_BUILD + 'index.html' | |
}; | |
config.client = { | |
src: config.PROJECT_SRC, | |
dest: config.PROJECT_BUILD, | |
vendor: config.PROJECT_BUILD + 'vendor/', | |
}; | |
config.coffee = { | |
src: config.PROJECT_SRC + '**/*.coffee', | |
dest: config.PROJECT_BUILD, | |
maps: './maps', | |
}; | |
config.css = { | |
src: [ | |
config.PROJECT_BUILD + 'vendor/**/*.css' | |
] | |
}; | |
config.js = { | |
src: [ | |
config.PROJECT_BUILD + 'vendor/**/*.js', | |
config.PROJECT_BUILD + '**/*.module.js', | |
config.PROJECT_BUILD + '**/*.js', | |
'!' + config.PROJECT_BUILD + '**/*.spec.js', | |
] | |
}; | |
config.bower = { | |
json: require('./bower.json'), | |
directory: config.PROJECT_ROOT + 'bower_components/', | |
ignorePath: '..' | |
}; | |
config.getWiredepDefaultOptions = function() { | |
var options = { | |
bowerJson: config.bower.json, | |
directory: config.bower.directory, | |
ignorePath: config.bower.ignorePath | |
}; | |
return options; | |
}; | |
module.exports = config; |
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 config = require('./gulp.config'); | |
var del = require('del'); | |
var bowerMain = require('bower-main'); | |
var runSequence = require('run-sequence'); | |
var $ = require('gulp-load-plugins')({lazy: true}); | |
gulp.task('help', $.taskListing); | |
gulp.task('default', ['help']); | |
gulp.task('coffee-lint', function() { | |
log("Linting coffeescript source files"); | |
var stylish = require('coffeelint-stylish'); | |
return gulp | |
.src(config.coffee.src) | |
.pipe($.coffeelint()) | |
.pipe($.coffeelint.reporter(stylish)) | |
.pipe($.coffeelint.reporter('fail')); | |
}); | |
gulp.task('coffee', ['coffee-lint'], function() { | |
log("Transpiling coffeescript into javascript"); | |
return gulp | |
.src(config.coffee.src) | |
.pipe($.plumber()) | |
.pipe($.sourcemaps.init()) | |
.pipe($.coffee({bare: true}).on('error', $.util.log)) | |
.pipe($.sourcemaps.write(config.coffee.maps)) | |
.pipe(gulp.dest(config.coffee.dest)); | |
}); | |
gulp.task('clean', function(done) { | |
log('Cleaning: ' + $.util.colors.blue(config.client.dest)); | |
del(config.client.dest, done); | |
}); | |
gulp.task('vendor:js', function() { | |
log('Concat vendor js and place in build folder'); | |
var bowerMainJavaScriptFiles = bowerMain('js','min.js'); | |
return gulp | |
.src(bowerMainJavaScriptFiles.normal) | |
.pipe($.if(args.verbose, $.print())) | |
.pipe($.concat('vendor-scripts.js')) | |
.pipe(gulp.dest(config.client.vendor)) | |
}); | |
gulp.task('vendor:css', function() { | |
log('Concat vendor css and place in build folder'); | |
var bowerMainCSSFiles = bowerMain('css', 'min.css'); | |
return gulp | |
.src(bowerMainCSSFiles.normal) | |
.pipe($.if(args.verbose, $.print())) | |
.pipe($.concat('vendor-styles.css')) | |
.pipe(gulp.dest(config.client.vendor)) | |
}); | |
gulp.task('inject', ['coffee'], function() { | |
log('Wire up the app css and js into the html'); | |
return gulp | |
.src(config.index.src) | |
.pipe($.inject(gulp.src(config.css.src, {read: false}), {ignorePath: ['build']})) | |
.pipe($.inject(gulp.src(config.js.src, {read: false}), {ignorePath: ['build']})) | |
.pipe(gulp.dest(config.client.dest)); | |
}); | |
gulp.task('build', ['clean'], function (cb) { | |
runSequence(['vendor:js', 'vendor:css'], 'inject', cb); | |
}); | |
///////////////////////////////// | |
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
{ | |
"name": "todo", | |
"version": "1.0.0", | |
"description": "Sample todo application", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Jefferson Carley", | |
"license": "MIT", | |
"devDependencies": { | |
"bower-main": "^0.2.14", | |
"coffeelint-stylish": "^0.1.2", | |
"del": "^1.2.0", | |
"gulp": "^3.9.0", | |
"gulp-angular-templatecache": "^1.7.0", | |
"gulp-autoprefixer": "^2.3.1", | |
"gulp-coffee": "^2.3.1", | |
"gulp-coffeelint": "^0.5.0", | |
"gulp-concat": "^2.6.0", | |
"gulp-csso": "^1.0.0", | |
"gulp-filter": "^2.0.2", | |
"gulp-if": "^1.2.5", | |
"gulp-imagemin": "^2.3.0", | |
"gulp-inject": "^1.3.1", | |
"gulp-jscs": "^1.6.0", | |
"gulp-jshint": "^1.11.0", | |
"gulp-load-plugins": "^0.10.0", | |
"gulp-minify-html": "^1.0.3", | |
"gulp-plumber": "^1.0.1", | |
"gulp-print": "^1.1.0", | |
"gulp-sourcemaps": "^1.5.2", | |
"gulp-task-listing": "^1.0.1", | |
"gulp-uglify": "^1.2.0", | |
"gulp-useref": "^1.2.0", | |
"gulp-util": "^3.0.6", | |
"jshint-stylish": "^2.0.1", | |
"run-sequence": "^1.1.1", | |
"wiredep": "^2.2.2", | |
"yargs": "^3.14.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment