<commit_before>//-------------------------------------------------------------------
// PLUGINS
//-------------------------------------------------------------------

// plugins
var gulp = require("gulp"),
    plugins = require("gulp-load-plugins")(),
    del = require("del"),
    browserSync = require("browser-sync"),
    historyApiFallback = require('connect-history-api-fallback'),
    runSequence = require("run-sequence"),
    webpack = require('webpack'),
    webpackStream = require('webpack-stream'),
    webpackDevMiddleware = require('webpack-dev-middleware'),
    webpackHotMiddleware = require('webpack-hot-middleware'),
    webpackConfig = require('./webpack.config'),
    babel = require('babel-core'),
    reporters = require('jasmine-reporters');

//-------------------------------------------------------------------
// SETUP
//-------------------------------------------------------------------

// environments
var app = "app/";
var dev = ".tmp/";
var prod = "dist/";

//folders
var styles = "assets/styles";
var scripts = "assets/scripts";
var images = "assets/images";
var fonts = "assets/fonts";

var AUTOPREFIXER_BROWSERS = [
    "ie >= 9",
    "ie_mob >= 10",
    "ff >= 30",
    "chrome >= 34",
    "safari >= 7",
    "opera >= 23",
    "ios >= 7",
    "android >= 4",
    "bb >= 10",
];

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

gulp.task("styles", function() {
    return gulp.src(app + styles + "/**/*.scss")
        .pipe(plugins.plumber())
        .pipe(plugins.sourcemaps.init())
        .pipe(plugins.sass({
            includePaths: ["./node_modules/frontendler-sass"]
        }).on("error", plugins.sass.logError))
        .pipe(plugins.autoprefixer(AUTOPREFIXER_BROWSERS))
        .pipe(plugins.sourcemaps.write())
        .pipe(gulp.dest(dev + styles))
        .pipe(browserSync.stream())
        .pipe(plugins.size({
            title: "styles",
        }));
});

gulp.task("scripts", function() {
    return gulp.src(app + scripts + "/main.js")
        .pipe(plugins.plumber())
        .pipe(webpackStream(webpackConfig.PROD))
        .pipe(gulp.dest(dev + scripts))
        .pipe(plugins.size({
            title: "scripts"
        }));
});

gulp.task("images", function() {
    return gulp.src(app + images + "/**/*")
        .pipe(plugins.plumber())
        .pipe(plugins.cache(plugins.imagemin({
            optimizationLevel: 3,
            progressive: true,
            interlaced: true
        })))
        .pipe(gulp.dest(prod + images))
        .pipe(plugins.size({
            title: "images"
        }));
});

gulp.task("html", function() {
    return gulp.src([app + "**/*.html"])
        .pipe(plugins.plumber())
        .pipe(plugins.useref({
            searchPath: "{" + dev + "," + app + "}"
        }))
        .pipe(plugins.if("*.js", plugins.uglify()))
        .pipe(plugins.if("*.css", plugins.cssnano()))
        .pipe(plugins.if("*.html", plugins.minifyHtml()))
        .pipe(gulp.dest(prod))
        .pipe(plugins.size({
            title: "useref total"
        }));
});

//-------------------------------------------------------------------
// WATCH
//-------------------------------------------------------------------

gulp.task("clean:dev", del.bind(null, [dev]));
gulp.task("serve:dev", function() {

    var bundler = webpack(webpackConfig.DEV);

    browserSync({
        // tunnel: "frontendler",
        logConnections: true,
        logFileChanges: true,
        logPrefix: "Frontendler",
        server: {
            baseDir: [dev, app],
            middleware: [
                webpackDevMiddleware(bundler, {
                    publicPath: webpackConfig.DEV.output.publicPath,
                    stats: {
                        colors: true
                    }
                }),
                webpackHotMiddleware(bundler),
                historyApiFallback()
            ]
        }
    });

    gulp.watch([app + styles + "/**/*.scss"], ["styles"]);
    gulp.watch([app + fonts + "**/*"], ["fonts", browserSync.reload]);
    gulp.watch([app + images + "/**/*"], browserSync.reload);

});

gulp.task("watch", ["clean:dev"], function(cb) {
    runSequence(["styles"], "serve:dev", cb);
});

//-------------------------------------------------------------------
// BUILD
//-------------------------------------------------------------------

gulp.task("clean:prod", del.bind(null, [prod]));
gulp.task("copy:prod", function() {
    gulp.src([app + fonts + "/**/*.{eot,svg,ttf,woff}"])
        .pipe(gulp.dest(prod + fonts));
    gulp.src([app + "*.*", "node_modules/apache-server-configs/dist/.htaccess"], {
            dot: true
        })
        .pipe(gulp.dest(prod));
});

gulp.task("build", ["clean:prod"], function(cb) {
    runSequence(["styles", "scripts", "images", "copy:prod"], "html", cb);
});

//-------------------------------------------------------------------
// TEST
//-------------------------------------------------------------------

gulp.task("test:server", function() {

    var bundler = webpack(webpackConfig.TEST);

    browserSync({
        logConnections: true,
        logFileChanges: true,
        logPrefix: "Frontendler",
        server: {
            baseDir: ['test/'],
            middleware: [
                webpackDevMiddleware(bundler, {
                    publicPath: webpackConfig.TEST.output.publicPath,
                    quiet: false,
                    stats: {
                        colors: true
                    }
                }),
                webpackHotMiddleware(bundler),
                historyApiFallback()
            ]
        }
    });

    gulp.watch(["test/**/*.js"], browserSync.reload);
});

gulp.task('test',function(){
    webpackConfig.PROD.devtool = "";
    return gulp.src(['test/**/*.js'])
        .pipe(plugins.plumber())
        .pipe(webpackStream(webpackConfig.PROD))
        .pipe(gulp.dest('.test/'))
        .pipe(plugins.jasmine());
});
<commit_msg>Change name of the default task ingulpfile<commit_after>//-------------------------------------------------------------------
// PLUGINS
//-------------------------------------------------------------------

// plugins
var gulp = require("gulp"),
    plugins = require("gulp-load-plugins")(),
    del = require("del"),
    browserSync = require("browser-sync"),
    historyApiFallback = require('connect-history-api-fallback'),
    runSequence = require("run-sequence"),
    webpack = require('webpack'),
    webpackStream = require('webpack-stream'),
    webpackDevMiddleware = require('webpack-dev-middleware'),
    webpackHotMiddleware = require('webpack-hot-middleware'),
    webpackConfig = require('./webpack.config'),
    babel = require('babel-core'),
    reporters = require('jasmine-reporters');

//-------------------------------------------------------------------
// SETUP
//-------------------------------------------------------------------

// environments
var app = "app/";
var dev = ".tmp/";
var prod = "dist/";

//folders
var styles = "assets/styles";
var scripts = "assets/scripts";
var images = "assets/images";
var fonts = "assets/fonts";

var AUTOPREFIXER_BROWSERS = [
    "ie >= 9",
    "ie_mob >= 10",
    "ff >= 30",
    "chrome >= 34",
    "safari >= 7",
    "opera >= 23",
    "ios >= 7",
    "android >= 4",
    "bb >= 10",
];

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

gulp.task("styles", function() {
    return gulp.src(app + styles + "/**/*.scss")
        .pipe(plugins.plumber())
        .pipe(plugins.sourcemaps.init())
        .pipe(plugins.sass({
            includePaths: ["./node_modules/frontendler-sass"]
        }).on("error", plugins.sass.logError))
        .pipe(plugins.autoprefixer(AUTOPREFIXER_BROWSERS))
        .pipe(plugins.sourcemaps.write())
        .pipe(gulp.dest(dev + styles))
        .pipe(browserSync.stream())
        .pipe(plugins.size({
            title: "styles",
        }));
});

gulp.task("scripts", function() {
    return gulp.src(app + scripts + "/main.js")
        .pipe(plugins.plumber())
        .pipe(webpackStream(webpackConfig.PROD))
        .pipe(gulp.dest(dev + scripts))
        .pipe(plugins.size({
            title: "scripts"
        }));
});

gulp.task("images", function() {
    return gulp.src(app + images + "/**/*")
        .pipe(plugins.plumber())
        .pipe(plugins.cache(plugins.imagemin({
            optimizationLevel: 3,
            progressive: true,
            interlaced: true
        })))
        .pipe(gulp.dest(prod + images))
        .pipe(plugins.size({
            title: "images"
        }));
});

gulp.task("html", function() {
    return gulp.src([app + "**/*.html"])
        .pipe(plugins.plumber())
        .pipe(plugins.useref({
            searchPath: "{" + dev + "," + app + "}"
        }))
        .pipe(plugins.if("*.js", plugins.uglify()))
        .pipe(plugins.if("*.css", plugins.cssnano()))
        .pipe(plugins.if("*.html", plugins.minifyHtml()))
        .pipe(gulp.dest(prod))
        .pipe(plugins.size({
            title: "useref total"
        }));
});

//-------------------------------------------------------------------
// WATCH
//-------------------------------------------------------------------

gulp.task("clean:dev", del.bind(null, [dev]));
gulp.task("serve:dev", function() {

    var bundler = webpack(webpackConfig.DEV);

    browserSync({
        // tunnel: "frontendler",
        logConnections: true,
        logFileChanges: true,
        logPrefix: "Frontendler",
        server: {
            baseDir: [dev, app],
            middleware: [
                webpackDevMiddleware(bundler, {
                    publicPath: webpackConfig.DEV.output.publicPath,
                    stats: {
                        colors: true
                    }
                }),
                webpackHotMiddleware(bundler),
                historyApiFallback()
            ]
        }
    });

    gulp.watch([app + styles + "/**/*.scss"], ["styles"]);
    gulp.watch([app + fonts + "**/*"], ["fonts", browserSync.reload]);
    gulp.watch([app + images + "/**/*"], browserSync.reload);

});

gulp.task("default", ["clean:dev"], function(cb) {
    runSequence(["styles"], "serve:dev", cb);
});

//-------------------------------------------------------------------
// BUILD
//-------------------------------------------------------------------

gulp.task("clean:prod", del.bind(null, [prod]));
gulp.task("copy:prod", function() {
    gulp.src([app + fonts + "/**/*.{eot,svg,ttf,woff}"])
        .pipe(gulp.dest(prod + fonts));
    gulp.src([app + "*.*", "node_modules/apache-server-configs/dist/.htaccess"], {
            dot: true
        })
        .pipe(gulp.dest(prod));
});

gulp.task("build", ["clean:prod"], function(cb) {
    runSequence(["styles", "scripts", "images", "copy:prod"], "html", cb);
});

//-------------------------------------------------------------------
// TEST
//-------------------------------------------------------------------

gulp.task("test:server", function() {

    var bundler = webpack(webpackConfig.TEST);

    browserSync({
        logConnections: true,
        logFileChanges: true,
        logPrefix: "Frontendler",
        server: {
            baseDir: ['test/'],
            middleware: [
                webpackDevMiddleware(bundler, {
                    publicPath: webpackConfig.TEST.output.publicPath,
                    quiet: false,
                    stats: {
                        colors: true
                    }
                }),
                webpackHotMiddleware(bundler),
                historyApiFallback()
            ]
        }
    });

    gulp.watch(["test/**/*.js"], browserSync.reload);
});

gulp.task('test',function(){
    webpackConfig.PROD.devtool = "";
    return gulp.src(['test/**/*.js'])
        .pipe(plugins.plumber())
        .pipe(webpackStream(webpackConfig.PROD))
        .pipe(gulp.dest('.test/'))
        .pipe(plugins.jasmine());
});
<|endoftext|>


<commit_before>const gulp = require('gulp');
const eslint = require('gulp-eslint');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');

const fs = require('fs');
const pkg = require('./package.json');

const VERSION = pkg.version;
const COPYRIGHT =
`/**
 * Particleground.js v${ VERSION } (https://github.com/Barrior/Particleground.js)
 * Copyright 2016 Barrior <Barrior@qq.com>
 * Licensed under the MIT (https://opensource.org/licenses/mit-license.php)
 */
`;

const devPath = './dev/';
const prodPath = './production/';

