Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. //*********** IMPORTS *****************
  2. var gulp = require('gulp');
  3. var sass = require('gulp-ruby-sass');
  4. var gutil = require('gulp-util');
  5. var rename = require("gulp-rename");
  6. var map = require("map-stream");
  7. var livereload = require("gulp-livereload");
  8. var concat = require("gulp-concat");
  9. var uglify = require('gulp-uglify');
  10. var watch = require('gulp-watch');
  11. global.errorMessage = '';
  12.  
  13. //Configuration - Change me
  14. var sassFiles = [
  15. {
  16. watch: '_scss/Site/**/*.scss',
  17. sass: '_scss/Site/site.scss',
  18. output: './www/app/View/Themed/Site/webroot/css',
  19. name: 'site.css',
  20. },
  21. {
  22. watch: '_scss/Admin/**/*.scss',
  23. sass: '_scss/Admin/admin.scss',
  24. output: './www/app/View/Themed/Admin/webroot/css',
  25. name: 'admin.min.css',
  26. }
  27. ];
  28. var jsFiles = [
  29. {
  30. watch: '_assets/admin/*.js',
  31. output: './www/app/View/Themed/Admin/webroot/js/',
  32. name: 'admin.js',
  33. nameMin: 'admin.min.js'
  34. },
  35. {
  36. watch: 'html/js/*.js',
  37. output: './www/app/View/Themed/Site/webroot/js/',
  38. name: 'site.js',
  39. nameMin: 'site.min.js'
  40. }
  41. ];
  42. //END configuration
  43.  
  44.  
  45. gulp.task('watch', function () {
  46. for (var i in sassFiles) {
  47. sassWatch(sassFiles[i]);
  48. }
  49.  
  50. for (var j in jsFiles) {
  51. scriptWatch(jsFiles[j]);
  52. }
  53. });
  54.  
  55. function sassWatch(sassData) {
  56. gulp.src(sassData.watch)
  57. .pipe(watch({glob:sassData.watch, emitOnGlob: true}, function() {
  58. gulp.src(sassData.sass)
  59. .pipe(sass(sassOptions))
  60. .on('error', function(err) {
  61. gutil.log(err.message);
  62. gutil.beep();
  63. global.errorMessage = err.message + " ";
  64. })
  65. .pipe(checkErrors())
  66. .pipe(rename(sassData.name))
  67. .pipe(gulp.dest(sassData.output))
  68. .pipe(livereload());
  69. }));
  70. }
  71.  
  72. function scriptWatch(jsData) {
  73. gulp.src(jsData.watch)
  74. .pipe(watch({glob:jsData.watch, emitOnGlob: true}, function() {
  75. gulp.src(jsData.watch)
  76. .pipe(concat(jsData.name))
  77. .pipe(gulp.dest(jsData.output))
  78. .pipe(uglify({outSourceMap: false}))
  79. .pipe(rename(jsData.nameMin))
  80. .pipe(gulp.dest(jsData.output));
  81. }));
  82. }
  83.  
  84. gulp.task('default', ['watch']);
  85.  
  86. /// Defaults yo
  87. var sassOptions = {
  88. 'style': 'compressed',
  89. 'unixNewlines': true,
  90. 'cacheLocation': '_scss/.sass_cache'
  91. };
  92.  
  93. // Does pretty printing of sass errors
  94. var checkErrors = function (obj) {
  95. function checkErrors(file, callback, errorMessage) {
  96. if (file.path.indexOf('.scss') != -1) {
  97. file.contents = new Buffer("\
  98. body * { white-space:pre; }\
  99. body * { display: none!important; }\
  100. body:before {\
  101. white-space:pre;\
  102. content: '"+ global.errorMessage.replace(/(\\)/gm,"/").replace(/(\r\n|\n|\r)/gm,"\\A") +"';\
  103. }\
  104. html{background:#ccf!important; }\
  105. ");
  106. }
  107. callback(null, file);
  108. }
  109. return map(checkErrors);
  110. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement