<commit_before>'use strict';

/**
 * Set the current node environment.
 */

process.env.NODE_ENV = process.env.NODE_ENV || 'development';

/**
 * Dependencies.
 */

var babelify = require('babelify');
var bourbon = require('node-bourbon');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var envc = require('envc')({ nodeenv: process.env.EXT_ENV || process.env.NODE_ENV });
var envify = require('envify');
var fs = require('fs');
var gulp = require('gulp');
var gulpif = require('gulp-if');
var gutil = require('gulp-util')
var gwatch = require('gulp-watch');
var harmonize = require('harmonize')();
var html = require('gulp-minify-html');
var imagemin = require('gulp-imagemin');
var jest = require('jest-cli');
var json = require('gulp-jsonminify');
var minifyCss = require('gulp-minify-css');
var mocha = require('gulp-spawn-mocha');
var neat = require('node-neat');
var rimraf = require('rimraf');
var sass = require('gulp-sass');
var source = require('vinyl-source-stream');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var watchify = require('watchify');
var zip = require('gulp-zip');

/**
 * Locals.
 */

var requiredVars = fs.readFileSync('.env.assert', 'utf8').split('\n');
var env = process.env;
var EXT_ENV = env.EXT_ENV;
var DEV = env.NODE_ENV === 'development' || env.NODE_ENV === 'test';
var assertEnv = require('assert-env')(requiredVars.filter(function(key) {
  return !!key;
}));

/**
 * Arguments.
 */

var argv = gutil.env;

/**
 * File patterns.
 */

var patterns = {
  html: 'src/**/*.html',
  img: 'src/**/*.{png,svg,ico}',
  css: 'src/**/*.{scss,css}',
  locales: 'src/_locales/**/*.json',
  vendor: 'vendor/**/**'
};

/**
 * Root dest.
 */

var dest = 'build' || argv.build;

/**
 * JavaScript bundles.
 */

var bundles = [
  { entry: './src/apps/popup/main.js', out: 'apps/popup/main.js' },
  { entry: './src/apps/background/main.js', out: 'apps/background/main.js' },
  { entry: './src/apps/content/main.js', out: 'apps/content/main.js' },
  { entry: './src/apps/tabs/main.js', out: 'apps/tabs/main.js' },
  { entry: './src/apps/options/main.js', out: 'apps/options/main.js' }
];

/**
 * Return a gulp-watch or noop, based on
 * the `--watch` flag.
 *
 * @return {Stream}
 * @private
 */

function watch(pattern) {
  return argv.watch ? gwatch(pattern, { verbose: true }) : gutil.noop();
}

/**
 * Build the JavaScript bundles.
 */

gulp.task('js', function() {
  return bundles.map(function(bundle) {
    var bundler = browserify({
      entries: [bundle.entry],
      transform: [envify, babelify],
      debug: DEV,
      cache: {},
      packageCache: {},
      fullPaths: true
    });

    bundler.on('log', gutil.log)

    var update = function() {
      return bundler.bundle()
        .on('error', function(err) {
          gutil.log(err.message);
        })
        .pipe(source(bundle.out))
        .pipe(buffer())
        .pipe(gulpif(!DEV, uglify()))
        .pipe(gulp.dest(dest));
    };

    if (argv.watch) {
      bundler = watchify(bundler);
      bundler.on('update', update);
    }

    return update();
  });
});

/**
 * Minify the HTML files.
 */

gulp.task('html', function() {
  return gulp.src(patterns.html)
    .pipe(watch(patterns.html))
    .pipe(html())
    .pipe(gulp.dest(dest));
});

/**
 * Copy vendor files.
 */

gulp.task('vendor', function() {
  return gulp.src(patterns.vendor)
    .pipe(watch(patterns.vendor))
    .pipe(gulp.dest(dest + '/vendor'));
});

/**
 * Minify the locale files.
 */

gulp.task('locales', function() {
  return gulp.src(patterns.locales)
    .pipe(watch(patterns.locales))
    .pipe(json())
    .pipe(gulp.dest(dest + '/_locales/'));
});

/**
 * Modify the manifest file.
 */

gulp.task('manifest', function(done) {
  var manifest = require('./src/manifest.json');

  if (EXT_ENV !== 'production') {
    manifest.name = '[' + EXT_ENV + '] ProductHunt';
  }

  fs.writeFile(dest + '/manifest.json', JSON.stringify(manifest), done);
});

/**
 * Compile the scss files.
 */

gulp.task('scss', function() {
  var paths = neat.includePaths.concat(['./src']);

  return gulp.src(patterns.css)
    .pipe(watch(patterns.css))
    .pipe(gulpif(DEV, sourcemaps.init()))
    .pipe(sass({
      imagePath: 'chrome-extension://' + env.EXTENSION_ID,
      includePaths: paths,
      errLogToConsole: true
    }))
    .pipe(gulpif(DEV, sourcemaps.write()))
    .pipe(gulpif(!DEV, minifyCss()))
    .pipe(gulp.dest(dest));
});

/**
 * Optimize the images.
 */

gulp.task('img', function() {
  return gulp.src(patterns.img)
    .pipe(watch(patterns.img))
    .pipe(imagemin())
    .pipe(gulp.dest(dest));
});

/**
 * Run the end to end tests.
 */

gulp.task('test-acceptance', function() {
  return gulp.src(['test/*.js'], { read: false })
    .pipe(mocha({ r: 'test/setup.js', timeout: 10000 }));
});

/**
 * Run all unit tests.
 */

gulp.task('test-unit', function(done) {
  var options = {
    config: {
      rootDir: __dirname,
      testPathDirs: [__dirname + '/src'],
      scriptPreprocessor: __dirname + '/node_modules/babel-jest/index.js',
      setupEnvScriptFile: __dirname + '/jest/env.js',
      setupTestFrameworkScriptFile: __dirname + '/jest/setup.js'
    }
  };

  jest.runCLI(options, __dirname, function(success) {
    done();
  });
});

/**
 * Create an archive from `build`.
 */

gulp.task('pack', function() {
  var version = require('./src/manifest.json').version;

  return gulp.src(dest + '/**/*')
    .pipe(zip(version + '-product-hunt.zip'))
    .pipe(gulp.dest('dist'));
});

/**
 * Clean the build folder.
 */

gulp.task('clean', function() {
  [
    dest + '/_locales',
    dest + '/apps',
    dest + '/common',
    dest + '/vendor',
    dest + '/manifest.json'
  ].forEach(function(dir) {
    rimraf.sync(dir)
  });
});

/**
 * Tests.
 */

gulp.task('test', ['test-acceptance', 'test-unit']);

/**
 * Build all.
 */

gulp.task('build', [
  'clean',
  'js',
  'html',
  'locales',
  'manifest',
  'scss',
  'img',
  'vendor'
]);
<commit_msg>Set default value for EXT_ENV<commit_after>'use strict';

/**
 * Set the current environment.
 */

process.env.NODE_ENV = process.env.NODE_ENV || 'development';
process.env.EXT_ENV = process.env.EXT_ENV || 'development';

/**
 * Dependencies.
 */

var babelify = require('babelify');
var bourbon = require('node-bourbon');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var envc = require('envc')({ nodeenv: process.env.EXT_ENV || process.env.NODE_ENV });
var envify = require('envify');
var fs = require('fs');
var gulp = require('gulp');
var gulpif = require('gulp-if');
var gutil = require('gulp-util')
var gwatch = require('gulp-watch');
var harmonize = require('harmonize')();
var html = require('gulp-minify-html');
var imagemin = require('gulp-imagemin');
var jest = require('jest-cli');
var json = require('gulp-jsonminify');
var minifyCss = require('gulp-minify-css');
var mocha = require('gulp-spawn-mocha');
var neat = require('node-neat');
var rimraf = require('rimraf');
var sass = require('gulp-sass');
var source = require('vinyl-source-stream');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var watchify = require('watchify');
var zip = require('gulp-zip');

/**
 * Locals.
 */

var requiredVars = fs.readFileSync('.env.assert', 'utf8').split('\n');
var env = process.env;
var EXT_ENV = env.EXT_ENV;
var DEV = env.NODE_ENV === 'development' || env.NODE_ENV === 'test';
var assertEnv = require('assert-env')(requiredVars.filter(function(key) {
  return !!key;
}));

/**
 * Arguments.
 */

var argv = gutil.env;

/**
 * File patterns.
 */

var patterns = {
  html: 'src/**/*.html',
  img: 'src/**/*.{png,svg,ico}',
  css: 'src/**/*.{scss,css}',
  locales: 'src/_locales/**/*.json',
  vendor: 'vendor/**/**'
};

/**
 * Root dest.
 */

var dest = 'build' || argv.build;

/**
 * JavaScript bundles.
 */

var bundles = [
  { entry: './src/apps/popup/main.js', out: 'apps/popup/main.js' },
  { entry: './src/apps/background/main.js', out: 'apps/background/main.js' },
  { entry: './src/apps/content/main.js', out: 'apps/content/main.js' },
  { entry: './src/apps/tabs/main.js', out: 'apps/tabs/main.js' },
  { entry: './src/apps/options/main.js', out: 'apps/options/main.js' }
];

/**
 * Return a gulp-watch or noop, based on
 * the `--watch` flag.
 *
 * @return {Stream}
 * @private
 */

function watch(pattern) {
  return argv.watch ? gwatch(pattern, { verbose: true }) : gutil.noop();
}

/**
 * Build the JavaScript bundles.
 */

gulp.task('js', function() {
  return bundles.map(function(bundle) {
    var bundler = browserify({
      entries: [bundle.entry],
      transform: [envify, babelify],
      debug: DEV,
      cache: {},
      packageCache: {},
      fullPaths: true
    });

    bundler.on('log', gutil.log)

    var update = function() {
      return bundler.bundle()
        .on('error', function(err) {
          gutil.log(err.message);
        })
        .pipe(source(bundle.out))
        .pipe(buffer())
        .pipe(gulpif(!DEV, uglify()))
        .pipe(gulp.dest(dest));
    };

    if (argv.watch) {
      bundler = watchify(bundler);
      bundler.on('update', update);
    }

    return update();
  });
});

/**
 * Minify the HTML files.
 */

gulp.task('html', function() {
  return gulp.src(patterns.html)
    .pipe(watch(patterns.html))
    .pipe(html())
    .pipe(gulp.dest(dest));
});

/**
 * Copy vendor files.
 */

gulp.task('vendor', function() {
  return gulp.src(patterns.vendor)
    .pipe(watch(patterns.vendor))
    .pipe(gulp.dest(dest + '/vendor'));
});

/**
 * Minify the locale files.
 */

gulp.task('locales', function() {
  return gulp.src(patterns.locales)
    .pipe(watch(patterns.locales))
    .pipe(json())
    .pipe(gulp.dest(dest + '/_locales/'));
});

/**
 * Modify the manifest file.
 */

gulp.task('manifest', function(done) {
  var manifest = require('./src/manifest.json');

  if (EXT_ENV !== 'production') {
    manifest.name = '[' + EXT_ENV + '] ProductHunt';
  }

  fs.writeFile(dest + '/manifest.json', JSON.stringify(manifest), done);
});

/**
 * Compile the scss files.
 */

gulp.task('scss', function() {
  var paths = neat.includePaths.concat(['./src']);

  return gulp.src(patterns.css)
    .pipe(watch(patterns.css))
    .pipe(gulpif(DEV, sourcemaps.init()))
    .pipe(sass({
      imagePath: 'chrome-extension://' + env.EXTENSION_ID,
      includePaths: paths,
      errLogToConsole: true
    }))
    .pipe(gulpif(DEV, sourcemaps.write()))
    .pipe(gulpif(!DEV, minifyCss()))
    .pipe(gulp.dest(dest));
});

/**
 * Optimize the images.
 */

gulp.task('img', function() {
  return gulp.src(patterns.img)
    .pipe(watch(patterns.img))
    .pipe(imagemin())
    .pipe(gulp.dest(dest));
});

/**
 * Run the end to end tests.
 */

gulp.task('test-acceptance', function() {
  return gulp.src(['test/*.js'], { read: false })
    .pipe(mocha({ r: 'test/setup.js', timeout: 10000 }));
});

/**
 * Run all unit tests.
 */

gulp.task('test-unit', function(done) {
  var options = {
    config: {
      rootDir: __dirname,
      testPathDirs: [__dirname + '/src'],
      scriptPreprocessor: __dirname + '/node_modules/babel-jest/index.js',
      setupEnvScriptFile: __dirname + '/jest/env.js',
      setupTestFrameworkScriptFile: __dirname + '/jest/setup.js'
    }
  };

  jest.runCLI(options, __dirname, function(success) {
    done();
  });
});

/**
 * Create an archive from `build`.
 */

gulp.task('pack', function() {
  var version = require('./src/manifest.json').version;

  return gulp.src(dest + '/**/*')
    .pipe(zip(version + '-product-hunt.zip'))
    .pipe(gulp.dest('dist'));
});

/**
 * Clean the build folder.
 */

gulp.task('clean', function() {
  [
    dest + '/_locales',
    dest + '/apps',
    dest + '/common',
    dest + '/vendor',
    dest + '/manifest.json'
  ].forEach(function(dir) {
    rimraf.sync(dir)
  });
});

/**
 * Tests.
 */

gulp.task('test', ['test-acceptance', 'test-unit']);

/**
 * Build all.
 */

gulp.task('build', [
  'clean',
  'js',
  'html',
  'locales',
  'manifest',
  'scss',
  'img',
  'vendor'
]);
<|endoftext|>


<commit_before>/*!
 * virtual-dom-component
 * https://github.com/alexmingoia/virtual-dom-component
 *
 * Copyright (c) 2014 Alex Mingoia <talk@alexmingoia.com>
 * Licensed under the BSD license.
 */

'use strict';

var Browserify = require('browserify')
  , clean = require('gulp-clean')
  , gulp = require('gulp')
  , instrument = require('gulp-instrument')
  , jshint = require('gulp-jshint')
  , mochaPhantomJS = require('gulp-mocha-phantomjs')
  , source = require('vinyl-source-stream')
  , stylish = require('jshint-stylish')
  , spawn = require('child_process').spawn;

gulp.task('coverage', ['instrument'], function() {
  process.env.JSCOV=1;

  return spawn('node_modules/gulp-mocha-phantomjs/node_modules/mocha-phantomjs/node_modules/mocha/bin/mocha', [
    'test', '--reporter', 'html-cov'
  ]).stdout
    .pipe(source('coverage.html'))
    .pipe(gulp.dest('./'));
});

gulp.task('instrument', function() {
  return gulp.src('lib/**.js')
    .pipe(instrument())
    .pipe(gulp.dest('lib-cov'));
});

gulp.task('wrap-umd', function() {
  var bundler = new Browserify({
    standalone: 'VirtualComponent'
  });

  bundler.add('./lib/virtual-dom-component.js');
  bundler.ignore('../lib-cov/virtual-dom-component');

  return bundler.bundle()
    .pipe(source('virtual-dom-component.js'))
    .pipe(gulp.dest('dist'));
});

gulp.task('browserify-tests', function() {
  var bundler = new Browserify();

  bundler.add('./test/virtual-dom-component.js');
  bundler.ignore('../lib-cov/virtual-dom-component');

  return bundler.bundle()
    .pipe(source('tests.js'))
    .pipe(gulp.dest('dist'));
});

gulp.task('mocha-phantomjs', ['browserify-tests'], function() {
  return gulp.src('test/virtual-dom-component.html')
    .pipe(mochaPhantomJS({
      mocha: {
        timeout: 6000,
        ignoreLeaks: false,
        ui: 'bdd',
        reporter: 'spec'
      }
    }));
});

gulp.task('test', ['mocha-phantomjs'], function () {
  return gulp.src('dist/tests.js').pipe(clean());
});

gulp.task('jshint', function () {
  return gulp.src(['lib/**/*.js', 'test/**/*.js'])
    .pipe(jshint())
    .pipe(jshint.reporter(stylish));
});

gulp.task('default', ['jshint', 'test']);
<commit_msg>Work-around for Browserify API change.<commit_after>/*!
 * virtual-dom-component
 * https://github.com/alexmingoia/virtual-dom-component
 *
 * Copyright (c) 2014 Alex Mingoia <talk@alexmingoia.com>
 * Licensed under the BSD license.
 */

'use strict';

var Browserify = require('browserify')
  , clean = require('gulp-clean')
  , gulp = require('gulp')
  , instrument = require('gulp-instrument')
  , jshint = require('gulp-jshint')
  , mochaPhantomJS = require('gulp-mocha-phantomjs')
  , source = require('vinyl-source-stream')
  , stylish = require('jshint-stylish')
  , spawn = require('child_process').spawn;

gulp.task('coverage', ['instrument'], function() {
  process.env.JSCOV=1;

  return spawn('node_modules/gulp-mocha-phantomjs/node_modules/mocha-phantomjs/node_modules/mocha/bin/mocha', [
    'test', '--reporter', 'html-cov'
  ]).stdout
    .pipe(source('coverage.html'))
    .pipe(gulp.dest('./'));
});

gulp.task('instrument', function() {
  return gulp.src('lib/**.js')
    .pipe(instrument())
    .pipe(gulp.dest('lib-cov'));
});

gulp.task('wrap-umd', function() {
  var bundler = new Browserify({
    standalone: 'VirtualComponent'
  });

  bundler.add('./lib/virtual-dom-component.js');
  bundler._ignore.push('../lib-cov/virtual-dom-component');

  return bundler.bundle()
    .pipe(source('virtual-dom-component.js'))
    .pipe(gulp.dest('dist'));
});

gulp.task('browserify-tests', function() {
  var bundler = new Browserify();

  bundler.add('./test/virtual-dom-component.js');
  bundler._ignore.push('../lib-cov/virtual-dom-component');

  return bundler.bundle()
    .pipe(source('tests.js'))
    .pipe(gulp.dest('dist'));
});

gulp.task('mocha-phantomjs', ['browserify-tests'], function() {
  return gulp.src('test/virtual-dom-component.html')
    .pipe(mochaPhantomJS({
      mocha: {
        timeout: 6000,
        ignoreLeaks: false,
        ui: 'bdd',
        reporter: 'spec'
      }
    }));
});

gulp.task('test', ['mocha-phantomjs'], function () {
  return gulp.src('dist/tests.js').pipe(clean());
});

gulp.task('jshint', function () {
  return gulp.src(['lib/**/*.js', 'test/**/*.js'])
    .pipe(jshint())
    .pipe(jshint.reporter(stylish));
});

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


<commit_before>"use strict";

var gulp = require("gulp"),
	fs = require("fs"),
	jshint = require("gulp-jshint");

// JSHint
// https://github.com/wearefractal/gulp-jshint
gulp.task("jshint", function () {

	//
	// FIXME
	//
	// gulp.jshint not reading .jshintrc
	// side-effect of JSHint itself not read configuration when using stdin
	//
	// https://github.com/wearefractal/gulp-jshint/issues/4
	//

	var options = JSON.parse(fs.readFileSync(".jshintrc", "utf8"));

	//
	// FIXME
	//
	// Can't use following due to Error: EMFILE, too many open files:
	//
	//	gulp.src("./**/*.js")
	//		.pipe(ignore({
	//			pattern: [
	//				"./node_modules/**",
	//				"./test/temp/**"]}))
	//
	// Must wait for core impl of .src() ignores
	//
	// https://github.com/wearefractal/gulp/issues/35
	//

	gulp.src("./*.js")
		.pipe(jshint(options))
		.pipe(jshint.reporter("default"));

	gulp.src("./test/**/*.js")
		.pipe(jshint(options))
		.pipe(jshint.reporter("default"));
});

// default task
gulp.task("default", function () {
	gulp.run("jshint");
});
<commit_msg>chore(gulp): add watcher<commit_after>"use strict";

var gulp = require("gulp"),
	fs = require("fs"),
	cp = require("child_process"),
	jshint = require("gulp-jshint");

// JSHint
// https://github.com/wearefractal/gulp-jshint
gulp.task("jshint", function () {

	//
	// FIXME
	//
	// gulp.jshint not reading .jshintrc
	// side-effect of JSHint itself not read configuration when using stdin
	//
	// https://github.com/wearefractal/gulp-jshint/issues/4
	//

	var options = JSON.parse(fs.readFileSync(".jshintrc", "utf8"));

	//
	// FIXME
	//
	// Can't use following due to Error: EMFILE, too many open files:
	//
	//	gulp.src("./**/*.js")
	//		.pipe(ignore({
	//			pattern: [
	//				"./node_modules/**",
	//				"./test/temp/**"]}))
	//
	// Must wait for core impl of .src() ignores
	//
	// https://github.com/wearefractal/gulp/issues/35
	//

	gulp.src("./*.js")
		.pipe(jshint(options))
		.pipe(jshint.reporter("default"));

	gulp.src("./test/**/*.js")
		.pipe(jshint(options))
		.pipe(jshint.reporter("default"));
});

// default task
gulp.task("default", function () {
	gulp.run("jshint");

	gulp.watch(["index.js", "./test/**"], function () {
		gulp.run("jshint");
		cp.fork("node_modules/.bin/mocha");
	});

});

<|endoftext|>


<commit_before>const gulp = require('gulp');
const minifycss = require('gulp-minify-css');
const rename = require('gulp-rename');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const livereload = require('gulp-livereload');

const distPath = './';
var minify = false;

gulp.task('js', function() {
  var src = [
    './src/js/ionic.material.motion.js',
    './src/js/ionic.material.ink.js'
  ];
  var js = gulp.src(src)
    .pipe(concat('ionic.material.js'))
    .pipe(gulp.dest(distPath));

  if (minify) {
    js.pipe(uglify())
    .pipe(rename('ionic.material.min.js'))
    .pipe(gulp.dest(distPath))
  }
  return js;
});

gulp.task('styles', function() {
  var src = [
    './src/css/directives/*.css',
    './src/css/elements/*.css',
    './src/css/helpers/*.css',
    './src/css/motion/*.css',
    './src/css/overrides/*.css'
  ];
  var css = gulp.src(src)
    .pipe(concat('ionic.material.css'))
    .pipe(gulp.dest(distPath))

  if (minify) {
    css.pipe(rename({
      suffix: '.min'
    }))
    .pipe(minifycss())
    .pipe(rename('ionic.material.min.css'))
    .pipe(gulp.dest(distPath));
  }

  return css;
});

gulp.task('watch', function() {
  livereload.listen();
  gulp.watch(['./*.js', '!./src/js/'], ['js']);
  gulp.watch('./*.css', ['styles']);
});

gulp.task('build', function () {
  minify = true;
  return gulp.start(['js', 'styles']);
})

gulp.task('default', ['js', 'styles', 'watch'], function() {});
<commit_msg>add jshint options to gulpfile<commit_after>/* jshint esnext: true, asi: true */
const gulp = require('gulp');
const minifycss = require('gulp-minify-css');
const rename = require('gulp-rename');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const livereload = require('gulp-livereload');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');

const distPath = './';
var minify = false;

gulp.task('js', function() {
  var src = [
    './src/js/ionic.material.motion.js',
    './src/js/ionic.material.ink.js'
  ];
  var js = gulp.src(src)
    .pipe(concat('ionic.material.js'))
    .pipe(gulp.dest(distPath));

  if (minify) {
    js.pipe(uglify())
    .pipe(rename('ionic.material.min.js'))
    .pipe(gulp.dest(distPath))
  }
  return js;
});

gulp.task('styles', function() {
  var src = [
    './src/css/directives/*.css',
    './src/css/elements/*.css',
    './src/css/helpers/*.css',
    './src/css/motion/*.css',
    './src/css/overrides/*.css'
  ];
  var css = gulp.src(src)
    .pipe(concat('ionic.material.css'))
    .pipe(gulp.dest(distPath))

  if (minify) {
    css.pipe(rename({
      suffix: '.min'
    }))
    .pipe(minifycss())
    .pipe(rename('ionic.material.min.css'))
    .pipe(gulp.dest(distPath));
  }

  return css;
});

gulp.task('scss', function() {
  var src = './src/scss/index.scss';
  var scss = gulp
  var css = gulp.src(src)
    .pipe(concat('ionic.material.css'))
    .pipe(gulp.dest(distPath))

  if (minify) {
    css.pipe(rename({
      suffix: '.min'
    }))
    .pipe(minifycss())
    .pipe(rename('ionic.material.min.css'))
    .pipe(gulp.dest(distPath));
  }

  return css;
});

gulp.task('watch', function() {
  livereload.listen();
  gulp.watch(['./*.js', '!./src/js/'], ['js']);
  gulp.watch('./*.css', ['styles']);
});

gulp.task('build', function () {
  minify = true;
  return gulp.start(['js', 'styles']);
})

gulp.task('default', ['js', 'styles', 'watch'], function() {});
<|endoftext|>


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

gulp.task('styles', function() {
    gulp.src('css/*.css')
        .pipe(gulp.dest('dist/app.css'));
});

// TODO: I was in the middle of setting up Gulp and Sass, but my machine's NPM doesn't work.
// http://ryanchristiani.com/getting-started-with-gulp-and-sass/
// https://css-tricks.com/gulp-for-beginners/
<commit_msg>Add concat to gulp<commit_after>var gulp = require('gulp');

gulp.task('default', function() {
    gulp.src('css/*.css')
        .pipe(concat('app.min.css'))
        .pipe(gulp.dest('dist/'));
});

// TODO: I was in the middle of setting up Gulp and Sass, but my machine's NPM doesn't work.
// http://ryanchristiani.com/getting-started-with-gulp-and-sass/
// https://css-tricks.com/gulp-for-beginners/
<|endoftext|>


