Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 KB | None | 0 0
  1. /* Variables */
  2. var gulp = require('gulp'),
  3. jshint = require('gulp-jshint'),
  4. jsmin = require('gulp-jsmin'),
  5. uglify = require('gulp-uglify'),
  6. rename = require('gulp-rename'),
  7. concat = require('gulp-concat'),
  8. notify = require('gulp-notify'),
  9. imagemin = require('gulp-imagemin'),
  10. del = require('del'),
  11. connect = require('gulp-connect'),
  12. uglifycss = require('gulp-uglifycss'),
  13. csslint = require('gulp-csslint'),
  14. zip = require("gulp-zip"),
  15. concatCss = require('gulp-concat-css'),
  16. autoprefixer = require('gulp-autoprefixer'),
  17. gutil = require('gulp-util'),
  18. gulpif = require('gulp-if')
  19. // livereload = require('gulp-livereload'),
  20. // jade = require('gulp-jade'),
  21. // less = require('gulp-less'),
  22. // sass = require('gulp-sass')
  23. // historyApiFallback = require('connect-history-api-fallback')
  24. ;
  25.  
  26. var shouldMinify = true; showReports = false;
  27.  
  28. var paths = {
  29. dev: [
  30. 'wp-content/themes/entelperu/dev/css/*.css',
  31. 'wp-content/themes/entelperu/dev/js/*.js',
  32. 'wp-content/themes/entelperu/dev/images/**/*.*'
  33. ],
  34. prod: [
  35. 'wp-content/themes/entelperu/css',
  36. 'wp-content/themes/entelperu/js',
  37. 'wp-content/themes/entelperu/images'
  38. ],
  39. cleaned: [
  40. 'wp-content/themes/entelperu/css/*.*',
  41. 'wp-content/themes/entelperu/js/*.*',
  42. 'wp-content/themes/entelperu/images/**/*.*'
  43. ],
  44. backups: [
  45. 'wp-content/themes/entelperu/css/*.*',
  46. 'wp-content/themes/entelperu/js/*.*',
  47. 'wp-content/themes/entelperu/images/**/*.*'
  48. ]
  49. };
  50.  
  51. var customReporter = function(file) {
  52. gutil.log(gutil.colors.cyan(file.csslint.errorCount)+' errors in '+gutil.colors.magenta(file.path));
  53.  
  54. file.csslint.results.forEach(function(result) {
  55. gutil.log(result.error.message+' on line '+result.error.line);
  56. });
  57. };
  58.  
  59. gulp.task('buildImg', ['buildCss'], function (cb) {
  60. return gulp.start("img");
  61. });
  62.  
  63. gulp.task('img', function (cb) {
  64. return gulp
  65. .src([paths.dev[2]])
  66. .pipe(
  67. gulpif(shouldMinify, imagemin())
  68. )
  69. .pipe(gulp.dest(paths.prod[2]));
  70. // .pipe(notify({ message: 'Images task complete' }))
  71. cb(null)
  72. });
  73.  
  74. // gulp.task('buildSass', function (cb) {
  75. // return gulp
  76. // .src([paths.dev[0]])
  77. // .pipe(sass())
  78. // .pipe(gulp.dest('../wp-content/themes/entelperu/dist/css'))
  79. // cb(null)
  80. // });
  81.  
  82. gulp.task('buildCss', ['clean'], function (cb) {
  83. return gulp.start("css");
  84. });
  85.  
  86. gulp.task('css', function (cb) {
  87. return gulp.src(paths.dev[0])
  88. .pipe(
  89. autoprefixer(
  90. 'last 2 version',
  91. 'safari 5',
  92. 'ie 8',
  93. 'ie 9',
  94. 'opera 12.1',
  95. 'ios 6',
  96. 'android 4'
  97. )
  98. )
  99. .pipe(
  100. gulpif(shouldMinify,
  101. uglifycss({
  102. 'max-line-len': 20
  103. })
  104. )
  105. )
  106. .pipe(csslint())
  107. .pipe(
  108. gulpif(showReports, csslint.reporter(customReporter))
  109. )
  110. .pipe(rename({suffix: '.min'}))
  111. .pipe(gulp.dest(paths.prod[0]));
  112. // .pipe(notify({ message: 'Images task complete' }));
  113. });
  114.  
  115. gulp.task('buildJs', ['buildImg'], function (cb) {
  116. return gulp.start("js");
  117. });
  118.  
  119. gulp.task('js', function (cb) {
  120. return gulp.src([paths.dev[1]])
  121. .pipe(
  122. gulpif(shouldMinify, uglify())
  123. ) /* Compresor del JS #1 */
  124. .pipe(jsmin()) /* Compresor del JS #2 */
  125. .pipe(
  126. gulpif(showReports, jshint())
  127. ) /* Reporte del JS */
  128. // .pipe(concat('app.js'))
  129. .pipe(rename({suffix: '.min'}))
  130. .pipe(gulp.dest(paths.prod[1]));
  131. // .pipe(notify({ message: 'Scripts task complete' }));
  132. });
  133.  
  134. gulp.task('clean', ['backup'], function (cb) {
  135. return del(paths.cleaned, cb);
  136. });
  137.  
  138. /* Init GulpServer PROD */
  139. gulp.task('default', function() {
  140. shouldMinify = true;
  141. showReports = false;
  142. return gulp.start("init");
  143. });
  144.  
  145. /* Init GulpServer DEV */
  146. gulp.task('dev', function() {
  147. shouldMinify = false;
  148. showReports = true;
  149. return gulp.start("init");
  150. });
  151.  
  152. /* Init Tasks */
  153. gulp.task('init', function() {
  154. return gulp
  155. .start("buildJs");
  156. });
  157.  
  158. /* Cambio de archivos */
  159. gulp.task('watch', function() {
  160. gulp.watch(paths.dev[2], ['img']);
  161. gulp.watch(paths.dev[0], ['css']);
  162. gulp.watch(paths.dev[1], ['js']);
  163. });
  164.  
  165. /* Compress Files CSS, JS and Images to .zip */
  166. gulp.task('backup', function(){
  167. var date = new Date().toISOString().replace(/[^0-9]/g, '');
  168.  
  169. return gulp.src(paths.backups, {base: "wp-content/themes/entelperu"})
  170. .pipe(zip("package-" + date + ".zip"))
  171. .pipe(gulp.dest("backups"))
  172. .pipe(notify({ message: 'Backup task complete' }));
  173. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement