<commit_before>"use strict";
var path = require('path'),
    extend = require('extend'),
    util = require('util'),
    gulp = require('gulp'),
    browsersync = require('browser-sync'),
    bowerFiles = require('main-bower-files'),
    $ = require('gulp-load-plugins')(),
    templateCache = require('gulp-angular-templatecache'),
    eventStream = require('event-stream'),
    packagejson = require('./package.json'),
    fs = require('fs'),
    scssLint = require('gulp-scss-lint'),
    server = require('gulp-develop-server'),
    find = require('find'),
    del = require('del');

var configLocalServer = './config/server';
var configLocalApp = './config/app';

/* Configurations. Note that most of the configuration is stored in
the task context. These are mainly for repeating configuration items */
var config = {
  version: packagejson.version,
  debug: Boolean($.util.env.debug),
  browsersync: Boolean($.util.env.browsersync),
  server: {
    host:         process.env.npm_package_config_server_host || "localhost",
    maxSockets:   parseInt(process.env.npm_package_config_server_maxSockets) || 100,
    port:         parseInt(process.env.npm_package_config_server_port) || 8080
  }
};

// Package management
/* Install & update Bower dependencies */
gulp.task('install', ['config', 'integrate'], function() {
  // FIXME specifying the component directory broken in gulp
  // For now, use .bowerrc; No need for piping, either
  $.bower();
  // Downloads the Selenium webdriver
  $.protractor.webdriver_update(function() {});
});

/* Bump version number for packagejson.json & bower.json */
// TODO Provide means for appending a patch id based on git commit id or md5 hash
gulp.task('bump', function() {
  // Fetch whether we're bumping major, minor or patch; default to minor
  var env = $.util.env,
      type = (env.major) ? 'major' : (env.patch) ? 'patch' : 'minor';

  gulp.src(['./bower.json', './package.json'])
    .pipe($.bump({ type: type }))
    .pipe(gulp.dest('./'));
});

// install will run this task _before_ bower install task
gulp.task('config', function() {
  var data; // just a tmp variable

  // Server config
  var serverConfig = JSON.parse(fs.readFileSync(configLocalServer+'/config.json'));
  serverConfig = extend(true, serverConfig, config.server);
  // read local config
  if (fs.existsSync(configLocalServer+'/config.local.json')) {
    data = JSON.parse(fs.readFileSync(configLocalServer+'/config.local.json'));
    serverConfig = extend(true, serverConfig, data);
  }
  serverConfig = extend(true, serverConfig, config.server);
  fs.writeFileSync('./config.json', JSON.stringify(serverConfig, null, 2));

  // Server test config
  var serverTestConfig = JSON.parse(fs.readFileSync(configLocalServer + '/config.test.json'));
  // read local config
  if (fs.existsSync(configLocalServer + '/config.test.local.json')) {
    data = JSON.parse(fs.readFileSync(configLocalServer + '/config.test.local.json'));
    serverTestConfig = extend(true, serverTestConfig, data);
  }
  fs.writeFileSync('./config.test.json', JSON.stringify(serverTestConfig, null, 2));

  // Control panel app config
  var clientConfig = JSON.parse(fs.readFileSync(configLocalApp + '/config.json'));
  clientConfig.appConfig.socketServer = 'http://' + serverConfig.host + ':' + serverConfig.port + '/devicewall';
  // read local config
  if (fs.existsSync(configLocalApp+'/config.local.json')) {
    data = JSON.parse(fs.readFileSync(configLocalApp+'/config.local.json'));
    clientConfig = extend(true, clientConfig, data);
  }
  // Write angular configuration
  return gulp.src(configLocalApp + '/config.json')
    .pipe($.ngConstant({
       name: 'configuration',
       constants: clientConfig
    }))
    .pipe(gulp.dest('./src/app'));
});

// Cleanup
gulp.task('clean', function(cb) {
  del(['dist/**', 'temp/**'], cb);
});

/* Serve the web site */
gulp.task('serve', $.serve({
  root: 'dist',
  port: config.server.controlPort
}));

gulp.task('preprocess', ['config', 'scss-lint'], function() {
  gulp.src(['src/app/**/*.js', 'server*.js'])
    .pipe($.jshint())
    .pipe($.jshint.reporter('default'));
});

gulp.task('scss-lint', function() {
  var lintTask = gulp.src('src/css/**/*.scss')
    .pipe(scssLint());
  // without --force flag scss-lint fails the task
  if (!$.util.env.force) {
    lintTask.pipe(scssLint.failReporter());
  }
});

gulp.task('javascript', ['preprocess'], function() {

  // The non-MD5fied prefix, so that we know which version we are actually
  // referring to in case of fixing bugs
  var bundleName = util.format('bundle-%s.js', config.version);

  // Note: two pipes get combined together by first
  // combining components into one bundle, then adding
  // app sources, and reordering the items. Note that
  // we expect Angular to be the first item in bower.json
  // so that component concatenation works
  var components = gulp.src(['src/components/socket.io-client/socket.io.js'].concat(bowerFiles()))
    // Socket.io does not specify main file in the manifest; add it manually
    .pipe($.filter('**/*.js', '!jquery*', '!foundation*'))
    .pipe($.plumber())
    .pipe($.concat('components.js'));

  var templates = gulp.src('src/assets/**/*.html')
    .pipe(templateCache('templates.js', { standalone: true, root: 'assets' }));

  var app = gulp.src('src/app/**/*.js')
    .pipe($.concat('app.js'));

  return eventStream.merge(components, app, templates)
    .pipe($.order([
      '**/components.js',
      '**/templates.js',
      '**/app.js'
    ]))
    .pipe($.concat(bundleName))
    .pipe($.if(!config.debug, $.ngmin()))
    .pipe($.if(!config.debug, $.uglify()))
    .pipe(gulp.dest('dist'));
});

gulp.task('stylesheets', function() {
  // The non-MD5fied prefix, so that we know which version we are actually
  // referring to in case of fixing bugs
  var bundleName = util.format('styles-%s.css', config.version);

  return gulp.src('src/css/styles.scss')
    .pipe($.plumber())
    // Compile
    .pipe($.compass({
        project: path.join(__dirname, 'src'),
        sass: 'css',
        css: '../temp/css'
    }))
    // Unit test
    // Integrate (link, packagejson, concatenate)
    .pipe($.concat(bundleName))
    // Integrate
    .pipe(gulp.dest('dist/css'));
    // Integration test
    // oh why css lint for css generated by sass? .pipe($.csslint())
    //.pipe($.csslint.reporter());
});

gulp.task('assets', function() {
  return gulp.src('src/assets/**')
    .pipe(gulp.dest('dist/assets'));
    // Integration test
});

gulp.task('favicon', function() {
  return gulp.src(['src/favicon.ico'])
    .pipe(gulp.dest('dist'));
});

gulp.task('integrate', ['javascript', 'stylesheets', 'assets', 'favicon'], function() {
  return gulp.src(['dist/*.js', 'dist/css/*.css'])
    .pipe($.inject('src/index.html', { ignorePath: ['/dist/'], addRootSlash: false }))
    .pipe(gulp.dest('./dist'));
});

var dependencies = (config.browsersync) ?
  ['integrate', 'test', 'browsersync'] : ['integrate', 'livereload'];

gulp.task('watch', dependencies, function() {

  return gulp.watch([
    'config/**/*.json',
    'src/css/**/*.scss',
    'src/app/**/*.js',
    'src/index.html',
    'tests/**/*.js'
  ], ['integrate']);

});

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

  // Only livereload if the HTML (or other static assets) are changed, because
  // the HTML will change for any JS or CSS change
  gulp.src('dist/**', { read: false })
    .pipe($.watch())
    .pipe($.livereload(parseInt(process.env.LIVERELOAD_PORT) || 35729));

});

/* Watch, live reload and serve the web site with browsersync */
gulp.task('browsersync', function() {

  var bs = browsersync.init('dist/*', {
    server: {
      baseDir: 'dist'
    }
  });

});

gulp.task('mywatch', ['integrate'], function() {
  $.nodemon({script: 'server/server.js', watch: 'dist/**/*'})
  .on('restart', function () {
    console.log('restarted!');
  });
  return gulp.watch([
      'server*.js',
      'config/**/*.json',
      'src/css/**/*.scss',
      'src/app/**/*.js',
      'src/assets/**/*',
      'src/index.html'
    ], ['integrate']);
});

// Tests
gulp.task('webdriver_manager_update', $.protractor.webdriver_update);

gulp.task('test:e2e', ['webdriver_manager_update'], function() {
  var testConfig = require('./config.test.json');
  var testDataDir = path.dirname(path.resolve(testConfig.devicesJson));
  var paths = find.fileSync(/selenium-server-standalone.*\.jar/, 'node_modules/protractor/selenium');
  var args = ['--seleniumServerJar', paths[0], '--baseUrl', 'http://' + testConfig.host + ':' + testConfig.port];
  var protractorConf = {
    configFile: './protractor.config.js',
    args: [args]
  };

  if (!fs.existsSync(testDataDir)) {
    fs.mkdirSync(testDataDir);
  }

  server.listen({path: './server/server.js', env: {"NODE_ENV": "test"}});
  gulp.src(['tests/e2e/**/*.js'], { read: false })
    .pipe($.protractor.protractor(protractorConf)).on('error', function(e) {
      server.kill();
    }).on('end', function() {
      server.kill();
    });
});
gulp.task('default', ['integrate']);
<commit_msg>fix watch task and add clean task<commit_after>"use strict";
var path = require('path'),
    extend = require('extend'),
    util = require('util'),
    gulp = require('gulp'),
    browsersync = require('browser-sync'),
    bowerFiles = require('main-bower-files'),
    $ = require('gulp-load-plugins')(),
    templateCache = require('gulp-angular-templatecache'),
    eventStream = require('event-stream'),
    packagejson = require('./package.json'),
    fs = require('fs'),
    scssLint = require('gulp-scss-lint'),
    server = require('gulp-develop-server'),
    find = require('find'),
    del = require('del');

var configLocalServer = './config/server';
var configLocalApp = './config/app';

/* Configurations. Note that most of the configuration is stored in
the task context. These are mainly for repeating configuration items */
var config = {
  version: packagejson.version,
  debug: Boolean($.util.env.debug),
  browsersync: Boolean($.util.env.browsersync),
  server: {
    host:         process.env.npm_package_config_server_host || "localhost",
    maxSockets:   parseInt(process.env.npm_package_config_server_maxSockets) || 100,
    port:         parseInt(process.env.npm_package_config_server_port) || 8080
  }
};

// Package management
/* Install & update Bower dependencies */
gulp.task('install', ['config', 'integrate'], function() {
  // FIXME specifying the component directory broken in gulp
  // For now, use .bowerrc; No need for piping, either
  $.bower();
  // Downloads the Selenium webdriver
  $.protractor.webdriver_update(function() {});
});

/* Bump version number for packagejson.json & bower.json */
// TODO Provide means for appending a patch id based on git commit id or md5 hash
gulp.task('bump', function() {
  // Fetch whether we're bumping major, minor or patch; default to minor
  var env = $.util.env,
      type = (env.major) ? 'major' : (env.patch) ? 'patch' : 'minor';

  gulp.src(['./bower.json', './package.json'])
    .pipe($.bump({ type: type }))
    .pipe(gulp.dest('./'));
});

// install will run this task _before_ bower install task
gulp.task('config', function() {
  var data; // just a tmp variable

  // Server config
  var serverConfig = JSON.parse(fs.readFileSync(configLocalServer+'/config.json'));
  serverConfig = extend(true, serverConfig, config.server);
  // read local config
  if (fs.existsSync(configLocalServer+'/config.local.json')) {
    data = JSON.parse(fs.readFileSync(configLocalServer+'/config.local.json'));
    serverConfig = extend(true, serverConfig, data);
  }
  serverConfig = extend(true, serverConfig, config.server);
  fs.writeFileSync('./config.json', JSON.stringify(serverConfig, null, 2));

  // Server test config
  var serverTestConfig = JSON.parse(fs.readFileSync(configLocalServer + '/config.test.json'));
  // read local config
  if (fs.existsSync(configLocalServer + '/config.test.local.json')) {
    data = JSON.parse(fs.readFileSync(configLocalServer + '/config.test.local.json'));
    serverTestConfig = extend(true, serverTestConfig, data);
  }
  fs.writeFileSync('./config.test.json', JSON.stringify(serverTestConfig, null, 2));

  // Control panel app config
  var clientConfig = JSON.parse(fs.readFileSync(configLocalApp + '/config.json'));
  clientConfig.appConfig.socketServer = 'http://' + serverConfig.host + ':' + serverConfig.port + '/devicewall';
  // read local config
  if (fs.existsSync(configLocalApp+'/config.local.json')) {
    data = JSON.parse(fs.readFileSync(configLocalApp+'/config.local.json'));
    clientConfig = extend(true, clientConfig, data);
  }
  // Write angular configuration
  return gulp.src(configLocalApp + '/config.json')
    .pipe($.ngConstant({
       name: 'configuration',
       constants: clientConfig
    }))
    .pipe(gulp.dest('./src/app'));
});

// Cleanup
gulp.task('clean', function(cb) {
  del(['dist/**', 'temp/**'], cb);
});

/* Serve the web site */
gulp.task('serve', $.serve({
  root: 'dist',
  port: config.server.controlPort
}));

gulp.task('preprocess', ['config', 'scss-lint'], function() {
  gulp.src(['src/app/**/*.js', 'server*.js'])
    .pipe($.jshint())
    .pipe($.jshint.reporter('default'));
});

gulp.task('scss-lint', function() {
  var lintTask = gulp.src('src/css/**/*.scss')
    .pipe(scssLint());
  // without --force flag scss-lint fails the task
  if (!$.util.env.force) {
    lintTask.pipe(scssLint.failReporter());
  }
});

gulp.task('javascript', ['preprocess'], function() {

  // The non-MD5fied prefix, so that we know which version we are actually
  // referring to in case of fixing bugs
  var bundleName = util.format('bundle-%s.js', config.version);

  // Note: two pipes get combined together by first
  // combining components into one bundle, then adding
  // app sources, and reordering the items. Note that
  // we expect Angular to be the first item in bower.json
  // so that component concatenation works
  var components = gulp.src(['src/components/socket.io-client/socket.io.js'].concat(bowerFiles()))
    // Socket.io does not specify main file in the manifest; add it manually
    .pipe($.filter('**/*.js', '!jquery*', '!foundation*'))
    .pipe($.plumber())
    .pipe($.concat('components.js'));

  var templates = gulp.src('src/assets/**/*.html')
    .pipe(templateCache('templates.js', { standalone: true, root: 'assets' }));

  var app = gulp.src('src/app/**/*.js')
    .pipe($.concat('app.js'));

  return eventStream.merge(components, app, templates)
    .pipe($.order([
      '**/components.js',
      '**/templates.js',
      '**/app.js'
    ]))
    .pipe($.concat(bundleName))
    .pipe($.if(!config.debug, $.ngmin()))
    .pipe($.if(!config.debug, $.uglify()))
    .pipe(gulp.dest('dist'));
});

gulp.task('stylesheets', function() {
  // The non-MD5fied prefix, so that we know which version we are actually
  // referring to in case of fixing bugs
  var bundleName = util.format('styles-%s.css', config.version);

  return gulp.src('src/css/styles.scss')
    .pipe($.plumber())
    // Compile
    .pipe($.compass({
        project: path.join(__dirname, 'src'),
        sass: 'css',
        css: '../temp/css'
    }))
    // Unit test
    // Integrate (link, packagejson, concatenate)
    .pipe($.concat(bundleName))
    // Integrate
    .pipe(gulp.dest('dist/css'));
    // Integration test
    // oh why css lint for css generated by sass? .pipe($.csslint())
    //.pipe($.csslint.reporter());
});

gulp.task('assets', function() {
  return gulp.src('src/assets/**')
    .pipe(gulp.dest('dist/assets'));
    // Integration test
});

gulp.task('favicon', function() {
  return gulp.src(['src/favicon.ico'])
    .pipe(gulp.dest('dist'));
});

gulp.task('integrate', ['javascript', 'stylesheets', 'assets', 'favicon'], function() {
  return gulp.src(['dist/*.js', 'dist/css/*.css'])
    .pipe($.inject('src/index.html', { ignorePath: ['/dist/'], addRootSlash: false }))
    .pipe(gulp.dest('./dist'));
});

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

  // Only livereload if the HTML (or other static assets) are changed, because
  // the HTML will change for any JS or CSS change
  gulp.src('dist/**', { read: false })
    .pipe($.watch())
    .pipe($.livereload(parseInt(process.env.LIVERELOAD_PORT) || 35729));

});

/* Watch, live reload and serve the web site with browsersync */
gulp.task('browsersync', function() {

  var bs = browsersync.init('dist/*', {
    server: {
      baseDir: 'dist'
    }
  });

});

gulp.task('watch', ['build'], function() {
  $.nodemon({script: 'server/server.js', watch: 'server/**/*.js'})
  .on('restart', function () {
    console.log('express restarted!');
  });
  return gulp.watch([
    'server/**/*.js',
    'config/**/*.json',
    'src/css/**/*.scss',
    'src/app/**/*.js',
    'src/assets/**/*',
    'src/index.html',
    '!src/app/config.js', // do not listen files which are modified during build process
    ], ['build']);
});

// Tests
gulp.task('webdriver_manager_update', $.protractor.webdriver_update);

gulp.task('test:e2e', ['webdriver_manager_update'], function() {
  var testConfig = require('./config.test.json');
  var testDataDir = path.dirname(path.resolve(testConfig.devicesJson));
  var paths = find.fileSync(/selenium-server-standalone.*\.jar/, 'node_modules/protractor/selenium');
  var args = ['--seleniumServerJar', paths[0], '--baseUrl', 'http://' + testConfig.host + ':' + testConfig.port];
  var protractorConf = {
    configFile: './protractor.config.js',
    args: [args]
  };

  if (!fs.existsSync(testDataDir)) {
    fs.mkdirSync(testDataDir);
  }

  server.listen({path: './server/server.js', env: {"NODE_ENV": "test"}});
  gulp.src(['tests/e2e/**/*.js'], { read: false })
    .pipe($.protractor.protractor(protractorConf)).on('error', function(e) {
      server.kill();
    }).on('end', function() {
      server.kill();
    });
});
gulp.task('default', ['integrate']);
gulp.task('build', ['clean'], function() {
  gulp.start('integrate');
});

<|endoftext|>


<commit_before>var gulp = require('gulp');
var mocha = require('gulp-mocha');
var rename = require('gulp-rename');
var license = require('gulp-license');
var concat = require('gulp-concat');
var bump = require('gulp-bump');
var clean = require('gulp-clean');
var eslint = require('gulp-eslint');
var gulp = require('gulp');
var istanbul = require('gulp-istanbul');
var mocha = require('gulp-mocha');

gulp.task('lint', ['lint-src', 'lint-test']);
gulp.task('lint-src', function() {
    return gulp.src('src/**/*.js').
        pipe(eslint({
            globals: {
                'require': false,
                'module': false
            },
            reset: true, // dz: remove me after linting is finished, else i can't do one at the time
            useEslintrc: true,
        })).
        pipe(eslint.format());
});

gulp.task('lint-test', function() {
    return gulp.src('test/**/*.js').
        pipe(eslint({
            globals: {
                'require': false,
                'module': false,
                'it': false,
                'xit': false,
                'describe': false
            },
            reset: true, // dz: remove me after linting is finished, else i can't do one at the time
            rules: {
                'max-len': [2, 200],
                'no-unused-expressions': 0
            },
            useEslintrc: true,
        })).
        pipe(eslint.format());
});

gulp.task('bump', function() {
    return gulp.
        src('package.json').
        pipe(bump({type: 'patch'})).
        pipe(gulp.dest('./'));
});

gulp.task('test-coverage', function (cb) {
    gulp.src(['./src/**/*.js']).
        pipe(istanbul()).
        pipe(istanbul.hookRequire()).
        on('finish', function () {
            gulp.src(['./test/index.js']).
                pipe(mocha()).
                pipe(istanbul.writeReports()).
                on('end', cb);
        });
});

gulp.task('test', function (cb) {
  gulp.src(['./test/index.js'])
    .pipe(mocha())
    .on('end', cb);
});

gulp.task('dist', ['lint', 'test-coverage']);
<commit_msg>Remove duplicate require statements in gulpfile<commit_after>var gulp = require('gulp');
var mocha = require('gulp-mocha');
var rename = require('gulp-rename');
var license = require('gulp-license');
var concat = require('gulp-concat');
var bump = require('gulp-bump');
var clean = require('gulp-clean');
var eslint = require('gulp-eslint');
var istanbul = require('gulp-istanbul');

gulp.task('lint', ['lint-src', 'lint-test']);

gulp.task('lint-src', function() {
    return gulp.src('src/**/*.js').
        pipe(eslint({
            globals: {
                'require': false,
                'module': false
            },
            reset: true, // dz: remove me after linting is finished, else i can't do one at the time
            useEslintrc: true,
        })).
        pipe(eslint.format());
});

gulp.task('lint-test', function() {
    return gulp.src('test/**/*.js').
        pipe(eslint({
            globals: {
                'require': false,
                'module': false,
                'it': false,
                'xit': false,
                'describe': false
            },
            reset: true, // dz: remove me after linting is finished, else i can't do one at the time
            rules: {
                'max-len': [2, 200],
                'no-unused-expressions': 0
            },
            useEslintrc: true,
        })).
        pipe(eslint.format());
});

gulp.task('bump', function() {
    return gulp.
        src('package.json').
        pipe(bump({type: 'patch'})).
        pipe(gulp.dest('./'));
});

gulp.task('test-coverage', function (cb) {
    gulp.src(['./src/**/*.js']).
        pipe(istanbul()).
        pipe(istanbul.hookRequire()).
        on('finish', function () {
            gulp.src(['./test/index.js']).
                pipe(mocha()).
                pipe(istanbul.writeReports()).
                on('end', cb);
        });
});

gulp.task('test', function (cb) {
  gulp.src(['./test/index.js'])
    .pipe(mocha())
    .on('end', cb);
});

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


<commit_before>var path = require('path');
var vinyl_source = require('vinyl-source-stream');
var _ = require('underscore');
var browserify = require('browserify');
var watchify = require('watchify');
var gulp = require('gulp');
var gulp_util = require('gulp-util');
var gulp_less = require('gulp-less');
var gulp_livereload = require('gulp-livereload');
var gulp_uglify = require('gulp-uglify');
var gulp_minify_css = require('gulp-minify-css');

var generateCssStream = function(){
	var stream = gulp.src('./assets/styles/index.less')
		.pipe( gulp_less({
			paths: [ path.join( __dirname, 'assets', 'styles' ) ]
		}))
		.pipe( gulp.dest('./assets/compiled') );
	return stream;
};

gulp.task( 'compile css', function(){
	generateCssStream();
});

gulp.task( 'compile and watch css', function(){
	var stream = generateCssStream();
	stream.pipe( gulp_livereload() );
	gulp.watch( './assets/styles/**/*.{less,css}', ['compile css'] );
});

var generateBrowserifyBundler = function(){
	var bundler = browserify( './assets/scripts/room.jsx', watchify.args );
	bundler.transform('reactify');
	bundler.transform('browserify-shim');
	return bundler;
};

var generateBrowserifyStream = function( bundler ){
	var stream = bundler.bundle()
		.on( 'error', gulp_util.log.bind( gulp_util, 'Browserify Error' ) )
		.pipe( vinyl_source('room.js') )
		.pipe( gulp.dest('./assets/compiled') );
	return stream;
};

gulp.task( 'compile js', function(){
	var bundler = generateBrowserifyBundler();
	return generateBrowserifyStream( bundler );
});

gulp.task( 'compile and watch js', function(){
	var bundler = watchify( generateBrowserifyBundler() );
	var rebundle = function() {
		console.log('[watchify] Bundling js...');
		return generateBrowserifyStream( bundler );
	};
	bundler.on( 'update', rebundle );
	bundler.on( 'time', function( bundle_time ){
		console.log('[watchify] Bundled in '+ bundle_time +'ms');
	});
	return rebundle();
});

gulp.task( 'minify', function(){
	gulp.src('./assets/compiled/**/*.js')
		.pipe( gulp_uglify() )
		.pipe( gulp.dest('./assets/compiled') );
	gulp.src('./assets/compiled/**/*.css')
		.pipe( gulp_minify_css({
			keepSpecialComments: 0
		}))
		.pipe( gulp.dest('./assets/compiled') );
});

gulp.task( 'compile', ['compile css', 'compile js', 'minify'] );
gulp.task( 'default', ['compile and watch css', 'compile and watch js'] );
<commit_msg>run minification task AFTER compilation tasks<commit_after>var path = require('path');
var vinyl_source = require('vinyl-source-stream');
var _ = require('underscore');
var browserify = require('browserify');
var watchify = require('watchify');
var gulp = require('gulp');
var gulp_util = require('gulp-util');
var gulp_less = require('gulp-less');
var gulp_livereload = require('gulp-livereload');
var gulp_uglify = require('gulp-uglify');
var gulp_minify_css = require('gulp-minify-css');

var minifyAssets = function(){
	gulp.src('./assets/compiled/**/*.js')
		.pipe( gulp_uglify() )
		.pipe( gulp.dest('./assets/compiled') );
	gulp.src('./assets/compiled/**/*.css')
		.pipe( gulp_minify_css({
			keepSpecialComments: 0
		}))
		.pipe( gulp.dest('./assets/compiled') );
};

var generateCssStream = function(){
	var stream = gulp.src('./assets/styles/index.less')
		.pipe( gulp_less({
			paths: [ path.join( __dirname, 'assets', 'styles' ) ]
		}))
		.pipe( gulp.dest('./assets/compiled') );
	return stream;
};

gulp.task( 'compile css', function(){
	generateCssStream();
});

gulp.task( 'compile and watch css', function(){
	var stream = generateCssStream();
	stream.pipe( gulp_livereload() );
	gulp.watch( './assets/styles/**/*.{less,css}', ['compile css'] );
});

var generateBrowserifyBundler = function(){
	var bundler = browserify( './assets/scripts/room.jsx', watchify.args );
	bundler.transform('reactify');
	bundler.transform('browserify-shim');
	return bundler;
};

var generateBrowserifyStream = function( bundler ){
	var stream = bundler.bundle()
		.on( 'error', gulp_util.log.bind( gulp_util, 'Browserify Error' ) )
		.pipe( vinyl_source('room.js') )
		.pipe( gulp.dest('./assets/compiled') );
	return stream;
};

gulp.task( 'compile js', function(){
	var bundler = generateBrowserifyBundler();
	return generateBrowserifyStream( bundler );
});

gulp.task( 'compile and watch js', function(){
	var bundler = watchify( generateBrowserifyBundler() );
	var rebundle = function() {
		console.log('[watchify] Bundling js...');
		return generateBrowserifyStream( bundler );
	};
	bundler.on( 'update', rebundle );
	bundler.on( 'time', function( bundle_time ){
		console.log('[watchify] Bundled in '+ bundle_time +'ms');
	});
	return rebundle();
});

gulp.task( 'compile and minify', ['compile css', 'compile js'], minifyAssets );

gulp.task( 'compile', ['compile and minify'] );
gulp.task( 'default', ['compile and watch css', 'compile and watch js'] );
<|endoftext|>


<commit_before>const gulp = require('gulp');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const uglify = require('gulp-uglify');
const cleanCSS = require('gulp-clean-css');
const imagemin = require('gulp-imagemin');
const fileInclude = require('gulp-file-include');
const concat = require('gulp-concat');
const babel = require('gulp-babel');

// **UIKit Only** scripts to concatenate and minify.
const UIKitScripts = [
    'src/uikit/js/uikit.js',
    'src/uikit/js/components/slideshow.js'
    ];

// **Created Only** scripts to concatenate and minify.
const scripts = [
    'src/js/events.js',
    'src/js/main.js',
    'src/js/header.js'
    ];

gulp.task('sass', () => {
    return gulp.src('src/sass/main.scss')
        .pipe(sass())
        .pipe(autoprefixer({
            browsers: ['last 3 versions']
        }))
        .pipe(cleanCSS())
        .pipe(concat('main.min.css'))
        .pipe(gulp.dest('build/css'));
});

gulp.task('uk-scripts', () => {
    return gulp.src(UIKitScripts)
        .pipe(concat('uikit.min.js'))
        .pipe(gulp.dest('build/js'))
        .pipe(uglify())
        .pipe(gulp.dest('build/js'));
});

gulp.task('scripts', () => {
    return gulp.src(scripts)
        .pipe(concat('main.min.js'))
        .pipe(babel({
            presets: ['es2015']
        }))
        .pipe(gulp.dest('build/js'))
        .pipe(uglify())
        .pipe(gulp.dest('build/js'));
});

gulp.task('html', () => {
    return gulp.src(['src/index.html', 'src/calendar.html'])
        .pipe(fileInclude({
            prefix: '@@',
            basepath: '@file'
        }))
        .pipe(gulp.dest('build'));
});

gulp.task('img', () => {
    return gulp.src('src/img/*')
        .pipe(imagemin())
        .pipe(gulp.dest('build/img'));
});

<<<<<<< HEAD
gulp.task('default', ['sass', 'uk-scripts', 'scripts', 'html'], () => {
=======
gulp.task('fonts', () => {
    return gulp.src('src/fonts/*')
        .pipe(gulp.dest('build/fonts'));
});

gulp.task('default', ['sass', 'uk-scripts', 'scripts', 'html', 'img', 'fonts'], () => {
>>>>>>> origin/header
    gulp.watch('src/sass/*.scss', ['sass']);
    gulp.watch('src/js/*.js', ['scripts']);
    gulp.watch(['src/index.html', 'src/partials/*.html'], ['html']);
});
<commit_msg>Fix gulpfile.js build<commit_after>const gulp = require('gulp');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const uglify = require('gulp-uglify');
const cleanCSS = require('gulp-clean-css');
const imagemin = require('gulp-imagemin');
const fileInclude = require('gulp-file-include');
const concat = require('gulp-concat');
const babel = require('gulp-babel');

// **UIKit Only** scripts to concatenate and minify.
const UIKitScripts = [
    'src/uikit/js/uikit.js',
    'src/uikit/js/components/slideshow.js'
    ];

// **Created Only** scripts to concatenate and minify.
const scripts = [
    'src/js/events.js',
    'src/js/main.js',
    'src/js/header.js'
    ];

gulp.task('sass', () => {
    return gulp.src('src/sass/main.scss')
        .pipe(sass())
        .pipe(autoprefixer({
            browsers: ['last 3 versions']
        }))
        .pipe(cleanCSS())
        .pipe(concat('main.min.css'))
        .pipe(gulp.dest('build/css'));
});

gulp.task('uk-scripts', () => {
    return gulp.src(UIKitScripts)
        .pipe(concat('uikit.min.js'))
        .pipe(gulp.dest('build/js'))
        .pipe(uglify())
        .pipe(gulp.dest('build/js'));
});

gulp.task('scripts', () => {
    return gulp.src(scripts)
        .pipe(concat('main.min.js'))
        .pipe(babel({
            presets: ['es2015']
        }))
        .pipe(gulp.dest('build/js'))
        .pipe(uglify())
        .pipe(gulp.dest('build/js'));
});

gulp.task('html', () => {
    return gulp.src(['src/index.html', 'src/calendar.html'])
        .pipe(fileInclude({
            prefix: '@@',
            basepath: '@file'
        }))
        .pipe(gulp.dest('build'));
});

gulp.task('img', () => {
    return gulp.src('src/img/*')
        .pipe(imagemin())
        .pipe(gulp.dest('build/img'));
});

gulp.task('fonts', () => {
    return gulp.src('src/fonts/*')
        .pipe(gulp.dest('build/fonts'));
});

gulp.task('default', ['sass', 'uk-scripts', 'scripts', 'html', 'img', 'fonts'], () => {
    gulp.watch('src/sass/*.scss', ['sass']);
    gulp.watch('src/js/*.js', ['scripts']);
    gulp.watch(['src/index.html', 'src/partials/*.html'], ['html']);
});
<|endoftext|>


<commit_before>
/* Gulpfile

 To Do List
 -------------------------------------------
 1. Icons and Images combine
 3. Improve overall
 4. Improve Documentation
 5. Add gulp-bower-files
 6. Add gulp-cache
 - gulp-html2jade?
 7. if production env =
    if dev env =

 ------------------------------------------- */

/* Dependencies
 ------------------------------------------- */
  var gulp       = require('gulp');
  var $ = require('gulp-load-plugins')();
    // - plugins used

      // size            = require('gulp-size'),
      // jade            = require('gulp-jade'),
      // sass            = require('gulp-ruby-sass'),
      // uncss           = require('gulp-uncss'),
      // csso            = require('gulp-csso'),
      // gulpif          = require('gulp-if'),
      // changed         = require('gulp-changed')
      // autoprefixer    = require('gulp-autoprefixer'),
      // imagemin        = require('gulp-imagemin'),
      // cache           = require('gulp-cache'),
      // uglify          = require('gulp-uglify'),
      // size            = require('gulp-size'),
      // notify          = require('gulp-notify'),
      // concat          = require('gulp-concat'),
      // coffee          = require('gulp-coffee'),
      // cssimport       = require("gulp-cssimport");
      // rename          = require('gulp-rename');

  var es = require('event-stream');
  var del = require('del');
  var runSequence = require('run-sequence');
  var browserSync = require('browser-sync');
  var reload = browserSync.reload;

/* Scripts - http://goo.gl/UOpv25 > $ gulp scripts
 ------------------------------------------- */
  gulp.task('scripts', function() {
    var coffeeToJs = gulp.src('app/assets/scripts/**/*.coffee')          // Coffee Directory
    .pipe($.coffee());                                                   // Coffee
    var js = gulp.src('app/assets/scripts/**/*.js');                     // Js Directory
    return es.merge(coffeeToJs, js)                                      // Merge js + coffee with event-stream
      .pipe($.concat('scripts.min.js'))                                  // Concat
      .pipe($.uglify())                                                  // Uglify
      .pipe(gulp.dest('_public/assets/scripts'))                         // Dest Path
      .pipe($.notify({ message: 'scripts done' }))                       // Notify
      .pipe($.size({title: 'scripts size'}));                            // Size
  });

/* Styles Task > $ gulp styles
 ------------------------------------------- */
  gulp.task('styles', function () {
    return gulp.src(
      [ 'app/assets/scss/**/*.scss',
        '!app/assets/scss/variables.scss',                               // omit variable.scs from
        'Gemfile'
      ])                                                                 // css directory + Gemfile for globbing
      .pipe($.changed('scss', {extension: '.scss'}))                     // Check to see if changed
      .pipe($.rubySass({                                                 // Use gulp-rubySass
        bundleExec: true,
        require: 'sass-globbing',                           									      // - true or false for bundle
        style: 'nested',                                             // - nested, compact, compressed, expanded
        precision: 10                                                    // - default 3, to use when outputting decimal numbers.
        })
        .on('error', function(err){                                      // Output SASS Error
          console.log(err.message);
          this.end();
        })
      )
      // https://github.com/postcss/autoprefixer#browsers
      .pipe($.autoprefixer(                                              // Autoprefixer Browsers
        'last 2 version',                                                 // - last 2 version
        'safari 5',                                                       // - safari 5
        'ie 8',                                                           // - ie 8
        'ie 9',                                                           // - ie 9
        'opera 12.1',                                                     // - opera 12.1
        'ios 6',                                                          // - ios 6
        'android 4'                                                       // - android 4'
      ))
      .pipe(gulp.dest('.dev/css/'))                                          // Dev nested before ccso > delete
      .pipe($.if('**/*.css', $.csso()))
      //.pipe($.rename({suffix: '.min'}))                                  // Add gulp-csso to minify
      .pipe(gulp.dest('_public/assets/css'))                             // Destination Path
      .pipe($.notify({ message: 'Styles completed fool' }))              // Notify
      .pipe($.size({title: 'styles size of'}));                          // Size
  });

  // uncss for removing used styles: $ gulp uncss
  gulp.task('uncss', ['html', 'styles'], function() {                    // Build HTML & Style files for uncss to run
    return gulp.src('_public/assets/css/*.css')                          // CSS Directory
      .pipe($.uncss({                                                    // Use gulp-uncss
        html: [
          '_public/index.html',                                            // List HTML files
          '_public/styleguide.html'
        ]
        // ,
        // ignore: [                                                     // CSS Selectors to ignore
        //   /.class-name/
        // ]
      }))
      .pipe($.csso())                                                    // Add gulp-sso to Minify
      .pipe(gulp.dest('_public/assets/css'))                             // Destination Path
      .pipe($.notify({ message: 'uncss completed' }))                    // Notify
      .pipe($.size({title: 'styles uncss size of'}));                    // Size
  });

// hack //
// if bower css covert to scss hack - fix later
// https://github.com/sass/sass/issues/556#issuecomment-50825607
  gulp.task('cssToSass', ['styles'],function() {
    return gulp.src('components-bower/**/*.css')                         // Add Directory
      // .pipe($.cached('cssToSass'))                                    // Add Cached
      .pipe($.rename(function(path) {                                 // use Rename
        path.basename = '_' + path.basename;
        path.extname = '.scss';
      }))
      .pipe(gulp.dest('components-bower/converted-scss/'))               // Add gulp-sso to Minify
      .pipe($.notify({ message: 'cssToSass' }))                          // Notify
      .pipe($.size({title: 'cssToSass size of'}));                       // Size
  });

/* Jade > $ gulp jade
 ------------------------------------------- */
  gulp.task('jade', function() {
    return gulp.src(
      [
        'app/**/*.jade',                                                 // Jade Directory
        '!app/_partials/**/*.jade',                                      // Exclude _partials directory from compiling in /app - app/_partials/**/*.html
      ])
      .pipe($.jade({                                                     // Use gulp-jade
        pretty: false                                                    // All Jade Options are available - http://jade-lang.com/api/
      }))
      .on('error', function(err){
        console.log(err.message);
        this.end();
      })
      .pipe(gulp.dest('_public'))
      // run and html min here to min html for .md files
      .pipe($.notify({ message: 'HTML built' }))                         // Notify
      .pipe($.size({title: 'jade size of'}));                            // Size
  });

/* HTML > $ gulp html
 ------------------------------------------- */
  gulp.task('html', function() {
    return gulp.src('app/**/*.html')
      .pipe($.htmlmin({collapseWhitespace: true}))
      .pipe(gulp.dest('_public'))
      .pipe($.notify({ message: 'HTML built' }))                         // Notify
      .pipe($.size({title: 'HTML size of'}));                            // Size
  });

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

  // images > $ gulp images
  gulp.task('images', function () {
    return gulp.src('app/assets/images/**/*')                              // Images Directory
      .pipe($.imagemin({                                                   // Use gulp-imagemin
        optimizationLevel: 3,                                               // Default: 3: level between 0 and 7.
        progressive: true,                                                  // Lossless conversion to progressive.
        interlaced: true                                                    // Interlace gif for progressive rendering.
      }))
      .pipe(gulp.dest('_public/assets/images'))                            // Destination Path
      .pipe($.notify({ message: 'Images built and minified' }))            // Notify
      .pipe($.size({title: 'images size of'}));                            // Size
  });

  // icons > $ gulp icons
  gulp.task('icons', function () {
    return gulp.src(                                                       // Icons Directory
      [
        'app/assets/icons/**/*'
      ])
      .pipe($.imagemin({                                                   // Use gulp-imagemin
        optimizationLevel: 3,                                              // Default: 3: level between 0 and 7.
        progressive: true,                                                 // Lossless conversion to progressive.
        interlaced: true                                                   // Interlace gif for progressive rendering.
      }))
      .pipe(gulp.dest('_public/assets/icons'))                             // Destination Path
      .pipe($.notify({ message: 'Icons built and minified' }))             // Notify
      .pipe($.size({title: 'icons size of'}));                             // Size
  });

/* Copy Task
 ------------------------------------------- */

  // copy root files > $ gulp copy
  gulp.task('copy', function () {
    return gulp.src('app/*.{txt,md,htaccess}', {
      dot: true
    }).pipe(gulp.dest('_public'))                                          // Destination Path
    .pipe($.notify({ message: 'root files copied' }))                      // Notify
    .pipe($.size({title: 'root files size of'}));                          // Size
  });

  // fonts > $ gulp fonts
  gulp.task('fonts', function () {
    return gulp.src('app/assets/fonts/**/*')                               // Fonts Directory
      .pipe(gulp.dest('_public/assets/fonts'))                             // Destination Path
      .pipe($.notify({ message: 'Fonts built' }))                          // Notify
      .pipe($.size({title: 'fonts size of'}));                             // Size
  });

/* Clean Output Directory > $ gulp serve
 ------------------------------------------- */
  gulp.task('clean', function(cb) {                                        // Clean
      del(['_public'] , cb)
  });

/* Server via gulp-browserSync > $ gulp serve
 ------------------------------------------- */
  gulp.task('serve', ['default'], function() {
      browserSync({
          server: {
              baseDir: "_public"
          },
          port: 3001,
          // proxy: "localhost:9001",
          open: true,
          notify: true
      });
      gulp.watch(['app/assets/scss/**/*'], ['styles', reload]);
      gulp.watch(['app/assets/scripts/**/*.{js,coffee}'], ['scripts', reload]);
      gulp.watch(['app/**/*.{jade,md}'], ['jade', reload]);
      gulp.watch(['app/**/*.html'], ['html', reload]);
      gulp.watch(['app/assets/images/**/*'], reload);
      gulp.watch(['app/assets/icons/**/*'], reload);
      gulp.watch(['app/assets/fonts/**/*'], reload);
  });

  // just build assets using runSequence > $ gulp assets
  gulp.task('assets', function (cb) {
    runSequence(['styles', 'scripts', 'images', 'fonts', 'icons'], cb);
  });

  // default: clean and build _public using runSequence > $ gulp default
  gulp.task('default', ['clean'], function (cb) {
    runSequence('styles', ['html', 'jade', 'scripts', 'images', 'fonts', 'icons', 'copy'], cb);
  });

  // publish: build and publish to github branch:'' > $ gulp publish
  gulp.task('publish', function () {
    return gulp.src("_public/**/*")
      .pipe($.ghPages({
        branch: 'gh-pages'
      }))
  });
<commit_msg>house keeping<commit_after>
/* Gulpfile

 To Do List
 -------------------------------------------
 1. Icons and Images combine
 3. Improve overall
 4. Improve Documentation
 5. Add gulp-bower-files
 6. Add gulp-cache
 - gulp-html2jade?
 7. if production env =
    if dev env =

 ------------------------------------------- */

/* Dependencies
 ------------------------------------------- */
  var gulp       = require('gulp');
  var $ = require('gulp-load-plugins')();
    // - plugins used

      // size            = require('gulp-size'),
      // jade            = require('gulp-jade'),
      // sass            = require('gulp-ruby-sass'),
      // uncss           = require('gulp-uncss'),
      // csso            = require('gulp-csso'),
      // gulpif          = require('gulp-if'),
      // changed         = require('gulp-changed')
      // autoprefixer    = require('gulp-autoprefixer'),
      // imagemin        = require('gulp-imagemin'),
      // cache           = require('gulp-cache'),
      // uglify          = require('gulp-uglify'),
      // size            = require('gulp-size'),
      // notify          = require('gulp-notify'),
      // concat          = require('gulp-concat'),
      // coffee          = require('gulp-coffee'),
      // cssimport       = require("gulp-cssimport");
      // rename          = require('gulp-rename');

  var es = require('event-stream');
  var del = require('del');
  var runSequence = require('run-sequence');
  var browserSync = require('browser-sync');
  var reload = browserSync.reload;

/* Scripts - http://goo.gl/UOpv25 > $ gulp scripts
 ------------------------------------------- */
  gulp.task('scripts', function() {
    var coffeeToJs = gulp.src('app/assets/scripts/**/*.coffee')          // Coffee Directory
    .pipe($.coffee());                                                   // Coffee
    var js = gulp.src('app/assets/scripts/**/*.js');                     // Js Directory
    return es.merge(coffeeToJs, js)                                      // Merge js + coffee with event-stream
      .pipe($.concat('scripts.min.js'))                                  // Concat
      .pipe($.uglify())                                                  // Uglify
      .pipe(gulp.dest('_public/assets/scripts'))                         // Dest Path
      .pipe($.notify({ message: 'scripts done' }))                       // Notify
      .pipe($.size({title: 'scripts size'}));                            // Size
  });

/* Styles Task > $ gulp styles
 ------------------------------------------- */
  gulp.task('styles', function () {
    return gulp.src(
      [ 'app/assets/scss/**/*.scss',
        '!app/assets/scss/variables.scss',                               // omit variable.scs from
        'Gemfile'
      ])                                                                 // css directory + Gemfile for globbing
      .pipe($.changed('scss', {extension: '.scss'}))                     // Check to see if changed
      .pipe($.rubySass({                                                 // Use gulp-rubySass
        bundleExec: true,
        require: 'sass-globbing',                           						 // - true or false for bundle
        style: 'nested',                                                 // - nested, compact, compressed, expanded
        precision: 10                                                    // - default 3, to use when outputting decimal numbers.
        })
        .on('error', function(err){                                      // Output SASS Error
          console.log(err.message);
          this.end();
        })
      )
      // https://github.com/postcss/autoprefixer#browsers
      .pipe($.autoprefixer(                                               // Autoprefixer Browsers
        'last 2 version',                                                 // - last 2 version
        'safari 5',                                                       // - safari 5
        'ie 8',                                                           // - ie 8
        'ie 9',                                                           // - ie 9
        'opera 12.1',                                                     // - opera 12.1
        'ios 6',                                                          // - ios 6
        'android 4'                                                       // - android 4'
      ))
      .pipe(gulp.dest('.dev/css/'))                                          // Dev nested before ccso > delete
      .pipe($.if('**/*.css', $.csso()))
      //.pipe($.rename({suffix: '.min'}))                                  // Add gulp-csso to minify
      .pipe(gulp.dest('_public/assets/css'))                             // Destination Path
      .pipe($.notify({ message: 'Styles completed fool' }))              // Notify
      .pipe($.size({title: 'styles size of'}));                          // Size
  });

  // uncss for removing used styles: $ gulp uncss
  gulp.task('uncss', ['html', 'styles'], function() {                    // Build HTML & Style files for uncss to run
    return gulp.src('_public/assets/css/*.css')                          // CSS Directory
      .pipe($.uncss({                                                    // Use gulp-uncss
        html: [
          '_public/index.html',                                            // List HTML files
          '_public/styleguide.html'
        ]
        // ,
        // ignore: [                                                     // CSS Selectors to ignore
        //   /.class-name/
        // ]
      }))
      .pipe($.csso())                                                    // Add gulp-sso to Minify
      .pipe(gulp.dest('_public/assets/css'))                             // Destination Path
      .pipe($.notify({ message: 'uncss completed' }))                    // Notify
      .pipe($.size({title: 'styles uncss size of'}));                    // Size
  });

// hack //
// if bower css covert to scss hack - fix later
// https://github.com/sass/sass/issues/556#issuecomment-50825607
  gulp.task('cssToSass', ['styles'],function() {
    return gulp.src('components-bower/**/*.css')                         // Add Directory
      // .pipe($.cached('cssToSass'))                                    // Add Cached
      .pipe($.rename(function(path) {                                    // use Rename
        path.basename = '_' + path.basename;
        path.extname = '.scss';
      }))
      .pipe(gulp.dest('components-bower/converted-scss/'))               // Add gulp-sso to Minify
      .pipe($.notify({ message: 'cssToSass' }))                          // Notify
      .pipe($.size({title: 'cssToSass size of'}));                       // Size
  });

/* Jade > $ gulp jade
 ------------------------------------------- */
  gulp.task('jade', function() {
    return gulp.src(
      [
        'app/**/*.jade',                                                 // Jade Directory
        '!app/_partials/**/*.jade',                                      // Exclude _partials directory from compiling in /app - app/_partials/**/*.html
      ])
      .pipe($.jade({                                                     // Use gulp-jade
        pretty: false                                                    // All Jade Options are available - http://jade-lang.com/api/
      }))
      .on('error', function(err){
        console.log(err.message);
        this.end();
      })
      .pipe(gulp.dest('_public'))
      // run and html min here to min html for .md files
      .pipe($.notify({ message: 'HTML built' }))                         // Notify
      .pipe($.size({title: 'jade size of'}));                            // Size
  });

/* HTML > $ gulp html
 ------------------------------------------- */
  gulp.task('html', function() {
    return gulp.src('app/**/*.html')
      .pipe($.htmlmin({collapseWhitespace: true}))
      .pipe(gulp.dest('_public'))
      .pipe($.notify({ message: 'HTML built' }))                         // Notify
      .pipe($.size({title: 'HTML size of'}));                            // Size
  });

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

  // images > $ gulp images
  gulp.task('images', function () {
    return gulp.src('app/assets/images/**/*')                              // Images Directory
      .pipe($.imagemin({                                                   // Use gulp-imagemin
        optimizationLevel: 3,                                               // Default: 3: level between 0 and 7.
        progressive: true,                                                  // Lossless conversion to progressive.
        interlaced: true                                                    // Interlace gif for progressive rendering.
      }))
      .pipe(gulp.dest('_public/assets/images'))                            // Destination Path
      .pipe($.notify({ message: 'Images built and minified' }))            // Notify
      .pipe($.size({title: 'images size of'}));                            // Size
  });

  // icons > $ gulp icons
  gulp.task('icons', function () {
    return gulp.src(                                                       // Icons Directory
      [
        'app/assets/icons/**/*'
      ])
      .pipe($.imagemin({                                                   // Use gulp-imagemin
        optimizationLevel: 3,                                              // Default: 3: level between 0 and 7.
        progressive: true,                                                 // Lossless conversion to progressive.
        interlaced: true                                                   // Interlace gif for progressive rendering.
      }))
      .pipe(gulp.dest('_public/assets/icons'))                             // Destination Path
      .pipe($.notify({ message: 'Icons built and minified' }))             // Notify
      .pipe($.size({title: 'icons size of'}));                             // Size
  });

/* Copy Task
 ------------------------------------------- */

  // copy root files > $ gulp copy
  gulp.task('copy', function () {
    return gulp.src('app/*.{txt,md,htaccess}', {
      dot: true
    }).pipe(gulp.dest('_public'))                                          // Destination Path
    .pipe($.notify({ message: 'root files copied' }))                      // Notify
    .pipe($.size({title: 'root files size of'}));                          // Size
  });

  // fonts > $ gulp fonts
  gulp.task('fonts', function () {
    return gulp.src('app/assets/fonts/**/*')                               // Fonts Directory
      .pipe(gulp.dest('_public/assets/fonts'))                             // Destination Path
      .pipe($.notify({ message: 'Fonts built' }))                          // Notify
      .pipe($.size({title: 'fonts size of'}));                             // Size
  });

/* Clean Output Directory > $ gulp serve
 ------------------------------------------- */
  gulp.task('clean', function(cb) {                                        // Clean
      del(['_public'] , cb)
  });

/* Server via gulp-browserSync > $ gulp serve
 ------------------------------------------- */
  gulp.task('serve', ['default'], function() {
      browserSync({
          server: {
              baseDir: "_public"
          },
          port: 3001,
          // proxy: "localhost:9001",
          open: true,
          notify: true
      });
      gulp.watch(['app/assets/scss/**/*'], ['styles', reload]);
      gulp.watch(['app/assets/scripts/**/*.{js,coffee}'], ['scripts', reload]);
      gulp.watch(['app/**/*.{jade,md}'], ['jade', reload]);
      gulp.watch(['app/**/*.html'], ['html', reload]);
      gulp.watch(['app/assets/images/**/*'], reload);
      gulp.watch(['app/assets/icons/**/*'], reload);
      gulp.watch(['app/assets/fonts/**/*'], reload);
  });

  // just build assets using runSequence > $ gulp assets
  gulp.task('assets', function (cb) {
    runSequence(['styles', 'scripts', 'images', 'fonts', 'icons'], cb);
  });

  // default: clean and build _public using runSequence > $ gulp default
  gulp.task('default', ['clean'], function (cb) {
    runSequence('styles', ['html', 'jade', 'scripts', 'images', 'fonts', 'icons', 'copy'], cb);
  });

  // publish: build and publish to github branch:'' > $ gulp publish
  gulp.task('publish', function () {
    return gulp.src("_public/**/*")
      .pipe($.ghPages({
        branch: 'gh-pages'
      }))
  });
<|endoftext|>


<commit_before>var gulp = require('gulp'),
    sass = require('gulp-sass'),
    rename = require('gulp-rename'),
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat'),
    cache = require('gulp-cache'),
    del = require('del'),
    git = require('gulp-git'),
    bump = require('gulp-bump'),
    tag = require('gulp-tag-version');

var proc = require('child_process');

var css_src = './public/scss/*.scss';
var js_src = [
  './public/js/dnss.js',
  './public/js/skill.js',
  './public/js/description.js'
];

gulp.task('css', function () {
  gulp.src(css_src)
      .pipe(concat('dnss.scss'))
      .pipe(sass({outputStyle: 'compressed'}))
      .pipe(rename({suffix: '.min'}))
      .pipe(gulp.dest('./public/css'));
});

gulp.task('js', function() {
  return gulp.src(js_src)
    .pipe(concat('dnss.js'))
    .pipe(rename({suffix: '.min'}))
    .pipe(uglify())
    .pipe(gulp.dest('./public/js'))
});

gulp.task('watch', function() {
  gulp.watch(css_src, ['css']);
  gulp.watch(js_src, ['js']);
});

function inc(importance) {
  return function() {
    gulp.src('./package.json')
        .pipe(bump({type: importance}))
        .pipe(gulp.dest('./'))
        .pipe(git.commit('[gulp] bumping package version'))
        .pipe(tag());
    git.push('origin', 'master', function (err) {
      if (err) throw err;
    });

    git.push('origin', 'master', {args: '--tags'}, function (err) {
      if (err) throw err;
    });
  };
}

gulp.task('patch', inc('patch'));
gulp.task('feature', inc('minor'));
gulp.task('release', inc('major'));
gulp.task('default', ['css', 'js'], function() {});<commit_msg>Only using gulp to push tags, nothing else<commit_after>var gulp = require('gulp'),
    sass = require('gulp-sass'),
    rename = require('gulp-rename'),
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat'),
    cache = require('gulp-cache'),
    del = require('del'),
    git = require('gulp-git'),
    bump = require('gulp-bump'),
    tag = require('gulp-tag-version');

var proc = require('child_process');

var css_src = './public/scss/*.scss';
var js_src = [
  './public/js/dnss.js',
  './public/js/skill.js',
  './public/js/description.js'
];

gulp.task('css', function () {
  gulp.src(css_src)
      .pipe(concat('dnss.scss'))
      .pipe(sass({outputStyle: 'compressed'}))
      .pipe(rename({suffix: '.min'}))
      .pipe(gulp.dest('./public/css'));
});

gulp.task('js', function() {
  return gulp.src(js_src)
    .pipe(concat('dnss.js'))
    .pipe(rename({suffix: '.min'}))
    .pipe(uglify())
    .pipe(gulp.dest('./public/js'))
});

gulp.task('watch', function() {
  gulp.watch(css_src, ['css']);
  gulp.watch(js_src, ['js']);
});

function inc(importance) {
  return function() {
    gulp.src('./package.json')
        .pipe(bump({type: importance}))
        .pipe(gulp.dest('./'))
        .pipe(git.commit('[gulp] bumping package version'))
        .pipe(tag());

    git.push('origin', 'master', {args: '--tags'}, function (err) {
      if (err) throw err;
    });
  };
}

gulp.task('patch', inc('patch'));
gulp.task('feature', inc('minor'));
gulp.task('release', inc('major'));
gulp.task('default', ['css', 'js'], function() {});<|endoftext|>


<commit_before>'use strict';

const autoprefixer = require('gulp-autoprefixer');
const fs = require('fs');
const gulp = require('gulp');
const headerLicense = require('gulp-header-license');
const del = require('del');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
const vinylNamed = require('vinyl-named');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');

const webpackConfig = require('./webpack.config');

const SRC_DIR = './src';
const BUILD_DIR = './dist';

gulp.task('clean', () => del(BUILD_DIR));

gulp.task('configs', () => {
  return gulp.src(`${SRC_DIR}/*`).pipe(gulp.dest(BUILD_DIR));
});

gulp.task('icons', () => {
  return gulp.src(`${SRC_DIR}/icons/**/*.png`).pipe(gulp.dest(`${BUILD_DIR}/icons`));
});

gulp.task('scripts', () => {
  return gulp.src(`${SRC_DIR}/js/*.js`)
    .pipe(vinylNamed())
    .pipe(webpackStream(webpackConfig, webpack))
    .pipe(gulp.dest(`${BUILD_DIR}/js`));
});

gulp.task('scripts:dist', ['scripts'], () => {
  return gulp.src(`${BUILD_DIR}/js/**/*.js`)
    .pipe(uglify())
    .pipe(headerLicense('/* ' + fs.readFileSync('./LICENSE') + '*/'))
    .pipe(gulp.dest(`${BUILD_DIR}/js`));
});

gulp.task('build', ['configs', 'icons', 'scripts']);

gulp.task('dist', ['scripts:dist']);

gulp.task('watch', ['build'], () => {
  return gulp.watch(`${SRC_DIR}/**/*`, ['build']);
});
<commit_msg>Fixed a couple of build issues in gulpfile<commit_after>'use strict';

const autoprefixer = require('gulp-autoprefixer');
const fs = require('fs');
const gulp = require('gulp');
const headerLicense = require('gulp-header-license');
const del = require('del');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
const vinylNamed = require('vinyl-named');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');

const webpackConfig = require('./webpack.config');

const SRC_DIR = './src';
const BUILD_DIR = './dist';

gulp.task('clean', () => del(BUILD_DIR));

gulp.task('configs', () => {
  return gulp.src(`${SRC_DIR}/manifest.json`).pipe(gulp.dest(BUILD_DIR));
});

gulp.task('icons', () => {
  return gulp.src(`${SRC_DIR}/icons/**/*.png`).pipe(gulp.dest(`${BUILD_DIR}/icons`));
});

gulp.task('scripts', () => {
  return gulp.src(`${SRC_DIR}/js/*.js`)
    .pipe(vinylNamed())
    .pipe(webpackStream(webpackConfig, webpack))
    .pipe(gulp.dest(`${BUILD_DIR}/js`));
});

gulp.task('scripts:dist', ['scripts'], () => {
  return gulp.src(`${BUILD_DIR}/js/**/*.js`)
    .pipe(uglify())
    .pipe(headerLicense('/* ' + fs.readFileSync('./LICENSE') + '*/'))
    .pipe(gulp.dest(`${BUILD_DIR}/js`));
});

gulp.task('build', ['configs', 'icons', 'scripts']);
gulp.task('build:dist', ['configs', 'icons', 'scripts:dist']);

gulp.task('watch', ['build'], () => {
  return gulp.watch(`${SRC_DIR}/**/*`, ['build']);
});
<|endoftext|>


<commit_before>// npm install --save-dev   gulp  gulp-changed  gulp-jscs  gulp-uglify  gulp-watch gulp-rev  gulp-minify-css gulp-watch  gulp-eslint

var gulp = require('gulp'),
    changed = require('gulp-changed'),
    // jscs = require('gulp-jscs'),
    uglify = require('gulp-uglify'),
    // watch = require('gulp-watch'),
    rev = require('gulp-rev'),
    minifycss = require('gulp-minify-css');
var eslint = require('gulp-eslint');

var SCRIPT_SRC = 'web/scripts/**/*.js';
var STYLE_SRC = 'web/styles/**/*.css';
var buildFolder = 'web/build';

/** gulp 3.9
 gulp.task('minifyscript', function() {
    return gulp.src(SCRIPT_SRC, {base: 'web'})
    // `changed` 任务需要提前知道目标目录位置才能找出哪些文件是被修改过的
        //.pipe(changed(buildFolder))// 只有被更改过的文件才会通过这里
        //.pipe(watch(SRC))//只重新编译被更改过的文件
        //.pipe(jscs())
        .pipe(uglify())
        //.pipe(gulp.dest(buildFolder))//// copy original src to build dir
        .pipe(rev())
        .pipe(gulp.dest(buildFolder))// write rev'd src to build dir
        .pipe(rev.manifest('web/build/rev-manifest.json',{
            base: buildFolder,
            merge: true // merge with the existing manifest (if one exists)
        }))
        .pipe(gulp.dest(buildFolder));//compressed file  // write manifest to build dir
});

 gulp.task('minifycss', function() {
    return gulp.src(STYLE_SRC, {base: 'web'})
        .pipe(minifycss())   //执行压缩
        //.pipe(gulp.dest(buildFolder))//// copy original src to build dir
        .pipe(rev())
        .pipe(gulp.dest(buildFolder))// write rev'd src to build dir
        .pipe(rev.manifest('web/build/rev-manifest.json', {
            base: buildFolder,
            merge: true // merge with the existing manifest (if one exists)
        }))
        .pipe(gulp.dest(buildFolder));//compressed file  // write manifest to build dir
});

 gulp.task('default', function () {
    // gulp.watch(SCRIPT_SRC, ['script', 'minifycss'], function(event){
    //     //console.log(event);
    // });

    gulp.start('minifyscript', 'minifycss');
});
 */

//gulp 4.0
var del = require('del');

function minifyScript() {
    return gulp.src(SCRIPT_SRC, {base: 'web'})
    // `changed` 任务需要提前知道目标目录位置才能找出哪些文件是被修改过的
    //.pipe(changed(buildFolder))// 只有被更改过的文件才会通过这里
    //.pipe(watch(SRC))//只重新编译被更改过的文件
    //.pipe(jscs())
        .pipe(uglify())
        //.pipe(gulp.dest(buildFolder))//// copy original src to build dir
        .pipe(rev())
        .pipe(gulp.dest(buildFolder))// write rev'd src to build dir
        .pipe(rev.manifest('web/build/rev-manifest.json', {
            base: buildFolder,
            merge: true // merge with the existing manifest (if one exists)
        }))
        .pipe(gulp.dest(buildFolder));//compressed file  // write manifest to build dir
}

function minifyCss() {
    return gulp.src(STYLE_SRC, {base: 'web'})
        .pipe(minifycss())   //执行压缩
        //.pipe(gulp.dest(buildFolder))//// copy original src to build dir
        .pipe(rev())
        .pipe(gulp.dest(buildFolder))// write rev'd src to build dir
        .pipe(rev.manifest('web/build/rev-manifest.json', {
            base: buildFolder,
            merge: true // merge with the existing manifest (if one exists)
        }))
        .pipe(gulp.dest(buildFolder));//compressed file  // write manifest to build dir
}

/* Not all tasks need to use streams, a gulpfile is just another node program
 * and you can use all packages available on npm, but it must return either a
 * Promise, a Stream or take a callback and call it
 */
function clean() {
    // You can use multiple globbing patterns as you would with `gulp.src`,
    // for example if you are using del 2.0 or above, return its promise
    return del(['web/assets/*', 'web/build']);
}

function watch() {
    gulp.watch(SCRIPT_SRC, minifyScript);
    gulp.watch(STYLE_SRC, minifyCss);
}

/*
 * You can use CommonJS `exports` module notation to declare tasks
 */
exports.clean = clean;
exports.scripts = minifyScript;
exports.styles = minifyCss;
exports.watch = watch;

/*
 * Specify if tasks run in series or parallel using `gulp.series` and `gulp.parallel`
 * 不能使用并发模式，因为涉及到写rev文件
 */
// var build = gulp.series(clean, gulp.parallel(minifyScript, minifyCss));
var build = gulp.series(clean, gulp.series(minifyScript, minifyCss));

/*
 * You can still use `gulp.task` to expose tasks
 */
// gulp.task('build', build);

/*
 * Define default task that can be called by just running `gulp` from cli
 */
gulp.task('default', build);

gulp.task('lint', function () {
    return gulp.src(SCRIPT_SRC)
        .pipe(eslint())
        .pipe(eslint.format());
});
<commit_msg>update gulpfile.js<commit_after>// npm install --save-dev   gulp  gulp-changed  gulp-jscs  gulp-uglify  gulp-watch gulp-rev  gulp-minify-css gulp-watch  gulp-eslint

let gulp = require('gulp'),
    changed = require('gulp-changed'),
    // jscs = require('gulp-jscs'),
    uglify = require('gulp-uglify'),
    // watch = require('gulp-watch'),
    rev = require('gulp-rev'),
    minifycss = require('gulp-minify-css');
let eslint = require('gulp-eslint');

let SCRIPT_SRC = 'web/scripts/**/*.js';
let STYLE_SRC = 'web/styles/**/*.css';
let buildFolder = 'web/build';

/** gulp 3.9
 gulp.task('minifyscript', function() {
    return gulp.src(SCRIPT_SRC, {base: 'web'})
    // `changed` 任务需要提前知道目标目录位置才能找出哪些文件是被修改过的
        //.pipe(changed(buildFolder))// 只有被更改过的文件才会通过这里
        //.pipe(watch(SRC))//只重新编译被更改过的文件
        //.pipe(jscs())
        .pipe(uglify())
        //.pipe(gulp.dest(buildFolder))//// copy original src to build dir
        .pipe(rev())
        .pipe(gulp.dest(buildFolder))// write rev'd src to build dir
        .pipe(rev.manifest('web/build/rev-manifest.json',{
            base: buildFolder,
            merge: true // merge with the existing manifest (if one exists)
        }))
        .pipe(gulp.dest(buildFolder));//compressed file  // write manifest to build dir
});

 gulp.task('minifycss', function() {
    return gulp.src(STYLE_SRC, {base: 'web'})
        .pipe(minifycss())   //执行压缩
        //.pipe(gulp.dest(buildFolder))//// copy original src to build dir
        .pipe(rev())
        .pipe(gulp.dest(buildFolder))// write rev'd src to build dir
        .pipe(rev.manifest('web/build/rev-manifest.json', {
            base: buildFolder,
            merge: true // merge with the existing manifest (if one exists)
        }))
        .pipe(gulp.dest(buildFolder));//compressed file  // write manifest to build dir
});

 gulp.task('default', function () {
    // gulp.watch(SCRIPT_SRC, ['script', 'minifycss'], function(event){
    //     //console.log(event);
    // });

    gulp.start('minifyscript', 'minifycss');
});
 */
let del = require('del');

function minifyScript() {
    return gulp.src(SCRIPT_SRC, {base: 'web'})
    // `changed` 任务需要提前知道目标目录位置才能找出哪些文件是被修改过的
    //.pipe(changed(buildFolder))// 只有被更改过的文件才会通过这里
    //.pipe(watch(SRC))//只重新编译被更改过的文件
    //.pipe(jscs())
        .pipe(uglify())
        //.pipe(gulp.dest(buildFolder))//// copy original src to build dir
        .pipe(rev())
        .pipe(gulp.dest(buildFolder))// write rev'd src to build dir
        .pipe(rev.manifest('web/build/rev-manifest.json', {
            base: buildFolder,
            merge: true // merge with the existing manifest (if one exists)
        }))
        .pipe(gulp.dest(buildFolder));//compressed file  // write manifest to build dir
}

function minifyCss() {
    return gulp.src(STYLE_SRC, {base: 'web'})
        .pipe(minifycss())   //执行压缩
        //.pipe(gulp.dest(buildFolder))//// copy original src to build dir
        .pipe(rev())
        .pipe(gulp.dest(buildFolder))// write rev'd src to build dir
        .pipe(rev.manifest('web/build/rev-manifest.json', {
            base: buildFolder,
            merge: true // merge with the existing manifest (if one exists)
        }))
        .pipe(gulp.dest(buildFolder));//compressed file  // write manifest to build dir
}

/* Not all tasks need to use streams, a gulpfile is just another node program
 * and you can use all packages available on npm, but it must return either a
 * Promise, a Stream or take a callback and call it
 */
function clean() {
    // You can use multiple globbing patterns as you would with `gulp.src`,
    // for example if you are using del 2.0 or above, return its promise
    return del(['web/assets/*', 'web/build']);
}

function watch() {
    gulp.watch(SCRIPT_SRC, minifyScript);
    gulp.watch(STYLE_SRC, minifyCss);
}

/*
 * You can use CommonJS `exports` module notation to declare tasks
 */
exports.clean = clean;
exports.scripts = minifyScript;
exports.styles = minifyCss;
exports.watch = watch;

/*
 * Specify if tasks run in series or parallel using `gulp.series` and `gulp.parallel`
 * 不能使用并发模式，因为涉及到写rev文件
 */
// var build = gulp.series(clean, gulp.parallel(minifyScript, minifyCss));
let build = gulp.series(clean, gulp.series(minifyScript, minifyCss));

/*
 * You can still use `gulp.task` to expose tasks
 */
// gulp.task('build', build);

/*
 * Define default task that can be called by just running `gulp` from cli
 */
gulp.task('default', build);

gulp.task('lint', function () {
    return gulp.src(SCRIPT_SRC)
        .pipe(eslint())
        .pipe(eslint.format());
});
<|endoftext|>


<commit_before>var gulp = require('gulp');
var gutil = require('gulp-util');
var clean = require('gulp-clean');
var watchLess = require('gulp-watch-less');
var less = require('gulp-less');
var cleanCSS = require('gulp-clean-css');
var postcss = require('gulp-postcss');
//var sourcemaps   = require('gulp-sourcemaps');
var autoprefixer = require('autoprefixer');

gulp.task('less:build', function () {
    return gulp.src('src/less/main.less')
        .pipe(less())
        .pipe(postcss([autoprefixer({
            browsers: ['last 2 versions']
        })]))
        .pipe(cleanCSS({
            compatibility: 'ie8'
        }))
        .pipe(gulp.dest('dist/css'));
});

gulp.task('less:build-watch', ['less:build'], function () {
    return gulp.src('src/less/main.less')
        .pipe(watchLess('src/less/main.less', function () {
            gulp.start('less:build');
        }));
});

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

gulp.task('dev', ['less:build-watch']);
<commit_msg>Fixed gulpfile.<commit_after>var gulp = require('gulp');
var gutil = require('gulp-util');
var clean = require('gulp-clean');
var watchLess = require('gulp-watch-less');
var less = require('gulp-less');
var cleanCSS = require('gulp-clean-css');
var postcss = require('gulp-postcss');
//var sourcemaps   = require('gulp-sourcemaps');
var autoprefixer = require('autoprefixer');

gulp.task('less:build', function () {
    return gulp.src('src/less/main.less')
        .pipe(less())
        .on('error', function (error) {
            console.log(error.toString());
            this.emit('end');
        })
        .pipe(postcss([autoprefixer({
            browsers: ['last 2 versions']
        })]))
        .pipe(cleanCSS({
            compatibility: 'ie8'
        }))
        .pipe(gulp.dest('dist/css'));
});

gulp.task('less:build-watch', ['less:build'], function () {
    return gulp.watch(["src/less/**/*"], ["less:build"]);
});

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

gulp.task('dev', ['less:build-watch']);
<|endoftext|>


<commit_before>var gulp = require('gulp');
var glob = require('glob');
var path = require('path');
var browserify  = require('browserify');
var source = require('vinyl-source-stream');
var transform = require('vinyl-transform');
var exorcist = require('exorcist');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var watchify = require('watchify');
var livereload = require('gulp-livereload');

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

var shell = require('gulp-shell');
var git = require('gulp-git');
var watch;

gulp.task('package', function(callback){
    watch = false;
    browserifyShare(callback);
});

gulp.task('package-min', ['package'], function(callback){
    return gulp.src('./build/awayjs-stagegl.js')
        .pipe(sourcemaps.init({loadMaps:true}))
        .pipe(uglify({compress:false}))
        .pipe(rename(function (path) {
            path.basename += '.min';
        }))
        .pipe(sourcemaps.write({sourceRoot: '../'}))
        .pipe(transform(function() {
            return exorcist('./build/awayjs-stagegl.min.js.map');
        }))
        .pipe(gulp.dest('./build'));
});

gulp.task('package-watch', function(callback){
    watch = true;
    browserifyShare(callback);
});

gulp.task('watch', ['package-watch'], function(){

    //Start live reload server
    livereload.listen();
});

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

    var tsProject = typescript.createProject({
        declarationFiles: true,
        noExternalResolve: true,
        target: 'ES5',
        module: 'commonjs',
        sourceRoot: './'
    });

    var tsResult = gulp.src(['./tests/**/*.ts', './node_modules/awayjs-**/build/*.d.ts', './build/awayjs-stagegl.d.ts'])
        .pipe(sourcemaps.init())
        .pipe(typescript(tsProject));

    return tsResult.js
        .pipe(sourcemaps.write({sourceRoot: './tests'}))
        .pipe(gulp.dest('./tests'));
});

function browserifyShare(callback) {
    var b = browserify({
        debug: true,
        paths: ['../'],
        cache: {},
        packageCache: {},
        fullPaths: true
    });

    b.plugin('tsify', {target:'ES5', sourceRoot:'../', noExternalResolve: true, declarationFiles: './node_modules/awayjs-**/build/*.d.ts', declarationOutput: './build/awayjs-stagegl.d.ts'});

    glob('./node_modules/awayjs-**/lib/**/*.ts', {}, function (error, files) {
        files.forEach(function (file) {
            b.external(file);
        });
    });

    glob('./lib/**/*.ts', {}, function (error, files) {

        files.forEach(function (file) {
            b.require(file, {expose:unixStylePath(path.relative('../', file.slice(0,-3)))});
        });

        if (watch) {
            b = watchify(b);
            b.on('update', function(){
                return b.bundle()
                    .pipe(source('awayjs-stagegl.js'))
                    .pipe(gulp.dest('./build'))
                    .pipe(livereload());
            });
        }

        b.bundle()
            .pipe(exorcist('./build/awayjs-stagegl.js.map'))
            .pipe(source('awayjs-stagegl.js'))
            .pipe(gulp.dest('./build'))
            .on('end', callback);
    });
}

function unixStylePath(filePath) {
    return filePath.split(path.sep).join('/');
}

gulp.task('commit', ['package-min'], function(callback){

    git.status({args:'--porcelain'}, function(err, stdout) {
        var buildModified = false;
        var packageModified = false;

        if (err)
            throw err;

        stdout = stdout.split('\n');
        stdout.forEach(function (line) {
            if (line.indexOf('build/') != -1)
                buildModified = true;
            else if (line.indexOf(' M ') != -1)
                packageModified = true;
        });

        if (packageModified) {
            console.log('un-commited changes detected in package');
            console.log('Please git commit all changes outside of build before continuing');
        } else {
            if (buildModified) {
                gulp.src('./build/*')
                    .pipe(git.commit('update build files'))
                    .on('error', function(err) {
                        throw err;
                    })
                    .on('end', callback);
            } else {
                callback();
            }
        }
    });
});

gulp.task('version', ['commit'], function(callback){
    gulp.src('')
        .pipe(shell([
            'npm version patch'
        ])).on('error', function(err) {
            throw err;
        }).on('end', callback);
});

gulp.task('push', ['version'], function(callback){
    gulp.src('')
        .pipe(shell([
            'git push origin dev --tags'
        ])).on('error', function(err) {
            throw err;
        }).on('end', callback);
});

gulp.task('publish', ['push'], function(callback){
    gulp.src('')
        .pipe(shell([
            'npm publish'
        ])).on('error', function(err) {
            throw err;
        }).on('end', callback);
});
gulp.task('compile', function() {
    var tsProject = typescript.createProject({
        declarationFiles: true,
        noExternalResolve: true,
        target: 'ES5',
        module: 'commonjs',
        sourceRoot: './awayjs-stagegl/lib/',
        moduleResolution: 'classic'
    });

    var tsResult = gulp.src([
        './lib/**/*.ts',
        './node_modules/awayjs-**/build/*.d.ts'
    ])
        //.pipe(sourcemaps.init())
        .pipe(typescript(tsProject));

    return tsResult.js
        //.pipe(sourcemaps.write({sourceRoot: '../'}))
        .pipe(gulp.dest('./lib'));
});<commit_msg>updated gulpfile<commit_after>var gulp = require('gulp');
var glob = require('glob');
var path = require('path');
var browserify  = require('browserify');
var source = require('vinyl-source-stream');
var transform = require('vinyl-transform');
var exorcist = require('exorcist');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var watchify = require('watchify');
var livereload = require('gulp-livereload');

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