<commit_before>"use strict";
const gulp = require("gulp"),
    sourcemaps = require("gulp-sourcemaps"),
    concat = require("gulp-concat"),
    mergeStream = require('merge-stream'),
    debug = require("gulp-debug"),
    nodemon = require('gulp-nodemon'),
    FileCache = require("gulp-file-cache"),
    sass = require('gulp-sass'),
    fs = require('fs'),
    path = require('path'),
    args = require('yargs').argv,
    plumber = require('gulp-plumber'),
    karmaServer = require('karma').Server,
    mocha = require('gulp-mocha'),
    // ts = require("gulp-typescript"), //todo: using exec until https://github.com/ivogabe/gulp-typescript/issues/460 is resolved
    { exec, spawn } = require('child_process'),
    browserSync = require('browser-sync'),
    intoStream = require('into-stream'),
    tslint = require('tslint'),
    gulpTslint = require('gulp-tslint'),
    gutil = require('gulp-util'),
    runSequence = require('run-sequence');
const { protractor } = require("gulp-protractor");

(function createGulpCacheDir() {
    var dir = path.resolve(__dirname, '.gulp-cache');
    if (!fs.existsSync(dir)) fs.mkdirSync(dir);
})();

gulp.task('watch:front', ['transpile:front'], () => {
    gulp.watch('public/**/*.ts', ['transpile:front']);
    gulp.watch('public/**/*.scss', ['transpile:sass']);
    gulp.watch('public/**/*.html', ['copy:html']);
});

gulp.task('watch:back', ['transpile:back'], () => {
    return gulp.watch(['test/**/*.ts', 'server/**/*.ts'], ['transpile:back']);
});

gulp.task('watch', ['transpile'], () => {
    gulp.watch('public/**/*.ts', ['transpile:front']);
    gulp.watch('public/**/*.scss', ['transpile:sass']);
    gulp.watch('public/**/*.html', ['copy:html']);
    gulp.watch('test/**/*.ts', ['transpile:back']);
    let nodemonOpt = {
        exec: `${process.execPath} --debug --harmony-async-await`,
        script: 'dist/server/bin/www.js',
        ext: 'ts',
        env: {
            'NODE_ENV': 'development',
            DEBUG: '*,-*socket*,-engine*,-koa*,-connect*,-mquery'
        },
        watch: ['server/**/*.ts'],
        tasks: ['transpile:back'],
    };
    var stream = nodemon(nodemonOpt);
    browserSync.init({
        proxy: 'http://localhost:3000',
        files: 'dist/public/**/*',
        browser: 'chrome',
        port: 7000
    });
    stream.on('start', () => {
        browserSync.reload();
    });
    return stream;
});

gulp.task('copy', ['copy:html']);

gulp.task("copy:html", () => {
    var htmlFileCache = new FileCache('.gulp-cache/.gulp-cache-html');
    return gulp.src(["public/**/*.html"])
        .pipe(plumber())
        //.pipe(htmlFileCache.filter())
        //.pipe(htmlFileCache.cache())
        .pipe(debug({ title: 'html' }))
        .pipe(gulp.dest("dist/public"));
});

gulp.task("transpile", ['copy:html'], () => {
    var merged = new mergeStream();
    merged.add(transpileFront(), transpileBack(), transpileSass());
    return merged;
});

gulp.task("transpile:production", ['copy:html'], () => {
    var merged = new mergeStream();
    merged.add(transpileFront({ bail: true, target: 'ES5' }), transpileBack({ bail: true, target: 'ES2015' }), transpileSass({ bail: true }));
    return merged;
});

gulp.task("transpile:front", transpileFront);
gulp.task("transpile:back", transpileBack);
gulp.task("transpile:sass", transpileSass);

gulp.task("autotest", ['transpile:front'], () => {
    gulp.watch('public/**/*.ts', ['transpile:front']);
    gulp.watch(["server/**/*.ts", "test/**/*.ts"], ['transpile:back']);
    gulp.watch(["dist/server/**/*.js", "dist/test/**/*.js"], ['test:back']);
    new karmaServer({
        configFile: path.resolve(__dirname, 'karma.conf.js'),
        singleRun: false
    }).start();
});

gulp.task('test', done => runSequence('transpile', ["test:back:notranspile", "test:front:notranspile", "test:acceptance:notranspile"], done));

gulp.task("test:quick", ["test:back:notranspile", "test:front:notranspile"]);

gulp.task("test:front", ['transpile:front'], testFront);
gulp.task("test:front:notranspile", testFront);

function testFront(done) {
    new karmaServer({
        configFile: path.resolve(__dirname, 'karma.conf.js'),
        singleRun: true
    }, () => done()).start();
};

gulp.task("test:back", ['transpile:back'], testBack);
gulp.task("test:back:notranspile", testBack);

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

gulp.task("test:acceptance", ["transpile"], testAcceptance);

gulp.task("test:acceptance:notranspile", testAcceptance);

gulp.task('run', done => {
    try {
        const node = spawn(process.execPath, ['--debug', '--harmony-async-await', 'dist/server/bin/www.js'], {
            cwd: __dirname,
            env: {
                DEBUG: '*,trans,-*socket*,-engine*,-koa*,-connect*,-mquery',
                NODE_ENV: 'development',
                DEBUG_COLORS: true
            }
        });
        node.stdout.on('data', data => {
            if (typeof (data) === 'string')
                gutil.log(data.toString());
            else
                gutil.log(data.toString('utf8'));
        });
        node.stderr.on('data', data => {
            if (typeof (data) === 'string')
                gutil.log(data.toString());
            else
                gutil.log(data.toString('utf8'));
        });
        node.on('close', code => {
            if (code > 0) {
                const message = `Running the app failed with code ${code}.`;
                gutil.log(message);
                done(message)
            }
        });
    } catch (error) {
        gutil.log(`Error: ${error}`);
        done(error);
    }
});

function testAcceptance(theDone) {
    let doneCalled = false;
    function done() {
        if (!doneCalled) {
            doneCalled = true;
            theDone(...arguments);
        }
    }
    try {
        const node = spawn(process.execPath, ['--debug', '--harmony-async-await', 'dist/server/bin/www.js'], {
            cwd: __dirname,
            env: {
                DEBUG: '*,trans,-*socket*,-engine*,-koa*,-connect*,-mquery',
                NODE_ENV: 'test',
                DEBUG_COLORS: true
            }
        });
        node.stdout.on('data', data => {
            if (typeof (data) === 'string')
                gutil.log(data.toString());
            else
                gutil.log(data.toString('utf8'));
        });
        node.stderr.on('data', data => {
            if (typeof (data) === 'string')
                gutil.log(data.toString());
            else
                gutil.log(data.toString('utf8'));
            if (data.indexOf('Listening on port') >= 0) {
                gulp.src(["./dist/test/**/*.feature.js"])
                    .pipe(protractor({
                        configFile: "dist/test/protractor.config.js",
                    }))
                    .on('error', (error) => {
                        gutil.log(error);
                        node.kill();
                        done(error);
                    })
                    .on('end', () => {
                        gutil.log('Done running tests.');
                        node.kill();
                        done();
                    });
            }
        });
        node.on('close', code => {
            if (code > 0) {
                const message = `Running the app failed with code ${code}.`;
                gutil.log(message);
                done(message)
            }
        });
    } catch (error) {
        gutil.log(`Error: ${error}`);
        done(error);
    }
};

function transpileSass(opt) {
    var sassFileCache = new FileCache('.gulp-cache/.gulp-cache-sass');
    return gulp.src(["public/**/*.scss"])
        .pipe(plumber())
        .pipe(sassFileCache.filter())
        .pipe(opt && opt.bail
            ? sass().on('error', (error) => { throw error; })
            : sass().on('error', sass.logError))
        .pipe(sassFileCache.cache())
        .pipe(debug({ title: 'sass' }))
        .pipe(gulp.dest("dist/public"));
}

// const tsProjectBack = ts.createProject("tsconfig.json");
function transpileBack(opt) {
    //todo: using exec until https://github.com/ivogabe/gulp-typescript/issues/460 is resolved
    const promise = new Promise((resolve, reject) => {
        let resolveCalled = false;
        try {
            exec(`npm run tsc -- --pretty --project ${__dirname} ${opt && opt.target ? '--target ' + opt.target : ''}`, {
                cwd: __dirname,
            }, (err, stdout, stderr) => {
                let info = "";
                if (err)
                    info += err;
                if (stderr)
                    info += stderr;
                if (stdout)
                    info += stdout;
                if (info)
                    gutil.log(info);
                resolveCalled = true;
                if (err && opt && opt.bail)
                    return reject(err);
                resolve("Done.");
            });
        } catch (error) {
            gutil.log(`Error: ${error}`);
            if (!resolveCalled)
                resolve("Done.");
        }
    });
    return intoStream(promise);
    // return tsProjectBack.src()
    //     .pipe(sourcemaps.init())
    //     .pipe(plumber())
    //     .pipe(debug({ title: 'back' }))
    //     .pipe(tsProjectBack()).js
    //     .pipe(sourcemaps.write('.'))
    //     .pipe(debug({ title: 'map' }))
    //     .pipe(gulp.dest("dist"));
}

// const tsProjectFront = ts.createProject("public/tsconfig.json");
function transpileFront(opt) {
    //todo: using exec until https://github.com/ivogabe/gulp-typescript/issues/460 is resolved
    const publicPath = path.resolve(__dirname, 'public');
    const promise = new Promise((resolve, reject) => {
        let resolveCalled = false;
        try {
            exec(`npm run tsc -- --pretty --project ${publicPath} ${opt && opt.target ? ' --target ' + opt.target : ''}`, {
                cwd: publicPath,
            }, (err, stdout, stderr) => {
                let info = "";
                if (err)
                    info += err;
                if (stderr)
                    info += stderr;
                if (stdout)
                    info += stdout;
                if (info)
                    gutil.log(info);
                resolveCalled = true;
                if (err && opt && opt.bail)
                    return reject(err);
                resolve("Done.");
            });
        } catch (error) {
            gutil.log(`Error: ${error}`);
            if (!resolveCalled)
                resolve("Done.");
        }
    });
    return intoStream(promise);
    // return tsProjectFront.src()
    //     .pipe(sourcemaps.init())
    //     .pipe(plumber())
    //     .pipe(debug({ title: 'front' }))
    //     .pipe(tsProjectFront()).js
    //     .pipe(sourcemaps.write('.'))
    //     .pipe(gulp.dest("dist/public"));
};

gulp.task('lint', ['lint:back', 'lint:front']);

gulp.task('lint:back', () => {
    return gulp.src(['server/**/*.ts', 'test/**/*.ts'], { base: '.' })
        .pipe(debug({ title: 'lint-back' }))
        .pipe(gulpTslint({ program: tslint.Linter.createProgram("./tsconfig.json"), configuration: './tslint.json' }))
        .pipe(gulpTslint.report());
});

gulp.task('lint:front', () => {
    return gulp.src(['public/**/*.ts'], { base: '.' })
        .pipe(debug({ title: 'lint-front' }))
        .pipe(gulpTslint({ program: tslint.Linter.createProgram("public/tsconfig.json"), configuration: 'public/tslint.json' }))
        .pipe(gulpTslint.report());
});

gulp.task('ci:quick', done => runSequence('ci-build', 'ci-test:quick', done));
gulp.task('ci:slow', ['ci-test:slow']);
gulp.task('ci-build', ['lint', 'transpile:production']);
gulp.task('ci-test:quick', ['test:quick']);
gulp.task('ci-test:slow', ['test:acceptance:notranspile']);

gulp.task("default", ['transpile']);<commit_msg>Copy pug files when releasing<commit_after>"use strict";
const gulp = require("gulp"),
    sourcemaps = require("gulp-sourcemaps"),
    concat = require("gulp-concat"),
    mergeStream = require('merge-stream'),
    debug = require("gulp-debug"),
    nodemon = require('gulp-nodemon'),
    FileCache = require("gulp-file-cache"),
    sass = require('gulp-sass'),
    fs = require('fs'),
    path = require('path'),
    args = require('yargs').argv,
    plumber = require('gulp-plumber'),
    karmaServer = require('karma').Server,
    mocha = require('gulp-mocha'),
    // ts = require("gulp-typescript"), //todo: using exec until https://github.com/ivogabe/gulp-typescript/issues/460 is resolved
    { exec, spawn } = require('child_process'),
    browserSync = require('browser-sync'),
    intoStream = require('into-stream'),
    tslint = require('tslint'),
    gulpTslint = require('gulp-tslint'),
    gutil = require('gulp-util'),
    runSequence = require('run-sequence');
const { protractor } = require("gulp-protractor");

(function createGulpCacheDir() {
    var dir = path.resolve(__dirname, '.gulp-cache');
    if (!fs.existsSync(dir)) fs.mkdirSync(dir);
})();

gulp.task('watch:front', ['transpile:front'], () => {
    gulp.watch('public/**/*.ts', ['transpile:front']);
    gulp.watch('public/**/*.scss', ['transpile:sass']);
    gulp.watch('public/**/*.html', ['copy:html']);
});

gulp.task('watch:back', ['transpile:back'], () => {
    return gulp.watch(['test/**/*.ts', 'server/**/*.ts'], ['transpile:back']);
});

