Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // imports
- var gulp = require('gulp');
- var concat = require('gulp-concat');
- var uglify = require('gulp-uglify');
- var sass = require('gulp-ruby-sass');
- var rename = require('gulp-rename');
- var sourcemaps = require('gulp-sourcemaps');
- var spritesmith = require('gulp.spritesmith');
- var minifyCSS = require('gulp-minify-css');
- var source = require('vinyl-source-stream');
- var vinylBuffer = require('vinyl-buffer');
- var burn = require('burn');
- var fs = require('fs');
- var stream = require('stream');
- var path = require('path');
- //////////////////////////////////////////////////////
- // BUILD CONFIG
- //////////////////////////////////////////////////////
- // Ref current location
- var current_path = path.join(path.dirname(fs.realpathSync(__filename)));
- var js_path = path.join(current_path, 'js');
- var scss_path = path.join(current_path, 'scss');
- var build_path = './build/';
- var font_files = [
- './fonts/**/fonts/*.*',
- ]
- var sass_files = [
- './scss/entry.scss',
- './fonts/**/*.css'
- ]
- var sprite_files = [
- './images/**/*.png'
- ]
- var js_modules = [
- {src: 'plugins/assert.js', name: 'assert'},
- {src: 'plugins/grouper.js', name: 'grouper'},
- {src: 'plugins/helpers.js', name: 'helpers'},
- {src: 'plugins/jquery-1.11.1.js', name: 'jquery'},
- {src: 'plugins/jquery.caret.js', name: 'jquery.caret'},
- {src: 'plugins/jquery.creditCardValidator.js', name: 'jquery.creditCardValidator'},
- {src: 'plugins/jquery.easyModal.js', name: 'jquery.easyModal'},
- {src: 'plugins/jquery.inputSanitizer.js', name: 'jquery.inputSanitizer'},
- {src: 'plugins/jquery.vide.js', name: 'jquery.vide'},
- {src: 'plugins/modernizr-2.8.3.js', name: 'modernizr'},
- {src: 'plugins/sprintf-1.0.0.js', name: 'sprintf'},
- {src: 'plugins/stapes-0.8.1.js', name: 'stapes'},
- {src: 'plugins/parsley-2.0.5.js', name: 'parsley'},
- {src: 'plugins/parsley-2.0.5.remote.js', name: 'parsley.remote'},
- {src: 'plugins/parsley.validators.js', name: 'parsley.validators'},
- //{src: 'plugins/swig-1.4.2.js', name: 'swig'},
- {src: 'modules/module.bookingmodal.js', name: 'module.bookingmodal'},
- {src: 'modules/page.pricing.js', name: 'page.pricing'},
- {src: 'modules/page.booking.js', name: 'page.booking'},
- ]
- var js_assets = [
- {src: '../../settings/config.json', name: 'config'}
- ];
- var js_entry = ['entry.js'];
- //////////////////////////////////////////////////////
- var spawn = require('child_process').spawn;
- var p;
- // http://vena.net/post/92094401640/reload-gulp-when-gulpfile-js-changes
- var spawn = require('child_process').spawn;
- gulp.task('default', function() {
- if(p) { p.kill(); }
- // Note: The 'watch' is the new name of your normally-default gulp task. Substitute if needed.
- p = spawn('gulp', ['watch'], {stdio: 'inherit'});
- });
- // helper function for creating pipes
- var createPipeFromString = function(name, value) {
- var stream = source(name);
- stream.write(value);
- //stream.write(null);
- stream.end();
- return stream.pipe(vinylBuffer());
- }
- gulp.task('compile', ['scripts', 'fonts', 'siteCSS']);
- gulp.task('watch', ['scripts', 'fonts', 'siteCSS'], function() {
- gulp.watch('gulpfile.js', ['default'])
- .on('change', function(event) {
- console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
- });
- gulp.watch(['js/**/*.js', '../settings/config.json'], { interval: 1000 }, ['scripts', ])
- .on('change', function(event) {
- console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
- });
- gulp.watch(['scss/**/*.scss', '!scss/bourbon/**/*', '!scss/neat/**/*'], { interval: 1000 }, ['siteCSS', ])
- .on('change', function(event) {
- console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
- });
- gulp.watch(font_files, { interval: 1000 }, ['fonts', ])
- .on('change', function(event) {
- console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
- });
- gulp.watch(sprite_files, { interval: 1000 }, ['siteCSS', ])
- .on('change', function(event) {
- console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
- });
- });
- gulp.task('sprite', function () {
- return gulp.src(sprite_files)
- .pipe(spritesmith({
- imgName: 'sprite.png',
- cssName: '_sprite.css',
- engine: 'gm',
- 'cssOpts': {
- 'functions': false,
- 'cssClass': function (item) {
- return '.sprite-' + item.name;
- }
- }
- }))
- .pipe(gulp.dest('./build/'));
- });
- gulp.task('siteCSS', ['sprite', 'styles'], function() {
- return gulp.src(['./build/_styles.css', './build/_sprite.css'])
- .pipe(minifyCSS({
- 'keepSpecialComments' : 0
- }))
- .pipe(concat('site.css'))
- .pipe(rename({dirname: ''}))
- .pipe(gulp.dest(build_path));
- });
- gulp.task('fonts', [], function() {
- return gulp.src(font_files)
- .pipe(rename({dirname: 'fonts/'}))
- .pipe(gulp.dest(build_path));
- })
- gulp.task('styles', [], function() {
- // sourcemaps disabled due to size
- return gulp.src(sass_files)
- //.pipe(sourcemaps.init())
- .pipe(sass())
- .pipe(concat('_styles.css'))
- //.pipe(sourcemaps.write())
- .pipe(gulp.dest(build_path));
- });
- gulp.task('scripts', [], function() {
- // read all js files, this is not async, sorry
- var resp = burn.compile({
- 'modules': js_modules,
- 'baseDir': js_path,
- 'assets': js_assets,
- 'entry': js_entry
- });
- // sourcemaps disabled due to size
- var js_content = createPipeFromString('site.js', resp.result);
- return js_content
- //.pipe(sourcemaps.init())
- //.pipe(sourcemaps.write())
- .pipe(gulp.dest(build_path))
- .pipe(uglify())
- .pipe(concat('site.min.js'))
- .pipe(gulp.dest(build_path))
- /*
- // Minify and copy all JavaScript (except vendor scripts)
- // with sourcemaps all the way down
- return gulp.src(paths.scripts)
- .pipe(sourcemaps.init())
- .pipe(coffee())
- .pipe(uglify())
- .pipe(concat('all.min.js'))
- .pipe(sourcemaps.write())
- .pipe(gulp.dest('build/js'));
- */
- });
Advertisement
Add Comment
Please, Sign In to add comment