<commit_before>/*
 *  Copyright (C) 2016, bitmovin GmbH, All Rights Reserved
 *
 * Authors: Mario Guggenberger <mario.guggenberger@bitmovin.com>
 *
 * This source code and its use and distribution, is subject to the terms
 * and conditions of the applicable license agreement.
 */

var gulp = require('gulp');

// Gulp plugins
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var cssBase64 = require('gulp-css-base64');
var postcss = require('gulp-postcss');
var uglify = require('gulp-uglify');
var gif = require('gulp-if');
var rename = require('gulp-rename');
var tslint = require('gulp-tslint');
var sassLint = require('gulp-sass-lint');

// PostCSS plugins
var postcssSVG = require('postcss-svg');
var autoprefixer = require('autoprefixer');
var cssnano = require('cssnano');

// Browserify
var browserify = require('browserify');
var tsify = require('tsify');
var watchify = require('watchify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');

// Various stuff
var del = require('del');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');

var paths = {
    source: {
        html: ['./src/html/*.html'],
        ts: ['./src/ts/main.ts'],
        tsWatch: ['./src/ts/**/*.ts'],
        sass: ['./src/scss/**/*.scss']
    },
    target: {
        html: './dist',
        js: './dist/js',
        css: './dist/css'
    }
};

var browserifyInstance = browserify({
    basedir: '.',
    debug: true,
    entries: paths.source.ts,
    cache: {},
    packageCache: {}
}).plugin(tsify);

var catchBrowserifyErrors = false;
var production = false;

// Deletes the target directory containing all generated files
gulp.task('clean', del.bind(null, [paths.target.html]));

// TypeScript linting
gulp.task('lint-ts', function () {
    return gulp.src(paths.source.tsWatch)
        .pipe(tslint({
            formatter: "verbose"
        }))
        .pipe(tslint.report({
            // Print just the number of errors (instead of printing all errors again)
            summarizeFailureOutput: true
        }))
});

// Sass/SCSS linting
gulp.task('lint-sass', function () {
    return gulp.src(paths.source.sass)
        .pipe(sassLint({
            rules: {
                'no-css-comments': 0 // Disable warning because of copyright headers
            }
        }))
        .pipe(sassLint.format())
        .pipe(sassLint.failOnError())
});

// Runs all linters
gulp.task('lint', function (callback) {
    // this fails at first error so we can't run all linters sequentially with runSequence and then print the errors
    runSequence('lint-ts', 'lint-sass', callback);
    // TODO check in Gulp 4.0 if all linters can be run sequentially before aborting due to an error
});

// Copies html files to the target directory
gulp.task('html', function () {
    return gulp.src(paths.source.html)
        .pipe(gulp.dest(paths.target.html));
});

// Compiles JS and TypeScript to JS in the target directory
gulp.task('browserify', function () {
    var browserifyBundle = browserifyInstance.bundle();

    if(catchBrowserifyErrors) {
        // Normally an error breaks a running task. For permanent tasks like watch/serve, we want the task to
        // stay alive and ignore errors, so we catch them here and print them to the console.
        browserifyBundle.on('error', console.error.bind(console));
    }

    // Compile output JS file
    var stream = browserifyBundle
        .pipe(source('bitmovin-playerui.js'))
        .pipe(buffer())
        .pipe(gulp.dest(paths.target.js));

    if (production) {
        // Minify JS
        stream.pipe(uglify())
            .pipe(rename({extname: '.min.js'}))
            .pipe(gulp.dest(paths.target.js));
    }

    stream.pipe(browserSync.reload({stream: true}));
});

// Compiles SASS stylesheets to CSS stylesheets in the target directory, adds autoprefixes and creates sourcemaps
gulp.task('sass', function () {
    var stream = gulp.src(paths.source.sass)
        .pipe(sourcemaps.init())
        .pipe(sass().on('error', sass.logError))
        .pipe(postcss([
            autoprefixer({browsers: ['> 1%', 'last 2 versions', 'Firefox ESR']}),
            postcssSVG()
        ]))
        .pipe(cssBase64())
        .pipe(sourcemaps.write())
        .pipe(gulp.dest(paths.target.css));

    if (production) {
        // Minify CSS
        stream.pipe(postcss([cssnano()]))
            .pipe(rename({extname: '.min.css'}))
            .pipe(gulp.dest(paths.target.css));
    }

    stream.pipe(browserSync.reload({stream: true}));
});

// Builds the complete project from the sources into the target directory
gulp.task('build', function(callback) {
    // First run 'clean', then the other tasks
    // TODO remove runSequence on Gulp 4.0 and use built in serial execution instead
    runSequence('clean',
        ['html', 'browserify', 'sass'],
        callback);
});

gulp.task('build-prod', function(callback) {
    production = true;
    runSequence('lint', 'build', callback);
});

gulp.task('default', ['build']);

// Watches files for changes and runs their build tasks
gulp.task('watch', function () {
    // Watch for changed html files
    gulp.watch(paths.source.html, ['html']);

    // Watch SASS files
    gulp.watch(paths.source.sass, ['sass']);

    // Watch files for changes through Browserify with Watchify
    catchBrowserifyErrors = true;
    return browserifyInstance
        .plugin(watchify)
        // When a file has changed, rerun the browserify task to create an updated bundle
        .on('update', function () {
            gulp.start('browserify');
        })
        .bundle();
});

// Serves the project in the browser and updates it automatically on changes
gulp.task('serve', function () {
    runSequence(['build'], function () {
        browserSync({
            notify: false,
            port: 9000,
            server: {
                baseDir: [paths.target.html]
            }
        });

        gulp.watch(paths.source.sass, ['sass']);
        gulp.watch(paths.source.html, ['html']).on('change', browserSync.reload);
        catchBrowserifyErrors = true;
        gulp.watch(paths.source.tsWatch, ['browserify']);
    });
});<commit_msg>Write sourcemap file for minified js<commit_after>/*
 *  Copyright (C) 2016, bitmovin GmbH, All Rights Reserved
 *
 * Authors: Mario Guggenberger <mario.guggenberger@bitmovin.com>
 *
 * This source code and its use and distribution, is subject to the terms
 * and conditions of the applicable license agreement.
 */

var gulp = require('gulp');

// Gulp plugins
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var cssBase64 = require('gulp-css-base64');
var postcss = require('gulp-postcss');
var uglify = require('gulp-uglify');
var gif = require('gulp-if');
var rename = require('gulp-rename');
var tslint = require('gulp-tslint');
var sassLint = require('gulp-sass-lint');

// PostCSS plugins
var postcssSVG = require('postcss-svg');
var autoprefixer = require('autoprefixer');
var cssnano = require('cssnano');

// Browserify
var browserify = require('browserify');
var tsify = require('tsify');
var watchify = require('watchify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');

// Various stuff
var del = require('del');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');

var paths = {
    source: {
        html: ['./src/html/*.html'],
        ts: ['./src/ts/main.ts'],
        tsWatch: ['./src/ts/**/*.ts'],
        sass: ['./src/scss/**/*.scss']
    },
    target: {
        html: './dist',
        js: './dist/js',
        css: './dist/css'
    }
};

var browserifyInstance = browserify({
    basedir: '.',
    debug: true,
    entries: paths.source.ts,
    cache: {},
    packageCache: {}
}).plugin(tsify);

var catchBrowserifyErrors = false;
var production = false;

// Deletes the target directory containing all generated files
gulp.task('clean', del.bind(null, [paths.target.html]));

// TypeScript linting
gulp.task('lint-ts', function () {
    return gulp.src(paths.source.tsWatch)
        .pipe(tslint({
            formatter: "verbose"
        }))
        .pipe(tslint.report({
            // Print just the number of errors (instead of printing all errors again)
            summarizeFailureOutput: true
        }))
});

// Sass/SCSS linting
gulp.task('lint-sass', function () {
    return gulp.src(paths.source.sass)
        .pipe(sassLint({
            rules: {
                'no-css-comments': 0 // Disable warning because of copyright headers
            }
        }))
        .pipe(sassLint.format())
        .pipe(sassLint.failOnError())
});

// Runs all linters
gulp.task('lint', function (callback) {
    // this fails at first error so we can't run all linters sequentially with runSequence and then print the errors
    runSequence('lint-ts', 'lint-sass', callback);
    // TODO check in Gulp 4.0 if all linters can be run sequentially before aborting due to an error
});

// Copies html files to the target directory
gulp.task('html', function () {
    return gulp.src(paths.source.html)
        .pipe(gulp.dest(paths.target.html));
});

// Compiles JS and TypeScript to JS in the target directory
gulp.task('browserify', function () {
    var browserifyBundle = browserifyInstance.bundle();

    if(catchBrowserifyErrors) {
        // Normally an error breaks a running task. For permanent tasks like watch/serve, we want the task to
        // stay alive and ignore errors, so we catch them here and print them to the console.
        browserifyBundle.on('error', console.error.bind(console));
    }

    // Compile output JS file
    var stream = browserifyBundle
        .pipe(source('bitmovin-playerui.js'))
        .pipe(buffer())
        .pipe(gulp.dest(paths.target.js));

    if (production) {
        // Minify JS
        stream.pipe(sourcemaps.init({loadMaps: true}))
            .pipe(uglify())
            .pipe(rename({extname: '.min.js'}))
            .pipe(sourcemaps.write('.'))
            .pipe(gulp.dest(paths.target.js));
    }

    stream.pipe(browserSync.reload({stream: true}));
});

// Compiles SASS stylesheets to CSS stylesheets in the target directory, adds autoprefixes and creates sourcemaps
gulp.task('sass', function () {
    var stream = gulp.src(paths.source.sass)
        .pipe(sourcemaps.init())
        .pipe(sass().on('error', sass.logError))
        .pipe(postcss([
            autoprefixer({browsers: ['> 1%', 'last 2 versions', 'Firefox ESR']}),
            postcssSVG()
        ]))
        .pipe(cssBase64())
        .pipe(sourcemaps.write())
        .pipe(gulp.dest(paths.target.css));

    if (production) {
        // Minify CSS
        stream.pipe(postcss([cssnano()]))
            .pipe(rename({extname: '.min.css'}))
            .pipe(gulp.dest(paths.target.css));
    }

    stream.pipe(browserSync.reload({stream: true}));
});

// Builds the complete project from the sources into the target directory
gulp.task('build', function(callback) {
    // First run 'clean', then the other tasks
    // TODO remove runSequence on Gulp 4.0 and use built in serial execution instead
    runSequence('clean',
        ['html', 'browserify', 'sass'],
        callback);
});

gulp.task('build-prod', function(callback) {
    production = true;
    runSequence('lint', 'build', callback);
});

gulp.task('default', ['build']);

// Watches files for changes and runs their build tasks
gulp.task('watch', function () {
    // Watch for changed html files
    gulp.watch(paths.source.html, ['html']);

    // Watch SASS files
    gulp.watch(paths.source.sass, ['sass']);

    // Watch files for changes through Browserify with Watchify
    catchBrowserifyErrors = true;
    return browserifyInstance
        .plugin(watchify)
        // When a file has changed, rerun the browserify task to create an updated bundle
        .on('update', function () {
            gulp.start('browserify');
        })
        .bundle();
});

// Serves the project in the browser and updates it automatically on changes
gulp.task('serve', function () {
    runSequence(['build'], function () {
        browserSync({
            notify: false,
            port: 9000,
            server: {
                baseDir: [paths.target.html]
            }
        });

        gulp.watch(paths.source.sass, ['sass']);
        gulp.watch(paths.source.html, ['html']).on('change', browserSync.reload);
        catchBrowserifyErrors = true;
        gulp.watch(paths.source.tsWatch, ['browserify']);
    });
});<|endoftext|>


<commit_before>var gulp = require('gulp');
var gutil = require('gulp-util');
var requirejs = require('requirejs');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var livereload = require('gulp-livereload');

gulp.task('scripts:tweentime', [], function(cb) {
  requirejs.optimize({
    baseUrl: 'src/scripts',
    mainConfigFile: 'src/scripts/require-config.js',
    name: 'bower_components/almond/almond',
    out: 'dist/scripts/TweenTime.js',
    optimize: 'none',
    inlineText: true,
    generateSourceMaps: true,
    preserveLicenseComments: true,
    include: 'TweenTime',
    paths: {
      requireLib: "bower_components/requirejs/require"
    },
    exclude: ['coffee-script', 'TweenMax', 'TimelineMax'],
    stubModules: ['cs'],
    wrap: {
      "startFile": "src/misc/wrap.start.js",
      "endFile": "src/misc/wrap.end.js"
    },
  }, function (buildResponse) {
    cb();
  }, function (err){
    gutil.log(gutil.colors.white.bgRed.bold('### Scripts error ###'));
    gutil.log(err);
    cb();
  })
});

gulp.task('scripts', ['scripts:tweentime'], function(cb) {
  requirejs.optimize({
    baseUrl: 'src/scripts',
    mainConfigFile: 'src/scripts/require-config.js',
    name: 'bower_components/almond/almond',
    out: 'dist/scripts/Editor.js',
    optimize: 'none',
    inlineText: true,
    generateSourceMaps: true,
    preserveLicenseComments: true,
    include: 'Editor',
    paths: {
      requireLib: "bower_components/requirejs/require"
    },
    exclude: ['coffee-script', 'TweenMax', 'TimelineMax', 'd3', 'jquery', 'Mustache', 'lodash', 'draggablenumber'],
    stubModules: ['cs'],
    wrap: {
      "startFile": "src/misc/wrap.start--editor.js",
      "endFile": "src/misc/wrap.end--editor.js"
    },
  }, function (buildResponse) {
    cb();
  }, function (err){
    gutil.log(gutil.colors.white.bgRed.bold('### Scripts error ###'));
    gutil.log(err);
    cb();
  })
});

gulp.task('styles', [], function(cb) {
  gulp.src('src/styles/editor.sass')
    .pipe(sourcemaps.init())
    .pipe(sass({
      style: 'expanded',
      errLogToConsole: true
    }))
    .pipe(sourcemaps.write('./maps'))
    .pipe(gulp.dest('./dist/styles/'));
});

gulp.task('default', function() {
  livereload.listen();

  gulp.watch([
    'examples/*.html',
    '!src/scripts/bower_components/**',
    'dist/styles/*.css',
    'dist/scripts/*.js'
  ], livereload.changed);

  gulp.watch(['src/styles/**'], ['styles']);
  gulp.watch(['src/scripts/**', '!src/scripts/bower_components/**'], ['scripts']);
});
<commit_msg>gulp: build script and styles by default<commit_after>var gulp = require('gulp');
var gutil = require('gulp-util');
var requirejs = require('requirejs');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var livereload = require('gulp-livereload');

gulp.task('scripts:tweentime', [], function(cb) {
  requirejs.optimize({
    baseUrl: 'src/scripts',
    mainConfigFile: 'src/scripts/require-config.js',
    name: 'bower_components/almond/almond',
    out: 'dist/scripts/TweenTime.js',
    optimize: 'none',
    inlineText: true,
    generateSourceMaps: true,
    preserveLicenseComments: true,
    include: 'TweenTime',
    paths: {
      requireLib: "bower_components/requirejs/require"
    },
    exclude: ['coffee-script', 'TweenMax', 'TimelineMax'],
    stubModules: ['cs'],
    wrap: {
      "startFile": "src/misc/wrap.start.js",
      "endFile": "src/misc/wrap.end.js"
    },
  }, function (buildResponse) {
    cb();
  }, function (err){
    gutil.log(gutil.colors.white.bgRed.bold('### Scripts error ###'));
    gutil.log(err);
    cb();
  })
});

gulp.task('scripts', ['scripts:tweentime'], function(cb) {
  requirejs.optimize({
    baseUrl: 'src/scripts',
    mainConfigFile: 'src/scripts/require-config.js',
    name: 'bower_components/almond/almond',
    out: 'dist/scripts/Editor.js',
    optimize: 'none',
    inlineText: true,
    generateSourceMaps: true,
    preserveLicenseComments: true,
    include: 'Editor',
    paths: {
      requireLib: "bower_components/requirejs/require"
    },
    exclude: ['coffee-script', 'TweenMax', 'TimelineMax', 'd3', 'jquery', 'Mustache', 'lodash', 'draggablenumber'],
    stubModules: ['cs'],
    wrap: {
      "startFile": "src/misc/wrap.start--editor.js",
      "endFile": "src/misc/wrap.end--editor.js"
    },
  }, function (buildResponse) {
    cb();
  }, function (err){
    gutil.log(gutil.colors.white.bgRed.bold('### Scripts error ###'));
    gutil.log(err);
    cb();
  })
});

gulp.task('styles', [], function(cb) {
  gulp.src('src/styles/editor.sass')
    .pipe(sourcemaps.init())
    .pipe(sass({
      style: 'expanded',
      errLogToConsole: true
    }))
    .pipe(sourcemaps.write('./maps'))
    .pipe(gulp.dest('./dist/styles/'));
});

gulp.task('livereload', function() {
  livereload.listen();
});

gulp.task('default', ['livereload', 'styles', 'scripts'], function() {
  gulp.watch([
    'examples/*.html',
    '!src/scripts/bower_components/**',
    'dist/styles/*.css',
    'dist/scripts/*.js'
  ], livereload.changed);

  gulp.watch(['src/styles/**'], ['styles']);
  gulp.watch(['src/scripts/**', '!src/scripts/bower_components/**'], ['scripts']);
});
<|endoftext|>


<commit_before>var gulp  = require('gulp')
var shell = require('./')

var paths = {
  js: ['*.js', 'test/*.js']
}

gulp.task('test', shell.task('mocha -R spec -r should'))

gulp.task('coverage', ['test'], shell.task('istanbul cover _mocha -- -R spec'))

gulp.task('coveralls', ['coverage'], shell.task('cat coverage/lcov.info | coveralls'))

gulp.task('lint', shell.task([
  'jshint ' + paths.js.join(' '),
  'jscs '   + paths.js.join(' '),
]))

gulp.task('default', ['coverage', 'lint'])

gulp.task('watch', function () {
  gulp.watch(paths.js, ['default'])
})
<commit_msg>no message<commit_after><|endoftext|>


<commit_before>var gulp = require('gulp');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');

 // Minify JS
gulp.task('dist', function() {
  return gulp.src('massautocomplete.js')
    .pipe(rename({suffix: '.min'}))
    .pipe(uglify())
    .pipe(gulp.dest(''));
});
 // Default Task
gulp.task('default', ['dist']);
<commit_msg>Small style changes to gulpfile.js<commit_after>var gulp = require('gulp'),
    uglify = require('gulp-uglify'),
    rename = require('gulp-rename');

gulp.task('dist', function() {
  return gulp.src('massautocomplete.js')
    .pipe(rename({suffix: '.min'}))
    .pipe(uglify())
    .pipe(gulp.dest(''));
});

gulp.task('default', ['dist']);
<|endoftext|>


<commit_before>// Uses some ideas from https://gist.github.com/kevinSuttle/c8b198aaa30349088c35

var gulp = require('gulp');
var pkg = require('./package.json');
var common = require('./common/common');

var del           = require('del'),
    sass          = require('gulp-sass'),
    sourcemaps    = require('gulp-sourcemaps'),
    autoprefixer  = require('gulp-autoprefixer'),
    browserSync   = require('browser-sync'),
    reload        = browserSync.reload,
    tap           = require('gulp-tap'),
    runSequence   = require('run-sequence').use(gulp),
    exec          = require('child_process').exec,
    nodemon       = require('gulp-nodemon');

// Auto load all gulp plugins
var plug = require('gulp-load-plugins')();

// Paths
var paths = {
  source : {
    root : './client',
    css : [
        './client/css/**/*.css',
        '!./client/css/**/*.min.css'
    ],
    sass : [
        './client/scss',
        './client/lib/github/zurb/bower-foundation@5.5.2/scss'
    ],
    sassMain : './client/scss/app.scss',
    js : './client/**/*.js',
    jsMain : './client/app.js'
  },
  dest : {
    css : './client/css',
    cssMain : 'app.min.css',
    jsMain : './client/app.min.js'
  }
};

// Load common utils
var _ = plug.loadUtils(['colors', 'env', 'log', 'date']);

// Create comments for minified files
var commentHeader = common.createComments(_);

// TASKS
// ----------------------------

// Js linter -- currently not used!
gulp.task('jshint', function() {
  return gulp.src(paths.source.jsMain)
             .pipe(plug.jshint('.jshintrc'))
             .pipe(plug.jshint.reporter('jshint-stylish'));
});

// uses jspm to create a self-executing bundle at /client/app.js
gulp.task('jspmBundle', function(cb) {
  exec('jspm bundle-sfx app/main ' + paths.source.jsMain, function(err) {
    if (err) return cb(err);
    cb();
  });
});

// js minify & header injection
gulp.task('js', ['jspmBundle'], function() {
  return gulp.src(paths.source.jsMain)
             .pipe(plug.size({ showFiles : true }))
             .pipe(plug.uglify())
             .pipe(plug.header(commentHeader))
               .pipe(tap(function(file,t) {
                 file.path = file.path.replace(/\.js$/, '.min.js');  // using gulp-tap to create a .min.js file with same name in same folder
               }))
               .pipe(gulp.dest(paths.source.root))
               .pipe(plug.size({ showFiles : true }));
});

// converting sass to css
gulp.task('sass', function() {
  return gulp.src(paths.source.sassMain)
               .pipe(sass({
                 includePaths : paths.source.sass,
                 outputStyle : 'nested'
               }, { errLogToConsole : true }))
               .pipe(autoprefixer())
               .pipe(gulp.dest(paths.dest.css));
});

// css minify & bundling
gulp.task('css', ['sass'], function() {
  return gulp.src(paths.source.css)
             .pipe(plug.size({ showFiles : true }))
             .pipe(sourcemaps.init())
             .pipe(plug.minifyCss({}))
             .pipe(plug.concat(paths.dest.cssMain))
             .pipe(plug.header(commentHeader))
             .pipe(sourcemaps.write('.'))
             .pipe(gulp.dest(paths.dest.css))
             .pipe(plug.size({ showFiles : true }));
});

gulp.task('clean', function(cb) {
  del([paths.dest.css, paths.source.root + '/app*'], function(err, paths) {
    var msg = 'Deleted files/folders:\n' + paths.join('\n');
    _.log(_.colors.yellow(msg));

    cb();
  });
});

gulp.task('build', function(cb) {
  runSequence('clean',
              ['css', 'js'],
              cb);
});

gulp.task('nodemon', function(cb) {
  var called = false;
  return nodemon({ script : pkg.main, ext : 'js vash ejs jade', ignore : ['./client/**', './logs/**'] }).on('start', function() {
    if (!called) {
      _.log(_.colors.green('Starting nodemon..'));
      called = true;
      cb();
    }
  });
});

gulp.task('browser-sync', ['nodemon'], function() {
  browserSync({
    proxy : 'http://localhost:5000'
  });
});

function reportChange(event) {
  _.log('File ' + _.colors.green(event.path) + ' was ' + _.colors.yellow(event.type) + ', running tasks...');
}

gulp.task('watch', ['browser-sync'], function() {
  gulp.watch(paths.source.sassMain, ['sass', reload({ stream : true })]).on('change', reportChange);
  gulp.watch(paths.source.js, ['', reload]).on('change', reportChange);
});

gulp.task('default', function(cb) {
  runSequence('build', 'watch', cb);
});

gulp.task('serveprod', function() {
  connect.server({
    root: paths.source.root,
    port: process.env.PORT || 5000, // localhost:5000
    livereload: false
  });
});

gulp.task('heroku:production', function(){
  runSeq('clean', 'js')
})<commit_msg>Updated gulpfile<commit_after>// Uses some ideas from https://gist.github.com/kevinSuttle/c8b198aaa30349088c35

var gulp = require('gulp');
var pkg = require('./package.json');
var common = require('./common/common');

var del           = require('del'),
    sass          = require('gulp-sass'),
    sourcemaps    = require('gulp-sourcemaps'),
    autoprefixer  = require('gulp-autoprefixer'),
    browserSync   = require('browser-sync'),
    reload        = browserSync.reload,
    tap           = require('gulp-tap'),
    runSequence   = require('run-sequence').use(gulp),
    exec          = require('child_process').exec,
    nodemon       = require('gulp-nodemon');

// Auto load all gulp plugins
var plug = require('gulp-load-plugins')();

// Paths
var paths = {
  source : {
    root : './client',
    css : [
        './client/css/**/*.css',
        '!./client/css/**/*.min.css'
    ],
    sass : [
        './client/scss',
        './client/lib/github/zurb/bower-foundation@5.5.2/scss'
    ],
    sassMain : './client/scss/app.scss',
    js : './client/**/*.js',
    jsMain : './client/app.js'
  },
  dest : {
    css : './client/css',
    cssMain : 'app.min.css',
    jsMain : './client/app.min.js'
  }
};

// Load common utils
var _ = plug.loadUtils(['colors', 'env', 'log', 'date']);

// Create comments for minified files
var commentHeader = common.createComments(_);

// TASKS
// ----------------------------

// Js linter -- currently not used!
gulp.task('jshint', function() {
  return gulp.src(paths.source.jsMain)
             .pipe(plug.jshint('.jshintrc'))
             .pipe(plug.jshint.reporter('jshint-stylish'));
});

// uses jspm to create a self-executing bundle at /client/app.js
gulp.task('jspmBundle', function(cb) {
  exec('jspm bundle-sfx app/main ' + paths.source.jsMain, function(err) {
    if (err) return cb(err);
    cb();
  });
});

// js minify & header injection
gulp.task('js', ['jspmBundle'], function() {
  return gulp.src(paths.source.jsMain)
             .pipe(plug.size({ showFiles : true }))
             .pipe(plug.uglify())
             .pipe(plug.header(commentHeader))
               .pipe(tap(function(file,t) {
                 file.path = file.path.replace(/\.js$/, '.min.js');  // using gulp-tap to create a .min.js file with same name in same folder
               }))
               .pipe(gulp.dest(paths.source.root))
               .pipe(plug.size({ showFiles : true }));
});

// converting sass to css
gulp.task('sass', function() {
  return gulp.src(paths.source.sassMain)
               .pipe(sass({
                 includePaths : paths.source.sass,
                 outputStyle : 'nested'
               }, { errLogToConsole : true }))
               .pipe(autoprefixer())
               .pipe(gulp.dest(paths.dest.css));
});

// css minify & bundling
gulp.task('css', ['sass'], function() {
  return gulp.src(paths.source.css)
             .pipe(plug.size({ showFiles : true }))
             .pipe(sourcemaps.init())
             .pipe(plug.minifyCss({}))
             .pipe(plug.concat(paths.dest.cssMain))
             .pipe(plug.header(commentHeader))
             .pipe(sourcemaps.write('.'))
             .pipe(gulp.dest(paths.dest.css))
             .pipe(plug.size({ showFiles : true }));
});

gulp.task('clean', function(cb) {
  del([paths.dest.css, paths.source.root + '/app*'], function(err, paths) {
    var msg = 'Deleted files/folders:\n' + paths.join('\n');
    _.log(_.colors.yellow(msg));

    cb();
  });
});

gulp.task('build', function(cb) {
  runSequence('clean',
              ['css', 'js'],
              cb);
});

gulp.task('nodemon', function(cb) {
  var called = false;
  return nodemon({ script : pkg.main, ext : 'js vash ejs jade', ignore : ['./client/**', './logs/**'] }).on('start', function() {
    if (!called) {
      _.log(_.colors.green('Starting nodemon..'));
      called = true;
      cb();
    }
  });
});

gulp.task('browser-sync', ['nodemon'], function() {
  browserSync({
    proxy : 'http://localhost:5000'
  });
});

function reportChange(event) {
  _.log('File ' + _.colors.green(event.path) + ' was ' + _.colors.yellow(event.type) + ', running tasks...');
}

gulp.task('watch', ['browser-sync'], function() {
  gulp.watch(paths.source.sassMain, ['sass', reload({ stream : true })]).on('change', reportChange);
  gulp.watch(paths.source.js, ['', reload]).on('change', reportChange);
});

gulp.task('default', function(cb) {
  runSequence('build', 'watch', cb);
});

gulp.task('serveprod', function() {
  connect.server({
    root: paths.source.root,
    port: process.env.PORT || 5000, // localhost:5000
    livereload: false
  });
});

gulp.task('heroku:production', function(){
  runSequence('clean', 'js')
})<|endoftext|>


<commit_before>'use strict'

const gulp = require('gulp')
  const sass = require('gulp-ruby-sass')
  const postcss = require('gulp-postcss')
    const sugarss = require('sugarss')
    const autoprefixer = require('autoprefixer')
  const jade = require('gulp-jade')
  const rename = require('gulp-rename')

gulp.task('sss', () => {
  return gulp.src('src/**/*.sss')
    .pipe(postcss([], { parser: sugarss }))
    .pipe(rename({ extname: '.scss' }))
    .pipe(gulp.dest('scss/'))
})

gulp.task('scss', ['sss'], () => {
  return sass('scss/**/index.scss', { style: 'expanded' }).on('error', sass.logError)
    .pipe(postcss([ autoprefixer ]))
    .pipe(gulp.dest('css/'))
})

gulp.task('jade', () => {
  return gulp.src('src/**/index.jade')
    .pipe(jade({ pretty: true }))
    .pipe(gulp.dest(''))
})

gulp.task('build', ['scss', 'jade'])

gulp.task('watch', () => {
  gulp.watch('src/**/*', ['build'])
})
<commit_msg>node sass instead of ruby sass<commit_after>'use strict'

const gulp = require('gulp')
  const sass = require('gulp-sass')
  const postcss = require('gulp-postcss')
    const sugarss = require('sugarss')
    const autoprefixer = require('autoprefixer')
  const jade = require('gulp-jade')
  const rename = require('gulp-rename')

gulp.task('sss', () => {
  return gulp.src('src/**/*.sss')
    .pipe(postcss([], { parser: sugarss }))
    .pipe(rename({ extname: '.scss' }))
    .pipe(gulp.dest('scss/'))
})

gulp.task('scss', ['sss'], () => {
  return sass('scss/**/index.scss', { style: 'expanded' }).on('error', sass.logError)
    .pipe(postcss([ autoprefixer ]))
    .pipe(gulp.dest('css/'))
})

gulp.task('jade', () => {
  return gulp.src('src/**/index.jade')
    .pipe(jade({ pretty: true }))
    .pipe(gulp.dest(''))
})

gulp.task('build', ['scss', 'jade'])

gulp.task('watch', () => {
  gulp.watch('src/**/*', ['build'])
})
<|endoftext|>


<commit_before>// including plugins
var gulp = require('gulp'),
    htmlmin = require("gulp-htmlmin"),
    minifyCss = require("gulp-minify-css"),
    uglify = require("gulp-uglify"),
    replace = require("gulp-replace"),
    clean = require("gulp-clean"),
    debug = require("gulp-debug"),
    pjson = require('./package.json');

gulp.task('clean', function () {
    return gulp.src('dist', {read: false})
        .pipe(clean());
});

gulp.task('minify-html', ['clean'], function () {
    return gulp.src('./public/*.html') // path to your files
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest('dist'));
});

gulp.task('copy-html-templates', ['clean'], function () {
    return gulp.src('./public/scripts/app/templates/*')
        .pipe(gulp.dest('dist/scripts/app/templates'));
})

gulp.task('copy-print-templates', ['clean'], function () {
    return gulp.src('./public/scripts/app/templates/print/*')
        .pipe(gulp.dest('dist/scripts/app/templates/print'));
})

gulp.task('copy-referendum-templates', ['clean'], function () {
    return gulp.src('./public/scripts/app/templates/referendum/*')
        .pipe(gulp.dest('dist/scripts/app/templates/referendum'));
})

gulp.task('minify-css', ['clean'], function () {
    return gulp.src('./public/**/*.css') // path to your files
        .pipe(minifyCss())
        .pipe(gulp.dest('dist'));
});

gulp.task('minify-js', ['clean'], function () {
    return gulp.src(['./public/**/*.js', '!./public/scripts/app/siteconfig.js', '!./public/**/*.min.js']) // path to your files
        .pipe(debug({title: 'minifying:'}))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist'));
});

gulp.task('images', ['clean'], function () {
    return gulp.src(['./public/**/*.{png,jpg,gif,svg}'])
        .pipe(gulp.dest('dist'));
});

gulp.task('siteconfig-pubstorm', ['minify-js'], function () {
    return gulp.src('./public/scripts/app/siteconfig.js')
        .pipe(replace('return ConfigGnuLorienDev;', 'return ConfigPubstorm;'))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist/scripts/app'));
});

gulp.task('siteconfig-patron', ['minify-js'], function () {
    return gulp.src('./public/scripts/app/siteconfig.js')
        .pipe(replace('return ConfigGnuLorienDev;', 'return ConfigPatron;'))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist/scripts/app'));
});

gulp.task('siteconfig-patron', ['minify-js'], function () {
    return gulp.src('./public/scripts/app/siteconfig.js')
        .pipe(replace('return ConfigGnuLorienDev;', 'return ConfigHeroku;'))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist/scripts/app'));
});

gulp.task('appbust', ['minify-js'], function () {
    return gulp.src('./public/scripts/app.js')
        .pipe(replace('bust=010101', 'bust=' + pjson.version))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist/scripts'));
});

gulp.task('indexbust', ['minify-html'], function () {
    return gulp.src('./public/index.html')
        .pipe(replace('require.js?bust=010101', 'require.js?bust=' + pjson.version))
        .pipe(replace('app.js?bust=010101', 'app.js?bust=' + pjson.version))
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest('dist'));
})

gulp.task('pubstorm', ['minify-html', 'copy-print-templates', 'copy-referendum-templates', 'copy-html-templates', 'minify-css', 'images', 'siteconfig-pubstorm', 'appbust', 'indexbust']);

gulp.task('patron', ['minify-html', 'copy-print-templates', 'copy-referendum-templates', 'copy-html-templates', 'minify-css', 'images', 'siteconfig-patron', 'appbust', 'indexbust']);

gulp.task('heroku', ['minify-html', 'copy-print-templates', 'copy-referendum-templates', 'copy-html-templates', 'minify-css', 'images', 'siteconfig-heroku', 'appbust', 'indexbust']);<commit_msg>Fix typo in new heroku generator<commit_after>// including plugins
var gulp = require('gulp'),
    htmlmin = require("gulp-htmlmin"),
    minifyCss = require("gulp-minify-css"),
    uglify = require("gulp-uglify"),
    replace = require("gulp-replace"),
    clean = require("gulp-clean"),
    debug = require("gulp-debug"),
    pjson = require('./package.json');

gulp.task('clean', function () {
    return gulp.src('dist', {read: false})
        .pipe(clean());
});

gulp.task('minify-html', ['clean'], function () {
    return gulp.src('./public/*.html') // path to your files
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest('dist'));
});

gulp.task('copy-html-templates', ['clean'], function () {
    return gulp.src('./public/scripts/app/templates/*')
        .pipe(gulp.dest('dist/scripts/app/templates'));
})

gulp.task('copy-print-templates', ['clean'], function () {
    return gulp.src('./public/scripts/app/templates/print/*')
        .pipe(gulp.dest('dist/scripts/app/templates/print'));
})

gulp.task('copy-referendum-templates', ['clean'], function () {
    return gulp.src('./public/scripts/app/templates/referendum/*')
        .pipe(gulp.dest('dist/scripts/app/templates/referendum'));
})

gulp.task('minify-css', ['clean'], function () {
    return gulp.src('./public/**/*.css') // path to your files
        .pipe(minifyCss())
        .pipe(gulp.dest('dist'));
});

gulp.task('minify-js', ['clean'], function () {
    return gulp.src(['./public/**/*.js', '!./public/scripts/app/siteconfig.js', '!./public/**/*.min.js']) // path to your files
        .pipe(debug({title: 'minifying:'}))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist'));
});

gulp.task('images', ['clean'], function () {
    return gulp.src(['./public/**/*.{png,jpg,gif,svg}'])
        .pipe(gulp.dest('dist'));
});

gulp.task('siteconfig-pubstorm', ['minify-js'], function () {
    return gulp.src('./public/scripts/app/siteconfig.js')
        .pipe(replace('return ConfigGnuLorienDev;', 'return ConfigPubstorm;'))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist/scripts/app'));
});

gulp.task('siteconfig-patron', ['minify-js'], function () {
    return gulp.src('./public/scripts/app/siteconfig.js')
        .pipe(replace('return ConfigGnuLorienDev;', 'return ConfigPatron;'))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist/scripts/app'));
});

gulp.task('siteconfig-heroku', ['minify-js'], function () {
    return gulp.src('./public/scripts/app/siteconfig.js')
        .pipe(replace('return ConfigGnuLorienDev;', 'return ConfigHeroku;'))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist/scripts/app'));
});

gulp.task('appbust', ['minify-js'], function () {
    return gulp.src('./public/scripts/app.js')
        .pipe(replace('bust=010101', 'bust=' + pjson.version))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist/scripts'));
});

gulp.task('indexbust', ['minify-html'], function () {
    return gulp.src('./public/index.html')
        .pipe(replace('require.js?bust=010101', 'require.js?bust=' + pjson.version))
        .pipe(replace('app.js?bust=010101', 'app.js?bust=' + pjson.version))
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest('dist'));
})

gulp.task('pubstorm', ['minify-html', 'copy-print-templates', 'copy-referendum-templates', 'copy-html-templates', 'minify-css', 'images', 'siteconfig-pubstorm', 'appbust', 'indexbust']);

gulp.task('patron', ['minify-html', 'copy-print-templates', 'copy-referendum-templates', 'copy-html-templates', 'minify-css', 'images', 'siteconfig-patron', 'appbust', 'indexbust']);

gulp.task('heroku', ['minify-html', 'copy-print-templates', 'copy-referendum-templates', 'copy-html-templates', 'minify-css', 'images', 'siteconfig-heroku', 'appbust', 'indexbust']);<|endoftext|>


<commit_before>var gulp = require('gulp'),
    minifyCSS = require('gulp-minify-css'), // CSS minifying
    //imagemin = require('gulp-imagemin'), // Img minifying
    uglify = require('gulp-uglify'),    // JS minifying
    concat = require('gulp-concat'),    // Files merging
    rev = require('gulp-rev'),          // Files versioning
    compass = require('gulp-compass'),  // Compass to work with CSS
    rjs = require("gulp-requirejs"),    //A gulp interface to r.js
    connect = require('gulp-connect'),  // Webserver
    rename = require("gulp-rename"),    //Rename files
    useref = require('gulp-useref'),    //Removes <!-- build:js ... blocks from html
    replaceRevRef = require('gulp-rev-manifest-replace'), //Plugin to replace assets urls based on generated manifest file
    reverse = require('reversible'),
    rimraf = require('gulp-rimraf');                      // Remove files and folders
    //wait = require('gulp-wait'),
    //lr = require('tiny-lr'), // Минивебсервер для livereload
    //server = lr(),
    //livereload = require('gulp-livereload'), // Livereload for Gulp

var buildConfig = {
        jekyllStageConfig : "_config.stage.yml",
        jekyllProdConfig : "_config.prod.yml",
        jekyllGHConfig : "_config.gh.yml",
        jekyllEEConfig : "_config.enterprise.yml",
    };

var paths = {
        src: 'app/',
        prod: 'target/prod/',
        stage: 'target/stage/',
        temp: 'target/temp/',
        dist: 'target/dist/',
        config: 'build/',
        site: 'app/_site/'
};

// prod building
gulp.task('jek', function () {
     require('child_process')
        .spawn('jekyll', ['build'], {stdio: 'inherit', cwd: paths.temp, exclude: [paths.temp +'site/_scss']});
});

gulp.task('rjs1',function(){
      /*return
      gulp.src(paths.temp + 'site/_rjs/*.js')
        .pipe(rjs({
            mainConfigFile: paths.temp +'site/_rjs/main.js',
            //optimize: 'none', //hardcoded in requirejs plugin
            baseUrl: paths.temp + 'site/_rjs',
            wrap: true,
            name: 'main',
            mainFile: paths.temp+'site/index.html',
            out: 'main.js'
        }))*/
        rjs({
            mainConfigFile: paths.temp +'site/_rjs/main.js',
            //optimize: 'none', //hardcoded in requirejs plugin
            baseUrl: paths.temp + 'site/_rjs',
            wrap: true,
            name: 'main',
            mainFile: paths.temp+'site/index.html',
            out: 'main.js'
        })
        .pipe(gulp.dest(paths.temp + 'site/scripts'))

        ;
 });

// This task creates local server
gulp.task('connect', function() {
  connect.server({
    root: paths.prod,
  });
});

// --------------------------- Building Prod -----------------------------
//----------------
//----------
gulp.task('prod',['copy_src','prod_cfg','css','rjs','jekyll','myrev','replace','rmbuild','copy_prod'], function(){

})
// Copies src to temp folder
gulp.task('copy_src', function(){
  return gulp.src(paths.src + '**/*.*')
  .pipe(gulp.dest(paths.temp))
})

gulp.task('prod_cfg', function(){
  return gulp.src(paths.config + buildConfig.jekyllProdConfig)
  .pipe(rename('_config.yml'))
  .pipe(gulp.dest(paths.temp))
})

gulp.task('css', ['copy_src'], function() {
  return gulp.src(paths.temp+'site/styles/*.scss')
  .pipe(compass({
    //config_file: './compass-config.rb',
    css: paths.temp +'site/styles',
    sass: paths.temp +'site/styles'
  }))
  .pipe(minifyCSS())
  .pipe(gulp.dest(paths.prod + 'site/styles/'));
});

// Builds projects using require.js's optimizer + Minify files with UglifyJS
gulp.task('rjs',['copy_src'], function(){
      return  rjs({
            mainConfigFile: paths.temp +'site/scripts/main.js',
            //optimize: 'none', //hardcoded in requirejs plugin
            baseUrl: paths.temp + 'site/scripts',
            wrap: true,
            name: 'main',
            mainFile: paths.temp+'site/index.html',
            out: 'amd-main.js'
        })
      .pipe(gulp.src(paths.temp +'site/scripts/vendor/require.js'))
      .pipe(reverse({objectMode: true})) // requirejs should be at the begining
      .pipe(concat('amd-app.js'))
      .pipe(uglify())
      .pipe(gulp.dest(paths.prod + 'site/scripts'));
 });

gulp.task('jekyll',['copy_src','prod_cfg']/*,['copy_src','css','rjs']*/, function () {
         console.log('Jekyll ......... ');
     return require('child_process')
        .spawn('jekyll', ['build'], {stdio: 'inherit', cwd: paths.temp});

});