gulp.task('watch', ['transpile'], () => {
    gulp.watch('public/**/*.ts', ['transpile:front']);
    gulp.watch('public/**/*.scss', ['transpile:sass']);
    gulp.watch('public/**/*.html', ['copy:html']);
    gulp.watch('server/**/*.pug', ['copy:pug']);
    gulp.watch('test/**/*.ts', ['transpile:back']);
    let nodemonOpt = {
        exec: `${process.execPath} --debug --harmony-async-await`,
        script: 'dist/server/bin/www.js',
        ext: 'ts',
        env: {
            'NODE_ENV': 'development',
            DEBUG: '*,-*socket*,-engine*,-koa*,-connect*,-mquery'
        },
        watch: ['server/**/*.ts'],
        tasks: ['transpile:back'],
    };
    var stream = nodemon(nodemonOpt);
    browserSync.init({
        proxy: 'http://localhost:3000',
        files: 'dist/public/**/*',
        browser: 'chrome',
        port: 7000
    });
    stream.on('start', () => {
        browserSync.reload();
    });
    return stream;
});

gulp.task('copy', ['copy:html', 'copy:pug']);

gulp.task("copy:html", () => {
    var htmlFileCache = new FileCache('.gulp-cache/.gulp-cache-html');
    return gulp.src(["public/**/*.html"])
        .pipe(plumber())
        .pipe(htmlFileCache.filter())
        .pipe(htmlFileCache.cache())
        .pipe(debug({ title: 'html' }))
        .pipe(gulp.dest("dist/public"));
});

gulp.task("copy:pug", () => {
    var pugFileCache = new FileCache('.gulp-cache/.gulp-cache-pug');
    return gulp.src(["server/**/*.pug"])
        .pipe(plumber())
        .pipe(pugFileCache.filter())
        .pipe(pugFileCache.cache())
        .pipe(debug({ title: 'pug' }))
        .pipe(gulp.dest("dist/server"));
});

gulp.task("transpile", ['copy'], () => {
    var merged = new mergeStream();
    merged.add(transpileFront(), transpileBack(), transpileSass());
    return merged;
});

gulp.task("transpile:production", ['copy'], () => {
    var merged = new mergeStream();
    merged.add(transpileFront({ bail: true, target: 'ES5' }), transpileBack({ bail: true, target: 'ES2015' }), transpileSass({ bail: true }));
    return merged;
});

gulp.task("transpile:front", transpileFront);
gulp.task("transpile:back", transpileBack);
gulp.task("transpile:sass", transpileSass);

gulp.task("autotest", ['transpile:front'], () => {
    gulp.watch('public/**/*.ts', ['transpile:front']);
    gulp.watch(["server/**/*.ts", "test/**/*.ts"], ['transpile:back']);
    gulp.watch(["dist/server/**/*.js", "dist/test/**/*.js"], ['test:back']);
    new karmaServer({
        configFile: path.resolve(__dirname, 'karma.conf.js'),
        singleRun: false
    }).start();
});

gulp.task('test', done => runSequence('transpile', ["test:back:notranspile", "test:front:notranspile", "test:acceptance:notranspile"], done));

gulp.task("test:quick", ["test:back:notranspile", "test:front:notranspile"]);

gulp.task("test:front", ['transpile:front'], testFront);
gulp.task("test:front:notranspile", testFront);

function testFront(done) {
    new karmaServer({
        configFile: path.resolve(__dirname, 'karma.conf.js'),
        singleRun: true
    }, () => done()).start();
};

gulp.task("test:back", ['transpile:back'], testBack);
gulp.task("test:back:notranspile", testBack);

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

gulp.task("test:acceptance", ["transpile"], testAcceptance);

gulp.task("test:acceptance:notranspile", testAcceptance);

gulp.task('run', done => {
    try {
        const node = spawn(process.execPath, ['--debug', '--harmony-async-await', 'dist/server/bin/www.js'], {
            cwd: __dirname,
            env: {
                DEBUG: '*,trans,-*socket*,-engine*,-koa*,-connect*,-mquery',
                NODE_ENV: 'development',
                DEBUG_COLORS: true
            }
        });
        node.stdout.on('data', data => {
            if (typeof (data) === 'string')
                gutil.log(data.toString());
            else
                gutil.log(data.toString('utf8'));
        });
        node.stderr.on('data', data => {
            if (typeof (data) === 'string')
                gutil.log(data.toString());
            else
                gutil.log(data.toString('utf8'));
        });
        node.on('close', code => {
            if (code > 0) {
                const message = `Running the app failed with code ${code}.`;
                gutil.log(message);
                done(message)
            }
        });
    } catch (error) {
        gutil.log(`Error: ${error}`);
        done(error);
    }
});

function testAcceptance(theDone) {
    let doneCalled = false;
    function done() {
        if (!doneCalled) {
            doneCalled = true;
            theDone(...arguments);
        }
    }
    try {
        const node = spawn(process.execPath, ['--debug', '--harmony-async-await', 'dist/server/bin/www.js'], {
            cwd: __dirname,
            env: {
                DEBUG: '*,trans,-*socket*,-engine*,-koa*,-connect*,-mquery',
                NODE_ENV: 'test',
                DEBUG_COLORS: true
            }
        });
        node.stdout.on('data', data => {
            if (typeof (data) === 'string')
                gutil.log(data.toString());
            else
                gutil.log(data.toString('utf8'));
        });
        node.stderr.on('data', data => {
            if (typeof (data) === 'string')
                gutil.log(data.toString());
            else
                gutil.log(data.toString('utf8'));
            if (data.indexOf('Listening on port') >= 0) {
                gulp.src(["./dist/test/**/*.feature.js"])
                    .pipe(protractor({
                        configFile: "dist/test/protractor.config.js",
                    }))
                    .on('error', (error) => {
                        gutil.log(error);
                        node.kill();
                        done(error);
                    })
                    .on('end', () => {
                        gutil.log('Done running tests.');
                        node.kill();
                        done();
                    });
            }
        });
        node.on('close', code => {
            if (code > 0) {
                const message = `Running the app failed with code ${code}.`;
                gutil.log(message);
                done(message)
            }
        });
    } catch (error) {
        gutil.log(`Error: ${error}`);
        done(error);
    }
};

function transpileSass(opt) {
    var sassFileCache = new FileCache('.gulp-cache/.gulp-cache-sass');
    return gulp.src(["public/**/*.scss"])
        .pipe(plumber())
        .pipe(sassFileCache.filter())
        .pipe(opt && opt.bail
            ? sass().on('error', (error) => { throw error; })
            : sass().on('error', sass.logError))
        .pipe(sassFileCache.cache())
        .pipe(debug({ title: 'sass' }))
        .pipe(gulp.dest("dist/public"));
}

// const tsProjectBack = ts.createProject("tsconfig.json");
function transpileBack(opt) {
    //todo: using exec until https://github.com/ivogabe/gulp-typescript/issues/460 is resolved
    const promise = new Promise((resolve, reject) => {
        let resolveCalled = false;
        try {
            exec(`npm run tsc -- --pretty --project ${__dirname} ${opt && opt.target ? '--target ' + opt.target : ''}`, {
                cwd: __dirname,
            }, (err, stdout, stderr) => {
                let info = "";
                if (err)
                    info += err;
                if (stderr)
                    info += stderr;
                if (stdout)
                    info += stdout;
                if (info)
                    gutil.log(info);
                resolveCalled = true;
                if (err && opt && opt.bail)
                    return reject(err);
                resolve("Done.");
            });
        } catch (error) {
            gutil.log(`Error: ${error}`);
            if (!resolveCalled)
                resolve("Done.");
        }
    });
    return intoStream(promise);
    // return tsProjectBack.src()
    //     .pipe(sourcemaps.init())
    //     .pipe(plumber())
    //     .pipe(debug({ title: 'back' }))
    //     .pipe(tsProjectBack()).js
    //     .pipe(sourcemaps.write('.'))
    //     .pipe(debug({ title: 'map' }))
    //     .pipe(gulp.dest("dist"));
}

// const tsProjectFront = ts.createProject("public/tsconfig.json");
function transpileFront(opt) {
    //todo: using exec until https://github.com/ivogabe/gulp-typescript/issues/460 is resolved
    const publicPath = path.resolve(__dirname, 'public');
    const promise = new Promise((resolve, reject) => {
        let resolveCalled = false;
        try {
            exec(`npm run tsc -- --pretty --project ${publicPath} ${opt && opt.target ? ' --target ' + opt.target : ''}`, {
                cwd: publicPath,
            }, (err, stdout, stderr) => {
                let info = "";
                if (err)
                    info += err;
                if (stderr)
                    info += stderr;
                if (stdout)
                    info += stdout;
                if (info)
                    gutil.log(info);
                resolveCalled = true;
                if (err && opt && opt.bail)
                    return reject(err);
                resolve("Done.");
            });
        } catch (error) {
            gutil.log(`Error: ${error}`);
            if (!resolveCalled)
                resolve("Done.");
        }
    });
    return intoStream(promise);
    // return tsProjectFront.src()
    //     .pipe(sourcemaps.init())
    //     .pipe(plumber())
    //     .pipe(debug({ title: 'front' }))
    //     .pipe(tsProjectFront()).js
    //     .pipe(sourcemaps.write('.'))
    //     .pipe(gulp.dest("dist/public"));
};

gulp.task('lint', ['lint:back', 'lint:front']);

gulp.task('lint:back', () => {
    return gulp.src(['server/**/*.ts', 'test/**/*.ts'], { base: '.' })
        .pipe(debug({ title: 'lint-back' }))
        .pipe(gulpTslint({ program: tslint.Linter.createProgram("./tsconfig.json"), configuration: './tslint.json' }))
        .pipe(gulpTslint.report());
});

gulp.task('lint:front', () => {
    return gulp.src(['public/**/*.ts'], { base: '.' })
        .pipe(debug({ title: 'lint-front' }))
        .pipe(gulpTslint({ program: tslint.Linter.createProgram("public/tsconfig.json"), configuration: 'public/tslint.json' }))
        .pipe(gulpTslint.report());
});

gulp.task('ci:quick', done => runSequence('ci-build', 'ci-test:quick', done));
gulp.task('ci:slow', ['ci-test:slow']);
gulp.task('ci-build', ['lint', 'transpile:production']);
gulp.task('ci-test:quick', ['test:quick']);
gulp.task('ci-test:slow', ['test:acceptance:notranspile']);

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


<commit_before>// gulp libs
var gulp = require('gulp');
var release = require('gulp-github-release');
var gutil = require('gulp-util');
var exec = require('child_process').exec;

var TAG_ERR_TEXT = 'Unable to resolve GIT TAG from environment variable GIT_LATEST_TAG';

gulp.task('release', function (callback) {
	var latestTag = process.env.GIT_LATEST_TAG;
	if (latestTag)
	{
		gutil.log('Using release tag: ' + latestTag);
		return gulp.src('./dist/deploy.zip')
			.pipe(release({
				tag: latestTag,
				name: 'publish release ' + latestTag,     // if missing, it will be the same as the tag
				notes: 'very good!',                // if missing it will be left undefined
				draft: false,                       // if missing it's false
				prerelease: false,                  // if missing it's false
				manifest: require('./package.json') // package.json from which default values will be extracted if they're missing
			}).on('error', function () {
				throw new gutil.PluginError({
					plugin: 'gulp release',
					message: 'Failed to make a release!'
				});
			}));
	}
	else
	{
		callback(TAG_ERR_TEXT);
	}
});

gulp.task('default', function () {});
<commit_msg>test with 'end'event<commit_after>// gulp libs
var gulp = require('gulp');
var release = require('gulp-github-release');
var gutil = require('gulp-util');
var exec = require('child_process').exec;

var TAG_ERR_TEXT = 'Unable to resolve GIT TAG from environment variable GIT_LATEST_TAG';

gulp.task('release', function (callback) {
	var latestTag = process.env.GIT_LATEST_TAG;
	if (latestTag)
	{
		gutil.log('Using release tag: ' + latestTag);
		return gulp.src('./dist/deploy.zip')
			.pipe(release({
				tag: latestTag,
				name: 'publish release ' + latestTag,     // if missing, it will be the same as the tag
				notes: 'very good!',                // if missing it will be left undefined
				draft: false,                       // if missing it's false
				prerelease: false,                  // if missing it's false
				manifest: require('./package.json') // package.json from which default values will be extracted if they're missing
			}).on('end', function () {
				throw new gutil.PluginError({
					plugin: 'gulp release',
					message: 'Failed to make a release!'
				});
			}));
	}
	else
	{
		callback(TAG_ERR_TEXT);
	}
});

gulp.task('default', function () {});
<|endoftext|>


<commit_before>var _ = require('lodash');
var express = require('express');
var fs = require('fs');
var gulp = require('gulp');
var lr = require('tiny-lr');
var path = require('path');

var browserify = require('gulp-browserify');
var concat = require('gulp-concat');
var gulpif = require('gulp-if');
var gzip = require('gulp-gzip');
var haml = require('gulp-haml');
var imagemin = require('gulp-imagemin');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var refresh = require('gulp-livereload');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var stylus = require('gulp-stylus');

var server = lr();
var config = _.extend({
  port: 8080,
  lrport: 35729,
  env: 'development'
}, gulp.env);
console.log(config);
var production = config.env === 'production';

function exec(cmd) {
  var child = require('child_process').spawn('bash', ['-c', cmd]);

  child.stderr.on('data', function(data) {
    console.log('stderr:' + data);
  });

  child.stdout.on('data', function(data) {
    console.log(data.toString());
  });
}

gulp.task('clean', function() {
  exec('rm -rf out');
  exec('rm src/js/lib/fs/usr/bin/*');
});

gulp.task('lr-server', function () {
  server.listen(config.lrport, function (err) {
    if (err) {
      console.log(err);
    }
  });
});

gulp.task('commands', function () {
  if (production) {
    gulp.run('clean', _commands);
  } else {
    _commands();
  }

  function _commands() {
    var commands = fs.readdirSync('src/js/lib/commands')
    .filter(function (f) {
      return f[0] != '.' && f.substr(-3) == '.js';
    }).map(function (f) {
      if (production) {
        exec('ln -fh ' + __dirname + '/src/js/lib/commands/' + f + ' src/js/lib/fs/usr/bin/' + f.slice(0, -3));
      }

      return 'require("' + './commands/' + f + '");';
    });

    fs.writeFileSync('src/js/lib/commands.js', commands.join('\n'));
  }
});

gulp.task('file-system', function () {
  var _fs = {};
  var _ignore = [
    '\\.DS_Store',
    '.*\\.swp'
  ];
  var root = 'src/js/lib/fs';

  (function readdir(path, container) {
    var files = fs.readdirSync(path);

    files.forEach(function (file) {
      for (var i = 0, l = _ignore.length; i < l; i++) {
        if (file.match(new RegExp('^' + _ignore[i] + '$'))) {
          return;
        }
      }

      var stat = fs.statSync(path + '/' + file);

      if (stat.isDirectory()) {
        var f = {};
        readdir(path + '/' + file, f);
        container[file] = f;
      } else {
        container[file] = fs.readFileSync(path + '/' + file).toString();
      }
    });
  })(root, _fs);

  fs.writeFileSync('src/js/lib/file-system.json', JSON.stringify(_fs, null, 2));
});

gulp.task('jshint', function() {
  gulp.src(['Gulpfile.js', 'spec/**/*.js', 'src/js/**/*.js'])
  .pipe(jshint())
  .pipe(jshint.reporter('jshint-stylish'));
});

gulp.task('js', ['jshint', 'commands', 'file-system'], function () {
  var src = config.site ? 'src/js/site.js' : 'src/js/main.js';

  gulp.src(src)
  .pipe(browserify({ debug: !production }))
  .pipe(concat('all.js'))
  .pipe(gulpif(production, uglify()))
  .pipe(gulp.dest('out/js'))
  .pipe(gulpif(production, gzip()))
  .pipe(gulpif(production, gulp.dest('out/js')))
  .pipe(refresh(server));
});

gulp.task('css', function () {
  gulp.src('src/css/**/*.styl')
  .pipe(stylus({ set: production ? ['compress'] : [] }))
  .pipe(concat('all.css'))
  .pipe(gulp.dest('out/css'))
  .pipe(gulpif(production, gzip()))
  .pipe(gulp.dest('out/css'))
  .pipe(refresh(server));
});

gulp.task('images', function () {
  gulp.src('src/images/**')
  .pipe(gulpif(production, imagemin()))
  .pipe(gulp.dest('out/images'))
  .pipe(refresh(server));
});

gulp.task('html', function () {
  gulp.src('src/**/*.haml')
  .pipe(haml({ optimize: production }))
  .pipe(gulp.dest('out'))
  .pipe(gulpif(production, gzip()))
  .pipe(gulp.dest('out'))
  .pipe(refresh(server));
});

gulp.task('start-server', function() {
  express()
  .use(express.static(path.resolve("./out")))
  .use(express.directory(path.resolve("./out")))
  .listen(config.port, function() {
    console.log("Listening on ", config.port);
  });
});

gulp.task('spec', ['js'], function () {
  gulp.src('spec/**/*-spec.js')
  .pipe(mocha());
});

gulp.task('build', ['js', 'css', 'images', 'html']);

gulp.task('server', ['build', 'lr-server', 'start-server'], function () {
  gulp.watch(['src/js/**/*.js', 'src/js/lib/fs/**'], function () {
    gulp.run('js');
  });

  gulp.watch('src/css/**/*.styl', function () {
    gulp.run('css');
  });

  gulp.watch('src/images/**', function () {
    gulp.run('images');
  });

  gulp.watch('src/**/*.haml', function () {
    gulp.run('html');
  });
});

gulp.task('spec-live', function(){
  gulp.watch('src/js/**/*.js', function () {
    gulp.run('js');
  });

  gulp.watch('spec/**/*.js', function(){
    gulp.run('spec');
  });
});

gulp.task('deploy', function () {
  config.site = true;
  production = true;
  config.env = 'production';

  gulp.run('build', function () {
    setTimeout(function() {
      fs.writeFileSync('out/CNAME', 'tadeuzagallo.com');
      exec('cd out && git init && git add -A . && git c -m "deploy" && git push --force git@github.com:tadeuzagallo/tadeuzagallo.github.io.git master');
    }, 5000);
  });
});
<commit_msg>fix: spec-live<commit_after>var _ = require('lodash');
var express = require('express');
var fs = require('fs');
var gulp = require('gulp');
var lr = require('tiny-lr');
var path = require('path');

var browserify = require('gulp-browserify');
var concat = require('gulp-concat');
var gulpif = require('gulp-if');
var gzip = require('gulp-gzip');
var haml = require('gulp-haml');
var imagemin = require('gulp-imagemin');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var refresh = require('gulp-livereload');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var stylus = require('gulp-stylus');

var server = lr();
var config = _.extend({
  port: 8080,
  lrport: 35729,
  env: 'development'
}, gulp.env);
console.log(config);
var production = config.env === 'production';

function exec(cmd) {
  var child = require('child_process').spawn('bash', ['-c', cmd]);

  child.stderr.on('data', function(data) {
    console.log('stderr:' + data);
  });

  child.stdout.on('data', function(data) {
    console.log(data.toString());
  });
}

gulp.task('clean', function() {
  exec('rm -rf out');
  exec('rm src/js/lib/fs/usr/bin/*');
});

gulp.task('lr-server', function () {
  server.listen(config.lrport, function (err) {
    if (err) {
      console.log(err);
    }
  });
});

gulp.task('commands', function () {
  if (production) {
    gulp.run('clean', _commands);
  } else {
    _commands();
  }

  function _commands() {
    var commands = fs.readdirSync('src/js/lib/commands')
    .filter(function (f) {
      return f[0] != '.' && f.substr(-3) == '.js';
    }).map(function (f) {
      if (production) {
        exec('ln -fh ' + __dirname + '/src/js/lib/commands/' + f + ' src/js/lib/fs/usr/bin/' + f.slice(0, -3));
      }

      return 'require("' + './commands/' + f + '");';
    });

    fs.writeFileSync('src/js/lib/commands.js', commands.join('\n'));
  }
});

gulp.task('file-system', function () {
  var _fs = {};
  var _ignore = [
    '\\.DS_Store',
    '.*\\.swp'
  ];
  var root = 'src/js/lib/fs';

  (function readdir(path, container) {
    var files = fs.readdirSync(path);

    files.forEach(function (file) {
      for (var i = 0, l = _ignore.length; i < l; i++) {
        if (file.match(new RegExp('^' + _ignore[i] + '$'))) {
          return;
        }
      }

      var stat = fs.statSync(path + '/' + file);

      if (stat.isDirectory()) {
        var f = {};
        readdir(path + '/' + file, f);
        container[file] = f;
      } else {
        container[file] = fs.readFileSync(path + '/' + file).toString();
      }
    });
  })(root, _fs);

  fs.writeFileSync('src/js/lib/file-system.json', JSON.stringify(_fs, null, 2));
});

gulp.task('jshint', function() {
  gulp.src(['Gulpfile.js', 'spec/**/*.js', 'src/js/**/*.js'])
  .pipe(jshint())
  .pipe(jshint.reporter('jshint-stylish'));
});

gulp.task('js', ['jshint', 'commands', 'file-system'], function () {
  var src = config.site ? 'src/js/site.js' : 'src/js/main.js';

  gulp.src(src)
  .pipe(browserify({ debug: !production }))
  .pipe(concat('all.js'))
  .pipe(gulpif(production, uglify()))
  .pipe(gulp.dest('out/js'))
  .pipe(gulpif(production, gzip()))
  .pipe(gulpif(production, gulp.dest('out/js')))
  .pipe(refresh(server));
});

gulp.task('css', function () {
  gulp.src('src/css/**/*.styl')
  .pipe(stylus({ set: production ? ['compress'] : [] }))
  .pipe(concat('all.css'))
  .pipe(gulp.dest('out/css'))
  .pipe(gulpif(production, gzip()))
  .pipe(gulp.dest('out/css'))
  .pipe(refresh(server));
});

gulp.task('images', function () {
  gulp.src('src/images/**')
  .pipe(gulpif(production, imagemin()))
  .pipe(gulp.dest('out/images'))
  .pipe(refresh(server));
});

gulp.task('html', function () {
  gulp.src('src/**/*.haml')
  .pipe(haml({ optimize: production }))
  .pipe(gulp.dest('out'))
  .pipe(gulpif(production, gzip()))
  .pipe(gulp.dest('out'))
  .pipe(refresh(server));
});

gulp.task('start-server', function() {
  express()
  .use(express.static(path.resolve("./out")))
  .use(express.directory(path.resolve("./out")))
  .listen(config.port, function() {
    console.log("Listening on ", config.port);
  });
});

gulp.task('spec', ['js'], function () {
  gulp.src('spec/**/*-spec.js')
  .pipe(mocha());
});

gulp.task('build', ['js', 'css', 'images', 'html']);

gulp.task('server', ['build', 'lr-server', 'start-server'], function () {
  gulp.watch(['src/js/**/*.js', 'src/js/lib/fs/**'], function () {
    gulp.run('js');
  });

  gulp.watch('src/css/**/*.styl', function () {
    gulp.run('css');
  });

  gulp.watch('src/images/**', function () {
    gulp.run('images');
  });

  gulp.watch('src/**/*.haml', function () {
    gulp.run('html');
  });
});

gulp.task('spec-live', ['spec'], function(){
  gulp.watch('src/js/**/*.js', function () {
    gulp.run('js', 'spec');
  });

  gulp.watch('spec/**/*.js', function(){
    gulp.run('spec');
  });
});

gulp.task('deploy', function () {
  config.site = true;
  production = true;
  config.env = 'production';

  gulp.run('build', function () {
    setTimeout(function() {
      fs.writeFileSync('out/CNAME', 'tadeuzagallo.com');
      exec('cd out && git init && git add -A . && git c -m "deploy" && git push --force git@github.com:tadeuzagallo/tadeuzagallo.github.io.git master');
    }, 5000);
  });
});
<|endoftext|>


<commit_before>/**
 * Created by xubt on 4/30/16.
 */
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var ngmin = require('gulp-ngmin');
var ngAnnotate = require('gulp-ng-annotate');
var lib = require('bower-files')({
    overrides: {
        'x-editable': {
            main: './dist/bootstrap3-editable/js/bootstrap-editable.js',
            dependencies: {
                "jquery": ">=1.6"
            }
        }
    }
});

var cleanCSS = require('gulp-clean-css');

// 语法检查
gulp.task('jshint', function () {
    return gulp.src(['kanban/**/*.js', '!kanban/static/**/*.js'])
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

// 合并压缩第三方类库
gulp.task('minify-bower-components', function () {
    gulp.src(lib.ext('js').files)
        .pipe(concat('lib.min.js'))
        .pipe(gulp.dest('kanban/static/js/'));
});

// 合并CSS
gulp.task('minify-css', function () {
    return gulp.src(['kanban/**/*.css', '!kanban/static/**/*.css'])
        .pipe(concat('thiki-kanban.min.css'))
        .pipe(cleanCSS({compatibility: 'ie8'}))
        .pipe(gulp.dest('kanban/static/css'));
});
// 合并文件之后压缩代码
gulp.task('minify', function () {
    return gulp.src([
        'kanban/*.js', 'kanban/**/*.js', '!kanban/static/**/*.js'])
        .pipe(ngAnnotate())
        .pipe(ngmin({dynamic: false}))
        .pipe(concat('thiki-kanban.js'))
        .pipe(gulp.dest('kanban/static/js'))
        .pipe(uglify())
        .pipe(rename('thiki-kanban.min.js'))
        .pipe(gulp.dest('kanban/static/js'));
});

// 监视文件的变化
gulp.task('watch', function () {
    gulp.watch(['kanban/*.js', 'kanban/**/*.js', 'kanban/styles/*.css', 'kanban/**/*.css', 'gulpfile.js', '!kanban/static/**/*.js', '!kanban/static/**/*.css'], ['jshint', 'minify', 'minify-css']);
});

// 注册缺省任务
gulp.task('default', ['jshint', 'minify-bower-components', 'minify', 'minify-css', 'watch']);
<commit_msg>removing empty line.<commit_after>/**
 * Created by xubt on 4/30/16.
 */
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var ngmin = require('gulp-ngmin');
var ngAnnotate = require('gulp-ng-annotate');
var lib = require('bower-files')({
    overrides: {
        'x-editable': {
            main: './dist/bootstrap3-editable/js/bootstrap-editable.js',
            dependencies: {
                "jquery": ">=1.6"
            }
        }
    }
});

var cleanCSS = require('gulp-clean-css');

// 语法检查
gulp.task('jshint', function () {
    return gulp.src(['kanban/**/*.js', '!kanban/static/**/*.js', '!kanban/**/util/*.js'])
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

// 合并压缩第三方类库
gulp.task('minify-bower-components', function () {
    gulp.src(lib.ext('js').files)
        .pipe(concat('lib.min.js'))
        .pipe(gulp.dest('kanban/static/js/'));
});

// 合并CSS
gulp.task('minify-css', function () {
    return gulp.src(['kanban/**/*.css', '!kanban/static/**/*.css'])
        .pipe(concat('thiki-kanban.min.css'))
        .pipe(cleanCSS({compatibility: 'ie8'}))
        .pipe(gulp.dest('kanban/static/css'));
});
// 合并文件之后压缩代码
gulp.task('minify', function () {
    return gulp.src([
        'kanban/*.js', 'kanban/**/*.js', '!kanban/static/**/*.js'])
        .pipe(ngAnnotate())
        .pipe(ngmin({dynamic: false}))
        .pipe(concat('thiki-kanban.js'))
        .pipe(gulp.dest('kanban/static/js'))
        .pipe(uglify())
        .pipe(rename('thiki-kanban.min.js'))
        .pipe(gulp.dest('kanban/static/js'));
});

// 监视文件的变化
gulp.task('watch', function () {
    gulp.watch(['kanban/*.js', 'kanban/**/*.js', 'kanban/styles/*.css', 'kanban/**/*.css', 'gulpfile.js', '!kanban/static/**/*.js', '!kanban/static/**/*.css'], ['jshint', 'minify', 'minify-css']);
});

// 注册缺省任务
gulp.task('default', ['jshint', 'minify-bower-components', 'minify', 'minify-css', 'watch']);
<|endoftext|>


<commit_before>'use strict';

var gulp = require('gulp'),
    sass = require('gulp-sass'),
    rename = require('gulp-rename'),
    cssnano = require('gulp-cssnano'),
    kss = require('kss'),
    sassLint = require('gulp-sass-lint'),
    autoprefixer = require('gulp-autoprefixer'),
    gitVersion = require('gulp-gitversion'),
    scssMerge = require('./lib/gulp-scss-merge.js'),
    uglify = require('gulp-uglify'),
    del = require('del'),
    runSequence = require('run-sequence'),
    connect = require('gulp-connect'),
    svg2png = require('gulp-svg2png'),
    webpack = require('webpack-stream'),
    zip = require('gulp-zip'),
    wrap = require('gulp-wrap'),
    imagemin = require('gulp-imagemin'),
    handlebars = require('gulp-compile-handlebars')
    ;

var paths = {
    assets: './assets/**/*.*',
    assetsDir: './assets',
    scssDir: './assets/sass/**/*.scss',
    scssTemplatesDir: './assets/sass/templates',
    kssScssDir: './kss-builder/kss-assets/*.scss',
    kssCssDir: './kss-builder/kss-assets',
    examples: './examples/*.hbs',
    examplePartialsDir: './examples/partials',
    kssBuilderDir: './kss-builder/**/*.*',
    images: './assets/img/**/*.+(png|svg|jpg)',
    scss: './assets/sass/ui-kit.scss',
    js: './assets/js/ui-kit.js',
    markdown: './*.md',
    readme: './README.md',
    outputAssets: './build/latest',
    outputCSS: './build/latest/*.css',
    outputHTML: './build'
};

var options = {
    autoprefixer: {
        browsers: ['last 2 versions', 'ie 8-10']
    },
    sass: {
        functions: {
            'image-url($img)': function(img) {
              var sass = require('node-sass');
              var String = sass.types.String;
              return new String('/latest/img/' + img.getValue());
            }
        },
        includePaths: [
          './node_modules'
        ]
    },
    webpack: {
        output: {
            filename: 'ui-kit.js',
        }
    },
    handlebars: {
      batch: [ paths.scssTemplatesDir, paths.examplePartialsDir ]
    }
};

gulp.task('lint', function () {
    return gulp.src([paths.scssDir, paths.kssScssDir, '!./assets/sass/vendor/**/*.scss'])
        .pipe(sassLint({
            configFile: '.sass-lint.yml'
        }))
        .pipe(sassLint.format())
        .pipe(sassLint.failOnError());
});

gulp.task('ui-kit', function () {
    gulp.start(['ui-kit.scss', 'ui-kit.js']);
});

gulp.task('ui-kit.scss', function () {
    return gulp.src(paths.scss)
        .pipe(sass(options.sass).on('error', sass.logError))
        .pipe(autoprefixer(options.autoprefixer))
        .pipe(gitVersion())
        .pipe(gulp.dest(paths.outputAssets));
});

gulp.task('ui-kit.js', function () {
    return gulp.src(paths.js)
        .pipe(webpack(options.webpack))
        .pipe(gitVersion())
        .pipe(gulp.dest(paths.outputAssets));
});

gulp.task('ui-kit.scssmerge', function () {
    return gulp.src(paths.scss)
        .pipe(scssMerge('_ui-kit.scss'))
        .pipe(gulp.dest(paths.outputAssets));
});

gulp.task('ui-kit.min', function () {
    gulp.start(['ui-kit.min.scss', 'ui-kit.min.js']);
});

gulp.task('ui-kit.min.scss', ['ui-kit.scss'], function () {
    return gulp.src([paths.outputCSS, '!./**/*.min.css'])
        .pipe(cssnano())
        .pipe(gitVersion())
        .pipe(rename({
            suffix: '.min'
        }))
        .pipe(gulp.dest(paths.outputAssets));
});

gulp.task('ui-kit.min.js', function () {
    return gulp.src(paths.js)
        .pipe(webpack({
            output: {
                filename: 'ui-kit.min.js',
            }
        }))
        .pipe(uglify())
        .pipe(gitVersion())
        .pipe(gulp.dest(paths.outputAssets));
});
gulp.task('ui-kit.img', ['svg2png'], function () {
    return gulp.src(paths.images)
        .pipe(imagemin())
        .pipe(gulp.dest(paths.outputAssets + '/img/'));
});

gulp.task('ui-kit.img.zip', ['ui-kit.img'], function () {
    return gulp.src(paths.outputAssets + '/img/**/*')
        .pipe(zip('images.zip'))
        .pipe(gulp.dest(paths.outputAssets));
});

gulp.task('svg2png', function () {
    return gulp.src(paths.assetsDir + '/img/icons/*.svg')
        .pipe(svg2png())
        .pipe(gulp.dest(paths.outputAssets + '/img/icons/'));
});

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

    return gulp.src(paths.examples)
      .pipe(handlebars({}, options.handlebars))
      .pipe(rename({
        extname: '.html'
      }))
      .pipe(gulp.dest(paths.outputHTML + '/examples')).pipe(connect.reload());
});

gulp.task('markdown', function () {
    return gulp.src(paths.markdown)
        .pipe(gulp.dest(paths.outputHTML));
});

gulp.task('nginx', function () {
    return gulp.src('nginx.conf')
        .pipe(gulp.dest(paths.outputHTML));
});

gulp.task('htmlvalidate', ['examples', 'styleguide'], function (cb) {
    try {
        var validator = require('gulp-html');
        return gulp.src(['build/*.html', 'build/**/*.html'])
            .pipe(validator({'verbose': true}));
    } catch (err) {
        if (err.code === 'MODULE_NOT_FOUND') {
            console.log('WARNING: optional HTML validator not installed, to resolve run:');
            console.log('> npm install AusDTO/gulp-html');
            return cb;
        }
        else {
            throw err;
        }
    }
});

gulp.task('styleguide', ['styleguide.scss'], function () {
    var kssresult = kss({
        source: 'assets/sass',
        destination: paths.outputHTML,
        homepage: '../../README.md',
        builder: 'kss-builder'
    });
    kssresult.then(function () {
        gulp.src('./build/*.html').pipe(connect.reload());
    });

});

gulp.task('styleguide.scss', ['svg2png'], function () {
    return gulp.src(paths.kssScssDir)
        .pipe(sass(options.sass).on('error', sass.logError))
        .pipe(autoprefixer(options.autoprefixer))
        .pipe(gitVersion())
        .pipe(gulp.dest(paths.kssCssDir));
});

gulp.task('clean', function (done) {
    return del([paths.outputAssets, paths.outputHTML], done);
});

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

gulp.task('build', ['lint', 'ui-kit', 'markdown', 'examples', 'styleguide']);

gulp.task('build.prod', function (callback) {
    runSequence('clean',
        ['lint', 'nginx', 'ui-kit', 'ui-kit.min', 'ui-kit.img.zip', 'ui-kit.scssmerge', 'markdown', 'htmlvalidate'],
        callback);
});

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

gulp.task('watch.build', function () {
    gulp.watch([
            paths.assets,
            paths.examples,
            paths.readme,
            paths.kssBuilderDir,
            '!./kss-builder/kss-assets/kss.css'
        ],
        {verbose: true},
        ['build']);
});

gulp.task('serve', ['webserver', 'build', 'watch.build', 'livereload']);

gulp.task('livereload', function () {
    gulp.watch(['./build/latest/'], () => {
        gulp.src('./build/latest/**/*').pipe(connect.reload());
    });
});

gulp.task('webserver', function () {
    connect.server({
        livereload: true,
        root: 'build'
    });
});
<commit_msg>Only run uikit.img task on production gulp build<commit_after>'use strict';

var gulp = require('gulp'),
    sass = require('gulp-sass'),
    rename = require('gulp-rename'),
    cssnano = require('gulp-cssnano'),
    kss = require('kss'),
    sassLint = require('gulp-sass-lint'),
    autoprefixer = require('gulp-autoprefixer'),
    gitVersion = require('gulp-gitversion'),
    scssMerge = require('./lib/gulp-scss-merge.js'),
    uglify = require('gulp-uglify'),
    del = require('del'),
    runSequence = require('run-sequence'),
    connect = require('gulp-connect'),
    svg2png = require('gulp-svg2png'),
    webpack = require('webpack-stream'),
    zip = require('gulp-zip'),
    wrap = require('gulp-wrap'),
    imagemin = require('gulp-imagemin'),
    handlebars = require('gulp-compile-handlebars')
    ;

var paths = {
    assets: './assets/**/*.*',
    assetsDir: './assets',
    scssDir: './assets/sass/**/*.scss',
    scssTemplatesDir: './assets/sass/templates',
    kssScssDir: './kss-builder/kss-assets/*.scss',
    kssCssDir: './kss-builder/kss-assets',
    examples: './examples/*.hbs',
    examplePartialsDir: './examples/partials',
    kssBuilderDir: './kss-builder/**/*.*',
    images: './assets/img/**/*.+(png|svg|jpg)',
    scss: './assets/sass/ui-kit.scss',
    js: './assets/js/ui-kit.js',
    markdown: './*.md',
    readme: './README.md',
    outputAssets: './build/latest',
    outputCSS: './build/latest/*.css',
    outputHTML: './build'
};

var options = {
    autoprefixer: {
        browsers: ['last 2 versions', 'ie 8-10']
    },
    sass: {
        functions: {
            'image-url($img)': function(img) {
              var sass = require('node-sass');
              var String = sass.types.String;
              return new String('/latest/img/' + img.getValue());
            }
        },
        includePaths: [
          './node_modules'
        ]
    },
    webpack: {
        output: {
            filename: 'ui-kit.js',
        }
    },
    handlebars: {
      batch: [ paths.scssTemplatesDir, paths.examplePartialsDir ]
    }
};

gulp.task('lint', function () {
    return gulp.src([paths.scssDir, paths.kssScssDir, '!./assets/sass/vendor/**/*.scss'])
        .pipe(sassLint({
            configFile: '.sass-lint.yml'
        }))
        .pipe(sassLint.format())
        .pipe(sassLint.failOnError());
});

gulp.task('ui-kit', function () {
    gulp.start(['ui-kit.scss', 'ui-kit.js']);
});

gulp.task('ui-kit.scss', function () {
    return gulp.src(paths.scss)
        .pipe(sass(options.sass).on('error', sass.logError))
        .pipe(autoprefixer(options.autoprefixer))
        .pipe(gitVersion())
        .pipe(gulp.dest(paths.outputAssets));
});

gulp.task('ui-kit.js', function () {
    return gulp.src(paths.js)
        .pipe(webpack(options.webpack))
        .pipe(gitVersion())
        .pipe(gulp.dest(paths.outputAssets));
});

gulp.task('ui-kit.scssmerge', function () {
    return gulp.src(paths.scss)
        .pipe(scssMerge('_ui-kit.scss'))
        .pipe(gulp.dest(paths.outputAssets));
});

gulp.task('ui-kit.min', function () {
    gulp.start(['ui-kit.min.scss', 'ui-kit.min.js']);
});

gulp.task('ui-kit.min.scss', ['ui-kit.scss'], function () {
    return gulp.src([paths.outputCSS, '!./**/*.min.css'])
        .pipe(cssnano())
        .pipe(gitVersion())
        .pipe(rename({
            suffix: '.min'
        }))
        .pipe(gulp.dest(paths.outputAssets));
});

gulp.task('ui-kit.min.js', function () {
    return gulp.src(paths.js)
        .pipe(webpack({
            output: {
                filename: 'ui-kit.min.js',
            }
        }))
        .pipe(uglify())
        .pipe(gitVersion())
        .pipe(gulp.dest(paths.outputAssets));
});

gulp.task('ui-kit.img', ['svg2png'], function () {
    return gulp.src(paths.images)
        .pipe(imagemin())
        .pipe(gulp.dest(paths.outputAssets + '/img/'));
});

gulp.task('ui-kit.img.zip', ['ui-kit.img'], function () {
    return gulp.src(paths.outputAssets + '/img/**/*')
        .pipe(zip('images.zip'))
        .pipe(gulp.dest(paths.outputAssets));
});

gulp.task('svg2png', function () {
    return gulp.src(paths.assetsDir + '/img/icons/*.svg')
        .pipe(svg2png())
        .pipe(gulp.dest(paths.outputAssets + '/img/icons/'));
});

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

    return gulp.src(paths.examples)
      .pipe(handlebars({}, options.handlebars))
      .pipe(rename({
        extname: '.html'
      }))
      .pipe(gulp.dest(paths.outputHTML + '/examples')).pipe(connect.reload());
});

gulp.task('markdown', function () {
    return gulp.src(paths.markdown)
        .pipe(gulp.dest(paths.outputHTML));
});

gulp.task('nginx', function () {
    return gulp.src('nginx.conf')
        .pipe(gulp.dest(paths.outputHTML));
});

gulp.task('htmlvalidate', ['examples', 'styleguide'], function (cb) {
    try {
        var validator = require('gulp-html');
        return gulp.src(['build/*.html', 'build/**/*.html'])
            .pipe(validator({'verbose': true}));
    } catch (err) {
        if (err.code === 'MODULE_NOT_FOUND') {
            console.log('WARNING: optional HTML validator not installed, to resolve run:');
            console.log('> npm install AusDTO/gulp-html');
            return cb;
        }
        else {
            throw err;
        }
    }
});

gulp.task('styleguide', ['styleguide.scss'], function () {
    var kssresult = kss({
        source: 'assets/sass',
        destination: paths.outputHTML,
        homepage: '../../README.md',
        builder: 'kss-builder'
    });
    kssresult.then(function () {
        gulp.src('./build/*.html').pipe(connect.reload());
    });

});

gulp.task('styleguide.scss', function () {
    return gulp.src(paths.kssScssDir)
        .pipe(sass(options.sass).on('error', sass.logError))
        .pipe(autoprefixer(options.autoprefixer))
        .pipe(gitVersion())
        .pipe(gulp.dest(paths.kssCssDir));
});

gulp.task('clean', function (done) {
    return del([paths.outputAssets, paths.outputHTML], done);
});

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

gulp.task('build', ['lint', 'ui-kit', 'markdown', 'examples', 'styleguide']);

gulp.task('build.prod', function (callback) {
    runSequence('clean',
        ['lint', 'nginx', 'ui-kit', 'ui-kit.min', 'ui-kit.img.zip', 'ui-kit.scssmerge', 'markdown', 'htmlvalidate'],
        callback);
});

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

gulp.task('watch.build', function () {
    gulp.watch([
            paths.assets,
            paths.examples,
            paths.readme,
            paths.kssBuilderDir,
            '!./kss-builder/kss-assets/kss.css'
        ],
        {verbose: true},
        ['build']);
});

gulp.task('serve', ['webserver', 'build', 'watch.build', 'livereload']);

gulp.task('livereload', function () {
    gulp.watch(['./build/latest/'], () => {
        gulp.src('./build/latest/**/*').pipe(connect.reload());
    });
});

gulp.task('webserver', function () {
    connect.server({
        livereload: true,
        root: 'build'
    });
});
<|endoftext|>


<commit_before>'use strict';

var gulp = require('gulp'),
    sass = require('gulp-sass'),
    del = require('del'),
    minifyCss = require('gulp-minify-css'),
    importCss = require('gulp-import-css'),
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat'),
    scsslint = require('gulp-scss-lint'),
    jshint = require('gulp-jshint');

var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');

var now = new Date().getTime();

var config = {
    sass: {
        includePaths: [
            'node_modules/govuk_frontend_toolkit/stylesheets',
            'node_modules/govuk-elements-sass/public/sass'
        ]
    },
    jsSrc: 'src/AppBundle/Resources/assets/javascripts',
    imgSrc: 'src/AppBundle/Resources/assets/images',
    sassSrc: 'src/AppBundle/Resources/assets/scss',
    webAssets: 'web/assets/' + now
};

// Remove previous builds of javascript and css files
gulp.task('clean', () => {
    del(['web/assets']);
});

// Build all style related files for all browsers and copy
// related images and font files along with them
gulp.task('sass', [
    'lint.sass',
    'sass.application',
    'sass.application-ie7',
    'sass.application-ie8',
    'sass.application-print',
    'sass.images',
    'sass.fonts']);

// Compile the sass for the main styles for the site into a minified .css file
gulp.task('sass.application', () => {

    return gulp.src(config.sassSrc + '/application.scss')
        .pipe(sass(config.sass))
        .pipe(importCss())
        .pipe(minifyCss())
        .pipe(gulp.dest(config.webAssets + '/stylesheets'));

});

// Compile styles that are unique to IE 7.
gulp.task('sass.application-ie7', () => {

    return gulp.src(config.sassSrc + '/application-ie7.scss')
        .pipe(sass(config.sass))
        .pipe(importCss())
        .pipe(minifyCss())
        .pipe(gulp.dest(config.webAssets + '/stylesheets'));

});

// Compile styles that are unique to IE 8
gulp.task('sass.application-ie8', () => {

    return gulp.src(config.sassSrc + '/application-ie8.scss')
        .pipe(sass(config.sass))
        .pipe(importCss())
        .pipe(gulp.dest(config.webAssets + '/stylesheets'));

});

// Compile styles that are used when the user prints something.
gulp.task('sass.application-print', () => {

    return gulp.src(config.sassSrc + '/application-print.scss')
        .pipe(sass(config.sass))
        .pipe(importCss())
        .pipe(minifyCss())
        .pipe(gulp.dest(config.webAssets + '/stylesheets'));

});

// Copy all style related images, we also bundle the external copy of fonts too, only used for ie 8
gulp.task('sass.images', () => {
    gulp.src('./node_modules/govuk_template_mustache/assets/stylesheets/images/**/*')
        .pipe(gulp.dest(config.webAssets + '/stylesheets/images'));

    gulp.src('./node_modules/govuk_template_mustache/assets/stylesheets/images/gov.uk_logotype_crown.png')
        .pipe(gulp.dest('./web/images'));

    gulp.src(config.sassSrc + '/images/**/*')
        .pipe(gulp.dest(config.webAssets + '/stylesheets/images'));
});
gulp.task('sass.fonts', () => {
    gulp.src('node_modules/govuk_template_mustache/assets/stylesheets/fonts/*')
        .pipe(gulp.dest(config.webAssets + '/stylesheets/fonts'));

    gulp.src('node_modules/govuk_template_mustache/assets/stylesheets/fonts-ie8.css')
        .pipe(gulp.dest(config.webAssets + '/stylesheets'));
});

// Copy non css related images
gulp.task('images', () => {
    gulp.src('./node_modules/govuk_frontend_toolkit/images/**/*').pipe(gulp.dest('./web/images'));
    gulp.src('./node_modules/govuk_template_mustache/assets/images/*').pipe(gulp.dest('./web/images'));
    gulp.src('./src/AppBundle/Resources/assets/images/**/*').pipe(gulp.dest('./web/images'));
});

// Creates the production version of the service javascript.
// Files are concatinated and then minified with uglify.
gulp.task('js.prod', ['lint.js'], () => {
    return gulp.src([
            './node_modules/govuk_template_mustache/assets/javascripts/govuk-template.js',
            './node_modules/govuk_frontend_toolkit/javascripts/govuk/selection-buttons.js',
            config.jsSrc + '/*.js'])
        .pipe(concat('application.js'))
        .pipe(uglify())
        .pipe(gulp.dest(config.webAssets + '/javascripts'));
});

// create a debug version of javascript to allow easier debugging by
// having javascript that can easily have breakpoints and stepped through
// Used by the watch process.
gulp.task('js.debug', function () {
    return gulp.src([
            './node_modules/govuk_template_mustache/assets/javascripts/govuk-template.js',
            './node_modules/govuk_frontend_toolkit/javascripts/govuk/selection-buttons.js',
            config.jsSrc + '/*.js'])
        .pipe(concat('application.js'))
        .pipe(gulp.dest(config.webAssets + '/javascripts'));
});

// Create IE javascript with polyfills for missing functions and support.
gulp.task('js.ie', function() {
    gulp.src('./node_modules/govuk_template_mustache/assets/javascripts/ie.js').pipe(gulp.dest(config.webAssets + '/javascripts'));
    gulp.src('./node_modules/govuk_template_mustache/assets/javascripts/vendor/goog/webfont-debug.js').pipe(gulp.dest(config.webAssets + '/javascripts'));
});

// Copy across javascript from other vendors.
gulp.task('vendor', function () {
    gulp.src('./node_modules/jquery/dist/jquery.min.js')
        .pipe(gulp.dest(config.webAssets + '/javascripts'));
});

// Check that the sass complies with simple rules for it's creation to encourage good code.
gulp.task('lint.sass', function() {
    return gulp.src('src/AppBundle/Resources/assets/scss/**/*.scss')
        .pipe(scsslint());
});

// Check javascript follows some good guidelines and check for obvious errors.
gulp.task('lint.js', function () {
    gulp.src(config.jsSrc + '/**/*.js')
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});
// Watch the source files and recompile in debug mode when there are changed.
gulp.task('watch', ['clean', 'lint.js', 'sass', 'images', 'js.debug', 'js.ie', 'vendor'], () => {
    gulp.watch(config.sassSrc + '/**/*', { interval: 1000 }, ['sass']);
    gulp.watch(config.imgSrc + '/**/*', { interval: 1000 }, ['images']);
    gulp.watch(config.jsSrc + '/**/*.js', { interval: 1000 }, ['lint.js', 'js.debug']);
});

// Build all assets in production ready mode.
gulp.task('default', ['clean', 'lint.js', 'sass', 'images', 'js.prod', 'js.ie', 'vendor']);
<commit_msg>Gulp - keep watch going even if sass errors<commit_after>'use strict';

var gulp = require('gulp'),
    sass = require('gulp-sass'),
    del = require('del'),
    minifyCss = require('gulp-minify-css'),
    importCss = require('gulp-import-css'),
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat'),
    scsslint = require('gulp-scss-lint'),
    jshint = require('gulp-jshint');

var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');

var now = new Date().getTime();

var config = {
    sass: {
        includePaths: [
            'node_modules/govuk_frontend_toolkit/stylesheets',
            'node_modules/govuk-elements-sass/public/sass'
        ]
    },
    jsSrc: 'src/AppBundle/Resources/assets/javascripts',
    imgSrc: 'src/AppBundle/Resources/assets/images',
    sassSrc: 'src/AppBundle/Resources/assets/scss',
    webAssets: 'web/assets/' + now
};

// Remove previous builds of javascript and css files
gulp.task('clean', () => {
    del(['web/assets']);
});

// Build all style related files for all browsers and copy
// related images and font files along with them
gulp.task('sass', [
    'lint.sass',
    'sass.application',
    'sass.application-ie7',
    'sass.application-ie8',
    'sass.application-print',
    'sass.images',
    'sass.fonts']);

// Compile the sass for the main styles for the site into a minified .css file
gulp.task('sass.application', () => {

    return gulp.src(config.sassSrc + '/application.scss')
        .pipe(sass(config.sass).on('error', sass.logError))
        .pipe(importCss())
        .pipe(minifyCss())
        .pipe(gulp.dest(config.webAssets + '/stylesheets'));

});

