<commit_before>var SITE_DIR = 'famous-angular-docs/';
var EXAMPLES_DIR = 'famous-angular-examples/';

var EXPRESS_PORT = 4000;
var EXPRESS_DOCS_ROOT = __dirname + '/' + SITE_DIR + '_site';

var LIVERELOAD_PORT = 35729;

// Load plugins
var gulp = require('gulp'),
  autoprefixer = require('gulp-autoprefixer'),
  minifycss = require('gulp-minify-css'),
  jshint = require('gulp-jshint'),
  uglify = require('gulp-uglify'),
  rename = require('gulp-rename'),
  clean = require('gulp-clean'),
  concat = require('gulp-concat'),
  notify = require('gulp-notify'),
  cache = require('gulp-cache'),
  livereload = require('gulp-livereload'),
  server = livereload(),
  gutil = require('gulp-util'),
  pkg = require('./package.json'),
  exec = require('gulp-exec');

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

// Build for dist
gulp.task('build', ['clean'], function(event) {

	var header = require('gulp-header');
	var banner = ['/**',
		' * <%= pkg.name %> - <%= pkg.description %>',
		' * @version v<%= pkg.version %>',
		' * @link <%= pkg.homepage %>',
		' * @license <%= pkg.license %>',
		' */',
		''].join('\n');

  // Build the CSS
  gulp.src([
    'src/styles/famous-angular.css'
  ])
	.pipe(header(banner, { pkg : pkg } ))
	.pipe(gulp.dest('dist/'))
  .pipe(minifycss())
	.pipe(header(banner, { pkg : pkg } ))
	.pipe(rename({suffix: '.min'}))
	.pipe(gulp.dest('dist/'));

  // Build the JS
	return gulp.src([
		'src/scripts/services/**/*.js',
		'src/scripts/directives/**/*.js'
	])
	.pipe(concat('famous-angular.js'))
	.pipe(jshint('.jshintrc'))
	.pipe(jshint.reporter('default'))
	.pipe(header(banner, { pkg : pkg } ))
	.pipe(gulp.dest('dist/'))
	.pipe(uglify())
	.pipe(rename({suffix: '.min'}))
	.pipe(header(banner, { pkg : pkg } ))
	.pipe(gulp.dest('dist/'))
	.pipe(notify({ message: 'Build task complete' }));
});

gulp.task('docs', ['build'], function(done) {
	var dgeni = require('dgeni'),
		semver = require('semver'),
		argv = require('minimist')(process.argv.slice(2)),
		docVersion = argv['doc-version'];

	if (docVersion != 'unstable' && !semver.valid(docVersion)) {
		console.log('Usage: gulp docs --doc-version=(unstable|versionName)');
		if(pkg.version) {
			console.log('Current package.json version is: '+pkg.version);
		}
		console.log('No version selected, using unstable');
		docVersion = 'unstable';
	}
	process.env.DOC_VERSION = docVersion;

	gutil.log('Generating documentation for ', gutil.colors.cyan(docVersion));
	var generateDocs = dgeni.generator('docs-generation/docs.config.js');
	return generateDocs().then(function() {
		gutil.log('Docs for', gutil.colors.cyan(docVersion), 'generated!');
	});
});

/***********************************************************************
*
* Tasks for the famous-angular-docs submodule
*
***********************************************************************/

// Main watch task for development
gulp.task('dev-site', ['build-jekyll'], function() {
  var server = livereload();

  // Watch source files inside site submodule
  gulp.watch([
	      // Because .styl compiles into .css, do not watch .css, else you will
	      // an infinite loop
	      SITE_DIR + '**/*.styl',
	      SITE_DIR + '**/*.html',
	      SITE_DIR + '**/*.md',
        // Only watch the js from app/
	      SITE_DIR + 'app/*.js',
	      // Do NOT watch the compile _site directory, else the watch will create
	      // an infinite loop
	      '!' + SITE_DIR + '_site/**',
	      '!' + SITE_DIR + 'js/**'
	  ],
	  ['build-jekyll']
	).on('change',
    function(file){
      server.changed(file.path);
    }
  );

  // Start the express server
  gulp.start('site');
});

// jekyll build the docs site
gulp.task('build-jekyll', ['site-styl', 'site-js'], function() {
  var jekyllCommand = 'jekyll build --source ' + SITE_DIR +  ' --destination ' + SITE_DIR + '_site/';
  // gulp-exec bugfix:
  // Need to call gulp.src('') exactly, before using .pipe(exec())
  return gulp.src('')
    .pipe(exec(jekyllCommand))
    .pipe(livereload(server));
});

// First generate the docs, and then run jekyll build to create a new _site
// with the fresh docs
gulp.task('build-site', ['docs'], function(done) {
  return gulp.start('build-jekyll');
});

// Compile .styl for the site submodule
gulp.task('site-styl', function() {
  var stylus = require('gulp-stylus');

  return gulp.src(SITE_DIR + "styl/*.styl")
    .pipe(stylus())
    .pipe(minifycss())
    .pipe(concat('main.css'))
    .pipe(rename({suffix: '.min'}))
    .pipe(gulp.dest(SITE_DIR + "css/"));
});

// Concat all app/ js files and minify them
gulp.task('site-js', function() {
  return gulp.src([
    SITE_DIR + "app/*.js",
  ])
    .pipe(concat('app.js'))
    .pipe(uglify())
    .pipe(rename({suffix: '.min'}))
    .pipe(gulp.dest(SITE_DIR + "js/"));
});

gulp.task('site', function(done) {
	var express = require('express'),
		app = express();
	app.use(require('connect-livereload')());
	app.use(express.static(EXPRESS_DOCS_ROOT));
	app.listen(EXPRESS_PORT);
	gutil.log('Server running at Docs for', gutil.colors.cyan('http://localhost:'+EXPRESS_PORT+'/'));
});

/***********************************************************************
 * Watch task for developing with the famous-angular-examples submodule
 ***********************************************************************/
gulp.task('build-to-examples', ['clean'], function(event) {
	return gulp.src([
		'src/scripts/services/**/*.js',
		'src/scripts/directives/**/*.js'
	])
	.pipe(concat('famous-angular.js'))
	.pipe(gulp.dest(EXAMPLES_DIR + 'app/bower_components/famous-angular/'))
	.pipe(notify({ message: 'Build task complete' }));
})

// Watch
gulp.task('watch-examples', function(event) {
	var server = livereload();
	// Watch .js files
	gulp.watch([
			'src/scripts/*/**/*.js',
			EXAMPLES_DIR + 'app/*'
		],
		['build-to-examples']
	).on('change',
		function(file){
			server.changed(file.path);
		}
	);
});

// Default task
gulp.task('dev', function() {
	var express = require('express');
	var app = express();
	app.use(require('connect-livereload')());
	app.use(express.static(EXAMPLES_DIR + 'app/'));
	app.listen(EXPRESS_PORT);
	gulp.start('watch-examples');
});
<commit_msg>Create non-minified app.js for site-js gulp task.<commit_after>var SITE_DIR = 'famous-angular-docs/';
var EXAMPLES_DIR = 'famous-angular-examples/';

var EXPRESS_PORT = 4000;
var EXPRESS_DOCS_ROOT = __dirname + '/' + SITE_DIR + '_site';

var LIVERELOAD_PORT = 35729;

// Load plugins
var gulp = require('gulp'),
  autoprefixer = require('gulp-autoprefixer'),
  minifycss = require('gulp-minify-css'),
  jshint = require('gulp-jshint'),
  uglify = require('gulp-uglify'),
  rename = require('gulp-rename'),
  clean = require('gulp-clean'),
  concat = require('gulp-concat'),
  notify = require('gulp-notify'),
  cache = require('gulp-cache'),
  livereload = require('gulp-livereload'),
  server = livereload(),
  gutil = require('gulp-util'),
  pkg = require('./package.json'),
  exec = require('gulp-exec');

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

// Build for dist
gulp.task('build', ['clean'], function(event) {

	var header = require('gulp-header');
	var banner = ['/**',
		' * <%= pkg.name %> - <%= pkg.description %>',
		' * @version v<%= pkg.version %>',
		' * @link <%= pkg.homepage %>',
		' * @license <%= pkg.license %>',
		' */',
		''].join('\n');

  // Build the CSS
  gulp.src([
    'src/styles/famous-angular.css'
  ])
	.pipe(header(banner, { pkg : pkg } ))
	.pipe(gulp.dest('dist/'))
  .pipe(minifycss())
	.pipe(header(banner, { pkg : pkg } ))
	.pipe(rename({suffix: '.min'}))
	.pipe(gulp.dest('dist/'));

  // Build the JS
	return gulp.src([
		'src/scripts/services/**/*.js',
		'src/scripts/directives/**/*.js'
	])
	.pipe(concat('famous-angular.js'))
	.pipe(jshint('.jshintrc'))
	.pipe(jshint.reporter('default'))
	.pipe(header(banner, { pkg : pkg } ))
	.pipe(gulp.dest('dist/'))
	.pipe(uglify())
	.pipe(rename({suffix: '.min'}))
	.pipe(header(banner, { pkg : pkg } ))
	.pipe(gulp.dest('dist/'))
	.pipe(notify({ message: 'Build task complete' }));
});

gulp.task('docs', ['build'], function(done) {
	var dgeni = require('dgeni'),
		semver = require('semver'),
		argv = require('minimist')(process.argv.slice(2)),
		docVersion = argv['doc-version'];

	if (docVersion != 'unstable' && !semver.valid(docVersion)) {
		console.log('Usage: gulp docs --doc-version=(unstable|versionName)');
		if(pkg.version) {
			console.log('Current package.json version is: '+pkg.version);
		}
		console.log('No version selected, using unstable');
		docVersion = 'unstable';
	}
	process.env.DOC_VERSION = docVersion;

	gutil.log('Generating documentation for ', gutil.colors.cyan(docVersion));
	var generateDocs = dgeni.generator('docs-generation/docs.config.js');
	return generateDocs().then(function() {
		gutil.log('Docs for', gutil.colors.cyan(docVersion), 'generated!');
	});
});

/***********************************************************************
*
* Tasks for the famous-angular-docs submodule
*
***********************************************************************/

// Main watch task for development
gulp.task('dev-site', ['build-jekyll'], function() {
  var server = livereload();

  // Watch source files inside site submodule
  gulp.watch([
	      // Because .styl compiles into .css, do not watch .css, else you will
	      // an infinite loop
	      SITE_DIR + '**/*.styl',
	      SITE_DIR + '**/*.html',
	      SITE_DIR + '**/*.md',
        // Only watch the js from app/
	      SITE_DIR + 'app/*.js',
	      // Do NOT watch the compile _site directory, else the watch will create
	      // an infinite loop
	      '!' + SITE_DIR + '_site/**',
	      '!' + SITE_DIR + 'js/**'
	  ],
	  ['build-jekyll']
	).on('change',
    function(file){
      server.changed(file.path);
    }
  );

  // Start the express server
  gulp.start('site');
});

// jekyll build the docs site
gulp.task('build-jekyll', ['site-styl', 'site-js'], function() {
  var jekyllCommand = 'jekyll build --source ' + SITE_DIR +  ' --destination ' + SITE_DIR + '_site/';
  // gulp-exec bugfix:
  // Need to call gulp.src('') exactly, before using .pipe(exec())
  return gulp.src('')
    .pipe(exec(jekyllCommand))
    .pipe(livereload(server));
});

// First generate the docs, and then run jekyll build to create a new _site
// with the fresh docs
gulp.task('build-site', ['docs'], function(done) {
  return gulp.start('build-jekyll');
});

// Compile .styl for the site submodule
gulp.task('site-styl', function() {
  var stylus = require('gulp-stylus');

  return gulp.src(SITE_DIR + "styl/*.styl")
    .pipe(stylus())
    .pipe(minifycss())
    .pipe(concat('main.css'))
    .pipe(rename({suffix: '.min'}))
    .pipe(gulp.dest(SITE_DIR + "css/"));
});

// Concat all app/ js files and minify them
gulp.task('site-js', function() {
  return gulp.src([
    SITE_DIR + "app/*.js",
  ])
    .pipe(concat('app.js'))
    .pipe(gulp.dest(SITE_DIR + "js/"))
    .pipe(uglify())
    .pipe(rename({suffix: '.min'}))
    .pipe(gulp.dest(SITE_DIR + "js/"));
});

gulp.task('site', function(done) {
	var express = require('express'),
		app = express();
	app.use(require('connect-livereload')());
	app.use(express.static(EXPRESS_DOCS_ROOT));
	app.listen(EXPRESS_PORT);
	gutil.log('Server running at Docs for', gutil.colors.cyan('http://localhost:'+EXPRESS_PORT+'/'));
});

/***********************************************************************
 * Watch task for developing with the famous-angular-examples submodule
 ***********************************************************************/
gulp.task('build-to-examples', ['clean'], function(event) {
	return gulp.src([
		'src/scripts/services/**/*.js',
		'src/scripts/directives/**/*.js'
	])
	.pipe(concat('famous-angular.js'))
	.pipe(gulp.dest(EXAMPLES_DIR + 'app/bower_components/famous-angular/'))
	.pipe(notify({ message: 'Build task complete' }));
})

// Watch
gulp.task('watch-examples', function(event) {
	var server = livereload();
	// Watch .js files
	gulp.watch([
			'src/scripts/*/**/*.js',
			EXAMPLES_DIR + 'app/*'
		],
		['build-to-examples']
	).on('change',
		function(file){
			server.changed(file.path);
		}
	);
});

// Default task
gulp.task('dev', function() {
	var express = require('express');
	var app = express();
	app.use(require('connect-livereload')());
	app.use(express.static(EXAMPLES_DIR + 'app/'));
	app.listen(EXPRESS_PORT);
	gulp.start('watch-examples');
});
<|endoftext|>


<commit_before>// require all the plugins used --------------------------------------------------------------------
var gulp        = require('gulp'),
    jade        = require('gulp-jade'),
    compass     = require('gulp-compass'),
    plumber     = require('gulp-plumber'),
    livereload  = require('gulp-livereload'),
    imagemin    = require('gulp-imagemin'),
    svgmin      = require('gulp-imagemin'),
    modernizr   = require('gulp-modernizr'),
    uglify      = require('gulp-uglify'),
    include     = require('gulp-include'),
    coffee      = require('gulp-coffee'),

    // open a file or url
    open    = require('open'),

    // http server
    http = require('http'),
    connect       = require('connect'),

    // through = stream handling
    through       = require('through'),

    // gulp_args = argument parser
    gulp_args     = require('minimist')(process.argv.slice(2)),

    development = gulp_args.dev,
    dev = function (stream) {
      return development ? stream : through();
    },
    CONNECT_PORT = 8000,
    paths;

// saving paths ------------------------------------------------------------------------------------
paths = {
  pages: './*.jade',
  styles: 'app/stylesheets/',
  stylesheet: 'app/stylesheets/style.sass',
  stylesheets: 'app/stylesheets/**/*.{scss,sass}',
  javascript: 'app/javascripts/scripts.coffee',
  javascripts: 'app/javascripts/**/*.{coffee,js}',
  images: 'app/images/**/*.{png,jpg,gif,jpeg}',
  svg: 'app/images/**/*.svg'
};

// define tasks ------------------------------------------------------------------------------------
gulp.task('pages', function() {
  var stream = gulp
    .src(paths.pages)
    .pipe(plumber())
    .pipe(jade(dev({ pretty: true })))
    .pipe(gulp.dest('./'));

  if(development) {
    stream = stream.pipe(livereload());
  }

  return stream;
});

gulp.task('styles', function() {
  var stream = gulp
    .src(paths.stylesheet)
    .pipe(plumber())
    .pipe(compass({
      sass: paths.styles,
      css: './',
      style: development ? 'expanded' : 'compressed'
    }))
    .pipe(gulp.dest('./'));

  if(development) {
    stream = stream.pipe(livereload());
  }

  return stream;
});

gulp.task('scripts', function() {
  var stream = gulp
    .src(paths.javascript)
    .pipe(plumber())
    .pipe(include())
    .pipe(coffee())
    .pipe(uglify(dev({ compress: false })))
    .pipe(gulp.dest('./js'));

  if(development) {
    stream = stream.pipe(livereload());
  }

  return stream;
});

gulp.task('modernizr', function() {
  var stream = gulp
    .src('./style.css')
    .pipe(modernizr('modernizr-cust.js'))
    .pipe(uglify())
    .pipe(gulp.dest("./"));
  return stream;
});

gulp.task('images', function() {
  var stream = gulp
    .src(paths.images)
    .pipe(plumber())
    .pipe(imagemin())
    .pipe(gulp.dest('./images'));

  if(development) {
    stream = stream.pipe(livereload());
  }

  return stream;
});

gulp.task('svg', function() {
  var stream = gulp
    .src(paths.svg)
    .pipe(plumber())
    .pipe(svgmin())
    .pipe(gulp.dest('./images'));

  if(development) {
    stream = stream.pipe(livereload());
  }

  return stream;
});

gulp.task('watch', function() {
  gulp.watch(paths.pages, ['compile']);
  gulp.watch(paths.stylesheets, ['styles']);
  gulp.watch(paths.javascripts, ['scripts']);
  gulp.watch(paths.images, ['images']);
  gulp.watch(paths.svg, ['svg']);
});

gulp.task('serve', ['default'], function() {

  // Start Connect server
  var app = connect().use(connect.static('.'));
  http.createServer(app).listen(CONNECT_PORT);

  // Open local server in browser
  open('http://localhost:' + CONNECT_PORT);

});

// define grouped tasks ----------------------------------------------------------------------------
gulp.task('default', ['pages', 'styles', 'scripts', 'images', 'svg', 'serve', 'watch']);

gulp.task('build', ['pages', 'styles', 'scripts', 'images', 'svg', 'modernizr']);
<commit_msg>use /img instead of /images<commit_after>// require all the plugins used --------------------------------------------------------------------
var gulp        = require('gulp'),
    jade        = require('gulp-jade'),
    compass     = require('gulp-compass'),
    plumber     = require('gulp-plumber'),
    livereload  = require('gulp-livereload'),
    imagemin    = require('gulp-imagemin'),
    svgmin      = require('gulp-imagemin'),
    modernizr   = require('gulp-modernizr'),
    uglify      = require('gulp-uglify'),
    include     = require('gulp-include'),
    coffee      = require('gulp-coffee'),

    // open a file or url
    open    = require('open'),

    // http server
    http = require('http'),
    connect       = require('connect'),

    // through = stream handling
    through       = require('through'),

    // gulp_args = argument parser
    gulp_args     = require('minimist')(process.argv.slice(2)),

    development = gulp_args.dev,
    dev = function (stream) {
      return development ? stream : through();
    },
    CONNECT_PORT = 8000,
    paths;

// saving paths ------------------------------------------------------------------------------------
paths = {
  pages: './*.jade',
  styles: 'app/stylesheets/',
  stylesheet: 'app/stylesheets/style.sass',
  stylesheets: 'app/stylesheets/**/*.{scss,sass}',
  javascript: 'app/javascripts/scripts.coffee',
  javascripts: 'app/javascripts/**/*.{coffee,js}',
  images: 'app/images/**/*.{png,jpg,gif,jpeg}',
  svg: 'app/images/**/*.svg'
};

// define tasks ------------------------------------------------------------------------------------
gulp.task('pages', function() {
  var stream = gulp
    .src(paths.pages)
    .pipe(plumber())
    .pipe(jade(dev({ pretty: true })))
    .pipe(gulp.dest('./'));

  if(development) {
    stream = stream.pipe(livereload());
  }

  return stream;
});

gulp.task('styles', function() {
  var stream = gulp
    .src(paths.stylesheet)
    .pipe(plumber())
    .pipe(compass({
      sass: paths.styles,
      css: './',
      style: development ? 'expanded' : 'compressed'
    }))
    .pipe(gulp.dest('./'));

  if(development) {
    stream = stream.pipe(livereload());
  }

  return stream;
});

gulp.task('scripts', function() {
  var stream = gulp
    .src(paths.javascript)
    .pipe(plumber())
    .pipe(include())
    .pipe(coffee())
    .pipe(uglify(dev({ compress: false })))
    .pipe(gulp.dest('./js'));

  if(development) {
    stream = stream.pipe(livereload());
  }

  return stream;
});

gulp.task('modernizr', function() {
  var stream = gulp
    .src('./style.css')
    .pipe(modernizr('modernizr-cust.js'))
    .pipe(uglify())
    .pipe(gulp.dest("./"));
  return stream;
});

gulp.task('images', function() {
  var stream = gulp
    .src(paths.images)
    .pipe(plumber())
    .pipe(imagemin())
    .pipe(gulp.dest('./img'));

  if(development) {
    stream = stream.pipe(livereload());
  }

  return stream;
});

gulp.task('svg', function() {
  var stream = gulp
    .src(paths.svg)
    .pipe(plumber())
    .pipe(svgmin())
    .pipe(gulp.dest('./img'));

  if(development) {
    stream = stream.pipe(livereload());
  }

  return stream;
});

gulp.task('watch', function() {
  gulp.watch(paths.pages, ['compile']);
  gulp.watch(paths.stylesheets, ['styles']);
  gulp.watch(paths.javascripts, ['scripts']);
  gulp.watch(paths.images, ['images']);
  gulp.watch(paths.svg, ['svg']);
});

gulp.task('serve', ['default'], function() {

  // Start Connect server
  var app = connect().use(connect.static('.'));
  http.createServer(app).listen(CONNECT_PORT);

  // Open local server in browser
  open('http://localhost:' + CONNECT_PORT);

});

// define grouped tasks ----------------------------------------------------------------------------
gulp.task('default', ['pages', 'styles', 'scripts', 'images', 'svg', 'serve', 'watch']);

gulp.task('build', ['pages', 'styles', 'scripts', 'images', 'svg', 'modernizr']);
<|endoftext|>


<commit_before>'use strict';

const gulp = require('gulp');
const htmlmin = require('gulp-htmlmin');
const replace = require('gulp-replace-task');
const spawn = require('child_process').spawn;
const fileinclude = require('gulp-file-include');
const liveServer = require('gulp-live-server');
const runSequence = require('run-sequence');

const build = (VQ_TENANT_API_URL, env) => {
    gulp.src([ 'src/**/index.html' ])
    .pipe(replace({
        patterns: [
            {
                match: 'VQ_TENANT_API_URL',
                replacement: VQ_TENANT_API_URL
            },
            {
                match: 'VQ_WEB_ENV',
                replacement: env
            },
            {
                match: 'VQ_WEB_URL',
                replacement: env === 'production' ? 'https://vqmarketplace.com' : 'http://localhost:3000'
            }
        ]
    }))
    .pipe(fileinclude({
      prefix: '@@',
      basepath: '@file'
    }))
    .pipe(htmlmin({ collapseWhitespace: true }))
    .pipe(gulp.dest('public'));

    gulp.src([ 'src/**/*.js' ])
    .pipe(replace({
        patterns: [
            {
                match: 'VQ_TENANT_API_URL',
                replacement: VQ_TENANT_API_URL
            },
            {
                match: 'VQ_WEB_ENV',
                replacement: env
            },
            {
                match: 'VQ_WEB_URL',
                replacement: env === 'production' ? 'https://vqmarketplace.com' : 'http://localhost:3000'
            }
        ]
    }))
    .pipe(gulp.dest('public'));

    gulp.src([ 'src/**/*.css' ])
    .pipe(fileinclude({
      prefix: '@@',
      basepath: '@file'
    }))
    .pipe(gulp.dest('public'))

    gulp.src([ 'assets/**/*' ])
    .pipe(gulp.dest('public'))
};

gulp.task('run:prod', function(cb) {
    runSequence(
        'build:prod',
        'runServer',
        cb
    );
});
gulp.task('run:dev', function(cb) {
    runSequence(
        'build:dev',
        'watch:dev',
        'runServer',
        cb
    );
});
gulp.task('run:local', function(cb) {
    runSequence(
        'build:local',
        'watch:local',
        'runServer',
        cb
    );
});

gulp.task('build:prod', () => build('https://vqmarketplace.vqmarketplace.com/api', 'production'));
gulp.task('build:dev', () => build('https://vqmarketplace.vqmarketplace.com/api', 'development'));
gulp.task('build:local', () => build('http://localhost:8081/api', 'local'));

gulp.task('watch:prod', () => gulp.watch('./src/**/**',  [ 'build:prod' ]));
gulp.task('watch:dev', () => gulp.watch('./src/**/**',  [ 'build:dev' ]));
gulp.task('watch:local', () => gulp.watch('./src/**/**',  [ 'build:local' ]));

gulp.task('runServer', function() {
    var server = liveServer.static('./public');
    server.start();
});

gulp.task('deploy', function() {
    const args = [ './**', '--region', 'eu-central-1', '--bucket', 'vqmarketplace.com', '--gzip' ];
    const npm = spawn("s3-deploy", args, { cwd: './public' });

    npm.stdout.on('data', data => {
        console.log(`stdout: ${data}`);
    });

    npm.stderr.on('data', data => {
        console.log(`stderr: ${data}`);
    });

    npm.on('close', code => {
        console.log(code !== 0 ? 'error in build' : 0);
    });
});<commit_msg>fix wrong dev. website url<commit_after>'use strict';

const gulp = require('gulp');
const htmlmin = require('gulp-htmlmin');
const replace = require('gulp-replace-task');
const spawn = require('child_process').spawn;
const fileinclude = require('gulp-file-include');
const liveServer = require('gulp-live-server');
const runSequence = require('run-sequence');

const build = (VQ_TENANT_API_URL, env) => {
    gulp.src([ 'src/**/index.html' ])
    .pipe(replace({
        patterns: [
            {
                match: 'VQ_TENANT_API_URL',
                replacement: VQ_TENANT_API_URL
            },
            {
                match: 'VQ_WEB_ENV',
                replacement: env
            },
            {
                match: 'VQ_WEB_URL',
                replacement: env === 'production' || env === 'development' ? 'https://vqmarketplace.com' : 'http://localhost:3000'
            }
        ]
    }))
    .pipe(fileinclude({
      prefix: '@@',
      basepath: '@file'
    }))
    .pipe(htmlmin({ collapseWhitespace: true }))
    .pipe(gulp.dest('public'));

    gulp.src([ 'src/**/*.js' ])
    .pipe(replace({
        patterns: [
            {
                match: 'VQ_TENANT_API_URL',
                replacement: VQ_TENANT_API_URL
            },
            {
                match: 'VQ_WEB_ENV',
                replacement: env
            },
            {
                match: 'VQ_WEB_URL',
                replacement: env === 'production' || env === 'development' ? 'https://vqmarketplace.com' : 'http://localhost:3000'
            }
        ]
    }))
    .pipe(gulp.dest('public'));

    gulp.src([ 'src/**/*.css' ])
    .pipe(fileinclude({
      prefix: '@@',
      basepath: '@file'
    }))
    .pipe(gulp.dest('public'))

    gulp.src([ 'assets/**/*' ])
    .pipe(gulp.dest('public'))
};

gulp.task('run:prod', function(cb) {
    runSequence(
        'build:prod',
        'runServer',
        cb
    );
});
gulp.task('run:dev', function(cb) {
    runSequence(
        'build:dev',
        'watch:dev',
        'runServer',
        cb
    );
});
gulp.task('run:local', function(cb) {
    runSequence(
        'build:local',
        'watch:local',
        'runServer',
        cb
    );
});

gulp.task('build:prod', () => build('https://vqmarketplace.vqmarketplace.com/api', 'production'));
gulp.task('build:dev', () => build('https://vqmarketplace.vqmarketplace.com/api', 'development'));
gulp.task('build:local', () => build('http://localhost:8081/api', 'local'));

gulp.task('watch:prod', () => gulp.watch('./src/**/**',  [ 'build:prod' ]));
gulp.task('watch:dev', () => gulp.watch('./src/**/**',  [ 'build:dev' ]));
gulp.task('watch:local', () => gulp.watch('./src/**/**',  [ 'build:local' ]));

gulp.task('runServer', function() {
    var server = liveServer.static('./public');
    server.start();
});

gulp.task('deploy', function() {
    const args = [ './**', '--region', 'eu-central-1', '--bucket', 'vqmarketplace.com', '--gzip' ];
    const npm = spawn("s3-deploy", args, { cwd: './public' });

    npm.stdout.on('data', data => {
        console.log(`stdout: ${data}`);
    });

    npm.stderr.on('data', data => {
        console.log(`stderr: ${data}`);
    });

    npm.on('close', code => {
        console.log(code !== 0 ? 'error in build' : 0);
    });
});<|endoftext|>


<commit_before>require('babel-register')
const gulp    = require('gulp')
const path    = require('path')
const babel   = require('gulp-babel')
const clean   = require('gulp-clean')
const mocha   = require('gulp-mocha')
const concat  = require('gulp-concat')
const clc     = require('cli-color')
const nodemon = require('gulp-nodemon')
var jsdoc     = require('gulp-jsdoc3')

const handleError = function (error) {
  console.log(error)
  this.emit('error')
}

const main       = 'index.js'
const buildDir   = 'build'
const libDir     = 'lib'
const testDir    = 'test'
const distDir    = 'dist'
const sources    = [path.join(libDir, '**', '*.js')]
const tests      = [path.join(testDir, '**', '*.js')]
const buildTests = tests.map(v => path.join(buildDir, v))
const buildFiles = path.join(buildDir, '**', '*.*')
const dists      = [path.join(distDir, '**', '*.js')]

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

gulp.task('clean', ['clean:lib', 'clean:test'])
gulp.task('clean:lib', function () {
  return gulp.src(path.join(buildDir, libDir), {read: false})
    .pipe(clean())
})
gulp.task('clean:test', function () {
  return gulp.src(path.join(buildDir, testDir), {read: false})
    .pipe(clean())
})

gulp.task('build', ['build:lib', 'build:test'])
gulp.task('build:lib', ['clean:lib'], function () {
  return gulp.src(sources)
    .pipe(babel())
    .pipe(gulp.dest(path.join(buildDir, libDir)))
    .pipe(gulp.dest(path.join(distDir)))
})
gulp.task('build:test', ['clean:test'], function () {
  return gulp.src(tests)
    .pipe(babel())
    .pipe(gulp.dest(path.join(buildDir, testDir)))
})

gulp.task('test', ['build'], function () {
  gulp.src(buildTests)
    .pipe(mocha({
      reporter: 'dot'
    }))
    .on('error', function (e) {
      if (typeof e.stack === 'undefined') return
      console.log(clc.red(`[ERROR] ${e.stack}`))
      this.emit(e)
    })
})
gulp.task('watch:test', ['test'], function () {
  gulp.watch([].concat(sources, tests), ['test'])
})
gulp.task('watch:build', ['build'], function () {
  gulp.watch([].concat(sources, tests), ['build'])
})
gulp.task('server', ['build:lib'], function () {
  nodemon({
    script: path.join(buildDir, libDir, 'index.js'),
    ext: 'js',
    ignore: ['gulpfile.js'].concat(buildFiles, tests, dists),
    env: {
      'NODE_ENV': 'development'
    },
    tasks: ['build:lib']
  })
})<commit_msg>Update npm test<commit_after>require('babel-register')
const gulp    = require('gulp')
const path    = require('path')
const babel   = require('gulp-babel')
const clean   = require('gulp-clean')
const mocha   = require('gulp-mocha')
const concat  = require('gulp-concat')
const clc     = require('cli-color')
const nodemon = require('gulp-nodemon')
var jsdoc     = require('gulp-jsdoc3')

const handleError = function (error) {
  console.log(error)
  this.emit('error')
}

const main       = 'index.js'
const buildDir   = 'build'
const libDir     = 'lib'
const testDir    = 'test'
const distDir    = 'dist'
const sources    = [path.join(libDir, '**', '*.js')]
const tests      = [path.join(testDir, '**', '*.js')]
const buildTests = tests.map(v => path.join(buildDir, v))
const buildFiles = path.join(buildDir, '**', '*.*')
const dists      = [path.join(distDir, '**', '*.js')]

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

gulp.task('clean', ['clean:lib', 'clean:test'])
gulp.task('clean:lib', function () {
  return gulp.src(path.join(buildDir, libDir), {read: false})
    .pipe(clean())
})
gulp.task('clean:test', function () {
  return gulp.src(path.join(buildDir, testDir), {read: false})
    .pipe(clean())
})

gulp.task('build', ['build:lib', 'build:test'])
gulp.task('build:lib', ['clean:lib'], function () {
  return gulp.src(sources)
    .pipe(babel())
    .pipe(gulp.dest(path.join(buildDir, libDir)))
    .pipe(gulp.dest(path.join(distDir)))
})
gulp.task('build:test', ['clean:test'], function () {
  return gulp.src(tests)
    .pipe(babel())
    .pipe(gulp.dest(path.join(buildDir, testDir)))
})

gulp.task('test', ['build'], function () {
  gulp.src(buildTests)
    .pipe(mocha({
      reporter: 'dot'
    }))
})
gulp.task('test:force', ['build'], function () {
  gulp.src(buildTests)
    .pipe(mocha({
      reporter: 'dot'
    }))
    .on('error', function (e) {
      if (typeof e.stack === 'undefined') return
      console.log(clc.red(`[ERROR] ${e.stack}`))
      this.emit(e)
    })
})
gulp.task('watch:test', ['test:force'], function () {
  gulp.watch([].concat(sources, tests), ['test'])
})
gulp.task('watch:build', ['build'], function () {
  gulp.watch([].concat(sources, tests), ['build'])
})
gulp.task('server', ['build:lib'], function () {
  nodemon({
    script: path.join(buildDir, libDir, 'index.js'),
    ext: 'js',
    ignore: ['gulpfile.js'].concat(buildFiles, tests, dists),
    env: {
      'NODE_ENV': 'development'
    },
    tasks: ['build:lib']
  })
})
<|endoftext|>


<commit_before>
/*
 * Main build file for fabric8-planner.
 * ---
 * Each main task has parametric handlers to achieve different result.
 * Check out the sections for task variants & accepted task arguments.
 */

// Require primitives
var del  = require('del')
  , path = require('path')
  , argv = require('yargs').argv
  , proc = require('child_process')
  ;

// Require gulp & its extension modules
var gulp = require('gulp')
  , ngc  = require('gulp-ngc')
  , less = require('gulp-less')
  , util = require('gulp-util')

  , changed   = require('gulp-changed')
  , lesshint  = require('gulp-lesshint')
  , concat    = require('gulp-concat-css')
  , srcmaps   = require('gulp-sourcemaps')
  , replace   = require('gulp-string-replace')
  ;

// Requirements with special treatments
var KarmaServer     = require('karma').Server
  , LessAutoprefix  = require('less-plugin-autoprefix')
  , autoprefix      = new LessAutoprefix({ browsers: ['last 2 versions'] })
  ;

// Not sure if var or const
var appSrc    = 'src';
var distPath  = 'dist';

/*
 * Utility functions
 */

// Global namespace to contain the reusable utility routines
let mach = {};

// Serialized typescript compile and post-compile steps
mach.transpileTS = function () {
  return (gulp.series(function () {
    return ngc('tsconfig.json');
  }, function () {
    // FIXME: why do we need that?
    // Replace templateURL/styleURL with require statements in js.
    return gulp.src(['dist/app/**/*.js'])
    .pipe(replace(/templateUrl:\s/g, "template: require("))
    .pipe(replace(/\.html',/g, ".html'),"))
    .pipe(replace(/styleUrls: \[/g, "styles: [require("))
    .pipe(replace(/\.less']/g, ".css').toString()]"))
    .pipe(gulp.dest(function (file) {
      return file.base; // because of Angular 2's encapsulation, it's natural to save the css where the less-file was
    }));
  }))();
}

// Copy files to the distPath
mach.copyToDist = function (srcArr) {
  return gulp.src(srcArr)
    .pipe(gulp.dest(function (file) {
      // Save directly to dist; @TODO: rethink the path evaluation strategy
      return distPath + file.base.slice(__dirname.length + 'src/'.length);
    }));
}

// Transpile given LESS source(s) to CSS, storing results to distPath.
mach.transpileLESS = function (src, debug) {
  var opts = {
    // THIS IS NEEDED FOR REFERENCE
    // paths: [ path.join(__dirname, 'less', 'includes') ]
  }
  return gulp.src(src)
    .pipe(less({
      plugins: [autoprefix]
    }))
    .pipe(lesshint({
      configPath: './.lesshintrc' // Options
    }))
    .pipe(lesshint.reporter()) // Leave empty to use the default, "stylish"
    .pipe(lesshint.failOnError()) // Use this to fail the task on lint errors
    .pipe(srcmaps.init())
    .pipe(less(opts))
    //.pipe(concat('styles.css'))
    .pipe(srcmaps.write())
    .pipe(gulp.dest(function (file) {
      return distPath + file.base.slice(__dirname.length + 'src/'.length);
  }));
}

/*
 * Task declarations
 */

// Build
gulp.task('build', function (done) {

  // app (default)
  mach.transpileTS(); // Transpile *.ts to *.js; _then_ post-process require statements to load templates
  mach.transpileLESS(appSrc + '/**/*.less'); // Transpile and minify less, storing results in distPath.
  mach.copyToDist(['src/**/*.html']); // Copy template html files to distPath
  gulp.src(['LICENSE', 'README.adoc', 'package.json']).pipe(gulp.dest(distPath)); // Copy static assets to distPath

  // image

  // tarball

  // validate

  // watch
  if (argv.watch) {
    gulp.watch([appSrc + '/app/**/*.ts', '!' + appSrc + '/app/**/*.spec.ts']).on('change', function (e) {
      util.log(util.colors.cyan(e) + ' has been changed. Compiling TypeScript.');
      mach.transpileTS();
    });
    gulp.watch(appSrc + '/app/**/*.less').on('change', function (e) {
      util.log(util.colors.cyan(e) + ' has been changed. Compiling LESS.');
      mach.transpileLESS(e);
    });
    gulp.watch(appSrc + '/app/**/*.html').on('change', function (e) {
      util.log(util.colors.cyan(e) + ' has been changed. Compiling HTML.');
      mach.copyToDist(e);
    });
    util.log('Now run');
    util.log('');
    util.log(util.colors.red('    npm link', path.resolve(distPath)));
    util.log('');
    util.log('in the npm module you want to link this one to');
  }

  done();

});

// Clean
gulp.task('clean', function (done) {

  // all (default): set flags to validate following conditional cleanups
  if (
    !argv.cache &&
    !argv.config &&
    !argv.dist &&
    !argv.images &&
    !argv.modules &&
    !argv.temp) {
      // if none of the known sub-task parameters for `clean` was provided
      // i.e. only `gulp clean` was called, then set default --all flag ON
      argv.all = true;
  }

  if (argv.all) {
    // Exclusively set all subroutine parameters ON for `gulp clean --all`
    argv.cache = argv.config = argv.dist = argv.images = argv.modules = argv.temp = true;
  }

  // cache
  if (argv.cache) proc.exec('npm cache clean');

  // config
  // if (argv.config) { subroutine to clean config - not yet needed }

  // dist
  if (argv.dist) del([distPath]);

  // images
  if (argv.images) {
    // Get ID of the images having 'fabric8-planner' in its name
    proc.exec('sudo docker ps -aq --filter "name=fabric8-planner"', function (e, containerID) {
      if (e) {
        console.log(e);
        return;
      }

      // @TODO: wrap this in a try-catch block to avoid unexpected behavior
      proc.exec('sudo docker stop ' + containerID);
      proc.exec('sudo docker rm '   + containerID);

      // Container has been killed, safe to remove image(s) with 'fabric8-planner-*' as part of their ref
      proc.exec('sudo docker images -aq --filter "reference=fabric8-planner-*"', function (e, imageID) {
        if (e) {
          console.log(e);
          return;
        }

        // @TODO: wrap this in a try-catch block to avoid unexpected behavior
        proc.exec('sudo docker rmi ' + imageID);
      });
    });
  }

  // modules
  if (argv.modules) del(['node_modules']);

  // temp
  if (argv.temp) del(['tmp', 'coverage', 'typings', '.sass-cache']);

  done();
});

// Release
gulp.task('release', function (done) {
  proc.exec('$(npm bin)/semantic-release', function(error, stdout) {
    console.log("error: ", error);
    console.log(stdout);
  });

  done();
});

// Test
gulp.task('tests', function (done) {

  // unit
  if (argv.unit) {
    new KarmaServer({
      configFile: __dirname + '/karma.conf.js',
      singleRun: true
    }, function (code) {
      process.exit(code);
    }).start();
  }

  // func
  if (argv.func) {
    // subroutine to run functional tests
  }

  // smok
  if (argv.smok) {
    // subroutine to run smoke tests
  }

  done();
});
<commit_msg>fix(release): copy over git repo in order for sem-rel to process<commit_after>
/*
 * Main build file for fabric8-planner.
 * ---
 * Each main task has parametric handlers to achieve different result.
 * Check out the sections for task variants & accepted task arguments.
 */

// Require primitives
var del  = require('del')
  , path = require('path')
  , argv = require('yargs').argv
  , proc = require('child_process')
  ;

// Require gulp & its extension modules
var gulp = require('gulp')
  , ngc  = require('gulp-ngc')
  , less = require('gulp-less')
  , util = require('gulp-util')

  , changed   = require('gulp-changed')
  , lesshint  = require('gulp-lesshint')
  , concat    = require('gulp-concat-css')
  , srcmaps   = require('gulp-sourcemaps')
  , replace   = require('gulp-string-replace')
  ;

// Requirements with special treatments
var KarmaServer     = require('karma').Server
  , LessAutoprefix  = require('less-plugin-autoprefix')
  , autoprefix      = new LessAutoprefix({ browsers: ['last 2 versions'] })
  ;

// Not sure if var or const
var appSrc    = 'src';
var distPath  = 'dist';

/*
 * Utility functions
 */

// Global namespace to contain the reusable utility routines
let mach = {};

// Serialized typescript compile and post-compile steps
mach.transpileTS = function () {
  return (gulp.series(function () {
    return ngc('tsconfig.json');
  }, function () {
    // FIXME: why do we need that?
    // Replace templateURL/styleURL with require statements in js.
    return gulp.src(['dist/app/**/*.js'])
    .pipe(replace(/templateUrl:\s/g, "template: require("))
    .pipe(replace(/\.html',/g, ".html'),"))
    .pipe(replace(/styleUrls: \[/g, "styles: [require("))
    .pipe(replace(/\.less']/g, ".css').toString()]"))
    .pipe(gulp.dest(function (file) {
      return file.base; // because of Angular 2's encapsulation, it's natural to save the css where the less-file was
    }));
  }))();
}

// Copy files to the distPath
mach.copyToDist = function (srcArr) {
  return gulp.src(srcArr)
    .pipe(gulp.dest(function (file) {
      // Save directly to dist; @TODO: rethink the path evaluation strategy
      return distPath + file.base.slice(__dirname.length + 'src/'.length);
    }));
}

// Transpile given LESS source(s) to CSS, storing results to distPath.
mach.transpileLESS = function (src, debug) {
  var opts = {
    // THIS IS NEEDED FOR REFERENCE
    // paths: [ path.join(__dirname, 'less', 'includes') ]
  }
  return gulp.src(src)
    .pipe(less({
      plugins: [autoprefix]
    }))
    .pipe(lesshint({
      configPath: './.lesshintrc' // Options
    }))
    .pipe(lesshint.reporter()) // Leave empty to use the default, "stylish"
    .pipe(lesshint.failOnError()) // Use this to fail the task on lint errors
    .pipe(srcmaps.init())
    .pipe(less(opts))
    //.pipe(concat('styles.css'))
    .pipe(srcmaps.write())
    .pipe(gulp.dest(function (file) {
      return distPath + file.base.slice(__dirname.length + 'src/'.length);
  }));
}

/*
 * Task declarations
 */

// Build
gulp.task('build', function (done) {

  // app (default)
  mach.transpileTS(); // Transpile *.ts to *.js; _then_ post-process require statements to load templates
  mach.transpileLESS(appSrc + '/**/*.less'); // Transpile and minify less, storing results in distPath.
  mach.copyToDist(['src/**/*.html']); // Copy template html files to distPath
  gulp.src(['LICENSE', 'README.adoc', 'package.json']).pipe(gulp.dest(distPath)); // Copy static assets to distPath

  // image

  // tarball

  // validate

  // watch
  if (argv.watch) {
    gulp.watch([appSrc + '/app/**/*.ts', '!' + appSrc + '/app/**/*.spec.ts']).on('change', function (e) {
      util.log(util.colors.cyan(e) + ' has been changed. Compiling TypeScript.');
      mach.transpileTS();
    });
    gulp.watch(appSrc + '/app/**/*.less').on('change', function (e) {
      util.log(util.colors.cyan(e) + ' has been changed. Compiling LESS.');
      mach.transpileLESS(e);
    });
    gulp.watch(appSrc + '/app/**/*.html').on('change', function (e) {
      util.log(util.colors.cyan(e) + ' has been changed. Compiling HTML.');
      mach.copyToDist(e);
    });
    util.log('Now run');
    util.log('');
    util.log(util.colors.red('    npm link', path.resolve(distPath)));
    util.log('');
    util.log('in the npm module you want to link this one to');
  }

  done();

});

// Clean
gulp.task('clean', function (done) {

  // all (default): set flags to validate following conditional cleanups
  if (
    !argv.cache &&
    !argv.config &&
    !argv.dist &&
    !argv.images &&
    !argv.modules &&
    !argv.temp) {
      // if none of the known sub-task parameters for `clean` was provided
      // i.e. only `gulp clean` was called, then set default --all flag ON
      argv.all = true;
  }

  if (argv.all) {
    // Exclusively set all subroutine parameters ON for `gulp clean --all`
    argv.cache = argv.config = argv.dist = argv.images = argv.modules = argv.temp = true;
  }

  // cache
  if (argv.cache) proc.exec('npm cache clean');

  // config
  // if (argv.config) { subroutine to clean config - not yet needed }

  // dist
  if (argv.dist) del([distPath]);

  // images
  if (argv.images) {
    // Get ID of the images having 'fabric8-planner' in its name
    proc.exec('sudo docker ps -aq --filter "name=fabric8-planner"', function (e, containerID) {
      if (e) {
        console.log(e);
        return;
      }

      // @TODO: wrap this in a try-catch block to avoid unexpected behavior
      proc.exec('sudo docker stop ' + containerID);
      proc.exec('sudo docker rm '   + containerID);

      // Container has been killed, safe to remove image(s) with 'fabric8-planner-*' as part of their ref
      proc.exec('sudo docker images -aq --filter "reference=fabric8-planner-*"', function (e, imageID) {
        if (e) {
          console.log(e);
          return;
        }

        // @TODO: wrap this in a try-catch block to avoid unexpected behavior
        proc.exec('sudo docker rmi ' + imageID);
      });
    });
  }

  // modules
  if (argv.modules) del(['node_modules']);

  // temp
  if (argv.temp) del(['tmp', 'coverage', 'typings', '.sass-cache']);

  done();
});

// Release
gulp.task('release', function (done) {
  gulp.src(['.git/**/*']).pipe(gulp.dest('dist/.git'));
  proc.exec('$(npm bin)/semantic-release', function(error, stdout) {
    console.log("error: ", error);
    console.log(stdout);
  });

  done();
});

// Test
gulp.task('tests', function (done) {

  // unit
  if (argv.unit) {
    new KarmaServer({
      configFile: __dirname + '/karma.conf.js',
      singleRun: true
    }, function (code) {
      process.exit(code);
    }).start();
  }

  // func
  if (argv.func) {
    // subroutine to run functional tests
  }

  // smok
  if (argv.smok) {
    // subroutine to run smoke tests
  }

  done();
});
<|endoftext|>


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

require('./tasks/build');
require('./tasks/sass');
require('./tasks/watch');
require('./tasks/test');

gulp.task('build', ['browserify', 'sass', 'fonts', 'assets','templates']);
gulp.task('release', ['browserify:release', 'sass', 'fonts', 'assets','templates']);
gulp.task('default', ['sass']);<commit_msg>serve task<commit_after>var gulp = require('gulp');

require('./tasks/build');
require('./tasks/sass');
require('./tasks/watch');
require('./tasks/test');
require('./tasks/server');

gulp.task('build', ['browserify', 'sass', 'fonts', 'assets','templates']);
gulp.task('release', ['browserify:release', 'sass', 'fonts', 'assets','templates']);
gulp.task('default', ['sass']);<|endoftext|>


<commit_before>var browserify = require('browserify'),
  concat = require('gulp-concat'),
  eslint = require('gulp-eslint'),
  gulp = require('gulp'),
  insert = require('gulp-insert'),
  karma = require('karma'),
  package = require('./package.json'),
  path = require('path'),
  replace = require('gulp-replace'),
  source = require('vinyl-source-stream');
  streamify = require('gulp-streamify'),
  uglify = require('gulp-uglify'),
  yargs = require('yargs');

var srcDir = './src/';
var srcFiles = srcDir + '**.js';
var buildDir = './';
var docsDir = './docs/';

var header = "/*!\n\
 * chartjs-chart-financial\n\
 * Version: {{ version }}\n\
 *\n\
 * Copyright 2017 chartjs-chart-financial contributors\n\
 * Released under the MIT license\n\
 * https://github.com/chartjs/chartjs-chart-financial/blob/master/LICENSE.md\n\
 */\n";

gulp.task('default', ['build', 'watch']);
gulp.task('build', buildTask);
gulp.task('lint', lintTask);
gulp.task('watch', watchTask);
gulp.task('test', ['lint', 'unittest']);
gulp.task('unittest', unittestTask);

var argv = yargs
  .option('force-output', {default: false})
  .option('silent-errors', {default: false})
  .option('verbose', {default: false})
  .argv;

function buildTask() {
  var nonBundled = browserify('./src/index.js')
    .ignore('chart.js')
    .bundle()
    .pipe(source('Chart.Financial.js'))
    .pipe(insert.prepend(header))
    .pipe(streamify(replace('{{ version }}', package.version)))
    .pipe(gulp.dest(buildDir))
    .pipe(gulp.dest(docsDir))
    .pipe(streamify(uglify()))
    .pipe(streamify(concat('Chart.Financial.min.js')))
    .pipe(gulp.dest(buildDir));

  return nonBundled;

}

function lintTask() {
  var files = [
//    'docs/**/*.js',
    'src/**/*.js'
//    'test/**/*.js'
  ];

  // NOTE(SB) codeclimate has 'complexity' and 'max-statements' eslint rules way too strict
  // compare to what the current codebase can support, and since it's not straightforward
  // to fix, let's turn them as warnings and rewrite code later progressively.
  var options = {
    rules: {
      'complexity': [1, 10],
      'max-statements': [1, 30]
    }
  };

  return gulp.src(files)
    .pipe(eslint(options))
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
}

function startTest() {
  return [
    './node_modules/moment/min/moment.min.js',
    './test/jasmine.index.js',
    './src/**/*.js',
  ].concat(
    ['./test/specs/**/*.js']
  );
}

function unittestTask(done) {
  new karma.Server({
    configFile: path.join(__dirname, 'karma.conf.js'),
    singleRun: !argv.watch,
    files: startTest(),
    args: {
      coverage: !!argv.coverage
    }
  },
  // https://github.com/karma-runner/gulp-karma/issues/18
  function(error) {
    error = error ? new Error('Karma returned with the error code: ' + error) : undefined;
    done(error);
  }).start();
}

function watchTask() {
  return gulp.watch(srcFiles, ['build']);
}
<commit_msg>Fix gulpfile to work with gulp 4.0<commit_after>var browserify = require('browserify'),
  concat = require('gulp-concat'),
  eslint = require('gulp-eslint'),
  gulp = require('gulp'),
  insert = require('gulp-insert'),
  karma = require('karma'),
  package = require('./package.json'),
  path = require('path'),
  replace = require('gulp-replace'),
  source = require('vinyl-source-stream');
  streamify = require('gulp-streamify'),
  uglify = require('gulp-uglify'),
  yargs = require('yargs');

var srcDir = './src/';
var srcFiles = srcDir + '**.js';
var buildDir = './';
var docsDir = './docs/';

var header = "/*!\n\
 * chartjs-chart-financial\n\
 * Version: {{ version }}\n\
 *\n\
 * Copyright 2017 chartjs-chart-financial contributors\n\
 * Released under the MIT license\n\
 * https://github.com/chartjs/chartjs-chart-financial/blob/master/LICENSE.md\n\
 */\n";

gulp.task('build', buildTask);
gulp.task('lint', lintTask);
gulp.task('unittest', unittestTask);
gulp.task('test', gulp.parallel('lint', 'unittest'));
gulp.task('watch', watchTask);
gulp.task('default', gulp.parallel('build'));

var argv = yargs
  .option('force-output', {default: false})
  .option('silent-errors', {default: false})
  .option('verbose', {default: false})
  .argv;

function buildTask() {
  var nonBundled = browserify('./src/index.js')
    .ignore('chart.js')
    .bundle()
    .pipe(source('Chart.Financial.js'))
    .pipe(insert.prepend(header))
    .pipe(streamify(replace('{{ version }}', package.version)))
    .pipe(gulp.dest(buildDir))
    .pipe(gulp.dest(docsDir))
    .pipe(streamify(uglify()))
    .pipe(streamify(concat('Chart.Financial.min.js')))
    .pipe(gulp.dest(buildDir));

  return nonBundled;

}

function lintTask() {
  var files = [
//    'docs/**/*.js',
    'src/**/*.js'
//    'test/**/*.js'
  ];

  // NOTE(SB) codeclimate has 'complexity' and 'max-statements' eslint rules way too strict
  // compare to what the current codebase can support, and since it's not straightforward
  // to fix, let's turn them as warnings and rewrite code later progressively.
  var options = {
    rules: {
      'complexity': [1, 10],
      'max-statements': [1, 30]
    }
  };

  return gulp.src(files)
    .pipe(eslint(options))
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
}

function startTest() {
  return [
    './node_modules/moment/min/moment.min.js',
    './test/jasmine.index.js',
    './src/**/*.js',
  ].concat(
    ['./test/specs/**/*.js']
  );
}

function unittestTask(done) {
  new karma.Server({
    configFile: path.join(__dirname, 'karma.conf.js'),
    singleRun: !argv.watch,
    files: startTest(),
    args: {
      coverage: !!argv.coverage
    }
  },
  // https://github.com/karma-runner/gulp-karma/issues/18
  function(error) {
    error = error ? new Error('Karma returned with the error code: ' + error) : undefined;
    done(error);
  }).start();
}

function watchTask() {
  return gulp.watch(srcFiles, ['build']);
}
<|endoftext|>


<commit_before>var gulp = require('gulp'),
    less = require('gulp-less'),
    cleancss = require('gulp-clean-css'),
    autoprefixer = require('gulp-autoprefixer'),
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat'),
    imagemin = require('gulp-imagemin');

gulp.task('styles', function() {
    gulp.src('./app/Resources/assets/less/**/*.less')
        .pipe(less())
        .pipe(autoprefixer('last 2 versions', 'ie 8', 'ie 9'))
        .pipe(cleancss({compatibility: 'ie11'}))
        .pipe(concat('style.css'))
        .pipe(gulp.dest('./web/css/'))
});

gulp.task('images', function(){
    gulp.src('./app/Resources/assets/img/**/*')
        .pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
        .pipe(gulp.dest('./web/img/'));
});

gulp.task('scripts', function(){
    gulp.src('./app/Resources/assets/js/**/*')
        .pipe(uglify())
        .pipe(concat('script.js'))
        .pipe(gulp.dest('./web/js/'));
});

gulp.task('bootstrap:scripts', function(){
    gulp.src('./node_modules/bootstrap/js/**/*.js')
        .pipe(uglify())
        .pipe(concat('bootstrap.min.js'))
        .pipe(gulp.dest('./web/js/'));
});

gulp.task('bootstrap:styles', function() {
    gulp.src('./node_modules/bootstrap/less/**/*.less')
        .pipe(less())
        .pipe(autoprefixer('last 2 versions', 'ie 8', 'ie 9'))
        .pipe(cleancss({compatibility: 'ie11'}))
        .pipe(concat('bootstrap.css'))
        .pipe(gulp.dest('./web/css/'))
});

gulp.task('bootstrap:fonts', function() {
    gulp.src('./node_modules/bootstrap/fonts/**/*')
        .pipe(gulp.dest('./web/fonts/'))
});

gulp.task('jquery:scripts', function() {
    gulp.src('./node_modules/jquery/dist/jquery.min.js')
        .pipe(gulp.dest('./web/js/'))
});

gulp.task('bootstrap',['bootstrap:scripts','bootstrap:styles','bootstrap:fonts']);
gulp.task('jquery',['jquery:scripts']);

gulp.task('default',['bootstrap','jquery','styles','images','scripts'],function() {
    gulp.watch('./app/Resources/assets/less/*.less',['styles']);
    gulp.watch('./app/Resources/assets/js/*.js',['scripts']);
    gulp.watch('./app/Resources/assets/img/**/*',['images']);
});<commit_msg>gulpfile mini bugfix<commit_after>var gulp = require('gulp'),
    less = require('gulp-less'),
    cleancss = require('gulp-clean-css'),
    autoprefixer = require('gulp-autoprefixer'),
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat'),
    imagemin = require('gulp-imagemin');

gulp.task('styles', function() {
    gulp.src('./app/Resources/assets/less/**/*.less')
        .pipe(less())
        .pipe(autoprefixer('last 2 versions', 'ie 8', 'ie 9'))
        .pipe(cleancss({compatibility: 'ie11'}))
        .pipe(concat('style.css'))
        .pipe(gulp.dest('./web/css/'))
});

gulp.task('images', function(){
    gulp.src('./app/Resources/assets/img/**/*')
        .pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
        .pipe(gulp.dest('./web/img/'));
});

gulp.task('scripts', function(){
    gulp.src('./app/Resources/assets/js/**/*')
        .pipe(uglify())
        .pipe(concat('script.js'))
        .pipe(gulp.dest('./web/js/'));
});

gulp.task('bootstrap:scripts', function(){
    gulp.src('./node_modules/bootstrap/js/**/*.js')
        .pipe(uglify())
        .pipe(concat('bootstrap.min.js'))
        .pipe(gulp.dest('./web/js/'));
});

gulp.task('bootstrap:styles', function() {
    gulp.src('./node_modules/bootstrap/dist/css/bootstrap.min.css')
        .pipe(gulp.dest('./web/css/'))
});

gulp.task('bootstrap:fonts', function() {
    gulp.src('./node_modules/bootstrap/fonts/**/*')
        .pipe(gulp.dest('./web/fonts/'))
});

gulp.task('jquery:scripts', function() {
    gulp.src('./node_modules/jquery/dist/jquery.min.js')
        .pipe(gulp.dest('./web/js/'))
});

gulp.task('bootstrap',['bootstrap:scripts','bootstrap:styles','bootstrap:fonts']);
gulp.task('jquery',['jquery:scripts']);

gulp.task('default',['bootstrap','jquery','styles','images','scripts'],function() {
    gulp.watch('./app/Resources/assets/less/*.less',['styles']);
    gulp.watch('./app/Resources/assets/js/*.js',['scripts']);
    gulp.watch('./app/Resources/assets/img/**/*',['images']);
});<|endoftext|>


<commit_before>'use strict';

var spawn = require('child_process').spawn,
    path = require('path'),
    existsSync = require('fs').existsSync;

var gulp = require('gulp'),
    less = require('gulp-less'),
    source = require('vinyl-source-stream'),
    buffer = require('vinyl-buffer'),
    watchify = require('watchify'),
    errorify = require('errorify'),
    gutil = require('gulp-util'),
    browserify = require('browserify'),
    runSequence = require('gulp-sequence'),
    which = require('which'),
    mocha = require('gulp-mocha');

var packager = require('electron-packager'),
    electron = require('electron-prebuilt'),
    copyRecursive = require('ncp'),
    app = require('electron-connect').server.create({ path: 'app/develop' });

var assign = require('lodash/object/assign'),
    forEach = require('lodash/collection/forEach');

var PACKAGE_JSON = require('./package.json'),
    ELECTRON_VERSION = '0.34.3';

// add custom browserify options here
var browserifyOptions = {
  entries: [ './client/lib/index.js' ],
  debug: true,
  transform: [ 'stringify' ]
};

// add transformations here
// i.e. b.transform(coffeeify);

function browserBundle(options) {

  var bundler,
      bundleOptions;

  function build() {
    return bundler
             .bundle()
             .pipe(source('index.js'))
             .pipe(buffer())
             .pipe(gulp.dest('public/'));
  }

  if (options && options.watch) {

    bundleOptions = assign({}, watchify.args, browserifyOptions);

    bundler = watchify(browserify(bundleOptions));

    bundler.plugin(errorify);

    bundler.on('update', build);

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

    // reload app on rebuild
    bundler.on('log', app.reload.bind(app, null, null));

  } else {
    bundler = browserify(browserifyOptions);
  }

  bundler.build = build;

  return build();
}

function buildDistroIgnore() {

  var ignore = [
    'app/develop',
    'distro',
    'client',
    'resources',
    'test',
    '.editorconfig',
    '.gitignore',
    '.jshintrc',
    'gulpfile.js',
    'README.md'
  ];

  forEach(PACKAGE_JSON.devDependencies, function(version, name) {
    ignore.push('node_modules/' + name);
  });

  return new RegExp('(' + ignore.join('|') + ')');
}

var archiver = require('archiver'),
    fs = require('fs');

function createArchive(platform, path, done) {

  return function(err) {

    if (err) {
      return done(err);
    }

    var archive,
        dest = path,
        output;

    if (platform === 'win32') {
      archive = archiver('zip', {});
      dest += '.zip';
    } else {
      archive = archiver('tar', { gzip: true });
      dest += '.tar.gz';
    }

    output = fs.createWriteStream(dest);

    archive.pipe(output);
    archive.on('end', done);
    archive.on('error', done);

    archive.directory(path, 'camunda-modeler').finalize();
  };
}

function amendAndArchive(platform, paths, done) {

  var idx = 0;

  var platformAssets = __dirname + '/resources/' + platform;

  function processNext(err) {

    if (err) {
      return done(err);
    }

    var currentPath = paths[idx++];

    if (!currentPath) {
      return done(err, paths);
    }

    var archive = createArchive(platform, currentPath, processNext);

    if (existsSync(platformAssets)) {
      copyRecursive(platformAssets, currentPath, archive);
    } else {
      archive();
    }
  }

  processNext();
}

// package pre-built electron application for the given platform

function electronPackage(platform) {
  var opts = {
    name: PACKAGE_JSON.name,
    version: ELECTRON_VERSION,
    dir: '.',
    out: 'distro',
    overwrite: true,
    asar: true,
    arch: 'all',
    platform: platform,
    icon: __dirname + '/resources/icons/icon_128'
  };

  opts['app-version'] = PACKAGE_JSON.version;
  opts.ignore = buildDistroIgnore();

  if (platform === 'darwin') {
    opts.name = 'Camunda Modeler';
  }

  if (platform === 'win32') {
    opts['version-string'] = {
      CompanyName: 'camunda Services GmbH',
      LegalCopyright: 'camunda Services GmbH, 2015',
      FileDescription: 'Camunda Modeler',
      OriginalFilename: 'camunda-modeler.exe',
      // inherited by electron
      // FileVersion: ELECTRON_VERSION,
      ProductVersion: PACKAGE_JSON.version,
      ProductName: 'Camunda Modeler',
      InternalName: 'camunda-modeler'
    };
  }

  // make sure wine is available on linux systems
  // if we are building the windows distribution
  if (process.platform !== 'win32' && platform === 'win32') {
    try {
      which.sync('wine');
    } catch(e) {
      return function(done) {
        gutil.log(gutil.colors.yellow('Skipping Windows packaging: wine is not found'));
        done(null);
      };
    }
  }

  return function(done) {
    packager(opts, function(err, paths) {

      if (err) {
        return done(err);
      }

      return amendAndArchive(platform, paths, done);
    });
  };
}

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

  // Start browser process
  app.start(__dirname + '/resources/diagram/simple.bpmn');

  // Restart browser process
  gulp.watch([ 'app/**/*.js' ], app.restart);

  gulp.watch([ 'client/lib/index.html' ], [ 'client:copy:html', app.reload ]);

  gulp.watch([ 'client/less/**.less' ], [ 'client:less', app.reload ]);
});

gulp.task('client:build:watch', function() {
  return browserBundle({ watch: true });
});

gulp.task('client:build', function() {
  return browserBundle();
});

gulp.task('client:less', function() {
  return gulp.src('client/less/app.less')
             .pipe(less({ paths: [ 'node_modules' ] }))
             .pipe(gulp.dest('public/css'));
});

gulp.task('client:copy:font', function() {
  return gulp.src('client/font/*').pipe(gulp.dest('public/font'));
});

gulp.task('client:copy:html', function() {
  return gulp.src('client/lib/index.html').pipe(gulp.dest('public/'));
});

gulp.task('diagram-js:css', function() {
  return gulp.src('node_modules/diagram-js/assets/diagram-js.css')
             .pipe(gulp.dest('public/vendor/diagram-js'));
});

gulp.task('properties-panel:less', function() {
  return gulp.src('node_modules/bpmn-js-properties-panel/styles/properties.less')
             .pipe(less())
             .pipe(gulp.dest('public/vendor/properties-panel'));
});

gulp.task('dmn-js:copy:font', function() {
  return gulp.src('node_modules/dmn-js/fonts/dmn-js.*').pipe(gulp.dest('public/vendor/fonts'));
});

gulp.task('dmn-js:less', function() {
  return gulp.src('node_modules/dmn-js/styles/dmn-js.less')
             .pipe(less({
               paths: [ path.join('node_modules/dmn-js', 'node_modules') ]
             }))
             .pipe(gulp.dest('public/vendor/dmn-js'));
});

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

gulp.task('client:copy:vendor', runSequence([
  'diagram-js:css',
  'properties-panel:less',
  'dmn-js:less',
  'dmn-js:copy:font'
]));

gulp.task('client:copy', runSequence([
  'client:copy:font',
  'client:copy:vendor',
  'client:copy:html'
]));

gulp.task('debug', function() {
  return spawn(electron, [ '--debug-brk=5858' ], { stdio: 'inherit' });
});

gulp.task('package:windows', electronPackage('win32'));
gulp.task('package:darwin', electronPackage('darwin'));
gulp.task('package:linux', electronPackage('linux'));

gulp.task('package', runSequence('package:windows', 'package:darwin', 'package:linux'));

gulp.task('build', runSequence('client:build', 'client:less', 'client:copy'));

gulp.task('auto-build', runSequence([ 'client:build:watch', 'client:less', 'client:copy', 'serve' ]));

gulp.task('distro', runSequence('test', 'build', 'package'));

gulp.task('distro:windows', runSequence('build', 'package:windows'));
gulp.task('distro:darwin', runSequence('build', 'package:darwin'));
gulp.task('distro:linux', runSequence('build', 'package:linux'));

gulp.task('default', runSequence('test', 'build'));
<commit_msg>fix(gulpfile): change archive name on darwin to camunda-modeler<commit_after>'use strict';

var spawn = require('child_process').spawn,
    path = require('path'),
    existsSync = require('fs').existsSync;

var gulp = require('gulp'),
    less = require('gulp-less'),
    source = require('vinyl-source-stream'),
    buffer = require('vinyl-buffer'),
    watchify = require('watchify'),
    errorify = require('errorify'),
    gutil = require('gulp-util'),
    browserify = require('browserify'),
    runSequence = require('gulp-sequence'),
    which = require('which'),
    mocha = require('gulp-mocha');

var packager = require('electron-packager'),
    electron = require('electron-prebuilt'),
    copyRecursive = require('ncp'),
    app = require('electron-connect').server.create({ path: 'app/develop' });

var assign = require('lodash/object/assign'),
    forEach = require('lodash/collection/forEach');

var PACKAGE_JSON = require('./package.json'),
    ELECTRON_VERSION = '0.34.3';

// add custom browserify options here
var browserifyOptions = {
  entries: [ './client/lib/index.js' ],
  debug: true,
  transform: [ 'stringify' ]
};

// add transformations here
// i.e. b.transform(coffeeify);

function browserBundle(options) {

  var bundler,
      bundleOptions;

  function build() {
    return bundler
             .bundle()
             .pipe(source('index.js'))
             .pipe(buffer())
             .pipe(gulp.dest('public/'));
  }

  if (options && options.watch) {

    bundleOptions = assign({}, watchify.args, browserifyOptions);

    bundler = watchify(browserify(bundleOptions));

    bundler.plugin(errorify);

    bundler.on('update', build);

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

    // reload app on rebuild
    bundler.on('log', app.reload.bind(app, null, null));

  } else {
    bundler = browserify(browserifyOptions);
  }

  bundler.build = build;

  return build();
}

function buildDistroIgnore() {

  var ignore = [
    'app/develop',
    'distro',
    'client',
    'resources',
    'test',
    '.editorconfig',
    '.gitignore',
    '.jshintrc',
    'gulpfile.js',
    'README.md'
  ];

  forEach(PACKAGE_JSON.devDependencies, function(version, name) {
    ignore.push('node_modules/' + name);
  });

  return new RegExp('(' + ignore.join('|') + ')');
}

var archiver = require('archiver'),
    fs = require('fs');

function createArchive(platform, path, done) {

  return function(err) {

    if (err) {
      return done(err);
    }

    var archive,
        dest = path,
        output;

    if (platform === 'win32') {
      archive = archiver('zip', {});
      dest += '.zip';
    } else {
      if (platform === 'darwin') {
        dest = dest.replace(/Camunda Modeler/, 'camunda-modeler');
      }

      dest += '.tar.gz';
      archive = archiver('tar', { gzip: true });
    }

    output = fs.createWriteStream(dest);

    archive.pipe(output);
    archive.on('end', done);
    archive.on('error', done);

    archive.directory(path, 'camunda-modeler').finalize();
  };
}

function amendAndArchive(platform, paths, done) {

  var idx = 0;

  var platformAssets = __dirname + '/resources/' + platform;

  function processNext(err) {

    if (err) {
      return done(err);
    }

    var currentPath = paths[idx++];

    if (!currentPath) {
      return done(err, paths);
    }

    var archive = createArchive(platform, currentPath, processNext);

    if (existsSync(platformAssets)) {
      copyRecursive(platformAssets, currentPath, archive);
    } else {
      archive();
    }
  }

  processNext();
}

// package pre-built electron application for the given platform

function electronPackage(platform) {
  var opts = {
    name: PACKAGE_JSON.name,
    version: ELECTRON_VERSION,
    dir: '.',
    out: 'distro',
    overwrite: true,
    asar: true,
    arch: 'all',
    platform: platform,
    icon: __dirname + '/resources/icons/icon_128'
  };

  opts['app-version'] = PACKAGE_JSON.version;
  opts.ignore = buildDistroIgnore();

  if (platform === 'darwin') {
    opts.name = 'Camunda Modeler';
  }

  if (platform === 'win32') {
    opts['version-string'] = {
      CompanyName: 'camunda Services GmbH',
      LegalCopyright: 'camunda Services GmbH, 2015',
      FileDescription: 'Camunda Modeler',
      OriginalFilename: 'camunda-modeler.exe',
      // inherited by electron
      // FileVersion: ELECTRON_VERSION,
      ProductVersion: PACKAGE_JSON.version,
      ProductName: 'Camunda Modeler',
      InternalName: 'camunda-modeler'
    };
  }

  // make sure wine is available on linux systems
  // if we are building the windows distribution
  if (process.platform !== 'win32' && platform === 'win32') {
    try {
      which.sync('wine');
    } catch(e) {
      return function(done) {
        gutil.log(gutil.colors.yellow('Skipping Windows packaging: wine is not found'));
        done(null);
      };
    }
  }

  return function(done) {
    packager(opts, function(err, paths) {

      if (err) {
        return done(err);
      }

      return amendAndArchive(platform, paths, done);
    });
  };
}

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

  // Start browser process
  app.start(__dirname + '/resources/diagram/simple.bpmn');

  // Restart browser process
  gulp.watch([ 'app/**/*.js' ], app.restart);

  gulp.watch([ 'client/lib/index.html' ], [ 'client:copy:html', app.reload ]);

  gulp.watch([ 'client/less/**.less' ], [ 'client:less', app.reload ]);
});

gulp.task('client:build:watch', function() {
  return browserBundle({ watch: true });
});

gulp.task('client:build', function() {
  return browserBundle();
});

gulp.task('client:less', function() {
  return gulp.src('client/less/app.less')
             .pipe(less({ paths: [ 'node_modules' ] }))
             .pipe(gulp.dest('public/css'));
});

gulp.task('client:copy:font', function() {
  return gulp.src('client/font/*').pipe(gulp.dest('public/font'));
});

gulp.task('client:copy:html', function() {
  return gulp.src('client/lib/index.html').pipe(gulp.dest('public/'));
});

gulp.task('diagram-js:css', function() {
  return gulp.src('node_modules/diagram-js/assets/diagram-js.css')
             .pipe(gulp.dest('public/vendor/diagram-js'));
});

gulp.task('properties-panel:less', function() {
  return gulp.src('node_modules/bpmn-js-properties-panel/styles/properties.less')
             .pipe(less())
             .pipe(gulp.dest('public/vendor/properties-panel'));
});

gulp.task('dmn-js:copy:font', function() {
  return gulp.src('node_modules/dmn-js/fonts/dmn-js.*').pipe(gulp.dest('public/vendor/fonts'));
});

gulp.task('dmn-js:less', function() {
  return gulp.src('node_modules/dmn-js/styles/dmn-js.less')
             .pipe(less({
               paths: [ path.join('node_modules/dmn-js', 'node_modules') ]
             }))
             .pipe(gulp.dest('public/vendor/dmn-js'));
});

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

gulp.task('client:copy:vendor', runSequence([
  'diagram-js:css',
  'properties-panel:less',
  'dmn-js:less',
  'dmn-js:copy:font'
]));

gulp.task('client:copy', runSequence([
  'client:copy:font',
  'client:copy:vendor',
  'client:copy:html'
]));

gulp.task('debug', function() {
  return spawn(electron, [ '--debug-brk=5858' ], { stdio: 'inherit' });
});

gulp.task('package:windows', electronPackage('win32'));
gulp.task('package:darwin', electronPackage('darwin'));
gulp.task('package:linux', electronPackage('linux'));

gulp.task('package', runSequence('package:windows', 'package:darwin', 'package:linux'));

gulp.task('build', runSequence('client:build', 'client:less', 'client:copy'));

gulp.task('auto-build', runSequence([ 'client:build:watch', 'client:less', 'client:copy', 'serve' ]));

gulp.task('distro', runSequence('test', 'build', 'package'));

gulp.task('distro:windows', runSequence('build', 'package:windows'));
gulp.task('distro:darwin', runSequence('build', 'package:darwin'));
gulp.task('distro:linux', runSequence('build', 'package:linux'));

gulp.task('default', runSequence('test', 'build'));
<|endoftext|>


<commit_before>var gulp         = require('gulp'),
	rename       = require('gulp-rename'),
	gulpif       = require("gulp-if"),
	debug        = require("gulp-debug"),
	order        = require("gulp-order"),
	concat       = require('gulp-concat'),
	uglify       = require('gulp-uglify'),
	runSequence  = require('run-sequence'),
	gzip         = require('gulp-gzip'),
	gutil        = require('gulp-util');

