Skip to content

Commit

Permalink
modify gulpfile with yeoman/generator-angular#1299
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoll committed Jul 7, 2016
1 parent b64d4f4 commit 17bf639
Showing 1 changed file with 64 additions and 40 deletions.
104 changes: 64 additions & 40 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated on 2016-06-14 using generator-angular 0.15.1
// Generated on 2016-03-15 using generator-angular 0.15.1
'use strict';

var gulp = require('gulp');
Expand All @@ -9,28 +9,37 @@ var rimraf = require('rimraf');
var wiredep = require('wiredep').stream;
var runSequence = require('run-sequence');

//app directory structor
var yeoman = {
app: require('./bower.json').appPath || 'app',
dist: 'dist'
dist: 'dist',
temp: '.tmp',
test: 'test'
};

// for sources
var paths = {
scripts: [yeoman.app + '/scripts/**/*.js'],
styles: [yeoman.app + '/styles/**/*.scss'],
test: ['test/spec/**/*.js'],
testRequire: [
yeoman.app + '/bower_components/angular/angular.js',
yeoman.app + '/bower_components/angular-mocks/angular-mocks.js',
yeoman.app + '/bower_components/angular-resource/angular-resource.js',
yeoman.app + '/bower_components/angular-cookies/angular-cookies.js',
yeoman.app + '/bower_components/angular-sanitize/angular-sanitize.js',
yeoman.app + '/bower_components/angular-route/angular-route.js',
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-cookies/angular-cookies.js',
'bower_components/angular-sanitize/angular-sanitize.js',
'bower_components/angular-route/angular-route.js',
'bower_components/angular-animate/angular-animate.js',
'bower_components/angular-touch/angular-touch.js',
'bower_components/angular-ui-sortable/sortable.js',
'bower_components/angular-local-storage/dist/angular-local-storage.js',
'test/mock/**/*.js',
'test/spec/**/*.js'
],
karma: 'karma.conf.js',
karma: yeoman.test + '/karma.conf.js',
views: {
main: yeoman.app + '/index.html',
bowermain: yeoman.temp + '/index.html',
files: [yeoman.app + '/views/**/*.html']
}
};
Expand All @@ -40,16 +49,18 @@ var paths = {
////////////////////////

var lintScripts = lazypipe()
.pipe($.jshint, '.jshintrc')
.pipe($.jshint.reporter, 'jshint-stylish');
.pipe($.jshint) // '.jshintrc'
.pipe($.jshint.reporter,'jshint-stylish' );

var styles = lazypipe()
.pipe($.sass, {
outputStyle: 'expanded',
precision: 10
})
.pipe($.autoprefixer, 'last 1 version')
.pipe(gulp.dest, '.tmp/styles');
.pipe($.autoprefixer, {
browsers:['last 2 version']
})
.pipe(gulp.dest,yeoman.temp + '/styles');

///////////
// Tasks //
Expand All @@ -66,64 +77,74 @@ gulp.task('lint:scripts', function () {
});

gulp.task('clean:tmp', function (cb) {
rimraf('./.tmp', cb);
rimraf(yeoman.temp, cb);
});

gulp.task('start:client', ['start:server', 'styles'], function () {
gulp.task('start:client', ['start:server', 'styles', 'lint:scripts'], function () {
openURL('http://localhost:9000');
});

gulp.task('start:server', function() {
$.connect.server({
root: [yeoman.app, '.tmp'],
livereload: true,
// Change this to '0.0.0.0' to access the server from outside.
port: 9000
root:[yeoman.temp, yeoman.app],
livereload:true,
port: 9000,
middleware:function(connect, opt){
return [['/bower_components',
connect["static"]('./bower_components')]]
}
});
});

gulp.task('start:server:test', function() {
$.connect.server({
root: ['test', yeoman.app, '.tmp'],
root: [yeoman.test, yeoman.app, yeoman.temp],
livereload: true,
port: 9001
port: 9001,
middleware:function(connect, opt){
return [['/bower_components', connect["static"]('./bower_components')]
]}
});
});

gulp.task('watch', function () {
$.watch(paths.styles)
.pipe($.plumber())
.pipe(styles())
.pipe($.connect.reload());
.pipe($.connect.reload())

$.watch(paths.views.files)
.pipe($.plumber())
.pipe($.connect.reload());
.pipe($.connect.reload())

$.watch(paths.scripts)
.pipe($.plumber())
.pipe(lintScripts())
.pipe($.connect.reload());

$.watch(paths.test)
.pipe($.plumber())
.pipe(lintScripts());

gulp.watch('bower.json', ['bower']);
});

gulp.task('serve', function (cb) {
runSequence('clean:tmp',
['bower'],
['lint:scripts'],
['start:client'],
'watch', cb);
});

gulp.task('serve:prod', function() {
$.connect.server({
root: [yeoman.dist],
livereload: true,
port: 9000
root:[yeoman.dist],
livereload:{
port:81
},
port: 80,
middleware:function(connect, opt){
return [['/bower_components', connect["static"]('./bower_components')]
]}
});
});

Expand All @@ -140,35 +161,33 @@ gulp.task('test', ['start:server:test'], function () {
gulp.task('bower', function () {
return gulp.src(paths.views.main)
.pipe(wiredep({
directory: yeoman.app + '/bower_components',
directory: /*yeoman.app +*/ 'bower_components',
ignorePath: '..'
}))
.pipe(gulp.dest(yeoman.app + '/views'));
.pipe(gulp.dest(yeoman.temp));
});

///////////
// Build //
///////////

gulp.task('clean:dist', function (cb) {
rimraf('./dist', cb);
rimraf(yeoman.dist, cb);
});

gulp.task('client:build', ['html', 'styles'], function () {
gulp.task('client:build', ['bower', 'html', 'styles'], function () {
var jsFilter = $.filter('**/*.js');
var cssFilter = $.filter('**/*.css');

return gulp.src(paths.views.main)
.pipe($.useref({searchPath: [yeoman.app, '.tmp']}))
return gulp.src(paths.views.bowermain)
.pipe($.useref({searchPath: [yeoman.app, yeoman.temp]}))
.pipe(jsFilter)
.pipe($.ngAnnotate())
.pipe($.uglify())
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe($.minifyCss({cache: true}))
.pipe(cssFilter.restore())
.pipe($.rev())
.pipe($.revReplace())
.pipe(gulp.dest(yeoman.dist));
});

Expand All @@ -193,12 +212,17 @@ gulp.task('copy:extras', function () {
});

gulp.task('copy:fonts', function () {
return gulp.src(yeoman.app + '/fonts/**/*')
return gulp.src('./bower_components/bootstrap/dist/fonts/**/*')
.pipe(gulp.dest(yeoman.dist + '/fonts'));
});

gulp.task('build', ['clean:dist'], function () {
runSequence(['images', 'copy:extras', 'copy:fonts', 'client:build']);
gulp.task('copy:favicon', function () {
return gulp.src(yeoman.app + '/favicon.ico')
.pipe(gulp.dest(yeoman.dist));
});

gulp.task('build', ['clean:dist', 'bower'], function () {
runSequence(['images', 'copy:extras', 'copy:fonts', 'copy:favicon', 'client:build']);
});

gulp.task('default', ['build']);
gulp.task('default', ['build']);

0 comments on commit 17bf639

Please sign in to comment.