// Compile styles that are unique to IE 7.
gulp.task('sass.application-ie7', () => {

    return gulp.src(config.sassSrc + '/application-ie7.scss')
        .pipe(sass(config.sass).on('error', sass.logError))
        .pipe(importCss())
        .pipe(minifyCss())
        .pipe(gulp.dest(config.webAssets + '/stylesheets'));

});

// Compile styles that are unique to IE 8
gulp.task('sass.application-ie8', () => {

    return gulp.src(config.sassSrc + '/application-ie8.scss')
        .pipe(sass(config.sass).on('error', sass.logError))
        .pipe(importCss())
        .pipe(gulp.dest(config.webAssets + '/stylesheets'));

});

// Compile styles that are used when the user prints something.
gulp.task('sass.application-print', () => {

    return gulp.src(config.sassSrc + '/application-print.scss')
        .pipe(sass(config.sass).on('error', sass.logError))
        .pipe(importCss())
        .pipe(minifyCss())
        .pipe(gulp.dest(config.webAssets + '/stylesheets'));

});

// Copy all style related images, we also bundle the external copy of fonts too, only used for ie 8
gulp.task('sass.images', () => {
    gulp.src('./node_modules/govuk_template_mustache/assets/stylesheets/images/**/*')
        .pipe(gulp.dest(config.webAssets + '/stylesheets/images'));

    gulp.src('./node_modules/govuk_template_mustache/assets/stylesheets/images/gov.uk_logotype_crown.png')
        .pipe(gulp.dest('./web/images'));

    gulp.src(config.sassSrc + '/images/**/*')
        .pipe(gulp.dest(config.webAssets + '/stylesheets/images'));
});
gulp.task('sass.fonts', () => {
    gulp.src('node_modules/govuk_template_mustache/assets/stylesheets/fonts/*')
        .pipe(gulp.dest(config.webAssets + '/stylesheets/fonts'));

    gulp.src('node_modules/govuk_template_mustache/assets/stylesheets/fonts-ie8.css')
        .pipe(gulp.dest(config.webAssets + '/stylesheets'));
});

// Copy non css related images
gulp.task('images', () => {
    gulp.src('./node_modules/govuk_frontend_toolkit/images/**/*').pipe(gulp.dest('./web/images'));
    gulp.src('./node_modules/govuk_template_mustache/assets/images/*').pipe(gulp.dest('./web/images'));
    gulp.src('./src/AppBundle/Resources/assets/images/**/*').pipe(gulp.dest('./web/images'));
});

// Creates the production version of the service javascript.
// Files are concatinated and then minified with uglify.
gulp.task('js.prod', ['lint.js'], () => {
    return gulp.src([
            './node_modules/govuk_template_mustache/assets/javascripts/govuk-template.js',
            './node_modules/govuk_frontend_toolkit/javascripts/govuk/selection-buttons.js',
            config.jsSrc + '/*.js'])
        .pipe(concat('application.js'))
        .pipe(uglify())
        .pipe(gulp.dest(config.webAssets + '/javascripts'));
});

// create a debug version of javascript to allow easier debugging by
// having javascript that can easily have breakpoints and stepped through
// Used by the watch process.
gulp.task('js.debug', function () {
    return gulp.src([
            './node_modules/govuk_template_mustache/assets/javascripts/govuk-template.js',
            './node_modules/govuk_frontend_toolkit/javascripts/govuk/selection-buttons.js',
            config.jsSrc + '/*.js'])
        .pipe(concat('application.js'))
        .pipe(gulp.dest(config.webAssets + '/javascripts'));
});

// Create IE javascript with polyfills for missing functions and support.
gulp.task('js.ie', function() {
    gulp.src('./node_modules/govuk_template_mustache/assets/javascripts/ie.js').pipe(gulp.dest(config.webAssets + '/javascripts'));
    gulp.src('./node_modules/govuk_template_mustache/assets/javascripts/vendor/goog/webfont-debug.js').pipe(gulp.dest(config.webAssets + '/javascripts'));
});

// Copy across javascript from other vendors.
gulp.task('vendor', function () {
    gulp.src('./node_modules/jquery/dist/jquery.min.js')
        .pipe(gulp.dest(config.webAssets + '/javascripts'));
});

// Check that the sass complies with simple rules for it's creation to encourage good code.
gulp.task('lint.sass', function() {
    return gulp.src('src/AppBundle/Resources/assets/scss/**/*.scss')
        .pipe(scsslint());
});

// Check javascript follows some good guidelines and check for obvious errors.
gulp.task('lint.js', function () {
    gulp.src(config.jsSrc + '/**/*.js')
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});
// Watch the source files and recompile in debug mode when there are changed.
gulp.task('watch', ['clean', 'lint.js', 'sass', 'images', 'js.debug', 'js.ie', 'vendor'], () => {
    gulp.watch(config.sassSrc + '/**/*', { interval: 1000 }, ['sass']);
    gulp.watch(config.imgSrc + '/**/*', { interval: 1000 }, ['images']);
    gulp.watch(config.jsSrc + '/**/*.js', { interval: 1000 }, ['lint.js', 'js.debug']);
});

// Build all assets in production ready mode.
gulp.task('default', ['clean', 'lint.js', 'sass', 'images', 'js.prod', 'js.ie', 'vendor']);
<|endoftext|>


<commit_before>'use strict';

var gulp = require('gulp'),
    jshint = require('gulp-jshint'),
    rimraf = require('gulp-rimraf'),
    env = require('node-env-file'),
    browserify = require('browserify'),
    source = require('vinyl-source-stream'),
    streamify = require('gulp-streamify'),
    autoprefixer = require('gulp-autoprefixer'),
    minify = require('gulp-minify-css'),
    concat = require('gulp-concat'),
    sass = require('gulp-sass'),
    plumber = require('gulp-plumber'),
    karma = require('karma').server,
    uglify = require('gulp-uglify'),
    express = require('express'),
    refresh = require('gulp-livereload'),
    livereload = require('connect-livereload'),
    lrserver = require('tiny-lr')(),
    livereloadport = 35729,
    serverport = 5000,
    server = express();

env(__dirname + '/.env');

var PRODUCTION = process.env.ENVIRONMENT === 'production',
    DIST_FOLDER = 'dist',
    KARMA_CONFIG = '/karma.conf.js',
    BUNDLE_FILENAME = "main";

server.use(livereload({port: livereloadport}));
server.use(express.static('./' + DIST_FOLDER));

server.all('/*', function (req, res) {
    res.sendfile('index.html', { root: DIST_FOLDER });
});

gulp.task('build', ['clean'], function () {
    gulp.start(['views', 'styles', 'browserify']);
});

gulp.task('clean', function () {
    return gulp.src('./' + DIST_FOLDER + '/', { read: false })
        .pipe(plumber())
        .pipe(rimraf({force: true}));
});

gulp.task('lint', function () {
    gulp.src('scripts/*.js')
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

gulp.task('styles', function () {
    var stream = gulp.src(['bootstrapper.scss', 'styles/*.scss'])
        .pipe(concat(BUNDLE_FILENAME + '.css'))
        .pipe(plumber())
        .pipe(sass())
        .pipe(autoprefixer('last 2 versions', '> 1%', 'ie 8'));
    if (PRODUCTION)
        stream = stream.pipe(minify());
    stream
        .pipe(gulp.dest(DIST_FOLDER + '/css/'))
        .pipe(refresh(lrserver));
});

gulp.task('browserify', function () {
    var stream = browserify({
        entries: ['./bootstrapper.js'],
        noParse: [
            require.resolve('jquery'),
            require.resolve('angular/angular'),
            require.resolve('angular/angular.mocks'),
            require.resolve('angular/angular.sanitize'),
            require.resolve('angular/angular.resource'),
            require.resolve('angular/angular.route'),
            require.resolve('angular/angular.animate'),
            require.resolve('underscore')
        ]
    })
        .bundle({ debug: !PRODUCTION })
        .pipe(plumber())
        .pipe(source('main.js'));
    if (PRODUCTION)
        stream = stream.pipe(streamify(uglify()));
    stream
        .pipe(gulp.dest('./' + DIST_FOLDER + '/js'))
        .pipe(refresh(lrserver));
});

gulp.task('test', function (done) {
    karma.start({
        configFile: __dirname + KARMA_CONFIG,
        singleRun: PRODUCTION
    }, done);
});

gulp.task('views', function () {
    gulp.src('index.html')
        .pipe(gulp.dest(DIST_FOLDER));
    gulp.src('views/**/*')
        .pipe(gulp.dest(DIST_FOLDER + '/views/'))
        .pipe(refresh(lrserver));
});

gulp.task('watch', ['build', 'serve'], function () {
    gulp.watch(['bootstrapper.js', 'scripts/**/*.js'], [
        'browserify'
    ]);

    gulp.watch(['bootstrapper.css', 'styles/**/*.scss'], [
        'styles'
    ]);

    gulp.watch(['views/**/*.html'], [
        'views'
    ]);
});

gulp.task('watch-test', ['build', 'serve', 'test']);

gulp.task('serve', function () {
    server.listen(serverport);
    refresh.listen(livereloadport);
    console.log('App listening on http://localhost:' + serverport);
});

gulp.task('default', ['build']);<commit_msg>Suppress browserify errors<commit_after>'use strict';

var gulp = require('gulp'),
    jshint = require('gulp-jshint'),
    rimraf = require('gulp-rimraf'),
    env = require('node-env-file'),
    browserify = require('browserify'),
    source = require('vinyl-source-stream'),
    streamify = require('gulp-streamify'),
    autoprefixer = require('gulp-autoprefixer'),
    minify = require('gulp-minify-css'),
    concat = require('gulp-concat'),
    sass = require('gulp-sass'),
    plumber = require('gulp-plumber'),
    karma = require('karma').server,
    uglify = require('gulp-uglify'),
    express = require('express'),
    refresh = require('gulp-livereload'),
    livereload = require('connect-livereload'),
    lrserver = require('tiny-lr')(),
    gutil = require('gulp-util'),
    livereloadport = 35729,
    serverport = 5000,
    server = express();

env(__dirname + '/.env');

var PRODUCTION = process.env.ENVIRONMENT === 'production',
    DIST_FOLDER = 'dist',
    KARMA_CONFIG = '/karma.conf.js',
    BUNDLE_FILENAME = "main";

server.use(livereload({port: livereloadport}));
server.use(express.static('./' + DIST_FOLDER));

server.all('/*', function (req, res) {
    res.sendfile('index.html', { root: DIST_FOLDER });
});

gulp.task('build', ['clean'], function () {
    gulp.start(['views', 'styles', 'browserify']);
});

gulp.task('clean', function () {
    return gulp.src('./' + DIST_FOLDER + '/', { read: false })
        .pipe(plumber())
        .pipe(rimraf({force: true}));
});

gulp.task('lint', function () {
    gulp.src('scripts/*.js')
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

gulp.task('styles', function () {
    var stream = gulp.src(['bootstrapper.scss', 'styles/*.scss'])
        .pipe(concat(BUNDLE_FILENAME + '.css'))
        .pipe(plumber())
        .pipe(sass())
        .pipe(autoprefixer('last 2 versions', '> 1%', 'ie 8'));
    if (PRODUCTION)
        stream = stream.pipe(minify());
    stream
        .pipe(gulp.dest(DIST_FOLDER + '/css/'))
        .pipe(refresh(lrserver));
});

gulp.task('browserify', function () {
    var stream = browserify({
        entries: ['./bootstrapper.js'],
        noParse: [
            require.resolve('jquery'),
            require.resolve('angular/angular'),
            require.resolve('angular/angular.mocks'),
            require.resolve('angular/angular.sanitize'),
            require.resolve('angular/angular.resource'),
            require.resolve('angular/angular.route'),
            require.resolve('angular/angular.animate'),
            require.resolve('underscore')
        ]
    })
        .bundle({ debug: !PRODUCTION })
        .on('error', gutil.log)
        .pipe(source('main.js'));
    if (PRODUCTION)
        stream = stream.pipe(streamify(uglify()));
    stream
        .pipe(gulp.dest('./' + DIST_FOLDER + '/js'))
        .pipe(refresh(lrserver));
});

gulp.task('test', function (done) {
    karma.start({
        configFile: __dirname + KARMA_CONFIG,
        singleRun: PRODUCTION
    }, done);
});

gulp.task('views', function () {
    gulp.src('index.html')
        .pipe(gulp.dest(DIST_FOLDER));
    gulp.src('views/**/*')
        .pipe(gulp.dest(DIST_FOLDER + '/views/'))
        .pipe(refresh(lrserver));
});

gulp.task('watch', ['build', 'serve'], function () {
    gulp.watch(['bootstrapper.js', 'scripts/**/*.js'], [
        'browserify'
    ]);

    gulp.watch(['bootstrapper.css', 'styles/**/*.scss'], [
        'styles'
    ]);

    gulp.watch(['views/**/*.html'], [
        'views'
    ]);
});

gulp.task('watch-test', ['build', 'serve', 'test']);

gulp.task('serve', function () {
    server.listen(serverport);
    refresh.listen(livereloadport);
    console.log('App listening on http://localhost:' + serverport);
});

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