Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. var gulp = require('gulp');
  4. var $ = require('gulp-load-plugins')();
  5. var openURL = require('open');
  6. var lazypipe = require('lazypipe');
  7. var rimraf = require('rimraf');
  8. var wiredep = require('wiredep').stream;
  9. var runSequence = require('run-sequence');
  10.  
  11. var yeoman = {
  12.   src: 'src',
  13.   dist: 'dist',
  14.   demo: 'demo'
  15. };
  16.  
  17. var paths = {
  18.   scripts: [yeoman.src + '/**/*.js'],
  19.   styles: [yeoman.src + '/**/*.scss'],
  20.   templates: [yeoman.src + '/**/*.html'],
  21.   test: ['test/spec/**/*.js'],
  22.   testRequire: [
  23.     yeoman.src + '/bower_components/angular/angular.js',
  24.     yeoman.src + '/bower_components/angular-mocks/angular-mocks.js',
  25.     yeoman.src + '/bower_components/angular-resource/angular-resource.js',
  26.     'test/mock/**/*.js',
  27.     'test/spec/**/*.js'
  28.   ],
  29.   karma: 'karma.conf.js',
  30.   view: yeoman.demo + '/index.html'
  31. };
  32.  
  33. // Reusable pipelines
  34. // --------------------------------------------------------
  35.  
  36. var lintScripts = lazypipe()
  37.     .pipe($.jshint, '.jshintrc')
  38.     .pipe($.jshint.reporter, 'jshint-stylish');
  39.  
  40. var styles = lazypipe()
  41.     .pipe($.sass, {
  42.         outputStyle: 'expanded',
  43.         precision: 10
  44.     })
  45.     .pipe($.autoprefixer, 'last 1 version')
  46.     .pipe(gulp.dest, '.tmp/styles');
  47.  
  48. var build = lazypipe()
  49.     .pipe($.sourcemaps.init)
  50.     .pipe($.ngAnnotate)
  51.     .pipe($.concat, 'jdm-loading-indicator.js')
  52.     .pipe(gulp.dest, yeoman.dist + '/js')
  53.     .pipe($.uglify)
  54.     .pipe($.rename, 'jdm-loading-indicator.min.js')
  55.     .pipe($.sourcemaps.write, './')
  56.     .pipe(gulp.dest, yeoman.dist + '/js');
  57.  
  58. // Tasks
  59. // --------------------------------------------------------
  60.  
  61.  
  62. gulp.task('default', ['build']);
  63.  
  64. gulp.task('serve', serveTask);
  65. gulp.task('serve:prod', serveProdTask);
  66.  
  67. gulp.task('lint:scripts', lintScriptsTask);
  68. gulp.task('clean:tmp', cleanTempTask);
  69.  
  70. gulp.task('start:client', ['start:server'], startClientTask);
  71. gulp.task('start:server', startServerTask);
  72.  
  73. gulp.task('test', ['start:server:test'], testTask);
  74. gulp.task('start:server:test', startServerTestTask);
  75.  
  76. gulp.task('watch', ['build'], watchTask);
  77. gulp.task('client:build', clientBuildTask);
  78. gulp.task('build', ['clean:dist', 'compass', 'cacheTemplates'], buildTask);
  79. gulp.task('clean:dist', cleanDistTask);
  80.  
  81. gulp.task('bower', bowerTask);
  82. gulp.task('compass', compassTask);
  83. gulp.task('cacheTemplates', cacheTemplates);
  84.  
  85. // Task Implementation
  86. // --------------------------------------------------------
  87.  
  88. function lintScriptsTask() {
  89.     return gulp.src(paths.scripts)
  90.         .pipe(lintScripts());
  91. }
  92.  
  93. function cleanTempTask(cb) {
  94.     rimraf('./.tmp', cb);  
  95. }
  96.  
  97. function startClientTask() {
  98.   openURL('http://localhost:9000');
  99. }
  100.  
  101. function startServerTask() {
  102.   $.connect.server({
  103.     root: [yeoman.demo, yeoman.dist],
  104.     livereload: true,
  105.     // Change this to '0.0.0.0' to access the server from outside.
  106.     port: 9000
  107.   });
  108. }
  109.  
  110. function startServerTestTask() {
  111.   $.connect.server({
  112.     root: ['test', yeoman.demo],
  113.     livereload: true,
  114.     port: 9001
  115.   });
  116. }
  117.  
  118. function watchTask() {
  119.     $.watch(paths.scripts, $.batch(function (events, done) {
  120.         gulp.start('build', done);
  121.     }));
  122.    
  123.     $.watch(paths.templates, $.batch(function (events, done) {
  124.         gulp.start('cacheTemplates', done);
  125.     }));
  126.        
  127.     $.watch(paths.scripts)
  128.         .pipe($.plumber())
  129.         .pipe(lintScripts())    
  130.     //  .pipe($.connect.reload());
  131.  
  132.     $.watch(paths.test)
  133.       .pipe($.plumber())
  134.       .pipe(lintScripts());
  135.  
  136.     gulp.watch('bower.json', ['bower']);
  137. }
  138.  
  139. function serveTask(cb) {
  140.   runSequence('clean:tmp',
  141.     ['lint:scripts'],
  142.     ['start:client'],
  143.     'watch', cb);
  144. }
  145.  
  146. function serveProdTask() {
  147.   $.connect.server({
  148.     root: [yeoman.dist],
  149.     livereload: true,
  150.     port: 9000
  151.   });  
  152. }
  153.  
  154. function testTask() {
  155.   var testToFiles = paths.testRequire.concat(paths.scripts, paths.test);
  156.   return gulp.src(testToFiles)
  157.     .pipe($.karma({
  158.       configFile: paths.karma,
  159.       action: 'watch'
  160.     }));
  161. }
  162.  
  163. function bowerTask() {
  164.     return gulp.src(paths.view)
  165.         .pipe(wiredep({
  166.             directory: yeoman.demo + '/bower_components',
  167.             ignorePath: '..'
  168.         }))
  169.         .pipe(gulp.dest(yeoman.demo));
  170. }
  171.  
  172. function cleanDistTask(cb) {
  173.     rimraf('./dist', cb);
  174. }
  175.  
  176. function clientBuildTask() {
  177.     return gulp.src(paths.scripts)
  178.         .pipe(build());
  179. }
  180.  
  181. function buildTask() {
  182.     runSequence(['client:build']);
  183. }
  184.  
  185. function compassTask() {
  186.     return gulp.src('./src/*.scss')
  187.         .pipe($.plumber())
  188.         .pipe($.compass({
  189.             css: yeoman.dist + '/css',
  190.             sass: yeoman.src + '/scss'
  191.         }))
  192.         //.pipe(minifyCSS())
  193.         .pipe(gulp.dest(yeoman.dist));
  194. }
  195.  
  196. function cacheTemplates() {
  197.     return gulp.src(paths.templates)
  198.         .pipe($.angularTemplatecache({
  199.             module: 'jdm.loadingIndicator'
  200.         }))
  201.         .pipe(gulp.dest(yeoman.dist));
  202. }
  203.  
  204. //gulp.task('client:build', ['html', 'styles'], function () {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement