<commit_before>var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var less = require('gulp-less');
var expect = require('gulp-expect-file');

var del = require('del');

var paths = {
    vendor_styles: [
        'bower_components/bootstrap/dist/css/bootstrap.min.css',
        'bower_components/AngularJS-Toaster/toaster.css',
        'bower_components/angular-ui-select/dist/select.min.css',
        'bower_components/clippy/build/clippy.css',
        'bower_components/angular-hotkeys/build/hotkeys.min.css'
    ],
    html_templates: [
        'src/**/*.html'
    ],
    vendor_scripts: [
        'bower_components/angular/angular.min.js',
        'bower_components/angular-sanitize/angular-sanitize.min.js',
        'bower_components/angular-resource/angular-resource.min.js',
        'bower_components/angular-cookies/angular-cookies.min.js',
        'bower_components/angular-animate/angular-animate.min.js',
        'bower_components/angular-bootstrap/ui-bootstrap.min.js',
        'bower_components/angular-ui-select/dist/select.min.js',
        'bower_components/AngularJS-Toaster/toaster.js',
        'bower_components/angular-ui-router/release/angular-ui-router.min.js',
        'bower_components/angular-jwt/dist/angular-jwt.min.js',
        'bower_components/jquery/jquery.min.js',
        'bower_components/angular-hotkeys/build/hotkeys.min.js',
        'bower_components/lodash/lodash.min.js',
        'js_vendor/moment.min.js',
        'js_vendor/angular-moment.min.js',
        'js_vendor/ZeroClipboard.min.js'
    ],
    clippy: [
        'bower_components/clippy/build/clippy.min.js'
    ],
    scripts: [
        'src/**/*.js'
    ],
    styles: [
        'styles/**/*.less'
    ],
    vendor_fonts: [
        'bower_components/bootstrap/dist/fonts/*',
        'styles/fonts/*'
    ],
    cleanup: [
        'api/public/t',
        'api/public/js',
        'api/public/fonts'
    ]
};

gulp.task('clean', function(cb) {
    del(paths.cleanup, cb);
});

gulp.task('vendor_scripts', [], function() {
    return gulp.src(paths.vendor_scripts)
        .pipe(expect(paths.vendor_scripts))
        .pipe(concat('vendor.js'))
        .pipe(gulp.dest('api/public/js'));
});

gulp.task('clippy', [], function() {
    return gulp.src(paths.clippy)
        .pipe(expect(paths.clippy))
        .pipe(concat('clippy.js'))
        .pipe(gulp.dest('api/public/js'));
});

gulp.task('vendor_styles', [], function() {
    return gulp.src(paths.vendor_styles)
        .pipe(expect(paths.vendor_styles))
        .pipe(concat('vendor_styles.css'))
        .pipe(gulp.dest('api/public/css'));
});

gulp.task('vendor_fonts', [], function() {
    return gulp.src(paths.vendor_fonts)
        .pipe(expect(paths.vendor_fonts))
        .pipe(gulp.dest('api/public/fonts'));
});

gulp.task('scripts', [], function() {
    return gulp.src(paths.scripts)
        .pipe(concat('app.js'))
        .pipe(gulp.dest('api/public/js'));
});

gulp.task('styles', [], function() {
    return gulp.src(paths.styles)
        .pipe(less())
        .pipe(concat('app.css'))
        .pipe(gulp.dest('api/public/css'));
});

gulp.task('html_templates', [], function() {
    return gulp.src(paths.html_templates)
        .pipe(gulp.dest('api/public/t'));
});

gulp.task('watch', function() {
  gulp.watch(paths.scripts, ['scripts']);
  gulp.watch(paths.html_templates, ['html_templates']);
  gulp.watch(paths.styles, ['styles']);
});

gulp.task('default', ['vendor_fonts', 'vendor_styles', 'html_templates', 'vendor_scripts', 'clippy', 'scripts', 'styles']);
<commit_msg>build everything before watching<commit_after>var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var less = require('gulp-less');
var expect = require('gulp-expect-file');

var del = require('del');

var paths = {
    vendor_styles: [
        'bower_components/bootstrap/dist/css/bootstrap.min.css',
        'bower_components/AngularJS-Toaster/toaster.css',
        'bower_components/angular-ui-select/dist/select.min.css',
        'bower_components/clippy/build/clippy.css',
        'bower_components/angular-hotkeys/build/hotkeys.min.css'
    ],
    html_templates: [
        'src/**/*.html'
    ],
    vendor_scripts: [
        'bower_components/angular/angular.min.js',
        'bower_components/angular-sanitize/angular-sanitize.min.js',
        'bower_components/angular-resource/angular-resource.min.js',
        'bower_components/angular-cookies/angular-cookies.min.js',
        'bower_components/angular-animate/angular-animate.min.js',
        'bower_components/angular-bootstrap/ui-bootstrap.min.js',
        'bower_components/angular-ui-select/dist/select.min.js',
        'bower_components/AngularJS-Toaster/toaster.js',
        'bower_components/angular-ui-router/release/angular-ui-router.min.js',
        'bower_components/angular-jwt/dist/angular-jwt.min.js',
        'bower_components/jquery/jquery.min.js',
        'bower_components/angular-hotkeys/build/hotkeys.min.js',
        'bower_components/lodash/lodash.min.js',
        'js_vendor/moment.min.js',
        'js_vendor/angular-moment.min.js',
        'js_vendor/ZeroClipboard.min.js'
    ],
    clippy: [
        'bower_components/clippy/build/clippy.min.js'
    ],
    scripts: [
        'src/**/*.js'
    ],
    styles: [
        'styles/**/*.less'
    ],
    vendor_fonts: [
        'bower_components/bootstrap/dist/fonts/*',
        'styles/fonts/*'
    ],
    cleanup: [
        'api/public/t',
        'api/public/js',
        'api/public/fonts'
    ]
};

gulp.task('clean', function(cb) {
    del(paths.cleanup, cb);
});

gulp.task('vendor_scripts', [], function() {
    return gulp.src(paths.vendor_scripts)
        .pipe(expect(paths.vendor_scripts))
        .pipe(concat('vendor.js'))
        .pipe(gulp.dest('api/public/js'));
});

gulp.task('clippy', [], function() {
    return gulp.src(paths.clippy)
        .pipe(expect(paths.clippy))
        .pipe(concat('clippy.js'))
        .pipe(gulp.dest('api/public/js'));
});

gulp.task('vendor_styles', [], function() {
    return gulp.src(paths.vendor_styles)
        .pipe(expect(paths.vendor_styles))
        .pipe(concat('vendor_styles.css'))
        .pipe(gulp.dest('api/public/css'));
});

gulp.task('vendor_fonts', [], function() {
    return gulp.src(paths.vendor_fonts)
        .pipe(expect(paths.vendor_fonts))
        .pipe(gulp.dest('api/public/fonts'));
});

gulp.task('scripts', [], function() {
    return gulp.src(paths.scripts)
        .pipe(concat('app.js'))
        .pipe(gulp.dest('api/public/js'));
});

gulp.task('styles', [], function() {
    return gulp.src(paths.styles)
        .pipe(less())
        .pipe(concat('app.css'))
        .pipe(gulp.dest('api/public/css'));
});

gulp.task('html_templates', [], function() {
    return gulp.src(paths.html_templates)
        .pipe(gulp.dest('api/public/t'));
});

gulp.task('watch', ['default'], function() {
  gulp.watch(paths.scripts, ['scripts']);
  gulp.watch(paths.html_templates, ['html_templates']);
  gulp.watch(paths.styles, ['styles']);
});

gulp.task('default', ['vendor_fonts', 'vendor_styles', 'html_templates', 'vendor_scripts', 'clippy', 'scripts', 'styles']);
<|endoftext|>


<commit_before>'use strict';
var util = require('util');
var gulp = require('gulp');
var concat = require('gulp-concat');
var del = require('del');
var inject = require('gulp-inject');
var cssnano = require('gulp-cssnano');
var uglify = require('gulp-uglify');
var ngAnnotate = require('gulp-ng-annotate');
var templateCache = require('gulp-angular-templatecache');
var eventStream = require('event-stream');
var argv = require('yargs').argv;
var gulpNgConfig = require('gulp-ng-config');
var less = require('gulp-less');
var mainBowerFiles = require('main-bower-files');
var gulpSync = require('gulp-sync')(gulp);
var wait = require('gulp-wait');
var autoprefixer = require('gulp-autoprefixer');
var jsHint = require('gulp-jshint');
var gulpIf = require('gulp-if');
var connect = require('gulp-connect');
var angularFilesort = require('gulp-angular-filesort');
var babel = require('gulp-babel');
var htmlmin = require('gulp-htmlmin');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var rev = require('gulp-rev');
var config = require('./build.config.js');

var environment = 'dev';
if (typeof argv.env === 'string' && config.environments.indexOf(argv.env.toLowerCase()) > -1) {
    environment = argv.env.toLowerCase();
}

gulp.task('lint', function () {
    return gulp.src(config.taskFiles.jshint)
        .pipe(jsHint())
        .pipe(jsHint.reporter('default'));
});

gulp.task('clean', function () {
    var options = {
        force: true
    };
    del(config.buildFiles, options).then(function (paths) {
        console.log('Deleted files/folders:\n', paths.join('\n'));
    });
});

gulp.task('constants', function () {
    var options = {
        environment: environment,
        createModule: true,
        wrap: '(function () {\n <%= module %> \n})();'
    };
    return gulp.src(config.appFiles.constants)
        .pipe(gulpNgConfig(config.names.constantsModule, options))
        .pipe(gulp.dest(config.outputPaths.constants));
});

gulp.task('less', function () {
    return gulp.src(config.appFiles.less)
        .pipe(less())
        .pipe(autoprefixer({
            browsers: ['last 2 versions'],
            cascade: false,
            remove: false
        }))
        .pipe(concat(config.names.output.appCss))
        .pipe(gulpIf(shouldMinify(), cssnano()))
        .pipe(gulpIf(shouldRevision(), rev()))
        .pipe(gulp.dest(config.outputPaths.css))
        .pipe(connect.reload());
});

gulp.task('html', function () {
    var htmlminOptions = {
        collapseWhitespace: true,
        removeComments: true
    };
    var options = {
        standalone: true,
        module: config.names.templatesModule,
        moduleSystem: 'IIFE'
    };
    return gulp.src(config.appFiles.html)
        .pipe(htmlmin(htmlminOptions))
        .pipe(templateCache(config.names.output.templatesJs, options))
        .pipe(gulpIf(shouldMinify(), uglify()))
        .pipe(gulpIf(shouldRevision(), rev()))
        .pipe(gulp.dest(config.outputPaths.templates))
        .pipe(connect.reload());
});

gulp.task('vendor-css', function () {
    var options = {
        filter: '**/*.css',
        debugging: false
    };
    return gulp.src(mainBowerFiles(options), {base: 'bower_components'})
        .pipe(concat(config.names.output.vendorCss))
        .pipe(gulpIf(shouldMinify(), cssnano()))
        .pipe(gulpIf(shouldRevision(), rev()))
        .pipe(gulp.dest(config.outputPaths.css));
});

gulp.task('app-js', ['constants'], function () {
    gulp.src(config.appFiles.js)
        .pipe(ngAnnotate())
        .pipe(angularFilesort())
        .pipe(babel({presets: ['es2015']}))
        .pipe(concat(config.names.output.appJs))
        .pipe(gulpIf(shouldMinify(), uglify()))
        .pipe(gulpIf(shouldRevision(), rev()))
        .pipe(gulp.dest(config.outputPaths.js))
        .pipe(connect.reload());
});

gulp.task('vendor-js', function () {
    var options = {
        filter: '**/*.js',
        debugging: false
    };
    var mainBowerSourceFiles = gulp.src(mainBowerFiles(options), {
        base: 'bower_components'
    });
    var vendorJsSourceFiles = gulp.src(config.vendorFiles.js);
    return eventStream.merge(mainBowerSourceFiles, vendorJsSourceFiles)
        .pipe(ngAnnotate())
        .pipe(concat(config.names.output.vendorJs))
        .pipe(gulpIf(shouldMinify(), uglify()))
        .pipe(gulpIf(shouldRevision(), rev()))
        .pipe(gulp.dest(config.outputPaths.js));
});

gulp.task('font', function () {
    return gulp.src(mainBowerFiles({
            filter: '**/*.{eot,svg,ttf,woff,woff2}'
        }))
        .pipe(gulp.dest(config.outputPaths.fonts));
});

gulp.task('static-font', function () {
    return gulp.src(config.appFiles.fonts)
        .pipe(gulp.dest(config.outputPaths.fonts));
});

gulp.task('static-files', function () {
    return gulp.src(config.appFiles.staticFiles)
        .pipe(gulp.dest(config.outputPaths.root));
});

gulp.task('favicon', function () {
    return gulp.src(config.appFiles.favicon)
        .pipe(gulp.dest(config.outputPaths.root));
});

gulp.task('images', function () {
    var options = {
        optimizationLevel: 3,
        progressive: true,
        interlaced: true,
        multipass: true,
        svgoPlugins: [{removeViewBox: false}],
        use: [pngquant()]
    };
    return gulp.src(config.appFiles.images)
        .pipe(gulpIf(shouldMinify(), imagemin(options)))
        .pipe(gulp.dest(config.outputPaths.images))
        .pipe(connect.reload());
});

gulp.task('build-index', gulpSync.sync(['clean', 'work']), function () {
    var jsSources = gulp.src([
        config.outputPaths.js + '/vendor*.js',
        config.outputPaths.js + '/templates*.js',
        config.outputPaths.js + '/build*.js'
    ], {
        read: false
    });

    var cssSources = gulp.src([
        config.outputPaths.css + '/**/*.css'
    ], {
        read: false
    });
    var options = {
        ignorePath: config.outputPaths.injectIgnoreString,
        addRootSlash: false,
        read: false
    };
    console.log('Environment: %s', environment);
    return gulp.src(config.appFiles.index)
        .pipe(wait(1000))
        .pipe(inject(cssSources, options))
        .pipe(inject(jsSources, options))
        .pipe(gulp.dest(config.outputPaths.root))
        .pipe(connect.reload());
});

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

gulp.task('work', ['html', 'vendor-css', 'less', 'vendor-js', 'app-js', 'static-font', 'font', 'favicon', 'images']);

gulp.task('watch', ['build-index', 'connect'], function () {
    gulp.watch(config.watch.less, ['less']);
    gulp.watch(config.watch.js, ['app-js']);
    gulp.watch(config.watch.html, ['html']);
    gulp.watch(config.watch.images, ['images']);
    gulp.watch(config.watch.constants, ['app-js']);
});

gulp.task('connect', ['build-index'], function () {
    connect.server({
        root: config.outputPaths.root,
        port: 9000,
        livereload: true,
        fallback: config.outputPaths.root + '/index.html'
    });
});

gulp.task('start', function () {
    connect.server({
        root: config.outputPaths.root,
        port: 9000,
        livereload: false,
        fallback: config.outputPaths.root + '/index.html'
    });
});

function shouldRevision() {
    if (environment === 'dev' || environment === 'localqa') {
        return false;
    }
    return true;
}

function shouldMinify() {
    if (environment === 'dev' || environment === 'localqa') {
        return false;
    }
    return true;
}
<commit_msg>Updated the build process<commit_after>'use strict';
var util = require('util');
var gulp = require('gulp');
var concat = require('gulp-concat');
var del = require('del');
var inject = require('gulp-inject');
var cssnano = require('gulp-cssnano');
var uglify = require('gulp-uglify');
var ngAnnotate = require('gulp-ng-annotate');
var templateCache = require('gulp-angular-templatecache');
var eventStream = require('event-stream');
var argv = require('yargs').argv;
var gulpNgConfig = require('gulp-ng-config');
var less = require('gulp-less');
var mainBowerFiles = require('main-bower-files');
var gulpSync = require('gulp-sync')(gulp);
var wait = require('gulp-wait');
var autoprefixer = require('gulp-autoprefixer');
var jsHint = require('gulp-jshint');
var gulpIf = require('gulp-if');
var connect = require('gulp-connect');
var angularFilesort = require('gulp-angular-filesort');
var babel = require('gulp-babel');
var htmlmin = require('gulp-htmlmin');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var rev = require('gulp-rev');
var config = require('./build.config.js');

var environment = 'dev';
if (typeof argv.env === 'string' && config.environments.indexOf(argv.env.toLowerCase()) > -1) {
    environment = argv.env.toLowerCase();
}

gulp.task('lint', function () {
    return gulp.src(config.taskFiles.jshint)
        .pipe(jsHint())
        .pipe(jsHint.reporter('default'));
});

gulp.task('clean', function (callback) {
    var options = {
        force: true
    };
    del(config.buildFiles, options).then(function (paths) {
        console.log('Deleted files/folders:\n', paths.join('\n'));
        callback();
    });
});

gulp.task('constants', function () {
    var options = {
        environment: environment,
        createModule: true,
        wrap: '(function () {\n <%= module %> \n})();'
    };
    return gulp.src(config.appFiles.constants)
        .pipe(gulpNgConfig(config.names.constantsModule, options))
        .pipe(gulp.dest(config.outputPaths.constants));
});

gulp.task('less', function () {
    return gulp.src(config.appFiles.less)
        .pipe(less())
        .pipe(autoprefixer({
            browsers: ['last 2 versions'],
            cascade: false,
            remove: false
        }))
        .pipe(concat(config.names.output.appCss))
        .pipe(gulpIf(shouldMinify(), cssnano()))
        .pipe(gulpIf(shouldRevision(), rev()))
        .pipe(gulp.dest(config.outputPaths.css))
        .pipe(connect.reload());
});

gulp.task('html', function () {
    var htmlminOptions = {
        collapseWhitespace: true,
        removeComments: true
    };
    var options = {
        standalone: true,
        module: config.names.templatesModule,
        moduleSystem: 'IIFE'
    };
    return gulp.src(config.appFiles.html)
        .pipe(htmlmin(htmlminOptions))
        .pipe(templateCache(config.names.output.templatesJs, options))
        .pipe(gulpIf(shouldMinify(), uglify()))
        .pipe(gulpIf(shouldRevision(), rev()))
        .pipe(gulp.dest(config.outputPaths.templates))
        .pipe(connect.reload());
});

gulp.task('vendor-css', function () {
    var options = {
        filter: '**/*.css',
        debugging: false
    };
    return gulp.src(mainBowerFiles(options), {base: 'bower_components'})
        .pipe(concat(config.names.output.vendorCss))
        .pipe(gulpIf(shouldMinify(), cssnano()))
        .pipe(gulpIf(shouldRevision(), rev()))
        .pipe(gulp.dest(config.outputPaths.css));
});

gulp.task('app-js', ['constants'], function () {
    gulp.src(config.appFiles.js)
        .pipe(ngAnnotate())
        .pipe(angularFilesort())
        .pipe(babel({presets: ['es2015']}))
        .pipe(concat(config.names.output.appJs))
        .pipe(gulpIf(shouldMinify(), uglify()))
        .pipe(gulpIf(shouldRevision(), rev()))
        .pipe(gulp.dest(config.outputPaths.js))
        .pipe(connect.reload());
});

gulp.task('vendor-js', function () {
    var options = {
        filter: '**/*.js',
        debugging: false
    };
    var mainBowerSourceFiles = gulp.src(mainBowerFiles(options), {
        base: 'bower_components'
    });
    var vendorJsSourceFiles = gulp.src(config.vendorFiles.js);
    return eventStream.merge(mainBowerSourceFiles, vendorJsSourceFiles)
        .pipe(ngAnnotate())
        .pipe(concat(config.names.output.vendorJs))
        .pipe(gulpIf(shouldMinify(), uglify()))
        .pipe(gulpIf(shouldRevision(), rev()))
        .pipe(gulp.dest(config.outputPaths.js));
});

gulp.task('font', function () {
    return gulp.src(mainBowerFiles({
            filter: '**/*.{eot,svg,ttf,woff,woff2}'
        }))
        .pipe(gulp.dest(config.outputPaths.fonts));
});

gulp.task('static-font', function () {
    return gulp.src(config.appFiles.fonts)
        .pipe(gulp.dest(config.outputPaths.fonts));
});

gulp.task('static-files', function () {
    return gulp.src(config.appFiles.staticFiles)
        .pipe(gulp.dest(config.outputPaths.root));
});

gulp.task('favicon', function () {
    return gulp.src(config.appFiles.favicon)
        .pipe(gulp.dest(config.outputPaths.root));
});

gulp.task('images', function () {
    var options = {
        optimizationLevel: 3,
        progressive: true,
        interlaced: true,
        multipass: true,
        svgoPlugins: [{removeViewBox: false}],
        use: [pngquant()]
    };
    return gulp.src(config.appFiles.images)
        .pipe(gulpIf(shouldMinify(), imagemin(options)))
        .pipe(gulp.dest(config.outputPaths.images))
        .pipe(connect.reload());
});

gulp.task('build-index', gulpSync.sync(['clean', 'work']), function () {
    var jsFiles = gulp.src([
        config.outputPaths.js + '/vendor*.js',
        config.outputPaths.js + '/templates*.js',
        config.outputPaths.js + '/build*.js'
    ], {
        read: false
    });

    var cssFiles = gulp.src([
        config.outputPaths.css + '/vendor*.css',
        config.outputPaths.css + '/build*.css'
    ], {
        read: false
    });
    var options = {
        ignorePath: config.outputPaths.injectIgnoreString,
        addRootSlash: false,
        read: false
    };
    console.log('Environment: %s', environment);
    return gulp.src(config.appFiles.index)
        .pipe(wait(1000))
        .pipe(inject(cssFiles, options))
        .pipe(inject(jsFiles, options))
        .pipe(gulp.dest(config.outputPaths.root))
        .pipe(connect.reload());
});

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

gulp.task('work', ['html', 'vendor-css', 'less', 'vendor-js', 'app-js', 'static-font', 'font', 'favicon', 'images']);

gulp.task('watch', ['build-index', 'connect'], function () {
    gulp.watch(config.watch.less, ['less']);
    gulp.watch(config.watch.js, ['app-js']);
    gulp.watch(config.watch.html, ['html']);
    gulp.watch(config.watch.images, ['images']);
    gulp.watch(config.watch.constants, ['app-js']);
});

gulp.task('connect', ['build-index'], function () {
    connect.server({
        root: config.outputPaths.root,
        port: 9000,
        livereload: true,
        fallback: config.outputPaths.root + '/index.html'
    });
});

gulp.task('start', function () {
    connect.server({
        root: config.outputPaths.root,
        port: 9000,
        livereload: false,
        fallback: config.outputPaths.root + '/index.html'
    });
});

function shouldRevision() {
    if (environment === 'dev' || environment === 'localqa') {
        return false;
    }
    return true;
}

function shouldMinify() {
    if (environment === 'dev' || environment === 'localqa') {
        return false;
    }
    return true;
}
<|endoftext|>


<commit_before>var gulp         = require('gulp');
var sass         = require('gulp-sass');
var less         = require('gulp-less');
var image        = require('gulp-image');
var uglify       = require('gulp-uglify');
var gulpIgnore   = require('gulp-ignore');
var cssnano      = require('gulp-cssnano');
var htmlmin      = require('gulp-htmlmin');
var changed      = require('gulp-changed');
var imageResize  = require('gulp-image-resize');
var autoprefixer = require('gulp-autoprefixer');
var prettify     = require('gulp-jsbeautifier');
var runSequence  = require('run-sequence');
var serveStatic  = require('serve-static');
var compression  = require('compression');
var fs           = require('file-system');
var sizeOf       = require('image-size');
var express      = require('express');
var http         = require('http');
var http2        = require('spdy');
var del          = require('del');
var opn          = require('opn');
var useref       = require('gulp-useref');

require('dotenv').config();

var imgPrefs = {
    pngquant: true,
    optipng: false,
    zopflipng: true,
    jpegRecompress: false,
    mozjpeg: true,
    guetzli: false,
    gifsicle: false,
    svgo: true,
    concurrent: 10
};

// https server with gzip and http2 (only if cert and key exist)

gulp.task('server', function(){
    fs.open('./.env', 'r', (err) => {
        if(err){
            if (err.code === 'ENOENT') {
                console.log('.env file not found');
                console.log("https://localhost:8888 only available when ssl cert and key are found");
                console.log("http://localhost:8888 in use");
                var dist = express();
                dist.use(compression())
                dist.use(serveStatic('./dist', {
                    'extensions': ['html'],
                    'maxAge': 3600000
                }))
                var disthttpsServer = http.createServer(dist);
                disthttpsServer.listen(8888);
                var dev = express();
                dev.use(compression())
                dev.use(serveStatic('./dev', {
                    'extensions': ['html'],
                    'maxAge': 3600000
                }))
                var devhttpsServer = http.createServer(dev);
                devhttpsServer.listen(8887);
            }
        } else {
            fs.readFile('./.env', 'utf8', (err, data) => {
                if( data.indexOf('SSL_CRT_PATH') < 0 || data.indexOf('SSL_KEY_PATH') < 0 ){
                    if(data.indexOf('SSL_CRT_PATH') < 0 ){
                        console.log("no 'SSL_CRT_PATH' found in .env file");
                    }
                    if(data.indexOf('SSL_KEY_PATH') < 0 ){
                        console.log("no 'SSL_KEY_PATH' found in .env file");
                    }
                    console.log("https://localhost:8888 only available when ssl cert and key are found");
                    console.log("http://localhost:8888 in use");
                    var dist = express();
                    dist.use(compression())
                    dist.use(serveStatic('./dist', {
                        'extensions': ['html'],
                        'maxAge': 3600000
                    }))
                    var disthttpsServer = http.createServer(dist);
                    disthttpsServer.listen(8888);
                    opn('http://localhost:8888');
                    var dev = express();
                    dev.use(compression())
                    dev.use(serveStatic('./dev', {
                        'extensions': ['html'],
                        'maxAge': 3600000
                    }))
                    var devhttpsServer = http.createServer(dev);
                    devhttpsServer.listen(8887);
                    opn('http://localhost:8887');
                } else {
                    sslCrt = process.env.HOME + process.env.SSL_CRT_PATH
                    sslKey = process.env.HOME + process.env.SSL_KEY_PATH
                    var privateKey  = fs.readFileSync(sslKey, 'utf8');
                    var certificate = fs.readFileSync(sslCrt, 'utf8');
                    var credentials = {key: privateKey, cert: certificate};
                    var dist = express();
                    dist.use(compression())
                    dist.use(serveStatic('./dist', {
                        'extensions': ['html'],
                        'maxAge': 3600000
                    }))
                    var disthttpsServer = http2.createServer(credentials, dist);

                    disthttpsServer.listen(8888);
                    console.log("https://localhost:8888");
                    //opn('https://localhost:8888');

                    var dev = express();
                    dev.use(compression())
                    dev.use(serveStatic('./dist', {
                        'extensions': ['html'],
                        'maxAge': 3600000
                    }))
                    var devhttpsServer = http2.createServer(credentials, dev);
                    devhttpsServer.listen(8887);
                    console.log("https://localhost:8887");
                    //opn('https://localhost:8887');
                }
            })
        }
    })
})

// less compilation + minification

gulp.task('less', function () {
  return gulp.src('src/less/**/*.less')
    .pipe(changed('dist/css'))
    .pipe(less())
    .pipe( autoprefixer({
            browsers: ['>1%'],
            cascade: false
    }))
    .pipe(gulp.dest('dev/css'))
    .pipe(cssnano())
    .pipe(gulp.dest('dist/css'))
})

// sass compilation + minification

gulp.task('sass', function () {
  return gulp.src('src/sass/**/*.scss')
    .pipe(changed('dist/css'))
    .pipe(sass())
    .pipe(autoprefixer({
            browsers: ['>1%'],
            cascade: false
    }))
    .pipe(gulp.dest('dev/css'))
    .pipe(cssnano())
    .pipe(gulp.dest('dist/css'))
})

// css minification

gulp.task('css', function() {
  return gulp.src('src/css/**/*.css')
    .pipe(changed('dist/css'))
    .pipe(autoprefixer({
    browsers: ['>1%'],
    cascade: false
    }))
    .pipe(gulp.dest('dev/css'))
    .pipe(cssnano())
    .pipe(gulp.dest('dist/css'))
})

// js minification + uglification

gulp.task('js', function() {
  return gulp.src('src/js/**/*.js')
  .pipe(changed('dist/js'))
  .pipe(gulp.dest('dev/js'))
  .pipe(uglify())
  .pipe(gulp.dest('dist/js'))
})

// image optimization

gulp.task('images', function() {
  return gulp.src('src/images/**/*.{png,jpg,jpeg,gif,svg}')
  .pipe(changed('dist/images'))
  .pipe(image(imgPrefs))
  .pipe(gulp.dest('dist/images'))
  .pipe(gulp.dest('dev/images'))
})

// html minification

gulp.task('html', function() {
  return gulp.src('src/**/*.html')
  .pipe(changed('dist'))
  .pipe(gulp.dest('dist'))
  .pipe(htmlmin({
    collapseWhitespace: true,
    removeComments: true,
    minifyCSS: true,
    minifyJS: true
  }))
  .pipe(gulp.dest('dev'))
})

// useref test

gulp.task('combine', function(){
    return gulp.src('dist/**/*.html')
    .pipe(useref())
    .pipe(htmlmin({
        collapseWhitespace: true,
        removeComments: true,
        minifyCSS: true,
        minifyJS: true
    }))
    .pipe(gulp.dest('dist'))
})

// copy everything else

gulp.task('other', function() {
  return gulp.src(['src/**/*.*', '!src/**/*.html', '!src/**/*.css', '!src/**/*.js', '!src/**/*.less', '!src/**/*.scss', '!src/images/*.png', '!src/images/*.jpg', '!src/images/*.jpeg', '!src/images/*.gif', '!src/images/*.svg' ])
  .pipe(changed('dist'))
  .pipe(gulp.dest('dev'))
  .pipe(gulp.dest('dist'))
})

// Cleaning

gulp.task('clean', function() {
  return del.sync(['dist', 'dev'])
})

gulp.task('clean:dev', function() {
  return del.sync('dev')
})

gulp.task('clean:dist', function() {
  return del.sync('dist')
})

gulp.task('clean:code', function() {
  return del.sync(['dist/**/*', '!dist/images', '!dist/images/**/*', 'dev/**/*', '!dev/images', '!dev/images/**/*'])
})

// Prettify css js html

gulp.task('prettify:dev', function() {
  return gulp.src('dev/**/*.+(html|css|js|less|scss)')
    .pipe(prettify())
    .pipe(gulp.dest('dev'))
})

gulp.task('prettify:src', function() {
  return gulp.src('src/**/*.+(html|css|js|less|scss)')
    .pipe(prettify())
    .pipe(gulp.dest('src'))
})

/* TODO optimize */

var lt256 = function (file) {
    var dimensions = sizeOf(file.path);
    if(dimensions.width > 256) {
        return false;
    }else{
        return true;
    }
};
var lt512 = function (file) {
    var dimensions = sizeOf(file.path);
    if(dimensions.width > 512) {
        return false;
    }else{
        return true;
    }
};
var lt1024 = function (file) {
    var dimensions = sizeOf(file.path);
    if(dimensions.width > 1024) {
        return false;
    }else{
        return true;
    }
};
var lt2048 = function (file) {
    var dimensions = sizeOf(file.path);
    if(dimensions.width > 2048) {
        return false;
    }else{
        return true;
    }
};

gulp.task('resize256', function() {
  return gulp.src('src/images/**/*.{jpg,jpeg,png,gif}')
    .pipe(changed('dist/images/256'))
    .pipe(gulpIgnore(lt256))
    .pipe(imageResize({
      width : 256
    }))
    .pipe(image(imgPrefs))
    .pipe(gulp.dest('dev/images/256'))
    .pipe(gulp.dest('dist/images/256'))
})

gulp.task('resize512', function() {
  return gulp.src('src/images/**/*.{jpg,jpeg,png,gif}')
    .pipe(changed('dist/images/512'))
    .pipe(gulpIgnore(lt512))
    .pipe(imageResize({
      width : 512
    }))
    .pipe(image(imgPrefs))
    .pipe(gulp.dest('dev/images/512'))
    .pipe(gulp.dest('dist/images/512'))
})

gulp.task('resize1024', function() {
  return gulp.src('src/images/**/*.{jpg,jpeg,png,gif}')
    .pipe(changed('dist/images/1024'))
    .pipe(gulpIgnore(lt1024))
    .pipe(imageResize({
      width : 1024
    }))
    .pipe(image(imgPrefs))
    .pipe(gulp.dest('dev/images/1024'))
    .pipe(gulp.dest('dist/images/1024'))
})

gulp.task('resize2048', function() {
  return gulp.src('src/images/**/*.{jpg,jpeg,png,gif}')
    .pipe(changed('dist/images/2048'))
    .pipe(gulpIgnore(lt2048))
    .pipe(imageResize({
      width : 2048
    }))
    .pipe(image(imgPrefs))
    .pipe(gulp.dest('dev/images/2048'))
    .pipe(gulp.dest('dist/images/2048'))
})

gulp.task('resize', function(callback) {
  runSequence(
    'resize2048',
    'resize1024',
    'resize512',
    'resize256',
    callback
  )
})

// Build

gulp.task('build', function(callback) {
  runSequence(
    'less',
    'sass',
    'css',
    'js',
    'images',
    'resize',
    'html',
    'combine',
    'other',
    'prettify:dev',
    callback
  )
})

// Watch

gulp.task('watch', function() {
    gulp.watch('src/**/*', ['build'])
})

// Gulp - Build + Watch + start-servers

gulp.task('default', function(callback) {
  runSequence(
    'build',
    'watch',
    'server',
    callback
  )
})
<commit_msg>serve dev not dist for dev server<commit_after>var gulp         = require('gulp');
var sass         = require('gulp-sass');
var less         = require('gulp-less');
var image        = require('gulp-image');
var uglify       = require('gulp-uglify');
var gulpIgnore   = require('gulp-ignore');
var cssnano      = require('gulp-cssnano');
var htmlmin      = require('gulp-htmlmin');
var changed      = require('gulp-changed');
var imageResize  = require('gulp-image-resize');
var autoprefixer = require('gulp-autoprefixer');
var prettify     = require('gulp-jsbeautifier');
var runSequence  = require('run-sequence');
var serveStatic  = require('serve-static');
var compression  = require('compression');
var fs           = require('file-system');
var sizeOf       = require('image-size');
var express      = require('express');
var http         = require('http');
var http2        = require('spdy');
var del          = require('del');
var opn          = require('opn');
var useref       = require('gulp-useref');

require('dotenv').config();

var imgPrefs = {
    pngquant: true,
    optipng: false,
    zopflipng: true,
    jpegRecompress: false,
    mozjpeg: true,
    guetzli: false,
    gifsicle: false,
    svgo: true,
    concurrent: 10
};

// https server with gzip and http2 (only if cert and key exist)

gulp.task('server', function(){
    fs.open('./.env', 'r', (err) => {
        if(err){
            if (err.code === 'ENOENT') {
                console.log('.env file not found');
                console.log("https://localhost:8888 only available when ssl cert and key are found");
                console.log("http://localhost:8888 in use");
                var dist = express();
                dist.use(compression())
                dist.use(serveStatic('./dist', {
                    'extensions': ['html'],
                    'maxAge': 3600000
                }))
                var disthttpsServer = http.createServer(dist);
                disthttpsServer.listen(8888);
                var dev = express();
                dev.use(compression())
                dev.use(serveStatic('./dev', {
                    'extensions': ['html'],
                    'maxAge': 3600000
                }))
                var devhttpsServer = http.createServer(dev);
                devhttpsServer.listen(8887);
            }
        } else {
            fs.readFile('./.env', 'utf8', (err, data) => {
                if( data.indexOf('SSL_CRT_PATH') < 0 || data.indexOf('SSL_KEY_PATH') < 0 ){
                    if(data.indexOf('SSL_CRT_PATH') < 0 ){
                        console.log("no 'SSL_CRT_PATH' found in .env file");
                    }
                    if(data.indexOf('SSL_KEY_PATH') < 0 ){
                        console.log("no 'SSL_KEY_PATH' found in .env file");
                    }
                    console.log("https://localhost:8888 only available when ssl cert and key are found");
                    console.log("http://localhost:8888 in use");
                    var dist = express();
                    dist.use(compression())
                    dist.use(serveStatic('./dist', {
                        'extensions': ['html'],
                        'maxAge': 3600000
                    }))
                    var disthttpsServer = http.createServer(dist);
                    disthttpsServer.listen(8888);
                    opn('http://localhost:8888');
                    var dev = express();
                    dev.use(compression())
                    dev.use(serveStatic('./dev', {
                        'extensions': ['html'],
                        'maxAge': 3600000
                    }))
                    var devhttpsServer = http.createServer(dev);
                    devhttpsServer.listen(8887);
                    opn('http://localhost:8887');
                } else {
                    sslCrt = process.env.HOME + process.env.SSL_CRT_PATH
                    sslKey = process.env.HOME + process.env.SSL_KEY_PATH
                    var privateKey  = fs.readFileSync(sslKey, 'utf8');
                    var certificate = fs.readFileSync(sslCrt, 'utf8');
                    var credentials = {key: privateKey, cert: certificate};
                    var dist = express();
                    dist.use(compression())
                    dist.use(serveStatic('./dist', {
                        'extensions': ['html'],
                        'maxAge': 3600000
                    }))
                    var disthttpsServer = http2.createServer(credentials, dist);

                    disthttpsServer.listen(8888);
                    console.log("https://localhost:8888");
                    //opn('https://localhost:8888');

                    var dev = express();
                    dev.use(compression())
                    dev.use(serveStatic('./dev', {
                        'extensions': ['html'],
                        'maxAge': 3600000
                    }))
                    var devhttpsServer = http2.createServer(credentials, dev);
                    devhttpsServer.listen(8887);
                    console.log("https://localhost:8887");
                    //opn('https://localhost:8887');
                }
            })
        }
    })
})

// less compilation + minification

gulp.task('less', function () {
  return gulp.src('src/less/**/*.less')
    .pipe(changed('dist/css'))
    .pipe(less())
    .pipe( autoprefixer({
            browsers: ['>1%'],
            cascade: false
    }))
    .pipe(gulp.dest('dev/css'))
    .pipe(cssnano())
    .pipe(gulp.dest('dist/css'))
})

// sass compilation + minification

gulp.task('sass', function () {
  return gulp.src('src/sass/**/*.scss')
    .pipe(changed('dist/css'))
    .pipe(sass())
    .pipe(autoprefixer({
            browsers: ['>1%'],
            cascade: false
    }))
    .pipe(gulp.dest('dev/css'))
    .pipe(cssnano())
    .pipe(gulp.dest('dist/css'))
})

// css minification

gulp.task('css', function() {
  return gulp.src('src/css/**/*.css')
    .pipe(changed('dist/css'))
    .pipe(autoprefixer({
    browsers: ['>1%'],
    cascade: false
    }))
    .pipe(gulp.dest('dev/css'))
    .pipe(cssnano())
    .pipe(gulp.dest('dist/css'))
})

// js minification + uglification

gulp.task('js', function() {
  return gulp.src('src/js/**/*.js')
  .pipe(changed('dist/js'))
  .pipe(gulp.dest('dev/js'))
  .pipe(uglify())
  .pipe(gulp.dest('dist/js'))
})

// image optimization

gulp.task('images', function() {
  return gulp.src('src/images/**/*.{png,jpg,jpeg,gif,svg}')
  .pipe(changed('dist/images'))
  .pipe(image(imgPrefs))
  .pipe(gulp.dest('dist/images'))
  .pipe(gulp.dest('dev/images'))
})

// html minification

gulp.task('html', function() {
  return gulp.src('src/**/*.html')
  .pipe(changed('dist'))
  .pipe(gulp.dest('dist'))
  .pipe(htmlmin({
    collapseWhitespace: true,
    removeComments: true,
    minifyCSS: true,
    minifyJS: true
  }))
  .pipe(gulp.dest('dev'))
})

// useref test

gulp.task('combine', function(){
    return gulp.src('dist/**/*.html')
    .pipe(useref())
    .pipe(htmlmin({
        collapseWhitespace: true,
        removeComments: true,
        minifyCSS: true,
        minifyJS: true
    }))
    .pipe(gulp.dest('dist'))
})

// copy everything else

gulp.task('other', function() {
  return gulp.src(['src/**/*.*', '!src/**/*.html', '!src/**/*.css', '!src/**/*.js', '!src/**/*.less', '!src/**/*.scss', '!src/images/*.png', '!src/images/*.jpg', '!src/images/*.jpeg', '!src/images/*.gif', '!src/images/*.svg' ])
  .pipe(changed('dist'))
  .pipe(gulp.dest('dev'))
  .pipe(gulp.dest('dist'))
})

// Cleaning

gulp.task('clean', function() {
  return del.sync(['dist', 'dev'])
})

gulp.task('clean:dev', function() {
  return del.sync('dev')
})

gulp.task('clean:dist', function() {
  return del.sync('dist')
})

gulp.task('clean:code', function() {
  return del.sync(['dist/**/*', '!dist/images', '!dist/images/**/*', 'dev/**/*', '!dev/images', '!dev/images/**/*'])
})

// Prettify css js html

gulp.task('prettify:dev', function() {
  return gulp.src('dev/**/*.+(html|css|js|less|scss)')
    .pipe(prettify())
    .pipe(gulp.dest('dev'))
})

gulp.task('prettify:src', function() {
  return gulp.src('src/**/*.+(html|css|js|less|scss)')
    .pipe(prettify())
    .pipe(gulp.dest('src'))
})

/* TODO optimize */

var lt256 = function (file) {
    var dimensions = sizeOf(file.path);
    if(dimensions.width > 256) {
        return false;
    }else{
        return true;
    }
};
var lt512 = function (file) {
    var dimensions = sizeOf(file.path);
    if(dimensions.width > 512) {
        return false;
    }else{
        return true;
    }
};
var lt1024 = function (file) {
    var dimensions = sizeOf(file.path);
    if(dimensions.width > 1024) {
        return false;
    }else{
        return true;
    }
};
var lt2048 = function (file) {
    var dimensions = sizeOf(file.path);
    if(dimensions.width > 2048) {
        return false;
    }else{
        return true;
    }
};

gulp.task('resize256', function() {
  return gulp.src('src/images/**/*.{jpg,jpeg,png,gif}')
    .pipe(changed('dist/images/256'))
    .pipe(gulpIgnore(lt256))
    .pipe(imageResize({
      width : 256
    }))
    .pipe(image(imgPrefs))
    .pipe(gulp.dest('dev/images/256'))
    .pipe(gulp.dest('dist/images/256'))
})

gulp.task('resize512', function() {
  return gulp.src('src/images/**/*.{jpg,jpeg,png,gif}')
    .pipe(changed('dist/images/512'))
    .pipe(gulpIgnore(lt512))
    .pipe(imageResize({
      width : 512
    }))
    .pipe(image(imgPrefs))
    .pipe(gulp.dest('dev/images/512'))
    .pipe(gulp.dest('dist/images/512'))
})

gulp.task('resize1024', function() {
  return gulp.src('src/images/**/*.{jpg,jpeg,png,gif}')
    .pipe(changed('dist/images/1024'))
    .pipe(gulpIgnore(lt1024))
    .pipe(imageResize({
      width : 1024
    }))
    .pipe(image(imgPrefs))
    .pipe(gulp.dest('dev/images/1024'))
    .pipe(gulp.dest('dist/images/1024'))
})

gulp.task('resize2048', function() {
  return gulp.src('src/images/**/*.{jpg,jpeg,png,gif}')
    .pipe(changed('dist/images/2048'))
    .pipe(gulpIgnore(lt2048))
    .pipe(imageResize({
      width : 2048
    }))
    .pipe(image(imgPrefs))
    .pipe(gulp.dest('dev/images/2048'))
    .pipe(gulp.dest('dist/images/2048'))
})

gulp.task('resize', function(callback) {
  runSequence(
    'resize2048',
    'resize1024',
    'resize512',
    'resize256',
    callback
  )
})

// Build

gulp.task('build', function(callback) {
  runSequence(
    'less',
    'sass',
    'css',
    'js',
    'images',
    'resize',
    'html',
    'combine',
    'other',
    'prettify:dev',
    callback
  )
})

// Watch

gulp.task('watch', function() {
    gulp.watch('src/**/*', ['build'])
})

// Gulp - Build + Watch + start-servers

gulp.task('default', function(callback) {
  runSequence(
    'build',
    'watch',
    'server',
    callback
  )
})
<|endoftext|>


<commit_before>'use strict';

// Require the needed npm modules.
const gulp = require('gulp'),
	uglify = require('gulp-uglify'),
	rename = require('gulp-rename'),
	sass = require('gulp-sass'),
	maps = require('gulp-sourcemaps'),
	useref = require('gulp-useref'),
	iff = require('gulp-if'),
	csso = require('gulp-csso'),
	concat = require('gulp-concat'),
	del = require('del');

const options = {
	src: 'src',
	dist: 'dist`'
};

// This task may be redundant due to 'minifyScripts' task.  Delete it?
gulp.task('concatScripts', function() {
	gulp.src(['js/**/*', 'js/*'])
		.pipe(concat('all.min.js'))
		.pipe(gulp.dest('js'));
});

gulp.task('minifyScripts', function() {
	gulp.src(['js/*/*'])
		.pipe(uglify())
		.pipe(rename('all.min.js'))
		.pipe(gulp.dest('dist/scripts/'));
});
<commit_msg>Added 'styles' task to compile, concat & minify all of the SaSS files.<commit_after>'use strict';

// Require the needed npm modules.
const gulp = require('gulp'),
	uglify = require('gulp-uglify'),
	rename = require('gulp-rename'),
	sass = require('gulp-sass'),
	maps = require('gulp-sourcemaps'),
	useref = require('gulp-useref'),
	iff = require('gulp-if'),
	csso = require('gulp-csso'),
	concat = require('gulp-concat'),
	del = require('del');

const options = {
	src: 'src',
	dist: 'dist`'
};

// This task may be redundant due to 'minifyScripts' task.  Delete it?
gulp.task('concatScripts', function() {
	gulp.src(['js/**/*', 'js/*'])
		.pipe(concat('all.min.js'))
		.pipe(gulp.dest('js'));
});

gulp.task('minifyScripts', function() {
	gulp.src(['js/*/*'])
		.pipe(uglify())
		.pipe(rename('all.min.js'))
		.pipe(gulp.dest('dist/scripts/'));
});

gulp.task('styles', function() {
	return gulp.src(['sass/global.scss'])
			.pipe(sass())
			.pipe(csso())
			.pipe(rename('all.min.css'))
			.pipe(gulp.dest('dist/styles/'));
});

//
<|endoftext|>


<commit_before>/* -------------------------------------------------------------------------------------------------

Build Configuration
Contributors: Luan Gjokaj, Adam McKenna, Mehdi Rezaei, Sören Wrede, Saneef Ansari

-------------------------------------------------------------------------------------------------- */
const babel = require('gulp-babel');
const browserSync = require('browser-sync');
const concat = require('gulp-concat');
const connect = require('gulp-connect-php');
const del = require('del');
const fs = require('fs');
const gulp = require('gulp');
const gutil = require('gulp-util');
const imagemin = require('gulp-imagemin');
const inject = require('gulp-inject-string');
const partialimport = require('postcss-easy-import');
const plumber = require('gulp-plumber');
const postcss = require('gulp-postcss');
const postCSSMixins = require('postcss-mixins');
const postcssPresetEnv = require('postcss-preset-env');
const remoteSrc = require('gulp-remote-src');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
const unzip = require('gulp-unzip');
const zip = require('gulp-zip');

/* -------------------------------------------------------------------------------------------------
Theme Name
-------------------------------------------------------------------------------------------------- */
const themeName = 'wordpressify';

/* -------------------------------------------------------------------------------------------------
PostCSS Plugins
-------------------------------------------------------------------------------------------------- */
const pluginsDev = [
	partialimport,
	postCSSMixins,
	postcssPresetEnv({
		stage: 0,
		features: {
			'nesting-rules': true,
			'color-mod-function': true,
			'custom-media': true,
		},
	}),
];
const pluginsProd = [
	partialimport,
	postCSSMixins,
	postcssPresetEnv({
		stage: 0,
		features: {
			'nesting-rules': true,
			'color-mod-function': true,
			'custom-media': true,
		},
	}),
];

/* -------------------------------------------------------------------------------------------------
Header & Footer JavaScript Boundles
-------------------------------------------------------------------------------------------------- */
const headerJS = [
	'node_modules/jquery/dist/jquery.js',
	'node_modules/nprogress/nprogress.js',
	'node_modules/aos/dist/aos.js',
	'node_modules/isotope-layout/dist/isotope.pkgd.js',
];
const footerJS = ['src/js/**'];

/* -------------------------------------------------------------------------------------------------
Installation Tasks
-------------------------------------------------------------------------------------------------- */
gulp.task('default');

gulp.task('cleanup', () => {
	del(['build/**']);
	del(['dist/**']);
});

gulp.task('download-wordpress', () => {
	remoteSrc(['latest.zip'], {
		base: 'https://wordpress.org/',
	}).pipe(gulp.dest('build/'));
});

gulp.task('setup', ['unzip-wordpress', 'copy-config']);

gulp.task('unzip-wordpress', () => {
	gulp
		.src('build/latest.zip')
		.pipe(unzip())
		.pipe(gulp.dest('build/'));
});

gulp.task('copy-config', () => {
	gulp
		.src('wp-config.php')
		.pipe(inject.after("define('DB_COLLATE', '');", "\ndefine('DISABLE_WP_CRON', true);"))
		.pipe(gulp.dest('build/wordpress'))
		.on('end', () => {
			gutil.beep();
			gutil.log(devServerReady);
			gutil.log(thankYou);
		});
});

gulp.task('disable-cron', () => {
	fs.readFile('./build/wordpress/wp-config.php', (err, data) => {
		if (err) {
			gutil.log(
				wpFy + ' - ' + errorMsg + ' wp-config.php still missing... WP_CRON was not disabled!',
			);
		}
		if (data) {
			if (data.indexOf('DISABLE_WP_CRON') >= 0) {
				gutil.log('WP_CRON is already disabled!');
			} else {
				gulp
					.src('build/wordpress/wp-config.php')
					.pipe(inject.after("define('DB_COLLATE', '');", "\ndefine('DISABLE_WP_CRON', true);"))
					.pipe(gulp.dest('build/wordpress'));
			}
		}
	});
});

gulp.task('fresh-install', () => {
	del(['src/**']).then(() => {
		gulp.src('tools/fresh-theme/**').pipe(gulp.dest('src'));
	});
});

/* -------------------------------------------------------------------------------------------------
Development Tasks
-------------------------------------------------------------------------------------------------- */
gulp.task(
	'build-dev',
	[
		'copy-theme-dev',
		'copy-fonts-dev',
		'style-dev',
		'header-scripts-dev',
		'footer-scripts-dev',
		'plugins-dev',
		'watch',
	],
	() => {
		connect.server(
			{
				base: 'build/wordpress',
				port: '3020',
			},
			() => {
				browserSync({
					proxy: '127.0.0.1:3020',
				});
			},
		);
	},
);

gulp.task('copy-theme-dev', () => {
	if (!fs.existsSync('./build')) {
		gutil.log(buildNotFound);
		process.exit(1);
	} else {
		gulp.src('src/theme/**').pipe(gulp.dest('build/wordpress/wp-content/themes/' + themeName));
	}
});

gulp.task('copy-fonts-dev', () => {
	gulp
		.src('src/fonts/**')
		.pipe(gulp.dest('build/wordpress/wp-content/themes/' + themeName + '/fonts'));
});

gulp.task('style-dev', () => {
	return gulp
		.src('src/style/style.css')
		.pipe(plumber({ errorHandler: onError }))
		.pipe(sourcemaps.init())
		.pipe(postcss(pluginsDev))
		.pipe(sourcemaps.write('.'))
		.pipe(gulp.dest('build/wordpress/wp-content/themes/' + themeName))
		.pipe(browserSync.stream({ match: '**/*.css' }));
});

gulp.task('header-scripts-dev', () => {
	return gulp
		.src(headerJS)
		.pipe(plumber({ errorHandler: onError }))
		.pipe(sourcemaps.init())
		.pipe(concat('header-bundle.js'))
		.pipe(sourcemaps.write('.'))
		.pipe(gulp.dest('build/wordpress/wp-content/themes/' + themeName + '/js'));
});

gulp.task('footer-scripts-dev', () => {
	return gulp
		.src(footerJS)
		.pipe(plumber({ errorHandler: onError }))
		.pipe(sourcemaps.init())
		.pipe(
			babel({
				presets: ['@babel/preset-env'],
			}),
		)
		.pipe(concat('footer-bundle.js'))
		.pipe(sourcemaps.write('.'))
		.pipe(gulp.dest('build/wordpress/wp-content/themes/' + themeName + '/js'));
});

gulp.task('plugins-dev', () => {
	return gulp.src('src/plugins/**').pipe(gulp.dest('build/wordpress/wp-content/plugins'));
});

gulp.task('reload-js', ['footer-scripts-dev', 'header-scripts-dev'], done => {
	browserSync.reload();
	done();
});

gulp.task('reload-fonts', ['copy-fonts-dev'], done => {
	browserSync.reload();
	done();
});

gulp.task('reload-theme', ['copy-theme-dev'], done => {
	browserSync.reload();
	done();
});

gulp.task('reload-plugins', ['plugins-dev'], done => {
	browserSync.reload();
	done();
});

gulp.task('watch', () => {
	gulp.watch(['src/style/**/*.css'], ['style-dev']);
	gulp.watch(['src/js/**'], ['reload-js']);
	gulp.watch(['src/fonts/**'], ['reload-fonts']);
	gulp.watch(['src/theme/**'], ['reload-theme']);
	gulp.watch(['src/plugins/**'], ['reload-plugins']);
	gulp.watch('build/wordpress/wp-config*.php', event => {
		if (event.type === 'added') {
			gulp.start('disable-cron');
		}
	});
});

/* -------------------------------------------------------------------------------------------------
Production Tasks
-------------------------------------------------------------------------------------------------- */
gulp.task('build-prod', [
	'copy-theme-prod',
	'copy-fonts-prod',
	'style-prod',
	'header-scripts-prod',
	'footer-scripts-prod',
	'plugins-prod',
	'zip-theme',
]);

gulp.task('copy-theme-prod', () => {
	gulp.src(['src/theme/**', '!src/theme/img/**']).pipe(gulp.dest('dist/themes/' + themeName));
});

gulp.task('copy-fonts-prod', () => {
	gulp.src('src/fonts/**').pipe(gulp.dest('dist/themes/' + themeName + '/fonts'));
});

gulp.task('process-images', ['copy-theme-prod'], () => {
	return gulp
		.src('src/theme/img/**')
		.pipe(plumber({ errorHandler: onError }))
		.pipe(
			imagemin([imagemin.svgo({ plugins: [{ removeViewBox: true }] })], {
				verbose: true,
			}),
		)
		.pipe(gulp.dest('dist/themes/' + themeName + '/img'));
});

gulp.task('style-prod', () => {
	return gulp
		.src('src/style/style.css')
		.pipe(plumber({ errorHandler: onError }))
		.pipe(postcss(pluginsProd))
		.pipe(gulp.dest('dist/themes/' + themeName));
});

gulp.task('header-scripts-prod', () => {
	return gulp
		.src(headerJS)
		.pipe(plumber({ errorHandler: onError }))
		.pipe(concat('header-bundle.js'))
		.pipe(uglify())
		.pipe(gulp.dest('dist/themes/' + themeName + '/js'));
});

gulp.task('footer-scripts-prod', () => {
	return gulp
		.src(footerJS)
		.pipe(plumber({ errorHandler: onError }))
		.pipe(
			babel({
				presets: ['@babel/preset-env'],
			}),
		)
		.pipe(concat('footer-bundle.js'))
		.pipe(uglify())
		.pipe(gulp.dest('dist/themes/' + themeName + '/js'));
});

gulp.task('plugins-prod', () => {
	return gulp.src('src/plugins/**').pipe(gulp.dest('dist/plugins'));
});

gulp.task(
	'zip-theme',
	[
		'copy-theme-prod',
		'copy-fonts-prod',
		'process-images',
		'style-prod',
		'header-scripts-prod',
		'footer-scripts-prod',
		'plugins-prod',
	],
	() => {
		gulp
			.src('dist/themes/' + themeName + '/**')
			.pipe(zip(themeName + '.zip'))
			.pipe(gulp.dest('dist'))
			.on('end', () => {
				gutil.beep();
				gutil.log(pluginsGenerated);
				gutil.log(filesGenerated);
				gutil.log(thankYou);
			});
	},
);

/* -------------------------------------------------------------------------------------------------
Utility Tasks
-------------------------------------------------------------------------------------------------- */
const onError = err => {
	gutil.beep();
	gutil.log(wpFy + ' - ' + errorMsg + ' ' + err.toString());
	this.emit('end');
};