// pack pjs to dev environment
gulp.task('pack-pjs', () => {
    gulp.watch([devPath + '*.js'], () => {
        fs.readdir(devPath, (err, files) => {

            files = files.join(' ').replace(/particleground\.js\s|particleground\.all\.js\s/g, '');
            files = ('particleground.js ' + files).split(' ');
            files.forEach((item, i, array) => {
                array.splice(i, 1, devPath + item);
            });

            gulp.src(files)
                .pipe(concat('particleground.all.js'))
                .pipe(gulp.dest(devPath))
        });
    });
});

// build pjs production
gulp.task('build-prod', () => {
    gulp.src(devPath + '*.js')
        .pipe(eslint())
        .pipe(eslint.format())
        .pipe(eslint.failAfterError())
        .pipe(uglify())
        .pipe(gulp.dest(prodPath))

        // add Copyright
        .on('end', () => {
            ['particleground.all.js', 'particleground.js']
                .forEach(item => {
                    let filename = prodPath + item;
                    fs.readFile(filename, (err, data) => {
                        let writeData = COPYRIGHT + data.toString();
                        if (!err) {
                            fs.writeFile(filename, writeData, err => {
                                !err && console.log(filename + '【写入成功】');
                            });
                        }
                    });
                });
        });
});

gulp.task('default', ['pack-pjs'], function () {
    // do something else if the pack-pjs task is successful...
});<commit_msg>adjust annotation<commit_after>const gulp = require('gulp');
const eslint = require('gulp-eslint');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');

const fs = require('fs');
const pkg = require('./package.json');

const VERSION = pkg.version;
const COPYRIGHT =
`/**
 * Particleground.js v${ VERSION } (https://github.com/Barrior/Particleground.js)
 * Copyright 2016 Barrior <Barrior@qq.com>
 * Licensed under the MIT (https://opensource.org/licenses/mit-license.php)
 */
`;

const devPath = './dev/';
const prodPath = './production/';

// pack pjs on dev environment
gulp.task('pack-pjs', () => {
    gulp.watch([devPath + '*.js'], () => {
        fs.readdir(devPath, (err, files) => {

            files = files.join(' ').replace(/particleground\.js\s|particleground\.all\.js\s/g, '');
            files = ('particleground.js ' + files).split(' ');
            files.forEach((item, i, array) => {
                array.splice(i, 1, devPath + item);
            });

            gulp.src(files)
                .pipe(concat('particleground.all.js'))
                .pipe(gulp.dest(devPath))
        });
    });
});

// build pjs production
gulp.task('build-prod', () => {
    gulp.src(devPath + '*.js')
        .pipe(eslint())
        .pipe(eslint.format())
        .pipe(eslint.failAfterError())
        .pipe(uglify())
        .pipe(gulp.dest(prodPath))

        // add Copyright
        .on('end', () => {
            ['particleground.all.js', 'particleground.js']
                .forEach(item => {
                    let filename = prodPath + item;
                    fs.readFile(filename, (err, data) => {
                        let writeData = COPYRIGHT + data.toString();
                        if (!err) {
                            fs.writeFile(filename, writeData, err => {
                                !err && console.log(filename + '【写入成功】');
                            });
                        }
                    });
                });
        });
});

gulp.task('default', ['pack-pjs'], function () {
    // do something else if the pack-pjs task is successful...
});<|endoftext|>


<commit_before>//
// Knockout-Modal
// MIT Licensed
//
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var config = {
  css: {
    src: 'styles/knockout-modal.less',
    dst: 'dist/',
    less_opts: {},
  },
  connect: {
    port: 4040,
    livereload: {
      port: 4041
    },
    root: [
      'spec/',
      'dist/',
      '.',
      'bower_components/',
    ]
  },
  watch: {
    js: ['index.js', 'spec/test.js'],
    html: 'spec/*.html',
    less: ['styles/*', 'spec/test.css']
  }
};

gulp.task('less', function () {
  return gulp.src(config.css.src)
     .pipe(plugins.less(config.css.less_opts).on('error', console.log))
     .pipe(plugins.autoprefixer())
     .pipe(gulp.dest(config.css.dst))
     .pipe(plugins.connect.reload());
})

gulp.task('connect', function () {
  plugins.connect.server(config.connect);
})

gulp.task('html', function () {
  gulp.src(config.watch.html)
    .pipe(plugins.connect.reload());
});

gulp.task('js', function () {
  gulp.src(config.watch.js)
    .pipe(plugins.connect.reload());
});

gulp.task('watch', ['less', 'html', 'js'], function () {
  gulp.watch(config.watch.less, ['less'])
  gulp.watch(config.watch.html, ['html'])
  gulp.watch(config.watch.js, ['js'])
})

gulp.task('live', ['watch', 'connect'])
gulp.task('default', ['live'])
<commit_msg>add git tagging/bump/etc<commit_after>//
// Knockout-Modal
// MIT Licensed
//
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var config = {
  css: {
    src: 'styles/knockout-modal.less',
    dst: 'dist/',
    less_opts: {},
  },
  connect: {
    port: 4040,
    livereload: {
      port: 4041
    },
    root: [
      'spec/',
      'dist/',
      '.',
      'bower_components/',
    ]
  },
  watch: {
    js: ['index.js', 'spec/test.js'],
    html: 'spec/*.html',
    less: ['styles/*', 'spec/test.css']
  }
};

// from https://github.com/ikari-pl/gulp-tag-version
function inc(importance) {
  return gulp.src(['./package.json', './bower.json'])
    .pipe(plugins.bump({type: importance}))
    .pipe(gulp.dest('./'))
    .pipe(plugins.git.commit('bumps package version'))
    .pipe(plugins.filter('package.json'))
    .pipe(plugins.tagVersion())
}

gulp.task('patch', function() { return inc('patch'); })
gulp.task('feature', function() { return inc('minor'); })
gulp.task('release', function() { return inc('major'); })

gulp.task('less', function () {
  return gulp.src(config.css.src)
     .pipe(plugins.less(config.css.less_opts).on('error', console.log))
     .pipe(plugins.autoprefixer())
     .pipe(gulp.dest(config.css.dst))
     .pipe(plugins.connect.reload());
})

gulp.task('connect', function () {
  plugins.connect.server(config.connect);
})

gulp.task('html', function () {
  gulp.src(config.watch.html)
    .pipe(plugins.connect.reload());
});

gulp.task('js', function () {
  gulp.src(config.watch.js)
    .pipe(plugins.connect.reload());
});

gulp.task('watch', ['less', 'html', 'js'], function () {
  gulp.watch(config.watch.less, ['less'])
  gulp.watch(config.watch.html, ['html'])
  gulp.watch(config.watch.js, ['js'])
})

gulp.task('live', ['watch', 'connect'])
gulp.task('default', ['live'])
<|endoftext|>


<commit_before>/*jslint browser: true, devel: true, plusplus: true, unparam: true, vars: true, white: true*/
/*global require*/

(function() {

    'use strict';

    // Gulp
    // ----------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------
    var gulp = require('gulp');

    // Importing Gulp dependencies
    // ------------------------------------------------------------------------------------------------------
    var
        uglify      = require('gulp-uglify'),
        less        = require('gulp-less'),
        minifyCSS   = require('gulp-minify-css'),
        rename      = require('gulp-rename'),
        jshint      = require('gulp-jshint'),
        notify      = require('gulp-notify'),
        qunit       = require('gulp-qunit');

    // Source path
    // ------------------------------------------------------------------------------------------------------
    var dist_path   = 'dist/';
    var doc_path    = 'doc/assets/';

    // Tasks configuration
    // ------------------------------------------------------------------------------------------------------
    var tasks = {
        'dist_js': {
            source: dist_path +'js/jquery.desoslide.js',
            dest:   dist_path +'js'
        },
        'dist_less': {
            source: dist_path +'less/jquery.desoslide.less',
            dest:   dist_path +'css'
        },
        'doc_less_main': {
            source: doc_path +'less/app/main.less',
            dest:   doc_path +'css/app'
        },
        'doc_less_views': {
            source: doc_path +'less/app/views/**/*.less',
            dest:   doc_path +'css/app/views'
        }
    };

    // Javascript
    // ------------------------------------------------------------------------------------------------------
    gulp.task('dist_js_min', function() {

        return gulp
            .src(tasks.dist_js.source)
            .pipe(uglify({
                preserveComments: 'some'
            }))
            .pipe(rename({
                suffix: '.min'
            }))
            .pipe(gulp.dest(tasks.dist_js.dest))
            .pipe(notify({
                title: 'Javascript',
                message: 'File minified successfully',
                onLast: true
            }))
            .on('error', notify.onError(function (error) {
                return 'Message to the notifier: '+ error.message;
            }));

    });

    gulp.task('dist_js_lint', function() {

        return gulp
            .src(tasks.dist_js.source)
            .pipe(jshint())
            .pipe(jshint.reporter('default'))
            .pipe(gulp.dest(tasks.dist_js.dest))
            .pipe(notify({
                title: 'Javascript',
                message: 'File linted successfully',
                onLast: true
            }))
            .on('error', notify.onError(function (error) {
                return 'Message to the notifier: '+ error.message;
            }));

    });

    // LESS
    // ------------------------------------------------------------------------------------------------------
    gulp.task('dist_less', function() {

        return gulp
            .src(tasks.dist_less.source)
            .pipe(less())
            .pipe(minifyCSS({
                keepSpecialComments: 1
            }))
            .pipe(rename({
                suffix: '.min'
            }))
            .pipe(gulp.dest(tasks.dist_less.dest))
            .pipe(notify({
                title: 'LESS',
                message: 'File compiled successfully',
                onLast: true
            }))
            .on('error', notify.onError(function (error) {
                return 'Message to the notifier: '+ error.message;
            }));

    });

    gulp.task('doc_less_main', function() {

        return gulp
            .src(tasks.doc_less_main.source)
            .pipe(less())
            .pipe(minifyCSS())
            .pipe(gulp.dest(tasks.doc_less_main.dest))
            .pipe(notify({
                title: 'LESS',
                message: 'Main compiled successfully',
                onLast: true
            }))
            .on('error', notify.onError(function (error) {
                return 'Message to the notifier: '+ error.message;
            }));

    });

    gulp.task('doc_less_views', function() {

        return gulp
            .src(tasks.doc_less_views.source)
            .pipe(less())
            .pipe(minifyCSS())
            .pipe(gulp.dest(tasks.doc_less_views.dest))
            .pipe(notify({
                title: 'LESS',
                message: 'Views compiled successfully',
                onLast: true
            }))
            .on('error', notify.onError(function (error) {
                return 'Message to the notifier: '+ error.message;
            }));

    });

    // Tests
    // ------------------------------------------------------------------------------------------------------
    gulp.task('tests', function() {

        return gulp
            .src('tests/index.html')
            .pipe(qunit());

    });

    // Build
    // ------------------------------------------------------------------------------------------------------
    gulp.task('build', [
        'dist_js_lint',
        'dist_js_min',
        'dist_less'
    ]);

    // Watching files
    // ------------------------------------------------------------------------------------------------------
    gulp.task('watch', function() {

        // Javascript
        // --------------------------------------------------------------------------------------------------
        gulp.watch(tasks.dist_js.source, ['dist_js_lint']);

        // LESS
        // --------------------------------------------------------------------------------------------------
        gulp.watch(tasks.doc_less_main.source, ['doc_less_main']);
        gulp.watch(doc_path +'less/app/**/*.less', ['doc_less_views']);
        gulp.watch(doc_path +'less/components/**/*.less', ['doc_less_main', 'doc_less_views']);
        gulp.watch(doc_path +'less/layouts/**/*.less', ['doc_less_main', 'doc_less_views']);
        gulp.watch(doc_path +'less/views/**/*.less', ['doc_less_views']);

    });

    // Default tasks (called when running `gulp` from cli)
    // ------------------------------------------------------------------------------------------------------
    gulp.task('default', [
        'doc_less_main',
        'doc_less_views',
        'watch'
    ]);

}());
<commit_msg>updated gulpfile<commit_after>/*jslint browser: true, devel: true, plusplus: true, unparam: true, vars: true, white: true*/
/*global require*/

(function() {

    'use strict';

    // Gulp
    // ----------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------
    var gulp = require('gulp');

    // Importing Gulp dependencies
    // ------------------------------------------------------------------------------------------------------
    var
        uglify      = require('gulp-uglify'),
        less        = require('gulp-less'),
        minifyCSS   = require('gulp-minify-css'),
        rename      = require('gulp-rename'),
        jshint      = require('gulp-jshint'),
        notify      = require('gulp-notify'),
        qunit       = require('gulp-qunit');

    // Source path
    // ------------------------------------------------------------------------------------------------------
    var dist_path   = 'dist/';
    var doc_path    = 'doc/assets/';

    // Tasks configuration
    // ------------------------------------------------------------------------------------------------------
    var tasks = {
        'dist_js': {
            source: dist_path +'js/jquery.desoslide.js',
            dest:   dist_path +'js'
        },
        'dist_less': {
            source: dist_path +'less/jquery.desoslide.less',
            dest:   dist_path +'css'
        },
        'doc_less_main': {
            source: doc_path +'less/app/main.less',
            dest:   doc_path +'css/app'
        },
        'doc_less_views': {
            source: doc_path +'less/app/views/**/*.less',
            dest:   doc_path +'css/app/views'
        }
    };

    // Javascript
    // ------------------------------------------------------------------------------------------------------
    gulp.task('dist_js_min', function() {

        return gulp
            .src(tasks.dist_js.source)
            .pipe(uglify({
                preserveComments: 'some'
            }))
            .pipe(rename({
                suffix: '.min'
            }))
            .pipe(gulp.dest(tasks.dist_js.dest))
            .pipe(notify({
                title: 'Javascript',
                message: 'File minified successfully',
                onLast: true
            }))
            .on('error', notify.onError(function (error) {
                return 'Message to the notifier: '+ error.message;
            }));

    });

    gulp.task('dist_js_lint', function() {

        return gulp
            .src(tasks.dist_js.source)
            .pipe(jshint())
            .pipe(jshint.reporter('default'))
            .pipe(gulp.dest(tasks.dist_js.dest))
            .pipe(notify({
                title: 'Javascript',
                message: 'File linted successfully',
                onLast: true
            }))
            .on('error', notify.onError(function (error) {
                return 'Message to the notifier: '+ error.message;
            }));

    });

    // LESS
    // ------------------------------------------------------------------------------------------------------
    gulp.task('dist_less', function() {

        return gulp
            .src(tasks.dist_less.source)
            .pipe(less())
            .pipe(minifyCSS({
                keepSpecialComments: 1
            }))
            .pipe(rename({
                suffix: '.min'
            }))
            .pipe(gulp.dest(tasks.dist_less.dest))
            .pipe(notify({
                title: 'LESS',
                message: 'File compiled successfully',
                onLast: true
            }))
            .on('error', notify.onError(function (error) {
                return 'Message to the notifier: '+ error.message;
            }));

    });

    gulp.task('doc_less_main', function() {

        return gulp
            .src(tasks.doc_less_main.source)
            .pipe(less())
            .pipe(minifyCSS())
            .pipe(gulp.dest(tasks.doc_less_main.dest))
            .pipe(notify({
                title: 'LESS',
                message: 'Main compiled successfully',
                onLast: true
            }))
            .on('error', notify.onError(function (error) {
                return 'Message to the notifier: '+ error.message;
            }));

    });

    gulp.task('doc_less_views', function() {

        return gulp
            .src(tasks.doc_less_views.source)
            .pipe(less())
            .pipe(minifyCSS())
            .pipe(gulp.dest(tasks.doc_less_views.dest))
            .pipe(notify({
                title: 'LESS',
                message: 'Views compiled successfully',
                onLast: true
            }))
            .on('error', notify.onError(function (error) {
                return 'Message to the notifier: '+ error.message;
            }));

    });

    // Tests
    // ------------------------------------------------------------------------------------------------------
    gulp.task('tests', function() {

        return gulp
            .src('tests/index.html')
            .pipe(qunit());

    });

    // Build
    // ------------------------------------------------------------------------------------------------------
    gulp.task('build', [
        'dist_js_lint',
        'dist_js_min',
        'dist_less'
    ]);

    // Watching files
    // ------------------------------------------------------------------------------------------------------
    gulp.task('watch', function() {

        // Javascript
        // --------------------------------------------------------------------------------------------------
        gulp.watch(tasks.dist_js.source, ['dist_js_lint']);

        // LESS
        // --------------------------------------------------------------------------------------------------
        gulp.watch(tasks.doc_less_main.source, ['doc_less_main']);
        gulp.watch(doc_path +'less/app/**/*.less', ['doc_less_main', 'doc_less_views']);

    });

    // Default tasks (called when running `gulp` from cli)
    // ------------------------------------------------------------------------------------------------------
    gulp.task('default', [
        'doc_less_main',
        'doc_less_views',
        'watch'
    ]);

}());
<|endoftext|>


<commit_before>var gulp = require('gulp'),
  gutil = require('gulp-util'),
  chalk = require('chalk'),
  source = require('vinyl-source-stream'),
  buffer = require('vinyl-buffer'),
  rename = require('gulp-rename'),
  gulpif = require('gulp-if'),
  browserify = require('browserify'),
  babelify = require('babelify'),
  watchify = require('watchify'),
  duration = require('gulp-duration'),
  uglify = require('gulp-uglify'),
  concat = require('gulp-concat'),
  sass = require('gulp-sass'),
  rfn = require('responsive-filenames'),
  autoprefix = require('gulp-autoprefixer'),
  cssmin = require('gulp-cssmin'),
  prefixOptions = { browsers: ['last 2 versions', 'ie >= 9', 'ios >= 7', 'android >= 4.4.2'] },
  stylesGlob = [
    'styleguide/*.scss',
    'styleguide/*.css',
    'behaviors/*.scss',
    'behaviors/*.css'
  ];

gulp.task('styles', function () {
  return gulp.src(stylesGlob)
    .pipe(sass().on('error', sass.logError))
    .pipe(rfn())
    .pipe(concat('clay-kiln.css'))
    .pipe(autoprefix(prefixOptions))
    .pipe(cssmin())
    .pipe(gulp.dest('dist'));
});

// Error reporting function
function mapError(err) {
  if (err.fileName) {
    // Regular error
    gutil.log(chalk.red(err.name)
      + ': ' + chalk.yellow(err.fileName.replace(__dirname, ''))
      + ': ' + 'Line ' + chalk.magenta(err.lineNumber)
      + ' & ' + 'Column ' + chalk.magenta(err.columnNumber || err.column)
      + ': ' + chalk.blue(err.description));
  } else {
    // Browserify error..
    gutil.log(chalk.red(err.name)
      + ': '
      + chalk.yellow(err.message));
  }
}

gulp.task('scripts', function () {
  var b = browserify({
      entries: ['./client.js'],
      cache: {},
      packageCache: {}
    }),
    runOnce = process.argv.indexOf('--production') > -1;
  // for non-dev environments, use `gulp scripts --once` or `gulp --once`

  // plugins and transforms
  if (!runOnce) {
    // on dev environments (by default), add watchify plugin
    b.plugin(watchify, { ignoreWatch: ['**/node_modules/**', '**/dist/**'] });
  }
  b.transform(babelify, { presets: ['es2015'] });

  if (!runOnce) {
    // on dev environments (by default), re-bundle every time js changes
    b.on('update', bundle);
  }
  // always kick things off with a bundle()
  bundle();

  function bundle() {
    var bundleTimer = duration('Compile time');

    console.log(chalk.blue('Compiling scripts!'));
    b.bundle()
      .on('error', mapError) // log bundling errors
      .pipe(source('client.js')) // Set source name
      .pipe(buffer()) // convert to vinyl buffer
      .pipe(rename('clay-kiln.js')) // rename the output file
      .pipe(gulpif(runOnce, uglify()))
      .pipe(bundleTimer)
      .pipe(gulp.dest('dist'));
  }
});

// default task: run scripts and styles
gulp.task('default', ['styles', 'scripts']);

// recompile scripts and styles when editing them
gulp.task('watch', function () {
  // styles
  gulp.watch(stylesGlob, ['styles']);
});
<commit_msg>hotfix explicitly require babel preset<commit_after>var gulp = require('gulp'),
  gutil = require('gulp-util'),
  chalk = require('chalk'),
  source = require('vinyl-source-stream'),
  buffer = require('vinyl-buffer'),
  rename = require('gulp-rename'),
  gulpif = require('gulp-if'),
  browserify = require('browserify'),
  babelify = require('babelify'),
  es2015 = require('babel-preset-es2015'),
  watchify = require('watchify'),
  duration = require('gulp-duration'),
  uglify = require('gulp-uglify'),
  concat = require('gulp-concat'),
  sass = require('gulp-sass'),
  rfn = require('responsive-filenames'),
  autoprefix = require('gulp-autoprefixer'),
  cssmin = require('gulp-cssmin'),
  prefixOptions = { browsers: ['last 2 versions', 'ie >= 9', 'ios >= 7', 'android >= 4.4.2'] },
  stylesGlob = [
    'styleguide/*.scss',
    'styleguide/*.css',
    'behaviors/*.scss',
    'behaviors/*.css'
  ];

gulp.task('styles', function () {
  return gulp.src(stylesGlob)
    .pipe(sass().on('error', sass.logError))
    .pipe(rfn())
    .pipe(concat('clay-kiln.css'))
    .pipe(autoprefix(prefixOptions))
    .pipe(cssmin())
    .pipe(gulp.dest('dist'));
});

// Error reporting function
function mapError(err) {
  if (err.fileName) {
    // Regular error
    gutil.log(chalk.red(err.name)
      + ': ' + chalk.yellow(err.fileName.replace(__dirname, ''))
      + ': ' + 'Line ' + chalk.magenta(err.lineNumber)
      + ' & ' + 'Column ' + chalk.magenta(err.columnNumber || err.column)
      + ': ' + chalk.blue(err.description));
  } else {
    // Browserify error..
    gutil.log(chalk.red(err.name)
      + ': '
      + chalk.yellow(err.message));
  }
}

gulp.task('scripts', function () {
  var b = browserify({
      entries: ['./client.js'],
      cache: {},
      packageCache: {}
    }),
    runOnce = process.argv.indexOf('--production') > -1;
  // for non-dev environments, use `gulp scripts --once` or `gulp --once`

  // plugins and transforms
  if (!runOnce) {
    // on dev environments (by default), add watchify plugin
    b.plugin(watchify, { ignoreWatch: ['**/node_modules/**', '**/dist/**'] });
  }
  b.transform(babelify, { presets: [es2015] });

  if (!runOnce) {
    // on dev environments (by default), re-bundle every time js changes
    b.on('update', bundle);
  }

  function bundle() {
    var bundleTimer = duration('Compile time');

    console.log(chalk.blue('Compiling scripts!'));
    return b.bundle()
      .on('error', mapError) // log bundling errors
      .pipe(source('client.js')) // Set source name
      .pipe(buffer()) // convert to vinyl buffer
      .pipe(rename('clay-kiln.js')) // rename the output file
      .pipe(gulpif(runOnce, uglify()))
      .pipe(bundleTimer)
      .pipe(gulp.dest('dist'));
  }

  // always kick things off with a bundle()
  return bundle();
});

// default task: run scripts and styles
gulp.task('default', ['styles', 'scripts']);

// recompile scripts and styles when editing them
gulp.task('watch', function () {
  // styles
  gulp.watch(stylesGlob, ['styles']);
});
<|endoftext|>


<commit_before>/*jslint node: true */
'use strict';

/*****************
 * Configuration *
 *****************/
var config = {
  source_folder : "src", // dossier source
  dev_folder : "serve", // dossier pour le serveur local
  prod_folder : "prod", // dossier de build :)

  uncss : {
    html : ['src/index.html'], // have to fix?
    ignore : [
      '.content',
      '.type',
      '.geoJson',
      '.headmasked',
      '.nohead',
      '.geo',
      '.on',
      'ul',
      'li',
      /\.ath/,
      /input/,
      /reverse-/,
      /leaflet-/,
      /photon-/
      ]
    },
  colorguard : {
      logOk: true,
      threshold: 3,
      ignore: ['#030303'],
      whitelist: [
        ['#000000', '#010101'],
        ['#cccccc', '#c3c3c3'],
        ['#cccccc', '#d1d1d1'],
        ['#bbbbbb', '#c3c3c3'],
        ['#dddddd', '#d1d1d1'],
        ['#eeeeee', '#f4f4f4'],
        ['#fefefe', '#f4f4f4'],
        ['#ffffff', '#f4f4f4'], // Can-i reduce?
        ['#ffffff', '#fefefe']
        ]
      }
};

/************
 * Includes *
 ************/
var gulp = require('gulp');
var $ = require('gulp-load-plugins')(); // auto load :)
// Permet de supprimer les dossier de destination
var del = require('del'); // ce n'est pas un plugin Gulp.
var argv = require('minimist')(process.argv.slice(2));

// Idem, on doit le charger manuellement.
var browserSync = require('browser-sync');
var reload = browserSync.reload; // on met la commande dans une variable locale
var bs; // voir plus loin :)

var merge = require('merge-stream'); // permet de joindre 2 flux de sorties.
var scsslint = require('gulp-scss-lint');
/*********
 * Tasks *
 *********/
// Deletes the directory that is used to serve the site during development
gulp.task('clean:dev', del.bind(null, [config.dev_folder]));

// Deletes the directory that the optimized site is output to
gulp.task('clean:prod', del.bind(null, [config.prod_folder]));

// SCSS-Lint
gulp.task('scss-lint', function() {
  gulp.src(config.source_folder+'/scss/style.scss')
    .pipe(scsslint());
});

// SCSS
gulp.task('SCSS', function () {
  gulp.src(['bower_components/add-to-homescreen/style/addtohomescreen.css',
    'bower_components/leaflet-plugins/css/distance.css',
    'bower_components/leaflet-plugins/css/osb.css',
    'bower_components/material-design-iconic-font/dist/css/material-design-iconic-font.min.css',
    'bower_components/leaflet.photon/leaflet.photon.css',
    'bower_components/leaflet/dist/leaflet.css',
    config.source_folder+'/scss/style.scss'])
    //  .pipe($.sourcemaps.init()) //useless ?
  .pipe($.sass())
  .pipe($.concat('style.css'))
  // AutoPrefix your CSS so it works between browsers
  .pipe($.autoprefixer('> 1%, last 2 versions, Firefox ESR, Opera 12.1', { cascade: true }))
  .pipe($.uncss(config.uncss))
  .pipe($.colorguard(config.colorguard))
  .pipe(gulp.dest(config.source_folder+'/css'))
  .pipe(gulp.dest(config.dev_folder+'/css'))
  // Outputs the size of the CSS file
  .pipe($.size({title: 'styles'}))
  // Injects the CSS changes to your browser since Jekyll doesn't rebuild the CSS
  .pipe(reload({stream: true}));
});

// Run JS Lint against your JS
gulp.task('jslint', function () {
  gulp.src(config.source_folder+'/js/*.js')
    // Checks your JS code quality against your .jshintrc file
    .pipe($.jshint('.jshintrc'))
    .pipe($.jshint.reporter());
});

// Copy over fonts to the 'site' directory
gulp.task('fonts', function () {
  return gulp.src([config.source_folder+'/fonts/**','bower_components/material-design-iconic-font/dist/font/*'])
    .pipe(gulp.dest(config.dev_folder+'/fonts'))
    .pipe(gulp.dest(config.prod_folder+'/fonts'))
    .pipe($.size({ title: 'fonts' }));
});

gulp.task('js', function() {
  gulp.src(config.source_folder+'/js/*.js')
  //.pipe($.concat('all.js'))
  //.pipe($.uglify({preserveComments: 'some'}))
  .pipe($.size({title: 'js'}))
  .pipe(gulp.dest(config.dev_folder+'/js/'));
});

// Optimizes the images that exists
gulp.task('images', function () {
  return gulp.src([config.source_folder+'/images/**','bower_components/leaflet/dist/images/**'])
    .pipe(gulp.dest(config.dev_folder+'/images'))
    .pipe($.changed(config.prod_folder+'/images'))
    .pipe($.imagemin({
      // Lossless conversion to progressive JPGs
      progressive: true,
      // Interlace GIFs for progressive rendering
      interlaced: true
    }))
    .pipe(gulp.dest(config.prod_folder+'/images'))
    .pipe($.size({title: 'images'}));
});

gulp.task('bower', function() {
  return $.bower()
    .pipe(gulp.dest(config.dev_folder+'/vendor'));
});

gulp.task('dev',['bower','fonts','images','scss-lint','SCSS','jslint','js'],function(){

  gulp.src(config.source_folder+'/**/*.html')
  .pipe(gulp.dest(config.dev_folder));
});
gulp.task('serve:dev', ['dev'], function () {
  bs = browserSync({
    notify: true,
    // tunnel: '',
    server: {
      baseDir: config.dev_folder
    }
  });
});

gulp.task('watch', function () {
  gulp.watch([config.source_folder+'/**/*.html', config.source_folder+'/**/*.js'], ['dev']);
  gulp.watch([config.dev_folder+'/css/*.css'], reload);
  gulp.watch([config.source_folder+'/scss/**/*.scss'], ['SCSS']);
});

gulp.task('default', ['serve:dev', 'watch']);

// Optimizes all the CSS, HTML and concats the JS etc
gulp.task('prod', ['dev'], function () {
  var assets = $.useref.assets({searchPath: config.dev_folder});

  return gulp.src(config.dev_folder+'/*.html')
    .pipe(assets)
    // Concatenate JavaScript files and preserve important comments
    .pipe($.if('*.js',$.uglify({preserveComments: 'some'})))
    // Minify CSS
    .pipe($.if('*.css', $.minifyCss()))
    // Start cache busting the files
    .pipe($.revAll({ ignore: ['.eot', '.svg', '.ttf', '.woff','png'] }))
    .pipe(assets.restore())
    // Conctenate your files based on what you specified in _layout/header.html
    .pipe($.useref())
    // Replace the asset names with their cache busted names
    .pipe($.revReplace())
    // Add GA
    .pipe($.if('*.html',$.ga({
          url: 'julien-noblet.github.io/cad-killer',
          uid: 'UA-59363844-3'
        })))
    // Minify HTML
    .pipe($.if('*.html', $.htmlmin({
      removeComments: true,
      removeCommentsFromCDATA: true,
      removeCDATASectionsFromCDATA: true,
      collapseWhitespace: true,
      collapseBooleanAttributes: true,
      removeAttributeQuotes: true,
      removeRedundantAttributes: true
    // Send the output to the correct folder
    })))
    .pipe(gulp.dest(config.prod_folder))
    .pipe($.size({title: 'optimizations'}));
});
gulp.task('serve:prod', ['prod'], function () {
  bs = browserSync({
    notify: true,
    // tunnel: '',
    server: {
      baseDir: config.prod_folder
    }
  });
});

gulp.task('deploy',['prod'], function () {
  if (argv.clean) {
        var os = require('os');
        var path = require('path');
        var repoPath = path.join(os.tmpdir(), 'tmpRepo');
        $.util.log('Delete ' + $.util.colors.magenta(repoPath));
        del.sync(repoPath, {force: true});
    }
  // Deploys your optimized site, you can change the settings in the html task if you want to
  return gulp.src(config.prod_folder+'/**/*')
    .pipe($.ghPages({
      // Currently only personal GitHub Pages are supported so it will upload to the master
      // branch and automatically overwrite anything that is in the directory
      branch: 'gh-pages'
      }));
});
<commit_msg>Remove gulp task deploy Not working, not used...<commit_after>/*jslint node: true */
'use strict';

/*****************
 * Configuration *
 *****************/
var config = {
  source_folder : "src", // dossier source
  dev_folder : "serve", // dossier pour le serveur local
  prod_folder : "prod", // dossier de build :)

  uncss : {
    html : ['src/index.html'], // have to fix?
    ignore : [
      '.content',
      '.type',
      '.geoJson',
      '.headmasked',
      '.nohead',
      '.geo',
      '.on',
      'ul',
      'li',
      /\.ath/,
      /input/,
      /reverse-/,
      /leaflet-/,
      /photon-/
      ]
    },
  colorguard : {
      logOk: true,
      threshold: 3,
      ignore: ['#030303'],
      whitelist: [
        ['#000000', '#010101'],
        ['#cccccc', '#c3c3c3'],
        ['#cccccc', '#d1d1d1'],
        ['#bbbbbb', '#c3c3c3'],
        ['#dddddd', '#d1d1d1'],
        ['#eeeeee', '#f4f4f4'],
        ['#fefefe', '#f4f4f4'],
        ['#ffffff', '#f4f4f4'], // Can-i reduce?
        ['#ffffff', '#fefefe']
        ]
      }
};

/************
 * Includes *
 ************/
var gulp = require('gulp');
var $ = require('gulp-load-plugins')(); // auto load :)
// Permet de supprimer les dossier de destination
var del = require('del'); // ce n'est pas un plugin Gulp.
var argv = require('minimist')(process.argv.slice(2));

// Idem, on doit le charger manuellement.
var browserSync = require('browser-sync');
var reload = browserSync.reload; // on met la commande dans une variable locale
var bs; // voir plus loin :)

var merge = require('merge-stream'); // permet de joindre 2 flux de sorties.
var scsslint = require('gulp-scss-lint');
/*********
 * Tasks *
 *********/
// Deletes the directory that is used to serve the site during development
gulp.task('clean:dev', del.bind(null, [config.dev_folder]));

// Deletes the directory that the optimized site is output to
gulp.task('clean:prod', del.bind(null, [config.prod_folder]));

// SCSS-Lint
gulp.task('scss-lint', function() {
  gulp.src(config.source_folder+'/scss/style.scss')
    .pipe(scsslint());
});

// SCSS
gulp.task('SCSS', function () {
  gulp.src(['bower_components/add-to-homescreen/style/addtohomescreen.css',
    'bower_components/leaflet-plugins/css/distance.css',
    'bower_components/leaflet-plugins/css/osb.css',
    'bower_components/material-design-iconic-font/dist/css/material-design-iconic-font.min.css',
    'bower_components/leaflet.photon/leaflet.photon.css',
    'bower_components/leaflet/dist/leaflet.css',
    config.source_folder+'/scss/style.scss'])
    //  .pipe($.sourcemaps.init()) //useless ?
  .pipe($.sass())
  .pipe($.concat('style.css'))
  // AutoPrefix your CSS so it works between browsers
  .pipe($.autoprefixer('> 1%, last 2 versions, Firefox ESR, Opera 12.1', { cascade: true }))
  .pipe($.uncss(config.uncss))
  .pipe($.colorguard(config.colorguard))
  .pipe(gulp.dest(config.source_folder+'/css'))
  .pipe(gulp.dest(config.dev_folder+'/css'))
  // Outputs the size of the CSS file
  .pipe($.size({title: 'styles'}))
  // Injects the CSS changes to your browser since Jekyll doesn't rebuild the CSS
  .pipe(reload({stream: true}));
});

// Run JS Lint against your JS
gulp.task('jslint', function () {
  gulp.src(config.source_folder+'/js/*.js')
    // Checks your JS code quality against your .jshintrc file
    .pipe($.jshint('.jshintrc'))
    .pipe($.jshint.reporter());
});

// Copy over fonts to the 'site' directory
gulp.task('fonts', function () {
  return gulp.src([config.source_folder+'/fonts/**','bower_components/material-design-iconic-font/dist/font/*'])
    .pipe(gulp.dest(config.dev_folder+'/fonts'))
    .pipe(gulp.dest(config.prod_folder+'/fonts'))
    .pipe($.size({ title: 'fonts' }));
});

gulp.task('js', function() {
  gulp.src(config.source_folder+'/js/*.js')
  //.pipe($.concat('all.js'))
  //.pipe($.uglify({preserveComments: 'some'}))
  .pipe($.size({title: 'js'}))
  .pipe(gulp.dest(config.dev_folder+'/js/'));
});

// Optimizes the images that exists
gulp.task('images', function () {
  return gulp.src([config.source_folder+'/images/**','bower_components/leaflet/dist/images/**'])
    .pipe(gulp.dest(config.dev_folder+'/images'))
    .pipe($.changed(config.prod_folder+'/images'))
    .pipe($.imagemin({
      // Lossless conversion to progressive JPGs
      progressive: true,
      // Interlace GIFs for progressive rendering
      interlaced: true
    }))
    .pipe(gulp.dest(config.prod_folder+'/images'))
    .pipe($.size({title: 'images'}));
});

