gulpfile.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. var gulp = require('gulp');
  2. var nodemon = require('gulp-nodemon');
  3. var browserSync = require('browser-sync').create();
  4. var jshint = require('gulp-jshint');
  5. var uglify = require('gulp-uglify');
  6. var minifyHTML = require('gulp-minify-html');
  7. var minifycss = require('gulp-minify-css');
  8. var concat = require('gulp-concat');
  9. var del = require('del');
  10. var hintTask = function() {
  11. gulp.src(['*.js', './src/js/**/*.js'])
  12. .pipe(jshint('.jshintrc'))
  13. .pipe(jshint.reporter('jshint-stylish'));
  14. };
  15. gulp.task('hint', function() {
  16. hintTask();
  17. });
  18. var cleanTask = function() {
  19. console.log('CLEAN: Clean Complete');
  20. return del([
  21. 'app/**/*',
  22. '!app/img/',
  23. '!app/css/',
  24. '!app/fonts/',
  25. '!app/js/',
  26. '!app/views/',
  27. '!app/models/',
  28. '!app/controllers/'
  29. ]);
  30. };
  31. gulp.task('clean', function() {
  32. cleanTask();
  33. });
  34. var buildTask = function() {
  35. gulp.src([
  36. './src/css/bootstrap.css',
  37. './src/css/font-awesome.css',
  38. './src/css/main.css'
  39. ])
  40. .pipe(concat('style.min.css'))
  41. .pipe(minifycss())
  42. .pipe(gulp.dest('./app/css'));
  43. gulp.src('./src/img/*')
  44. .pipe(gulp.dest('./app/img'));
  45. gulp.src('./src/fonts/*')
  46. .pipe(gulp.dest('./app/fonts'));
  47. gulp.src([
  48. './src/js/jquery.js',
  49. './src/js/bootstrap.js',
  50. './src/js/bootstrap-datepicker.js',
  51. './src/js/bootstrap-validator.js'
  52. ])
  53. .pipe(concat('lib.min.js'))
  54. .pipe(uglify())
  55. .pipe(gulp.dest('./app/js'));
  56. gulp.src(['./src/js/main.js'])
  57. .pipe(concat('main.min.js'))
  58. .pipe(uglify())
  59. .pipe(gulp.dest('./app/js'));
  60. gulp.src('./src/views/**/*')
  61. .pipe(gulp.dest('./app/views'));
  62. gulp.src('./src/models/**/*')
  63. .pipe(gulp.dest('./app/models'));
  64. gulp.src('./src/controllers/**/*')
  65. .pipe(gulp.dest('./app/controllers'));
  66. console.log('BUILD: Build Complete');
  67. };
  68. gulp.task('build', function() {
  69. buildTask();
  70. });
  71. var watchTask = function() {
  72. gulp.src([
  73. './src/css/bootstrap.css',
  74. './src/css/bootstrap-datepicker.css',
  75. './src/css/font-awesome.css',
  76. './src/css/main.css'
  77. ])
  78. .pipe(concat('style.min.css'))
  79. .pipe(minifycss())
  80. .pipe(gulp.dest('./app/css'));
  81. gulp.src([
  82. './src/js/jquery.js',
  83. './src/js/bootstrap.js',
  84. './src/js/bootstrap-datepicker.js',
  85. './src/js/bootstrap-validator.js'
  86. ])
  87. .pipe(concat('lib.min.js'))
  88. .pipe(uglify())
  89. .pipe(gulp.dest('./app/js'));
  90. gulp.src(['./src/js/main.js'])
  91. .pipe(concat('main.min.js'))
  92. .pipe(uglify())
  93. .pipe(gulp.dest('./app/js'));
  94. gulp.src('./src/models/**/*')
  95. //.pipe(uglify())
  96. .pipe(gulp.dest('./app/models'));
  97. gulp.src('./src/views/**/*')
  98. //.pipe(uglify())
  99. .pipe(gulp.dest('./app/views'));
  100. gulp.src('./src/controllers/**/*')
  101. //.pipe(uglify())
  102. .pipe(gulp.dest('./app/controllers'));
  103. console.log('WATCH: Watch Complete');
  104. };
  105. gulp.task('watch', function() {
  106. watchTask();
  107. });
  108. var syncTask = function() {
  109. browserSync.init({
  110. proxy: {
  111. target: 'https://juryd.macs',
  112. ws: true
  113. },
  114. https: true,
  115. files: ['./src/**/*.*'],
  116. port: 7000,
  117. });
  118. };
  119. gulp.task('sync', function() {
  120. watchTask();
  121. syncTask();
  122. });
  123. var nodemonTask = function() {
  124. nodemon({
  125. tasks: ['watch'],
  126. env: { 'NODE_ENV': 'development' },
  127. script: 'app.js',
  128. verbose: true,
  129. watch: [
  130. './src/',
  131. './models/',
  132. './controllers',
  133. './app.js'
  134. ],
  135. ext: 'js jade hbs html css'
  136. });
  137. };
  138. gulp.task('run', function () {
  139. nodemonTask();
  140. });