const date = new Date().toLocaleDateString('en-GB').replace(/\//g, '.');
const errorMsg = '\x1b[41mError\x1b[0m';
const devServerReady =
	'Your development server is ready, start the workflow with the command: $ \x1b[1mnpm run dev\x1b[0m';
const buildNotFound =
	errorMsg +
	' ⚠　- You need to install WordPress first. Run the command: $ \x1b[1mnpm run install:wordpress\x1b[0m';
const filesGenerated =
	'Your ZIP template file was generated in: \x1b[1m' +
	__dirname +
	'/dist/' +
	themeName +
	'.zip\x1b[0m - ✅';
const pluginsGenerated =
	'Plugins are generated in: \x1b[1m' + __dirname + '/dist/plugins/\x1b[0m - ✅';
const backupsGenerated =
	'Your backup was generated in: \x1b[1m' + __dirname + '/backups/' + date + '.zip\x1b[0m - ✅';
const wpFy = '\x1b[42m\x1b[1mWordPressify\x1b[0m';
const wpFyUrl = '\x1b[2m - http://www.wordpressify.co/\x1b[0m';
const thankYou = 'Thank you for using ' + wpFy + wpFyUrl;

gulp.task('backup', () => {
	if (!fs.existsSync('./build')) {
		gutil.log(buildNotFound);
		process.exit(1);
	} else {
		gulp
			.src('build/wordpress/**')
			.pipe(zip(date + '.zip'))
			.pipe(gulp.dest('backups'))
			.on('end', () => {
				gutil.beep();
				gutil.log(backupsGenerated);
				gutil.log(thankYou);
			});
	}
});

/* -------------------------------------------------------------------------------------------------
End of all Tasks
-------------------------------------------------------------------------------------------------- */
<commit_msg>Update console colors<commit_after>/* -------------------------------------------------------------------------------------------------

Build Configuration
Contributors: Luan Gjokaj, Adam McKenna, Mehdi Rezaei, Sören Wrede, Saneef Ansari

-------------------------------------------------------------------------------------------------- */
const babel = require('gulp-babel');
const browserSync = require('browser-sync');
const concat = require('gulp-concat');
const connect = require('gulp-connect-php');
const del = require('del');
const fs = require('fs');
const gulp = require('gulp');
const gutil = require('gulp-util');
const imagemin = require('gulp-imagemin');
const inject = require('gulp-inject-string');
const partialimport = require('postcss-easy-import');
const plumber = require('gulp-plumber');
const postcss = require('gulp-postcss');
const postCSSMixins = require('postcss-mixins');
const postcssPresetEnv = require('postcss-preset-env');
const remoteSrc = require('gulp-remote-src');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
const unzip = require('gulp-unzip');
const zip = require('gulp-zip');

/* -------------------------------------------------------------------------------------------------
Theme Name
-------------------------------------------------------------------------------------------------- */
const themeName = 'wordpressify';

/* -------------------------------------------------------------------------------------------------
PostCSS Plugins
-------------------------------------------------------------------------------------------------- */
const pluginsDev = [
	partialimport,
	postCSSMixins,
	postcssPresetEnv({
		stage: 0,
		features: {
			'nesting-rules': true,
			'color-mod-function': true,
			'custom-media': true,
		},
	}),
];
const pluginsProd = [
	partialimport,
	postCSSMixins,
	postcssPresetEnv({
		stage: 0,
		features: {
			'nesting-rules': true,
			'color-mod-function': true,
			'custom-media': true,
		},
	}),
];

/* -------------------------------------------------------------------------------------------------
Header & Footer JavaScript Boundles
-------------------------------------------------------------------------------------------------- */
const headerJS = [
	'node_modules/jquery/dist/jquery.js',
	'node_modules/nprogress/nprogress.js',
	'node_modules/aos/dist/aos.js',
	'node_modules/isotope-layout/dist/isotope.pkgd.js',
];
const footerJS = ['src/js/**'];

/* -------------------------------------------------------------------------------------------------
Installation Tasks
-------------------------------------------------------------------------------------------------- */
gulp.task('default');

gulp.task('cleanup', () => {
	del(['build/**']);
	del(['dist/**']);
});

gulp.task('download-wordpress', () => {
	remoteSrc(['latest.zip'], {
		base: 'https://wordpress.org/',
	}).pipe(gulp.dest('build/'));
});

gulp.task('setup', ['unzip-wordpress', 'copy-config']);

gulp.task('unzip-wordpress', () => {
	gulp
		.src('build/latest.zip')
		.pipe(unzip())
		.pipe(gulp.dest('build/'));
});

gulp.task('copy-config', () => {
	gulp
		.src('wp-config.php')
		.pipe(inject.after("define('DB_COLLATE', '');", "\ndefine('DISABLE_WP_CRON', true);"))
		.pipe(gulp.dest('build/wordpress'))
		.on('end', () => {
			gutil.beep();
			gutil.log(devServerReady);
			gutil.log(thankYou);
		});
});

gulp.task('disable-cron', () => {
	fs.readFile('./build/wordpress/wp-config.php', (err, data) => {
		if (err) {
			gutil.log(
				wpFy + ' - ' + warning + ' wp-config.php still missing... WP_CRON was not disabled!',
			);
		}
		if (data) {
			if (data.indexOf('DISABLE_WP_CRON') >= 0) {
				gutil.log('WP_CRON is already disabled!');
			} else {
				gulp
					.src('build/wordpress/wp-config.php')
					.pipe(inject.after("define('DB_COLLATE', '');", "\ndefine('DISABLE_WP_CRON', true);"))
					.pipe(gulp.dest('build/wordpress'));
			}
		}
	});
});

gulp.task('fresh-install', () => {
	del(['src/**']).then(() => {
		gulp.src('tools/fresh-theme/**').pipe(gulp.dest('src'));
	});
});

/* -------------------------------------------------------------------------------------------------
Development Tasks
-------------------------------------------------------------------------------------------------- */
gulp.task(
	'build-dev',
	[
		'copy-theme-dev',
		'copy-fonts-dev',
		'style-dev',
		'header-scripts-dev',
		'footer-scripts-dev',
		'plugins-dev',
		'watch',
	],
	() => {
		connect.server(
			{
				base: 'build/wordpress',
				port: '3020',
			},
			() => {
				browserSync({
					proxy: '127.0.0.1:3020',
				});
			},
		);
	},
);

gulp.task('copy-theme-dev', () => {
	if (!fs.existsSync('./build')) {
		gutil.log(buildNotFound);
		process.exit(1);
	} else {
		gulp.src('src/theme/**').pipe(gulp.dest('build/wordpress/wp-content/themes/' + themeName));
	}
});

gulp.task('copy-fonts-dev', () => {
	gulp
		.src('src/fonts/**')
		.pipe(gulp.dest('build/wordpress/wp-content/themes/' + themeName + '/fonts'));
});

gulp.task('style-dev', () => {
	return gulp
		.src('src/style/style.css')
		.pipe(plumber({ errorHandler: onError }))
		.pipe(sourcemaps.init())
		.pipe(postcss(pluginsDev))
		.pipe(sourcemaps.write('.'))
		.pipe(gulp.dest('build/wordpress/wp-content/themes/' + themeName))
		.pipe(browserSync.stream({ match: '**/*.css' }));
});

gulp.task('header-scripts-dev', () => {
	return gulp
		.src(headerJS)
		.pipe(plumber({ errorHandler: onError }))
		.pipe(sourcemaps.init())
		.pipe(concat('header-bundle.js'))
		.pipe(sourcemaps.write('.'))
		.pipe(gulp.dest('build/wordpress/wp-content/themes/' + themeName + '/js'));
});

gulp.task('footer-scripts-dev', () => {
	return gulp
		.src(footerJS)
		.pipe(plumber({ errorHandler: onError }))
		.pipe(sourcemaps.init())
		.pipe(
			babel({
				presets: ['@babel/preset-env'],
			}),
		)
		.pipe(concat('footer-bundle.js'))
		.pipe(sourcemaps.write('.'))
		.pipe(gulp.dest('build/wordpress/wp-content/themes/' + themeName + '/js'));
});

gulp.task('plugins-dev', () => {
	return gulp.src('src/plugins/**').pipe(gulp.dest('build/wordpress/wp-content/plugins'));
});

gulp.task('reload-js', ['footer-scripts-dev', 'header-scripts-dev'], done => {
	browserSync.reload();
	done();
});

gulp.task('reload-fonts', ['copy-fonts-dev'], done => {
	browserSync.reload();
	done();
});

gulp.task('reload-theme', ['copy-theme-dev'], done => {
	browserSync.reload();
	done();
});

gulp.task('reload-plugins', ['plugins-dev'], done => {
	browserSync.reload();
	done();
});

gulp.task('watch', () => {
	gulp.watch(['src/style/**/*.css'], ['style-dev']);
	gulp.watch(['src/js/**'], ['reload-js']);
	gulp.watch(['src/fonts/**'], ['reload-fonts']);
	gulp.watch(['src/theme/**'], ['reload-theme']);
	gulp.watch(['src/plugins/**'], ['reload-plugins']);
	gulp.watch('build/wordpress/wp-config*.php', event => {
		if (event.type === 'added') {
			gulp.start('disable-cron');
		}
	});
});

/* -------------------------------------------------------------------------------------------------
Production Tasks
-------------------------------------------------------------------------------------------------- */
gulp.task('build-prod', [
	'copy-theme-prod',
	'copy-fonts-prod',
	'style-prod',
	'header-scripts-prod',
	'footer-scripts-prod',
	'plugins-prod',
	'zip-theme',
]);

gulp.task('copy-theme-prod', () => {
	gulp.src(['src/theme/**', '!src/theme/img/**']).pipe(gulp.dest('dist/themes/' + themeName));
});

gulp.task('copy-fonts-prod', () => {
	gulp.src('src/fonts/**').pipe(gulp.dest('dist/themes/' + themeName + '/fonts'));
});

gulp.task('process-images', ['copy-theme-prod'], () => {
	return gulp
		.src('src/theme/img/**')
		.pipe(plumber({ errorHandler: onError }))
		.pipe(
			imagemin([imagemin.svgo({ plugins: [{ removeViewBox: true }] })], {
				verbose: true,
			}),
		)
		.pipe(gulp.dest('dist/themes/' + themeName + '/img'));
});

gulp.task('style-prod', () => {
	return gulp
		.src('src/style/style.css')
		.pipe(plumber({ errorHandler: onError }))
		.pipe(postcss(pluginsProd))
		.pipe(gulp.dest('dist/themes/' + themeName));
});

gulp.task('header-scripts-prod', () => {
	return gulp
		.src(headerJS)
		.pipe(plumber({ errorHandler: onError }))
		.pipe(concat('header-bundle.js'))
		.pipe(uglify())
		.pipe(gulp.dest('dist/themes/' + themeName + '/js'));
});

gulp.task('footer-scripts-prod', () => {
	return gulp
		.src(footerJS)
		.pipe(plumber({ errorHandler: onError }))
		.pipe(
			babel({
				presets: ['@babel/preset-env'],
			}),
		)
		.pipe(concat('footer-bundle.js'))
		.pipe(uglify())
		.pipe(gulp.dest('dist/themes/' + themeName + '/js'));
});

gulp.task('plugins-prod', () => {
	return gulp.src('src/plugins/**').pipe(gulp.dest('dist/plugins'));
});

gulp.task(
	'zip-theme',
	[
		'copy-theme-prod',
		'copy-fonts-prod',
		'process-images',
		'style-prod',
		'header-scripts-prod',
		'footer-scripts-prod',
		'plugins-prod',
	],
	() => {
		gulp
			.src('dist/themes/' + themeName + '/**')
			.pipe(zip(themeName + '.zip'))
			.pipe(gulp.dest('dist'))
			.on('end', () => {
				gutil.beep();
				gutil.log(pluginsGenerated);
				gutil.log(filesGenerated);
				gutil.log(thankYou);
			});
	},
);

/* -------------------------------------------------------------------------------------------------
Utility Tasks
-------------------------------------------------------------------------------------------------- */
const onError = err => {
	gutil.beep();
	gutil.log(wpFy + ' - ' + errorMsg + ' ' + err.toString());
	this.emit('end');
};

const date = new Date().toLocaleDateString('en-GB').replace(/\//g, '.');
const errorMsg = '\x1b[41mError\x1b[0m';
const warning = '\x1b[43mWarning\x1b[0m';
const devServerReady =
	'Your development server is ready, start the workflow with the command: $ \x1b[1mnpm run dev\x1b[0m';
const buildNotFound =
	errorMsg +
	' ⚠　- You need to install WordPress first. Run the command: $ \x1b[1mnpm run install:wordpress\x1b[0m';
const filesGenerated =
	'Your ZIP template file was generated in: \x1b[1m' +
	__dirname +
	'/dist/' +
	themeName +
	'.zip\x1b[0m - ✅';
const pluginsGenerated =
	'Plugins are generated in: \x1b[1m' + __dirname + '/dist/plugins/\x1b[0m - ✅';
const backupsGenerated =
	'Your backup was generated in: \x1b[1m' + __dirname + '/backups/' + date + '.zip\x1b[0m - ✅';
const wpFy = '\x1b[42m\x1b[1mWordPressify\x1b[0m';
const wpFyUrl = '\x1b[2m - http://www.wordpressify.co/\x1b[0m';
const thankYou = 'Thank you for using ' + wpFy + wpFyUrl;

gulp.task('backup', () => {
	if (!fs.existsSync('./build')) {
		gutil.log(buildNotFound);
		process.exit(1);
	} else {
		gulp
			.src('build/wordpress/**')
			.pipe(zip(date + '.zip'))
			.pipe(gulp.dest('backups'))
			.on('end', () => {
				gutil.beep();
				gutil.log(backupsGenerated);
				gutil.log(thankYou);
			});
	}
});

/* -------------------------------------------------------------------------------------------------
End of all Tasks
-------------------------------------------------------------------------------------------------- */
<|endoftext|>


<commit_before>
var http = require('http');
var path = require('path');
var gulp = require('gulp');

var gutil = require('gulp-util');
var todo = require('gulp-todo');
var removeLines = require('gulp-remove-lines');
var replace = require('gulp-replace');
var vinylPaths = require('vinyl-paths');
var del = require('del');

var bower = require('gulp-bower');
var concat = require('gulp-concat');
var rename = require("gulp-rename");
var flatten = require("gulp-flatten");

var coffeelint = require('gulp-coffeelint');
var coffee = require('gulp-coffee');
var cjsx = require('gulp-cjsx');
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');

var less = require('gulp-less');
var uncss = require('gulp-uncss');
var minifyCSS = require('gulp-minify-css');

var jade = require('gulp-jade');

var watch = require("gulp-watch");
var nodemon = require("gulp-nodemon");
var livereload = require('gulp-livereload');
var tinylr = require('tiny-lr')();

var LIVERELOAD_PORT = 35729;
var BASEDIR = path.join(__dirname, 'server/views');
var UNCSS_REFERENCE_HTML = [
  'build/index.html'
];
var UNCSS_KEEP_STYLES = [
  /(hover|focus|active)/i,
  /collapse/i,
  /dropdown/i
];
var DIST_PREFIX_PATH = '';

var defaultOptions = function(options) {
  if (typeof options === 'undefined') { options = {}; }
  if (typeof options.copyPaths === 'undefined') { options.copyPaths = ['client/**/*.*', '!client/**/*.{coffee,cjsx,less,css,map,html}']; }
  if (typeof options.prefix != 'string') { options.prefix = ''; }
  if (typeof options.watch != 'boolean') { options.watch = false; }
  return options;
}

var clean = function(paths){
  return gulp.src(paths, {read: false})
    .pipe(vinylPaths(del));
};

var copy = function(destinationPath, options){
  options = defaultOptions(options);
  return gulp.src(options.copyPaths)
    .pipe(gulp.dest(destinationPath))
    .pipe(options.watch === true ? livereload(tinylr) : gutil.noop());
};

var thirdPartyScripts = function(destinationPath) {
  return gulp.src([
    'third-party/jquery/dist/jquery.js',
    'third-party/lodash/dist/lodash.js',
    'third-party/react/react.js',
    'third-party/bootstrap/dist/js/bootstrap.js'
    ])
    .pipe(flatten())
    .pipe(gulp.dest(destinationPath));
};

var cjsxScripts = function(destinationPath, options) {
  options = defaultOptions(options);
  return gulp.src('client/coffee/**/*.cjsx')
    .pipe(cjsx({bare: true}).on('error', gutil.log))
    .pipe(options.prefix.length > 0 ? replace(/\/images\//g, options.prefix + '/images/') : gutil.noop())
    .pipe(replace(/\.(jpg|jpeg|gif|png|svg)$/g, '.$1?' + (new Date()).getTime()))
    .pipe(jshint())
    .pipe(jshint.reporter('default'))
    .pipe(jshint.reporter('fail'))
    .pipe(concat(options.watch === true ? 'react-components.js' : 'react-components.min.js'))
    .pipe(options.watch === false ? uglify() : gutil.noop())
    .pipe(gulp.dest(destinationPath))
    .pipe(options.watch === true ? livereload(tinylr) : gutil.noop());
};

var coffeeScripts = function(destinationPath, options) {
  options = defaultOptions(options);
  return gulp.src(['client/**/*.coffee'])
    .pipe(coffeelint())
    .pipe(coffeelint.reporter())
    .pipe(coffee()).on('error', function(err){ console.log(err.message); })
    .pipe(options.prefix.length > 0 ? replace(/\/images\//g, options.prefix + '/images/') : gutil.noop())
    .pipe(replace(/\.(jpg|jpeg|gif|png|svg)$/g, '.$1?' + (new Date()).getTime()))
    .pipe(jshint())
    .pipe(jshint.reporter('default'))
    .pipe(jshint.reporter('fail'))
    .pipe(concat(options.watch === true ? 'main.js' : 'main.min.js'))
    .pipe(options.watch === false ? uglify() : gutil.noop())
    .pipe(gulp.dest(destinationPath))
    .pipe(options.watch === true ? livereload(tinylr) : gutil.noop());
};

var lessStyles = function(destinationPath, options) {
  options = defaultOptions(options);
  return gulp.src(['client/less/*.less'])
    .pipe(less()).on('error', function(err){ console.log(err.message); })
    .pipe(options.prefix.length > 0 ? replace(/\/images\//g, options.prefix + '/images/') : gutil.noop())
    .pipe(replace(/\.(jpg|jpeg|gif|png|svg)$/g, '.$1?' + (new Date()).getTime()))
    .pipe(options.watch === false ? rename({ extname: '.min.css' }) : gutil.noop())
    .pipe(options.watch === false ? minifyCSS({ removeEmpty: true }) : gutil.noop())
    .pipe(gulp.dest(destinationPath))
    .pipe(options.watch === true ? livereload(tinylr) : gutil.noop());
};

var jadeTemplates = function(destinationPath, options) {
  options = defaultOptions(options);
  var marker = (new Date()).getTime(),
      locals = {
        env: options.watch === true ? 'dev' : 'pro',
        marker: marker,
        prefixPath: options.prefix
      };
  if (options.watch === true) { locals.liveReloadPort = LIVERELOAD_PORT; }
  return gulp.src('server/views/pages/**/*.jade')
    .pipe(jade({
      basedir: BASEDIR,
      locals: locals
    })).on('error', function(err){ console.log(err.message); })
    .pipe(options.prefix.length > 0 ? replace(/\/images\//g, options.prefix + '/images/') : gutil.noop())
    .pipe(replace(/\.(jpg|jpeg|gif|png|svg)$/g, '.$1?' + marker))
    .pipe(gulp.dest(destinationPath))
    .pipe(options.watch === true ? livereload(tinylr) : gutil.noop());
};

gulp.task('clean-build', function() {
  return clean(['build/**/*.*', '!build/**/*.{js,css,html,map}']);
});

gulp.task('clean-scripts-build', function() {
  return clean('build/scripts/*.*');
});

gulp.task('clean-styles-build', function() {
  return clean('build/styles/*.*');
});

gulp.task('clean-templates-build', function() {
  return clean('build/**/*.html');
});

gulp.task('clean-dist', function() {
  return clean('dist/*.*');
});

gulp.task('clean-live', function() {
  return clean('live/*.*');
});

gulp.task('clean-server', function() {
  return clean('server/**/*.js');
});

gulp.task('copy-to-build', ['clean-build'], function() {
  return copy('build', { watch: true });
});

gulp.task('copy-to-dist', function() {
  return copy('dist');
});

gulp.task('copy-to-live', function() {
  return copy('live');
});

gulp.task('scripts-build', ['clean-scripts-build'], function() {
  return thirdPartyScripts('build/scripts') &&
    cjsxScripts('build/scripts', { watch: true }) &&
    coffeeScripts('build/scripts', { watch: true });
});

gulp.task('scripts-dist', function() {
  return thirdPartyScripts('dist/scripts') &&
    cjsxScripts('dist/scripts', { prefix: DIST_PREFIX_PATH }) &&
    coffeeScripts('dist/scripts', { prefix: DIST_PREFIX_PATH });
});

gulp.task('scripts-live', function() {
  return thirdPartyScripts('live/scripts') &&
    cjsxScripts('live/scripts') &&
    coffeeScripts('live/scripts');
});

gulp.task('scripts-server', function() {
  return gulp.src(['server/**/*.coffee'])
    .pipe(coffeelint())
    .pipe(coffeelint.reporter())
    .pipe(coffee())
    .pipe(jshint())
    .pipe(jshint.reporter('default'))
    .pipe(jshint.reporter('fail'))
    .pipe(gulp.dest('server'));
});

gulp.task('bootstrap-styles', ['templates-build'], function() {
  return gulp.src('third-party/bootstrap/dist/css/bootstrap.css')
    .pipe(uncss({
      html: UNCSS_REFERENCE_HTML,
      ignore: UNCSS_KEEP_STYLES
    }))
    .pipe(removeLines({'filters': [/sourceMappingURL/]}))
    .pipe(gulp.dest('client/css'))
});

gulp.task('styles-build', ['clean-styles-build'], function() {
  return lessStyles('build/styles', { watch: true });
});

gulp.task('styles-dist', ['templates-dist'], function() {
  return lessStyles('dist/styles', { prefix: DIST_PREFIX_PATH });
});

gulp.task('styles-live', ['templates-live'], function() {
  return lessStyles('live/styles');
});

gulp.task('templates-build', ['clean-templates-build'], function() {
  return jadeTemplates('build', { watch: true });
});

gulp.task('templates-dist', function() {
  return jadeTemplates('dist', { prefix: DIST_PREFIX_PATH });
});

gulp.task('templates-live', function() {
  return jadeTemplates('live');
});

gulp.task('serve', ['scripts-server'], function () {
  nodemon({
    watch: ['server/'],
    script: 'server/app.js',
    ext: 'coffee'
    })
    .on('change', ['scripts-server'])
    .on('restart', function () {
      console.log('restarted!')
    })
  tinylr.listen(LIVERELOAD_PORT, function() {
    console.log('TinyLR Listening on %s', LIVERELOAD_PORT);
  });
});

gulp.task('watch', function() {
  gulp.watch(['client/**/*.*', '!client/**/*.{coffee,cjsx,less,html,map}'], ['copy-to-build']).on('change', function(file) {
    tinylr.changed(file.path);
  });
  gulp.watch(['client/coffee/**/*.coffee', 'client/coffee/**/*.cjsx'], ['scripts-build']).on('change', function(file) {
    tinylr.changed(file.path);
  });
  gulp.watch('client/less/**/*.less', ['styles-build']).on('change', function(file) {
    tinylr.changed(file.path);
  });
  gulp.watch('client/less/**/*.jade', ['templates-build']).on('change', function(file) {
    tinylr.changed(file.path);
  });
});

gulp.task('todo', ['scripts-server', 'templates-build', 'scripts-build'], function(){
  return gulp.src([
    'server/**/*.js',
    'server/views/**/*.jade',
    'build/scripts/main.js',
    'build/scripts/react-components.js'
    ])
    .pipe(todo({
      fileName: 'TODO.md'
    }))
    .pipe(gulp.dest('./'));
});

gulp.task('server', [
  'scripts-server',
  'bootstrap-styles',
  'templates-build',
  'scripts-build',
  'styles-build',
  'copy-to-build',
  'serve',
  'watch'
]);

gulp.task('dist', [
  'clean-dist',
  'bootstrap-styles',
  'templates-dist',
  'scripts-server',
  'scripts-dist',
  'styles-dist',
  'copy-to-dist'
]);

gulp.task('live', [
  'clean-live',
  'bootstrap-styles',
  'templates-live',
  'scripts-server',
  'scripts-live',
  'styles-live',
  'copy-to-live'
]);
<commit_msg>Correcting jade watch path<commit_after>
var http = require('http');
var path = require('path');
var gulp = require('gulp');

var gutil = require('gulp-util');
var todo = require('gulp-todo');
var removeLines = require('gulp-remove-lines');
var replace = require('gulp-replace');
var vinylPaths = require('vinyl-paths');
var del = require('del');

var bower = require('gulp-bower');
var concat = require('gulp-concat');
var rename = require("gulp-rename");
var flatten = require("gulp-flatten");

var coffeelint = require('gulp-coffeelint');
var coffee = require('gulp-coffee');
var cjsx = require('gulp-cjsx');
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');

var less = require('gulp-less');
var uncss = require('gulp-uncss');
var minifyCSS = require('gulp-minify-css');

var jade = require('gulp-jade');

var watch = require("gulp-watch");
var nodemon = require("gulp-nodemon");
var livereload = require('gulp-livereload');
var tinylr = require('tiny-lr')();

var LIVERELOAD_PORT = 35729;
var BASEDIR = path.join(__dirname, 'server/views');
var UNCSS_REFERENCE_HTML = [
  'build/index.html'
];
var UNCSS_KEEP_STYLES = [
  /(hover|focus|active)/i,
  /collapse/i,
  /dropdown/i
];
var DIST_PREFIX_PATH = '';

var defaultOptions = function(options) {
  if (typeof options === 'undefined') { options = {}; }
  if (typeof options.copyPaths === 'undefined') { options.copyPaths = ['client/**/*.*', '!client/**/*.{coffee,cjsx,less,css,map,html}']; }
  if (typeof options.prefix != 'string') { options.prefix = ''; }
  if (typeof options.watch != 'boolean') { options.watch = false; }
  return options;
}

var clean = function(paths){
  return gulp.src(paths, {read: false})
    .pipe(vinylPaths(del));
};

var copy = function(destinationPath, options){
  options = defaultOptions(options);
  return gulp.src(options.copyPaths)
    .pipe(gulp.dest(destinationPath))
    .pipe(options.watch === true ? livereload(tinylr) : gutil.noop());
};

var thirdPartyScripts = function(destinationPath) {
  return gulp.src([
    'third-party/jquery/dist/jquery.js',
    'third-party/lodash/dist/lodash.js',
    'third-party/react/react.js',
    'third-party/bootstrap/dist/js/bootstrap.js'
    ])
    .pipe(flatten())
    .pipe(gulp.dest(destinationPath));
};

var cjsxScripts = function(destinationPath, options) {
  options = defaultOptions(options);
  return gulp.src('client/coffee/**/*.cjsx')
    .pipe(cjsx({bare: true}).on('error', gutil.log))
    .pipe(options.prefix.length > 0 ? replace(/\/images\//g, options.prefix + '/images/') : gutil.noop())
    .pipe(replace(/\.(jpg|jpeg|gif|png|svg)$/g, '.$1?' + (new Date()).getTime()))
    .pipe(jshint())
    .pipe(jshint.reporter('default'))
    .pipe(jshint.reporter('fail'))
    .pipe(concat(options.watch === true ? 'react-components.js' : 'react-components.min.js'))
    .pipe(options.watch === false ? uglify() : gutil.noop())
    .pipe(gulp.dest(destinationPath))
    .pipe(options.watch === true ? livereload(tinylr) : gutil.noop());
};

var coffeeScripts = function(destinationPath, options) {
  options = defaultOptions(options);
  return gulp.src(['client/**/*.coffee'])
    .pipe(coffeelint())
    .pipe(coffeelint.reporter())
    .pipe(coffee()).on('error', function(err){ console.log(err.message); })
    .pipe(options.prefix.length > 0 ? replace(/\/images\//g, options.prefix + '/images/') : gutil.noop())
    .pipe(replace(/\.(jpg|jpeg|gif|png|svg)$/g, '.$1?' + (new Date()).getTime()))
    .pipe(jshint())
    .pipe(jshint.reporter('default'))
    .pipe(jshint.reporter('fail'))
    .pipe(concat(options.watch === true ? 'main.js' : 'main.min.js'))
    .pipe(options.watch === false ? uglify() : gutil.noop())
    .pipe(gulp.dest(destinationPath))
    .pipe(options.watch === true ? livereload(tinylr) : gutil.noop());
};

var lessStyles = function(destinationPath, options) {
  options = defaultOptions(options);
  return gulp.src(['client/less/*.less'])
    .pipe(less()).on('error', function(err){ console.log(err.message); })
    .pipe(options.prefix.length > 0 ? replace(/\/images\//g, options.prefix + '/images/') : gutil.noop())
    .pipe(replace(/\.(jpg|jpeg|gif|png|svg)$/g, '.$1?' + (new Date()).getTime()))
    .pipe(options.watch === false ? rename({ extname: '.min.css' }) : gutil.noop())
    .pipe(options.watch === false ? minifyCSS({ removeEmpty: true }) : gutil.noop())
    .pipe(gulp.dest(destinationPath))
    .pipe(options.watch === true ? livereload(tinylr) : gutil.noop());
};

var jadeTemplates = function(destinationPath, options) {
  options = defaultOptions(options);
  var marker = (new Date()).getTime(),
      locals = {
        env: options.watch === true ? 'dev' : 'pro',
        marker: marker,
        prefixPath: options.prefix
      };
  if (options.watch === true) { locals.liveReloadPort = LIVERELOAD_PORT; }
  return gulp.src('server/views/pages/**/*.jade')
    .pipe(jade({
      basedir: BASEDIR,
      locals: locals
    })).on('error', function(err){ console.log(err.message); })
    .pipe(options.prefix.length > 0 ? replace(/\/images\//g, options.prefix + '/images/') : gutil.noop())
    .pipe(replace(/\.(jpg|jpeg|gif|png|svg)$/g, '.$1?' + marker))
    .pipe(gulp.dest(destinationPath))
    .pipe(options.watch === true ? livereload(tinylr) : gutil.noop());
};

gulp.task('clean-build', function() {
  return clean(['build/**/*.*', '!build/**/*.{js,css,html,map}']);
});

gulp.task('clean-scripts-build', function() {
  return clean('build/scripts/*.*');
});

gulp.task('clean-styles-build', function() {
  return clean('build/styles/*.*');
});

gulp.task('clean-templates-build', function() {
  return clean('build/**/*.html');
});

gulp.task('clean-dist', function() {
  return clean('dist/*.*');
});

gulp.task('clean-live', function() {
  return clean('live/*.*');
});

gulp.task('clean-server', function() {
  return clean('server/**/*.js');
});

gulp.task('copy-to-build', ['clean-build'], function() {
  return copy('build', { watch: true });
});

gulp.task('copy-to-dist', function() {
  return copy('dist');
});

gulp.task('copy-to-live', function() {
  return copy('live');
});

gulp.task('scripts-build', ['clean-scripts-build'], function() {
  return thirdPartyScripts('build/scripts') &&
    cjsxScripts('build/scripts', { watch: true }) &&
    coffeeScripts('build/scripts', { watch: true });
});

gulp.task('scripts-dist', function() {
  return thirdPartyScripts('dist/scripts') &&
    cjsxScripts('dist/scripts', { prefix: DIST_PREFIX_PATH }) &&
    coffeeScripts('dist/scripts', { prefix: DIST_PREFIX_PATH });
});

gulp.task('scripts-live', function() {
  return thirdPartyScripts('live/scripts') &&
    cjsxScripts('live/scripts') &&
    coffeeScripts('live/scripts');
});

gulp.task('scripts-server', function() {
  return gulp.src(['server/**/*.coffee'])
    .pipe(coffeelint())
    .pipe(coffeelint.reporter())
    .pipe(coffee())
    .pipe(jshint())
    .pipe(jshint.reporter('default'))
    .pipe(jshint.reporter('fail'))
    .pipe(gulp.dest('server'));
});

gulp.task('bootstrap-styles', ['templates-build'], function() {
  return gulp.src('third-party/bootstrap/dist/css/bootstrap.css')
    .pipe(uncss({
      html: UNCSS_REFERENCE_HTML,
      ignore: UNCSS_KEEP_STYLES
    }))
    .pipe(removeLines({'filters': [/sourceMappingURL/]}))
    .pipe(gulp.dest('client/css'))
});

gulp.task('styles-build', ['clean-styles-build'], function() {
  return lessStyles('build/styles', { watch: true });
});

gulp.task('styles-dist', ['templates-dist'], function() {
  return lessStyles('dist/styles', { prefix: DIST_PREFIX_PATH });
});

gulp.task('styles-live', ['templates-live'], function() {
  return lessStyles('live/styles');
});

gulp.task('templates-build', ['clean-templates-build'], function() {
  return jadeTemplates('build', { watch: true });
});

gulp.task('templates-dist', function() {
  return jadeTemplates('dist', { prefix: DIST_PREFIX_PATH });
});

gulp.task('templates-live', function() {
  return jadeTemplates('live');
});

gulp.task('serve', ['scripts-server'], function () {
  nodemon({
    watch: ['server/'],
    script: 'server/app.js',
    ext: 'coffee'
    })
    .on('change', ['scripts-server'])
    .on('restart', function () {
      console.log('restarted!')
    })
  tinylr.listen(LIVERELOAD_PORT, function() {
    console.log('TinyLR Listening on %s', LIVERELOAD_PORT);
  });
});

gulp.task('watch', function() {
  gulp.watch(['client/**/*.*', '!client/**/*.{coffee,cjsx,less,html,map}'], ['copy-to-build']).on('change', function(file) {
    tinylr.changed(file.path);
  });
  gulp.watch(['client/coffee/**/*.coffee', 'client/coffee/**/*.cjsx'], ['scripts-build']).on('change', function(file) {
    tinylr.changed(file.path);
  });
  gulp.watch('client/less/**/*.less', ['styles-build']).on('change', function(file) {
    tinylr.changed(file.path);
  });
  gulp.watch('server/views/**/*.jade', ['templates-build']).on('change', function(file) {
    tinylr.changed(file.path);
  });
});

gulp.task('todo', ['scripts-server', 'templates-build', 'scripts-build'], function(){
  return gulp.src([
    'server/**/*.js',
    'server/views/**/*.jade',
    'build/scripts/main.js',
    'build/scripts/react-components.js'
    ])
    .pipe(todo({
      fileName: 'TODO.md'
    }))
    .pipe(gulp.dest('./'));
});

gulp.task('server', [
  'scripts-server',
  'bootstrap-styles',
  'templates-build',
  'scripts-build',
  'styles-build',
  'copy-to-build',
  'serve',
  'watch'
]);

gulp.task('dist', [
  'clean-dist',
  'bootstrap-styles',
  'templates-dist',
  'scripts-server',
  'scripts-dist',
  'styles-dist',
  'copy-to-dist'
]);

gulp.task('live', [
  'clean-live',
  'bootstrap-styles',
  'templates-live',
  'scripts-server',
  'scripts-live',
  'styles-live',
  'copy-to-live'
]);
<|endoftext|>


<commit_before>const gulp = require('gulp');
const path = require('path');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config');
const webpackStream = require('webpack-stream');
const babel = require('gulp-babel');
const coveralls = require('gulp-coveralls');
const eslint = require('gulp-eslint');
const manifest = require('./package.json');

const mainFile = manifest.main
const destinationDirectory = path.dirname(mainFile);

function build() {
  return gulp.src('./src/formwood.js')
    .pipe(webpackStream(webpackConfig, webpack))
    .pipe(gulp.dest(destinationDirectory));
}

function sendToCoveralls() {
  gulp.src('coverage/**/lcov.info')
    .pipe(coveralls());
}

function lint() {
  return gulp.src('src/**/*')
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
}

gulp.task('build', build);
gulp.task('coveralls', sendToCoveralls);
gulp.task('lint', lint);
gulp.task('default', ['build']);
<commit_msg>Remove gulp-coveralls<commit_after>const gulp = require('gulp');
const path = require('path');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config');
const webpackStream = require('webpack-stream');
const babel = require('gulp-babel');
const eslint = require('gulp-eslint');
const manifest = require('./package.json');

const mainFile = manifest.main
const destinationDirectory = path.dirname(mainFile);

function build() {
  return gulp.src('./src/formwood.js')
    .pipe(webpackStream(webpackConfig, webpack))
    .pipe(gulp.dest(destinationDirectory));
}

function sendToCoveralls() {
  gulp.src('coverage/**/lcov.info')
    .pipe(coveralls());
}

function lint() {
  return gulp.src('src/**/*')
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
}

gulp.task('build', build);
gulp.task('coveralls', sendToCoveralls);
gulp.task('lint', lint);
gulp.task('default', ['build']);
<|endoftext|>