gulp.task('bower', function() {
  return $.bower()
    .pipe(gulp.dest(config.dev_folder+'/vendor'));
});

gulp.task('dev',['bower','fonts','images','scss-lint','SCSS','jslint','js'],function(){

  gulp.src(config.source_folder+'/**/*.html')
  .pipe(gulp.dest(config.dev_folder));
});
gulp.task('serve:dev', ['dev'], function () {
  bs = browserSync({
    notify: true,
    // tunnel: '',
    server: {
      baseDir: config.dev_folder
    }
  });
});

gulp.task('watch', function () {
  gulp.watch([config.source_folder+'/**/*.html', config.source_folder+'/**/*.js'], ['dev']);
  gulp.watch([config.dev_folder+'/css/*.css'], reload);
  gulp.watch([config.source_folder+'/scss/**/*.scss'], ['SCSS']);
});

gulp.task('default', ['serve:dev', 'watch']);

// Optimizes all the CSS, HTML and concats the JS etc
gulp.task('prod', ['dev'], function () {
  var assets = $.useref.assets({searchPath: config.dev_folder});

  return gulp.src(config.dev_folder+'/*.html')
    .pipe(assets)
    // Concatenate JavaScript files and preserve important comments
    .pipe($.if('*.js',$.uglify({preserveComments: 'some'})))
    // Minify CSS
    .pipe($.if('*.css', $.minifyCss()))
    // Start cache busting the files
    .pipe($.revAll({ ignore: ['.eot', '.svg', '.ttf', '.woff','png'] }))
    .pipe(assets.restore())
    // Conctenate your files based on what you specified in _layout/header.html
    .pipe($.useref())
    // Replace the asset names with their cache busted names
    .pipe($.revReplace())
    // Add GA
    .pipe($.if('*.html',$.ga({
          url: 'julien-noblet.github.io/cad-killer',
          uid: 'UA-59363844-3'
        })))
    // Minify HTML
    .pipe($.if('*.html', $.htmlmin({
      removeComments: true,
      removeCommentsFromCDATA: true,
      removeCDATASectionsFromCDATA: true,
      collapseWhitespace: true,
      collapseBooleanAttributes: true,
      removeAttributeQuotes: true,
      removeRedundantAttributes: true
    // Send the output to the correct folder
    })))
    .pipe(gulp.dest(config.prod_folder))
    .pipe($.size({title: 'optimizations'}));
});
gulp.task('serve:prod', ['prod'], function () {
  bs = browserSync({
    notify: true,
    // tunnel: '',
    server: {
      baseDir: config.prod_folder
    }
  });
});
<|endoftext|>


<commit_before>"use strict";

// NB: This gulp file is intended to be used with Gulp 4.x and won't
// work with Gulp 3.x or below.
var _ = require("lodash"),
    autoprefixer = require("gulp-autoprefixer"),
    babel = require("babelify"),
    browserify = require("browserify"),
    buffer = require("vinyl-buffer"),
    del = require("del"),
    ecstatic = require("ecstatic"),
    gulp = require("gulp"),
    gutil = require("gulp-util"),
    http = require("http"),
    less = require("gulp-less"),
    merge = require("merge-stream"),
    minifyCss = require("gulp-cssnano"),
    minifyHtml = require("gulp-htmlmin"),
    nunjucks = require("gulp-nunjucks-render"),
    path = require("path"),
    source = require("vinyl-source-stream"),
    sourcemaps = require("gulp-sourcemaps"),
    uglify = require("gulp-uglify"),
    watchify = require("watchify");

var PRODUCTION = process.env.NODE_ENV === "production";

/* LESS */

gulp.task("build-less", function() {
  var ret = gulp.src(["less/**/*.less", "!less/**/_*.less"])
    .pipe(sourcemaps.init())
    .pipe(less())
    .on('error', function(err) {
      console.error(err.toString());
      this.emit('end');
    })
    .pipe(autoprefixer());

  if (PRODUCTION) {
    ret = ret
      .pipe(minifyCss({ zindex: false }))
      .pipe(sourcemaps.write("./"))
  } else {
    ret = ret.pipe(sourcemaps.write());
  }

  return ret.pipe(gulp.dest("./pub/css"));
});

gulp.task("watch-less",function() {
  return gulp.watch("./less/**/*.less", gulp.series("build-less"));
});

/* ES6/Babel */

function compileES6(entry, watch) {
  var bundler = watchify(browserify(entry, {
    debug: true // Always write sourcemaps
  }).transform(babel, {presets: ["es2015"]}));

  var target = path.basename(entry);
  target = target.substr(0, target.lastIndexOf(".")) + ".js";

  function rebundle() {
    var b = bundler.bundle()
      .on('error', function(err) { console.error(err); this.emit('end'); })
      .pipe(source(target))
      .pipe(buffer())
      .pipe(sourcemaps.init({ loadMaps: true }));

    if (PRODUCTION) {
      b = b
        .pipe(uglify({
          output: {
            "ascii_only": true
          }
        }))
        .pipe(sourcemaps.write("./"))
    } else {
      b = b.pipe(sourcemaps.write());
    }

    return b.pipe(gulp.dest('./pub/js'))
      .on('end', function(){ gutil.log(target + ' done!'); });
  }

  if (watch) {
    bundler.on('update', function() {
      gutil.log('Bundling ' + target + " ...");
      rebundle();
    });
  }

  return rebundle();
}

gulp.task("build-es6", function() {
  return merge(
    compileES6("./js/index.es6"),
    compileES6("./js/registry.es6")
  );
});

gulp.task("watch-es6", function() {
  return merge(
    compileES6("./js/index.es6", true),
    compileES6("./js/registry.es6", true)
  );
});

/* HTML */

gulp.task("build-html", function() {
  var ret = gulp.src(["html/**/*.html", "!html/**/_*.html"])
    .pipe(nunjucks({
      path: ['html']
    }));

  if (PRODUCTION) {
    ret = ret.pipe(minifyHtml({
      collapseWhitespace: true,
      conservativeCollapse: true
    }));
  }

  return ret.pipe(gulp.dest("./pub"));
});

gulp.task("watch-html", function() {
  return gulp.watch("html/**/*.html", gulp.series("build-html"));
});

/* Our uncompiled assets */

gulp.task("build-assets", function() {
  return gulp.src("assets/**/*.*")
    .pipe(gulp.dest("./pub"));
});

gulp.task("watch-assets", function() {
  return gulp.watch("assets/**/*.*", gulp.series("build-assets"));
});

/* Font-Awesome */

gulp.task("build-fonts", function() {
  return gulp.src([
    "./node_modules/font-awesome/fonts/**/*.*"
  ]).pipe(gulp.dest("./pub/fonts"));
});

/* Dev server */

gulp.task("dev-server", function(cb) {
  var port = 5000;
  http.createServer(
    ecstatic({ root: path.resolve("./pub"),
               contentType: 'text/html' })
  ).listen(port);
  console.log("Dev server listening at http://localhost:" + port);
  cb();
});

////

gulp.task("clean", function() {
  return del(["./pub"]);
});

gulp.task("build", gulp.series("clean",
  gulp.parallel("build-assets",
                "build-fonts",
                "build-html",
                "build-es6",
                "build-less")));

gulp.task("watch", gulp.series("build",
  gulp.parallel(
    "dev-server",
    "watch-html",
    "watch-es6",
    "watch-less",
    "watch-assets"
  )
));

gulp.task("prod", gulp.series(function(cb) {
  process.env.NODE_ENV = "production";
  PRODUCTION = true;
  cb();
}, "build"))

gulp.task("default", gulp.series("build"));
<commit_msg>Don't crash on Nunjucks error<commit_after>"use strict";

// NB: This gulp file is intended to be used with Gulp 4.x and won't
// work with Gulp 3.x or below.
var _ = require("lodash"),
    autoprefixer = require("gulp-autoprefixer"),
    babel = require("babelify"),
    browserify = require("browserify"),
    buffer = require("vinyl-buffer"),
    del = require("del"),
    ecstatic = require("ecstatic"),
    gulp = require("gulp"),
    gutil = require("gulp-util"),
    http = require("http"),
    less = require("gulp-less"),
    merge = require("merge-stream"),
    minifyCss = require("gulp-cssnano"),
    minifyHtml = require("gulp-htmlmin"),
    nunjucks = require("gulp-nunjucks-render"),
    path = require("path"),
    source = require("vinyl-source-stream"),
    sourcemaps = require("gulp-sourcemaps"),
    uglify = require("gulp-uglify"),
    watchify = require("watchify");

var PRODUCTION = process.env.NODE_ENV === "production";

/* LESS */

gulp.task("build-less", function() {
  var ret = gulp.src(["less/**/*.less", "!less/**/_*.less"])
    .pipe(sourcemaps.init())
    .pipe(less())
    .on('error', function(err) {
      console.error(err.toString());
      this.emit('end');
    })
    .pipe(autoprefixer());

  if (PRODUCTION) {
    ret = ret
      .pipe(minifyCss({ zindex: false }))
      .pipe(sourcemaps.write("./"))
  } else {
    ret = ret.pipe(sourcemaps.write());
  }

  return ret.pipe(gulp.dest("./pub/css"));
});

gulp.task("watch-less",function() {
  return gulp.watch("./less/**/*.less", gulp.series("build-less"));
});

/* ES6/Babel */

function compileES6(entry, watch) {
  var bundler = watchify(browserify(entry, {
    debug: true // Always write sourcemaps
  }).transform(babel, {presets: ["es2015"]}));

  var target = path.basename(entry);
  target = target.substr(0, target.lastIndexOf(".")) + ".js";

  function rebundle() {
    var b = bundler.bundle()
      .on('error', function(err) { console.error(err); this.emit('end'); })
      .pipe(source(target))
      .pipe(buffer())
      .pipe(sourcemaps.init({ loadMaps: true }));

    if (PRODUCTION) {
      b = b
        .pipe(uglify({
          output: {
            "ascii_only": true
          }
        }))
        .pipe(sourcemaps.write("./"))
    } else {
      b = b.pipe(sourcemaps.write());
    }

    return b.pipe(gulp.dest('./pub/js'))
      .on('end', function(){ gutil.log(target + ' done!'); });
  }

  if (watch) {
    bundler.on('update', function() {
      gutil.log('Bundling ' + target + " ...");
      rebundle();
    });
  }

  return rebundle();
}

gulp.task("build-es6", function() {
  return merge(
    compileES6("./js/index.es6"),
    compileES6("./js/registry.es6")
  );
});

gulp.task("watch-es6", function() {
  return merge(
    compileES6("./js/index.es6", true),
    compileES6("./js/registry.es6", true)
  );
});

/* HTML */

gulp.task("build-html", function() {
  var ret = gulp.src(["html/**/*.html", "!html/**/_*.html"])
    .pipe(nunjucks({
      path: ['html']
    }))
    .on('error', function(err) {
      console.error(err.toString());
      this.emit('end');
    });

  if (PRODUCTION) {
    ret = ret.pipe(minifyHtml({
      collapseWhitespace: true,
      conservativeCollapse: true
    }));
  }

  return ret.pipe(gulp.dest("./pub"));
});

gulp.task("watch-html", function() {
  return gulp.watch("html/**/*.html", gulp.series("build-html"));
});

/* Our uncompiled assets */

gulp.task("build-assets", function() {
  return gulp.src("assets/**/*.*")
    .pipe(gulp.dest("./pub"));
});

gulp.task("watch-assets", function() {
  return gulp.watch("assets/**/*.*", gulp.series("build-assets"));
});

/* Font-Awesome */

gulp.task("build-fonts", function() {
  return gulp.src([
    "./node_modules/font-awesome/fonts/**/*.*"
  ]).pipe(gulp.dest("./pub/fonts"));
});

/* Dev server */

gulp.task("dev-server", function(cb) {
  var port = 5000;
  http.createServer(
    ecstatic({ root: path.resolve("./pub"),
               contentType: 'text/html' })
  ).listen(port);
  console.log("Dev server listening at http://localhost:" + port);
  cb();
});

