Skip to content

Instantly share code, notes, and snippets.

@kenyonj
Created August 19, 2014 20:04
Show Gist options
  • Save kenyonj/0b340337eaf559209b29 to your computer and use it in GitHub Desktop.
Save kenyonj/0b340337eaf559209b29 to your computer and use it in GitHub Desktop.
var _ = require('lodash'),
concat = require('gulp-concat'),
debug = require('gulp-debug'),
gulp = require('gulp'),
ignore = require('gulp-ignore'),
jshint = require('gulp-jshint'),
karma = require('karma').server,
htmlmin = require('gulp-htmlmin'),
includeSource = require('gulp-include-source'),
minifyCss = require('gulp-minify-css'),
minifyHtml = require('gulp-minify-html'),
mocha = require('gulp-mocha'),
ngtemplates = require('gulp-ngtemplates'),
nodemon = require('gulp-nodemon'),
rev = require('gulp-rev'),
rimraf = require('gulp-rimraf'),
sass = require('gulp-sass'),
uglify = require('gulp-uglify'),
usemin = require('gulp-usemin');
var paths = {
scripts: ['app/assets/javascripts/**/*.js'],
server: {
index: 'server.js',
specs: ['test/models/**/*.js', 'test/features/**/*.js']
},
karma: {
config: 'test/support/karma.conf.js'
},
clean: ['.tmp', 'build'],
assets: {
dest: 'build/assets/',
vendorDest: 'build/assets/vendor/'
},
ngtemplates: {
build: {
js: 'build/assets/javascripts/config/template-cache.js'
}
}
};
var pkg = require('./package.json')
gulp.task('serve', ['prepare', 'watch'], function() {
nodemon({script: paths.server.index});
});
gulp.task('clean', function() {
gulp.src(paths.clean)
.pipe(ignore('node_modules/**'))
.pipe(rimraf({ force: true }));
});
gulp.task('includeSource', function() {
gulp.src('app/views/**/*.html')
.pipe(includeSource({basePath: paths.assets.dest, baseUrl: '/'}))
.pipe(gulp.dest('build/views/'));
});
gulp.task('mochaTest', function() {
gulp.src(paths.server.specs)
.pipe(mocha({reporter: 'spec'}))
});
gulp.task('karmaTest', function(done) {
karma.start(_.assign({}, paths.karma.config), done);
});
gulp.task('concat', function() {
gulp.src(paths.scripts)
.pipe(concat('build.js'))
.pipe(gulp.dest('build'))
});
gulp.task('jshint', function() {
gulp.src(paths.scripts)
.pipe(jshint())
.pipe(jshint.reporter('default'))
});
gulp.task('usemin', function() {
gulp.src('**/*.css')
.pipe(usemin({
css: [minifyCss(), 'concat'],
html: [minifyHtml({empty: true})],
js: [uglify(), rev()]
}))
.pipe(gulp.dest('build'));
});
gulp.task('sass', function() {
gulp.src('app/assets/stylesheets/*.scss')
.pipe(sass({
includePaths: require('node-neat').includePaths
}))
.pipe(gulp.dest('build'));
});
gulp.task('compile-templates', function() {
gulp.src('app/assets/templates/**/*.html')
.pipe(ngtemplates({module: pkg.name, prefix: '/'}))
.pipe(gulp.dest(paths.ngtemplates.build.js));
});
gulp.task('copyAssets', function() {
gulp.src('app/assets/{images,javascripts}/**')
.pipe(gulp.dest(paths.assets.dest));
});
gulp.task('copyVendor', function() {
gulp.src('vendor/**')
.pipe(gulp.dest(paths.assets.vendorDest));
});
gulp.task('copyDist', function() {
gulp.src([
'app/**',
'build/**',
'config/**',
'doc/**',
'server.js',
'vendor/**'
])
.pipe(gulp.dest('dist/'));
});
gulp.task('copyAll', ['copyAssets', 'copyVendor', 'copyDist']);
gulp.task('prepare', [
'clean',
'copyAssets',
'copyVendor',
'compile-templates',
'includeSource',
'sass'
]
);
gulp.task('build', [
'prepare',
'jshint',
'concat',
'usemin'
]
);
gulp.task('watch', function() {
gulp.watch(paths.scripts, ['build']);
});
gulp.task('test', ['karmaTest', 'mochaTest']);
gulp.task('default', ['build', 'test', 'prepare']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment