<commit_before>var gulp = require('gulp'),
    concat = require('gulp-concat-sourcemap'),
    uglify = require('gulp-uglify'),
    sass = require('gulp-sass'),
    sourcemaps = require('gulp-sourcemaps'),
    autoprefixer = require('gulp-autoprefixer'),
    base64 = require('gulp-base64'),
    svgmin = require('gulp-svgmin'),
    size = require('gulp-size'),
    Q = require('q'),
    colors = require('colors');

// paths & options used within the tasks
var paths = {
    scripts : [
        {
            dest : 'html/js',
            destFile : 'public.min.js',
            files :
                [
                    'node_modules/jquery/dist/jquery.js',
                    'html/js/src/common/svg_icons.js',
                    'html/js/src/public.js'
                ],
        },
        {
            dest : 'html/js',
            destFile : 'admin.min.js',
            files :
                [
                    'node_modules/jquery/dist/jquery.js',
                    'html/js/src/common/svg_icons.js',
                    'html/js/src/common/md.js',
                    'html/js/src/admin/admin.js',
                    'html/js/src/admin/user.js',
                    'html/js/src/admin.js'
                ],
        }
    ],
    styles : [
        {
            src : 'html/css/sass/*.scss',
            dest : 'html/css',
            options : {
                outputStyle : 'compressed'
            }
        }
    ]
};

// Scripts
gulp.task('scripts', function() {
    var deferred = Q.defer();

    setTimeout(function() {
        var script, uglify_options;
        for (var key in paths.scripts) {
            script = paths.scripts[key];

            uglify_options = {
                mangle : true
            };
            for (var _key in script.uglify_options) {
                uglify_options[_key] = script.uglify_options[_key];
            }

            gulp.src(script.files)
                .pipe(sourcemaps.init())
                .pipe(concat(script.destFile))
                .on('error', function (err) {
                    console.log('   ' + 'Concat JS ERROR'.underline.red);
                    console.log('   ' + err.message.underline.red);
                })
                .pipe(uglify(uglify_options))
                .on('error', function (err) {
                    console.log('   ' + 'Uglify JS ERROR'.underline.red);
                    console.log('   Line ' + err.lineNumber + ': ' + err.message.underline.red);
                })
                .pipe(sourcemaps.write('.', {
                    includeContent : false,
                    sourceRoot : 'src/'
                }))
                .pipe(size({
                    showFiles: true
                }))
                .pipe(gulp.dest(script.dest));
        }

        deferred.resolve();
    }, 1);

    return deferred.promise;
});

