Guest User

Untitled

a guest
Nov 14th, 2014
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // imports
  2. var gulp = require('gulp');
  3. var concat = require('gulp-concat');
  4. var uglify = require('gulp-uglify');
  5. var sass = require('gulp-ruby-sass');
  6. var rename = require('gulp-rename');
  7. var sourcemaps = require('gulp-sourcemaps');
  8. var spritesmith = require('gulp.spritesmith');
  9. var minifyCSS = require('gulp-minify-css');
  10. var source = require('vinyl-source-stream');
  11. var vinylBuffer = require('vinyl-buffer');
  12. var burn = require('burn');
  13. var fs = require('fs');
  14. var stream = require('stream');
  15. var path = require('path');
  16.  
  17. //////////////////////////////////////////////////////
  18. // BUILD CONFIG
  19. //////////////////////////////////////////////////////
  20.  
  21. // Ref current location
  22. var current_path = path.join(path.dirname(fs.realpathSync(__filename)));
  23. var js_path = path.join(current_path, 'js');
  24. var scss_path = path.join(current_path, 'scss');
  25.  
  26. var build_path = './build/';
  27.  
  28. var font_files = [
  29.   './fonts/**/fonts/*.*',
  30. ]
  31.  
  32. var sass_files = [
  33.   './scss/entry.scss',
  34.   './fonts/**/*.css'
  35. ]
  36.  
  37. var sprite_files = [
  38.   './images/**/*.png'
  39. ]
  40.  
  41. var js_modules = [
  42.   {src: 'plugins/assert.js', name: 'assert'},
  43.   {src: 'plugins/grouper.js', name: 'grouper'},
  44.   {src: 'plugins/helpers.js', name: 'helpers'},
  45.  
  46.   {src: 'plugins/jquery-1.11.1.js', name: 'jquery'},
  47.   {src: 'plugins/jquery.caret.js', name: 'jquery.caret'},
  48.   {src: 'plugins/jquery.creditCardValidator.js', name: 'jquery.creditCardValidator'},
  49.   {src: 'plugins/jquery.easyModal.js', name: 'jquery.easyModal'},
  50.   {src: 'plugins/jquery.inputSanitizer.js', name: 'jquery.inputSanitizer'},
  51.   {src: 'plugins/jquery.vide.js', name: 'jquery.vide'},
  52.  
  53.   {src: 'plugins/modernizr-2.8.3.js', name: 'modernizr'},
  54.   {src: 'plugins/sprintf-1.0.0.js', name: 'sprintf'},
  55.   {src: 'plugins/stapes-0.8.1.js', name: 'stapes'},
  56.  
  57.   {src: 'plugins/parsley-2.0.5.js', name: 'parsley'},
  58.   {src: 'plugins/parsley-2.0.5.remote.js', name: 'parsley.remote'},
  59.   {src: 'plugins/parsley.validators.js', name: 'parsley.validators'},
  60.   //{src: 'plugins/swig-1.4.2.js', name: 'swig'},
  61.  
  62.   {src: 'modules/module.bookingmodal.js', name: 'module.bookingmodal'},
  63.   {src: 'modules/page.pricing.js', name: 'page.pricing'},
  64.   {src: 'modules/page.booking.js', name: 'page.booking'},
  65. ]
  66.  
  67. var js_assets = [
  68.   {src: '../../settings/config.json', name: 'config'}
  69. ];
  70.  
  71. var js_entry = ['entry.js'];
  72.  
  73. //////////////////////////////////////////////////////
  74.  
  75. var spawn = require('child_process').spawn;
  76. var p;
  77.  
  78.  
  79. // http://vena.net/post/92094401640/reload-gulp-when-gulpfile-js-changes
  80. var spawn = require('child_process').spawn;
  81. gulp.task('default', function() {
  82.   if(p) { p.kill(); }
  83.   // Note: The 'watch' is the new name of your normally-default gulp task. Substitute if needed.
  84.   p = spawn('gulp', ['watch'], {stdio: 'inherit'});
  85. });
  86.  
  87. // helper function for creating pipes
  88. var createPipeFromString = function(name, value) {
  89.   var stream = source(name);
  90.   stream.write(value);
  91.   //stream.write(null);
  92.   stream.end();
  93.   return stream.pipe(vinylBuffer());
  94. }
  95.  
  96. gulp.task('compile', ['scripts', 'fonts', 'siteCSS']);
  97.  
  98. gulp.task('watch', ['scripts', 'fonts', 'siteCSS'], function() {
  99.   gulp.watch('gulpfile.js', ['default'])
  100.     .on('change', function(event) {
  101.       console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
  102.     });
  103.  
  104.   gulp.watch(['js/**/*.js', '../settings/config.json'], { interval: 1000 }, ['scripts', ])
  105.     .on('change', function(event) {
  106.       console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
  107.     });
  108.  
  109.   gulp.watch(['scss/**/*.scss', '!scss/bourbon/**/*', '!scss/neat/**/*'], { interval: 1000 }, ['siteCSS', ])
  110.     .on('change', function(event) {
  111.       console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
  112.     });
  113.  
  114.   gulp.watch(font_files, { interval: 1000 }, ['fonts', ])
  115.     .on('change', function(event) {
  116.       console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
  117.     });
  118.  
  119.   gulp.watch(sprite_files, { interval: 1000 }, ['siteCSS', ])
  120.     .on('change', function(event) {
  121.       console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
  122.     });
  123. });
  124.  
  125. gulp.task('sprite', function () {
  126.   return gulp.src(sprite_files)
  127.     .pipe(spritesmith({
  128.       imgName: 'sprite.png',
  129.       cssName: '_sprite.css',
  130.       engine: 'gm',
  131.       'cssOpts': {
  132.         'functions': false,
  133.         'cssClass': function (item) {
  134.           return '.sprite-' + item.name;
  135.         }
  136.       }
  137.     }))
  138.     .pipe(gulp.dest('./build/'));
  139. });
  140.  
  141. gulp.task('siteCSS', ['sprite', 'styles'], function() {
  142.   return gulp.src(['./build/_styles.css', './build/_sprite.css'])
  143.     .pipe(minifyCSS({
  144.       'keepSpecialComments' : 0
  145.     }))
  146.     .pipe(concat('site.css'))
  147.     .pipe(rename({dirname: ''}))
  148.     .pipe(gulp.dest(build_path));
  149. });
  150.  
  151. gulp.task('fonts', [], function() {
  152.   return gulp.src(font_files)
  153.     .pipe(rename({dirname: 'fonts/'}))
  154.     .pipe(gulp.dest(build_path));
  155. })
  156.  
  157. gulp.task('styles', [], function() {
  158.   // sourcemaps disabled due to size
  159.   return gulp.src(sass_files)
  160.     //.pipe(sourcemaps.init())
  161.     .pipe(sass())
  162.     .pipe(concat('_styles.css'))
  163.     //.pipe(sourcemaps.write())
  164.     .pipe(gulp.dest(build_path));
  165. });
  166.  
  167. gulp.task('scripts', [], function() {
  168.   // read all js files, this is not async, sorry
  169.   var resp = burn.compile({
  170.     'modules': js_modules,
  171.     'baseDir': js_path,
  172.     'assets': js_assets,
  173.     'entry': js_entry
  174.   });
  175.  
  176.   // sourcemaps disabled due to size
  177.   var js_content = createPipeFromString('site.js', resp.result);
  178.   return js_content
  179.     //.pipe(sourcemaps.init())
  180.     //.pipe(sourcemaps.write())
  181.     .pipe(gulp.dest(build_path))
  182.     .pipe(uglify())
  183.     .pipe(concat('site.min.js'))
  184.     .pipe(gulp.dest(build_path))
  185.  
  186.   /*
  187.   // Minify and copy all JavaScript (except vendor scripts)
  188.   // with sourcemaps all the way down
  189.   return gulp.src(paths.scripts)
  190.     .pipe(sourcemaps.init())
  191.       .pipe(coffee())
  192.       .pipe(uglify())
  193.       .pipe(concat('all.min.js'))
  194.     .pipe(sourcemaps.write())
  195.     .pipe(gulp.dest('build/js'));
  196.   */
  197. });
Advertisement
Add Comment
Please, Sign In to add comment