<commit_before>"use strict";

var runSequence = require('run-sequence');
var gulp = require('gulp');
var gutil = require('gulp-util');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var notify = require('gulp-notify');
var connect = require('gulp-connect');

var browserify = require('gulp-browserify');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');

var restartCount = 0;

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

gulp.task('connect', function() {
  connect.server({
    port: 8088,
    livereload: true
  });
});

gulp.task('jshint', function() {
  return gulp.src([
      '*.js',
      '{lib,test}/**/*.{js,html}'
    ])
    .pipe(jshint.extract('auto'))
    .pipe(jshint())
    .pipe(notify(function(file) {
      if(file.jshint.success) {
        return false;
      }

      var errors = file.jshint.results.map(function(data) {
        if(data.error) {
          return '(' + data.error.line + ':' + data.error.character + ') ' + data.error.reason;
        }
      }).join('\n');
      return file.relative + " (" + file.jshint.results.length + ' errors)\n' + errors;
    }))
    .pipe(jshint.reporter('default', { verbose: true }));
});

gulp.task('mocha', function() {
  return gulp.src('test/*.js', { read: false })
    .pipe(mocha({
        timeout: 5000,
        reporter: 'spec',
        growl: 'true'
    }))
    .on('error', gutil.log);
});

var karma = require('karma').server;
gulp.task('karmaWatch', function(done) {

  karma.start({
    configFile: __dirname + '/karma.conf.js',
    singleRun: true
  }, function() {
    done();
  });
  return ;

});

gulp.task('karma', function(done) {

  karma.start({
    configFile: __dirname + '/karma.conf.js',
    singleRun: true,
  }, function() {
    done();
  });
  return ;

});

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

  gulp.src('lib/index.js', { read: false })
  .pipe(browserify({
    insertGlobals: false,
    standalone: 'AnthParticle',
    debug: false
  }))
  .pipe(rename('anthParticle-' + VERSION + '.js'))
  .pipe(gulp.dest('./build/release'));

  gulp.src('lib/index.js', { read: false })
  .pipe(browserify({
    insertGlobals: false,
    standalone: 'AnthParticle',
    debug: false
  }))
  .pipe(rename('anthParticle-' + VERSION + '.min.js'))
  .pipe(uglify())
  .pipe(gulp.dest('./build/release'));

  gulp.src('lib/loader/xml.js', { read: false})
  .pipe(browserify({
    insertGlobals: false,
    standalone: 'AnthParticleXmlLoader',
    debug: false
  })).pipe(rename('anthParticle.xmlLoader-' + VERSION + '.min.js'))
  .pipe(uglify())
  .pipe(gulp.dest('./build/release/loaders'));

  gulp.src('lib/loader/json.js', { read: false})
  .pipe(browserify({
    insertGlobals: false,
    standalone: 'AnthParticleJsonLoader',
    debug: false
  })).pipe(rename('anthParticle.jsonLoader-' + VERSION + '.min.js'))
  .pipe(uglify())
  .pipe(gulp.dest('./build/release/loaders'));

});

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

  // index
  gulp.src('lib/index.js', { read: false })
    .pipe(browserify({
      insertGlobals: false,
      standalone: 'AnthParticle',
      debug: false
    }))
    .pipe(rename('anthParticle.js'))
    .pipe(gulp.dest('./build/'))
    .pipe(gulp.dest('./example/lib/'));

  // loaders
  gulp.src('lib/loader/xml.js', { read: false})
    .pipe(browserify({
      insertGlobals: false,
      standalone: 'AnthParticleXmlLoader',
      debug: false
    }))
    .pipe(rename('anthParticle.xmlLoader.js'))
    .pipe(gulp.dest('./build/'))
    .pipe(gulp.dest('./example/lib/'))
    .pipe(connect.reload());

  gulp.src('lib/loader/json.js', { read: false})
    .pipe(browserify({
      insertGlobals: false,
      standalone: 'AnthParticleJsonLoader',
      debug: false
    }))
    .pipe(rename('anthParticle.jsonLoader.js'))
    .pipe(gulp.dest('./build/'))
    .pipe(gulp.dest('./example/lib/'))
    .pipe(connect.reload());

});

gulp.task('restartCount', function() {
  restartCount ++;

  var st = '';
  st += '//////////////////////////////////////////\n';
  st += '/// No.' + restartCount + ' restart.\n';
  st += '//////////////////////////////////////////';

  gutil.log('\n' + st);

});

gulp.task('reloadServer', function() {
  return gulp.src([
    'build/**', 'example/**'
  ]).pipe(connect.reload());
});

gulp.task('watch', function() {
  runSequence('connect');
  gulp.watch([
    'lib/**', 'example/**', '!example/lib/**'
  ], function() {
    runSequence('reloadServer', 'restartCount', 'jshint', 'build', 'karmaWatch');
  });
});

gulp.task('test', function() {
  gulp.watch([
    'lib/**', 'test/test-*.js'
  ], function() {
    runSequence('jshint', 'karmaWatch');
  });
});

gulp.task('default', function() {
  // start, for git pre-commit hook
  return runSequence('jshint', 'karma', 'build');
});

gulp.task('release', function() {
  return runSequence('jshint', 'karma', 'build', 'package');
});
<commit_msg>fix karma start when watching<commit_after>"use strict";

var runSequence = require('run-sequence');
var gulp = require('gulp');
var gutil = require('gulp-util');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var notify = require('gulp-notify');
var connect = require('gulp-connect');

var browserify = require('gulp-browserify');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');

var restartCount = 0;

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

gulp.task('connect', function() {
  connect.server({
    port: 8088,
    livereload: true
  });
});

gulp.task('jshint', function() {
  return gulp.src([
      '*.js',
      '{lib,test}/**/*.{js,html}'
    ])
    .pipe(jshint.extract('auto'))
    .pipe(jshint())
    .pipe(notify(function(file) {
      if(file.jshint.success) {
        return false;
      }

      var errors = file.jshint.results.map(function(data) {
        if(data.error) {
          return '(' + data.error.line + ':' + data.error.character + ') ' + data.error.reason;
        }
      }).join('\n');
      return file.relative + " (" + file.jshint.results.length + ' errors)\n' + errors;
    }))
    .pipe(jshint.reporter('default', { verbose: true }));
});

gulp.task('mocha', function() {
  return gulp.src('test/*.js', { read: false })
    .pipe(mocha({
        timeout: 5000,
        reporter: 'spec',
        growl: 'true'
    }))
    .on('error', gutil.log);
});

var karma = require('karma').server;
gulp.task('karmaWatch', function(done) {

  karma.start({
    configFile: __dirname + '/karma.conf.js',
    singleRun: false
  }, function() {
    done();
  });
  return ;

});

gulp.task('karma', function(done) {

  karma.start({
    configFile: __dirname + '/karma.conf.js',
    singleRun: true,
  }, function() {
    done();
  });
  return ;

});

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

  gulp.src('lib/index.js', { read: false })
  .pipe(browserify({
    insertGlobals: false,
    standalone: 'AnthParticle',
    debug: false
  }))
  .pipe(rename('anthParticle-' + VERSION + '.js'))
  .pipe(gulp.dest('./build/release'));

  gulp.src('lib/index.js', { read: false })
  .pipe(browserify({
    insertGlobals: false,
    standalone: 'AnthParticle',
    debug: false
  }))
  .pipe(rename('anthParticle-' + VERSION + '.min.js'))
  .pipe(uglify())
  .pipe(gulp.dest('./build/release'));

  gulp.src('lib/loader/xml.js', { read: false})
  .pipe(browserify({
    insertGlobals: false,
    standalone: 'AnthParticleXmlLoader',
    debug: false
  })).pipe(rename('anthParticle.xmlLoader-' + VERSION + '.min.js'))
  .pipe(uglify())
  .pipe(gulp.dest('./build/release/loaders'));

  gulp.src('lib/loader/json.js', { read: false})
  .pipe(browserify({
    insertGlobals: false,
    standalone: 'AnthParticleJsonLoader',
    debug: false
  })).pipe(rename('anthParticle.jsonLoader-' + VERSION + '.min.js'))
  .pipe(uglify())
  .pipe(gulp.dest('./build/release/loaders'));

});

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

  // index
  gulp.src('lib/index.js', { read: false })
    .pipe(browserify({
      insertGlobals: false,
      standalone: 'AnthParticle',
      debug: false
    }))
    .pipe(rename('anthParticle.js'))
    .pipe(gulp.dest('./build/'))
    .pipe(gulp.dest('./example/lib/'));

  // loaders
  gulp.src('lib/loader/xml.js', { read: false})
    .pipe(browserify({
      insertGlobals: false,
      standalone: 'AnthParticleXmlLoader',
      debug: false
    }))
    .pipe(rename('anthParticle.xmlLoader.js'))
    .pipe(gulp.dest('./build/'))
    .pipe(gulp.dest('./example/lib/'))
    .pipe(connect.reload());

  gulp.src('lib/loader/json.js', { read: false})
    .pipe(browserify({
      insertGlobals: false,
      standalone: 'AnthParticleJsonLoader',
      debug: false
    }))
    .pipe(rename('anthParticle.jsonLoader.js'))
    .pipe(gulp.dest('./build/'))
    .pipe(gulp.dest('./example/lib/'))
    .pipe(connect.reload());

});

gulp.task('restartCount', function() {
  restartCount ++;

  var st = '';
  st += '//////////////////////////////////////////\n';
  st += '/// No.' + restartCount + ' restart.\n';
  st += '//////////////////////////////////////////';

  gutil.log('\n' + st);

});

gulp.task('reloadServer', function() {
  return gulp.src([
    'build/**', 'example/**'
  ]).pipe(connect.reload());
});

gulp.task('watch', function() {
  runSequence('connect');
  gulp.watch([
    'lib/**', 'example/**', '!example/lib/**'
  ], function() {
    runSequence('reloadServer', 'restartCount', 'jshint', 'build', 'karmaWatch');
  });
});

gulp.task('test', function() {
  gulp.watch([
    'lib/**', 'test/test-*.js'
  ], function() {
    runSequence('jshint', 'karmaWatch');
  });
});

gulp.task('default', function() {
  // start, for git pre-commit hook
  return runSequence('jshint', 'karma', 'build');
});

gulp.task('release', function() {
  return runSequence('jshint', 'karma', 'build', 'package');
});
<|endoftext|>


<commit_before>'use strict';

var gulp = require('gulp'),
    concat = require('gulp-concat'),
    uglifycss = require('gulp-uglifycss'),
    rename = require('gulp-rename'),
    del = require('del'),
    flatten = require('gulp-flatten');

gulp.task('build-css', function() {
	gulp.src([
        'components/common/common.css',
		'components/**/*.css'
    ])
	.pipe(concat('primeng.css'))
	.pipe(gulp.dest('resources'));
});

gulp.task('build-css-prod', function() {
    gulp.src([
        'components/common/common.css',
		'components/**/*.css'
    ])
	.pipe(concat('primeng.css'))
	.pipe(gulp.dest('resources'))
    .pipe(uglifycss({"uglyComments": true}))
    .pipe(rename('primeng.min.css'))
    .pipe(gulp.dest('resources'));
});

//Building images
gulp.task('images', function() {
    return gulp.src(['components/**/images/*.png', 'components/**/images/*.gif'])
        .pipe(flatten())
        .pipe(gulp.dest('resources/images'));
});

//Cleaning previous gulp tasks from project
gulp.task('clean', function() {
	del(['resources/primeng.css','resources/primeng.min.css']);
});

//Building project with run sequence
gulp.task('build', ['clean','build-css-prod', 'images']);

        <commit_msg>Remove images as well<commit_after>'use strict';

var gulp = require('gulp'),
    concat = require('gulp-concat'),
    uglifycss = require('gulp-uglifycss'),
    rename = require('gulp-rename'),
    del = require('del'),
    flatten = require('gulp-flatten');

gulp.task('build-css', function() {
	gulp.src([
        'components/common/common.css',
		'components/**/*.css'
    ])
	.pipe(concat('primeng.css'))
	.pipe(gulp.dest('resources'));
});

gulp.task('build-css-prod', function() {
    gulp.src([
        'components/common/common.css',
		'components/**/*.css'
    ])
	.pipe(concat('primeng.css'))
	.pipe(gulp.dest('resources'))
    .pipe(uglifycss({"uglyComments": true}))
    .pipe(rename('primeng.min.css'))
    .pipe(gulp.dest('resources'));
});

//Building images
gulp.task('images', function() {
    return gulp.src(['components/**/images/*.png', 'components/**/images/*.gif'])
        .pipe(flatten())
        .pipe(gulp.dest('resources/images'));
});

//Cleaning previous gulp tasks from project
gulp.task('clean', function() {
	del(['resources/primeng.css','resources/primeng.min.css','resources/images']);
});

//Building project with run sequence
gulp.task('build', ['clean','build-css-prod', 'images']);

        <|endoftext|>


<commit_before>var gulp     = require('gulp');
var WorkflowForm = require('./gulp/form/WorkflowForm');
require('./gulp/build');
require('./gulp/serve');
require('./gulp/test');
require('./gulp/docs');

// default task => instanciate GulpForm
gulp.task('default', function (cb) {
	var g = new WorkflowForm(cb);
});<commit_msg>basic refactoring<commit_after>var gulp         = require('gulp');
var WorkflowForm = require('./gulp/form/WorkflowForm');
require('./gulp/build');
require('./gulp/serve');
require('./gulp/test');
require('./gulp/docs');

// default task => instanciate GulpForm
gulp.task('default', function (cb) {
	var g = new WorkflowForm(cb);
});<|endoftext|>


<commit_before>var gulp = require('gulp');
var sass = require('gulp-sass');
var pleeease = require('gulp-pleeease');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var browserSync = require('browser-sync');
var reload      = browserSync.reload;
var ejs = require("gulp-ejs");
var plumber = require("gulp-plumber");

// Sass

gulp.task('sass', function () {
    gulp.src('sass/**/*.scss')
        .pipe(sass().on('error', sass.logError)) // Keep running gulp even though occurred compile error
        .pipe(pleeease({
            autoprefixer: {
                browsers: ['last 2 versions']
            }
        }))
        .pipe(gulp.dest('build/css'))
        .pipe(reload({stream:true}));
});

// Js-concat-uglify

gulp.task('js', function() {
    gulp.src(['js/*.js'])
        .pipe(concat('scripts.js'))
        .pipe(uglify({preserveComments: 'some'})) // Keep some comments
        .pipe(gulp.dest('build/js'))
        .pipe(reload({stream:true}));
});

// Imagemin

gulp.task('imagemin', function() {
    gulp.src(['images/**/*.{png,jpg,gif,svg}'])
        .pipe(imagemin({optimizationLevel: 7}))
        .pipe(gulp.dest('build/images'));
});

// ejs

var fs = require('fs');
var json = JSON.parse(fs.readFileSync("site.json")); // parse json
gulp.task("ejs", function() {
    gulp.src(['templates/*.ejs','!' + 'templates/_*.ejs']) // Don't build html which starts from underline
        .pipe(plumber())
        .pipe(ejs(json))
        .pipe(gulp.dest('./'))
});

// Static server

gulp.task('browser-sync', function() {
    browserSync({
        server: {
            baseDir: "./", //　Target directory
            index  : "index.html" // index file
        }
    });
});

// Reload all browsers

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

// Task for `gulp` command

gulp.task('default',['browser-sync'], function() {
    gulp.watch('sass/**/*.scss',['sass']);
    gulp.watch('js/*.js',['js']);
    gulp.watch('images/**/*.{png,jpg,gif,svg}',['imagemin']);
    gulp.watch("./*.html", ['bs-reload']);
    gulp.watch(['templates/*.ejs', 'site.json'], ['ejs']);
});<commit_msg>set extension for ejs<commit_after>var gulp = require('gulp');
var sass = require('gulp-sass');
var pleeease = require('gulp-pleeease');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var browserSync = require('browser-sync');
var reload      = browserSync.reload;
var ejs = require("gulp-ejs");
var plumber = require("gulp-plumber");

// Sass

gulp.task('sass', function () {
    gulp.src('sass/**/*.scss')
        .pipe(sass().on('error', sass.logError)) // Keep running gulp even though occurred compile error
        .pipe(pleeease({
            autoprefixer: {
                browsers: ['last 2 versions']
            }
        }))
        .pipe(gulp.dest('build/css'))
        .pipe(reload({stream:true}));
});

// Js-concat-uglify

gulp.task('js', function() {
    gulp.src(['js/*.js'])
        .pipe(concat('scripts.js'))
        .pipe(uglify({preserveComments: 'some'})) // Keep some comments
        .pipe(gulp.dest('build/js'))
        .pipe(reload({stream:true}));
});

// Imagemin

gulp.task('imagemin', function() {
    gulp.src(['images/**/*.{png,jpg,gif,svg}'])
        .pipe(imagemin({optimizationLevel: 7}))
        .pipe(gulp.dest('build/images'));
});

// ejs

var fs = require('fs');
var json = JSON.parse(fs.readFileSync("site.json")); // parse json
gulp.task("ejs", function() {
    gulp.src(['templates/*.ejs','!' + 'templates/_*.ejs']) // Don't build html which starts from underline
        .pipe(plumber())
        .pipe(ejs(json, {"ext": ".html"}))
        .pipe(gulp.dest('./'))
});

// Static server

gulp.task('browser-sync', function() {
    browserSync({
        server: {
            baseDir: "./", //　Target directory
            index  : "index.html" // index file
        }
    });
});

// Reload all browsers

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

// Task for `gulp` command

gulp.task('default',['browser-sync'], function() {
    gulp.watch('sass/**/*.scss',['sass']);
    gulp.watch('js/*.js',['js']);
    gulp.watch('images/**/*.{png,jpg,gif,svg}',['imagemin']);
    gulp.watch("./*.html", ['bs-reload']);
    gulp.watch(['templates/*.ejs', 'site.json'], ['ejs']);
});<|endoftext|>


<commit_before>const browserify = require('browserify');
const babelify = require('babelify');
const gulp = require('gulp');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const gutil = require('gulp-util');
const gulpif = require('gulp-if');
const sourcemaps = require('gulp-sourcemaps');
const rename = require('gulp-rename');
const postcss = require('gulp-postcss');
const uglify = require('gulp-uglify');

var isProduction = false;
var isLocalDev = false;

gulp.task('is-production', () => {
  isProduction = true;
});

gulp.task('is-local-dev', () => {
  isLocalDev = true;
});

gulp.task('build-js', () => {
  return browserify({
    entries: ['./js/app.js'],
    debug: isProduction,
  }).transform(babelify, { presets: ['es2015', 'react'] })
    .transform('brfs')
    .bundle()
    .pipe(source('bundle.js')) // gives streaming vinyl file object
    .pipe(buffer()) // <----- convert from streaming to buffered vinyl file object
    .pipe(sourcemaps.init({ loadMaps: true })) // loads map from browserify file
    .pipe(uglify()) // now gulp-uglify works
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('./dist'))
    .pipe(gulpif(isLocalDev, gulp.dest('./../api/app/static/dist')));
});

gulp.task('postcss', () => {
  // Runs postCSS with all its plugins.
  const nano = require('gulp-cssnano');
  const plugins = [
    require('autoprefixer'),
  ];
  // Run PostCSS
  return gulp.src('./stylesheets/styles.css')
      .pipe(postcss(plugins))
      .on('error', (error) => {
        gutil.log(gutil.colors.magenta.bold('Error while compiling CSS'));
        gutil.log(gutil.colors.magenta(error.message));
      })
      .pipe(gulp.dest('./dist'))
      .pipe(rename({ suffix: '.min' }))
      .pipe(nano({ discardUnused: false }))
      .pipe(gulp.dest('./dist'))
      .pipe(gulpif(isLocalDev, gulp.dest('./../api/app/static/dist')));
});

gulp.task('watch-styles', function watchStyles() {
  // Watches the stylesheet folders for changes and runs the 'postcss' task if a change occurs.
  gulp.watch(['./stylesheets/**/*.css'], ['postcss']);
  return;
});

gulp.task('watch-js', function watchStyles() {
  // Watches the stylesheet folders for changes and runs the 'postcss' task if a change occurs.
  gulp.watch(['./js/**/*.js'], ['build-js']);
  return;
});

gulp.task('default', [
  'is-local-dev',
  'postcss',
  'build-js',
  'watch-styles',
  'watch-js',
]);

gulp.task('build', [
  'postcss',
  'build-js',
]);

gulp.task('build-production', [
  'is-production',
  'postcss',
  'build-js',
]);
<commit_msg>Add line in gulp file to set node to production when proper to do so (causes react to use production version).<commit_after>const browserify = require('browserify');
const babelify = require('babelify');
const gulp = require('gulp');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const gutil = require('gulp-util');
const gulpif = require('gulp-if');
const sourcemaps = require('gulp-sourcemaps');
const rename = require('gulp-rename');
const postcss = require('gulp-postcss');
const uglify = require('gulp-uglify');

var isProduction = false;
var isLocalDev = false;

gulp.task('is-production', () => {
  isProduction = true;
  process.env.NODE_ENV = 'production';
});

gulp.task('is-local-dev', () => {
  isLocalDev = true;
});

gulp.task('build-js', () => {
  return browserify({
    entries: ['./js/app.js'],
    debug: isProduction,
  }).transform(babelify, { presets: ['es2015', 'react'] })
    .transform('brfs')
    .bundle()
    .pipe(source('bundle.js')) // gives streaming vinyl file object
    .pipe(buffer()) // <----- convert from streaming to buffered vinyl file object
    .pipe(sourcemaps.init({ loadMaps: true })) // loads map from browserify file
    .pipe(uglify()) // now gulp-uglify works
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('./dist'))
    .pipe(gulpif(isLocalDev, gulp.dest('./../api/app/static/dist')));
});

gulp.task('postcss', () => {
  // Runs postCSS with all its plugins.
  const nano = require('gulp-cssnano');
  const plugins = [
    require('autoprefixer'),
  ];
  // Run PostCSS
  return gulp.src('./stylesheets/styles.css')
      .pipe(postcss(plugins))
      .on('error', (error) => {
        gutil.log(gutil.colors.magenta.bold('Error while compiling CSS'));
        gutil.log(gutil.colors.magenta(error.message));
      })
      .pipe(gulp.dest('./dist'))
      .pipe(rename({ suffix: '.min' }))
      .pipe(nano({ discardUnused: false }))
      .pipe(gulp.dest('./dist'))
      .pipe(gulpif(isLocalDev, gulp.dest('./../api/app/static/dist')));
});

gulp.task('watch-styles', function watchStyles() {
  // Watches the stylesheet folders for changes and runs the 'postcss' task if a change occurs.
  gulp.watch(['./stylesheets/**/*.css'], ['postcss']);
  return;
});

gulp.task('watch-js', function watchStyles() {
  // Watches the stylesheet folders for changes and runs the 'postcss' task if a change occurs.
  gulp.watch(['./js/**/*.js'], ['build-js']);
  return;
});

gulp.task('default', [
  'is-local-dev',
  'postcss',
  'build-js',
  'watch-styles',
  'watch-js',
]);

gulp.task('build', [
  'postcss',
  'build-js',
]);

gulp.task('build-production', [
  'is-production',
  'postcss',
  'build-js',
]);
<|endoftext|>


<commit_before>'use strict'

/**
* gulpfile.js
*
* Available tasks:
*   `gulp watch`
*   `gulp build`
*   `gulp assets:watch`
*   `gulp assets:clean`
*   `gulp assets:build`
*   `gulp assets:stylesheets`
*   `gulp assets:stylesheets:format`
*   `gulp assets:stylesheets:clean`
*   `gulp assets:javascripts`
*   `gulp assets:javascripts:format`
*   `gulp assets:javascripts:clean`
*   `gulp server:build`
*   `gulp server:spawn`
*   `gulp server:watch`
*
*    Options:
*    --dev                     : Add sourcemaps, refresh livereload
*
* Modules:
*   gulp                       : The streaming build system.
*   args                       : Add arguments support.
*   child_process              : Spawn child process through Node.
*   del                        : Delete files and folders.
*   gulp-autoprefixer          : Prefix CSS.
*   gulp-babel                 : Transpile ES6+ js files.
*   gulp-cleancss              : Minify CSS with clean-css.
*   gulp-concat                : Concatenates files.
*   gulp-csscomb               : Format and sort SCSS/CSS files with CSScomb.
*   gulp-if                    : Conditionally run a task.
*   gulp-livereload            : Reload web browser on demand.
*   gulp-notify                : Notify system.
*   gulp-plumber               : Prevent pipe breaking caused by errors.
*   gulp-rename                : Rename files.
*   gulp-sass                  : Gulp plugin for sass.
*   gulp-sourcemaps            : Source map support for Gulp.js.
*   gulp-standard              : JS linter.
*   gulp-standardFormat        : Format JS files using standard rules.
*   gulp-stylefmt              : Format CSS/SCSS files using stylelint rules.
*   gulp-stylelint             : CSS/SCSS linter.
*   gulp-sync                  : Sync Gulp tasks.
*   gulp-uglify                : Minify files with UglifyJS.
*   gulp-util                  : Utility functions for gulp plugins.
*/

var args = require('yargs').argv
var autoprefix = require('gulp-autoprefixer')
var babel = require('gulp-babel')
var child = require('child_process')
var cleancss = require('gulp-clean-css')
var concat = require('gulp-concat')
var csscomb = require('gulp-csscomb')
var del = require('del')
var gulp = require('gulp')
var gulpif = require('gulp-if')
var gutil = require('gulp-util')
var livereload = require('gulp-livereload')
var notify = require('gulp-notify')
var plumber = require('gulp-plumber')
var rename = require('gulp-rename')
var sass = require('gulp-sass')
var sourcemaps = require('gulp-sourcemaps')
var standard = require('gulp-standard')
var standardFormat = require('gulp-standard-format')
var stylefmt = require('gulp-stylefmt')
var stylelint = require('gulp-stylelint')
var sync = require('gulp-sync')(gulp)
var uglify = require('gulp-uglify')

/* ----------------------------------------------------------------------------
 * locals
 * ------------------------------------------------------------------------- */

var server = null

var root = {
  src: './assets/',
  dest: './public/assets/'
}

var css = {
  src: 'stylesheets/',
  dest: 'stylesheets/',
  main: 'main.scss',
  watch: '**/*',
  include: [
    './node_modules/bulma'
  ]
}

var js = {
  src: 'javascripts/',
  dest: 'javascripts/',
  watch: '**/*'
}

var views = {
  src: 'views/',
  watch: '**/*.tmpl'
}

var go = {
  src: '*/**/*.go'
}

/* ----------------------------------------------------------------------------
 * Functions
 * ------------------------------------------------------------------------- */

/**
 * Functions
 *
 * handleErrors                   : Send a notification to the system on error.
 */

function handleErrors () {
  var args = Array.prototype.slice.call(arguments)

  notify.onError({
    title: '<%= error.plugin %> failed',
    message: '<%= error.message %>'
  }).apply(this, args)
  gutil.beep()
  this.emit('end')
}

/* ----------------------------------------------------------------------------
 * Assets
 * ------------------------------------------------------------------------- */

/**
* CSS Tasks
*
* assets:stylesheets             : Compile/sort/lint/sourcemap/autoprefix/minify SCSS files to one CSS file.
* assets:stylesheets:format    : Sort SCSS files.
* assets:stylesheets:clean       : Remove any CSS files in stylesheet dist folder.
*/

gulp.task('assets:stylesheets', function () {
  return gulp.src(root.src + css.src + css.main)
    .pipe(plumber({ errorHandler: handleErrors }))
    .pipe(gulpif(args.dev, sourcemaps.init()))
    .pipe(csscomb())
    .pipe(stylefmt())
    .pipe(stylelint({ reporters: [{ formatter: 'string', console: true }] }))
    .pipe(sass({ includePaths: css.include }))
    .pipe(autoprefix({ browsers: ['last 2 versions'] }))
    .pipe(cleancss())
    .pipe(rename('stylesheet.min.css'))
    .pipe(gulpif(args.dev, sourcemaps.write()))
    .pipe(gulp.dest(root.dest + css.dest))
    .pipe(gulpif(args.dev, livereload()))
})

gulp.task('assets:stylesheets:format', function () {
  return gulp.src(['!' + root.src + css.src + css.main, root.src + css.src + css.watch])
   .pipe(plumber({ errorHandler: handleErrors }))
   .pipe(csscomb())
   .pipe(stylefmt())
   .pipe(stylelint({ reporters: [{ formatter: 'string', console: true }] }))
   .pipe(gulp.dest(root.src + css.src))
})

gulp.task('assets:stylesheets:clean', function () {
  return del([root.dest + css.dest])
})

/**
* JS Tasks
*
* assets:javascripts             : Compile/format/lint/sourcemap/concat/minify JS files to one JS file.
* assets:javascripts:format      : Format JS files.
* assets:javascripts:clean       : Remove any JS files in javascript dist folder.
*/
gulp.task('assets:javascripts', function () {
  return gulp.src(root.src + js.src + js.watch)
    .pipe(plumber({ errorHandler: handleErrors }))
    .pipe(gulpif(args.dev, sourcemaps.init()))
    .pipe(standardFormat())
    .pipe(standard())
    .pipe(babel({ presets: ['es2015'] }))
    .pipe(concat('javascript.js'))
    .pipe(uglify())
    .pipe(rename('javascript.min.js'))
    .pipe(gulpif(args.dev, sourcemaps.write()))
    .pipe(gulp.dest(root.dest + js.dest))
    .pipe(gulpif(args.dev, livereload()))
})

gulp.task('assets:javascripts:format', function () {
  return gulp.src(root.src + js.src + js.watch)
   .pipe(plumber({ errorHandler: handleErrors }))
   .pipe(standardFormat())
   .pipe(standard())
   .pipe(gulp.dest(root.src + js.src))
})

gulp.task('assets:javascripts:clean', function () {
  return del([root.dest + js.dest])
})

/**
 * Global assets tasks
 *
 * assets:watch                   : Watch SCSS and JS files for changes and compile them.
 * assets:clean                   : Remove any files in CSS/JS dist folders.
 * assets:build                   : Clean/format/compile CSS/JS files.
 */

gulp.task('assets:watch', function () {
  gulp.watch([root.src + css.src + css.watch], ['assets:stylesheets'])
  gulp.watch([root.src + js.src + js.watch], ['assets:javascripts'])
})

gulp.task('assets:clean', [
  'assets:stylesheets:clean',
  'assets:javascripts:clean'
])

gulp.task('assets:build', [
  'assets:clean',
  'assets:stylesheets:format',
  'assets:stylesheets',
  'assets:javascripts:format',
  'assets:javascripts'
])

/* ----------------------------------------------------------------------------
 * Server
 * ------------------------------------------------------------------------- */

/**
* Global assets tasks
*
* server:build                   : Go install.
* server:spawn                   : Restart Go server.
* server:watch                   : Watch Go/tmpl files for changes and restart server.
*/

gulp.task('server:build', function () {
  var build = child.spawnSync('go', ['install'])

  // Log build errors
  if (build.stderr.length) {
    var lines = build.stderr
      .toString()
      .split('\n')
      .filter(function (line) {
        return line.length
      })

    for (var l in lines) {
      gutil.log(
        gutil.colors.red('Error (go install): ' + lines[l])
      )
    }

    notify.notify({
      title: 'Error (go install)',
      message: lines
    })
  }

  return build
})

gulp.task('server:spawn', function () {
  if (server) {
    server.kill()
  }

  server = child.spawn('go', ['run', 'breizhtrip.go', 'server', '-p', '5050'], { stdio: 'inherit' })

  livereload()
})

gulp.task('server:watch', function () {
  gulp.watch([views.src + views.watch], ['server:spawn'])
  gulp.watch(go.src, sync.sync([
    'server:build',
    'server:spawn'
  ]))
})

/* ----------------------------------------------------------------------------
 * Interface
 * ------------------------------------------------------------------------- */

/**
* Global tasks
*
* build                          : Build assets and server
* watch                          : Watch files for changes and execute their watch tasks.
*/

gulp.task('build', [
  'assets:build',
  'server:build'
])

gulp.task('watch', ['build'], function () {
  livereload.listen()
  return gulp.start([
    'assets:watch',
    'server:watch',
    'server:spawn'
  ])
})
<commit_msg>Ignore temp files<commit_after>'use strict'

/**
* gulpfile.js
*
* Available tasks:
*   `gulp watch`
*   `gulp build`
*   `gulp assets:watch`
*   `gulp assets:clean`
*   `gulp assets:build`
*   `gulp assets:stylesheets`
*   `gulp assets:stylesheets:format`
*   `gulp assets:stylesheets:clean`
*   `gulp assets:javascripts`
*   `gulp assets:javascripts:format`
*   `gulp assets:javascripts:clean`
*   `gulp server:build`
*   `gulp server:spawn`
*   `gulp server:watch`
*
*    Options:
*    --dev                     : Add sourcemaps, refresh livereload
*
* Modules:
*   gulp                       : The streaming build system.
*   args                       : Add arguments support.
*   child_process              : Spawn child process through Node.
*   del                        : Delete files and folders.
*   gulp-autoprefixer          : Prefix CSS.
*   gulp-babel                 : Transpile ES6+ js files.
*   gulp-cleancss              : Minify CSS with clean-css.
*   gulp-concat                : Concatenates files.
*   gulp-csscomb               : Format and sort SCSS/CSS files with CSScomb.
*   gulp-if                    : Conditionally run a task.
*   gulp-livereload            : Reload web browser on demand.
*   gulp-notify                : Notify system.
*   gulp-plumber               : Prevent pipe breaking caused by errors.
*   gulp-rename                : Rename files.
*   gulp-sass                  : Gulp plugin for sass.
*   gulp-sourcemaps            : Source map support for Gulp.js.
*   gulp-standard              : JS linter.
*   gulp-standardFormat        : Format JS files using standard rules.
*   gulp-stylefmt              : Format CSS/SCSS files using stylelint rules.
*   gulp-stylelint             : CSS/SCSS linter.
*   gulp-sync                  : Sync Gulp tasks.
*   gulp-uglify                : Minify files with UglifyJS.
*   gulp-util                  : Utility functions for gulp plugins.
*/

var args = require('yargs').argv
var autoprefix = require('gulp-autoprefixer')
var babel = require('gulp-babel')
var child = require('child_process')
var cleancss = require('gulp-clean-css')
var concat = require('gulp-concat')
var csscomb = require('gulp-csscomb')
var del = require('del')
var gulp = require('gulp')
var gulpif = require('gulp-if')
var gutil = require('gulp-util')
var livereload = require('gulp-livereload')
var notify = require('gulp-notify')
var plumber = require('gulp-plumber')
var rename = require('gulp-rename')
var sass = require('gulp-sass')
var sourcemaps = require('gulp-sourcemaps')
var standard = require('gulp-standard')
var standardFormat = require('gulp-standard-format')
var stylefmt = require('gulp-stylefmt')
var stylelint = require('gulp-stylelint')
var sync = require('gulp-sync')(gulp)
var uglify = require('gulp-uglify')

/* ----------------------------------------------------------------------------
 * locals
 * ------------------------------------------------------------------------- */

var server = null

var root = {
  src: './assets/',
  dest: './public/assets/'
}

var css = {
  src: 'stylesheets/',
  dest: 'stylesheets/',
  main: 'main.scss',
  watch: '**/*',
  include: [
    './node_modules/bulma'
  ]
}

var js = {
  src: 'javascripts/',
  dest: 'javascripts/',
  watch: '**/*',
  ignore: [
    '*/**~'
  ]
}

var views = {
  src: 'views/',
  watch: '**/*.tmpl'
}

var go = {
  src: '*/**/*.go'
}

/* ----------------------------------------------------------------------------
 * Functions
 * ------------------------------------------------------------------------- */

/**
 * Functions
 *
 * handleErrors                   : Send a notification to the system on error.
 */

function handleErrors () {
  var args = Array.prototype.slice.call(arguments)

  notify.onError({
    title: '<%= error.plugin %> failed',
    message: '<%= error.message %>'
  }).apply(this, args)
  gutil.beep()
  this.emit('end')
}

/* ----------------------------------------------------------------------------
 * Assets
 * ------------------------------------------------------------------------- */

/**
* CSS Tasks
*
* assets:stylesheets             : Compile/sort/lint/sourcemap/autoprefix/minify SCSS files to one CSS file.
* assets:stylesheets:format    : Sort SCSS files.
* assets:stylesheets:clean       : Remove any CSS files in stylesheet dist folder.
*/

gulp.task('assets:stylesheets', function () {
  return gulp.src([
      '!' + (root.src + css.src + css.main + '~'),
      root.src + css.src + css.main
    ])
    .pipe(plumber({ errorHandler: handleErrors }))
    .pipe(gulpif(args.dev, sourcemaps.init()))
    .pipe(csscomb())
    .pipe(stylefmt())
    .pipe(stylelint({ reporters: [{ formatter: 'string', console: true }] }))
    .pipe(sass({ includePaths: css.include }))
    .pipe(autoprefix({ browsers: ['last 2 versions'] }))
    .pipe(cleancss())
    .pipe(rename('stylesheet.min.css'))
    .pipe(gulpif(args.dev, sourcemaps.write()))
    .pipe(gulp.dest(root.dest + css.dest))
    .pipe(gulpif(args.dev, livereload()))
})

gulp.task('assets:stylesheets:format', function () {
  return gulp.src([
      '!' + root.src + css.src + css.main,
      '!' + root.src + css.src + css.watch + '~',
      root.src + css.src + css.watch
    ])
   .pipe(plumber({ errorHandler: handleErrors }))
   .pipe(csscomb())
   .pipe(stylefmt())
   .pipe(stylelint({ reporters: [{ formatter: 'string', console: true }] }))
   .pipe(gulp.dest(root.src + css.src))
})

gulp.task('assets:stylesheets:clean', function () {
  return del([root.dest + css.dest])
})

/**
* JS Tasks
*
* assets:javascripts             : Compile/format/lint/sourcemap/concat/minify JS files to one JS file.
* assets:javascripts:format      : Format JS files.
* assets:javascripts:clean       : Remove any JS files in javascript dist folder.
*/
gulp.task('assets:javascripts', function () {
  return gulp.src([
      '!' + root.src + js.src + js.watch + '~',
      root.src + js.src + js.watch
    ])
    .pipe(plumber({ errorHandler: handleErrors }))
    .pipe(gulpif(args.dev, sourcemaps.init()))
    .pipe(standardFormat())
    .pipe(standard())
    .pipe(babel({ presets: ['es2015'] }))
    .pipe(concat('javascript.js'))
    .pipe(uglify())
    .pipe(rename('javascript.min.js'))
    .pipe(gulpif(args.dev, sourcemaps.write()))
    .pipe(gulp.dest(root.dest + js.dest))
    .pipe(gulpif(args.dev, livereload()))
})

gulp.task('assets:javascripts:format', function () {
  return gulp.src(root.src + js.src + js.watch)
   .pipe(plumber({ errorHandler: handleErrors }))
   .pipe(standardFormat())
   .pipe(standard())
   .pipe(gulp.dest(root.src + js.src))
})

gulp.task('assets:javascripts:clean', function () {
  return del([root.dest + js.dest])
})

/**
 * Global assets tasks
 *
 * assets:watch                   : Watch SCSS and JS files for changes and compile them.
 * assets:clean                   : Remove any files in CSS/JS dist folders.
 * assets:build                   : Clean/format/compile CSS/JS files.
 */

gulp.task('assets:watch', function () {
  gulp.watch([root.src + css.src + css.watch], ['assets:stylesheets'])
  gulp.watch([root.src + js.src + js.watch], ['assets:javascripts'])
})

gulp.task('assets:clean', [
  'assets:stylesheets:clean',
  'assets:javascripts:clean'
])

gulp.task('assets:build', [
  'assets:clean',
  'assets:stylesheets:format',
  'assets:stylesheets',
  'assets:javascripts:format',
  'assets:javascripts'
])

/* ----------------------------------------------------------------------------
 * Server
 * ------------------------------------------------------------------------- */

/**
* Global assets tasks
*
* server:build                   : Go install.
* server:spawn                   : Restart Go server.
* server:watch                   : Watch Go/tmpl files for changes and restart server.
*/

gulp.task('server:build', function () {
  var build = child.spawnSync('go', ['install'])

  // Log build errors
  if (build.stderr.length) {
    var lines = build.stderr
      .toString()
      .split('\n')
      .filter(function (line) {
        return line.length
      })

    for (var l in lines) {
      gutil.log(
        gutil.colors.red('Error (go install): ' + lines[l])
      )
    }

    notify.notify({
      title: 'Error (go install)',
      message: lines
    })
  }

  return build
})

gulp.task('server:spawn', function () {
  if (server) {
    server.kill()
  }

  server = child.spawn('go', ['run', 'breizhtrip.go', 'server', '-p', '5050'], { stdio: 'inherit' })

  livereload()
})

gulp.task('server:watch', function () {
  gulp.watch([views.src + views.watch], ['server:spawn'])
  gulp.watch(go.src, sync.sync([
    'server:build',
    'server:spawn'
  ]))
})

/* ----------------------------------------------------------------------------
 * Interface
 * ------------------------------------------------------------------------- */

/**
* Global tasks
*
* build                          : Build assets and server
* watch                          : Watch files for changes and execute their watch tasks.
*/

gulp.task('build', [
  'assets:build',
  'server:build'
])

gulp.task('watch', ['build'], function () {
  livereload.listen()
  return gulp.start([
    'assets:watch',
    'server:watch',
    'server:spawn'
  ])
})
<|endoftext|>


<commit_before>var path = require('path');
var util = require('util');

var gulp = require('gulp');
var lazypipe = require('lazypipe');
var merge = require('merge-stream');
var cache = require('gulp-cache');
var jscs = require('gulp-jscs');
var jshint = require('gulp-jshint');
var replace = require('gulp-replace');
var CacheSwap = require('cache-swap');
var jshintStylish = require('jshint-stylish');

var fileCache = new CacheSwap({tmpDir: '', cacheDirName: 'gulp-cache'});

var globals = {};
var globalList = [
	'Config', 'ResourceMonitor', 'toId', 'Tools', 'LoginServer', 'Users', 'Rooms', 'Verifier',
	'CommandParser', 'Simulator', 'Tournaments', 'Dnsbl', 'Cidr', 'Sockets', 'TeamValidator'
];
globalList.forEach(function (identifier) {globals[identifier] = false;});

function transformLet() {
	// Replacing `var` with `let` is sort of a hack that stops jsHint from
	// complaining that I'm using `var` like `let` should be used, but
	// without having to deal with iffy `let` support.

	return lazypipe()
		.pipe(replace.bind(null, /\bvar\b/g, 'let'))();
}

function lint(jsHintOptions, jscsOptions) {
	function cachedJsHint() {
		return cache(jshint(jsHintOptions), {
			success: function (file) {
				return file.jshint.success;
			},
			value: function (file) {
				return {jshint: file.jshint};
			},
			fileCache: fileCache
		});
	}
	return lazypipe()
		.pipe(cachedJsHint)
		.pipe(jscs.bind(jscs, jscsOptions))();
}

var jsHintOptions = {};
jsHintOptions.base = {
	"nonbsp": true,
	"nonew": true,
	"noarg": true,
	"loopfunc": true,
	"latedef": 'nofunc',

	"freeze": true,
	"undef": true,

	"sub": true,
	"evil": true,
	"esnext": true,
	"node": true,
	"eqeqeq": true,

	"globals": globals
};
jsHintOptions.legacy = util._extend(util._extend({}, jsHintOptions.base), {
	"es3": true
});
jsHintOptions.test = util._extend(util._extend({}, jsHintOptions.base), {
	"globals": util._extend(globals, {
		"BattleEngine": false
	}),
	"mocha": true
});

var jscsOptions = {};
jscsOptions.base = {
	"preset": "yandex",

	"additionalRules": [
		new (require('./dev-tools/jscs-custom-rules/validate-conditionals.js'))(),
		new (require('./dev-tools/jscs-custom-rules/validate-case-indentation.js'))()
	],
	"validateConditionals": true,
	"validateCaseIndentation": true,

	"requireCurlyBraces": null,

	"maximumLineLength": null,
	"validateIndentation": '\t',
	"validateQuoteMarks": null,
	"disallowQuotedKeysInObjects": null,
	"requireDotNotation": null,

	"disallowMultipleVarDecl": null,
	"disallowImplicitTypeConversion": null,
	"requireSpaceAfterLineComment": null,

	"disallowMixedSpacesAndTabs": "smart",
	"requireSpaceAfterKeywords": true,
	"disallowSpacesInsideArrayBrackets": true,
	"disallowSpacesInsideObjectBrackets": true,

	"disallowSpacesInCallExpression": true,
	"validateParameterSeparator": ", ",

	"requireBlocksOnNewline": 1,
	"disallowPaddingNewlinesInBlocks": true,

	"disallowSpaceBeforeSemicolon": true,
	"requireOperatorBeforeLineBreak": true,
	"disallowTrailingComma": true,

	"requireCapitalizedConstructors": true,

	"validateLineBreaks": require('os').EOL === '\n' ? 'LF' : null,
	"disallowMultipleLineBreaks": null
};
jscsOptions.config = util._extend(util._extend({}, jscsOptions.base), {
	"disallowTrailingComma": null
});
jscsOptions.dataCompactArr = util._extend(util._extend({}, jscsOptions.base), {
	"requireSpaceAfterBinaryOperators": ["="],
	"requireSpaceBeforeBinaryOperators": ["="],
	"disallowSpaceAfterBinaryOperators": [","],
	"disallowSpaceBeforeBinaryOperators": [","]
});
jscsOptions.dataCompactAll = {
	"disallowTrailingComma": true,

	"validateLineBreaks": 'CI' in process.env ? 'LF' : null,
	"requireLineFeedAtFileEnd": true,
	"requireSpaceAfterBinaryOperators": ["="],
	"requireSpaceBeforeBinaryOperators": ["="],

	"validateQuoteMarks": "\"",
	"disallowQuotedKeysInObjects": "allButReserved",

	"disallowSpaceAfterObjectKeys": true,
	"disallowSpaceBeforeObjectValues": true,
	"disallowSpacesInsideBrackets": true,
	"disallowSpacesInsideArrayBrackets": true,
	"disallowSpacesInsideObjectBrackets": true,
	"disallowSpacesInsideParentheses": true,
	"disallowSpaceAfterBinaryOperators": [","],
	"disallowSpaceBeforeBinaryOperators": [","]
};
jscsOptions.dataCompactAllIndented = util._extend(util._extend({}, jscsOptions.dataCompactAll), {
	"validateIndentation": '\t'
});

var lintData = [
	{
		dirs: ['./*.js', './tournaments/*.js', './chat-plugins/*.js', './config/!(config).js', './data/rulesets.js', './data/statuses.js'],
		jsHint: jsHintOptions.base,
		jscs: jscsOptions.base
	}, {
		dirs: ['./data/scripts.js', './mods/*/scripts.js', './mods/*/rulesets.js', './mods/*/statuses.js', './dev-tools/**.js'],
		jsHint: jsHintOptions.base,
		jscs: jscsOptions.base
	}, {
		dirs: ['./config/config*.js'],
		jsHint: jsHintOptions.base,
		jscs: jscsOptions.config
	}, {
		dirs: ['./data/abilities.js', './data/items.js', './data/moves.js', './data/typechart.js', './data/aliases.js', './mods/*/abilities.js', './mods/*/items.js', './mods/*/moves.js', './mods/*/typechart.js'],
		jsHint: jsHintOptions.legacy,
		jscs: jscsOptions.base
	}, {
		dirs: ['./data/formats-data.js', './mods/*/formats-data.js', './mods/!(gen1)/pokedex.js'],
		jsHint: jsHintOptions.legacy,
		jscs: jscsOptions.dataCompactArr
	}, {
		dirs: ['./data/pokedex.js', './mods/gen1/pokedex.js'],
		jsHint: jsHintOptions.legacy,
		jscs: jscsOptions.dataCompactAll
	}, {
		dirs: ['./test/*.js', './test/application/*.js', './test/simulator/*/*.js', './test/dev-tools/*/*.js'],
		jsHint: jsHintOptions.test,
		jscs: jscsOptions.base
	}
];
lintData.extra = {
	fastlint: lintData[0],
	learnsets: {
		dirs: ['./data/learnsets*.js', './mods/*/learnsets.js'],
		jsHint: jsHintOptions.legacy,
		jscs: jscsOptions.dataCompactAllIndented
	}
};

var linter = function () {
	return (
		merge.apply(
			null,
			lintData.map(function (source) {
				return gulp.src(source.dirs)
					.pipe(transformLet())
					.pipe(lint(source.jsHint, source.jscs));
			})
		).pipe(jshint.reporter(jshintStylish))
		 .pipe(jshint.reporter('fail'))
	);
};

for (var taskName in lintData.extra) {
	gulp.task(taskName, (function (task) {
		return function () {
			return gulp.src(task.dirs)
				.pipe(transformLet())
				.pipe(lint(task.jsHint, task.jscs))
				.pipe(jshint.reporter(jshintStylish))
				.pipe(jshint.reporter('fail'));
		};
	})(lintData.extra[taskName]));
}

gulp.task('clear', function (done) {
	fileCache.clear('default', done);
});

gulp.task('lint', linter);
gulp.task('default', linter);
<commit_msg>Add tells<commit_after>var path = require('path');
var util = require('util');

var gulp = require('gulp');
var lazypipe = require('lazypipe');
var merge = require('merge-stream');
var cache = require('gulp-cache');
var jscs = require('gulp-jscs');
var jshint = require('gulp-jshint');
var replace = require('gulp-replace');
var CacheSwap = require('cache-swap');
var jshintStylish = require('jshint-stylish');

var fileCache = new CacheSwap({tmpDir: '', cacheDirName: 'gulp-cache'});

var globals = {};
var globalList = [
	'Config', 'ResourceMonitor', 'toId', 'Tools', 'LoginServer', 'Users', 'Rooms', 'Verifier',
	'CommandParser', 'Simulator', 'Tournaments', 'Dnsbl', 'Cidr', 'Sockets', 'TeamValidator', 'Tells'
];
globalList.forEach(function (identifier) {globals[identifier] = false;});

function transformLet() {
	// Replacing `var` with `let` is sort of a hack that stops jsHint from
	// complaining that I'm using `var` like `let` should be used, but
	// without having to deal with iffy `let` support.

	return lazypipe()
		.pipe(replace.bind(null, /\bvar\b/g, 'let'))();
}

function lint(jsHintOptions, jscsOptions) {
	function cachedJsHint() {
		return cache(jshint(jsHintOptions), {
			success: function (file) {
				return file.jshint.success;
			},
			value: function (file) {
				return {jshint: file.jshint};
			},
			fileCache: fileCache
		});
	}
	return lazypipe()
		.pipe(cachedJsHint)
		.pipe(jscs.bind(jscs, jscsOptions))();
}

var jsHintOptions = {};
jsHintOptions.base = {
	"nonbsp": true,
	"nonew": true,
	"noarg": true,
	"loopfunc": true,
	"latedef": 'nofunc',

	"freeze": true,
	"undef": true,

	"sub": true,
	"evil": true,
	"esnext": true,
	"node": true,
	"eqeqeq": true,

	"globals": globals
};
jsHintOptions.legacy = util._extend(util._extend({}, jsHintOptions.base), {
	"es3": true
});
jsHintOptions.test = util._extend(util._extend({}, jsHintOptions.base), {
	"globals": util._extend(globals, {
		"BattleEngine": false
	}),
	"mocha": true
});

var jscsOptions = {};
jscsOptions.base = {
	"preset": "yandex",

	"additionalRules": [
		new (require('./dev-tools/jscs-custom-rules/validate-conditionals.js'))(),
		new (require('./dev-tools/jscs-custom-rules/validate-case-indentation.js'))()
	],
	"validateConditionals": true,
	"validateCaseIndentation": true,

	"requireCurlyBraces": null,

	"maximumLineLength": null,
	"validateIndentation": '\t',
	"validateQuoteMarks": null,
	"disallowQuotedKeysInObjects": null,
	"requireDotNotation": null,

	"disallowMultipleVarDecl": null,
	"disallowImplicitTypeConversion": null,
	"requireSpaceAfterLineComment": null,

	"disallowMixedSpacesAndTabs": "smart",
	"requireSpaceAfterKeywords": true,
	"disallowSpacesInsideArrayBrackets": true,
	"disallowSpacesInsideObjectBrackets": true,

	"disallowSpacesInCallExpression": true,
	"validateParameterSeparator": ", ",

	"requireBlocksOnNewline": 1,
	"disallowPaddingNewlinesInBlocks": true,

	"disallowSpaceBeforeSemicolon": true,
	"requireOperatorBeforeLineBreak": true,
	"disallowTrailingComma": true,

	"requireCapitalizedConstructors": true,

	"validateLineBreaks": require('os').EOL === '\n' ? 'LF' : null,
	"disallowMultipleLineBreaks": null
};
jscsOptions.config = util._extend(util._extend({}, jscsOptions.base), {
	"disallowTrailingComma": null
});
jscsOptions.dataCompactArr = util._extend(util._extend({}, jscsOptions.base), {
	"requireSpaceAfterBinaryOperators": ["="],
	"requireSpaceBeforeBinaryOperators": ["="],
	"disallowSpaceAfterBinaryOperators": [","],
	"disallowSpaceBeforeBinaryOperators": [","]
});
jscsOptions.dataCompactAll = {
	"disallowTrailingComma": true,

	"validateLineBreaks": 'CI' in process.env ? 'LF' : null,
	"requireLineFeedAtFileEnd": true,
	"requireSpaceAfterBinaryOperators": ["="],
	"requireSpaceBeforeBinaryOperators": ["="],

	"validateQuoteMarks": "\"",
	"disallowQuotedKeysInObjects": "allButReserved",

	"disallowSpaceAfterObjectKeys": true,
	"disallowSpaceBeforeObjectValues": true,
	"disallowSpacesInsideBrackets": true,
	"disallowSpacesInsideArrayBrackets": true,
	"disallowSpacesInsideObjectBrackets": true,
	"disallowSpacesInsideParentheses": true,
	"disallowSpaceAfterBinaryOperators": [","],
	"disallowSpaceBeforeBinaryOperators": [","]
};
jscsOptions.dataCompactAllIndented = util._extend(util._extend({}, jscsOptions.dataCompactAll), {
	"validateIndentation": '\t'
});

var lintData = [
	{
		dirs: ['./*.js', './tournaments/*.js', './chat-plugins/*.js', './config/!(config).js', './data/rulesets.js', './data/statuses.js'],
		jsHint: jsHintOptions.base,
		jscs: jscsOptions.base
	}, {
		dirs: ['./data/scripts.js', './mods/*/scripts.js', './mods/*/rulesets.js', './mods/*/statuses.js', './dev-tools/**.js'],
		jsHint: jsHintOptions.base,
		jscs: jscsOptions.base
	}, {
		dirs: ['./config/config*.js'],
		jsHint: jsHintOptions.base,
		jscs: jscsOptions.config
	}, {
		dirs: ['./data/abilities.js', './data/items.js', './data/moves.js', './data/typechart.js', './data/aliases.js', './mods/*/abilities.js', './mods/*/items.js', './mods/*/moves.js', './mods/*/typechart.js'],
		jsHint: jsHintOptions.legacy,
		jscs: jscsOptions.base
	}, {
		dirs: ['./data/formats-data.js', './mods/*/formats-data.js', './mods/!(gen1)/pokedex.js'],
		jsHint: jsHintOptions.legacy,
		jscs: jscsOptions.dataCompactArr
	}, {
		dirs: ['./data/pokedex.js', './mods/gen1/pokedex.js'],
		jsHint: jsHintOptions.legacy,
		jscs: jscsOptions.dataCompactAll
	}, {
		dirs: ['./test/*.js', './test/application/*.js', './test/simulator/*/*.js', './test/dev-tools/*/*.js'],
		jsHint: jsHintOptions.test,
		jscs: jscsOptions.base
	}
];
lintData.extra = {
	fastlint: lintData[0],
	learnsets: {
		dirs: ['./data/learnsets*.js', './mods/*/learnsets.js'],
		jsHint: jsHintOptions.legacy,
		jscs: jscsOptions.dataCompactAllIndented
	}
};

var linter = function () {
	return (
		merge.apply(
			null,
			lintData.map(function (source) {
				return gulp.src(source.dirs)
					.pipe(transformLet())
					.pipe(lint(source.jsHint, source.jscs));
			})
		).pipe(jshint.reporter(jshintStylish))
		 .pipe(jshint.reporter('fail'))
	);
};

for (var taskName in lintData.extra) {
	gulp.task(taskName, (function (task) {
		return function () {
			return gulp.src(task.dirs)
				.pipe(transformLet())
				.pipe(lint(task.jsHint, task.jscs))
				.pipe(jshint.reporter(jshintStylish))
				.pipe(jshint.reporter('fail'));
		};
	})(lintData.extra[taskName]));
}

gulp.task('clear', function (done) {
	fileCache.clear('default', done);
});

gulp.task('lint', linter);
gulp.task('default', linter);
<|endoftext|>


<commit_before>var gulp = require('gulp');
var less = require('gulp-less');
var browserSync = require('browser-sync').create();
var header = require('gulp-header');
var cleanCSS = require('gulp-clean-css');
var rename = require("gulp-rename");
var uglify = require('gulp-uglify');
var pkg = require('./package.json');

// Set the banner content
var banner = ['/*!\n',
    ' * Start Bootstrap - <%= pkg.title %> v<%= pkg.version %> (<%= pkg.homepage %>)\n',
    ' * Copyright 2013-' + (new Date()).getFullYear(), ' <%= pkg.author %>\n',
    ' * Licensed under <%= pkg.license.type %> (<%= pkg.license.url %>)\n',
    ' */\n',
    ''
].join('');

// Compile LESS files from /less into /css
gulp.task('less', function() {
    return gulp.src('less/freelancer.less')
        .pipe(less())
        .pipe(gulp.dest('css'))
        .pipe(browserSync.reload({
            stream: true
        })) &&
        // to be changed (gulp-file refinement)
        gulp.src('less/custom.less')
        .pipe(less())
        .pipe(gulp.dest('css'))
        .pipe(browserSync.reload({
            stream: true
        })) &&
        gulp.src('less/responsive.less')
        .pipe(less())
        .pipe(gulp.dest('css'))
        .pipe(browserSync.reload({
            stream: true
        }))
});

// Minify compiled CSS
gulp.task('minify-css', ['less'], function() {
    return gulp.src('css/freelancer.css')
        .pipe(cleanCSS({ compatibility: 'ie8' }))
        .pipe(rename({ suffix: '.min' }))
        .pipe(gulp.dest('css'))
        .pipe(browserSync.reload({
            stream: true
        })) &&
        // to be changed (gulp-file refinement)
        gulp.src('css/custom.css')
        .pipe(cleanCSS({ compatibility: 'ie8' }))
        .pipe(rename({ suffix: '.min' }))
        .pipe(gulp.dest('css'))
        .pipe(browserSync.reload({
            stream: true
        })) &&
        gulp.src('css/responsive.css')
        .pipe(cleanCSS({ compatibility: 'ie8' }))
        .pipe(rename({ suffix: '.min' }))
        .pipe(gulp.dest('css'))
        .pipe(browserSync.reload({
            stream: true
        }))
});

// Minify JS
gulp.task('minify-js', function() {
    return gulp.src('js/freelancer.js')
        .pipe(uglify())
        .pipe(header(banner, { pkg: pkg }))
        .pipe(rename({ suffix: '.min' }))
        .pipe(gulp.dest('js'))
        .pipe(browserSync.reload({
            stream: true
        }))
});

// Copy vendor libraries from /node_modules into /vendor
gulp.task('copy', function() {
    gulp.src(['node_modules/bootstrap/dist/**/*', '!**/npm.js', '!**/bootstrap-theme.*', '!**/*.map'])
        .pipe(gulp.dest('vendor/bootstrap'))

    gulp.src(['node_modules/jquery/dist/jquery.js', 'node_modules/jquery/dist/jquery.min.js'])
        .pipe(gulp.dest('vendor/jquery'))

    gulp.src([
            'node_modules/font-awesome/**',
            '!node_modules/font-awesome/**/*.map',
            '!node_modules/font-awesome/.npmignore',
            '!node_modules/font-awesome/*.txt',
            '!node_modules/font-awesome/*.md',
            '!node_modules/font-awesome/*.json'
        ])
        .pipe(gulp.dest('vendor/font-awesome'))
})

// Run everything
gulp.task('default', ['less', 'minify-css', 'minify-js', 'copy']);

// Configure the browserSync task
gulp.task('browserSync', function() {
    browserSync.init({
        server: {
            baseDir: ''
        },
    })
})

// Dev task with browserSync
gulp.task('dev', ['browserSync', 'less', 'minify-css', 'minify-js'], function() {
    gulp.watch('less/*.less', ['less']);
    gulp.watch('css/*.css', ['minify-css']);
    gulp.watch('js/*.js', ['minify-js']);
    // Reloads the browser whenever HTML or JS files change
    gulp.watch('*.html', browserSync.reload);
    gulp.watch('js/**/*.js', browserSync.reload);
});
<commit_msg>gulpfile refinement<commit_after>var gulp = require('gulp');
var less = require('gulp-less');
var browserSync = require('browser-sync').create();
var header = require('gulp-header');
var cleanCSS = require('gulp-clean-css');
var rename = require("gulp-rename");
var uglify = require('gulp-uglify');
var pkg = require('./package.json');

// Set the banner content
var banner = ['/*!\n',
    ' * Start Bootstrap - <%= pkg.title %> v<%= pkg.version %> (<%= pkg.homepage %>)\n',
    ' * Copyright 2013-' + (new Date()).getFullYear(), ' <%= pkg.author %>\n',
    ' * Licensed under <%= pkg.license.type %> (<%= pkg.license.url %>)\n',
    ' */\n',
    ''
].join('');

// Compile LESS files from /less into /css
gulp.task('less', function() {
    return gulp.src('less/freelancer.less')
        .pipe(less())
        .pipe(gulp.dest('css'))
        .pipe(browserSync.reload({
            stream: true
        })) &&
        // to be changed (gulp-file refinement)
        gulp.src('less/custom.less')
        .pipe(less())
        .pipe(gulp.dest('css'))
        .pipe(browserSync.reload({
            stream: true
        })) &&
        gulp.src('less/responsive.less')
        .pipe(less())
        .pipe(gulp.dest('css'))
        .pipe(browserSync.reload({
            stream: true
        }))
});

// Minify compiled CSS
gulp.task('minify-css', ['less'], function() {
    return gulp.src('css/*.css')
        .pipe(cleanCSS({ compatibility: 'ie8' }))
        .pipe(rename({ suffix: '.min' }))
        .pipe(gulp.dest('css/min'))
        .pipe(browserSync.reload({
            stream: true
        }))
});

// Minify JS
gulp.task('minify-js', function() {
    return gulp.src('js/freelancer.js')
        .pipe(uglify())
        .pipe(header(banner, { pkg: pkg }))
        .pipe(rename({ suffix: '.min' }))
        .pipe(gulp.dest('js'))
        .pipe(browserSync.reload({
            stream: true
        }))
});

// Copy vendor libraries from /node_modules into /vendor
gulp.task('copy', function() {
    gulp.src(['node_modules/bootstrap/dist/**/*', '!**/npm.js', '!**/bootstrap-theme.*', '!**/*.map'])
        .pipe(gulp.dest('vendor/bootstrap'))

    gulp.src(['node_modules/jquery/dist/jquery.js', 'node_modules/jquery/dist/jquery.min.js'])
        .pipe(gulp.dest('vendor/jquery'))

    gulp.src([
            'node_modules/font-awesome/**',
            '!node_modules/font-awesome/**/*.map',
            '!node_modules/font-awesome/.npmignore',
            '!node_modules/font-awesome/*.txt',
            '!node_modules/font-awesome/*.md',
            '!node_modules/font-awesome/*.json'
        ])
        .pipe(gulp.dest('vendor/font-awesome'))
})

// Run everything
gulp.task('default', ['less', 'minify-css', 'minify-js', 'copy']);

// Configure the browserSync task
gulp.task('browserSync', function() {
    browserSync.init({
        server: {
            baseDir: ''
        },
    })
})

// Dev task with browserSync
gulp.task('dev', ['browserSync', 'less', 'minify-css', 'minify-js'], function() {
    gulp.watch('less/*.less', ['less']);
    gulp.watch('css/*.css', ['minify-css']);
    gulp.watch('js/*.js', ['minify-js']);
    // Reloads the browser whenever files change
    gulp.watch('*.html', browserSync.reload);
    gulp.watch('css/*.css', browserSync.reload);
    gulp.watch('js/**/*.js', browserSync.reload);
});
<|endoftext|>


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

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

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

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

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

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

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

