var gulp = require('gulp'),
mainBowerFiles = require('main-bower-files'),
inject = require('gulp-inject'),
server = require('gulp-express'),
del = require('del');
var paths = {
temp: '.tmp',
tempVendor: '.tmp/vendor',
tempIndex: '.tmp/views/index.html',
index: 'app/views/index.html',
appSrc: ['app/**/*', '!app/views/index.html'],
bowerSrc: 'bower_components/**/*'
};
gulp.task('default', ['watch']);
gulp.task('watch', ['serve'], function () {
gulp.watch(paths.appSrc, ['scripts']);
gulp.watch(paths.bowerSrc, ['vendors']);
gulp.watch(paths.index, ['copyAll']);
});
gulp.task('serve', ['copyAll'], function () {
server.run(['prod.js']);
});
gulp.task('copyAll', function () {
var vendorFiles = gulp.src(mainBowerFiles()).pipe(gulp.dest(paths.tempVendor));
var appFiles = gulp.src(paths.appSrc).pipe(gulp.dest(paths.temp));
return gulp.src(paths.index)
.pipe(gulp.dest(paths.temp))
.pipe(inject(appFiles, {
relative: true
}))
.pipe(inject(vendorFiles, {
relative: true,
name: 'vendorInject'
}))
.pipe(gulp.dest(paths.temp));
});
gulp.task('vendors', function () {
var tempVendors = gulp.src(mainBowerFiles()).pipe(gulp.dest(paths.tempVendor));
return gulp.src(paths.tempIndex)
.pipe(inject(tempVendors, {
relative: true,
name: 'vendorInject'
}))
.pipe(gulp.dest(paths.temp))
.pipe(server.notify());
});
gulp.task('scripts', function () {
var appFiles = gulp.src(paths.appSrc).pipe(gulp.dest(paths.temp));
return gulp.src(paths.tempIndex)
.pipe(inject(appFiles, {
relative: true
}))
.pipe(gulp.dest(paths.temp))
.pipe(server.notify());
});
gulp.task('clean', function () {
del([paths.temp]);
});
Gulpfile.js