// Replaces references with reved names
  gulp.task ('myrev', ['copy_src','prod_cfg','css','rjs','jekyll'], function(){
    return gulp.src([paths.prod + 'site/scripts/amd-app.js', paths.prod + 'site/styles/*.css'],{base:paths.prod})
    //.pipe(wait(1500))
    .pipe(rev())
    .pipe(gulp.dest(paths.prod))
    .pipe(rev.manifest())
    .pipe(gulp.dest(paths.prod));
  });

// Start replacing rev references
gulp.task('replace',['copy_src','prod_cfg','css','rjs','jekyll','myrev'], function(){

  var manifest = require(paths.prod+'rev-manifest.json')
  return gulp.src([paths.prod+'**/*.html'])
  .pipe(replaceRevRef({
    base: process.cwd()+'/target/prod',
    manifest: manifest,
    path: ''/*,
    cdnPrefix: 'http://absolute.path/cdn/'*/
  }))
  .pipe(gulp.dest(paths.prod));

});

// Removes <!-- build:js ... blocks from html for prod configeration
gulp.task('rmbuild', ['copy_src','prod_cfg','css','rjs','jekyll','myrev','replace'], function(){
  return gulp.src(paths.prod+'**/*.html')
  .pipe(useref())
  .pipe(gulp.dest(paths.prod));

});

gulp.task('copy_prod',['copy_src','prod_cfg','css','rjs','jekyll','myrev','replace','rmbuild'], function(){
  gulp.src([paths.prod+'/**/*.html', // all HTML
    paths.prod+'**/amd-app-*.js', // minified JS
    paths.prod+'**/*-*.css', // minified CSS
    paths.prod+'**/*.jpg',
    paths.prod+'**/*.png',
    paths.prod+'**/*.svg',
    paths.prod+'**/*.txt',
    paths.prod+'**/modernizr.custom.*.js'] // robots.txt
    )
  .pipe(gulp.dest(paths.dist+'prod'));
});

// Cleans gulp's folders
gulp.task('clean',function(){
  return gulp.src([paths.temp,paths.prod,paths.stage,paths.dist],{ read: false }) // much faster
    .pipe(rimraf());
})
<commit_msg>CLDIDE set relative paths<commit_after>var gulp = require('gulp'),
    minifyCSS = require('gulp-minify-css'), // CSS minifying
    //imagemin = require('gulp-imagemin'), // Img minifying
    uglify = require('gulp-uglify'),    // JS minifying
    concat = require('gulp-concat'),    // Files merging
    rev = require('gulp-rev'),          // Files versioning
    compass = require('gulp-compass'),  // Compass to work with CSS
    rjs = require("gulp-requirejs"),    //A gulp interface to r.js
    connect = require('gulp-connect'),  // Webserver
    rename = require("gulp-rename"),    //Rename files
    useref = require('gulp-useref'),    //Removes <!-- build:js ... blocks from html
    replaceRevRef = require('gulp-rev-manifest-replace'), //Plugin to replace assets urls based on generated manifest file
    reverse = require('reversible'),
    rimraf = require('gulp-rimraf');                      // Remove files and folders
    //wait = require('gulp-wait'),
    //lr = require('tiny-lr'), // Минивебсервер для livereload
    //server = lr(),
    //livereload = require('gulp-livereload'), // Livereload for Gulp

var buildConfig = {
        jekyllStageConfig : "_config.stage.yml",
        jekyllProdConfig : "_config.prod.yml",
        jekyllGHConfig : "_config.gh.yml",
        jekyllEEConfig : "_config.enterprise.yml",
    };

var paths = {
        src: './app/',
        prod: './target/prod/',
        stage: './target/stage/',
        temp: './target/temp/',
        dist: './target/dist/',
        config: './build/',
        site: './app/_site/'
};

// prod building
gulp.task('jek', function () {
     require('child_process')
        .spawn('jekyll', ['build'], {stdio: 'inherit', cwd: paths.temp, exclude: [paths.temp +'site/_scss']});
});

gulp.task('rjs1',function(){
      /*return
      gulp.src(paths.temp + 'site/_rjs/*.js')
        .pipe(rjs({
            mainConfigFile: paths.temp +'site/_rjs/main.js',
            //optimize: 'none', //hardcoded in requirejs plugin
            baseUrl: paths.temp + 'site/_rjs',
            wrap: true,
            name: 'main',
            mainFile: paths.temp+'site/index.html',
            out: 'main.js'
        }))*/
        rjs({
            mainConfigFile: paths.temp +'site/_rjs/main.js',
            //optimize: 'none', //hardcoded in requirejs plugin
            baseUrl: paths.temp + 'site/_rjs',
            wrap: true,
            name: 'main',
            mainFile: paths.temp+'site/index.html',
            out: 'main.js'
        })
        .pipe(gulp.dest(paths.temp + 'site/scripts'))

        ;
 });

// This task creates local server
gulp.task('connect', function() {
  connect.server({
    root: paths.stage
  });
});

// --------------------------- Building Prod -----------------------------
//----------------
//----------
gulp.task('prod',['copy_src','prod_cfg','css','rjs','jekyll','myrev','replace','rmbuild','copy_prod'], function(){

})
// Copies src to temp folder
gulp.task('copy_src', function(){
  return gulp.src(paths.src + '**/*.*')
  .pipe(gulp.dest(paths.temp))
})

gulp.task('prod_cfg', function(){
  return gulp.src(paths.config + buildConfig.jekyllProdConfig)
  .pipe(rename('_config.yml'))
  .pipe(gulp.dest(paths.temp))
})

gulp.task('css', ['copy_src'], function() {
  return gulp.src(paths.temp+'site/styles/*.scss')
  .pipe(compass({
    //config_file: './compass-config.rb',
    css: paths.temp +'site/styles',
    sass: paths.temp +'site/styles'
  }))
  .pipe(minifyCSS())
  .pipe(gulp.dest(paths.prod + 'site/styles/'));
});

// Builds projects using require.js's optimizer + Minify files with UglifyJS
gulp.task('rjs',['copy_src'], function(){
      return  rjs({
            mainConfigFile: paths.temp +'site/scripts/main.js',
            //optimize: 'none', //hardcoded in requirejs plugin
            baseUrl: paths.temp + 'site/scripts',
            wrap: true,
            name: 'main',
            mainFile: paths.temp+'site/index.html',
            out: 'amd-main.js'
        })
      .pipe(gulp.src(paths.temp +'site/scripts/vendor/require.js'))
      .pipe(reverse({objectMode: true})) // requirejs should be at the begining
      .pipe(concat('amd-app.js'))
      .pipe(uglify())
      .pipe(gulp.dest(paths.prod + 'site/scripts'));
 });

gulp.task('jekyll',['copy_src','prod_cfg'], function () {
         console.log('Jekyll ......... ');
     return require('child_process')
        .spawn('jekyll', ['build'], {stdio: 'inherit', cwd: paths.temp});

});

// Replaces references with reved names
  gulp.task ('myrev', ['copy_src','prod_cfg','css','rjs','jekyll'], function(){
    return gulp.src([paths.prod + 'site/scripts/amd-app.js', paths.prod + 'site/styles/*.css'],{base:paths.prod})
    //.pipe(wait(1500))
    .pipe(rev())
    .pipe(gulp.dest(paths.prod))
    .pipe(rev.manifest())
    .pipe(gulp.dest(paths.prod));
  });

// Start replacing rev references
gulp.task('replace',['copy_src','prod_cfg','css','rjs','jekyll','myrev'], function(){

  var manifest = require(paths.prod+'rev-manifest.json')
  return gulp.src([paths.prod+'**/*.html'])
  .pipe(replaceRevRef({
    base: process.cwd()+'/target/prod',
    manifest: manifest,
    path: ''/*,
    cdnPrefix: 'http://absolute.path/cdn/'*/
  }))
  .pipe(gulp.dest(paths.prod));

});

// Removes <!-- build:js ... blocks from html for prod configeration
gulp.task('rmbuild', ['copy_src','prod_cfg','css','rjs','jekyll','myrev','replace'], function(){
  return gulp.src(paths.prod+'**/*.html')
  .pipe(useref())
  .pipe(gulp.dest(paths.prod));

});

gulp.task('copy_prod',['copy_src','prod_cfg','css','rjs','jekyll','myrev','replace','rmbuild'], function(){
  gulp.src([paths.prod+'/**/*.html', // all HTML
    paths.prod+'**/amd-app-*.js', // minified JS
    paths.prod+'**/*-*.css', // minified CSS
    paths.prod+'**/*.jpg',
    paths.prod+'**/*.png',
    paths.prod+'**/*.svg',
    paths.prod+'**/*.txt',
    paths.prod+'**/modernizr.custom.*.js'] // robots.txt
    )
  .pipe(gulp.dest(paths.dist+'prod'));
});

// Cleans gulp's folders
gulp.task('clean',function(){
  return gulp.src([paths.temp,paths.prod,paths.stage,paths.dist],{ read: false }) // much faster
    .pipe(rimraf());
})

// --------------------------- Building Stage -----------------------------
//----------------
//----------
gulp.task('stage',['copy_src','stage_cfg','css_stage','jekyll_stage','copy_stage'], function(){

})
// Copies src to temp folder
gulp.task('copy_src', function(){
  return gulp.src(paths.src + '**/*.*')
  .pipe(gulp.dest(paths.temp))
})

gulp.task('stage_cfg', function(){
  return gulp.src(paths.config + buildConfig.jekyllStageConfig)
  .pipe(rename('_config.yml'))
  .pipe(gulp.dest(paths.temp))
})

gulp.task('css_stage', ['copy_src'], function() {
  return gulp.src(paths.temp+'site/styles/*.scss')
  .pipe(compass({
    //config_file: './compass-config.rb',
    css: paths.temp +'site/styles',
    sass: paths.temp +'site/styles'
  }))
  .pipe(gulp.dest(paths.stage + 'site/styles/'));
});

gulp.task('jekyll_stage',['copy_src','stage_cfg'], function () {
         console.log('Jekyll ......... ');
     return require('child_process')
        .spawn('jekyll', ['build'], {stdio: 'inherit', cwd: paths.temp});

});

gulp.task('copy_stage',['copy_src','stage_cfg','css_stage','jekyll_stage'], function(){
  gulp.src([paths.stage+'/**/*.html', // all HTML
    paths.stage+'**/*.js',
    paths.stage+'**/*.css',
    paths.stage+'**/*.jpg',
    paths.stage+'**/*.png',
    paths.stage+'**/*.svg',
    paths.stage+'**/*.txt'  // robots.txt
    ])
  .pipe(gulp.dest(paths.dist+'stage'));
});

// Cleans gulp's folders
gulp.task('clean',function(){
  return gulp.src([paths.temp,paths.prod,paths.stage,paths.dist],{ read: false }) // much faster
    .pipe(rimraf());
})
<|endoftext|>