var LIVERELOAD_PORT = 35729;
var BASEDIR = path.join(__dirname, 'server/views');
var UNCSS_REFERENCE_HTML = [
  'build/index.html'
];
var DIST_PREFIX_PATH = '';
var THIRD_PARTY_SCRIPTS = [
  'third-party/jquery/dist/jquery.js',
  'third-party/lodash/dist/lodash.js',
  'third-party/react/react.js',
  'third-party/bootstrap/dist/js/bootstrap.js'
];
var THIRD_PARTY_SCRIPTS_MINIFIED = [
  'third-party/jquery/dist/jquery.min.js',
  'third-party/lodash/dist/lodash.min.js',
  'third-party/react/react.min.js',
  'third-party/bootstrap/dist/js/bootstrap.min.js'
];

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

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

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

var thirdPartyScripts = function(destinationPath, options) {
  options = defaultOptions(options);
  if (options.minified === true) {
    return gulp.src(THIRD_PARTY_SCRIPTS_MINIFIED)
      .pipe(flatten())
      .pipe(gulp.dest(destinationPath));
  } else {
    return gulp.src(THIRD_PARTY_SCRIPTS)
      .pipe(flatten())
      .pipe(gulp.dest(destinationPath));
  }
};

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

gulp.task('bootstrap-styles', ['templates-build'], function() {
  return gulp.src('third-party/bootstrap/dist/css/bootstrap.css')
    .pipe(gulp.dest('client/css'))
});

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

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

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

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

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

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

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

gulp.task('watch', function() {
  livereload.listen();
  gulp.watch(['client/**/*.*', '!client/**/*.{coffee,cjsx,less,html,map}'], ['copy-to-build']);
  gulp.watch(['client/coffee/**/*.coffee', 'client/coffee/**/*.cjsx'], ['scripts-build']);
  gulp.watch('client/less/**/*.less', ['styles-build']);
  gulp.watch('server/views/**/*.jade', ['bootstrap-styles']);
});

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

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

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

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

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

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

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

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

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

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

var LIVERELOAD_PORT = 35729;
var BASEDIR = path.join(__dirname, 'server/views');
var DIST_PREFIX_PATH = '';
var THIRD_PARTY_SCRIPTS = [
  'third-party/jquery/dist/jquery.js',
  'third-party/lodash/dist/lodash.js',
  'third-party/react/react.js',
  'third-party/bootstrap/dist/js/bootstrap.js'
];
var THIRD_PARTY_SCRIPTS_MINIFIED = [
  'third-party/jquery/dist/jquery.min.js',
  'third-party/lodash/dist/lodash.min.js',
  'third-party/react/react.min.js',
  'third-party/bootstrap/dist/js/bootstrap.min.js'
];

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

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

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

var thirdPartyScripts = function(destinationPath, options) {
  options = defaultOptions(options);
  if (options.minified === true) {
    return gulp.src(THIRD_PARTY_SCRIPTS_MINIFIED)
      .pipe(flatten())
      .pipe(gulp.dest(destinationPath));
  } else {
    return gulp.src(THIRD_PARTY_SCRIPTS)
      .pipe(flatten())
      .pipe(gulp.dest(destinationPath));
  }
};

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

gulp.task('bootstrap-styles', ['templates-build'], function() {
  return gulp.src('third-party/bootstrap/dist/css/bootstrap.css')
    .pipe(gulp.dest('client/css'))
});

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

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

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

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

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

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

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

gulp.task('watch', function() {
  livereload.listen();
  gulp.watch(['client/**/*.*', '!client/**/*.{coffee,cjsx,less,html,map}'], ['copy-to-build']);
  gulp.watch(['client/coffee/**/*.coffee', 'client/coffee/**/*.cjsx'], ['scripts-build']);
  gulp.watch('client/less/**/*.less', ['styles-build']);
  gulp.watch('server/views/**/*.jade', ['bootstrap-styles']);
});

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

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

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

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


<commit_before>const gulp = require('gulp')
const path = require('path')
const fs = require('fs-extra')

gulp.task('clean', done => {
  fs.remove(path.join(__dirname, 'autoprefixer.js'), () => {
    fs.remove(path.join(__dirname, 'build'), done)
  })
})

gulp.task('build:lib', ['clean'], () => {
  const babel = require('gulp-babel')

  return gulp.src(['{lib,data}/**/*.js'])
    .pipe(babel())
    .pipe(gulp.dest('build/'))
})

gulp.task('build:docs', ['clean'], () => {
  const ignore = require('fs').readFileSync('.npmignore').toString()
    .trim().split(/\n+/)
    .concat(['.npmignore', 'index.js', 'package.json', 'logo.svg'])
    .map(i => '!' + i)

  return gulp.src(['*'].concat(ignore))
    .pipe(gulp.dest('build'))
})

gulp.task('build:bin', ['clean'], () => {
  return gulp.src('bin/*').pipe(gulp.dest('build/bin'))
})

gulp.task('build:package', ['clean'], () => {
  const editor = require('gulp-json-editor')

  return gulp.src('./package.json')
    .pipe(editor(json => {
      json.main = 'lib/autoprefixer'
      json.devDependencies['babel-register'] =
                json.dependencies['babel-register']
      delete json.dependencies['babel-register']
      delete json.babel
      delete json.scripts
      delete json.jest
      delete json.eslintConfig
      delete json['size-limit']
      delete json['pre-commit']
      delete json['lint-staged']
      delete json.devDependencies
      return json
    }))
    .pipe(gulp.dest('build'))
})

gulp.task('build', ['build:lib', 'build:docs', 'build:bin', 'build:package'])

gulp.task('standalone', ['build:lib'], done => {
  const builder = require('browserify')({
    basedir: path.join(__dirname, 'build'),
    standalone: 'autoprefixer'
  })
  builder.add('./lib/autoprefixer.js')

  builder
    .transform('babelify', {
      global: true,
      presets: [
        ['env', { node: '0.10', loose: true }]
      ]
    })
    .bundle((error, build) => {
      if (error) throw error

      fs.removeSync(path.join(__dirname, 'build'))

      const rails = path.join(__dirname, '..', 'autoprefixer-rails',
        'vendor', 'autoprefixer.js')
      if (fs.existsSync(rails)) {
        fs.writeFileSync(rails, build)
      } else {
        const out = path.join(__dirname, 'autoprefixer.js')
        fs.writeFileSync(out, build)
      }
      done()
    })
})

gulp.task('default', ['build'])
<commit_msg>Remove AUTHORS from npm package<commit_after>const gulp = require('gulp')
const path = require('path')
const fs = require('fs-extra')

gulp.task('clean', done => {
  fs.remove(path.join(__dirname, 'autoprefixer.js'), () => {
    fs.remove(path.join(__dirname, 'build'), done)
  })
})

gulp.task('build:lib', ['clean'], () => {
  const babel = require('gulp-babel')

  return gulp.src(['{lib,data}/**/*.js'])
    .pipe(babel())
    .pipe(gulp.dest('build/'))
})

gulp.task('build:docs', ['clean'], () => {
  const ignore = require('fs').readFileSync('.npmignore').toString()
    .trim().split(/\n+/)
    .concat(['.npmignore', 'index.js', 'package.json', 'logo.svg', 'AUTHORS'])
    .map(i => '!' + i)

  return gulp.src(['*'].concat(ignore))
    .pipe(gulp.dest('build'))
})

gulp.task('build:bin', ['clean'], () => {
  return gulp.src('bin/*').pipe(gulp.dest('build/bin'))
})

gulp.task('build:package', ['clean'], () => {
  const editor = require('gulp-json-editor')

  return gulp.src('./package.json')
    .pipe(editor(json => {
      json.main = 'lib/autoprefixer'
      json.devDependencies['babel-register'] =
                json.dependencies['babel-register']
      delete json.dependencies['babel-register']
      delete json.babel
      delete json.scripts
      delete json.jest
      delete json.eslintConfig
      delete json['size-limit']
      delete json['pre-commit']
      delete json['lint-staged']
      delete json.devDependencies
      return json
    }))
    .pipe(gulp.dest('build'))
})

gulp.task('build', ['build:lib', 'build:docs', 'build:bin', 'build:package'])

gulp.task('standalone', ['build:lib'], done => {
  const builder = require('browserify')({
    basedir: path.join(__dirname, 'build'),
    standalone: 'autoprefixer'
  })
  builder.add('./lib/autoprefixer.js')

  builder
    .transform('babelify', {
      global: true,
      presets: [
        ['env', { node: '0.10', loose: true }]
      ]
    })
    .bundle((error, build) => {
      if (error) throw error

      fs.removeSync(path.join(__dirname, 'build'))

      const rails = path.join(__dirname, '..', 'autoprefixer-rails',
        'vendor', 'autoprefixer.js')
      if (fs.existsSync(rails)) {
        fs.writeFileSync(rails, build)
      } else {
        const out = path.join(__dirname, 'autoprefixer.js')
        fs.writeFileSync(out, build)
      }
      done()
    })
})

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


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

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

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

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

gulp.task('lint', function () {
  return gulp.src('lib/!(external)**/*.js')
    .pipe(jshint())
    .pipe(jshint.reporter('jshint-stylish'))
    .pipe(jshint.reporter('fail'));
});

// Run unit tests
gulp.task('test', function() {
  return gulp.src(
//  [
//    //'./lib/external/require.js',
//    './test/**/*.js',
//    './test/test-main.js'
//  ]
  )
    .pipe(karma({ configFile: 'test/karma.conf.js' }))
    .on('error', function(err) { throw err; });
});

gulp.task('default', ['lint', 'test']);
<commit_msg>use karma decoupled from gulp<commit_after>var gulp = require('gulp');

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

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

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

gulp.task('lint', function () {
  return gulp.src('lib/!(external)**/*.js')
    .pipe(jshint())
    .pipe(jshint.reporter('jshint-stylish'))
    .pipe(jshint.reporter('fail'));
});

// Run unit tests
gulp.task('test', function(done) {
  return gulp.src(
//  [
//    //'./lib/external/require.js',
//    './test/**/*.js',
//    './test/test-main.js'
//  ]
//  )
//    .pipe(karma({ configFile: 'test/karma.conf.js' }))
//    .on('error', function(err) { throw err; });
  karma.start({
    configFile: 'test/karma.conf.js',
    singleRun: true
  }, done);
});

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


<commit_before>var require_install = require('require-install')
    ,gulp = require('gulp')
    ,fs = require('fs')
    ,path = require('path')
    ,autoprefixer = require_install('gulp-autoprefixer')
    ,browserSync = require_install('browser-sync')
    ,concat = require_install('gulp-concat')
    ,filter = require_install('gulp-filter')
    ,sass = require_install('gulp-ruby-sass')
    ,sourcemaps = require_install('gulp-sourcemaps')
    ,browserify = require_install('browserify')
    //,browserify_shim = require_install('browserify-shim')
    //,bower = require_install('gulp-bower')
    //,bower_files = require_install('main-bower-files')
    //,browserify = require_install('browserify')
    //,browserify_shim = require_install('browserify-shim')
    //,cache = require_install('gulp-cache')
    //,coffee = require_install('gulp-coffee')
    //,coffeelint = require_install('gulp-coffeelint')
    //,colors = require_install(//'colors')
    //,compass = require_install('gulp-compass')
    //,cssimport = require_install("gulp-cssimport")
    //,cssGlobbing = require_install('gulp-css-globbing')
    //,debug = require_install('gulp-debug')
    //,globule = require_install('globule')
    //,insert = require_install('gulp-insert')
    ,mq_remove = require_install('gulp-mq-remove')
    //,native_exec = require_install('child_process').exec
    ,no_media_queries = require_install('gulp-no-media-queries')
    //,spawn = require_install('child_process')//.spawn
    //,exec = require_install('gulp-exec')
    //,exit = require_install('gulp-exit')
    //,less = require_install('gulp-less')
    //,minifycss = require_install('gulp-minify-css')
    //,phpunit = require_install('gulp-phpunit')
    //,phpspec = require_install('gulp-phpspec')
    //,plumber = require_install('gulp-plumber')
    ,rem_to_px = require_install('gulp-rem-to-px')
    //,sass = require_install('gulp-sass')
    ,source = require_install('vinyl-source-stream')
    //,svg2png = require_install('gulp-svg2png')
    //,sys = require_install('sys')
    ,rename = require_install('gulp-rename')
    //,uglify = require_install('gulp-uglify')
    //,gutil = require_install('gulp-util')
    //,watchify = require_install('watchify')
    ;

var backend_try_list = [
    process.env.BACKEND_PORT_8000_TCP,
    process.env.BACKEND_PORT_80_TCP,
    process.env.BACKEND_PORT,
    'tcp://localhost:8000',
];

var base_path = process.env.BASE_DIR ? process.env.BASE_DIR : 'src/static/app';

var paths = {
    src: 'src',
    images: base_path+'/../../../media/images',
    styles: base_path+'/src/styles',
    scripts: base_path+'/src/scripts',
    output_styles: base_path+'/dist',
    output_scripts: base_path+'/dist',
    bower: base_path+'/bower_components',
};

var reload = browserSync.reload;
var browserSyncConfig = {
    stream: true
};

var report_options = {
    err: true, // default = true, false means don't write err
    stderr: true, // default = true, false means don't write stderr
    stdout: true, // default = true, false means don't write stdout
};

gulp.task('sass', function () {
    return sass(paths.styles+'/masters', { sourcemap: true})
        .on('error', function (err) {
            console.error('Error', err.message);
        })
        .pipe(autoprefixer({
            browsers: [
                "last 2 version",
                "> 1%",
                "ie 11",
                "ie 10",
                "ie 9",
            ]
        }))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest(paths.output_styles))
        .pipe(filter('**/*.css'))
        .pipe(reload(browserSyncConfig));
});

gulp.task('css-master-ie', ['sass'], function () {
    gulp.src(paths.output_styles+'/style.css')
        .pipe(no_media_queries({width: '1026px'}))
        .pipe(rename('no-media-query.css'))
        .pipe(gulp.dest(paths.output_styles));

    return gulp.src([paths.output_styles+'/style.css', paths.output_styles+'/no-media-query.css', paths.output_styles+'/ie.css'])
        .pipe(concat('style-ie.css'))
        .pipe(mq_remove({type: 'screen'}))
        .pipe(rem_to_px({fontSize: 16}))
        .pipe(gulp.dest(paths.output_styles))
        .pipe(filter('**/*.css'))
        .pipe(reload(browserSyncConfig));
});

gulp.task('js:all', function() {
    return browserify(paths.scripts+'/masters/script.js')
            .bundle()
            .pipe(source('script.js'))
            .pipe(gulp.dest(paths.output_scripts))
            .pipe(reload(browserSyncConfig))
            ;
});

gulp.task('js:ie', function() {

    browserify(paths.scripts+'/masters/ie.js')
        .bundle()
        .pipe(source('ie.js'))
        .pipe(gulp.dest(paths.output_scripts))
        .pipe(reload(browserSyncConfig))
        ;
});

var backend_tcp;
for (var k in backend_try_list) {
    if (backend_try_list[k] === undefined) {
        continue;
    }
    backend_tcp = backend_try_list[k];
    break;
}

gulp.task('browser-sync', function() {
    browserSync.init({
        proxy: backend_tcp.substr(6)
    });
});

gulp.task('watch', ['browser-sync'], function() {
    gulp.watch(paths.styles+'/**/*.sass', [
        'sass',
        'css-master-ie',
    ]);
    gulp.watch(paths.scripts+'/**/*.js', [
        'js:all',
        'js:ie',
    ]);
    //gulp.watch(paths.images+'/**/*.svg', [
    //    'svg',
    //]);
    gulp.watch(paths.src+"/**/*.html").on('change', reload);
});

gulp.task('default', [
    'gulpfile-watch',
    'watch',
    'sass',
    'css-master-ie',
    'js:all',
    'js:ie',
    //'svg',
]);

gulp.task('exit-gulp', function(){
    process.exit(0);
});

gulp.task('gulpfile-watch', function(){
   gulp.watch(__filename, ['exit-gulp']);
});
<commit_msg>switch to better rem-to-px package<commit_after>var require_install = require('require-install')
    ,gulp = require('gulp')
    ,fs = require('fs')
    ,path = require('path')
    ,autoprefixer = require_install('gulp-autoprefixer')
    ,browserSync = require_install('browser-sync')
    ,concat = require_install('gulp-concat')
    ,filter = require_install('gulp-filter')
    ,sass = require_install('gulp-ruby-sass')
    ,sourcemaps = require_install('gulp-sourcemaps')
    ,browserify = require_install('browserify')
    //,browserify_shim = require_install('browserify-shim')
    //,bower = require_install('gulp-bower')
    //,bower_files = require_install('main-bower-files')
    //,browserify = require_install('browserify')
    //,browserify_shim = require_install('browserify-shim')
    //,cache = require_install('gulp-cache')
    //,coffee = require_install('gulp-coffee')
    //,coffeelint = require_install('gulp-coffeelint')
    //,colors = require_install(//'colors')
    //,compass = require_install('gulp-compass')
    //,cssimport = require_install("gulp-cssimport")
    //,cssGlobbing = require_install('gulp-css-globbing')
    //,debug = require_install('gulp-debug')
    //,globule = require_install('globule')
    //,insert = require_install('gulp-insert')
    ,mq_remove = require_install('gulp-mq-remove')
    //,native_exec = require_install('child_process').exec
    ,no_media_queries = require_install('gulp-no-media-queries')
    //,spawn = require_install('child_process')//.spawn
    //,exec = require_install('gulp-exec')
    //,exit = require_install('gulp-exit')
    //,less = require_install('gulp-less')
    //,minifycss = require_install('gulp-minify-css')
    //,phpunit = require_install('gulp-phpunit')
    //,phpspec = require_install('gulp-phpspec')
    //,plumber = require_install('gulp-plumber')
    ,rem_to_px = require_install('gulp-rem-to-px-cleanup')
    //,sass = require_install('gulp-sass')
    ,source = require_install('vinyl-source-stream')
    //,svg2png = require_install('gulp-svg2png')
    //,sys = require_install('sys')
    ,rename = require_install('gulp-rename')
    //,uglify = require_install('gulp-uglify')
    //,gutil = require_install('gulp-util')
    //,watchify = require_install('watchify')
    ;

var backend_try_list = [
    process.env.BACKEND_PORT_8000_TCP,
    process.env.BACKEND_PORT_80_TCP,
    process.env.BACKEND_PORT,
    'tcp://localhost:8000',
];

var base_path = process.env.BASE_DIR ? process.env.BASE_DIR : 'src/static/app';

var paths = {
    src: 'src',
    images: base_path+'/../../../media/images',
    styles: base_path+'/src/styles',
    scripts: base_path+'/src/scripts',
    output_styles: base_path+'/dist',
    output_scripts: base_path+'/dist',
    bower: base_path+'/bower_components',
};

var reload = browserSync.reload;
var browserSyncConfig = {
    stream: true
};

var report_options = {
    err: true, // default = true, false means don't write err
    stderr: true, // default = true, false means don't write stderr
    stdout: true, // default = true, false means don't write stdout
};

gulp.task('sass', function () {
    return sass(paths.styles+'/masters', { sourcemap: true})
        .on('error', function (err) {
            console.error('Error', err.message);
        })
        .pipe(autoprefixer({
            browsers: [
                "last 2 version",
                "> 1%",
                "ie 11",
                "ie 10",
                "ie 9",
            ]
        }))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest(paths.output_styles))
        .pipe(filter('**/*.css'))
        .pipe(reload(browserSyncConfig));
});

gulp.task('css-master-ie', ['sass'], function () {
    gulp.src(paths.output_styles+'/style.css')
        .pipe(no_media_queries({width: '1026px'}))
        .pipe(rename('no-media-query.css'))
        .pipe(gulp.dest(paths.output_styles));

    return gulp.src([paths.output_styles+'/style.css', paths.output_styles+'/no-media-query.css', paths.output_styles+'/ie.css'])
        .pipe(concat('style-ie.css'))
        .pipe(mq_remove({type: 'screen'}))
        .pipe(rem_to_px({baseFontSize: 16}))
        .pipe(gulp.dest(paths.output_styles))
        .pipe(filter('**/*.css'))
        .pipe(reload(browserSyncConfig));
});

gulp.task('js:all', function() {
    return browserify(paths.scripts+'/masters/script.js')
            .bundle()
            .pipe(source('script.js'))
            .pipe(gulp.dest(paths.output_scripts))
            .pipe(reload(browserSyncConfig))
            ;
});

gulp.task('js:ie', function() {

    browserify(paths.scripts+'/masters/ie.js')
        .bundle()
        .pipe(source('ie.js'))
        .pipe(gulp.dest(paths.output_scripts))
        .pipe(reload(browserSyncConfig))
        ;
});

var backend_tcp;
for (var k in backend_try_list) {
    if (backend_try_list[k] === undefined) {
        continue;
    }
    backend_tcp = backend_try_list[k];
    break;
}

gulp.task('browser-sync', function() {
    browserSync.init({
        proxy: backend_tcp.substr(6)
    });
});

gulp.task('watch', ['browser-sync'], function() {
    gulp.watch(paths.styles+'/**/*.sass', [
        'sass',
        'css-master-ie',
    ]);
    gulp.watch(paths.scripts+'/**/*.js', [
        'js:all',
        'js:ie',
    ]);
    //gulp.watch(paths.images+'/**/*.svg', [
    //    'svg',
    //]);
    gulp.watch(paths.src+"/**/*.html").on('change', reload);
});

gulp.task('default', [
    'gulpfile-watch',
    'watch',
    'sass',
    'css-master-ie',
    'js:all',
    'js:ie',
    //'svg',
]);

gulp.task('exit-gulp', function(){
    process.exit(0);
});

gulp.task('gulpfile-watch', function(){
   gulp.watch(__filename, ['exit-gulp']);
});
<|endoftext|>