var DIST = "dist";
var SRC = "src";
var PROD = false;

var banner = ['/**',
	' * @preserve <%= pkg.name %> - <%= pkg.description %>',
	' * ',
	' * @version v<%= pkg.version %>',
	' * @link <%= pkg.homepage %>',
	' * @author <%= pkg.author %>',
	' * @license <%= pkg.license %>',
	' */',
	''].join('\n');

gulp.task("js", function () {

	var filename = "cookie-warn.js";
	var header = require('gulp-header');
	var package = require('./package.json');

	return gulp.src([
		SRC + "/*.js"
	])
		.pipe(order([
			"cookie-warn.js"
		], {
			base: SRC
		}))
		.pipe(concat(filename))
		.pipe(header(banner, {pkg: package}))
		.pipe(gulp.dest(DIST))
		.pipe(debug());

});

gulp.task("js-min", function () {

	var filename = "cookie-warn.js";
	var header = require('gulp-header');
	var package = require('./package.json');

	return gulp.src([
		DIST + "/" + filename,
	])
		.pipe(concat(filename))
		.pipe(rename({suffix: '.min'}))
		.pipe(uglify().on('error', function (err) {
			gutil.log(gutil.colors.red('[Error]'), err.toString());
			this.emit('end');
		}))
		.pipe(header(banner, {pkg: package}))
		.pipe(gulp.dest(DIST))
		.pipe(debug())
		.pipe(gzip({append: true}))
		.pipe(gulp.dest(DIST))
		.pipe(debug());

});

gulp.task("watch", function () {

	var watch = require("gulp-watch");
	var batch = require("gulp-batch");

	watch(SRC + "/*.js", batch(function (events, done) {
		gulp.start("js", done);
	}));

});

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

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

	return gulp.src(['./package.json'])
		.pipe(bump({type: 'patch', indent: 4}))
		.pipe(gulp.dest('./'))
});

gulp.task('version', function (callback) {

	var package = require('./package.json');
	var replace = require('gulp-replace');

	//@version 2.0.0

	return gulp.src([
		SRC + '/cookie-warn.js',
	])
		.pipe(replace(/@version\s\d+\.\d+\.\d+/g, '@version ' + package.version))
		.pipe(gulp.dest(SRC))
		.pipe(debug())

});

gulp.task('dev', function (callback) {

	prod = false;

	runSequence(
		["js"],
		["version"],
		callback
	)
});

gulp.task('prod', function (callback) {

	prod = true;

	runSequence(
		["bump"],
		["js-min"],
		["version"],
		callback
	)
});

<commit_msg>Fixed gulpfile typo<commit_after>var gulp         = require('gulp'),
	rename       = require('gulp-rename'),
	gulpif       = require("gulp-if"),
	debug        = require("gulp-debug"),
	order        = require("gulp-order"),
	concat       = require('gulp-concat'),
	uglify       = require('gulp-uglify'),
	runSequence  = require('run-sequence'),
	gzip         = require('gulp-gzip'),
	gutil        = require('gulp-util');

var DIST = "dist";
var SRC = "src";
var PROD = false;

var banner = ['/**',
	' * @preserve <%= pkg.name %> - <%= pkg.description %>',
	' * ',
	' * @version v<%= pkg.version %>',
	' * @link <%= pkg.homepage %>',
	' * @author <%= pkg.author %>',
	' * @license <%= pkg.license %>',
	' */',
	''].join('\n');

gulp.task("js", function () {

	var filename = "cookie-warn.js";
	var header = require('gulp-header');
	var package = require('./package.json');

	return gulp.src([
		SRC + "/*.js"
	])
		.pipe(order([
			"cookie-warn.js"
		], {
			base: SRC
		}))
		.pipe(concat(filename))
		.pipe(header(banner, {pkg: package}))
		.pipe(gulp.dest(DIST))
		.pipe(debug());

});

gulp.task("js-min", function () {

	var filename = "cookie-warn.js";
	var header = require('gulp-header');
	var package = require('./package.json');

	return gulp.src([
		DIST + "/" + filename,
	])
		.pipe(concat(filename))
		.pipe(rename({suffix: '.min'}))
		.pipe(uglify().on('error', function (err) {
			gutil.log(gutil.colors.red('[Error]'), err.toString());
			this.emit('end');
		}))
		.pipe(header(banner, {pkg: package}))
		.pipe(gulp.dest(DIST))
		.pipe(debug())
		.pipe(gzip({append: true}))
		.pipe(gulp.dest(DIST))
		.pipe(debug());

});

gulp.task("watch", function () {

	var watch = require("gulp-watch");
	var batch = require("gulp-batch");

	watch(SRC + "/*.js", batch(function (events, done) {
		gulp.start("js", done);
	}));

});

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

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

	return gulp.src(['./package.json'])
		.pipe(bump({type: 'patch', indent: 4}))
		.pipe(gulp.dest('./'));
});

gulp.task('version', function (callback) {

	var package = require('./package.json');
	var replace = require('gulp-replace');

	//@version 2.0.0

	return gulp.src([
		SRC + '/cookie-warn.js',
	])
		.pipe(replace(/@version\s\d+\.\d+\.\d+/g, '@version ' + package.version))
		.pipe(gulp.dest(SRC))
		.pipe(debug());

});

gulp.task('dev', function (callback) {

	prod = false;

	runSequence(
		["js"],
		["version"],
		callback
	);

});

gulp.task('prod', function (callback) {

	prod = true;

	runSequence(
		["bump"],
		["js-min"],
		["version"],
		callback
	);

});

<|endoftext|>


<commit_before>/**
 *
 *  Web Starter Kit
 *  Copyright 2014 Google Inc. All rights reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License
 *
 */

'use strict';

// Include Gulp & Tools We'll Use
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var del = require('del');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');
var nodemon = require('gulp-nodemon');
var pagespeed = require('psi');
var reload = browserSync.reload;

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

// Lint JavaScript
gulp.task('jshint', function () {
  return gulp.src('public/scripts/**/*.js')
    .pipe(reload({stream: true, once: true}))
    .pipe($.jshint())
    .pipe($.jshint.reporter('jshint-stylish'))
    .pipe($.if(!browserSync.active, $.jshint.reporter('fail')))
    .pipe($.uglify({mangle: false})) //mangle: false for uglify angular
    .pipe(gulp.dest('dist/scripts'))
    .pipe($.size({title: 'scripts'}));
});

// Optimize Images
gulp.task('images', function () {
  return gulp.src('public/images/**/*')
    .pipe($.imagemin({
      progressive: true,
      interlaced: true
    }))
    .pipe(gulp.dest('dist/images'))
    .pipe($.size({title: 'images'}));
});

// Copy All Files At The Root Level (public)
gulp.task('copy', function () {
  return gulp.src([
    'public/*',
    '!public/*.html',
    'node_modules/apache-server-configs/dist/.htaccess'
  ], {
    dot: true
  }).pipe(gulp.dest('dist'))
    .pipe($.size({title: 'copy'}));
});

// Copy Web Fonts To Dist
gulp.task('fonts', function () {
  return gulp.src(['public/fonts/**'])
    .pipe(gulp.dest('dist/fonts'))
    .pipe($.size({title: 'fonts'}));
});

// Compile and Automatically Prefix Stylesheets
gulp.task('sass', function () {
  // For best performance, don't add Sass partials to `gulp.src`
  return gulp.src([
    'public/styles/theme.scss',
    'public/styles/sass/*.scss'
  ])
    .pipe($.changed('styles', {extension: '.scss'}))
    .pipe($.rubySass({
      style: 'expanded',
      precision: 10
    }))
    .on('error', console.error.bind(console))
    .pipe($.autoprefixer({browsers: AUTOPREFIXER_BROWSERS}))
    .pipe(gulp.dest('.tmp/styles'))
    // Concatenate And Minify Styles
    .pipe($.if('*.css', $.csso()))
    .pipe(gulp.dest('dist/styles'))
    .pipe($.size({title: 'styles'}));
});

gulp.task('styles', function () {
  // For best performance, don't add Sass partials to `gulp.src`
  return gulp.src(['public/styles/*.css'])
    // Concatenate And Minify Styles
    .pipe($.if('*.css', $.csso()))
    .pipe(gulp.dest('dist/styles'))
    .pipe($.size({title: 'styles'}));
});

// Scan Your HTML For Assets & Optimize Them
gulp.task('html', function () {
  var assets = $.useref.assets({searchPath: '{.tmp,public}'});

  return gulp.src('public/**/*.html')
    .pipe(assets)
    // Concatenate And Minify JavaScript
    .pipe($.if('*.js', $.uglify({preserveComments: 'some'})))
    // Remove Any Unused CSS
    // Note: If not using the Style Guide, you can delete it from
    // the next line to only include styles your project uses.
    .pipe($.if('*.css', $.uncss({
      html: [
        'public/index.html',
        'public/styleguide.html'
      ],
      // CSS Selectors for UnCSS to ignore
      ignore: [
        /.navdrawer-container.open/,
        /.app-bar.open/
      ]
    })))
    // Concatenate And Minify Styles
    // In case you are still using useref build blocks
    .pipe($.if('*.css', $.csso()))
    .pipe(assets.restore())
    .pipe($.useref())
    // Update Production Style Guide Paths
    .pipe($.replace('components/components.css', 'components/main.min.css'))
    // Minify Any HTML
    .pipe($.if('*.html', $.minifyHtml()))
    // Output Files
    .pipe(gulp.dest('dist'))
    .pipe($.size({title: 'html'}));
});

// Clean Output Directory
gulp.task('clean', del.bind(null, ['.tmp', 'dist']));

// Watch Files For Changes & Reload
gulp.task('serve', ['styles', 'nodemon'], function () {
  browserSync.init(null, {
		proxy: "http://localhost:3000",
        files: ["public/**/*.*"],
        browser: "google chrome",
        port: 5000,
	});

  gulp.watch(['public/**/*.html'], reload);
  gulp.watch(['public/styles/**/*.{scss,css}'], ['styles', reload]);
  gulp.watch(['public/scripts/**/*.js'], ['jshint']);
  gulp.watch(['public/images/**/*'], reload);
});

// Build and serve the output from the dist build
gulp.task('serve:dist', ['nodemon'], function () {
  browserSync.init(null, {
		proxy: "http://localhost:3000",
        files: ["dist/**/*.*"],
        browser: "google chrome",
        port: 5000,
	});
});

gulp.task('nodemon', function (cb) {
	return nodemon({
	  script: './bin/www'
	}).on('start', function () {
      cb();
  });
});

// Build Production Files, the Default Task
gulp.task('default', ['clean'], function (cb) {
  runSequence('sass', 'styles', ['jshint', 'html', 'images', 'fonts', 'copy'], cb);
});

// Run PageSpeed Insights
// Update `url` below to the public URL for your site
gulp.task('pagespeed', pagespeed.bind(null, {
  // By default, we use the PageSpeed Insights
  // free (no API key) tier. You can use a Google
  // Developer API key if you have one. See
  // http://goo.gl/RkN0vE for info key: 'YOUR_API_KEY'
  url: 'https://example.com',
  strategy: 'mobile'
}));

// Load custom tasks from the `tasks` directory
try { require('require-dir')('tasks'); } catch (err) {}
<commit_msg>updating browserSync for sass and css<commit_after>/**
 *
 *  Web Starter Kit
 *  Copyright 2014 Google Inc. All rights reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License
 *
 */

'use strict';

// Include Gulp & Tools We'll Use
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var del = require('del');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');
var nodemon = require('gulp-nodemon');
var pagespeed = require('psi');
var reload = browserSync.reload;

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

// Lint JavaScript
gulp.task('jshint', function () {
  return gulp.src('public/scripts/**/*.js')
    .pipe(reload({stream: true, once: true}))
    .pipe($.jshint())
    .pipe($.jshint.reporter('jshint-stylish'))
    .pipe($.if(!browserSync.active, $.jshint.reporter('fail')))
    .pipe($.uglify({mangle: false})) //mangle: false for uglify angular
    .pipe(gulp.dest('dist/scripts'))
    .pipe($.size({title: 'scripts'}));
});

// Optimize Images
gulp.task('images', function () {
  return gulp.src('public/images/**/*')
    .pipe($.imagemin({
      progressive: true,
      interlaced: true
    }))
    .pipe(gulp.dest('dist/images'))
    .pipe($.size({title: 'images'}));
});