<commit_before>const gulp = require('gulp')
const rename = require('gulp-rename');

const replace = require('gulp-replace');
const ts = require('gulp-typescript');
const concat = require('gulp-concat');
const fs = require('fs');
const sourcemaps = require('gulp-sourcemaps');
const runSequence = require('run-sequence');
const bump = require('gulp-bump');
const child_process = require('child_process');
const spawn = child_process.spawn;
const wrap = require('gulp-wrap');
const uglify = require('gulp-uglify');

/**
 * Fail on error if not in watch mode
 */
let watching = false;
function onError(error) {
    if (!watching) {
        process.exit(1);
    }
}

/**
 * ts projects
 */
let projectTypings = ts.createProject('src/tsconfig.json', {
    removeComments: false,
});
let projectCommonjs = ts.createProject('src/tsconfig.json');
let projectLoader = ts.createProject('src/loader/tsconfig.json');
let projectLoaderTypings = ts.createProject('src/loader/tsconfig.json', {
    removeComments: false,
});
let projectModule = ts.createProject('src/modules/tsconfig.json');

/**
 * Our commonjs only files
 */
let filesMain = ['src/**/*.ts', "!./src/loader/LoaderAPI.ts", "!./src/modules/**/*.ts"];

/**
 * Loader API building
 */
gulp.task('dist-loader-js', () => {
    return gulp.src('src/loader/LoaderAPI.ts')
        .pipe(projectLoader()).on('error', onError).js
        .pipe(wrap(`(function(__root__){
if (__root__["FuseBox"]) return __root__["FuseBox"];
<%= contents %>
return __root__["FuseBox"] = FuseBox; } )(this)`
        ))
        .pipe(rename('fusebox.js'))
        .pipe(gulp.dest('modules/fuse-box-loader-api'))
        .pipe(rename('fusebox.min.js'))
        .pipe(uglify())
        .pipe(replace(/;$/, ''))
        .pipe(replace(/^\!/, ''))
        .pipe(gulp.dest('modules/fuse-box-loader-api'))

});
gulp.task('dist-loader-typings', () => {
    return gulp.src('src/loader/LoaderAPI.ts')
        .pipe(projectLoaderTypings()).dts
        .pipe(rename('LoaderAPI.ts'))
        .pipe(gulp.dest('src/modules/fuse-loader'));
});
gulp.task('dist-loader', ['dist-loader-js', 'dist-loader-typings'])

/**
 * Used to build the fusebox modules
 * When adding a new module here be sure to .gitignore `modules/${name}/`
 */
gulp.task('dist-modules', ['dist-loader-typings'], () => {
    return gulp.src(`src/modules/**/*.ts`)
        .pipe(projectModule()).on('error', onError)
        .pipe(gulp.dest(`modules`))
});

/**
 * Main building
 */
gulp.task('dist-typings', () => {
    return result = gulp.src(filesMain)
        .pipe(projectTypings()).dts
        .pipe(gulp.dest('dist/typings'));
});
gulp.task('dist-commonjs', () => {
    return gulp.src(filesMain)
        .pipe(sourcemaps.init())
        .pipe(projectCommonjs()).on('error', onError).js
        .pipe(gulp.dest('dist/commonjs'));
});
gulp.task('dist-main', ['dist-typings', 'dist-commonjs']);

/**
 * NPM deploy management
 */
gulp.task('publish', function(done) {
    runSequence('dist', 'increment-version', 'commit-release', 'npm-publish', done);
});
gulp.task('increment-version', function() {
    return gulp.src('./package.json')
        .pipe(bump())
        .pipe(gulp.dest('./'));
});
gulp.task('commit-release', function(done) {
    let json = JSON.parse(fs.readFileSync(__dirname + '/package.json').toString());
    child_process.exec(`git add .; git commit -m "Release ${json.version}" -a; git tag v${json.version}; git push origin master --tags`, (error, stdout, stderr) => {
        if (error) {
            console.error(`exec error: ${error}`);
            return;
        }
        console.log(`stdout: ${stdout}`);
        console.log(`stderr: ${stderr}`);
        done();
    });
});
gulp.task('npm-publish', function(done) {
    var publish = spawn('npm', ['publish'], {
        stdio: 'inherit'
    })
    publish.on('close', function(code) {
        if (code === 8) {
            gulp.log('Error detected, waiting for changes...');
        }
        done()
    });
});

/**
 * Combined build task
 */
gulp.task('dist', ['dist-main', 'dist-loader', 'dist-modules']);

/**
 * For development workflow
 */
gulp.task('watch', ['dist'], function() {
    watching = true;

    gulp.watch(['src/loader/**/*.ts'], () => {
        runSequence('dist-loader');
    });

    gulp.watch(['src/modules/**/*.ts'], () => {
        runSequence('dist-modules');
    });

    gulp.watch(filesMain, () => {
        runSequence('dist-main');
    });
});
<commit_msg>Travis?<commit_after>const gulp = require('gulp')
const rename = require('gulp-rename');

const replace = require('gulp-replace');
const ts = require('gulp-typescript');
const concat = require('gulp-concat');
const fs = require('fs');
const sourcemaps = require('gulp-sourcemaps');
const runSequence = require('run-sequence');
const bump = require('gulp-bump');
const child_process = require('child_process');
const spawn = child_process.spawn;
const wrap = require('gulp-wrap');
const uglify = require('gulp-uglify');

/**
 * Fail on error if not in watch mode
 */
let watching = false;

function onError(error) {
    if (!watching) {
        process.exit(1);
    }
}

/**
 * ts projects
 */
let projectTypings = ts.createProject('src/tsconfig.json', {
    removeComments: false,
});
let projectCommonjs = ts.createProject('src/tsconfig.json');
let projectLoader = ts.createProject('src/loader/tsconfig.json');
let projectLoaderTypings = ts.createProject('src/loader/tsconfig.json', {
    removeComments: false,
});
let projectModule = ts.createProject('src/modules/tsconfig.json');

/**
 * Our commonjs only files
 */
let filesMain = ['src/**/*.ts', "!./src/loader/LoaderAPI.ts", "!./src/modules/**/*.ts"];

/**
 * Loader API building
 */
gulp.task('dist-loader-js', () => {
    return gulp.src('src/loader/LoaderAPI.ts')
        .pipe(projectLoader()).on('error', onError).js
        .pipe(wrap(`(function(__root__){
if (__root__["FuseBox"]) return __root__["FuseBox"];
<%= contents %>
return __root__["FuseBox"] = FuseBox; } )(this)`))
        .pipe(rename('fusebox.js'))
        .pipe(gulp.dest('modules/fuse-box-loader-api'))
        .pipe(rename('fusebox.min.js'))
        .pipe(uglify())
        .pipe(replace(/;$/, ''))
        .pipe(replace(/^\!/, ''))
        .pipe(gulp.dest('modules/fuse-box-loader-api'))

});
gulp.task('dist-loader-typings', () => {
    return gulp.src('src/loader/LoaderAPI.ts')
        .pipe(projectLoaderTypings()).dts
        .pipe(rename('LoaderAPI.ts'))
        .pipe(gulp.dest('src/modules/fuse-loader'));
});
gulp.task('dist-loader', ['dist-loader-js', 'dist-loader-typings'])

/**
 * Used to build the fusebox modules
 * When adding a new module here be sure to .gitignore `modules/${name}/`
 */
gulp.task('dist-modules', ['dist-loader-typings'], () => {
    return gulp.src(`src/modules/**/*.ts`)
        .pipe(projectModule()).on('error', onError)
        .pipe(gulp.dest(`modules`))
});

/**
 * Main building
 */
gulp.task('dist-typings', () => {
    return result = gulp.src(filesMain)
        .pipe(projectTypings()).dts
        .pipe(gulp.dest('dist/typings'));
});
gulp.task('dist-commonjs', () => {
    return gulp.src(filesMain)
        .pipe(sourcemaps.init())
        .pipe(projectCommonjs()).on('error', onError).js
        .pipe(gulp.dest('dist/commonjs'));
});
gulp.task('dist-main', ['dist-typings', 'dist-commonjs']);

/**
 *  NPM deploy management
 */
gulp.task('publish', function(done) {
    runSequence('dist', 'increment-version', 'commit-release', 'npm-publish', done);
});
gulp.task('increment-version', function() {
    return gulp.src('./package.json')
        .pipe(bump())
        .pipe(gulp.dest('./'));
});
gulp.task('commit-release', function(done) {
    let json = JSON.parse(fs.readFileSync(__dirname + '/package.json').toString());
    child_process.exec(`git add .; git commit -m "Release ${json.version}" -a; git tag v${json.version}; git push origin master --tags`, (error, stdout, stderr) => {
        if (error) {
            console.error(`exec error: ${error}`);
            return;
        }
        console.log(`stdout: ${stdout}`);
        console.log(`stderr: ${stderr}`);
        done();
    });
});
gulp.task('npm-publish', function(done) {
    var publish = spawn('npm', ['publish'], {
        stdio: 'inherit'
    })
    publish.on('close', function(code) {
        if (code === 8) {
            gulp.log('Error detected, waiting for changes...');
        }
        done()
    });
});

/**
 * Combined build task
 */
gulp.task('dist', ['dist-main', 'dist-loader', 'dist-modules']);

/**
 * For development workflow
 */
gulp.task('watch', ['dist'], function() {
    watching = true;

    gulp.watch(['src/loader/**/*.ts'], () => {
        runSequence('dist-loader');
    });

    gulp.watch(['src/modules/**/*.ts'], () => {
        runSequence('dist-modules');
    });

    gulp.watch(filesMain, () => {
        runSequence('dist-main');
    });
});<|endoftext|>


<commit_before>// ## Globals
var argv         = require('minimist')(process.argv.slice(2));
var autoprefixer = require('gulp-autoprefixer');
var browserSync  = require('browser-sync').create();
var changed      = require('gulp-changed');
var concat       = require('gulp-concat');
var flatten      = require('gulp-flatten');
var gulp         = require('gulp');
var gulpif       = require('gulp-if');
var imagemin     = require('gulp-imagemin');
var jshint       = require('gulp-jshint');
var lazypipe     = require('lazypipe');
var less         = require('gulp-less');
var merge        = require('merge-stream');
var cssNano      = require('gulp-cssnano');
var plumber      = require('gulp-plumber');
var rev          = require('gulp-rev');
var runSequence  = require('run-sequence');
var sass         = require('gulp-sass');
var sourcemaps   = require('gulp-sourcemaps');
var uglify       = require('gulp-uglify');
var svgstore     = require('gulp-svgstore');
// var wpPot        = require('gulp-wp-pot');
// var sort         = require('gulp-sort');

// See https://github.com/austinpray/asset-builder
var manifest = require('asset-builder')('./assets/manifest.json');