////

gulp.task("clean", function() {
  return del(["./pub"]);
});

gulp.task("build", gulp.series("clean",
  gulp.parallel("build-assets",
                "build-fonts",
                "build-html",
                "build-es6",
                "build-less")));

gulp.task("watch", gulp.series("build",
  gulp.parallel(
    "dev-server",
    "watch-html",
    "watch-es6",
    "watch-less",
    "watch-assets"
  )
));

gulp.task("prod", gulp.series(function(cb) {
  process.env.NODE_ENV = "production";
  PRODUCTION = true;
  cb();
}, "build"))

gulp.task("default", gulp.series("build"));
<|endoftext|>


<commit_before>(function() {
  'use strict';
  var env = process.env.NODE_ENV || 'development';
  if (env === 'development') {
    require('dotenv').load();
  }

  var gulp = require('gulp'),
    jade = require('gulp-jade'),
    less = require('gulp-less'),
    mocha = require('gulp-mocha'),
    Server = require('karma').Server,
    browserSync = require('browser-sync'),
    bower = require('gulp-bower'),
    stripeDebug = require('gulp-strip-debug'),
    istanbul = require('gulp-istanbul'),
    nodemon = require('gulp-nodemon'),
    // change = require('gulp-changed'),
    rename = require('gulp-rename'),
    del = require('del'),
    browserify = require('browserify'),
    source = require('vinyl-source-stream'),
    notify = require('gulp-notify'),
    imagemin = require('gulp-imagemin'),
    // concat = require('gulp-concat'),
    // stylish = require('jshint-stylish'),
    ngAnnotate = require('gulp-ng-annotate'),
    jshint = require('gulp-jshint'),
    karma = require('gulp-karma'),
    uglify = require('gulp-uglify'),
    buffer = require('vinyl-buffer'),
    minifyCss = require('gulp-minify-css'),
    sourcemaps = require('gulp-sourcemaps'),
    gutil = require('gulp-util'),
    cache = require('gulp-cache');
  // coveralls = require('gulp-coveralls'),
  // rev = require('rev');

  // define clean task
  gulp.task('clean', function() {
    return del(['public/']);
  });

  // minify css
  gulp.task('less', function() {
    return gulp.src('./app/styles/*.+(less|css)')
      .pipe(less())
      .pipe(minifyCss())
      .pipe(rename({
        suffix: '.min'
      }))
      .pipe(gulp.dest('./public/css/'))
      .pipe(sourcemaps.init())
      .pipe(rename('application.min.css'))
      .pipe(gulp.dest('public/css/'))
      .pipe(sourcemaps.write('./maps'))
      .pipe(browserSync.reload({
        stream: true
      }))
      .pipe(notify({
        message: 'less task completed'
      }))
      .on('error', function(error) {
        gutil.log(gutil.colors.red(error.message));
        // Notify on error. Uses node-notifier
        notifier.notify({
          title: 'Less compilation error',
          message: error.message
        });
      });
  });

  // jade task
  gulp.task('jade', function() {
    return gulp.src(['!app/shared/**', 'app/**/*.jade'])
      .pipe(jade())
      .pipe(gulp.dest('./public/'));
  });

  // define task for imagemin
  gulp.task('imagemin', function() {
    return del(['public/images']),
      gulp.src('app/images/**/*')
      .pipe(cache(imagemin({
        optimizationLevel: 3,
        progressive: true,
        interlaced: true
      })))
      .pipe(gulp.dest('public/images'))
      .pipe(notify({
        message: 'Images task completed'
      }));
  });
  // bower install task
  gulp.task('bower', function() {
    return bower()
      .pipe(gulp.dest('public/lib/'));
  });

  // browserify function
  // TODO: remember to work on this later
  gulp.task('browserify', function() {
    return browserify('./app/js/application.js')
      .bundle()
      .on('success', gutil.log.bind(gutil, 'Browserify Rebundled'))
      .on('error', gutil.log.bind(gutil, 'Browserify ' +
        'Error: in browserify gulp task'))
      // vinyl-source-stream makes the bundle compatible with gulp
      .pipe(source('application.js')) // Desired filename
      //.pipe(ngAnnotate())
      // .pipe(buffer())
      // .pipe(uglify())
      // .pipe(stripeDebug())
      // Output the file
      // .pipe(gulp.dest('./public/js/'))
      // .pipe(sourcemaps.init({
      //  loadMaps: true
      // }))
      // .pipe(sourcemaps.write('./maps'))
      .pipe(gulp.dest('./public/js/'));
  });

  // define jshint lint
  gulp.task('jshint', function() {
    return gulp.src(['./app/js/**/*.js', './server/**/*.js',
        './index.js', './spec/**/*.js'
      ])
      .pipe(jshint())
      .pipe(jshint.reporter('default'));
  });

  // staatic files task
  gulp.task('static-files', function() {
    return gulp.src(['!app/**/*.+(less|css|js|jade)',
        '!app/images/**/*',
        'app/**/*.*'
      ])
      .pipe(gulp.dest('./public/'));
  });

  // browser-sync task
  gulp.task('browser-sync', ['default'], function() {
    browserSync.init(null, {
      baseDir: 'public',
      proxy: 'http://localhost:5555',
      injectChanges: true
    });
  });

  // define coverage report
  gulp.task('test-coverage', function() {
    return gulp.src('./coverage/lcov/info')
      .pipe(istanbul())
      // .pipe(coveralls())
      // Force `require` to return covered files
      .pipe(istanbul.hookRequire());
  });

  //  task for back end test
  gulp.task('test:bend', ['test:fend'], function() {
    return gulp.src('spec/server/*.js', {
        read: false
      })
      .pipe(mocha({
        reporter: 'spec'
      }))
      // Creating the reports after tests ran
      .pipe(istanbul.writeReports())
      // Enforce a coverage of at least 80%
      .pipe(istanbul.enforceThresholds({
        thresholds: {
          global: 80
        }
      }));
  });

  // task for front end test
  gulp.task('test:fend', ['browserify', 'bower'], function() {
  new Server({
      configFile: __dirname + '/karma.conf.js',
      singleRun: true
    }).start();
    // server.on('browser_error', function(browser, err) {
    //   gutil.log('Karma Run Failed: ' + err.message);
    //   throw err;
    // });

    // server.on('run_complete', function(browsers, results) {
    //   if (results.failed) {
    //     throw new Error('Karma: Tests Failed');
    //   }
    //   gutil.log('Karma Run Complete: No Failures');
    //   done();
    // });

    // server.start();
  });

  // e2e test task
  gulp.task('test:e2e', function(cb) {
    gulp.src(['./spec/e2e/*.js'])
      .pipe(protractor({
        configFile: './protractor.conf.js',
        args: ['--baseUrl', 'http://127.0.0.1:8000']
      }))
      .on('error', function(e) {
        console.log(e);
      })
      .on('end', cb);
  });

  // task for nodemon
  gulp.task('nodemon', function() {
    nodemon({
      ext: 'js',
      script: 'index.js',
      ignore: ['node_modules/', 'public/', 'coverage/']
    })
    // .on('watch', ['watch'])
    .on('change', ['watch'])
      .on('restart', function() {
        console.log('Appliction restarted..>>');
      });
  });

  // task to watch files
  gulp.task('watch', function() {
    gulp.watch('./app/**/*.jade', ['jade'], browserSync.reload);
    gulp.watch('./app/styles/*.+(less|css)', ['less'], browserSync.reload);
    gulp.watch('./app/**/*.js', ['browserify'], browserSync.reload);
    gulp.watch('./gulpfile.js', ['build'], browserSync.reload);
  });

  // build task
  gulp.task('build', ['jade', 'less', 'static-files',
    'imagemin', 'browserify', 'bower'
  ]);

  // register test task
  gulp.task('test', ['test:fend', 'test:bend']);
  // deployment tasks
  gulp.task('heroku:production', ['build']);
  gulp.task('heroku:develop', ['build']);
  gulp.task('production', ['nodemon', 'build']);
  // register default tasks
  gulp.task('default', ['nodemon', 'watch', 'build']);
})();<commit_msg>Update gulpfile Refers to [#114487833] - Remove unrequired module dependencies<commit_after>(function() {
  'use strict';
  var env = process.env.NODE_ENV || 'development';
  if (env === 'development') {
    require('dotenv').load();
  }

  var gulp = require('gulp'),
    jade = require('gulp-jade'),
    less = require('gulp-less'),
    mocha = require('gulp-mocha'),
    Server = require('karma').Server,
    browserSync = require('browser-sync'),
    bower = require('gulp-bower'),
    stripeDebug = require('gulp-strip-debug'),
    istanbul = require('gulp-istanbul'),
    nodemon = require('gulp-nodemon'),
    rename = require('gulp-rename'),
    del = require('del'),
    browserify = require('browserify'),
    source = require('vinyl-source-stream'),
    notify = require('gulp-notify'),
    imagemin = require('gulp-imagemin'),

    ngAnnotate = require('gulp-ng-annotate'),
    jshint = require('gulp-jshint'),
    karma = require('gulp-karma'),
    uglify = require('gulp-uglify'),
    minifyCss = require('gulp-minify-css'),
    gutil = require('gulp-util'),
    cache = require('gulp-cache');

  // minify css
  gulp.task('less', function() {
    return gulp.src('./app/styles/*.+(less|css)')
      .pipe(less())
      .pipe(minifyCss())
      .pipe(rename({
        suffix: '.min'
      }))
      .pipe(gulp.dest('./public/css/'))
      .pipe(sourcemaps.init())
      .pipe(rename('application.min.css'))
      .pipe(gulp.dest('public/css/'))
      .pipe(sourcemaps.write('./maps'))
      .pipe(browserSync.reload({
        stream: true
      }))
      .pipe(notify({
        message: 'less task completed'
      }))
      .on('error', function(error) {
        gutil.log(gutil.colors.red(error.message));
        // Notify on error. Uses node-notifier
        notifier.notify({
          title: 'Less compilation error',
          message: error.message
        });
      });
  });

  // jade task
  gulp.task('jade', function() {
    return gulp.src(['!app/shared/**', 'app/**/*.jade'])
      .pipe(jade())
      .pipe(gulp.dest('./public/'));
  });

  // define task for imagemin
  gulp.task('imagemin', function() {
    return del(['public/images']),
      gulp.src('app/images/**/*')
      .pipe(cache(imagemin({
        optimizationLevel: 3,
        progressive: true,
        interlaced: true
      })))
      .pipe(gulp.dest('public/images'))
      .pipe(notify({
        message: 'Images task completed'
      }));
  });
  // bower install task
  gulp.task('bower', function() {
    return bower()
      .pipe(gulp.dest('public/lib/'));
  });

  // browserify function
  // TODO: remember to work on this later
  gulp.task('browserify', function() {
    return browserify('./app/js/application.js')
      .bundle()
      .on('success', gutil.log.bind(gutil, 'Browserify Rebundled'))
      .on('error', gutil.log.bind(gutil, 'Browserify ' +
        'Error: in browserify gulp task'))
      // vinyl-source-stream makes the bundle compatible with gulp
      .pipe(source('application.js')) // Desired filename
      //.pipe(ngAnnotate())
      // .pipe(buffer())
      // .pipe(uglify())
      // .pipe(stripeDebug())
      // Output the file
      // .pipe(gulp.dest('./public/js/'))
      // .pipe(sourcemaps.init({
      //  loadMaps: true
      // }))
      // .pipe(sourcemaps.write('./maps'))
      .pipe(gulp.dest('./public/js/'));
  });

  // define jshint lint
  gulp.task('jshint', function() {
    return gulp.src(['./app/js/**/*.js', './server/**/*.js',
        './index.js', './spec/**/*.js'
      ])
      .pipe(jshint())
      .pipe(jshint.reporter('default'));
  });

  // staatic files task
  gulp.task('static-files', function() {
    return gulp.src(['!app/**/*.+(less|css|js|jade)',
        '!app/images/**/*',
        'app/**/*.*'
      ])
      .pipe(gulp.dest('./public/'));
  });

  // browser-sync task
  gulp.task('browser-sync', ['default'], function() {
    browserSync.init(null, {
      baseDir: 'public',
      proxy: 'http://localhost:5555',
      injectChanges: true
    });
  });

  // define coverage report
  gulp.task('test-coverage', function() {
    return gulp.src('./coverage/lcov/info')
      .pipe(istanbul())
      // .pipe(coveralls())
      // Force `require` to return covered files
      .pipe(istanbul.hookRequire());
  });

  //  task for back end test
  gulp.task('test:bend', ['test:fend'], function() {
    return gulp.src('spec/server/*.js', {
        read: false
      })
      .pipe(mocha({
        reporter: 'spec'
      }))
      // Creating the reports after tests ran
      .pipe(istanbul.writeReports())
      // Enforce a coverage of at least 80%
      .pipe(istanbul.enforceThresholds({
        thresholds: {
          global: 80
        }
      }));
  });

  // task for front end test
  gulp.task('test:fend', ['browserify', 'bower'], function() {
  new Server({
      configFile: __dirname + '/karma.conf.js',
      singleRun: true
    }).start();
    // server.on('browser_error', function(browser, err) {
    //   gutil.log('Karma Run Failed: ' + err.message);
    //   throw err;
    // });

    // server.on('run_complete', function(browsers, results) {
    //   if (results.failed) {
    //     throw new Error('Karma: Tests Failed');
    //   }
    //   gutil.log('Karma Run Complete: No Failures');
    //   done();
    // });

    // server.start();
  });

  // e2e test task
  gulp.task('test:e2e', function(cb) {
    gulp.src(['./spec/e2e/*.js'])
      .pipe(protractor({
        configFile: './protractor.conf.js',
        args: ['--baseUrl', 'http://127.0.0.1:8000']
      }))
      .on('error', function(e) {
        console.log(e);
      })
      .on('end', cb);
  });

  // task for nodemon
  gulp.task('nodemon', function() {
    nodemon({
      ext: 'js',
      script: 'index.js',
      ignore: ['node_modules/', 'public/', 'coverage/']
    })
    // .on('watch', ['watch'])
    .on('change', ['watch'])
      .on('restart', function() {
        console.log('Appliction restarted..>>');
      });
  });

  // task to watch files
  gulp.task('watch', function() {
    gulp.watch('./app/**/*.jade', ['jade'], browserSync.reload);
    gulp.watch('./app/styles/*.+(less|css)', ['less'], browserSync.reload);
    gulp.watch('./app/**/*.js', ['browserify'], browserSync.reload);
    gulp.watch('./gulpfile.js', ['build'], browserSync.reload);
  });

  // build task
  gulp.task('build', ['jade', 'less', 'static-files',
    'imagemin', 'browserify', 'bower'
  ]);

  // register test task
  gulp.task('test', ['test:fend', 'test:bend']);
  // deployment tasks
  gulp.task('heroku:production', ['build']);
  gulp.task('heroku:develop', ['build']);
  gulp.task('production', ['nodemon', 'build']);
  // register default tasks
  gulp.task('default', ['nodemon', 'watch', 'build']);
})();<|endoftext|>