var shell = require('gulp-shell');
var git = require('gulp-git');
var watch;

gulp.task('package', function(callback){
    watch = false;
    browserifyShare(callback);
});

gulp.task('package-min', ['package'], function(callback){
    return gulp.src('./build/awayjs-stagegl.js')
        .pipe(sourcemaps.init({loadMaps:true}))
        .pipe(uglify({compress:false}))
        .pipe(rename(function (path) {
            path.basename += '.min';
        }))
        .pipe(sourcemaps.write({sourceRoot: '../'}))
        .pipe(transform(function() {
            return exorcist('./build/awayjs-stagegl.min.js.map');
        }))
        .pipe(gulp.dest('./build'));
});

gulp.task('package-watch', function(callback){
    watch = true;
    browserifyShare(callback);
});

gulp.task('watch', ['package-watch'], function(){

    //Start live reload server
    livereload.listen();
});

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

    var tsProject = typescript.createProject({
        declarationFiles: true,
        noExternalResolve: true,
        target: 'ES5',
        module: 'commonjs',
        sourceRoot: './'
    });

    var tsResult = gulp.src(['./tests/**/*.ts', './node_modules/awayjs-**/build/*.d.ts', './build/awayjs-stagegl.d.ts'])
        .pipe(sourcemaps.init())
        .pipe(typescript(tsProject));

    return tsResult.js
        .pipe(sourcemaps.write({sourceRoot: './tests'}))
        .pipe(gulp.dest('./tests'));
});