// `path` - Paths to base asset directories. With trailing slashes.
// - `path.source` - Path to the source files. Default: `assets/`
// - `path.dist` - Path to the build directory. Default: `dist/`
var path = manifest.paths;

// `config` - Store arbitrary configuration values here.
var config = manifest.config || {};

// `globs` - These ultimately end up in their respective `gulp.src`.
// - `globs.js` - Array of asset-builder JS dependency objects. Example:
//   ```
//   {type: 'js', name: 'main.js', globs: []}
//   ```
// - `globs.css` - Array of asset-builder CSS dependency objects. Example:
//   ```
//   {type: 'css', name: 'main.css', globs: []}
//   ```
// - `globs.fonts` - Array of font path globs.
// - `globs.images` - Array of image path globs.
// - `globs.bower` - Array of all the main Bower files.
var globs = manifest.globs;

// `project` - paths to first-party assets.
// - `project.js` - Array of first-party JS assets.
// - `project.css` - Array of first-party CSS assets.
var project = manifest.getProjectGlobs();

// CLI options
var enabled = {
  // Enable static asset revisioning when `--production`
  rev: argv.production,
  // Disable source maps when `--production`
  maps: !argv.production,
  // Fail styles task on error when `--production`
  failStyleTask: argv.production,
  // Fail due to JSHint warnings only when `--production`
  failJSHint: argv.production,
  // Strip debug statments from javascript when `--production`
  stripJSDebug: argv.production
};

// Path to the compiled assets manifest in the dist directory
var revManifest = path.dist + 'assets.json';

// Error checking; produce an error rather than crashing.
var onError = function(err) {
  console.log(err.toString());
  this.emit('end');
};

// ## Reusable Pipelines
// See https://github.com/OverZealous/lazypipe

// ### CSS processing pipeline
// Example
// ```
// gulp.src(cssFiles)
//   .pipe(cssTasks('main.css')
//   .pipe(gulp.dest(path.dist + 'styles'))
// ```
var cssTasks = function(filename) {
  return lazypipe()
    .pipe(function() {
      return gulpif(!enabled.failStyleTask, plumber());
    })
    .pipe(function() {
      return gulpif(enabled.maps, sourcemaps.init());
    })
    .pipe(function() {
      return gulpif('*.less', less());
    })
    .pipe(function() {
      return gulpif('*.scss', sass({
        outputStyle: 'nested', // libsass doesn't support expanded yet
        precision: 10,
        includePaths: ['.'],
        errLogToConsole: !enabled.failStyleTask
      }));
    })
    .pipe(concat, filename)
    .pipe(autoprefixer, {
      browsers: [
        'last 2 versions',
        'android 4',
        'opera 12'
      ]
    })
    .pipe(cssNano, {
      safe: true
    })
    .pipe(function() {
      return gulpif(enabled.rev, rev());
    })
    .pipe(function() {
      return gulpif(enabled.maps, sourcemaps.write('.', {
        sourceRoot: 'assets/styles/'
      }));
    })();
};

// ### JS processing pipeline
// Example
// ```
// gulp.src(jsFiles)
//   .pipe(jsTasks('main.js')
//   .pipe(gulp.dest(path.dist + 'scripts'))
// ```
var jsTasks = function(filename) {
  return lazypipe()
    .pipe(function() {
      return gulpif(enabled.maps, sourcemaps.init());
    })
    .pipe(concat, filename)
    .pipe(uglify, {
      compress: {
        'drop_debugger': enabled.stripJSDebug
      }
    })
    .pipe(function() {
      return gulpif(enabled.rev, rev());
    })
    .pipe(function() {
      return gulpif(enabled.maps, sourcemaps.write('.', {
        sourceRoot: 'assets/scripts/'
      }));
    })();
};

// ### Write to rev manifest
// If there are any revved files then write them to the rev manifest.
// See https://github.com/sindresorhus/gulp-rev
var writeToManifest = function(directory) {
  return lazypipe()
    .pipe(gulp.dest, path.dist + directory)
    .pipe(browserSync.stream, {match: '**/*.{js,css}'})
    .pipe(rev.manifest, revManifest, {
      base: path.dist,
      merge: true
    })
    .pipe(gulp.dest, path.dist)();
};

// ## Gulp tasks
// Run `gulp -T` for a task summary

// ### Styles
// `gulp styles` - Compiles, combines, and optimizes Bower CSS and project CSS.
// By default this task will only log a warning if a precompiler error is
// raised. If the `--production` flag is set: this task will fail outright.
gulp.task('styles', ['wiredep'], function() {
  var merged = merge();
  manifest.forEachDependency('css', function(dep) {
    var cssTasksInstance = cssTasks(dep.name);
    if (!enabled.failStyleTask) {
      cssTasksInstance.on('error', function(err) {
        console.error(err.message);
        this.emit('end');
      });
    }
    merged.add(gulp.src(dep.globs, {base: 'styles'})
      .pipe(plumber({errorHandler: onError}))
      .pipe(cssTasksInstance));
  });
  return merged
    .pipe(writeToManifest('styles'));
});

// ### Scripts
// `gulp scripts` - Runs JSHint then compiles, combines, and optimizes Bower JS
// and project JS.
gulp.task('scripts', ['jshint'], function() {
  var merged = merge();
  manifest.forEachDependency('js', function(dep) {
    merged.add(
      gulp.src(dep.globs, {base: 'scripts'})
        .pipe(plumber({errorHandler: onError}))
        .pipe(jsTasks(dep.name))
    );
  });
  return merged
    .pipe(writeToManifest('scripts'));
});

// ### Fonts
// `gulp fonts` - Grabs all the fonts and outputs them in a flattened directory
// structure. See: https://github.com/armed/gulp-flatten
gulp.task('fonts', function() {
  return gulp.src(globs.fonts)
    .pipe(flatten())
    .pipe(gulp.dest(path.dist + 'fonts'))
    .pipe(browserSync.stream());
});

// ### Images
// `gulp images` - Run lossless compression on all the images.
gulp.task('images', function() {
  return gulp.src(globs.images)
    .pipe(imagemin([
      imagemin.jpegtran({progressive: true}),
      imagemin.gifsicle({interlaced: true}),
      imagemin.svgo({plugins: [{removeUnknownsAndDefaults: false}, {cleanupIDs: false}]})
    ]))
    .pipe(gulp.dest(path.dist + 'images'))
    .pipe(browserSync.stream());
});

// ### SvgStore
// `gulp svgstore` - Compile all svg files in a single one
gulp.task('svgstore', function () {
  return gulp
    .src([path.source + 'svg/**/*.svg'])
    .pipe(svgstore())
    .pipe(gulp.dest(path.dist + 'images'));
});

// ### JSHint
// `gulp jshint` - Lints configuration JSON and project JS.
gulp.task('jshint', function() {
  return gulp.src([
    'bower.json', 'gulpfile.js'
  ].concat(project.js))
    .pipe(jshint())
    .pipe(jshint.reporter('jshint-stylish'))
    .pipe(gulpif(enabled.failJSHint, jshint.reporter('fail')));
});

// ### PO File
// gulp.task('I18n', function () {
//   return gulp.src(['{lib,templates}/**/*.php', '*.php'])
//     .pipe(sort())
//     .pipe(wpPot( {
//         domain: 'oxbow',
//         destFile:'oxbow.pot',
//         package: 'oxbow',
//         bugReport: '',
//         lastTranslator: 'name LASTNAME <email@email.com>',
//         team: 'name LASTNAME <email@email.com>',
//     } ))
//     .pipe(gulp.dest('lang'));
// });

// ### Clean
// `gulp clean` - Deletes the build folder entirely.
gulp.task('clean', require('del').bind(null, [path.dist]));

// ### Watch
// `gulp watch` - Use BrowserSync to proxy your dev server and synchronize code
// changes across devices. Specify the hostname of your dev server at
// `manifest.config.devUrl`. When a modification is made to an asset, run the
// build step for that asset and inject the changes into the page.
// See: http://www.browsersync.io
gulp.task('watch', function() {
  browserSync.init({
    files: ['{lib,templates}/**/*.php', '*.php'],
    proxy: config.devUrl,
    snippetOptions: {
      whitelist: ['/wp-admin/admin-ajax.php'],
      blacklist: ['/wp-admin/**']
    }
  });
  gulp.watch([path.source + 'styles/**/*'], ['styles']);
  gulp.watch([path.source + 'scripts/**/*'], ['jshint', 'scripts']);
  gulp.watch([path.source + 'fonts/**/*'], ['fonts']);
  gulp.watch([path.source + 'images/**/*'], ['images']);
  gulp.watch([path.source + 'svg/**/*'], ['svgstore']);
  gulp.watch(['bower.json', 'assets/manifest.json'], ['build']);
});

// ### Build
// `gulp build` - Run all the build tasks but don't clean up beforehand.
// Generally you should be running `gulp` instead of `gulp build`.
gulp.task('build', function(callback) {
  runSequence('styles',
              'scripts',
              ['fonts', 'images', 'svgstore'],
              // ['fonts', 'images', 'svgstore', 'I18n'],
              callback);
});

// ### Wiredep
// `gulp wiredep` - Automatically inject Less and Sass Bower dependencies. See
// https://github.com/taptapship/wiredep
gulp.task('wiredep', function() {
  var wiredep = require('wiredep').stream;
  return gulp.src(project.css)
    .pipe(wiredep())
    .pipe(changed(path.source + 'styles', {
      hasChanged: changed.compareSha1Digest
    }))
    .pipe(gulp.dest(path.source + 'styles'));
});

// ### Gulp
// `gulp` - Run a complete build. To compile for production run `gulp --production`.
gulp.task('default', ['clean'], function() {
  gulp.start('build');
});
<commit_msg>[CONFIG] - fix svgstore<commit_after>// ## Globals
var argv         = require('minimist')(process.argv.slice(2));
var autoprefixer = require('gulp-autoprefixer');
var browserSync  = require('browser-sync').create();
var changed      = require('gulp-changed');
var concat       = require('gulp-concat');
var flatten      = require('gulp-flatten');
var gulp         = require('gulp');
var gulpif       = require('gulp-if');
var imagemin     = require('gulp-imagemin');
var jshint       = require('gulp-jshint');
var lazypipe     = require('lazypipe');
var less         = require('gulp-less');
var merge        = require('merge-stream');
var cssNano      = require('gulp-cssnano');
var plumber      = require('gulp-plumber');
var rev          = require('gulp-rev');
var runSequence  = require('run-sequence');
var sass         = require('gulp-sass');
var sourcemaps   = require('gulp-sourcemaps');
var uglify       = require('gulp-uglify');
var svgstore     = require('gulp-svgstore');
var rename       = require('gulp-rename');
// var wpPot        = require('gulp-wp-pot');
// var sort         = require('gulp-sort');

// See https://github.com/austinpray/asset-builder
var manifest = require('asset-builder')('./assets/manifest.json');