<commit_before>process.env.NODE_ENV = '"release"';

var gulp = require('gulp'),
    rename = require('gulp-rename'),
    browserify = require('browserify'),
    sass = require('gulp-sass'),
    babel = require('gulp-babel'),
    gulpSequence = require('gulp-sequence'),
    miniPackageJson = require('./scripts/gulp-mini-package-json'),
    componentPropTypeJson = require('./scripts/gulp-component-prop-type-json');

function printError(e) {
    console.error(e.toString());
}

/**
 * sass compile
 */
gulp.task('sass', function () {
    return gulp.src('./src/**/*.scss')
        .pipe(sass())
        .on('error', printError)
        .pipe(gulp.dest('./dist'));
});

/**
 * es compile
 */
gulp.task('es', function () {
    return gulp.src('./src/**/*.js')
        .pipe(babel({
            plugins: ['transform-runtime']
        }))
        .on('error', printError)
        .pipe(gulp.dest('./dist'));
});

/**
 * copy extra files to dist
 */
gulp.task('copyAssets', function () {
    return gulp.src('./assets/**')
        .pipe(gulp.dest('./dist/assets'));
});
gulp.task('copyNpmFiles', function () {
    return gulp.src(['README.md', './LICENSE'])
        .pipe(gulp.dest('./dist'));
});
gulp.task('copyPackageJson', function () {
    return gulp.src('./package.json')
        .pipe(miniPackageJson())
        .pipe(gulp.dest('./dist'));
});
gulp.task('copyFiles', gulpSequence('copyAssets', 'copyNpmFiles', 'copyPackageJson'));

/**
 * generate props type json include name, type, default and desc of components
 */
gulp.task('propType', function () {
    return gulp.src(['./src/**/*.js', '!./src/**/index.js'])
        .pipe(componentPropTypeJson())
        .pipe(rename(function (path) {
            path.dirname = '';
            path.extname = '.json';
        }))
        .pipe(gulp.dest('./examples/assets/propTypes'));
});

/**
 * build components for npm publish
 */
gulp.task('build', gulpSequence('sass', 'es', 'copyFiles'));

/**
 * watch components src files
 */
gulp.task('watch', function () {
    gulp.watch('./src/**/*.scss', ['sass']);
    gulp.watch('./src/**/*.js', ['es']);
});<commit_msg>remove unused code<commit_after>process.env.NODE_ENV = '"release"';

var gulp = require('gulp'),
    rename = require('gulp-rename'),
    sass = require('gulp-sass'),
    babel = require('gulp-babel'),
    gulpSequence = require('gulp-sequence'),
    miniPackageJson = require('./scripts/gulp-mini-package-json'),
    componentPropTypeJson = require('./scripts/gulp-component-prop-type-json');

function printError(e) {
    console.error(e.toString());
}

/**
 * sass compile
 */
gulp.task('sass', function () {
    return gulp.src('./src/**/*.scss')
        .pipe(sass())
        .on('error', printError)
        .pipe(gulp.dest('./dist'));
});

/**
 * es compile
 */
gulp.task('es', function () {
    return gulp.src('./src/**/*.js')
        .pipe(babel({
            plugins: ['transform-runtime']
        }))
        .on('error', printError)
        .pipe(gulp.dest('./dist'));
});

/**
 * copy extra files to dist
 */
gulp.task('copyAssets', function () {
    return gulp.src('./assets/**')
        .pipe(gulp.dest('./dist/assets'));
});
gulp.task('copyNpmFiles', function () {
    return gulp.src(['README.md', './LICENSE'])
        .pipe(gulp.dest('./dist'));
});
gulp.task('copyPackageJson', function () {
    return gulp.src('./package.json')
        .pipe(miniPackageJson())
        .pipe(gulp.dest('./dist'));
});
gulp.task('copyFiles', gulpSequence('copyAssets', 'copyNpmFiles', 'copyPackageJson'));

/**
 * generate props type json include name, type, default and desc of components
 */
gulp.task('propType', function () {
    return gulp.src(['./src/**/*.js', '!./src/**/index.js'])
        .pipe(componentPropTypeJson())
        .pipe(rename(function (path) {
            path.dirname = '';
            path.extname = '.json';
        }))
        .pipe(gulp.dest('./examples/assets/propTypes'));
});

/**
 * build components for npm publish
 */
gulp.task('build', gulpSequence('sass', 'es', 'copyFiles'));

/**
 * watch components src files
 */
gulp.task('watch', function () {
    gulp.watch('./src/**/*.scss', ['sass']);
    gulp.watch('./src/**/*.js', ['es']);
});<|endoftext|>


<commit_before>require('coffee-script');
require('./gulpfile.coffee');
<commit_msg>Fixed CoffeeScript issue with node<commit_after>require('coffee-script/register');
require('./gulpfile.coffee');
<|endoftext|>


<commit_before>var uglifyJS = require('uglify-js');
var cleanCSS = require('clean-css');
var fs = require('fs');
var gulp = require('gulp');
var through = require('through2');

var config = JSON.parse(fs.readFileSync('./package.json'));
var cdnconf, cdnBucket, cdnDomain;

try{
  cdnconf = JSON.parse(fs.readFileSync('.cdnconf.json'));

  var qiniu = require('node-qiniu');
  qiniu.config(cdnconf);

  cdnBucket = require('node-qiniu').bucket(cdnconf.bucket);
  cdnDomain = cdnconf.domain;
}catch(ex){
  cdnconf = null;
}

function compile(src){

  var query = require('path').parse(src);

  var name = query.name;
  var ext = query.ext;

  var path = srcToFilePath(src);
  var contents = '';
  var prePromise = Promise.resolve();

  if(ext === '.js'){
    contents = uglifyJS.minify(path).code;
    if(name === 'app'){
      if(cdnBucket){
        var extensions = contents.match(/lang-[a-z]+?\.js/g);
        var promises = [];
        var prefix = '/static/module/code-prettify/';

        //console.log(extensions);
        extensions.forEach(function(extension){
          var src = prefix + extension;
          promises.push(compile(src).then(function(res){
            contents = contents.replace(extension, res);
          }));
        });
        prePromise = Promise.all(promises).then(function(){
          contents = contents.replace(prefix, '');
        });
      }else{
        contents = contents.replace(/(lang-[a-z]+?)(\.js)/g, '$1.min$2');
      }
    }
  }else if(ext === '.css'){
    var cssText = fs.readFileSync(path);
    contents = new cleanCSS().minify(cssText).styles;
  }

  var re = new RegExp(name + ext + '$');
  var compressed = name + '.min' + ext;

  path = path.replace(re, compressed);

  if(cdnBucket){
    return prePromise.then(function(){
      fs.writeFileSync(path, contents, 'utf-8');

      return new Promise(function(resolve, reject){
        require('checksum').file(path, function(err, sum){
          var cdnFile = 'static/!ssl' + sum.slice(20) + '/' + compressed;

          cdnBucket.putFile(cdnFile, path, function(err, reply){
            if(!err){
              var url = cdnDomain +'/'+ reply.key;
              resolve(url);
            }else{
              reject(err);
            }
          });
        });
      });
    });
  }else{
    return prePromise.then(function(){
      fs.writeFileSync(path, contents, 'utf-8');

      return Promise.resolve(src.replace(re, compressed) + '?v=' + config.version);
    });
  }
}

function srcToFilePath(src){
  src = require('url').parse(src).pathname;
  return __dirname  + '/src' + src;
}

gulp.task('resource', function() {
  gulp.src(['./src/**/*.min.js', './src/**/*.min.css'])
      .pipe(gulp.dest('./dist'));
});

gulp.task('default', function() {
  gulp.src(['./src/index.html'])
      .pipe(through.obj(function(file, encode, cb) {
        var contents = file.contents.toString(encode);
        var $ = require('cheerio').load(contents, {decodeEntities: false});

        var promises = [];

        //处理外链 css
        var links = $('link');
        for(var i = 0; i < links.length; i++){
          var link = $(links[i]);
          if(link.attr('rel') === 'stylesheet'){
            var href = link.attr('href');
            if(/^\/static\//.test(href)){
              (function(link){
                promises.push(compile(href).then(function(res){
                  link.attr('href', res);
                }).catch(function(err){
                  console.log(err);
                }));
              })(link);
            }
          }
        }

        var scripts = $('script');
        for(var i = 0; i < scripts.length; i++){
          var s = $(scripts[i]);

          if(s.attr('type') == null
            || s.attr('type') === 'text/javascript'){
            var src = s.attr('src');

            if(src){
              if(/^\/static\//.test(src)){
                (function(s, src){
                  promises.push(compile(src).then(function(res){
                    s.attr('src', res);
                  }).catch(function(err){
                    console.log(err);
                  }));
                })(s, src);
              }
            }
          }
        }

        Promise.all(promises).then(function(){
          contents = $.html();

          var HTMLMinifier = require('html-minifier').minify;

          var minified = HTMLMinifier(contents, {
            minifyCSS: true,
            minifyJS: true,
            collapseWhitespace: true,
            removeAttributeQuotes: true
          });

          file.contents = new Buffer(minified, encode);

          if(!cdnBucket) gulp.start('resource');

          cb(null, file, encode);
        });

      })).pipe(gulp.dest('./dist'));
});<commit_msg>bug fixed<commit_after>var uglifyJS = require('uglify-js');
var cleanCSS = require('clean-css');
var fs = require('fs');
var gulp = require('gulp');
var through = require('through2');