function browserifyShare(callback) {
    var b = browserify({
        debug: true,
        paths: ['../'],
        entries: './lib/StageGL.ts',
        cache: {},
        packageCache: {},
        fullPaths: true
    });

    b.plugin('tsify', {target:'ES5', sourceRoot:'../', noExternalResolve: true, declarationFiles: './node_modules/awayjs-**/build/*.d.ts', declarationOutput: './build/awayjs-stagegl.d.ts'});

    glob('./node_modules/awayjs-**/lib/**/*.ts', {}, function (error, files) {
        files.forEach(function (file) {
            b.external(file);
        });
    });

    glob('./lib/**/*.ts', {}, function (error, files) {

        files.forEach(function (file) {
            b.require(file, {expose:unixStylePath(path.relative('../', file.slice(0,-3)))});
        });

        if (watch) {
            b = watchify(b);
            b.on('update', function(){
                return b.bundle()
                    .pipe(source('awayjs-stagegl.js'))
                    .pipe(gulp.dest('./build'))
                    .pipe(livereload());
            });
        }

        b.bundle()
            .pipe(exorcist('./build/awayjs-stagegl.js.map'))
            .pipe(source('awayjs-stagegl.js'))
            .pipe(gulp.dest('./build'))
            .on('end', callback);
    });
}

function unixStylePath(filePath) {
    return filePath.split(path.sep).join('/');
}

gulp.task('commit', ['package-min'], function(callback){

    git.status({args:'--porcelain'}, function(err, stdout) {
        var buildModified = false;
        var packageModified = false;

        if (err)
            throw err;

        stdout = stdout.split('\n');
        stdout.forEach(function (line) {
            if (line.indexOf('build/') != -1)
                buildModified = true;
            else if (line.indexOf(' M ') != -1)
                packageModified = true;
        });

        if (packageModified) {
            console.log('un-commited changes detected in package');
            console.log('Please git commit all changes outside of build before continuing');
        } else {
            if (buildModified) {
                gulp.src('./build/*')
                    .pipe(git.commit('update build files'))
                    .on('error', function(err) {
                        throw err;
                    })
                    .on('end', callback);
            } else {
                callback();
            }
        }
    });
});

gulp.task('version', ['commit'], function(callback){
    gulp.src('')
        .pipe(shell([
            'npm version patch'
        ])).on('error', function(err) {
            throw err;
        }).on('end', callback);
});

gulp.task('push', ['version'], function(callback){
    gulp.src('')
        .pipe(shell([
            'git push origin dev --tags'
        ])).on('error', function(err) {
            throw err;
        }).on('end', callback);
});

gulp.task('publish', ['push'], function(callback){
    gulp.src('')
        .pipe(shell([
            'npm publish'
        ])).on('error', function(err) {
            throw err;
        }).on('end', callback);
});
gulp.task('compile', function() {
    var tsProject = typescript.createProject({
        declarationFiles: true,
        noExternalResolve: true,
        target: 'ES5',
        module: 'commonjs',
        sourceRoot: './awayjs-stagegl/lib/',
        moduleResolution: 'classic'
    });

    var tsResult = gulp.src([
        './lib/**/*.ts',
        './node_modules/awayjs-**/build/*.d.ts'
    ])
        //.pipe(sourcemaps.init())
        .pipe(typescript(tsProject));

    return tsResult.js
        //.pipe(sourcemaps.write({sourceRoot: '../'}))
        .pipe(gulp.dest('./lib'));
});<|endoftext|>


<commit_before>'use strict';

var gulp = require('gulp');
var notify = require('gulp-notify');
var webserver = require('gulp-webserver');

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

var jest = require('jest-cli');
var open = require('open');
require('harmonize')();

var config = {
    dest: 'public',
    script: {
        path: 'js',
        main: 'js/script.js',
    },
    test: {
        path: '__tests__',
    },
};

gulp.task('script', function() {
    var b = browserify({
        entries: 'js/script.js',
        debug: true,
        transform: 'babelify',
    });

    return b.bundle()
        .on('error', notify.onError('[SCRIPT] <%= error.message %>'))
        .pipe(source('js/script.js'))
        .pipe(buffer())
        .pipe(gulp.dest(config.dest))
        .pipe(notify('[SCRIPT] Generated script: <%= file.relative %> '))
        ;
});

gulp.task('test', function(callback) {
    var _write = process.stdout.write;
    var output = '';
    process.stdout.write = function(str) {
        if (str && str.match(/^{.*}$/)) {
            output += str;
        } else {
            _write.apply(this, arguments);
        }
    };

    jest.runCLI({ json: true, }, __dirname, function(success) {
        process.stdout.write = _write;

        var data;
        try {
            data = JSON.parse(output);
        } catch (e) {
            notify.onError('<%= error.message %>').call(new Buffer(''), e);
            return callback();
        }

        var endTime = data.testResults
            .map(r => r.endTime)
            .reduce(Math.max.bind(Math));
        var time = (endTime - data.startTime) / 1000;

        var result = `${data.numPassedTests} test passed (${data.numTotalTests} total in ${data.numTotalTestSuites}, run time ${time}s)`;
        if (data.numFailedTests) result = `${data.numFailedTests} test failed, ${result}`;
        result = `[TEST] ${result}`;

        var logLevel = notify.logLevel();
        notify.logLevel(0);
        if (success) {
            notify('<%= file.message %>', { onLast: false})
                ._transform({ message: result }, null, () => callback);
        } else {
            data.testResults
                .filter(r => !r.success)
                .map(r => r.message)
                .forEach(function (message) {
                    var _message = message.replace(/\u001b\[[0-9]*m/g, '').sub(0, 1000);
                    notify.onError('<%= error.message %>', function() {}).call(new Buffer(''), new Error(_message));
                });

            notify.onError('<%= error.message %>', function() {}).call(new Buffer(''), new Error(result));
        }
        notify.logLevel(logLevel);

        return callback();
    });
});

gulp.task('watch:script', ['script'], function() {
    return gulp.watch(config.script.path + '/**/*.js', ['script']);
});
gulp.task('watch:test', ['test'], function() {
    return gulp.watch([config.script.path + '/**/*.js', config.test.path + '/**/*.js'], ['test']);
});
gulp.task('watch', ['watch:script', 'watch:test']);

gulp.task('server', function() {
    gulp.src(config.dest)
        .pipe(webserver({
            livereload: true,
            open: false,
        }));
});
gulp.task('open', function() {
    open('http://localhost:8000/');
});

gulp.task('tdd', ['server', 'watch']);
gulp.task('tdd-open', ['tdd', 'open']);

gulp.task('default', ['script', 'test']);
<commit_msg>Fix gulp notification of jest<commit_after>'use strict';

var gulp = require('gulp');
var notify = require('gulp-notify');
var webserver = require('gulp-webserver');

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

var jest = require('jest-cli');
var open = require('open');
require('harmonize')();

var config = {
    dest: 'public',
    script: {
        path: 'js',
        main: 'js/script.js',
    },
    test: {
        path: '__tests__',
    },
};

gulp.task('script', function() {
    var b = browserify({
        entries: 'js/script.js',
        debug: true,
        transform: 'babelify',
    });

    return b.bundle()
        .on('error', notify.onError('[SCRIPT] <%= error.message %>'))
        .pipe(source('js/script.js'))
        .pipe(buffer())
        .pipe(gulp.dest(config.dest))
        .pipe(notify('[SCRIPT] Generated script: <%= file.relative %> '))
        ;
});

gulp.task('test', function(callback) {
    var _write = process.stdout.write;
    var output = '';
    process.stdout.write = function(str) {
        if (str && str.match(/^{.*}$/)) {
            output += str;
        } else {
            _write.apply(this, arguments);
        }
    };

    jest.runCLI({ json: true, }, __dirname, function(success) {
        process.stdout.write = _write;

        var data;
        try {
            data = JSON.parse(output);
        } catch (e) {
            notify.onError('<%= error.message %>').call(new Buffer(''), e);
            return callback();
        }

        var endTime = data.testResults
            .map(r => r.endTime)
            .reduce(Math.max.bind(Math));
        var time = (endTime - data.startTime) / 1000;

        var result = `${data.numPassedTests} test passed (${data.numTotalTests} total in ${data.numTotalTestSuites}, run time ${time}s)`;
        if (data.numFailedTests) result = `${data.numFailedTests} test failed, ${result}`;
        result = `[TEST] ${result}`;

        var logLevel = notify.logLevel();
        notify.logLevel(0);
        if (success) {
            notify('<%= file.message %>', { onLast: false})
                ._transform({ message: result }, null, () => callback);
        } else {
            data.testResults
                .filter(r => !r.success)
                .map(r => r.message)
                .forEach(function (message) {
                    var _message = message.replace(/\u001b\[[0-9]*m/g, '').substr(0, 1000);
                    notify.onError('<%= error.message %>', function() {}).call(new Buffer(''), new Error(_message));
                });

            notify.onError('<%= error.message %>', function() {}).call(new Buffer(''), new Error(result));
        }
        notify.logLevel(logLevel);

        return callback();
    });
});

gulp.task('watch:script', ['script'], function() {
    return gulp.watch(config.script.path + '/**/*.js', ['script']);
});
gulp.task('watch:test', ['test'], function() {
    return gulp.watch([config.script.path + '/**/*.js', config.test.path + '/**/*.js'], ['test']);
});
gulp.task('watch', ['watch:script', 'watch:test']);

gulp.task('server', function() {
    gulp.src(config.dest)
        .pipe(webserver({
            livereload: true,
            open: false,
        }));
});
gulp.task('open', function() {
    open('http://localhost:8000/');
});

gulp.task('tdd', ['server', 'watch']);
gulp.task('tdd-open', ['tdd', 'open']);

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