SHARE
TWEET

gulpfile.js

VishnuAVenu Jan 8th, 2016 14 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Generated on 2016-01-08 using generator-angular 0.15.1
  2. 'use strict';
  3.  
  4. var gulp = require('gulp');
  5. var $ = require('gulp-load-plugins')();
  6. var openURL = require('open');
  7. var lazypipe = require('lazypipe');
  8. var rimraf = require('rimraf');
  9. var wiredep = require('wiredep').stream;
  10. var runSequence = require('run-sequence');
  11.  
  12. var yeoman = {
  13.   app: require('./bower.json').appPath || 'app',
  14.   dist: 'dist'
  15. };
  16.  
  17. var paths = {
  18.   scripts: [yeoman.app + '/scripts/**/*.js'],
  19.   styles: [yeoman.app + '/styles/**/*.css'],
  20.   test: ['test/spec/**/*.js'],
  21.   testRequire: [
  22.     yeoman.app + '/bower_components/angular/angular.js',
  23.     yeoman.app + '/bower_components/angular-mocks/angular-mocks.js',
  24.     yeoman.app + '/bower_components/angular-resource/angular-resource.js',
  25.     yeoman.app + '/bower_components/angular-cookies/angular-cookies.js',
  26.     yeoman.app + '/bower_components/angular-sanitize/angular-sanitize.js',
  27.     yeoman.app + '/bower_components/angular-route/angular-route.js',
  28.     'test/mock/**/*.js',
  29.     'test/spec/**/*.js'
  30.   ],
  31.   karma: 'karma.conf.js',
  32.   views: {
  33.     main: yeoman.app + '/index.html',
  34.     files: [yeoman.app + '/views/**/*.html']
  35.   }
  36. };
  37.  
  38. ////////////////////////
  39. // Reusable pipelines //
  40. ////////////////////////
  41.  
  42. var lintScripts = lazypipe()
  43.   .pipe($.jshint, '.jshintrc')
  44.   .pipe($.jshint.reporter, 'jshint-stylish');
  45.  
  46. var styles = lazypipe()
  47.   .pipe($.autoprefixer, 'last 1 version')
  48.   .pipe(gulp.dest, '.tmp/styles');
  49.  
  50. ///////////
  51. // Tasks //
  52. ///////////
  53.  
  54.  
  55. gulp.task('styles', function () {
  56.   return gulp.src(paths.styles)
  57.     .pipe(styles());
  58. });
  59.  
  60. gulp.task('lint:scripts', function () {
  61.   return gulp.src(paths.scripts)
  62.     .pipe(lintScripts());
  63. });
  64.  
  65. gulp.task('clean:tmp', function (cb) {
  66.   rimraf('./.tmp', cb);
  67. });
  68.  
  69. gulp.task('start:client', ['start:server', 'styles'], function () {
  70.   openURL('http://localhost:9000');
  71. });
  72.  
  73. gulp.task('start:server', function() {
  74.   $.connect.server({
  75.     root: [yeoman.app, 'bower_components','.tmp'],
  76.     livereload: true,
  77.     // Change this to '0.0.0.0' to access the server from outside.
  78.     port: 9000
  79.   });
  80. });
  81.  
  82. gulp.task('start:server:test', function() {
  83.   $.connect.server({
  84.     root: ['test', yeoman.app, '.tmp'],
  85.     livereload: true,
  86.     port: 9001
  87.   });
  88. });
  89.  
  90. gulp.task('watch', function () {
  91.   $.watch(paths.styles)
  92.     .pipe($.plumber())
  93.     .pipe(styles())
  94.     .pipe($.connect.reload());
  95.  
  96.   $.watch(paths.views.files)
  97.     .pipe($.plumber())
  98.     .pipe($.connect.reload());
  99.  
  100.   $.watch(paths.scripts)
  101.     .pipe($.plumber())
  102.     .pipe(lintScripts())
  103.     .pipe($.connect.reload());
  104.  
  105.   $.watch(paths.test)
  106.     .pipe($.plumber())
  107.     .pipe(lintScripts());
  108.  
  109.   gulp.watch('bower.json', ['bower']);
  110. });
  111.  
  112. gulp.task('serve', function (cb) {
  113.   runSequence('clean:tmp',
  114.     ['lint:scripts'],
  115.     ['start:client'],
  116.     'watch', cb);
  117. });
  118.  
  119. gulp.task('serve:prod', function() {
  120.   $.connect.server({
  121.     root: [yeoman.dist],
  122.     livereload: true,
  123.     port: 9000
  124.   });
  125. });
  126.  
  127. gulp.task('test', ['start:server:test'], function () {
  128.   var testToFiles = paths.testRequire.concat(paths.scripts, paths.test);
  129.   return gulp.src(testToFiles)
  130.     .pipe($.karma({
  131.       configFile: paths.karma,
  132.       action: 'watch'
  133.     }));
  134. });
  135.  
  136. // inject bower components
  137. gulp.task('bower', function () {
  138.   return gulp.src(paths.views.main)
  139.     .pipe(wiredep({
  140.       directory: 'bower_components',
  141.       ignorePath: '..'
  142.     }))
  143.   .pipe(gulp.dest(yeoman.app + '/views'));
  144. });
  145.  
  146. ///////////
  147. // Build //
  148. ///////////
  149.  
  150. gulp.task('clean:dist', function (cb) {
  151.   rimraf('./dist', cb);
  152. });
  153.  
  154. gulp.task('client:build', ['html', 'styles'], function () {
  155.   var jsFilter = $.filter('**/*.js');
  156.   var cssFilter = $.filter('**/*.css');
  157.  
  158.   return gulp.src(paths.views.main)
  159.     .pipe($.useref({searchPath: [yeoman.app, '.tmp']}))
  160.     .pipe(jsFilter)
  161.     .pipe($.ngAnnotate())
  162.     .pipe($.uglify())
  163.     .pipe(jsFilter.restore())
  164.     .pipe(cssFilter)
  165.     .pipe($.minifyCss({cache: true}))
  166.     .pipe(cssFilter.restore())
  167.     .pipe($.rev())
  168.     .pipe($.revReplace())
  169.     .pipe(gulp.dest(yeoman.dist));
  170. });
  171.  
  172. gulp.task('html', function () {
  173.   return gulp.src(yeoman.app + '/views/**/*')
  174.     .pipe(gulp.dest(yeoman.dist + '/views'));
  175. });
  176.  
  177. gulp.task('images', function () {
  178.   return gulp.src(yeoman.app + '/images/**/*')
  179.     .pipe($.cache($.imagemin({
  180.         optimizationLevel: 5,
  181.         progressive: true,
  182.         interlaced: true
  183.     })))
  184.     .pipe(gulp.dest(yeoman.dist + '/images'));
  185. });
  186.  
  187. gulp.task('copy:extras', function () {
  188.   return gulp.src(yeoman.app + '/*/.*', { dot: true })
  189.     .pipe(gulp.dest(yeoman.dist));
  190. });
  191.  
  192. gulp.task('copy:fonts', function () {
  193.   return gulp.src(yeoman.app + '/fonts/**/*')
  194.     .pipe(gulp.dest(yeoman.dist + '/fonts'));
  195. });
  196.  
  197. gulp.task('build', ['clean:dist'], function () {
  198.   runSequence(['images', 'copy:extras', 'copy:fonts', 'client:build']);
  199. });
  200.  
  201. gulp.task('default', ['build']);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top