// `path` - Paths to base asset directories. With trailing slashes.
// - `path.source` - Path to the source files. Default: `assets/`
// - `path.dist` - Path to the build directory. Default: `dist/`
var path = manifest.paths;

// `config` - Store arbitrary configuration values here.
var config = manifest.config || {};

// `globs` - These ultimately end up in their respective `gulp.src`.
// - `globs.js` - Array of asset-builder JS dependency objects. Example:
//   ```
//   {type: 'js', name: 'main.js', globs: []}
//   ```
// - `globs.css` - Array of asset-builder CSS dependency objects. Example:
//   ```
//   {type: 'css', name: 'main.css', globs: []}
//   ```
// - `globs.fonts` - Array of font path globs.
// - `globs.images` - Array of image path globs.
// - `globs.bower` - Array of all the main Bower files.
var globs = manifest.globs;

// `project` - paths to first-party assets.
// - `project.js` - Array of first-party JS assets.
// - `project.css` - Array of first-party CSS assets.
var project = manifest.getProjectGlobs();

// CLI options
var enabled = {
  // Enable static asset revisioning when `--production`
  rev: argv.production,
  // Disable source maps when `--production`
  maps: !argv.production,
  // Fail styles task on error when `--production`
  failStyleTask: argv.production,
  // Fail due to JSHint warnings only when `--production`
  failJSHint: argv.production,
  // Strip debug statments from javascript when `--production`
  stripJSDebug: argv.production
};

// Path to the compiled assets manifest in the dist directory
var revManifest = path.dist + 'assets.json';

// Error checking; produce an error rather than crashing.
var onError = function(err) {
  console.log(err.toString());
  this.emit('end');
};

// ## Reusable Pipelines
// See https://github.com/OverZealous/lazypipe

// ### CSS processing pipeline
// Example
// ```
// gulp.src(cssFiles)
//   .pipe(cssTasks('main.css')
//   .pipe(gulp.dest(path.dist + 'styles'))
// ```
var cssTasks = function(filename) {
  return lazypipe()
    .pipe(function() {
      return gulpif(!enabled.failStyleTask, plumber());
    })
    .pipe(function() {
      return gulpif(enabled.maps, sourcemaps.init());
    })
    .pipe(function() {
      return gulpif('*.less', less());
    })
    .pipe(function() {
      return gulpif('*.scss', sass({
        outputStyle: 'nested', // libsass doesn't support expanded yet
        precision: 10,
        includePaths: ['.'],
        errLogToConsole: !enabled.failStyleTask
      }));
    })
    .pipe(concat, filename)
    .pipe(autoprefixer, {
      browsers: [
        'last 2 versions',
        'android 4',
        'opera 12'
      ]
    })
    .pipe(cssNano, {
      safe: true
    })
    .pipe(function() {
      return gulpif(enabled.rev, rev());
    })
    .pipe(function() {
      return gulpif(enabled.maps, sourcemaps.write('.', {
        sourceRoot: 'assets/styles/'
      }));
    })();
};

// ### JS processing pipeline
// Example
// ```
// gulp.src(jsFiles)
//   .pipe(jsTasks('main.js')
//   .pipe(gulp.dest(path.dist + 'scripts'))
// ```
var jsTasks = function(filename) {
  return lazypipe()
    .pipe(function() {
      return gulpif(enabled.maps, sourcemaps.init());
    })
    .pipe(concat, filename)
    .pipe(uglify, {
      compress: {
        'drop_debugger': enabled.stripJSDebug
      }
    })
    .pipe(function() {
      return gulpif(enabled.rev, rev());
    })
    .pipe(function() {
      return gulpif(enabled.maps, sourcemaps.write('.', {
        sourceRoot: 'assets/scripts/'
      }));
    })();
};

// ### Write to rev manifest
// If there are any revved files then write them to the rev manifest.
// See https://github.com/sindresorhus/gulp-rev
var writeToManifest = function(directory) {
  return lazypipe()
    .pipe(gulp.dest, path.dist + directory)
    .pipe(browserSync.stream, {match: '**/*.{js,css}'})
    .pipe(rev.manifest, revManifest, {
      base: path.dist,
      merge: true
    })
    .pipe(gulp.dest, path.dist)();
};

// ## Gulp tasks
// Run `gulp -T` for a task summary

// ### Styles
// `gulp styles` - Compiles, combines, and optimizes Bower CSS and project CSS.
// By default this task will only log a warning if a precompiler error is
// raised. If the `--production` flag is set: this task will fail outright.
gulp.task('styles', ['wiredep'], function() {
  var merged = merge();
  manifest.forEachDependency('css', function(dep) {
    var cssTasksInstance = cssTasks(dep.name);
    if (!enabled.failStyleTask) {
      cssTasksInstance.on('error', function(err) {
        console.error(err.message);
        this.emit('end');
      });
    }
    merged.add(gulp.src(dep.globs, {base: 'styles'})
      .pipe(plumber({errorHandler: onError}))
      .pipe(cssTasksInstance));
  });
  return merged
    .pipe(writeToManifest('styles'));
});

// ### Scripts
// `gulp scripts` - Runs JSHint then compiles, combines, and optimizes Bower JS
// and project JS.
gulp.task('scripts', ['jshint'], function() {
  var merged = merge();
  manifest.forEachDependency('js', function(dep) {
    merged.add(
      gulp.src(dep.globs, {base: 'scripts'})
        .pipe(plumber({errorHandler: onError}))
        .pipe(jsTasks(dep.name))
    );
  });
  return merged
    .pipe(writeToManifest('scripts'));
});

// ### Fonts
// `gulp fonts` - Grabs all the fonts and outputs them in a flattened directory
// structure. See: https://github.com/armed/gulp-flatten
gulp.task('fonts', function() {
  return gulp.src(globs.fonts)
    .pipe(flatten())
    .pipe(gulp.dest(path.dist + 'fonts'))
    .pipe(browserSync.stream());
});

// ### Images
// `gulp images` - Run lossless compression on all the images.
gulp.task('images', function() {
  return gulp.src(globs.images)
    .pipe(imagemin([
      imagemin.jpegtran({progressive: true}),
      imagemin.gifsicle({interlaced: true}),
      imagemin.svgo({plugins: [{removeUnknownsAndDefaults: false}, {cleanupIDs: false}]})
    ]))
    .pipe(gulp.dest(path.dist + 'images'))
    .pipe(browserSync.stream());
});

// ### SvgStore
// `gulp svgstore` - Compile all svg files in a single one
gulp.task('svgstore', function () {
  return gulp
    .src([path.source + 'svg/**/*.svg'])
    .pipe(rename({prefix: 'svg-'}))
    .pipe(svgstore())
    .pipe(gulp.dest(path.dist + 'images'));
});

// ### JSHint
// `gulp jshint` - Lints configuration JSON and project JS.
gulp.task('jshint', function() {
  return gulp.src([
    'bower.json', 'gulpfile.js'
  ].concat(project.js))
    .pipe(jshint())
    .pipe(jshint.reporter('jshint-stylish'))
    .pipe(gulpif(enabled.failJSHint, jshint.reporter('fail')));
});

// ### PO File
// gulp.task('I18n', function () {
//   return gulp.src(['{lib,templates}/**/*.php', '*.php'])
//     .pipe(sort())
//     .pipe(wpPot( {
//         domain: 'oxbow',
//         destFile:'oxbow.pot',
//         package: 'oxbow',
//         bugReport: '',
//         lastTranslator: 'name LASTNAME <email@email.com>',
//         team: 'name LASTNAME <email@email.com>',
//     } ))
//     .pipe(gulp.dest('lang'));
// });

// ### Clean
// `gulp clean` - Deletes the build folder entirely.
gulp.task('clean', require('del').bind(null, [path.dist]));

// ### Watch
// `gulp watch` - Use BrowserSync to proxy your dev server and synchronize code
// changes across devices. Specify the hostname of your dev server at
// `manifest.config.devUrl`. When a modification is made to an asset, run the
// build step for that asset and inject the changes into the page.
// See: http://www.browsersync.io
gulp.task('watch', function() {
  browserSync.init({
    files: ['{lib,templates}/**/*.php', '*.php'],
    proxy: config.devUrl,
    snippetOptions: {
      whitelist: ['/wp-admin/admin-ajax.php'],
      blacklist: ['/wp-admin/**']
    }
  });
  gulp.watch([path.source + 'styles/**/*'], ['styles']);
  gulp.watch([path.source + 'scripts/**/*'], ['jshint', 'scripts']);
  gulp.watch([path.source + 'fonts/**/*'], ['fonts']);
  gulp.watch([path.source + 'images/**/*'], ['images']);
  gulp.watch([path.source + 'svg/**/*'], ['svgstore']);
  gulp.watch(['bower.json', 'assets/manifest.json'], ['build']);
});

// ### Build
// `gulp build` - Run all the build tasks but don't clean up beforehand.
// Generally you should be running `gulp` instead of `gulp build`.
gulp.task('build', function(callback) {
  runSequence('styles',
              'scripts',
              ['fonts', 'images', 'svgstore'],
              // ['fonts', 'images', 'svgstore', 'I18n'],
              callback);
});

// ### Wiredep
// `gulp wiredep` - Automatically inject Less and Sass Bower dependencies. See
// https://github.com/taptapship/wiredep
gulp.task('wiredep', function() {
  var wiredep = require('wiredep').stream;
  return gulp.src(project.css)
    .pipe(wiredep())
    .pipe(changed(path.source + 'styles', {
      hasChanged: changed.compareSha1Digest
    }))
    .pipe(gulp.dest(path.source + 'styles'));
});

// ### Gulp
// `gulp` - Run a complete build. To compile for production run `gulp --production`.
gulp.task('default', ['clean'], function() {
  gulp.start('build');
});
<|endoftext|>


<commit_before>/*jshint node:true*/

'use strict';

var gulp = require('gulp');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');

gulp.task('default', ['test']);

gulp.task('test', ['lint'], function () {
    return gulp.src('**/*.spec.js', {read: false})
        .pipe(mocha({reporter: 'spec'}));
});

gulp.task('lint', function () {
    return gulp.src(['**/*.js', '!node_modules/**/*.js'])
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

gulp.task('watch', function () {
    gulp.watch('**/*.spec.js', ['test']);
    gulp.watch('**/*.js', ['test']);
});<commit_msg>integrated gulp-mocha<commit_after>
'use strict';

var gulp = require('gulp');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');

gulp.task('default', ['test']);

gulp.task('test', ['lint'], function () {
    return gulp.src('**/*.spec.js', {read: false})
        .pipe(mocha({reporter: 'spec'}));
});

gulp.task('lint', function () {
    return gulp.src(['**/*.js', '!node_modules/**/*.js'])
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

gulp.task('watch', function () {
    gulp.watch('**/*.spec.js', ['test']);
    gulp.watch('**/*.js', ['test']);
});<|endoftext|>