// Copy All Files At The Root Level (public)
gulp.task('copy', function () {
  return gulp.src([
    'public/*',
    '!public/*.html',
    'node_modules/apache-server-configs/dist/.htaccess'
  ], {
    dot: true
  }).pipe(gulp.dest('dist'))
    .pipe($.size({title: 'copy'}));
});

// Copy Web Fonts To Dist
gulp.task('fonts', function () {
  return gulp.src(['public/fonts/**'])
    .pipe(gulp.dest('dist/fonts'))
    .pipe($.size({title: 'fonts'}));
});

// Compile and Automatically Prefix Stylesheets
gulp.task('sass', function () {
  // For best performance, don't add Sass partials to `gulp.src`
  return gulp.src([
    'public/styles/theme.scss',
    'public/styles/sass/*.scss'
  ])
    .pipe($.changed('styles', {extension: '.scss'}))
    .pipe($.rubySass({
      style: 'expanded',
      precision: 10
    }))
    .on('error', console.error.bind(console))
    .pipe($.autoprefixer({browsers: AUTOPREFIXER_BROWSERS}))
    .pipe(gulp.dest('.tmp/styles'))
    // Concatenate And Minify Styles
    .pipe($.if('*.css', $.csso()))
    .pipe(gulp.dest('dist/styles'))
    .pipe($.size({title: 'styles'}));
});

gulp.task('styles', function () {
  // For best performance, don't add Sass partials to `gulp.src`
  return gulp.src(['public/styles/*.css'])
    // Concatenate And Minify Styles
    .pipe($.if('*.css', $.csso()))
    .pipe(gulp.dest('dist/styles'))
    .pipe($.size({title: 'styles'}));
});

// Scan Your HTML For Assets & Optimize Them
gulp.task('html', function () {
  var assets = $.useref.assets({searchPath: '{.tmp,public}'});

  return gulp.src('public/**/*.html')
    .pipe(assets)
    // Concatenate And Minify JavaScript
    .pipe($.if('*.js', $.uglify({preserveComments: 'some'})))
    // Remove Any Unused CSS
    // Note: If not using the Style Guide, you can delete it from
    // the next line to only include styles your project uses.
    .pipe($.if('*.css', $.uncss({
      html: [
        'public/index.html',
        'public/styleguide.html'
      ],
      // CSS Selectors for UnCSS to ignore
      ignore: [
        /.navdrawer-container.open/,
        /.app-bar.open/
      ]
    })))
    // Concatenate And Minify Styles
    // In case you are still using useref build blocks
    .pipe($.if('*.css', $.csso()))
    .pipe(assets.restore())
    .pipe($.useref())
    // Update Production Style Guide Paths
    .pipe($.replace('components/components.css', 'components/main.min.css'))
    // Minify Any HTML
    .pipe($.if('*.html', $.minifyHtml()))
    // Output Files
    .pipe(gulp.dest('dist'))
    .pipe($.size({title: 'html'}));
});

// Clean Output Directory
gulp.task('clean', del.bind(null, ['.tmp', 'dist']));

// Watch Files For Changes & Reload
gulp.task('serve', ['styles', 'nodemon'], function () {
  browserSync.init(null, {
		proxy: "http://localhost:3000",
        files: ["public/**/*.*"],
        browser: "google chrome",
        port: 5000,
	});

  gulp.watch(['public/**/*.html'], reload);
  gulp.watch(['public/styles/**/*.{scss,css}'], ['styles', 'sass', reload]);
  gulp.watch(['public/scripts/**/*.js'], ['jshint']);
  gulp.watch(['public/images/**/*'], reload);
});

// Build and serve the output from the dist build
gulp.task('serve:dist', ['nodemon'], function () {
  browserSync.init(null, {
		proxy: "http://localhost:3000",
        files: ["dist/**/*.*"],
        browser: "google chrome",
        port: 5000,
	});
});

gulp.task('nodemon', function (cb) {
	return nodemon({
	  script: './bin/www'
	}).on('start', function () {
      cb();
  });
});

// Build Production Files, the Default Task
gulp.task('default', ['clean'], function (cb) {
  runSequence('sass', 'styles', ['jshint', 'html', 'images', 'fonts', 'copy'], cb);
});

// Run PageSpeed Insights
// Update `url` below to the public URL for your site
gulp.task('pagespeed', pagespeed.bind(null, {
  // By default, we use the PageSpeed Insights
  // free (no API key) tier. You can use a Google
  // Developer API key if you have one. See
  // http://goo.gl/RkN0vE for info key: 'YOUR_API_KEY'
  url: 'https://example.com',
  strategy: 'mobile'
}));

// Load custom tasks from the `tasks` directory
try { require('require-dir')('tasks'); } catch (err) {}
<|endoftext|>


<commit_before>var gulp      = require('gulp'),
  concat      = require('gulp-concat'),
  rename      = require('gulp-rename'),
  cleanCss    = require('gulp-clean-css'),
  prefixer    = require('gulp-autoprefixer'),
  uglify      = require('gulp-uglify'),
  responsive  = require('gulp-responsive'),
  bower       = require('gulp-main-bower-files'),
  filter      = require('gulp-filter'),
  browserSync = require('browser-sync').create();

// TODO: include source maps.

var templatesPath = './**/*.html';
  stylesPath      = './resources/styles/*.css',
  jsPath          = './js/*.js',
  imagesPath      = './resources/images/*.{jpg,gif,png}',
  imagesBuildPath = './build/resources/images',
  bowerPath       = './bower_components/**/*';

gulp.task('styles', function() {
  gulp.src(stylesPath)
    .pipe(concat('styles.all.css'))
    .pipe(prefixer({
      browsers: ['last 2 versions'],
      cascade: false
    }))
    .pipe(cleanCss())
    .pipe(rename('main.min.css'))
    .pipe(gulp.dest('build/styles'))
    .pipe(browserSync.stream());
});

gulp.task('scripts', function() {
  gulp.src(jsPath)
    .pipe(concat('js.all.css'))
    .pipe(uglify())
    .pipe(rename('main.min.js'))
    .pipe(gulp.dest('build/js'));
});

gulp.task('scripts-watch', ['scripts'], function() {
  browserSync.reload();
  done();
});

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

  var getConfigurations = function(options) {
    return options.map(function(option) {
      return {
        name: '*',
        width: option.width,
        rename: {
          suffix: option.suffix
        },
        grayscale: 1
      }
    });
  }

  gulp.src(imagesPath)
    .pipe(responsive(getConfigurations([{
        width: 480,
        suffix: '-small'
      }, {
        width: 960,
        suffix: '-small-2x'
      }, {
        width: 700,
        suffix: '-medium'
      }, {
        width: 1400,
        suffix: '-medium-2x'
      }, {
        width: 1024,
        suffix: '-large'
      }, {
        width: 2048,
        suffix: '-large-2x'
      }]), {
        quality: 70,
        progressive: true,
        compressionLevel: 6,
        withMetaData: false
      }))
    .pipe(gulp.dest(imagesBuildPath));
});

gulp.task('bower', function() {
  var jsFilter  = filter(['**/*.js'], {restore: true}),
    cssFilter   = filter(['**/*.css'], {restore: true});

  return gulp.src('./bower.json')
    .pipe(bower())

    .pipe(jsFilter)
    .pipe(concat('vendor.js'))
    .pipe(uglify())
    .pipe(rename('vendor.min.js'))
    .pipe(gulp.dest('build/js/vendor'))
    .pipe(jsFilter.restore)

    .pipe(cssFilter)
    .pipe(concat('vendor.css'))
    .pipe(cleanCss())
    .pipe(rename('vendor.min.css'))
    .pipe(gulp.dest('build/styles/vendor'))
    .pipe(cssFilter.restore);
    // TODO: Build the fonts as well.
});

gulp.task('bower-watch', ['bower'], function() {
  browserSync.reload();
  done();
});

gulp.task('browser-sync', function() {
  browserSync.init({
    server: {
      baseDir: './'
    }
  });
});

gulp.task('serve', ['browser-sync', 'styles'], function() {
  gulp.watch(stylesPath, ['styles']);
  gulp.watch(jsPath, ['scripts-watch']);
  gulp.watch(bowerPath, ['bower-watch']);
  gulp.watch(templatesPath).on('change', browserSync.reload);
});
<commit_msg>Adding specific task for bower js files.<commit_after>var gulp      = require('gulp'),
  concat      = require('gulp-concat'),
  rename      = require('gulp-rename'),
  cleanCss    = require('gulp-clean-css'),
  prefixer    = require('gulp-autoprefixer'),
  uglify      = require('gulp-uglify'),
  responsive  = require('gulp-responsive'),
  bower       = require('gulp-main-bower-files'),
  filter      = require('gulp-filter'),
  browserSync = require('browser-sync').create();

// TODO: include source maps.

var templatesPath = './**/*.html';
  stylesPath      = './resources/styles/*.css',
  jsPath          = './js/*.js',
  imagesPath      = './resources/images/*.{jpg,gif,png}',
  imagesBuildPath = './build/resources/images',
  bowerPath       = './bower_components/**/*';

gulp.task('styles', function() {
  gulp.src(stylesPath)
    .pipe(concat('styles.all.css'))
    .pipe(prefixer({
      browsers: ['last 2 versions'],
      cascade: false
    }))
    .pipe(cleanCss())
    .pipe(rename('main.min.css'))
    .pipe(gulp.dest('build/styles'))
    .pipe(browserSync.stream());
});

gulp.task('scripts', function() {
  gulp.src(jsPath)
    .pipe(concat('js.all.css'))
    .pipe(uglify())
    .pipe(rename('main.min.js'))
    .pipe(gulp.dest('build/js'));
});

gulp.task('scripts-watch', ['scripts'], function() {
  browserSync.reload();
  done();
});

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

  var getConfigurations = function(options) {
    return options.map(function(option) {
      return {
        name: '*',
        width: option.width,
        rename: {
          suffix: option.suffix
        },
        grayscale: 1
      }
    });
  }

  gulp.src(imagesPath)
    .pipe(responsive(getConfigurations([{
        width: 480,
        suffix: '-small'
      }, {
        width: 960,
        suffix: '-small-2x'
      }, {
        width: 700,
        suffix: '-medium'
      }, {
        width: 1400,
        suffix: '-medium-2x'
      }, {
        width: 1024,
        suffix: '-large'
      }, {
        width: 2048,
        suffix: '-large-2x'
      }]), {
        quality: 70,
        progressive: true,
        compressionLevel: 6,
        withMetaData: false
      }))
    .pipe(gulp.dest(imagesBuildPath));
});

gulp.task('bower-scripts', function() {
  var jsFilter = filter(['**/*.js'], {restore: true});

  return gulp.src('./bower.json')
    .pipe(bower('**/*.js', {
      overrides: {
        jquery: {
          main: [
            './dist/jquery.min.js'
          ]
        }
      }
    }))
    .pipe(jsFilter)
    .pipe(concat('vendor.js'))
    .pipe(uglify())
    .pipe(rename('vendor.min.js'))
    .pipe(jsFilter.restore)
    .pipe(gulp.dest('build/js/vendor'))
});

gulp.task('bower-styles', function() {
  var cssFilter = filter(['**/*.css'], {restore: true});

  gulp.src('./bower.json')
    .pipe(bower())
    .pipe(cssFilter)
    .pipe(concat('vendor.css'))
    .pipe(cleanCss())
    .pipe(rename('vendor.min.css'))
    .pipe(cssFilter.restore)
    .pipe(gulp.dest('build/styles/vendor'));
})

gulp.task('bower', function() {
  var jsFilter  = filter(['**/*.js'], {restore: true}),
    cssFilter   = filter(['**/*.css'], {restore: true});

  return gulp.src('./bower.json')
    .pipe(bower())

    .pipe(jsFilter)
    .pipe(concat('vendor.js'))
    .pipe(uglify())
    .pipe(rename('vendor.min.js'))
    .pipe(jsFilter.restore)
    .pipe(gulp.dest('build/js/vendor'))

    .pipe(cssFilter)
    .pipe(concat('vendor.css'))
    .pipe(cleanCss())
    .pipe(rename('vendor.min.css'))
    .pipe(cssFilter.restore)
    .pipe(gulp.dest('build/styles/vendor'));
    // TODO: Build the fonts as well.
});

gulp.task('bower-watch', ['bower'], function() {
  browserSync.reload();
  done();
});

gulp.task('browser-sync', function() {
  browserSync.init({
    server: {
      baseDir: './'
    }
  });
});

gulp.task('serve', ['browser-sync', 'styles'], function() {
  gulp.watch(stylesPath, ['styles']);
  gulp.watch(jsPath, ['scripts-watch']);
  gulp.watch(bowerPath, ['bower-watch']);
  gulp.watch(templatesPath).on('change', browserSync.reload);
});
<|endoftext|>