// Styles
gulp.task('styles', function() {
    var deferred = Q.defer();

    setTimeout(function() {
        var style;
        for (var key in paths.styles) {
            style = paths.styles[key];

            gulp.src(style.src)
                .pipe(sourcemaps.init())
                .pipe(sass(style.options))
                .on('error', function (err) {
                    console.log('   ' + 'SASS ERROR'.underline.red);
                    console.log('   ' + err.message.underline.red);
                })
                .pipe(autoprefixer())
                .on('error', function (err) {
                    console.log('   ' + 'Autoprefixer ERROR'.underline.red);
                    console.log('   ' + err.message.underline.red);
                })
                .pipe(sourcemaps.write('.', {
                    includeContent : false,
                    sourceRoot : 'sass/'
                }))
                // inline any files with extensions: svg, png#datauri, or jpg#datauri
                .pipe(base64({
                    baseDir : 'html',
                    extensions : ['svg', /\.png#datauri$/i, /\.jpg#datauri$/i],
                    maxImageSize : 8*1024 // bytes
                }))
                .on('error', function (err) {
                    console.log('   ' + 'Base64 ERROR'.underline.red);
                    console.log('   ' + err.message.underline.red);
                })
                .pipe(size({
                    showFiles: true
                }))
                .pipe(gulp.dest(style.dest));
        }

        deferred.resolve();
    }, 1);

    return deferred.promise;
});

// SVGs
gulp.task('svgs', function() {
    return gulp.src('html/images/**/*.svg')
        .pipe(svgmin())
        .pipe(gulp.dest('html/images'));
});

// Rerun the task when a file changes
gulp.task('watch', function() {
    // watch everything in the JS dirs & sub dirs with extension .js, but exclude the .min.js files
    gulp.watch(['html/js/src/**/*.js'], ['scripts']);
    // watch everything in the sass dirs & sub dirs with extension .scss
    gulp.watch(['html/css/sass/**/*.scss'], ['styles']);
});

// The default task (called when you run `gulp` from cli)
gulp.task('default', ['scripts', 'styles']);<commit_msg>removing trailing commas in JS<commit_after>var gulp = require('gulp'),
    concat = require('gulp-concat-sourcemap'),
    uglify = require('gulp-uglify'),
    sass = require('gulp-sass'),
    sourcemaps = require('gulp-sourcemaps'),
    autoprefixer = require('gulp-autoprefixer'),
    base64 = require('gulp-base64'),
    svgmin = require('gulp-svgmin'),
    size = require('gulp-size'),
    Q = require('q'),
    colors = require('colors');

// paths & options used within the tasks
var paths = {
    scripts : [
        {
            dest : 'html/js',
            destFile : 'public.min.js',
            files :
                [
                    'node_modules/jquery/dist/jquery.js',
                    'html/js/src/common/svg_icons.js',
                    'html/js/src/public.js'
                ]
        },
        {
            dest : 'html/js',
            destFile : 'admin.min.js',
            files :
                [
                    'node_modules/jquery/dist/jquery.js',
                    'html/js/src/common/svg_icons.js',
                    'html/js/src/common/md.js',
                    'html/js/src/admin/admin.js',
                    'html/js/src/admin/user.js',
                    'html/js/src/admin.js'
                ]
        }
    ],
    styles : [
        {
            src : 'html/css/sass/*.scss',
            dest : 'html/css',
            options : {
                outputStyle : 'compressed'
            }
        }
    ]
};

// Scripts
gulp.task('scripts', function() {
    var deferred = Q.defer();

    setTimeout(function() {
        var script, uglify_options;
        for (var key in paths.scripts) {
            script = paths.scripts[key];

            uglify_options = {
                mangle : true
            };
            for (var _key in script.uglify_options) {
                uglify_options[_key] = script.uglify_options[_key];
            }

            gulp.src(script.files)
                .pipe(sourcemaps.init())
                .pipe(concat(script.destFile))
                .on('error', function (err) {
                    console.log('   ' + 'Concat JS ERROR'.underline.red);
                    console.log('   ' + err.message.underline.red);
                })
                .pipe(uglify(uglify_options))
                .on('error', function (err) {
                    console.log('   ' + 'Uglify JS ERROR'.underline.red);
                    console.log('   Line ' + err.lineNumber + ': ' + err.message.underline.red);
                })
                .pipe(sourcemaps.write('.', {
                    includeContent : false,
                    sourceRoot : 'src/'
                }))
                .pipe(size({
                    showFiles: true
                }))
                .pipe(gulp.dest(script.dest));
        }

        deferred.resolve();
    }, 1);

    return deferred.promise;
});

// Styles
gulp.task('styles', function() {
    var deferred = Q.defer();

    setTimeout(function() {
        var style;
        for (var key in paths.styles) {
            style = paths.styles[key];

            gulp.src(style.src)
                .pipe(sourcemaps.init())
                .pipe(sass(style.options))
                .on('error', function (err) {
                    console.log('   ' + 'SASS ERROR'.underline.red);
                    console.log('   ' + err.message.underline.red);
                })
                .pipe(autoprefixer())
                .on('error', function (err) {
                    console.log('   ' + 'Autoprefixer ERROR'.underline.red);
                    console.log('   ' + err.message.underline.red);
                })
                .pipe(sourcemaps.write('.', {
                    includeContent : false,
                    sourceRoot : 'sass/'
                }))
                // inline any files with extensions: svg, png#datauri, or jpg#datauri
                .pipe(base64({
                    baseDir : 'html',
                    extensions : ['svg', /\.png#datauri$/i, /\.jpg#datauri$/i],
                    maxImageSize : 8*1024 // bytes
                }))
                .on('error', function (err) {
                    console.log('   ' + 'Base64 ERROR'.underline.red);
                    console.log('   ' + err.message.underline.red);
                })
                .pipe(size({
                    showFiles: true
                }))
                .pipe(gulp.dest(style.dest));
        }

        deferred.resolve();
    }, 1);

    return deferred.promise;
});

// SVGs
gulp.task('svgs', function() {
    return gulp.src('html/images/**/*.svg')
        .pipe(svgmin())
        .pipe(gulp.dest('html/images'));
});

// Rerun the task when a file changes
gulp.task('watch', function() {
    // watch everything in the JS dirs & sub dirs with extension .js, but exclude the .min.js files
    gulp.watch(['html/js/src/**/*.js'], ['scripts']);
    // watch everything in the sass dirs & sub dirs with extension .scss
    gulp.watch(['html/css/sass/**/*.scss'], ['styles']);
});

// The default task (called when you run `gulp` from cli)
gulp.task('default', ['scripts', 'styles']);<|endoftext|>


<commit_before>/*globals require, __dirname */
/* jshint node:true */
'use strict';

var gulp = require('gulp');
var jshint = require('gulp-jshint');
var karma = require('karma').server;
var lodash = require('lodash');
var plato = require('gulp-plato');
var karmaConfig = __dirname + '/karma.conf.js';
var paths = require('./paths');

gulp.task('complexity', function () {
  return gulp.src('src/**/*.js')
    .pipe(plato('complexity'));
});

var testConfig = function (options) {
  var travisOptions = process.env.TRAVIS &&
    {
      browsers: ['Firefox']
    };

  return lodash.assign(options, travisOptions);
};

gulp.task('test', function (done) {
  karma.start(testConfig(
    {
      configFile: karmaConfig,
      singleRun: true,
      reporters: ['progress', 'coverage', 'threshold']
    }
  ), done);
});

gulp.task('tdd', function (done) {
  gulp.watch(paths.all, ['lint']);

  karma.start({
    configFile: karmaConfig
  }, done);
});

gulp.task('lint', function () {
  return gulp
    .src(paths.lint)
    .pipe(jshint('.jshintrc'))
    .pipe(jshint.reporter('default', {verbose: true}))
    .pipe(jshint.reporter('jshint-stylish'))
    .pipe(jshint.reporter('fail'));
});

gulp.task('default', ['lint', 'complexity', 'test']);
<commit_msg>Fix issues with not using dots reporter on travis<commit_after>/*globals require, __dirname */
/* jshint node:true */
'use strict';

var gulp = require('gulp');
var jshint = require('gulp-jshint');
var karma = require('karma').server;
var lodash = require('lodash');
var plato = require('gulp-plato');
var karmaConfig = __dirname + '/karma.conf.js';
var paths = require('./paths');

gulp.task('complexity', function () {
  return gulp.src('src/**/*.js')
    .pipe(plato('complexity'));
});

var testConfig = function (options) {
  var travisOptions = process.env.TRAVIS &&
    {
      browsers: ['Firefox'],
      reporters: ['dots', 'coverage', 'threshold']
    };

  return lodash.assign(options, travisOptions);
};

gulp.task('test', function (done) {
  karma.start(testConfig(
    {
      configFile: karmaConfig,
      singleRun: true,
      reporters: ['progress', 'coverage', 'threshold']
    }
  ), done);
});

gulp.task('tdd', function (done) {
  gulp.watch(paths.all, ['lint']);

  karma.start({
    configFile: karmaConfig
  }, done);
});

gulp.task('lint', function () {
  return gulp
    .src(paths.lint)
    .pipe(jshint('.jshintrc'))
    .pipe(jshint.reporter('default', {verbose: true}))
    .pipe(jshint.reporter('jshint-stylish'))
    .pipe(jshint.reporter('fail'));
});

gulp.task('default', ['lint', 'complexity', 'test']);
<|endoftext|>


<commit_before>'use strict'; // http://www.w3schools.com/js/js_strict.asp

// 1. LOAD PLUGINS

var gulp = require('gulp');
var bourbon = require('bourbon').includePaths;
var neat = require('bourbon-neat').includePaths;
var p    = require('gulp-load-plugins')({ // This loads all the other plugins.
	DEBUG: false,
	pattern: ['gulp-*', 'gulp.*', 'del', 'run-*', 'browser*', 'vinyl-*', 'through2'],
	rename: {
		'vinyl-source-stream': 'source',
		'vinyl-buffer': 'buffer',
	},
});

// 2. CONFIGURATION

var
	src  = 'source/', // The Middleman source folder
	dest = '.tmp/',   // The "hot" build folder used by Middleman's external pipeline

	development = p.environments.development,
	production = p.environments.production,

	css = {
		in: src + 'stylesheets/**/*.{css,scss,sass}',
		out: dest + 'stylesheets/',
	},

	sassOpts = {
		imagePath: '../images',
    includePaths: [bourbon, neat],
		errLogToConsole: true
	},

	js = {
		in: src + 'javascripts/*.{js,coffee}',
		out: dest + 'javascripts/'
	},

	uglifyOpts = {
    output: {
      comments: 'uglify-save-license'
    }
	},

	images = {
		in: src + 'images/*',
		out: dest + 'images/'
	},

	serverOpts = {
		proxy: 'localhost:4567',
		open: false,
		reloadDelay: 500,
		files: [dest + '**/*.{js,css}', src + '**/*.{html,erb,haml,markdown}']
	};

// 3. WORKER TASKS

// CSS Preprocessing
gulp.task('css', function() {
	return gulp.src(css.in)
		.pipe(development(p.sourcemaps.init()))
		.pipe(p.sass(sassOpts).on('error', p.sass.logError))
		.pipe(p.autoprefixer()).on('error', handleError)
		.pipe(production(p.cleanCss()))
		.pipe(development(p.sourcemaps.write()))
		.pipe(gulp.dest(css.out));
});

// Javascript Bundling
gulp.task('js', function(done) {
	var b = p.browserify({
		entries: src + 'javascripts/all.js',
		debug: true
	});

	return b.bundle().on('error', handleError)
		.pipe(p.source('bundle.js'))
		.pipe(production ? p.buffer() : p.through.obj())
		.pipe(production(p.stripDebug()))
		.pipe(production ? p.uglify(uglifyOpts) : p.through.obj())
		.pipe(gulp.dest(js.out))
    done();
});

// Image Optimization
gulp.task('images', function() {
	return gulp.src(images.in)
		.pipe(p.changed(images.out))
		.pipe(p.imagemin())
		.pipe(gulp.dest(images.out));
});

// Clean .tmp/
gulp.task('clean', function(done) {
	p.del([
		dest + '*'
	]), done();
});

// Asset Size Report
gulp.task('sizereport', function () {
	return gulp.src(dest + '**/*')
		.pipe(p.sizereport({
			gzip: true
		}));
});

// 4. SUPER TASKS

// Development Task
gulp.task('development', gulp.series('clean', 'css', 'js', 'images'));

// Production Task
gulp.task('production', function(done) {
	p.runSequence('clean', 'css', 'js', 'images', 'sizereport', done);
});

// Default Task
// This is the task that will be invoked by Middleman's exteranal pipeline when
// running 'middleman server'
gulp.task('default', gulp.series('development', function browsersync () {

	p.browserSync.init(serverOpts);

	gulp.watch(css.in, gulp.series('css'));
	gulp.watch(js.in, gulp.series('js'));
	gulp.watch(images.in, gulp.series('images'));

}));

function handleError(err) {
	console.log(err.toString());
	this.emit('end');
}
<commit_msg>Update Gulp production task<commit_after>'use strict'; // http://www.w3schools.com/js/js_strict.asp

// 1. LOAD PLUGINS

var gulp = require('gulp');
var bourbon = require('bourbon').includePaths;
var neat = require('bourbon-neat').includePaths;
var p    = require('gulp-load-plugins')({ // This loads all the other plugins.
	DEBUG: false,
	pattern: ['gulp-*', 'gulp.*', 'del', 'run-*', 'browser*', 'vinyl-*', 'through2'],
	rename: {
		'vinyl-source-stream': 'source',
		'vinyl-buffer': 'buffer',
	},
});

// 2. CONFIGURATION

var
	src  = 'source/', // The Middleman source folder
	dest = '.tmp/',   // The "hot" build folder used by Middleman's external pipeline

	development = p.environments.development,
	production = p.environments.production,

	css = {
		in: src + 'stylesheets/**/*.{css,scss,sass}',
		out: dest + 'stylesheets/',
	},

	sassOpts = {
		imagePath: '../images',
    includePaths: [bourbon, neat],
		errLogToConsole: true
	},

	js = {
		in: src + 'javascripts/*.{js,coffee}',
		out: dest + 'javascripts/'
	},

	uglifyOpts = {
    output: {
      comments: 'uglify-save-license'
    }
	},

	images = {
		in: src + 'images/*',
		out: dest + 'images/'
	},

	serverOpts = {
		proxy: 'localhost:4567',
		open: false,
		reloadDelay: 500,
		files: [dest + '**/*.{js,css}', src + '**/*.{html,erb,haml,markdown}']
	};

// 3. WORKER TASKS

// CSS Preprocessing
gulp.task('css', function() {
	return gulp.src(css.in)
		.pipe(development(p.sourcemaps.init()))
		.pipe(p.sass(sassOpts).on('error', p.sass.logError))
		.pipe(p.autoprefixer()).on('error', handleError)
		.pipe(production(p.cleanCss()))
		.pipe(development(p.sourcemaps.write()))
		.pipe(gulp.dest(css.out));
});

// Javascript Bundling
gulp.task('js', function(done) {
	var b = p.browserify({
		entries: src + 'javascripts/all.js',
		debug: true
	});

	return b.bundle().on('error', handleError)
		.pipe(p.source('bundle.js'))
		.pipe(production ? p.buffer() : p.through.obj())
		.pipe(production(p.stripDebug()))
		.pipe(production ? p.uglify(uglifyOpts) : p.through.obj())
		.pipe(gulp.dest(js.out))
    done();
});

// Image Optimization
gulp.task('images', function() {
	return gulp.src(images.in)
		.pipe(p.changed(images.out))
		.pipe(p.imagemin())
		.pipe(gulp.dest(images.out));
});

// Clean .tmp/
gulp.task('clean', function(done) {
	p.del([
		dest + '*'
	]), done();
});

// Asset Size Report
gulp.task('sizereport', function () {
	return gulp.src(dest + '**/*')
		.pipe(p.sizereport({
			gzip: true
		}));
});

// 4. SUPER TASKS

// Development Task
gulp.task('development', gulp.series('clean', 'css', 'js', 'images'));

// Production Task
gulp.task('production', gulp.series('clean', 'css', 'js', 'images', 'sizereport'));

// Default Task
// This is the task that will be invoked by Middleman's exteranal pipeline when
// running 'middleman server'
gulp.task('default', gulp.series('development', function browsersync () {

	p.browserSync.init(serverOpts);

	gulp.watch(css.in, gulp.series('css'));
	gulp.watch(js.in, gulp.series('js'));
	gulp.watch(images.in, gulp.series('images'));

}));

function handleError(err) {
	console.log(err.toString());
	this.emit('end');
}
<|endoftext|>


<commit_before>// gulpfile.js
'use strict';

// ----------------------------------
// available tasks:
//    'gulp'
//    'gulp clean'
//          clean:cache
//    'gulp bower'
//          bower:clean - bower:scss - bower:js
//    'gulp sass'
//          sass:doc
//    'gulp html'
//          html:nunjucks - html:inject
//    'gulp serve'
//    'gulp watch'
// ----------------------------------
// plugins:
//     gulp, run-sequence, gulp-util, gulp-plumber
//     gulp-load-plugins, gulp-load-subtasks
//     gulp-nunjucks-render, gulp-changed,
//     gulp-sass, gulp-sourcemaps, browser-sync
//     gulp-prettify, gulp-newer, main-bower-files
//     gulp-flatten, del, gulp-inject, gulp-cached
//     gulp-autoprefixer, sassdoc, gulp-minify-css
//     gulp-rename, lazypipe
// ----------------------------------

// main gulp plugins
var gulp     = require('gulp'),
    path     = require('./gulp/paths.js'),
    config   = require('./gulp/config.js'),
    sequence = require('run-sequence'),
    $        = require('gulp-load-plugins')({
        // used for all plugins type not just with gulp-*
        pattern: '*'
    });

// require all tasks : gulp-load-subtasks
$.loadSubtasks('./gulp/tasks/**/*.js', $, path, config);

// common tasks
gulp.task('default', function(cb) {
    sequence(
    	// config.task.clean,
    	// config.task.clean + ':cache',
    	config.task.bower,
        [
            config.task.sass,
            // config.task.sass + ':doc',
        ],
        config.task.html,
        config.task.browserSync,
        'watch',
        cb
    )
});<commit_msg>update gulpfile<commit_after>// gulpfile.js
'use strict';

// ----------------------------------
// available tasks:
//    'gulp'
//    'gulp clean'
//          clean:cache
//    'gulp bower'
//          bower:clean - bower:scss - bower:js
//    'gulp sass'
//          sass:compile - sass:doc - sass:minifycss
//    'gulp html'
//          html:nunjucks - html:inject
//    'gulp serve'
//    'gulp watch'
// ----------------------------------
// plugins:
//     gulp, run-sequence, gulp-util, gulp-plumber
//     gulp-load-plugins, gulp-load-subtasks
//     gulp-nunjucks-render, gulp-changed,
//     gulp-sass, gulp-sourcemaps, browser-sync
//     gulp-prettify, gulp-newer, main-bower-files
//     gulp-flatten, del, gulp-inject, gulp-cached
//     gulp-autoprefixer, sassdoc, gulp-minify-css
//     gulp-rename, lazypipe
// ----------------------------------

// main gulp plugins
var gulp     = require('gulp'),
    path     = require('./gulp/paths.js'),
    config   = require('./gulp/config.js'),
    sequence = require('run-sequence'),
    $        = require('gulp-load-plugins')({
        // used for all plugins type not just with gulp-*
        pattern: '*'
    });

// require all tasks : gulp-load-subtasks
$.loadSubtasks('./gulp/tasks/**/*.js', $, path, config);

// common tasks
gulp.task('default', function(cb) {
    sequence(
    	// config.task.clean,
    	// config.task.clean + ':cache',
    	config.task.bower,
        [
            config.task.sass,
            // config.task.sass + ':doc',
        ],
        config.task.html,
        config.task.browserSync,
        'watch',
        cb
    )
});<|endoftext|>


<commit_before>'use strict';

const gulp = require('gulp');
const sass = require('gulp-sass');
const webpack = require('webpack');
const RestoreDirname = require('./webpack/restoredirname.webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

gulp.task('default', ['webpack', 'sass']);

gulp.task('sass', ['webpack'], function () {
  gulp.src([
    './src/assets/css/bundle.scss',
    './src/assets/css/composer.scss',
    './src/assets/css/viewer.scss',
    './src/assets/css/preferences.scss',
    './src/assets/css/suggestions.scss'
  ])
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest('./src/assets/css/'));
});

gulp.task('webpack', function (cb) {
  webpack({
    target: 'electron',
    context: __dirname + '/src',
    node: {
      __dirname: false
    },
    entry: {
      'index': './view/index.js',
      'prompt': './view/prompt.js',
      'composer': './view/composer.js',
      'about': './view/about.js',
      'viewer': './view/viewer.js',
      'suggestions': './view/suggestions.js',
      'preferences': './view/preferences.js',
      'entry': './main.js'
    },
    output: {
      path: __dirname + '/src/assets/js',
      publicPath: './js/',
      filename: '[name].js',
      chunkFilename: '[id].js'
    },
    module: {
      loaders: [
        {
          test: /\.vue$/,
          loader: 'vue-loader'
        },
        {
          test: /\.json$/,
          loader: 'json-loader'
        }
      ],
      noParse: /node_modules\/json-schema\/lib\/validate\.js/
    },
    plugins: [
      new RestoreDirname(),
      new ExtractTextPlugin('../css/components.scss'),
      new webpack.LoaderOptionsPlugin({
        options: {
          vue: {
            loaders: {
              sass: ExtractTextPlugin.extract('css-loader!sass-loader')
            }
          }
        }
      })
    ],
    devtool: 'source-map',
    externals: { spellchecker: 'commonjs spellchecker' }
  }, cb);
});

gulp.task('watch', function () {
  gulp.watch('./src/static/css/**/*.scss', ['sass']);
  gulp.watch(['./src/**/*.js', '!./src/entry.js', '!./src/static/js/**/*.js'], ['webpack']);
});
<commit_msg>Fix path join<commit_after>'use strict';

const gulp = require('gulp');
const sass = require('gulp-sass');
const webpack = require('webpack');
const path = require('path');
const RestoreDirname = require('./webpack/restoredirname.webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

gulp.task('default', ['webpack', 'sass']);

gulp.task('sass', ['webpack'], function () {
  gulp.src([
    './src/assets/css/bundle.scss',
    './src/assets/css/composer.scss',
    './src/assets/css/viewer.scss',
    './src/assets/css/preferences.scss',
    './src/assets/css/suggestions.scss'
  ])
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest('./src/assets/css/'));
});

gulp.task('webpack', function (cb) {
  webpack({
    target: 'electron',
    context: path.join(__dirname, 'src'),
    node: {
      __dirname: false
    },
    entry: {
      'index': './view/index.js',
      'prompt': './view/prompt.js',
      'composer': './view/composer.js',
      'about': './view/about.js',
      'viewer': './view/viewer.js',
      'suggestions': './view/suggestions.js',
      'preferences': './view/preferences.js',
      'entry': './main.js'
    },
    output: {
      path: path.join(__dirname, 'src/assets/js'),
      publicPath: './js/',
      filename: '[name].js',
      chunkFilename: '[id].js'
    },
    module: {
      loaders: [
        {
          test: /\.vue$/,
          loader: 'vue-loader'
        },
        {
          test: /\.json$/,
          loader: 'json-loader'
        }
      ],
      noParse: /node_modules\/json-schema\/lib\/validate\.js/
    },
    plugins: [
      new RestoreDirname(),
      new ExtractTextPlugin('../css/components.scss'),
      new webpack.LoaderOptionsPlugin({
        options: {
          vue: {
            loaders: {
              sass: ExtractTextPlugin.extract('css-loader!sass-loader')
            }
          }
        }
      })
    ],
    devtool: 'source-map',
    externals: { spellchecker: 'commonjs spellchecker' }
  }, cb);
});

gulp.task('watch', function () {
  gulp.watch('./src/static/css/**/*.scss', ['sass']);
  gulp.watch(['./src/**/*.js', '!./src/entry.js', '!./src/static/js/**/*.js'], ['webpack']);
});
<|endoftext|>


<commit_before>/*!
 * rose-normalize-sass [v0.0.1]
 * ___________________________________________________
 * Gulp: The streaming build system.
 * https://github.com/gulpjs/gulp | http://gulpjs.com/
 * @author  : Prabhat Kumar, http://prabhatkumar.org/
 * @date    : 11-July-2015
 * ___________________________________________________
 * @require   : Node.js®
 * @require   : Gulp
 */

'use strict';

// main module.
var gulp                   = require('gulp');
// required modules.
var sass              = require('gulp-sass');
var concat          = require('gulp-concat');
var scsslint     = require('gulp-scss-lint');
var uglify          = require('gulp-uglify');
var beautify      = require('gulp-beautify');
var sourcemaps  = require('gulp-sourcemaps');
// utility modules.
var path                   = require('path');
var gutil             = require('gulp-util');
var gulpif              = require('gulp-if');
var size              = require('gulp-size');
var del                     = require('del');
var notify          = require("gulp-notify");
var rename          = require("gulp-rename");
var replace        = require('gulp-replace');
var bytediff      = require('gulp-bytediff');
var chmod            = require('gulp-chmod');

// After every @Done, gulp-css-target;
//  Break a CSS file down into multiple targets allowing for better targeting and performance.
//  @[v0.1.0]
//  https://github.com/Snugug/gulp-css-target/
var target      = require('gulp-css-target');

// ***** SETTINGS ***** //
var AUTOPREFIXER_BROWSERS = [
  'ie >= 10',
  'ie_mob >= 10',
  'ff >= 30',
  'chrome >= 34',
  'safari >= 7',
  'opera >= 22',
  'ios >= 7',
  'android >= 4.4',
  'bb >= 10'
];
<commit_msg>update of gulpfile.js - commit.<commit_after>/*!
 * rose-normalize-sass [v0.0.1]
 * ___________________________________________________
 * Gulp: The streaming build system.
 * https://github.com/gulpjs/gulp | http://gulpjs.com/
 * @author  : Prabhat Kumar, http://prabhatkumar.org/
 * @date    : 11-July-2015
 * ___________________________________________________
 * @require   : Node.js®
 * @require   : Gulp
 */

'use strict';

// main module.
var gulp                   = require('gulp');
// required modules.
var sass              = require('gulp-sass');
var concat          = require('gulp-concat');
var scsslint     = require('gulp-scss-lint');
var uglify          = require('gulp-uglify');
var beautify      = require('gulp-beautify');
var sourcemaps  = require('gulp-sourcemaps');
// utility modules.
var path                   = require('path');
var gutil             = require('gulp-util');
var gulpif              = require('gulp-if');
var size              = require('gulp-size');
var del                     = require('del');
var notify          = require("gulp-notify");
var rename          = require("gulp-rename");
var replace        = require('gulp-replace');
var bytediff      = require('gulp-bytediff');
var chmod            = require('gulp-chmod');

// After every @Done, gulp-css-target;
//  Break a CSS file down into multiple targets allowing for better targeting and performance.
//  @[v0.1.0]
//  https://github.com/Snugug/gulp-css-target/
var target      = require('gulp-css-target');

// ***** SETTINGS ***** //
var paths = {
  root: ['']
};

var AUTOPREFIXER_BROWSERS = [
  'ie >= 10',
  'ie_mob >= 10',
  'ff >= 30',
  'chrome >= 34',
  'safari >= 7',
  'opera >= 22',
  'ios >= 7',
  'android >= 4.4',
  'bb >= 10'
];

// ***** TASKS ***** //
// Rerun the task when a file changes.
gulp.task('watch', function(){
  gulp.watch(paths.root, ['rose-sass']);
});

// The default task (called when you run 'gulp' from cli)
gulp.task('default', ['watch', 'rose-sass']);
<|endoftext|>


<commit_before>// =======================================================================
// Gulp Plugins
// =======================================================================
var gulp            = require('gulp'),
    gutil           = require('gulp-util'),
    jshint          = require('gulp-jshint'),
    stylish         = require('jshint-stylish'),
    concat          = require('gulp-concat'),
    rimraf          = require('gulp-rimraf'),
    streamify       = require('gulp-streamify'),
    uglify          = require('gulp-uglify'),
    sourcemaps      = require('gulp-sourcemaps'),
    less            = require('gulp-less'),
    prefix          = require('gulp-autoprefixer'),
    minifyCSS       = require('gulp-minify-css'),
    notify          = require('gulp-notify'),
    angularTplCache = require('gulp-angular-templatecache'),
    browserify      = require('browserify'),
    watchify        = require('watchify'),
    source          = require('vinyl-source-stream'),
    buffer          = require('vinyl-buffer'),
    runSequence     = require('run-sequence');

// =======================================================================
// File Paths
// =======================================================================
var filePath = {
    build: {
        dest: './dist'
    },
    lint: {
        src: ['./app/*.js', './app/**/*.js']
    },
    browserify: {
        src: './app/app.js',
        watch:
        [
            '!./app/assets/libs/*.js',
            '!./app/assets/libs/**/*.js',
            './app/*.js','./app/**/*.js',
            '/app/**/*.html'
        ]
    },
    styles: {
        src: './app/app.less',
        watch: ['./app/app.less','./app/**/*.less']
    },
    images: {
        src: './app/assets/images/**/*',
        watch: ['./app/assets/images', './app/assets/images/**/*'],
        dest: './dist/images/'
    },
    vendorJS: {
        // These files will be bundled into a single vendor.js file that's called at the bottom of index.html
        src:
        [
            './libs/jquery/dist/jquery.js', // v2.1.1
            './libs/bootstrap/dist/js/bootstrap.js' // v3.1.1
        ]
    },
    vendorCSS: {
        src:
        [
            './libs/bootstrap/dist/css/bootstrap.css', // v3.1.1
            './libs/font-awesome/css/font-awesome.css' // v4.1.0
        ]
    },
    copyIndex: {
        src: './app/index.html',
        watch: './app/index.html'
    },
    copyFavicon: {
        src: './app/favicon.png'
    }
};

// =======================================================================
// Error Handling
// =======================================================================
function handleError(err) {
    console.log(err.toString());
    this.emit('end');
}

// =======================================================================
// Server Settings for local development (Express Server)
// =======================================================================
var embedlr         = require('gulp-embedlr'),
    refresh         = require('gulp-livereload'),
    lrserver        = require('tiny-lr')(),
    express         = require('express'),
    livereload      = require('connect-livereload'),
    livereloadport  = 35728,
    serverportDev   = 5000,
    serverportProd  = 5050,
    server          = express();

server.use(livereload({port: livereloadport}));
// Use our 'dist' folder as rootfolder
server.use(express.static('./dist'));
// Redirects everything back to our index.html
server.all('/*', function(req, res) {
    res.sendfile('/', { root: './dist' });
});

// =======================================================================
// Dev Server Task
// =======================================================================
gulp.task('dev', function() {
    server.listen(serverportDev);
    lrserver.listen(livereloadport);
    console.log('Server running at http://localhost:5000');
});

gulp.task('stage', function() {
    server.listen(serverportProd);
    lrserver.listen(livereloadport);
    console.log('Server running at http://localhost:5050');
});

// =======================================================================
// Clean out dist folder contents on build
// =======================================================================
gulp.task('clean-dev', function () {
    return gulp.src(['!./dist/vendor.js', '!./dist/vendor.css', './dist/*.js', './dist/*.css', './dist/*.html', './dist/*.png', './dist/*.ico'], {read: false})
        .pipe(rimraf());
});

gulp.task('clean-full', function () {
    return gulp.src(['./dist/*'], {read: false})
        .pipe(rimraf());
});

// =======================================================================
// JSHint
// =======================================================================
gulp.task('lint', function() {
    return gulp.src(filePath.lint.src)
    .pipe(jshint())
    .pipe(jshint.reporter(stylish));
});

// =======================================================================
// Browserify Bundle
// =======================================================================
gulp.task('bundle-dev', function() {
    var bundler = watchify(filePath.browserify.src);

    bundler.on('update', rebundle)

    function rebundle () {
        return bundler.bundle({ debug: true })

            .pipe(source('bundle.js'))
            .on("error", handleError)
            .pipe(buffer())
            // Comment out the "Uglify" task if you don't want to minify your app in your dev environment.
            // However, it can be useful to minify your app periodically to debug any problems with minification.
            // .pipe(streamify(uglify()))
            .pipe(sourcemaps.write())
            .pipe(gulp.dest(filePath.build.dest))
            .pipe(notify({ message: 'Browserify task complete' }))
            .pipe(refresh(lrserver));
    }

    return rebundle()
});

gulp.task('bundle-prod', function() {
    var bundler = watchify(filePath.browserify.src);

    bundler.on('update', rebundle)

    function rebundle () {
        return bundler.bundle({ debug: true })
            .pipe(sourcemaps.init())
            .pipe(source('bundle.js'))
            .on("error", handleError)
            .pipe(buffer())
            .pipe(streamify(uglify()))
            .pipe(gulp.dest(filePath.build.dest))
            .pipe(notify({ message: 'Browserify task complete' }))
            .pipe(refresh(lrserver));
    }

    return rebundle()
});

// =======================================================================
// Styles Task
// =======================================================================
gulp.task('styles-dev', function () {
    return gulp.src(filePath.styles.src)
        .pipe(sourcemaps.init())
        .pipe(less())
        .on("error", handleError)
        .pipe(prefix("last 1 version", "> 1%", "ie 8", "ie 7"), {map: true})
    //    .pipe(minifyCSS())
        .pipe(sourcemaps.write())
        .pipe(gulp.dest(filePath.build.dest))
        .on("error", handleError)
        .pipe(notify({ message: 'Styles task complete' }))
        .pipe(refresh(lrserver));
});

gulp.task('styles-prod', function () {
    return gulp.src(filePath.styles.src)
        .pipe(less())
        .on("error", handleError)
        .pipe(prefix("last 1 version", "> 1%", "ie 8", "ie 7"), {map: true})
        .pipe(minifyCSS())
        .pipe(gulp.dest(filePath.build.dest))
        .on("error", handleError)
        .pipe(notify({ message: 'Styles task complete' }))
});

// =======================================================================
// Images Task
// =======================================================================
gulp.task('images', function() {
    return gulp.src(filePath.images.src)
        .on("error", handleError)
        .pipe(gulp.dest(filePath.images.dest))
        .pipe(notify({ message: 'Images copied' }))
        .pipe(refresh(lrserver));
});

// =======================================================================
// Vendor JS Task
// =======================================================================
gulp.task('vendorJS', function () {
    return gulp.src(filePath.vendorJS.src)
        .pipe(concat("vendor.js"))
        .on("error", handleError)
        .pipe(uglify())
        .pipe(gulp.dest(filePath.build.dest))
        .pipe(notify({ message: 'VendorJS task complete' }))
});

// =======================================================================
// Vendor CSS Task
// =======================================================================
gulp.task('vendorCSS', function () {
    return gulp.src(filePath.vendorCSS.src)
        .pipe(concat("vendor.css"))
        .on("error", handleError)
        .pipe(minifyCSS())
        .pipe(gulp.dest(filePath.build.dest))
        .pipe(notify({ message: 'VendorCSS task complete' }))
        .pipe(refresh(lrserver));
});

// =======================================================================
// Copy index.html
// =======================================================================
gulp.task('copyIndex', function () {
    return gulp.src(filePath.copyIndex.src)
        .pipe(gulp.dest(filePath.build.dest))
        .pipe(notify({ message: 'index.html successfully copied' }))
        .pipe(refresh(lrserver));
});

// =======================================================================
// Copy Favicon
// =======================================================================
gulp.task('copyFavicon', function () {
    return gulp.src(filePath.copyFavicon.src)
        .pipe(gulp.dest(filePath.build.dest))
        .pipe(notify({ message: 'favicon successfully copied' }));
});

// =======================================================================
// Watch for changes
// =======================================================================
gulp.task('watch', function () {
    gulp.watch(filePath.browserify.watch, ['bundle-dev']);
    gulp.watch(filePath.styles.watch, ['styles-dev']);
    gulp.watch(filePath.images.watch, ['images']);
    gulp.watch(filePath.vendorJS.src, ['vendorJS']);
    gulp.watch(filePath.vendorCSS.src, ['vendorCSS']);
    gulp.watch(filePath.copyIndex.watch, ['copyIndex']);
    console.log('Watching...');
});

// =======================================================================
// Sequential Build Rendering
// =======================================================================

// run "gulp" in terminal to build the DEV app
gulp.task('build-dev', function(callback) {
    runSequence(
        ['clean-dev', 'lint'],
        // images and vendor tasks are removed to speed up build time. Use "gulp build" to do a full re-build of the dev app.
        ['bundle-dev', 'styles-dev', 'copyIndex', 'copyFavicon'],
        ['dev', 'watch'],
        callback
    );
});

// run "gulp prod" in terminal to build the PROD-ready app
gulp.task('build-prod', function(callback) {
    runSequence(
        ['clean-full', 'lint'],
        ['bundle-prod', 'styles-prod', 'images', 'vendorJS', 'vendorCSS', 'copyIndex', 'copyFavicon'],
        ['stage'],
        callback
    );
});

// run "gulp build" in terminal for a full re-build in DEV
gulp.task('build', function(callback) {
    runSequence(
        ['clean-full', 'lint'],
        ['bundle-dev', 'styles-dev', 'images', 'vendorJS', 'vendorCSS', 'copyIndex', 'copyFavicon'],
        ['dev', 'watch'],
        callback
    );
});

gulp.task('default',['build-dev']);
gulp.task('prod',['build-prod']); <commit_msg>Removed sourcemaps from the production bundle<commit_after>// =======================================================================
// Gulp Plugins
// =======================================================================
var gulp            = require('gulp'),
    gutil           = require('gulp-util'),
    jshint          = require('gulp-jshint'),
    stylish         = require('jshint-stylish'),
    concat          = require('gulp-concat'),
    rimraf          = require('gulp-rimraf'),
    streamify       = require('gulp-streamify'),
    uglify          = require('gulp-uglify'),
    sourcemaps      = require('gulp-sourcemaps'),
    less            = require('gulp-less'),
    prefix          = require('gulp-autoprefixer'),
    minifyCSS       = require('gulp-minify-css'),
    notify          = require('gulp-notify'),
    angularTplCache = require('gulp-angular-templatecache'),
    browserify      = require('browserify'),
    watchify        = require('watchify'),
    source          = require('vinyl-source-stream'),
    buffer          = require('vinyl-buffer'),
    runSequence     = require('run-sequence');

// =======================================================================
// File Paths
// =======================================================================
var filePath = {
    build: {
        dest: './dist'
    },
    lint: {
        src: ['./app/*.js', './app/**/*.js']
    },
    browserify: {
        src: './app/app.js',
        watch:
        [
            '!./app/assets/libs/*.js',
            '!./app/assets/libs/**/*.js',
            './app/*.js','./app/**/*.js',
            '/app/**/*.html'
        ]
    },
    styles: {
        src: './app/app.less',
        watch: ['./app/app.less','./app/**/*.less']
    },
    images: {
        src: './app/assets/images/**/*',
        watch: ['./app/assets/images', './app/assets/images/**/*'],
        dest: './dist/images/'
    },
    vendorJS: {
        // These files will be bundled into a single vendor.js file that's called at the bottom of index.html
        src:
        [
            './libs/jquery/dist/jquery.js', // v2.1.1
            './libs/bootstrap/dist/js/bootstrap.js' // v3.1.1
        ]
    },
    vendorCSS: {
        src:
        [
            './libs/bootstrap/dist/css/bootstrap.css', // v3.1.1
            './libs/font-awesome/css/font-awesome.css' // v4.1.0
        ]
    },
    copyIndex: {
        src: './app/index.html',
        watch: './app/index.html'
    },
    copyFavicon: {
        src: './app/favicon.png'
    }
};

// =======================================================================
// Error Handling
// =======================================================================
function handleError(err) {
    console.log(err.toString());
    this.emit('end');
}

// =======================================================================
// Server Settings for local development (Express Server)
// =======================================================================
var embedlr         = require('gulp-embedlr'),
    refresh         = require('gulp-livereload'),
    lrserver        = require('tiny-lr')(),
    express         = require('express'),
    livereload      = require('connect-livereload'),
    livereloadport  = 35728,
    serverportDev   = 5000,
    serverportProd  = 5050,
    server          = express();

server.use(livereload({port: livereloadport}));
// Use our 'dist' folder as rootfolder
server.use(express.static('./dist'));
// Redirects everything back to our index.html
server.all('/*', function(req, res) {
    res.sendfile('/', { root: './dist' });
});

// =======================================================================
// Dev Server Task
// =======================================================================
gulp.task('dev', function() {
    server.listen(serverportDev);
    lrserver.listen(livereloadport);
    console.log('Server running at http://localhost:5000');
});

gulp.task('stage', function() {
    server.listen(serverportProd);
    lrserver.listen(livereloadport);
    console.log('Server running at http://localhost:5050');
});

// =======================================================================
// Clean out dist folder contents on build
// =======================================================================
gulp.task('clean-dev', function () {
    return gulp.src(['!./dist/vendor.js', '!./dist/vendor.css', './dist/*.js', './dist/*.css', './dist/*.html', './dist/*.png', './dist/*.ico'], {read: false})
        .pipe(rimraf());
});

gulp.task('clean-full', function () {
    return gulp.src(['./dist/*'], {read: false})
        .pipe(rimraf());
});

// =======================================================================
// JSHint
// =======================================================================
gulp.task('lint', function() {
    return gulp.src(filePath.lint.src)
    .pipe(jshint())
    .pipe(jshint.reporter(stylish));
});

// =======================================================================
// Browserify Bundle
// =======================================================================
gulp.task('bundle-dev', function() {
    var bundler = watchify(filePath.browserify.src);

    bundler.on('update', rebundle)

    function rebundle () {
        return bundler.bundle({ debug: true })
            .pipe(source('bundle.js'))
            .on("error", handleError)
            .pipe(buffer())
            // Comment out the "Uglify" task if you don't want to minify your app in your dev environment.
            // However, it can be useful to minify your app periodically to debug any problems with minification.
            // .pipe(streamify(uglify()))
            .pipe(sourcemaps.write())
            .pipe(gulp.dest(filePath.build.dest))
            .pipe(notify({ message: 'Browserify task complete' }))
            .pipe(refresh(lrserver));
    }

    return rebundle()
});

gulp.task('bundle-prod', function() {
    var bundler = watchify(filePath.browserify.src);

    bundler.on('update', rebundle)

    function rebundle () {
        return bundler.bundle({ debug: true })
            .pipe(source('bundle.js'))
            .on("error", handleError)
            .pipe(buffer())
            .pipe(streamify(uglify()))
            .pipe(gulp.dest(filePath.build.dest))
            .pipe(notify({ message: 'Browserify task complete' }))
            .pipe(refresh(lrserver));
    }

    return rebundle()
});

// =======================================================================
// Styles Task
// =======================================================================
gulp.task('styles-dev', function () {
    return gulp.src(filePath.styles.src)
        .pipe(sourcemaps.init())
        .pipe(less())
        .on("error", handleError)
        .pipe(prefix("last 1 version", "> 1%", "ie 8", "ie 7"), {map: true})
    //    .pipe(minifyCSS())
        .pipe(sourcemaps.write())
        .pipe(gulp.dest(filePath.build.dest))
        .on("error", handleError)
        .pipe(notify({ message: 'Styles task complete' }))
        .pipe(refresh(lrserver));
});

gulp.task('styles-prod', function () {
    return gulp.src(filePath.styles.src)
        .pipe(less())
        .on("error", handleError)
        .pipe(prefix("last 1 version", "> 1%", "ie 8", "ie 7"), {map: true})
        .pipe(minifyCSS())
        .pipe(gulp.dest(filePath.build.dest))
        .on("error", handleError)
        .pipe(notify({ message: 'Styles task complete' }))
});

// =======================================================================
// Images Task
// =======================================================================
gulp.task('images', function() {
    return gulp.src(filePath.images.src)
        .on("error", handleError)
        .pipe(gulp.dest(filePath.images.dest))
        .pipe(notify({ message: 'Images copied' }))
        .pipe(refresh(lrserver));
});

// =======================================================================
// Vendor JS Task
// =======================================================================
gulp.task('vendorJS', function () {
    return gulp.src(filePath.vendorJS.src)
        .pipe(concat("vendor.js"))
        .on("error", handleError)
        .pipe(uglify())
        .pipe(gulp.dest(filePath.build.dest))
        .pipe(notify({ message: 'VendorJS task complete' }))
});

// =======================================================================
// Vendor CSS Task
// =======================================================================
gulp.task('vendorCSS', function () {
    return gulp.src(filePath.vendorCSS.src)
        .pipe(concat("vendor.css"))
        .on("error", handleError)
        .pipe(minifyCSS())
        .pipe(gulp.dest(filePath.build.dest))
        .pipe(notify({ message: 'VendorCSS task complete' }))
        .pipe(refresh(lrserver));
});

// =======================================================================
// Copy index.html
// =======================================================================
gulp.task('copyIndex', function () {
    return gulp.src(filePath.copyIndex.src)
        .pipe(gulp.dest(filePath.build.dest))
        .pipe(notify({ message: 'index.html successfully copied' }))
        .pipe(refresh(lrserver));
});

// =======================================================================
// Copy Favicon
// =======================================================================
gulp.task('copyFavicon', function () {
    return gulp.src(filePath.copyFavicon.src)
        .pipe(gulp.dest(filePath.build.dest))
        .pipe(notify({ message: 'favicon successfully copied' }));
});

// =======================================================================
// Watch for changes
// =======================================================================
gulp.task('watch', function () {
    gulp.watch(filePath.browserify.watch, ['bundle-dev']);
    gulp.watch(filePath.styles.watch, ['styles-dev']);
    gulp.watch(filePath.images.watch, ['images']);
    gulp.watch(filePath.vendorJS.src, ['vendorJS']);
    gulp.watch(filePath.vendorCSS.src, ['vendorCSS']);
    gulp.watch(filePath.copyIndex.watch, ['copyIndex']);
    console.log('Watching...');
});

// =======================================================================
// Sequential Build Rendering
// =======================================================================

// run "gulp" in terminal to build the DEV app
gulp.task('build-dev', function(callback) {
    runSequence(
        ['clean-dev', 'lint'],
        // images and vendor tasks are removed to speed up build time. Use "gulp build" to do a full re-build of the dev app.
        ['bundle-dev', 'styles-dev', 'copyIndex', 'copyFavicon'],
        ['dev', 'watch'],
        callback
    );
});

// run "gulp prod" in terminal to build the PROD-ready app
gulp.task('build-prod', function(callback) {
    runSequence(
        ['clean-full', 'lint'],
        ['bundle-prod', 'styles-prod', 'images', 'vendorJS', 'vendorCSS', 'copyIndex', 'copyFavicon'],
        ['stage'],
        callback
    );
});

// run "gulp build" in terminal for a full re-build in DEV
gulp.task('build', function(callback) {
    runSequence(
        ['clean-full', 'lint'],
        ['bundle-dev', 'styles-dev', 'images', 'vendorJS', 'vendorCSS', 'copyIndex', 'copyFavicon'],
        ['dev', 'watch'],
        callback
    );
});

gulp.task('default',['build-dev']);
gulp.task('prod',['build-prod']); <|endoftext|>


<commit_before>'use strict'

var gulp = require('gulp')
var browserSync = require('browser-sync')
var nodemon = require('gulp-nodemon')
const imagemin = require('gulp-imagemin')
const mozjpeg = require('imagemin-mozjpeg')
const pngquant = require('imagemin-pngquant')

gulp.task('images', () =>
  gulp.src('public/images/**/*')
    .pipe(imagemin(
        [mozjpeg({
                'quality' : '60',
                'quantTable': 2
              }),
              pngquant({
                'quality': '60'
              })],

            {
              optimizationLevel: 3,
              progressive: true,
              interlaced: true,
            }))
    .pipe(gulp.dest('public/images'))
)

gulp.task('fa', ['fa-css'], function() {
  return gulp.src('node_modules/font-awesome/fonts/*')
    .pipe(gulp.dest('public/fonts'))
})

gulp.task('fa-css', function() {
  return gulp.src('node_modules/font-awesome/css/font-awesome.min.css')
    .pipe(gulp.dest('public/stylesheets'))
})

gulp.task('bs', ['bs-css', 'bs-jquery', 'bs-tether', 'bs-js'], function() {
})

gulp.task('bs-css', function() {
  return gulp.src('node_modules/bootstrap/dist/css/bootstrap.min.css')
    .pipe(gulp.dest('public/stylesheets'))
})

gulp.task('bs-jquery', function() {
  return gulp.src('node_modules/jquery-slim/dist/jquery.slim.min.js')
    .pipe(gulp.dest('public/javascripts'))
})

gulp.task('bs-tether', function() {
  return gulp.src('node_modules/tether/dist/js/tether.min.js')
    .pipe(gulp.dest('public/javascripts'))
})

gulp.task('bs-js', function() {
  return gulp.src('node_modules/bootstrap/dist/js/bootstrap.min.js')
    .pipe(gulp.dest('public/javascripts'))
})

gulp.task('default', ['browser-sync'], function () {
})

gulp.task('browser-sync', ['nodemon'], function () {
  browserSync.init(null, {
    proxy: 'http://localhost:3000',
    files: ['public/**/*.*'],
    port: 3001
  })
})
gulp.task('nodemon', function (cb) {
  var started = false

  return nodemon({
    exec: 'node --debug',
    script: './bin/www'
  }).on('start', function () {
    // to avoid nodemon being started multiple times
    // thanks @matthisk
    if (!started) {
      cb()
      started = true
    }
  })
})
<commit_msg>Updated gulp tasks to watch more directories for browsersync<commit_after>'use strict'

var gulp = require('gulp')
var browserSync = require('browser-sync')
var nodemon = require('gulp-nodemon')
const imagemin = require('gulp-imagemin')
const mozjpeg = require('imagemin-mozjpeg')
const pngquant = require('imagemin-pngquant')

gulp.task('images', () =>
  gulp.src('public/images/**/*')
    .pipe(imagemin(
      [mozjpeg({
        'quality': '60',
        'quantTable': 2
      }),
      pngquant({
        'quality': '60'
      })],

      {
        optimizationLevel: 3,
        progressive: true,
        interlaced: true,
      }))
    .pipe(gulp.dest('public/images'))
)

gulp.task('fa', ['fa-css'], function () {
  return gulp.src('node_modules/font-awesome/fonts/*')
    .pipe(gulp.dest('public/fonts'))
})

gulp.task('fa-css', function () {
  return gulp.src('node_modules/font-awesome/css/font-awesome.min.css')
    .pipe(gulp.dest('public/stylesheets'))
})

gulp.task('bs', ['bs-css', 'bs-jquery', 'bs-tether', 'bs-js'], function () {
})

gulp.task('bs-css', function () {
  return gulp.src('node_modules/bootstrap/dist/css/bootstrap.min.css')
    .pipe(gulp.dest('public/stylesheets'))
})

gulp.task('bs-jquery', function () {
  return gulp.src('node_modules/jquery-slim/dist/jquery.slim.min.js')
    .pipe(gulp.dest('public/javascripts'))
})

gulp.task('bs-tether', function () {
  return gulp.src('node_modules/tether/dist/js/tether.min.js')
    .pipe(gulp.dest('public/javascripts'))
})

gulp.task('bs-js', function () {
  return gulp.src('node_modules/bootstrap/dist/js/bootstrap.min.js')
    .pipe(gulp.dest('public/javascripts'))
})

gulp.task('browser-sync', ['nodemon'], function () {
  browserSync.init(null, {
    proxy: 'http://localhost:3000',
    files: ['public/**/*.*'],
    port: 3001
  })
})

gulp.task('nodemon', function (cb) {
  var started = false

  return nodemon({
    exec: 'node --debug',
    script: './bin/www'
  }).on('start', function () {
    // to avoid nodemon being started multiple times
    // thanks @matthisk
    if (!started) {
      cb()
      started = true
    }
  }).on('restart', function onRestart() {
    // reload connected browsers after a slight delay
    setTimeout(function reload() {
      browserSync.reload({
        stream: false
      });
    }, 500);
  })
})

gulp.task('bs-reload', function () {
  browserSync.reload();
});

gulp.task('default', ['browser-sync'], function () {
  gulp.watch('config/**/*.js',   ['bs-reload'])
  gulp.watch('models/**/*.js',  ['bs-reload'])
  gulp.watch('controllers/**/*.js',  ['bs-reload'])
  gulp.watch('views/**/*.pug', ['bs-reload'])

  gulp.watch('public/**/*.js',   ['bs-reload'])
  gulp.watch('public/**/*.css',  ['bs-reload'])
});
<|endoftext|>


<commit_before>// GULP TEMPLATE - Gulfile.js - Victor Allegret
//
//   - $ gulp
//   - $ gulp build
//   - $ gulp clean
//
// --------------------------------------------------------

////////////////////
// VARIABLES
////////////////////////////////////////////////////////////////////////////////

// REQUIRE
// ---------------------------------------------------------

var gulp    = require('gulp'),
    plugins = require('gulp-load-plugins')({
        pattern: '*'
    }),
    // reload auto for Browser Sync
    reload  = plugins.browserSync.reload
    // reload once for Browser Sync
    stream = plugins.browserSync.stream

// PATH
// ---------------------------------------------------------

///// PATHS FOR DEV
var slim_dev    = './dev/views/',
    sass_dev    = './dev/assets/stylesheets/',
    coffee_dev  = './dev/assets/javascripts/',
    fonts_dev   = './dev/assets/fonts/',
    img_dev     = './dev/assets/images/',
    dev         = './dev';

///// PATH FOR PROD
var slim_build     = './build/views/',
    sass_build     = './build/assets/stylesheets/',
    coffee_build   = './build/assets/javascripts/',
    fonts_build    = './build/assets/fonts/',
    img_build      = './build/assets/images/',
    build          = './build';

////////////////////
// TASKS
////////////////////////////////////////////////////////////////////////////////

// COMPILE SLIM TO HTML
// ---------------------------------------------------------
gulp.task('slim', function () {
  return gulp.src([slim_dev + '/**/*.slim', '!./dev/views/partials/**/*.slim', '!./dev/views/layout/**/*.slim'])
    // prevent server from crashing
    .pipe(plugins.plumber({ errorHandler: function(err) {
      plugins.notify.onError({
          title: "Gulp error in " + err.plugin
      })(err);
    }}))
    // compile slim to html
    .pipe(plugins.slim({
      pretty: false,
      include: true
    }))
    // run task only for updated files
    .pipe(plugins.newer(build))
    // minify html
    .pipe(plugins.minifyHtml())
    // remove all folder
    .pipe(plugins.rename({dirname: ''}))
    // copy result to build folder
    .pipe(gulp.dest(build))
    // reload server on slim save
    .pipe(stream({once:true}))
    // notify when task completed
    .pipe(plugins.notify('Slim compilation completed !'));
});

// COMPILE SASS TO CSS
// ---------------------------------------------------------
gulp.task('sass', function () {
  return gulp.src(sass_dev + '/**/*.sass')
    // prevent server from crashing
    .pipe(plugins.plumber({ errorHandler: function(err) {
      plugins.notify.onError({
          title: "Gulp error in " + err.plugin,
      })(err);
    }}))
    // add sass glob import
    .pipe(plugins.sassGlob())
    // compile sass to css
    .pipe(plugins.sass())
    // add auto-prefixes
    .pipe(plugins.autoprefixer({
      browsers: ['last 2 versions'],
      cascade: false
    }))
    // concat all files
    .pipe(plugins.concat('main.css'))
    // rename to .min
    .pipe(plugins.rename('main.min.css'))
    // minify css
    .pipe(plugins.minifyCss())
    // copy result to build folder
    .pipe(gulp.dest(sass_build))
    // reload on sass save
    .pipe(reload({stream:true}))
    // notify when task completed
    .pipe(plugins.notify('Sass compilation completed !'));
});

// COMPILE COFFEE TO JS
// ---------------------------------------------------------
gulp.task('coffee', function() {
  return gulp.src(coffee_dev + '/**/*.coffee')
    // compile coffee to js
    .pipe(plugins.coffee())
    // concat all files
    .pipe(plugins.concat('all.js'))
    // rename to .min
    .pipe(plugins.rename('all.min.js'))
    // minify js
    .pipe(plugins.uglify())
    // copy result to build folder
    .pipe(gulp.dest(coffee_build))
    // notify when task completed
    .pipe(plugins.notify('Coffee compilation completed !'));
});

// FONTS
// ---------------------------------------------------------
gulp.task('fonts', function() {
  return gulp.src(fonts_dev + '/**/*.{eot,svg,ttf,woff,woff2}')
    // remove under-folder
    .pipe(plugins.rename({dirname: ''}))
    // copy result to build folder
    .pipe(gulp.dest(fonts_build))
});

// REMOVE UNUSED CSS
// ---------------------------------------------------------
gulp.task('uncss', function () {
  return gulp.src(sass_build + '/app.css')
  // remove unused css
   .pipe(plugins.uncss({
      html: [build + '/**/*.html']
   }))
   // minify css
   .pipe(plugins.minifyCss())
   // copy result to build folder
   .pipe(gulp.dest(sass_build))
   // notify when task completed
   .pipe(plugins.notify('Unused CSS removed !'));
});

// MINIFY IMAGES
// ---------------------------------------------------------
gulp.task('img', function () {
  return gulp.src(img_dev + '/**/*.{png,jpg,jpeg,gif,svg,ico}')
    // run task only for updated files
    .pipe(plugins.newer(img_build))
    // minify images
    .pipe(plugins.imagemin())
    // copy result to build folder
    .pipe(gulp.dest(img_build))
    // notify when task completed
    .pipe(plugins.notify('Images are optimized!'));
});

// REMOVE BUILD FOLDER
// ---------------------------------------------------------
gulp.task('removeBuild', function () {
  return gulp.src(build, { read: false})
    .pipe(plugins.rimraf())
    .pipe(plugins.notify('Prod folder deleted !'));
});

////////////////////
// COMMANDS
////////////////////////////////////////////////////////////////////////////////

// RUN SLIM | SASS | COFFEE ($ gulp dev)
// ---------------------------------------------------------
gulp.task('dev', ['slim', 'sass', 'coffee']);

// RUN SLIM | SASS | COFFEE | UNCSS | IMG ($ gulp build)
// ---------------------------------------------------------
gulp.task('build', ['slim', 'sass', 'coffee', 'fonts', 'uncss', 'img']);

// RUN CLEAN ($ gulp clean)
// ---------------------------------------------------------
gulp.task('clean', ['removeBuild']);

// RUN SERVER ($ gulp)
// ---------------------------------------------------------

///// WATCH
gulp.task('watch', ['dev'], function () {
  plugins.browserSync.init({
    server: {
      baseDir: build,
      index: "index.html"
    },
    scrollProportionally: true,
    notify: false
  })
  gulp.watch(dev + '/**/*.slim', ['slim']);
  gulp.watch(dev + '/**/*.sass', ['sass']);
  gulp.watch(dev + '/**/*.coffee', ['coffee']);
  gulp.watch(build  + '/**/*.html').on('change', stream);
});

////// COMMAND
gulp.task('default', ['watch'])<commit_msg>MINOR [gulpfile, port] Setup basic port<commit_after>// GULP TEMPLATE - Gulfile.js - Victor Allegret
//
//   - $ gulp
//   - $ gulp build
//   - $ gulp clean
//
// --------------------------------------------------------

////////////////////
// VARIABLES
////////////////////////////////////////////////////////////////////////////////

// REQUIRE
// ---------------------------------------------------------

var gulp    = require('gulp'),
    plugins = require('gulp-load-plugins')({
        pattern: '*'
    }),
    // reload auto for Browser Sync
    reload  = plugins.browserSync.reload
    // reload once for Browser Sync
    stream = plugins.browserSync.stream

// PATH
// ---------------------------------------------------------

///// PATHS FOR DEV
var slim_dev    = './dev/views/',
    sass_dev    = './dev/assets/stylesheets/',
    coffee_dev  = './dev/assets/javascripts/',
    fonts_dev   = './dev/assets/fonts/',
    img_dev     = './dev/assets/images/',
    dev         = './dev';

///// PATH FOR PROD
var slim_build     = './build/views/',
    sass_build     = './build/assets/stylesheets/',
    coffee_build   = './build/assets/javascripts/',
    fonts_build    = './build/assets/fonts/',
    img_build      = './build/assets/images/',
    build          = './build';

////////////////////
// TASKS
////////////////////////////////////////////////////////////////////////////////

// COMPILE SLIM TO HTML
// ---------------------------------------------------------
gulp.task('slim', function () {
  return gulp.src([slim_dev + '/**/*.slim', '!./dev/views/partials/**/*.slim', '!./dev/views/layout/**/*.slim'])
    // prevent server from crashing
    .pipe(plugins.plumber({ errorHandler: function(err) {
      plugins.notify.onError({
          title: "Gulp error in " + err.plugin
      })(err);
    }}))
    // compile slim to html
    .pipe(plugins.slim({
      pretty: false,
      include: true
    }))
    // run task only for updated files
    .pipe(plugins.newer(build))
    // minify html
    .pipe(plugins.minifyHtml())
    // remove all folder
    .pipe(plugins.rename({dirname: ''}))
    // copy result to build folder
    .pipe(gulp.dest(build))
    // reload server on slim save
    .pipe(stream({once:true}))
    // notify when task completed
    .pipe(plugins.notify('Slim compilation completed !'));
});

// COMPILE SASS TO CSS
// ---------------------------------------------------------
gulp.task('sass', function () {
  return gulp.src(sass_dev + '/**/*.sass')
    // prevent server from crashing
    .pipe(plugins.plumber({ errorHandler: function(err) {
      plugins.notify.onError({
          title: "Gulp error in " + err.plugin,
      })(err);
    }}))
    // add sass glob import
    .pipe(plugins.sassGlob())
    // compile sass to css
    .pipe(plugins.sass())
    // add auto-prefixes
    .pipe(plugins.autoprefixer({
      browsers: ['last 2 versions'],
      cascade: false
    }))
    // concat all files
    .pipe(plugins.concat('main.css'))
    // rename to .min
    .pipe(plugins.rename('main.min.css'))
    // minify css
    .pipe(plugins.minifyCss())
    // copy result to build folder
    .pipe(gulp.dest(sass_build))
    // reload on sass save
    .pipe(reload({stream:true}))
    // notify when task completed
    .pipe(plugins.notify('Sass compilation completed !'));
});

// COMPILE COFFEE TO JS
// ---------------------------------------------------------
gulp.task('coffee', function() {
  return gulp.src(coffee_dev + '/**/*.coffee')
    // compile coffee to js
    .pipe(plugins.coffee())
    // concat all files
    .pipe(plugins.concat('all.js'))
    // rename to .min
    .pipe(plugins.rename('all.min.js'))
    // minify js
    .pipe(plugins.uglify())
    // copy result to build folder
    .pipe(gulp.dest(coffee_build))
    // notify when task completed
    .pipe(plugins.notify('Coffee compilation completed !'));
});

// FONTS
// ---------------------------------------------------------
gulp.task('fonts', function() {
  return gulp.src(fonts_dev + '/**/*.{eot,svg,ttf,woff,woff2}')
    // remove under-folder
    .pipe(plugins.rename({dirname: ''}))
    // copy result to build folder
    .pipe(gulp.dest(fonts_build))
});

// REMOVE UNUSED CSS
// ---------------------------------------------------------
gulp.task('uncss', function () {
  return gulp.src(sass_build + '/app.css')
  // remove unused css
   .pipe(plugins.uncss({
      html: [build + '/**/*.html']
   }))
   // minify css
   .pipe(plugins.minifyCss())
   // copy result to build folder
   .pipe(gulp.dest(sass_build))
   // notify when task completed
   .pipe(plugins.notify('Unused CSS removed !'));
});

// MINIFY IMAGES
// ---------------------------------------------------------
gulp.task('img', function () {
  return gulp.src(img_dev + '/**/*.{png,jpg,jpeg,gif,svg,ico}')
    // run task only for updated files
    .pipe(plugins.newer(img_build))
    // minify images
    .pipe(plugins.imagemin())
    // copy result to build folder
    .pipe(gulp.dest(img_build))
    // notify when task completed
    .pipe(plugins.notify('Images are optimized!'));
});

// REMOVE BUILD FOLDER
// ---------------------------------------------------------
gulp.task('removeBuild', function () {
  return gulp.src(build, { read: false})
    .pipe(plugins.rimraf())
    .pipe(plugins.notify('Prod folder deleted !'));
});

////////////////////
// COMMANDS
////////////////////////////////////////////////////////////////////////////////

// RUN SLIM | SASS | COFFEE ($ gulp dev)
// ---------------------------------------------------------
gulp.task('dev', ['slim', 'sass', 'coffee']);

// RUN SLIM | SASS | COFFEE | UNCSS | IMG ($ gulp build)
// ---------------------------------------------------------
gulp.task('build', ['slim', 'sass', 'coffee', 'fonts', 'uncss', 'img']);

// RUN CLEAN ($ gulp clean)
// ---------------------------------------------------------
gulp.task('clean', ['removeBuild']);

// RUN SERVER ($ gulp)
// ---------------------------------------------------------

///// WATCH
gulp.task('watch', ['dev'], function () {
  plugins.browserSync.init({
    port: 3000,
    server: {
      baseDir: build,
      index: "index.html"
    },
    scrollProportionally: true,
    notify: false
  })
  gulp.watch(dev + '/**/*.slim', ['slim']);
  gulp.watch(dev + '/**/*.sass', ['sass']);
  gulp.watch(dev + '/**/*.coffee', ['coffee']);
  gulp.watch(build  + '/**/*.html').on('change', stream);
});

////// COMMAND
gulp.task('default', ['watch'])<|endoftext|>


<commit_before>"use strict";

const gulp = require("gulp"),
    concat = require("gulp-concat"),
    cssmin = require("gulp-cssmin"),
    htmlmin = require("gulp-htmlmin"),
    uglify = require("gulp-uglify"),
    merge = require("merge-stream"),
    pipeline = require('readable-stream').pipeline,
    del = require("del"),
    bundleconfig = require("./distbundlesconfig.json");

const replace = require('gulp-replace');
const jsdoc = require('gulp-jsdoc3');

// the md doc output is, e.g. MeadCoScriptXPrint for MeadCo.ScriptX.Print
// this table drives back replacement
const namespaces = [
    "MeadCo.ScriptX.Print",
    "Print.Licensing",
    "Print.PDF",
    "Print.HTML",
];

function getBundles(regexPattern) {
    return bundleconfig.filter(function (bundle) {
        return regexPattern.test(bundle.outputFileName);
    });
}

function mintoDist() {
    var tasks = getBundles(/\.js$/).map(function (bundle) {
        return pipeline(
            gulp.src(bundle.inputFiles, { base: "." }),
            uglify({
                output: {
                    comments: "some"
                }
                }),
            concat(bundle.outputFileName),
            gulp.dest(".")
        );
    });
    return merge(tasks);
}

function cleanDist() {
    var files = bundleconfig.map(function (bundle) {
        return bundle.outputFileName;
    });

    return del(files, { force: true });
}

function cleanDocs() {
    return del('./docs');
}

gulp.task('CompileDocs', function (done) {
    const config = require('./tooling/docs/jsdoc.json');
    gulp.src(['readme.md', '.src/**/*.js'], { read: false }).pipe(jsdoc(config,done));
});

function ProcessName(nsname) {
    console.log("Start ProcessName: " + nsname);

    var badName = nsname.replace(/\./g, "");

    console.log("Replace: " + badName + " with: " + nsname);

    var regx = new RegExp(badName + "(?![a-zA-Z]*\.html)", "gi")
    return gulp.src("./docs/*.html").pipe(replace(regx, nsname)).pipe(gulp.dest("./docs"));
}

gulp.task('ProcessDocs1', function () {
    return ProcessName("MeadCo.ScriptX.Print.Licensing");
});

gulp.task('ProcessDocs2', function () {
    return ProcessName("MeadCo.ScriptX.Print.HTML");
});

gulp.task('ProcessDocs3', function () {
    return ProcessName("MeadCo.ScriptX.Print.PDF");
});

gulp.task('ProcessDocs4', function () {
    return ProcessName("MeadCo.ScriptX.Print");
});

gulp.task('MakeDocs', gulp.series('CompileDocs', 'ProcessDocs1', 'ProcessDocs2','ProcessDocs3', 'ProcessDocs4'));

exports.buildDist = gulp.series(gulp.parallel(cleanDist,cleanDocs), gulp.parallel(mintoDist, 'MakeDocs'));
<commit_msg>tidy gulp processes<commit_after>"use strict";

const gulp = require("gulp"),
    concat = require("gulp-concat"),
    cssmin = require("gulp-cssmin"),
    htmlmin = require("gulp-htmlmin"),
    uglify = require("gulp-uglify"),
    merge = require("merge-stream"),
    pipeline = require('readable-stream').pipeline,
    del = require("del"),
    bundleconfig = require("./distbundlesconfig.json");

const replace = require('gulp-replace');
const jsdoc = require('gulp-jsdoc3');

// the md doc output is, e.g. MeadCoScriptXPrint for MeadCo.ScriptX.Print
// this table drives back replacement
const namespaces = [
    "MeadCo.ScriptX.Print",
    "Print.Licensing",
    "Print.PDF",
    "Print.HTML",
];

function getBundles(regexPattern) {
    return bundleconfig.filter(function (bundle) {
        return regexPattern.test(bundle.outputFileName);
    });
}

function mintoDist() {
    var tasks = getBundles(/\.js$/).map(function (bundle) {
        return pipeline(
            gulp.src(bundle.inputFiles, { base: "." }),
            uglify({
                output: {
                    comments: "some"
                }
                }),
            concat(bundle.outputFileName),
            gulp.dest(".")
        );
    });
    return merge(tasks);
}

function cleanDist() {
    var files = bundleconfig.map(function (bundle) {
        return bundle.outputFileName;
    });

    return del(files, { force: true });
}

function cleanDocs() {
    return del('./docs');
}

gulp.task('CompileDocs', function (done) {
    const config = require('./tooling/docs/jsdoc.json');
    gulp.src(['readme.md', '.src/**/*.js'], { read: false }).pipe(jsdoc(config,done));
});

function ProcessName(nsname) {

    var badName = nsname.replace(/\./g, "");

    // console.log("Replace: " + badName + " with: " + nsname);

    var regx = new RegExp(badName + "(?![a-zA-Z]*\.html)", "gi")
    return gulp.src("./docs/*.html").pipe(replace(regx, nsname)).pipe(gulp.dest("./docs"));
}

gulp.task('ProcessDocs1', function () {
    return ProcessName("MeadCo.ScriptX.Print.Licensing");
});

gulp.task('ProcessDocs2', function () {
    return ProcessName("MeadCo.ScriptX.Print.HTML");
});

gulp.task('ProcessDocs3', function () {
    return ProcessName("MeadCo.ScriptX.Print.PDF");
});

gulp.task('ProcessDocs4', function () {
    return ProcessName("MeadCo.ScriptX.Print");
});

gulp.task('MakeDocs', gulp.series('CompileDocs', 'ProcessDocs1', 'ProcessDocs2', 'ProcessDocs3', 'ProcessDocs4'));

gulp.task('BuildDocs', gulp.series(cleanDocs,'MakeDocs'));

gulp.task('BuildDist', gulp.series(gulp.parallel(cleanDist,cleanDocs), gulp.parallel(mintoDist, 'MakeDocs')));
<|endoftext|>


<commit_before>var fs      = require('fs');
var path    = require('path');
var mime    = require('mime');
var gulp    = require('gulp');
var clean   = require('gulp-clean');
var concat  = require('gulp-concat');
var footer  = require('gulp-footer');
var header  = require('gulp-header');
var jade    = require('gulp-jade');
var run     = require('gulp-run');
var zip     = require('gulp-zip');
var merge   = require('merge-stream');
var map     = require('vinyl-map');
var source  = require('vinyl-source-stream');
var plist   = require('plist');

var package = require('./package.json');

gulp.task('default', [ 'chrome:zip', 'firefox:xpi', 'safari' ], function() {
});

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

var rImages = /(url\(['|"]?)([^:'"]*)(?=['|"]?\))/ig;

var encode64 = map(function(code, filename) {
    code = code.toString();
    var dir = path.dirname(filename);
    return code.replace(rImages, function(match, p1, url) {
        var imgPath = path.join(dir, url);
        if (fs.existsSync(imgPath)) {
            var img = fs.readFileSync(imgPath);
            url = 'data:' + mime.lookup(imgPath) + ';base64,' + img.toString('base64');
            match = p1 + url;
        } else {
            console.error('Could not find image: ' + imgPath);
        }
        return match;
    });
});

gulp.task('chrome:css', function() {
    var extPath = map(function(code) {
        code = code.toString();
        return code.replace(rImages, '$1chrome-extension://__MSG_@@extension_id__/$2');
    });
    return gulp.src('./betterdgg/*.css')
        .pipe(extPath)
        .pipe(concat('betterdgg.css'))
        .pipe(gulp.dest('./build/chrome/'));
});

gulp.task('firefox:css', function() {
    return gulp.src('./betterdgg/*.css')
        .pipe(encode64)
        .pipe(concat('betterdgg.css'))
        .pipe(gulp.dest('./build/firefox/data/'));
});

gulp.task('safari:css', function() {
    return gulp.src('./betterdgg/*.css')
        .pipe(encode64)
        .pipe(concat('betterdgg.css'))
        .pipe(gulp.dest('./dist/betterdgg.safariextension/'));
});

gulp.task('js', [ 'templates', 'version' ], function() {
    return gulp.src([ './vendor/**/*.js',
            './betterdgg/modules/*.js', './build/templates.js', './build/version.js',
            './betterdgg/*.js' ])
        .pipe(concat('betterdgg.js'))
        .pipe(header('var injectedBetterDGG = function() {\n'))
        .pipe(footer('\n};'))
        .pipe(gulp.dest('./build/'));
});

gulp.task('templates', function() {
    var nameTemplate = map(function(code, filename) {
        code = code.toString();
        var declaration = 'window.BetterDGG.templates.' + path.basename(filename, '.js') + ' = function(';
        return code.replace(/^function template\(/, declaration);
    });

    return gulp.src([ './betterdgg/templates/**/*.jade' ])
        .pipe(jade({ client: true }))
        .pipe(nameTemplate)
        .pipe(concat('templates.js'))
        .pipe(gulp.dest('./build/'));
});

gulp.task('version', function() {
    var stream = source('version.js');
    stream.write(';(function(bdgg) {');
    stream.write('bdgg.version = "' + package.version + '";');
    stream.write('}(window.BetterDGG = window.BetterDGG || {}));');

    return gulp.src('version.js')
        .pipe(stream)
        .pipe(gulp.dest('./build/'));
});

gulp.task('chrome:manifest', function() {
    return gulp.src('./chrome/manifest.json')
        .pipe(map(function(code) {
            var obj = JSON.parse(code.toString());
            obj.version = package.version;
            return JSON.stringify(obj);
        }))
        .pipe(gulp.dest('./build/chrome/'));
});

gulp.task('chrome', [ 'chrome:css', 'chrome:manifest', 'js' ], function() {
    var assets = gulp.src([ './betterdgg/**/*.png',
            './chrome/**/*', '!./chrome/inject.js', '!./chrome/manifest.json' ])
        .pipe(gulp.dest('./build/chrome/'));
    var js = gulp.src([ './build/betterdgg.js', './chrome/inject.js' ])
        .pipe(concat('betterdgg.js'))
        .pipe(gulp.dest('./build/chrome/'));
    return merge(assets, js);
});

gulp.task('chrome:zip', [ 'chrome' ], function() {
    gulp.src('./build/chrome/**/*')
        .pipe(zip('betterdgg-chrome.zip'))
        .pipe(gulp.dest('./dist/'));
});

gulp.task('firefox:manifest', function() {
    return gulp.src('./firefox/package.json')
        .pipe(map(function(code) {
            var obj = JSON.parse(code.toString());
            obj.version = package.version;
            return JSON.stringify(obj);
        }))
        .pipe(gulp.dest('./build/firefox/'));
});

gulp.task('firefox', [ 'firefox:css', 'firefox:manifest', 'js' ], function() {
    var assets = gulp.src([ './firefox/**/*', '!./firefox/data/inject.js',
            '!./firefox/package.json' ])
        .pipe(gulp.dest('./build/firefox/'));
    var js = gulp.src([ './build/betterdgg.js', './firefox/data/inject.js' ])
        .pipe(concat('betterdgg.js'))
        .pipe(gulp.dest('./build/firefox/data/'));
    return merge(assets, js);
});

gulp.task('firefox:xpi', [ 'firefox' ], function() {
    run('mkdir -p ./dist && cd ./build/firefox && cfx xpi --output-file=../../dist/betterdgg.xpi').exec();
});

gulp.task('safari:plist', function() {
    return gulp.src('./safari/Info.plist')
        .pipe(map(function(code) {
            var obj = plist.parse(code.toString());
            obj.CFBundleVersion = package.version;
            obj.CFBundleShortVersionString = package.version.replace(/^(\d+\.\d+)\..*/, '$1');
            return plist.build(obj);
        }))
        .pipe(gulp.dest('./dist/betterdgg.safariextension/'));
});

gulp.task('safari', [ 'safari:css', 'safari:plist', 'js' ], function() {
    var assets = gulp.src([ './betterdgg/**/*.png',
            './safari/**/*', '!./safari/inject.js', '!./safari/Info.plist' ])
        .pipe(gulp.dest('./dist/betterdgg.safariextension/'));
    var js = gulp.src([ './build/betterdgg.js', './safari/inject.js' ])
        .pipe(concat('betterdgg.js'))
        .pipe(gulp.dest('./dist/betterdgg.safariextension/'));
    merge(assets, js).on('end', function() {
        console.log('Open ./dist/betterdgg.safariextension in Safari Extension Builder'
            + ' to dist Safari extension');
    });
});
<commit_msg>add updateUrl for non-AMO releases. resolves #46<commit_after>var fs      = require('fs');
var path    = require('path');
var mime    = require('mime');
var gulp    = require('gulp');
var clean   = require('gulp-clean');
var concat  = require('gulp-concat');
var footer  = require('gulp-footer');
var header  = require('gulp-header');
var jade    = require('gulp-jade');
var run     = require('gulp-run');
var zip     = require('gulp-zip');
var merge   = require('merge-stream');
var map     = require('vinyl-map');
var source  = require('vinyl-source-stream');
var plist   = require('plist');

var package = require('./package.json');

gulp.task('default', [ 'chrome:zip', 'firefox:xpi', 'safari' ], function() {
});

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

var rImages = /(url\(['|"]?)([^:'"]*)(?=['|"]?\))/ig;

var encode64 = map(function(code, filename) {
    code = code.toString();
    var dir = path.dirname(filename);
    return code.replace(rImages, function(match, p1, url) {
        var imgPath = path.join(dir, url);
        if (fs.existsSync(imgPath)) {
            var img = fs.readFileSync(imgPath);
            url = 'data:' + mime.lookup(imgPath) + ';base64,' + img.toString('base64');
            match = p1 + url;
        } else {
            console.error('Could not find image: ' + imgPath);
        }
        return match;
    });
});

gulp.task('chrome:css', function() {
    var extPath = map(function(code) {
        code = code.toString();
        return code.replace(rImages, '$1chrome-extension://__MSG_@@extension_id__/$2');
    });
    return gulp.src('./betterdgg/*.css')
        .pipe(extPath)
        .pipe(concat('betterdgg.css'))
        .pipe(gulp.dest('./build/chrome/'));
});

gulp.task('firefox:css', function() {
    return gulp.src('./betterdgg/*.css')
        .pipe(encode64)
        .pipe(concat('betterdgg.css'))
        .pipe(gulp.dest('./build/firefox/data/'));
});

gulp.task('safari:css', function() {
    return gulp.src('./betterdgg/*.css')
        .pipe(encode64)
        .pipe(concat('betterdgg.css'))
        .pipe(gulp.dest('./dist/betterdgg.safariextension/'));
});

gulp.task('js', [ 'templates', 'version' ], function() {
    return gulp.src([ './vendor/**/*.js',
            './betterdgg/modules/*.js', './build/templates.js', './build/version.js',
            './betterdgg/*.js' ])
        .pipe(concat('betterdgg.js'))
        .pipe(header('var injectedBetterDGG = function() {\n'))
        .pipe(footer('\n};'))
        .pipe(gulp.dest('./build/'));
});

gulp.task('templates', function() {
    var nameTemplate = map(function(code, filename) {
        code = code.toString();
        var declaration = 'window.BetterDGG.templates.' + path.basename(filename, '.js') + ' = function(';
        return code.replace(/^function template\(/, declaration);
    });

    return gulp.src([ './betterdgg/templates/**/*.jade' ])
        .pipe(jade({ client: true }))
        .pipe(nameTemplate)
        .pipe(concat('templates.js'))
        .pipe(gulp.dest('./build/'));
});

gulp.task('version', function() {
    var stream = source('version.js');
    stream.write(';(function(bdgg) {');
    stream.write('bdgg.version = "' + package.version + '";');
    stream.write('}(window.BetterDGG = window.BetterDGG || {}));');

    return gulp.src('version.js')
        .pipe(stream)
        .pipe(gulp.dest('./build/'));
});

gulp.task('chrome:manifest', function() {
    return gulp.src('./chrome/manifest.json')
        .pipe(map(function(code) {
            var obj = JSON.parse(code.toString());
            obj.version = package.version;
            return JSON.stringify(obj);
        }))
        .pipe(gulp.dest('./build/chrome/'));
});

gulp.task('chrome', [ 'chrome:css', 'chrome:manifest', 'js' ], function() {
    var assets = gulp.src([ './betterdgg/**/*.png',
            './chrome/**/*', '!./chrome/inject.js', '!./chrome/manifest.json' ])
        .pipe(gulp.dest('./build/chrome/'));
    var js = gulp.src([ './build/betterdgg.js', './chrome/inject.js' ])
        .pipe(concat('betterdgg.js'))
        .pipe(gulp.dest('./build/chrome/'));
    return merge(assets, js);
});

gulp.task('chrome:zip', [ 'chrome' ], function() {
    gulp.src('./build/chrome/**/*')
        .pipe(zip('betterdgg-chrome.zip'))
        .pipe(gulp.dest('./dist/'));
});

gulp.task('firefox:manifest', function() {
    return gulp.src('./firefox/package.json')
        .pipe(map(function(code) {
            var obj = JSON.parse(code.toString());
            obj.version = package.version;
            return JSON.stringify(obj);
        }))
        .pipe(gulp.dest('./build/firefox/'));
});

gulp.task('firefox', [ 'firefox:css', 'firefox:manifest', 'js' ], function() {
    var assets = gulp.src([ './firefox/**/*', '!./firefox/data/inject.js',
            '!./firefox/package.json' ])
        .pipe(gulp.dest('./build/firefox/'));
    var js = gulp.src([ './build/betterdgg.js', './firefox/data/inject.js' ])
        .pipe(concat('betterdgg.js'))
        .pipe(gulp.dest('./build/firefox/data/'));
    return merge(assets, js);
});

gulp.task('firefox:xpi', [ 'firefox' ], function() {
    run('mkdir -p ./dist && cd ./build/firefox && cfx xpi'
	+ ' --update-url https://9inevolt.github.io/betterdgg/firefox/update.rdf'
        + ' --output-file=../../dist/betterdgg.xpi').exec();
});

gulp.task('safari:plist', function() {
    return gulp.src('./safari/Info.plist')
        .pipe(map(function(code) {
            var obj = plist.parse(code.toString());
            obj.CFBundleVersion = package.version;
            obj.CFBundleShortVersionString = package.version.replace(/^(\d+\.\d+)\..*/, '$1');
            return plist.build(obj);
        }))
        .pipe(gulp.dest('./dist/betterdgg.safariextension/'));
});

gulp.task('safari', [ 'safari:css', 'safari:plist', 'js' ], function() {
    var assets = gulp.src([ './betterdgg/**/*.png',
            './safari/**/*', '!./safari/inject.js', '!./safari/Info.plist' ])
        .pipe(gulp.dest('./dist/betterdgg.safariextension/'));
    var js = gulp.src([ './build/betterdgg.js', './safari/inject.js' ])
        .pipe(concat('betterdgg.js'))
        .pipe(gulp.dest('./dist/betterdgg.safariextension/'));
    merge(assets, js).on('end', function() {
        console.log('Open ./dist/betterdgg.safariextension in Safari Extension Builder'
            + ' to dist Safari extension');
    });
});
<|endoftext|>


<commit_before>// generated on 2014-09-19 using generator-gulp-webapp 0.1.0
'use strict';

var autoprefixer = require('gulp-autoprefixer');
var clean        = require('gulp-clean');
var flatten      = require('gulp-flatten');
var gulp         = require('gulp');
var gutil        = require('gulp-util');
var jshint       = require('gulp-jshint');
var opn          = require('opn');
var plumber      = require('gulp-plumber');
var sass         = require('gulp-ruby-sass');
var server       = require("webpack-dev-server");
var size         = require('gulp-size');
var streamify    = require('gulp-streamify');
var subtree      = require('gulp-subtree');
var symlink      = require('gulp-symlink');
var uglify       = require('gulp-uglify');
var webpack      = require('webpack');

jshint.stylish = require('jshint-stylish');

/////////

gulp.task('styles', function () {
	return gulp.src('app/styles/app.scss')
	    .pipe(plumber())
	    .pipe(sass({
			style: 'expanded',
			precision: 10
	    }))
		.pipe(autoprefixer('last 1 version'))
		.pipe(gulp.dest('dist'))
		.pipe(size());
});

gulp.task('html', function () {
	// Copy index.html to dist
	return gulp.src('app/index.html').pipe(gulp.dest('dist'));
});

gulp.task('fonts', function () {
	// Copy fonts to dist
	return gulp.src(['app/fonts/**/*.woff', 'bower_components/**/*.woff'])
		.pipe(flatten())
		.pipe(gulp.dest('dist/fonts'))
		.pipe(size());
});

gulp.task('link', function() {
	gulp.src('public/data').pipe(symlink('dist'))
	gulp.src('bower_components').pipe(symlink('dist'))
})

//////////

var webpackConfig = require("./webpack.config.js");

// The development server (the recommended option for development)
gulp.task("default", ["webpack-dev-server"]);
gulp.task("serve", ["webpack-dev-server"]);

// Build and watch cycle (another option for development)
//// Advantage: No server required, can run app from filesystem
//// Disadvantage: Requests are not blocked until bundle is available,
////   can serve an old app on refresh
gulp.task("build-dev", ["webpack:build-dev"], function() {
	gulp.watch(["app/**/*"], ["webpack:build-dev"]);
});

// Production build
gulp.task("build", ["webpack:build"]);

gulp.task("prepare-build", ['html', 'styles', 'fonts', 'link'])

gulp.task("webpack:build", ['prepare-build'], function(callback) {
	// modify some webpack config options
	var myConfig = Object.create(webpackConfig);
	myConfig.plugins = myConfig.plugins.concat(
		new webpack.DefinePlugin({
			"process.env": {
				// This has effect on the react lib size
				"NODE_ENV": JSON.stringify("production")
			}
		}),
		new webpack.optimize.DedupePlugin(),
		new webpack.optimize.UglifyJsPlugin()
	);

	// run webpack
	webpack(myConfig, function(err, stats) {
		if(err) throw new gutil.PluginError("webpack:build", err);
		gutil.log("[webpack:build]", stats.toString({
			colors: true
		}));
		callback();
	});
});

// modify some webpack config options
var myDevConfig = Object.create(webpackConfig);
myDevConfig.devtool = "source-map";
myDevConfig.debug = true;

// create a single instance of the compiler to allow caching
var devCompiler = webpack(myDevConfig);

gulp.task("webpack:build-dev", ['prepare-build'], function(callback) {
	// run webpack
	devCompiler.run(function(err, stats) {
		if(err) throw new gutil.PluginError("webpack:build-dev", err);
		gutil.log("[webpack:build-dev]", stats.toString({
			colors: true
		}));
		callback();
	});
});

gulp.task("webpack-dev-server", ['prepare-build'], function(callback) {
	gulp.watch('app/styles/**/*.scss', ['styles']);

	// modify some webpack config options
	var myConfig = Object.create(webpackConfig);
	myConfig.devtool = "source-map";
	myConfig.debug = true;

	// Start a webpack-dev-server
	new server(webpack(myConfig), {
		contentBase: myConfig.output.contentBase,
		path: myConfig.output.path,
		publicPath: "/" + myConfig.output.publicPath,
		stats: {
			colors: true
		}
	}).listen(8080, "localhost", function(err) {
		if(err) throw new gutil.PluginError("webpack-dev-server", err);
		var url = "http://localhost:8080/webpack-dev-server/index.html";
		gutil.log("[webpack-dev-server]", url);
		opn(url);
	});
});

//////////

gulp.task('deploy', ['build'], function () {
	return gulp.src('dist')
		.pipe(subtree())
		.pipe(clean());
});

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

// gulp.task('default', function () {
// 	console.log('gulp build');
// 	console.log('gulp watch');
// 	console.log('gulp deploy');
// });
<commit_msg>Stop copying fonts around<commit_after>// generated on 2014-09-19 using generator-gulp-webapp 0.1.0
'use strict';

var autoprefixer = require('gulp-autoprefixer');
var clean        = require('gulp-clean');
var flatten      = require('gulp-flatten');
var gulp         = require('gulp');
var gutil        = require('gulp-util');
var jshint       = require('gulp-jshint');
var opn          = require('opn');
var plumber      = require('gulp-plumber');
var sass         = require('gulp-ruby-sass');
var server       = require("webpack-dev-server");
var size         = require('gulp-size');
var streamify    = require('gulp-streamify');
var subtree      = require('gulp-subtree');
var symlink      = require('gulp-symlink');
var uglify       = require('gulp-uglify');
var webpack      = require('webpack');

jshint.stylish = require('jshint-stylish');

/////////

gulp.task('styles', function () {
	return gulp.src('app/styles/app.scss')
	    .pipe(plumber())
	    .pipe(sass({
			style: 'expanded',
			precision: 10
	    }))
		.pipe(autoprefixer('last 1 version'))
		.pipe(gulp.dest('dist'))
		.pipe(size());
});

gulp.task('html', function () {
	// Copy index.html to dist
	return gulp.src('app/index.html').pipe(gulp.dest('dist'));
});

gulp.task('link', function() {
	gulp.src('public/data').pipe(symlink('dist'))
	gulp.src('bower_components').pipe(symlink('dist'))
})

//////////

var webpackConfig = require("./webpack.config.js");

// The development server (the recommended option for development)
gulp.task("default", ["webpack-dev-server"]);
gulp.task("serve", ["webpack-dev-server"]);

// Build and watch cycle (another option for development)
//// Advantage: No server required, can run app from filesystem
//// Disadvantage: Requests are not blocked until bundle is available,
////   can serve an old app on refresh
gulp.task("build-dev", ["webpack:build-dev"], function() {
	gulp.watch(["app/**/*"], ["webpack:build-dev"]);
});

// Production build
gulp.task("build", ["webpack:build"]);

gulp.task("prepare-build", ['html', 'styles', 'fonts', 'link'])

gulp.task("webpack:build", ['prepare-build'], function(callback) {
	// modify some webpack config options
	var myConfig = Object.create(webpackConfig);
	myConfig.plugins = myConfig.plugins.concat(
		new webpack.DefinePlugin({
			"process.env": {
				// This has effect on the react lib size
				"NODE_ENV": JSON.stringify("production")
			}
		}),
		new webpack.optimize.DedupePlugin(),
		new webpack.optimize.UglifyJsPlugin()
	);

	// run webpack
	webpack(myConfig, function(err, stats) {
		if(err) throw new gutil.PluginError("webpack:build", err);
		gutil.log("[webpack:build]", stats.toString({
			colors: true
		}));
		callback();
	});
});

// modify some webpack config options
var myDevConfig = Object.create(webpackConfig);
myDevConfig.devtool = "source-map";
myDevConfig.debug = true;

// create a single instance of the compiler to allow caching
var devCompiler = webpack(myDevConfig);

gulp.task("webpack:build-dev", ['prepare-build'], function(callback) {
	// run webpack
	devCompiler.run(function(err, stats) {
		if(err) throw new gutil.PluginError("webpack:build-dev", err);
		gutil.log("[webpack:build-dev]", stats.toString({
			colors: true
		}));
		callback();
	});
});

gulp.task("webpack-dev-server", ['prepare-build'], function(callback) {
	gulp.watch('app/styles/**/*.scss', ['styles']);

	// modify some webpack config options
	var myConfig = Object.create(webpackConfig);
	myConfig.devtool = "source-map";
	myConfig.debug = true;

	// Start a webpack-dev-server
	new server(webpack(myConfig), {
		contentBase: myConfig.output.contentBase,
		path: myConfig.output.path,
		publicPath: "/" + myConfig.output.publicPath,
		stats: {
			colors: true
		}
	}).listen(8080, "localhost", function(err) {
		if(err) throw new gutil.PluginError("webpack-dev-server", err);
		var url = "http://localhost:8080/webpack-dev-server/index.html";
		gutil.log("[webpack-dev-server]", url);
		opn(url);
	});
});

//////////

gulp.task('deploy', ['build'], function () {
	return gulp.src('dist')
		.pipe(subtree())
		.pipe(clean());
});

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

// gulp.task('default', function () {
// 	console.log('gulp build');
// 	console.log('gulp watch');
// 	console.log('gulp deploy');
// });
<|endoftext|>