var config = JSON.parse(fs.readFileSync('./package.json'));
var cdnconf, cdnBucket, cdnDomain;

try{
  cdnconf = JSON.parse(fs.readFileSync('.cdnconf.json'));

  var qiniu = require('node-qiniu');
  qiniu.config(cdnconf);

  cdnBucket = require('node-qiniu').bucket(cdnconf.bucket);
  cdnDomain = cdnconf.domain;
}catch(ex){
  cdnconf = null;
}

function compile(src){

  var query = require('path').parse(src);

  var name = query.name;
  var ext = query.ext;

  var path = srcToFilePath(src);
  var contents = '';
  var prePromise = Promise.resolve();

  if(ext === '.js'){
    contents = uglifyJS.minify(path).code;
    if(name === 'app'){
      var extensions = contents.match(/lang-[a-z]+?\.js/g);
      var promises = [];

      var prefix = '/static/module/code-prettify/';

      //console.log(extensions);
      extensions.forEach(function(extension){
        var src = prefix + extension;
        promises.push(compile(src).then(function(res){
          contents = contents.replace(extension, res);
        }));
      });
      prePromise = Promise.all(promises).then(function(){
        contents = contents.replace(prefix, '');
      });
    }
  }else if(ext === '.css'){
    var cssText = fs.readFileSync(path);
    contents = new cleanCSS().minify(cssText).styles;
  }

  var re = new RegExp(name + ext + '$');
  var compressed = name + '.min' + ext;

  path = path.replace(re, compressed);

  if(cdnBucket){
    return prePromise.then(function(){
      fs.writeFileSync(path, contents, 'utf-8');

      return new Promise(function(resolve, reject){
        require('checksum').file(path, function(err, sum){
          var cdnFile = 'static/!ssl' + sum.slice(20) + '/' + compressed;

          cdnBucket.putFile(cdnFile, path, function(err, reply){
            if(!err){
              var url = cdnDomain +'/'+ reply.key;
              resolve(url);
            }else{
              reject(err);
            }
          });
        });
      });
    });
  }else{
    return prePromise.then(function(){
      fs.writeFileSync(path, contents, 'utf-8');

      return Promise.resolve(src.replace(re, compressed) + '?v=' + config.version);
    });
  }
}

function srcToFilePath(src){
  src = require('url').parse(src).pathname;
  return __dirname  + '/src' + src;
}

gulp.task('resource', function() {
  gulp.src(['./src/**/*.min.js', './src/**/*.min.css'])
      .pipe(gulp.dest('./dist'));
});

gulp.task('default', function() {
  gulp.src(['./src/index.html'])
      .pipe(through.obj(function(file, encode, cb) {
        var contents = file.contents.toString(encode);
        var $ = require('cheerio').load(contents, {decodeEntities: false});

        var promises = [];

        //处理外链 css
        var links = $('link');
        for(var i = 0; i < links.length; i++){
          var link = $(links[i]);
          if(link.attr('rel') === 'stylesheet'){
            var href = link.attr('href');
            if(/^\/static\//.test(href)){
              (function(link){
                promises.push(compile(href).then(function(res){
                  link.attr('href', res);
                }).catch(function(err){
                  console.log(err);
                }));
              })(link);
            }
          }
        }

        var scripts = $('script');
        for(var i = 0; i < scripts.length; i++){
          var s = $(scripts[i]);

          if(s.attr('type') == null
            || s.attr('type') === 'text/javascript'){
            var src = s.attr('src');

            if(src){
              if(/^\/static\//.test(src)){
                (function(s, src){
                  promises.push(compile(src).then(function(res){
                    s.attr('src', res);
                  }).catch(function(err){
                    console.log(err);
                  }));
                })(s, src);
              }
            }
          }
        }

        Promise.all(promises).then(function(){
          contents = $.html();

          var HTMLMinifier = require('html-minifier').minify;

          var minified = HTMLMinifier(contents, {
            minifyCSS: true,
            minifyJS: true,
            collapseWhitespace: true,
            removeAttributeQuotes: true
          });

          file.contents = new Buffer(minified, encode);

          if(!cdnBucket) gulp.start('resource');

          cb(null, file, encode);
        });

      })).pipe(gulp.dest('./dist'));
});<|endoftext|>


<commit_before>var browsersync = require('browser-sync');
var reload      = browsersync.reload;
var gulp        = require('gulp');
var rename      = require('gulp-rename');
var runSequence = require('run-sequence');
var pkg         = require('./package.json');
var autoprefixerBrowsers = ['> 1%', 'last 2 version', 'Firefox ESR', 'Opera 12.1', 'IE 8', 'IE 9'];
var headerBanner = [
'/*!',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link    <%= pkg.homepage %>',
' * @author  <%= pkg.author %>',
' * @license <%= pkg.license %>',
' */',
''].join('\n');

module.exports = {
  'browsersync': {
    server: './_public'
  },
  'uninstall': {
    files: [
      './dist',
      './_public',
      './docs/static/build',
      './scss/vendor'
    ]
  },
  'rubysass': {
    src: './scss/sircus.scss',
    dest: './docs/static/build',
    rubySassOptions: {
      sourcemap: true,
      noCache: true,
      // style:''
    },
    autoprefixer: autoprefixerBrowsers,
    fallback:{
      use:false,
      colorHexOptions:{rgba: true}
    },
    filter:'**/*.css',
    headerBanner : true,
    banner:headerBanner,
    pkg: pkg,
    notify :"Compiled Sass"
  },
  'csslint': {
    setting:'./.csslintrc',
    src: './docs/static/build/sircus.css'
  },
  'cssmin': {
    src: './docs/static/build/sircus.css',
    dest: './docs/static/build'
  },
  'ghpage' : {
    src : './_public/**/*',
    remoteUrl : 'https://github.com/sircus/sircus.github.io.git',
    branch : 'master'
  },
  'hugo' : {
    src : './docs'
  },
  'bump': {
    version: pkg.version, // base
    src:  './bower.json', //
    dest: '.'
  },
  'pagespeed': {
    production: 'http://sircus.blivesta.com',
    strategy: 'mobile'
  },
  'stylestats' :{
    src:  './dist/sircus.css'
  }
};

gulp.task('bower', require('gulptasks/lib/bower'));
gulp.task('rubysass', require('gulptasks/lib/rubysass'));
gulp.task('csslint', require('gulptasks/lib/csslint'));
gulp.task('cssmin', require('gulptasks/lib/cssmin'));
gulp.task('stylestats', require('gulptasks/lib/stylestats'));
gulp.task('deploy', require('gulptasks/lib/ghpage'));
gulp.task('bump', require('gulptasks/lib/bump'));
gulp.task('hugo', require('gulptasks/lib/hugo'));
gulp.task('uninstall', require('gulptasks/lib/uninstall'));
gulp.task('pagespeed', require('gulptasks/lib/pagespeed'));
gulp.task('browsersync', require('gulptasks/lib/browsersync'));

gulp.task('default',['browsersync'],function() {
  gulp.watch(['./scss/**/*.scss'], ['rubysass']);
  gulp.watch(['./docs/**/*.{html,css,md}'], ['hugo',reload]);
  gulp.watch(['./_public'], reload);
});

gulp.task('dist',function() {
  return gulp.src('./docs/static/build/**.css')
    .pipe(gulp.dest('./dist'));
});

gulp.task('bower-html5-reset',function() {
  return gulp.src('./bower_components/HTML5-Reset/assets/css/reset.css')
    .pipe(rename('_html5-reset.scss'))
    .pipe(gulp.dest('./scss/vendor/'));
});

gulp.task('bower-normalize',function() {
  return gulp.src('./bower_components/normalize.css/normalize.css')
    .pipe(rename('_normalize.scss'))
    .pipe(gulp.dest('./scss/vendor/'));
});

gulp.task('build', function() {
  runSequence(
    'bower','uninstall',
    ['bower-html5-reset','bower-normalize'],
    'rubysass',
    [
      // 'csslint',
      'cssmin'],
    'hugo',
    ['bump','dist'],
    'stylestats',
    ['default']
  );
});
<commit_msg>fix buid task<commit_after>var browsersync = require('browser-sync');
var reload      = browsersync.reload;
var gulp        = require('gulp');
var rename      = require('gulp-rename');
var runSequence = require('run-sequence');
var pkg         = require('./package.json');
var autoprefixerBrowsers = ['> 1%', 'last 2 version', 'Firefox ESR', 'Opera 12.1', 'IE 8', 'IE 9'];
var headerBanner = [
'/*!',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link    <%= pkg.homepage %>',
' * @author  <%= pkg.author %>',
' * @license <%= pkg.license %>',
' */',
''].join('\n');

module.exports = {
  'browsersync': {
    server: './_public'
  },
  'uninstall': {
    files: [
      './dist',
      './_public',
      './docs/static/build',
      './scss/vendor'
    ]
  },
  'rubysass': {
    src: './scss/sircus.scss',
    dest: './docs/static/build',
    rubySassOptions: {
      sourcemap: true,
      noCache: true,
      // style:''
    },
    autoprefixer: autoprefixerBrowsers,
    fallback:{
      use:false,
      colorHexOptions:{rgba: true}
    },
    filter:'**/*.css',
    headerBanner : true,
    banner:headerBanner,
    pkg: pkg,
    notify :"Compiled Sass"
  },
  'csslint': {
    setting:'./.csslintrc',
    src: './docs/static/build/sircus.css'
  },
  'cssmin': {
    src: './docs/static/build/sircus.css',
    dest: './docs/static/build'
  },
  'ghpage' : {
    src : './_public/**/*',
    remoteUrl : 'https://github.com/sircus/sircus.github.io.git',
    branch : 'master'
  },
  'hugo' : {
    src : './docs'
  },
  'bump': {
    version: pkg.version, // base
    src:  './bower.json', //
    dest: '.'
  },
  'pagespeed': {
    production: 'http://sircus.blivesta.com',
    strategy: 'mobile'
  },
  'stylestats' :{
    src:  './dist/sircus.css'
  }
};

gulp.task('bower', require('gulptasks/lib/bower'));
gulp.task('rubysass', require('gulptasks/lib/rubysass'));
gulp.task('csslint', require('gulptasks/lib/csslint'));
gulp.task('cssmin', require('gulptasks/lib/cssmin'));
gulp.task('stylestats', require('gulptasks/lib/stylestats'));
gulp.task('deploy', require('gulptasks/lib/ghpage'));
gulp.task('bump', require('gulptasks/lib/bump'));
gulp.task('hugo', require('gulptasks/lib/hugo'));
gulp.task('uninstall', require('gulptasks/lib/uninstall'));
gulp.task('pagespeed', require('gulptasks/lib/pagespeed'));
gulp.task('browsersync', require('gulptasks/lib/browsersync'));

gulp.task('default',['browsersync'],function() {
  gulp.watch(['./scss/**/*.scss'], ['rubysass']);
  gulp.watch(['./docs/**/*.{html,css,md}'], ['hugo',reload]);
  gulp.watch(['./_public'], reload);
});

gulp.task('dist',function() {
  return gulp.src('./docs/static/build/**.css')
    .pipe(gulp.dest('./dist'));
});

gulp.task('bower-html5-reset',function() {
  return gulp.src('./bower_components/HTML5-Reset/assets/css/reset.css')
    .pipe(rename('_html5-reset.scss'))
    .pipe(gulp.dest('./scss/vendor/'));
});

gulp.task('bower-normalize',function() {
  return gulp.src('./bower_components/normalize.css/normalize.css')
    .pipe(rename('_normalize.scss'))
    .pipe(gulp.dest('./scss/vendor/'));
});

gulp.task('build', function() {
  runSequence(
    'bower','uninstall',
    // ['bower-html5-reset','bower-normalize'],
    'rubysass',
    [
      // 'csslint',
      'cssmin'],
    'hugo',
    ['bump','dist'],
    'stylestats',
    ['default']
  );
});
<|endoftext|>


<commit_before><commit_msg>Added a line of text in gulpfile.<commit_after>'use strict';<|endoftext|>