<commit_before>'use strict';
/////////////////////////////////////////////////////////////////////////////
// GULP PLUGINS
var gulp = require('gulp'),
    watch = require('gulp-watch'),
    autoprefix = require('gulp-autoprefixer'),
    sass = require('gulp-sass'),
    minifyCss = require('gulp-clean-css'),
    rename = require('gulp-rename'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglify'),
    rigger = require('gulp-rigger'),
    ignore = require('gulp-ignore'),
    imageop = require('gulp-imagemin'),
    rimraf = require('rimraf'),
    browserSync = require("browser-sync"),
    reload = browserSync.reload;
    var modRewrite  = require('connect-modrewrite');

/////////////////////////////////////////////////////////////////////////////
// GULP PATHS
var path = {
    src: {
        application: 'src/app/**/*.*',
        root: 'src/*.*',
        img: 'src/assets/img/**/*.*',
        fonts: 'src/assets/fonts/**/*.*',
        css: 'src/assets/css/**/*.scss',
        js: 'src/assets/js/**/*.*'
    },
    build: {
        application: 'build/app/',
        root: 'build/',
        img: 'build/assets/img/',
        fonts: 'build/assets/fonts/',
        css: 'build/assets/cssTest/',
        cssSource: 'build/assets/css/',
        js: 'build/assets/js/'
    },
    watch: {
        application: 'src/app/**/*.*',
        root: 'src/**/*.*',
        img: 'src/assets/img/**/*.*',
        fonts: 'src/assets/fonts/**/*.*',
        css: 'src/assets/css/**/*.scss',
        js: 'src/assets/js/**/*.*'
    },
    clean: 'build/'
};

// SERVER

// ======================== Heroku Server Configuration ========================
gulp.task('serve', function () {
  var express = require("express");
  var bodyParser = require("body-parser");

  var app = express();
  app.use(express.static(__dirname + "/build"));
  app.use(bodyParser.json());

  app.get('/token', function (req, res) {
    var options = {
      method: 'POST',
      url: 'https://codehackdays.eu.auth0.com/oauth/token',
      headers: { 'content-type': 'application/json' },
      body: {
        "client_id":process.env.CLIENT_ID,
        "client_secret":process.env.CLIENT_SECRET,
        "audience":"https://codehackdays-helloworld.herokuapp.com/",
        "grant_type":"client_credentials"
      }
    };

    res.send("win");

//    request(options, function (error, response, body) {
//      if (error) { throw error };
//
//      console.log(response);
//      console.log(body);

//      res.setHeader('Content-Type', 'application/json');
//      res.send(JSON.stringify(body));
    });
  });

  var server = app.listen(process.env.PORT || 8080, function () {
      var port = server.address().port;
      console.log("App now running on port", port);
  });
});

/////////////////////////////////////////////////////////////////////////////
// PRINT ERRORS
function printError(error) {
    console.log(error.toString());
    this.emit('end');
}

/////////////////////////////////////////////////////////////////////////////
//BROWSERSYNC SERVE
var config = {
    server: {
        baseDir: "./build",
        middleware: [
                modRewrite([
                    '!\\.\\w+$ /index.html [L]'
                ])
            ]
    },
    files: ['./build/**/*'],
    tunnel: false,
    host: 'localhost',
    port: process.env.PORT || 8080,
    notify: false,
    logPrefix: "frontend",
    watchTask: true
};

gulp.task('serve2', function () {
    setTimeout(function () {
        browserSync(config);
    }, 5000)
});

/////////////////////////////////////////////////////////////////////////////
// application BUILD
gulp.task('application:build', function () {
    return gulp.src(path.src.application)
        .pipe(ignore.exclude(['*___jb_tmp___', '_header.html', '_footer.html', '_top-menu.html', '_left-menu.html']))
        .pipe(rigger())
        .on('error', printError)
        .pipe(gulp.dest(path.build.application))
        .pipe(reload({stream: true}));
});

gulp.task('root:build', function () {
    return gulp.src(path.src.root)
        .pipe(ignore.exclude(['*___jb_tmp___', 'index.php', 'MAMP-PRO-Logo.png']))
        .pipe(rigger())
        .on('error', printError)
        .pipe(gulp.dest(path.build.root))
        .pipe(reload({stream: true}));
});

/////////////////////////////////////////////////////////////////////////////
// JAVASCRIPT BUILD
gulp.task('js:build', function () {
    return gulp.src(path.src.js)
        .pipe(gulp.dest(path.build.js))
        .pipe(reload({stream: true}));
});

/////////////////////////////////////////////////////////////////////////////
// STYLES BUILD
gulp.task('css:build', function () {
    return gulp.src(path.src.css)
        .pipe(sass({outputStyle: 'expanded', indentWidth: 4}))
        .on('error', printError)
        .pipe(autoprefix({
            browsers: ['last 30 versions', '> 1%', 'ie 9'],
            cascade: true
        }))
        .pipe(ignore.exclude('mixins.css'))
        .pipe(gulp.dest(path.build.cssSource))
        .pipe(ignore.exclude('main.css'))
        .pipe(minifyCss())
        .pipe(concat('main.css'))
        .pipe(rename({extname: '.min.css'}))
        .pipe(gulp.dest(path.build.css))
        .pipe(reload({stream: true}))
});

/////////////////////////////////////////////////////////////////////////////
// IMAGES BUILD
gulp.task('img:build', function (cb) {
    gulp.src(path.src.img)
        .pipe(imageop())
        .on('error', printError)
        .pipe(gulp.dest(path.build.img))
        .on('end', cb)
});

/////////////////////////////////////////////////////////////////////////////
// FONTS BUILD
gulp.task('fonts:build', function () {
    return gulp.src(path.src.fonts)
        .pipe(gulp.dest(path.build.fonts))
});

/////////////////////////////////////////////////////////////////////////////
// BUILD ALL
gulp.task('build', [
    'application:build',
    'root:build',
    'fonts:build',
    'img:build',
    'css:build',
    'js:build'
]);

/////////////////////////////////////////////////////////////////////////////
// WATCH ALL
gulp.task('watch', function () {
    watch([path.watch.application], function (event, cb) {
        gulp.start('application:build');
    });
    watch([path.watch.root], function (event, cb) {
        gulp.start('root:build');
    });
    watch([path.watch.img], function (event, cb) {
        gulp.start('img:build');
    });
    watch([path.watch.fonts], function (event, cb) {
        gulp.start('fonts:build');
    });
    watch([path.watch.css], function (event, cb) {
        gulp.start('css:build');
    });
    watch([path.watch.js], function (event, cb) {
        gulp.start('js:build');
    });
});

/////////////////////////////////////////////////////////////////////////////
// CLEAN PRODUCTION
gulp.task('clean', function (cb) {
    rimraf(path.clean, cb);
});

/////////////////////////////////////////////////////////////////////////////
// DEFAULT TASK
gulp.task('default', ['build', 'serve', 'watch']);
gulp.task('develop', ['build', 'serve2', 'watch']);
<commit_msg>Just a test<commit_after>'use strict';
/////////////////////////////////////////////////////////////////////////////
// GULP PLUGINS
var gulp = require('gulp'),
    watch = require('gulp-watch'),
    autoprefix = require('gulp-autoprefixer'),
    sass = require('gulp-sass'),
    minifyCss = require('gulp-clean-css'),
    rename = require('gulp-rename'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglify'),
    rigger = require('gulp-rigger'),
    ignore = require('gulp-ignore'),
    imageop = require('gulp-imagemin'),
    rimraf = require('rimraf'),
    browserSync = require("browser-sync"),
    reload = browserSync.reload;
    var modRewrite  = require('connect-modrewrite');

/////////////////////////////////////////////////////////////////////////////
// GULP PATHS
var path = {
    src: {
        application: 'src/app/**/*.*',
        root: 'src/*.*',
        img: 'src/assets/img/**/*.*',
        fonts: 'src/assets/fonts/**/*.*',
        css: 'src/assets/css/**/*.scss',
        js: 'src/assets/js/**/*.*'
    },
    build: {
        application: 'build/app/',
        root: 'build/',
        img: 'build/assets/img/',
        fonts: 'build/assets/fonts/',
        css: 'build/assets/cssTest/',
        cssSource: 'build/assets/css/',
        js: 'build/assets/js/'
    },
    watch: {
        application: 'src/app/**/*.*',
        root: 'src/**/*.*',
        img: 'src/assets/img/**/*.*',
        fonts: 'src/assets/fonts/**/*.*',
        css: 'src/assets/css/**/*.scss',
        js: 'src/assets/js/**/*.*'
    },
    clean: 'build/'
};

// SERVER

// ======================== Heroku Server Configuration ========================
gulp.task('serve', function () {
  var express = require("express");
  var bodyParser = require("body-parser");

  var app = express();
  app.use(express.static(__dirname + "/build"));
  app.use(bodyParser.json());

  app.get('/token', function (req, res) {
//    var options = {
//      method: 'POST',
//      url: 'https://codehackdays.eu.auth0.com/oauth/token',
//      headers: { 'content-type': 'application/json' },
//      body: {
//        "client_id":process.env.CLIENT_ID,
//        "client_secret":process.env.CLIENT_SECRET,
//        "audience":"https://codehackdays-helloworld.herokuapp.com/",
//        "grant_type":"client_credentials"
//      }
//    };

    res.send("win");

//    request(options, function (error, response, body) {
//      if (error) { throw error };
//
//      console.log(response);
//      console.log(body);

//      res.setHeader('Content-Type', 'application/json');
//      res.send(JSON.stringify(body));
    });
  });

  var server = app.listen(process.env.PORT || 8080, function () {
      var port = server.address().port;
      console.log("App now running on port", port);
  });
});

/////////////////////////////////////////////////////////////////////////////
// PRINT ERRORS
function printError(error) {
    console.log(error.toString());
    this.emit('end');
}

/////////////////////////////////////////////////////////////////////////////
//BROWSERSYNC SERVE
var config = {
    server: {
        baseDir: "./build",
        middleware: [
                modRewrite([
                    '!\\.\\w+$ /index.html [L]'
                ])
            ]
    },
    files: ['./build/**/*'],
    tunnel: false,
    host: 'localhost',
    port: process.env.PORT || 8080,
    notify: false,
    logPrefix: "frontend",
    watchTask: true
};

gulp.task('serve2', function () {
    setTimeout(function () {
        browserSync(config);
    }, 5000)
});

/////////////////////////////////////////////////////////////////////////////
// application BUILD
gulp.task('application:build', function () {
    return gulp.src(path.src.application)
        .pipe(ignore.exclude(['*___jb_tmp___', '_header.html', '_footer.html', '_top-menu.html', '_left-menu.html']))
        .pipe(rigger())
        .on('error', printError)
        .pipe(gulp.dest(path.build.application))
        .pipe(reload({stream: true}));
});

gulp.task('root:build', function () {
    return gulp.src(path.src.root)
        .pipe(ignore.exclude(['*___jb_tmp___', 'index.php', 'MAMP-PRO-Logo.png']))
        .pipe(rigger())
        .on('error', printError)
        .pipe(gulp.dest(path.build.root))
        .pipe(reload({stream: true}));
});

/////////////////////////////////////////////////////////////////////////////
// JAVASCRIPT BUILD
gulp.task('js:build', function () {
    return gulp.src(path.src.js)
        .pipe(gulp.dest(path.build.js))
        .pipe(reload({stream: true}));
});

/////////////////////////////////////////////////////////////////////////////
// STYLES BUILD
gulp.task('css:build', function () {
    return gulp.src(path.src.css)
        .pipe(sass({outputStyle: 'expanded', indentWidth: 4}))
        .on('error', printError)
        .pipe(autoprefix({
            browsers: ['last 30 versions', '> 1%', 'ie 9'],
            cascade: true
        }))
        .pipe(ignore.exclude('mixins.css'))
        .pipe(gulp.dest(path.build.cssSource))
        .pipe(ignore.exclude('main.css'))
        .pipe(minifyCss())
        .pipe(concat('main.css'))
        .pipe(rename({extname: '.min.css'}))
        .pipe(gulp.dest(path.build.css))
        .pipe(reload({stream: true}))
});

/////////////////////////////////////////////////////////////////////////////
// IMAGES BUILD
gulp.task('img:build', function (cb) {
    gulp.src(path.src.img)
        .pipe(imageop())
        .on('error', printError)
        .pipe(gulp.dest(path.build.img))
        .on('end', cb)
});

/////////////////////////////////////////////////////////////////////////////
// FONTS BUILD
gulp.task('fonts:build', function () {
    return gulp.src(path.src.fonts)
        .pipe(gulp.dest(path.build.fonts))
});

/////////////////////////////////////////////////////////////////////////////
// BUILD ALL
gulp.task('build', [
    'application:build',
    'root:build',
    'fonts:build',
    'img:build',
    'css:build',
    'js:build'
]);

/////////////////////////////////////////////////////////////////////////////
// WATCH ALL
gulp.task('watch', function () {
    watch([path.watch.application], function (event, cb) {
        gulp.start('application:build');
    });
    watch([path.watch.root], function (event, cb) {
        gulp.start('root:build');
    });
    watch([path.watch.img], function (event, cb) {
        gulp.start('img:build');
    });
    watch([path.watch.fonts], function (event, cb) {
        gulp.start('fonts:build');
    });
    watch([path.watch.css], function (event, cb) {
        gulp.start('css:build');
    });
    watch([path.watch.js], function (event, cb) {
        gulp.start('js:build');
    });
});

/////////////////////////////////////////////////////////////////////////////
// CLEAN PRODUCTION
gulp.task('clean', function (cb) {
    rimraf(path.clean, cb);
});

/////////////////////////////////////////////////////////////////////////////
// DEFAULT TASK
gulp.task('default', ['build', 'serve', 'watch']);
gulp.task('develop', ['build', 'serve2', 'watch']);
<|endoftext|>


<commit_before>const gulp = require('gulp');
const browserSync = require('browser-sync').create(),
  browserify = require('browserify'),
  source = require('vinyl-source-stream'),
  run = require('gulp-run');

gulp.task('browser-sync', () => {
  browserSync.init({
    server: {
      baseDir: './',
      port: process.env.PORT || 3000
    }
  });
});

gulp.task('reload', (done) => {
  browserSync.reload();
  done();
});

gulp.task('watch', () => {
  gulp.watch('src/*.js', ['reload']);
  gulp.watch('css/*.css', ['reload']);
  gulp.watch('*.html', ['reload']);
});

gulp.task('browserify', () => browserify('./jasmine/spec/inverted-index-spec.js')
    .bundle()
    .pipe(source('test-spec.js'))
    .pipe(gulp.dest('./jasmine/spec/browser')));

gulp.task('test', ['browserify'], () => {
  run('node_modules/karma/bin/karma start karma.conf.js --single-run').exec();
});
gulp.task('default', ['browser-sync', 'browserify', 'watch']);
<commit_msg>Unnecessary space fix<commit_after>const gulp = require('gulp');
const browserSync = require('browser-sync').create(),
  browserify = require('browserify'),
  source = require('vinyl-source-stream'),
  run = require('gulp-run');

gulp.task('browser-sync', () => {
  browserSync.init({
    server: {
      baseDir: './',
      port: process.env.PORT || 3000
    }
  });
});

gulp.task('reload', (done) => {
  browserSync.reload();
  done();
});

gulp.task('watch', () => {
  gulp.watch('src/*.js', ['reload']);
  gulp.watch('css/*.css', ['reload']);
  gulp.watch('*.html', ['reload']);
});

gulp.task('browserify', () => browserify('./jasmine/spec/inverted-index-spec.js')
    .bundle()
    .pipe(source('test-spec.js'))
    .pipe(gulp.dest('./jasmine/spec/browser')));

gulp.task('test', ['browserify'], () => {
  run('node_modules/karma/bin/karma start karma.conf.js --single-run').exec();
});

gulp.task('default', ['browser-sync', 'browserify', 'watch']);
<|endoftext|>


<commit_before>var gulp   = require('gulp');
var tsc    = require('gulp-tsc');
var shell  = require('gulp-shell');
var runseq = require('run-sequence');
var del  = require('del');

var paths = {
	tscripts : {
		src : ['app/src/**/*.ts'],
		dest : 'app/build'
	},
	tests: {
		src: ['test/**/*.ts'],
		dest: 'app/build/test'
	},
	output: 'output/**/*'
};

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

// ** Running ** //

gulp.task('run', shell.task([
  'node app/build/app.js ../aws-sdk-js/apis'
]));

gulp.task('buildrun', function (cb) {
	runseq('build', 'run', cb);
});

// ** Watching ** //
gulp.task('watch', function () {
	gulp.watch(paths.tscripts.src, ['compile:typescript']);
});

gulp.task('watchrun', function () {
	gulp.watch(paths.tscripts.src, runseq('compile:typescript', 'run'));
});

// ** Compilation ** //
gulp.task('build', function(cb) {
	runseq('clean',	'compile:typescript', cb);
});

gulp.task('compile:typescript', function () {
	return gulp
	.src(paths.tscripts.src)
	.pipe(tsc({
		module: "commonjs",
		emitError: false
	}))
	.pipe(gulp.dest(paths.tscripts.dest));
});

gulp.task('compile:tests', function() {
	return gulp
	.src(paths.tests.src)
	.pipe(tsc({
		module: "commonjs",
		emitError: false
	}))
	.pipe(gulp.dest(paths.tests.dest));
});

// ** Clean ** //

gulp.task('clean', ['clean:generated', 'clean:build']);

gulp.task('clean:generated', function() {
	return del(paths.output);
});

gulp.task('clean:build', function() {
	return del(paths.tscripts.dest);
});<commit_msg>Compile test code on buildrun, watchrun tasks<commit_after>var gulp   = require('gulp');
var tsc    = require('gulp-tsc');
var shell  = require('gulp-shell');
var runseq = require('run-sequence');
var del  = require('del');

var paths = {
	tscripts : {
		src : ['app/src/**/*.ts'],
		dest : 'app/build'
	},
	tests: {
		src: ['test/**/*.ts'],
		dest: 'app/build/test'
	},
	output: 'output/**/*'
};

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

// ** Running ** //

gulp.task('run', shell.task([
  'node app/build/app.js ../aws-sdk-js/apis'
]));

gulp.task('buildrun', function (cb) {
	runseq('build', 'run', 'compile:tests', cb);
});

// ** Watching ** //
gulp.task('watch', function () {
	gulp.watch(paths.tscripts.src, ['build']);
});

gulp.task('watchrun', function () {
	gulp.watch(paths.tscripts.src, runseq('buildrun'));
});

// ** Compilation ** //
gulp.task('build', function(cb) {
	runseq('clean',	'compile:typescript', cb);
});

gulp.task('compile:typescript', function () {
	return gulp
	.src(paths.tscripts.src)
	.pipe(tsc({
		module: "commonjs",
		emitError: false
	}))
	.pipe(gulp.dest(paths.tscripts.dest));
});

gulp.task('compile:tests', function() {
	return gulp
	.src(paths.tests.src)
	.pipe(tsc({
		module: "commonjs",
		emitError: false
	}))
	.pipe(gulp.dest(paths.tests.dest));
});

// ** Clean ** //

gulp.task('clean', ['clean:generated', 'clean:build']);

gulp.task('clean:generated', function() {
	return del(paths.output);
});

gulp.task('clean:build', function() {
	return del(paths.tscripts.dest);
});
<|endoftext|>


<commit_before>/********* Variables *********/
/** Paths **/
var destinationPath = 'testpage';
var assetsPath = '/assets'
var styleRootPath = 'less'
var styleDestPath = destinationPath + assetsPath + '/css';
var scriptRootPath = 'lib'
var scriptDestPath = destinationPath + assetsPath + '/scripts';
var viewPath = destinationPath + '/views'

/** Extensions **/
var styleRootExtension = '/*.less'
var styleDestExtension = '/*.css'
var scriptExtension = '/*.js'

/********* Dependencies *********/
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var less = require('gulp-less');
var path = require('path');

/************* Files *************/
gulp.task('scripts', function() {
    return gulp.src(scriptRootPath + scriptExtension)
        .pipe(concat('look.js'))
        .pipe(gulp.dest(scriptDestPath))
        .pipe(rename('look.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest(scriptDestPath));
});

/************* Others *************/
gulp.task('lint', function() {
    return gulp.src(scriptRootPath + scriptExtension)
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

gulp.task('style', function () {
  gulp.src(styleRootPath + styleRootExtension)
    .pipe(less({
      paths: [ path.join(__dirname, 'less', 'includes') ]
    }))
    .pipe(gulp.dest(styleDestPath));
});

gulp.task('default', ['lint', 'style', 'scripts']);
<commit_msg>minified library<commit_after>/********* Variables *********/
/** Paths **/
var destinationPath = 'testpage';
var assetsPath = '/assets'
var styleRootPath = 'less'
var styleDestPath = destinationPath + assetsPath + '/css';
var scriptRootPath = 'lib'
var scriptDestPath = destinationPath + assetsPath + '/scripts';
var viewPath = destinationPath + '/views'

/** Extensions **/
var styleRootExtension = '/*.less'
var styleDestExtension = '/*.css'
var scriptExtension = '/*.js'

/********* Dependencies *********/
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var less = require('gulp-less');
var path = require('path');

/************* Files *************/
gulp.task('scripts', function() {
    return gulp.src(scriptRootPath + scriptExtension)
        .pipe(concat('look.js'))
        .pipe(gulp.dest(scriptDestPath))
        .pipe(rename('look.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest(scriptDestPath));
});

gulp.task('looklib', function() {
  return gulp.src('lib/Look.js')
        .pipe(uglify())
        .pipe(rename('Look.min.js'))
        .pipe(gulp.dest('lib'));
})

/************* Others *************/
gulp.task('lint', function() {
    return gulp.src(scriptRootPath + scriptExtension)
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

gulp.task('style', function () {
  gulp.src(styleRootPath + styleRootExtension)
    .pipe(less({
      paths: [ path.join(__dirname, 'less', 'includes') ]
    }))
    .pipe(gulp.dest(styleDestPath));
});

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


<commit_before>/// <binding />
"use strict";
var gulp = require("gulp");
var requireDir = require('require-dir');
var path = require('path');

var iusPath = path.join(process.cwd(), 'node_modules/gulp-ius-web');
var ius = requireDir(iusPath);

var appSettingsPath = path.join(process.cwd(), 'node_modules/gulp-appsettings');
var appSettings = requireDir(appSettingsPath);

// Set the global.Filename to override this
var OUTPUT_FILE_NAME = global.FileName || "site";

var BOWER_COMPONENTS = global.BowerComponents || "wwwroot/lib";

gulp.task("build", ['sass', 'typescript', 'concat', 'uglify:js','copyfonts', 'copyimages']);
<commit_msg>updates to build tasks<commit_after>/// <binding />
"use strict";
var gulp = require("gulp");
var requireDir = require('require-dir');
var path = require('path');

var iusPath = path.join(process.cwd(), 'node_modules/gulp-ius-web');
var ius = requireDir(iusPath);

var appSettingsPath = path.join(process.cwd(), 'node_modules/gulp-appsettings');
var appSettings = requireDir(appSettingsPath);

// Set the global.Filename to override this
var OUTPUT_FILE_NAME = global.FileName || "site";

var BOWER_COMPONENTS = global.BowerComponents || "wwwroot/lib";

gulp.task("build", ['clean', 'sass', 'concat', 'minify:css', 'uglify:js','copyfonts', 'copyimages']);
<|endoftext|>


<commit_before>var path = require('path');
var gulp = require('gulp');
var gutil = require('gulp-util');
var eslint = require('gulp-eslint');
var excludeGitignore = require('gulp-exclude-gitignore');
var democase = require('gulp-democase');
var webpack = require('webpack');
var del = require('del');
var http = require('http');
var fs = require('fs');
var os = require('os');
var resolve = require('resolve');
// coveralls
var coveralls = require('gulp-coveralls');
// coveralls-end
var jsdoc = require('gulp-jsdoc3');
var Server = require('karma').Server;

var childProcess = require('child_process');
var spawn = childProcess.spawn;

var specUnit = './spec/unit/$speclist.js';
var unitFilePath = [specUnit];
var unitPreprocessor = {};
unitPreprocessor[specUnit] = ['webpack', 'sourcemap'];

var specIntegrated = './spec/integrated/$speclist.js';
var integratedFilePath = ['./node_modules/babel-polyfill/dist/polyfill.js', specIntegrated];
var integratedPreprocessor = {};
integratedPreprocessor[specIntegrated] = ['webpack', 'sourcemap'];

function webpackBuild(configFilePath) {
  return function (cb) {
    webpack(require(configFilePath), function (err, stats) {
      gutil.log(stats.toString({ colors: true }));
      cb(err || stats.hasErrors() && new Error('webpack compile error'));
    });
  };
}

function getSeleniumFilePath() {
  var SELENIUM_NAME = 'selenium-server-standalone-2.53.0.jar';
  return path.resolve(os.tmpdir(), SELENIUM_NAME);
}

gulp.task('download-selenium', function (cb) {
  var filePath = getSeleniumFilePath();
  fs.stat(filePath, function (err) {
    if (!err) {
      return cb(null);
    }
    var file = fs.createWriteStream(filePath);
    var URL = "http://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.0.jar";
    http.get(URL, function (response) {
      response.pipe(file);
    });
    file.on('error', function (err) {
      fs.unlinkSync(filePath);
      cb(err);
    });
    file.on('finish', cb);
  });
});

function startSeleniumServer() {
  var filePath = getSeleniumFilePath();
  return childProcess.spawn('java', ['-jar', filePath], { stdio: 'inherit' });
}

// coveralls
gulp.task('coveralls', ['test'], function () {
  if (!process.env.CI) {
    return;
  }
  return gulp.src(path.join(__dirname, 'coverage/report-lcov/lcov.info')).pipe(coveralls());
});
// coveralls-end

gulp.task('test:unit', function(done) {
  new Server({
    configFile: path.join(__dirname, './spec/unit/conf/karma.conf.js'),
    files: unitFilePath,
    preprocessors: unitPreprocessor,
    singleRun: true,
  }, done).start();
})

// debug in chrome by default
// Todo: envole yargs to config in cmd
gulp.task('test-debug:unit', function(done) {
  new Server({
    configFile: path.join(__dirname, './spec/unit/conf/karma.debug.conf.js'),
    files: unitFilePath,
    preprocessors: unitPreprocessor,
    singleRun: false,
  }, done).start();
})

gulp.task('test:integrated', function(done) {
  new Server({
    configFile: path.join(__dirname, './spec/integrated/conf/karma.conf.js'),
    files: integratedFilePath,
    preprocessors: integratedPreprocessor,
    singleRun: true,
  }, done).start();
})

// debug in chrome by default
// Todo: envole yargs to config in cmd
gulp.task('test-debug:integrated', function(done) {
  new Server({
    configFile: path.join(__dirname, './spec/integrated/conf/karma.debug.conf.js'),
    files: integratedFilePath,
    preprocessors: integratedPreprocessor,
    singleRun: false,
  }, done).start();
})

gulp.task('static', function () {
  return gulp.src('**/*.js')
    .pipe(excludeGitignore())
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
});

gulp.task('jsdoc', function (cb) {
  gulp.src(['README.md', './js/vnext/**/*.js'], { read: false })
    .pipe(jsdoc(require('./jsdoc.json'), cb));
});

gulp.task('webpack', webpackBuild('./webpack.config'));

gulp.task('demos', function () {
  return gulp.src('./demos').pipe(democase());
});

gulp.task('test:demos', ['download-selenium'], function (done) {
  var pathCli = path.resolve(path.dirname(resolve.sync('webdriverio', {
    basedir: '.',
  })), 'lib/cli');
  var cpSelenium = null;
  var cpWdio = null;

  cpSelenium = startSeleniumServer().on('error', function () {
    if (cpWdio) {
      cpWdio.kill();
    }
    done(new Error('Failed to launch the selenium standalone server. Make sure you have JRE available'));
  });

  cpWdio = childProcess.fork(pathCli, [path.join(__dirname, 'wdio.conf.js')], {
    env: { DEMOCASE_HTTP_PORT: 8081 },
  }).on('close', function (code) {
    cpSelenium.kill();
    if (code) {
      done(new Error('selenium test failue'));
    }
    done();
  });
});

gulp.task('test', ['test:unit', 'test:integrated']);

gulp.task('prepublish', ['webpack']);

gulp.task('clean:test', function () {
  return del([
    './spec/*/test-results',
    './spec/*/coverage',
    'errorShots',
  ]);
});

gulp.task('clean:build', function () {
  return del(['dist']);
});

gulp.task('clean', ['clean:build', 'clean:test']);

gulp.task('default', ['webpack', 'coveralls']);
<commit_msg>coverage config<commit_after>var path = require('path');
var gulp = require('gulp');
var gutil = require('gulp-util');
var eslint = require('gulp-eslint');
var excludeGitignore = require('gulp-exclude-gitignore');
var democase = require('gulp-democase');
var webpack = require('webpack');
var del = require('del');
var http = require('http');
var fs = require('fs');
var os = require('os');
var resolve = require('resolve');
// coveralls
var coveralls = require('gulp-coveralls');
// coveralls-end
var jsdoc = require('gulp-jsdoc3');
var Server = require('karma').Server;

var childProcess = require('child_process');
var spawn = childProcess.spawn;

var specUnit = './spec/unit/$speclist.js';
var unitFilePath = [specUnit];
var unitPreprocessor = {};
unitPreprocessor[specUnit] = ['webpack', 'sourcemap'];

var specIntegrated = './spec/integrated/$speclist.js';
var integratedFilePath = ['./node_modules/babel-polyfill/dist/polyfill.js', specIntegrated];
var integratedPreprocessor = {};
integratedPreprocessor[specIntegrated] = ['webpack', 'sourcemap'];

function webpackBuild(configFilePath) {
  return function (cb) {
    webpack(require(configFilePath), function (err, stats) {
      gutil.log(stats.toString({ colors: true }));
      cb(err || stats.hasErrors() && new Error('webpack compile error'));
    });
  };
}

function getSeleniumFilePath() {
  var SELENIUM_NAME = 'selenium-server-standalone-2.53.0.jar';
  return path.resolve(os.tmpdir(), SELENIUM_NAME);
}

gulp.task('download-selenium', function (cb) {
  var filePath = getSeleniumFilePath();
  fs.stat(filePath, function (err) {
    if (!err) {
      return cb(null);
    }
    var file = fs.createWriteStream(filePath);
    var URL = "http://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.0.jar";
    http.get(URL, function (response) {
      response.pipe(file);
    });
    file.on('error', function (err) {
      fs.unlinkSync(filePath);
      cb(err);
    });
    file.on('finish', cb);
  });
});

function startSeleniumServer() {
  var filePath = getSeleniumFilePath();
  return childProcess.spawn('java', ['-jar', filePath], { stdio: 'inherit' });
}

// coveralls
gulp.task('coveralls', ['test'], function () {
  if (!process.env.CI) {
    return;
  }
  return gulp.src(path.join(__dirname, './spec/*/coverage/report-lcov/lcov.info')).pipe(coveralls());
});
// coveralls-end

gulp.task('test:unit', function(done) {
  new Server({
    configFile: path.join(__dirname, './spec/unit/conf/karma.conf.js'),
    files: unitFilePath,
    preprocessors: unitPreprocessor,
    singleRun: true,
  }, done).start();
})

// debug in chrome by default
// Todo: envole yargs to config in cmd
gulp.task('test-debug:unit', function(done) {
  new Server({
    configFile: path.join(__dirname, './spec/unit/conf/karma.debug.conf.js'),
    files: unitFilePath,
    preprocessors: unitPreprocessor,
    singleRun: false,
  }, done).start();
})

gulp.task('test:integrated', function(done) {
  new Server({
    configFile: path.join(__dirname, './spec/integrated/conf/karma.conf.js'),
    files: integratedFilePath,
    preprocessors: integratedPreprocessor,
    singleRun: true,
  }, done).start();
})

// debug in chrome by default
// Todo: envole yargs to config in cmd
gulp.task('test-debug:integrated', function(done) {
  new Server({
    configFile: path.join(__dirname, './spec/integrated/conf/karma.debug.conf.js'),
    files: integratedFilePath,
    preprocessors: integratedPreprocessor,
    singleRun: false,
  }, done).start();
})

gulp.task('static', function () {
  return gulp.src('**/*.js')
    .pipe(excludeGitignore())
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
});

gulp.task('jsdoc', function (cb) {
  gulp.src(['README.md', './js/vnext/**/*.js'], { read: false })
    .pipe(jsdoc(require('./jsdoc.json'), cb));
});

gulp.task('webpack', webpackBuild('./webpack.config'));

gulp.task('demos', function () {
  return gulp.src('./demos').pipe(democase());
});

gulp.task('test:demos', ['download-selenium'], function (done) {
  var pathCli = path.resolve(path.dirname(resolve.sync('webdriverio', {
    basedir: '.',
  })), 'lib/cli');
  var cpSelenium = null;
  var cpWdio = null;

  cpSelenium = startSeleniumServer().on('error', function () {
    if (cpWdio) {
      cpWdio.kill();
    }
    done(new Error('Failed to launch the selenium standalone server. Make sure you have JRE available'));
  });

  cpWdio = childProcess.fork(pathCli, [path.join(__dirname, 'wdio.conf.js')], {
    env: { DEMOCASE_HTTP_PORT: 8081 },
  }).on('close', function (code) {
    cpSelenium.kill();
    if (code) {
      done(new Error('selenium test failue'));
    }
    done();
  });
});

gulp.task('test', ['test:unit', 'test:integrated']);

gulp.task('prepublish', ['webpack']);

gulp.task('clean:test', function () {
  return del([
    './spec/*/test-results',
    './spec/*/coverage',
    'errorShots',
  ]);
});

gulp.task('clean:build', function () {
  return del(['dist']);
});

gulp.task('clean', ['clean:build', 'clean:test']);

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


<commit_before>/**

@property maria.ElementView

@parameter model {Object} Optional

@parameter controller {Object} Optional

@parameter document {Document} Optional

@description

A constructor function to create new element view objects.

    var elementView = new maria.ElementView();

This constructor function takes three optional arguments.

    var model = new maria.Model();
    var controller = new maria.Controller();
    var myFrameDoc = window.frames['myFrame'].document;
    var elementView =
        new maria.ElementView(model, controller, myFrameDoc);

The null or undefined value can be passed for any of these three
parameters to skip setting it.

The purpose of the third document parameter is to allow the creation
of element views in one window that will be shown in another window.
At least some older browsers do not allow a DOM element created with
one document object to be appended to another document object.

An element view is a view (inheriting from maria.View) and so has
a model and controller. See maria.View for more documentation about
setting and getting the model and controller objects.

What makes maria.ElementView different from the more abstract
maria.View is that an element view has the concept of a "root element"
which is the main DOM element that acts as a container for all the
other DOM elements that are part of the element view.

The DOM is built using the getTemplate method which should return a
fragment of HTML for a single DOM element and its children. By default
the template is just an empty div element. You can redefine or override
this to suit your needs.

    maria.ElementView.prototype.getTemplate = function() {
        return '
' +
                   'hello, ' +
                   'world' +
               '
';
    };

When an element view is created and its HTML template is rendered as
a DOM element, the view will automatically start listening to the DOM
element or its children for the events specified in the map returned
by the getUIActions method. This map is empty by default but you can
redefine or override as necessary and supply the necessary handler
functions which usually delegate to the controller.

    maria.ElementView.prototype.getUIActions = function() {
        return {
            'mouseover .greeting': 'onMouseoverGreeting',
            'click .name'        : 'onClickName'
        };
    };

    maria.ElementView.prototype.onMouseoverGreeting = function(evt) {
        this.getController().onMouseoverGreeting(evt);
    };

    maria.ElementView.prototype.onClickName = function(evt) {
        this.getController().onClickName(evt);
    };

Only a few simple CSS selectors are allowed in the keys of the UI
action map. An id can be used like "#alpha" but this is not
recommended. A class name like ".greeting", a tag name like "div", or
a combination of tag name and class name like "div.greeting" are
acceptable. In almost all cases, a single class name is sufficient and
recommended as the best practice. (If you need more complex selectors
you can use a different query library to replace the Grail library
used by default in Maria.)

You can find an element or multiple elements in a view using the
element view's find and findAll methods.

    elementView.find('.name');   // returns a DOM element
    elementView.findAll('span'); // returns an array

Because maria.View objects are composite views, so are
maria.ElementView objects. This means that sub-element-view objects can
be added to an element view. By default the sub-element-view object's
root DOM element will be added to the parent element view's root
DOM element. You can change the element to which they are added by
redefining or overridding the getContainerEl function.

    maria.ElementView.prototype.getContainerEl = function() {
        return this.find('.name');
    };

A particularly useful pattern is using maria.ElementView as the
"superclass" of your application's element views. The following example
shows how this can be done at a low level for a to-do application. See
maria.ElementView.subclass for a much more compact way to accomplish
the same.

    checkit.TodoView = function() {
        maria.ElementView.apply(this, arguments);
    };
    checkit.TodoView.prototype = new maria.ElementView();
    checkit.TodoView.prototype.constructor = checkit.TodoView;
    checkit.TodoView.prototype.initialize = function() {
        if (!this.getModel()) {
            this.setModel(new checkit.TodoModel());
        }
    };
    checkit.TodoView.prototype.getDefaultControllerConstructor = function() {
        return checkit.TodoController;
    };
    checkit.TodoView.prototype.getTemplate = function() {
        return checkit.TodoTemplate;
    };
    checkit.TodoView.prototype.getUIActions = function() {
        return {
            'click     .check'       : 'onClickCheck'     ,
            'dblclick  .todo-content': 'onDblclickDisplay',
            'keyup     .todo-input'  : 'onKeyupInput'     ,
            'keypress  .todo-input'  : 'onKeypressInput'  ,
            'blur      .todo-input'  : 'onBlurInput'
        };
    };
    checkit.TodoView.prototype.onClickCheck = function(evt) {
        this.getController().onClickCheck(evt);
    };
    checkit.TodoView.prototype.onDblclickDisplay = function(evt) {
        this.getController().onDblclickDisplay(evt);
    };
    checkit.TodoView.prototype.onKeyupInput = function(evt) {
        this.getController().onKeyupInput(evt);
    };
    checkit.TodoView.prototype.onKeypressInput = function(evt) {
        this.getController().onKeypressInput(evt);
    };
    checkit.TodoView.prototype.onBlurInput = function(evt) {
        this.getController().onBlurInput(evt);
    };
    checkit.TodoView.prototype.update = function() {
        var model = this.getModel();
        var content = model.getContent();
        this.find('.todo-content').innerHTML =
            content.replace('&', '&').replace('<', '<');
        this.find('.check').checked = model.isDone();
        aristocrat[model.isDone() ? 'addClass' : 'removeClass'](this.getRootEl(), 'done');
    };
    checkit.TodoView.prototype.showEdit = function() {
        var input = this.find('.todo-input');
        input.value = this.getModel().getContent();
        aristocrat.addClass(this.getRootEl(), 'editing');
        input.select();
    };
    checkit.TodoView.prototype.showDisplay = function() {
        aristocrat.removeClass(this.getRootEl(), 'editing');
    };
    checkit.TodoView.prototype.getInputValue = function() {
        return this.find('.todo-input').value;
    };
    checkit.TodoView.prototype.showToolTip = function() {
        this.find('.ui-tooltip-top').style.display = 'block';
    };
    checkit.TodoView.prototype.hideToolTip = function() {
        this.find('.ui-tooltip-top').style.display = 'none';
    };

*/
maria.ElementView = function(model, controller, doc) {
    this._doc = doc || document;
    maria.View.call(this, model, controller);
};

maria.ElementView.prototype = new maria.View();
maria.ElementView.prototype.constructor = maria.ElementView;

maria.ElementView.prototype.getDocument = function() {
    return this._doc;
};

maria.ElementView.prototype.getTemplate = function() {
    return '

';
};

maria.ElementView.prototype.getUIActions = function() {
    return {};
};

(function() {
    var actionRegExp = /^(\S+)\s*(.*)$/;

    maria.ElementView.prototype.getRootEl = function() {
        if (!this._rootEl) {
            // parseHTML returns a DocumentFragment so take firstChild as the rootEl
            var rootEl = this._rootEl = maria.parseHTML(this.getTemplate(), this._doc).firstChild;

            var uiActions = this.getUIActions();
            for (var key in uiActions) {
                if (Object.prototype.hasOwnProperty.call(uiActions, key)) {
                    var matches = key.match(actionRegExp),
                        eventType = matches[1],
                        selector = matches[2],
                        methodName = uiActions[key],
                        elements = maria.findAll(selector, this._rootEl);
                    for (var i = 0, ilen = elements.length; i < ilen; i++) {
                        maria.addEventListener(elements[i], eventType, this, methodName);
                    }
                }
            }

            var childViews = this.childNodes;
            for (var i = 0, ilen = childViews.length; i < ilen; i++) {
                this.getContainerEl().appendChild(childViews[i].getRootEl());
            }

            this.update();
        }
        return this._rootEl;
    };

}());

maria.ElementView.prototype.getContainerEl = function() {
    return this.getRootEl();
};

maria.ElementView.prototype.insertBefore = function(newChild, oldChild) {
    maria.View.prototype.insertBefore.call(this, newChild, oldChild);
    if (this._rootEl) {
        this.getContainerEl().insertBefore(newChild.getRootEl(), oldChild ? oldChild.getRootEl() : null);
    }
};

maria.ElementView.prototype.removeChild = function(oldChild) {
    maria.View.prototype.removeChild.call(this, oldChild);
    if (this._rootEl) {
        this.getContainerEl().removeChild(oldChild.getRootEl());
    }
};

maria.ElementView.prototype.find = function(selector) {
    return maria.find(selector, this.getRootEl());
};

maria.ElementView.prototype.findAll = function(selector) {
    return maria.findAll(selector, this.getRootEl());
};
<commit_msg>update docs. Views don't create models on initialization anymore.<commit_after>/**

@property maria.ElementView

@parameter model {Object} Optional

@parameter controller {Object} Optional

@parameter document {Document} Optional

@description

A constructor function to create new element view objects.

    var elementView = new maria.ElementView();

This constructor function takes three optional arguments.

    var model = new maria.Model();
    var controller = new maria.Controller();
    var myFrameDoc = window.frames['myFrame'].document;
    var elementView =
        new maria.ElementView(model, controller, myFrameDoc);

The null or undefined value can be passed for any of these three
parameters to skip setting it.

The purpose of the third document parameter is to allow the creation
of element views in one window that will be shown in another window.
At least some older browsers do not allow a DOM element created with
one document object to be appended to another document object.

An element view is a view (inheriting from maria.View) and so has
a model and controller. See maria.View for more documentation about
setting and getting the model and controller objects.

What makes maria.ElementView different from the more abstract
maria.View is that an element view has the concept of a "root element"
which is the main DOM element that acts as a container for all the
other DOM elements that are part of the element view.

The DOM is built using the getTemplate method which should return a
fragment of HTML for a single DOM element and its children. By default
the template is just an empty div element. You can redefine or override
this to suit your needs.

    maria.ElementView.prototype.getTemplate = function() {
        return '
' +
                   'hello, ' +
                   'world' +
               '
';
    };

When an element view is created and its HTML template is rendered as
a DOM element, the view will automatically start listening to the DOM
element or its children for the events specified in the map returned
by the getUIActions method. This map is empty by default but you can
redefine or override as necessary and supply the necessary handler
functions which usually delegate to the controller.

    maria.ElementView.prototype.getUIActions = function() {
        return {
            'mouseover .greeting': 'onMouseoverGreeting',
            'click .name'        : 'onClickName'
        };
    };

    maria.ElementView.prototype.onMouseoverGreeting = function(evt) {
        this.getController().onMouseoverGreeting(evt);
    };

    maria.ElementView.prototype.onClickName = function(evt) {
        this.getController().onClickName(evt);
    };

Only a few simple CSS selectors are allowed in the keys of the UI
action map. An id can be used like "#alpha" but this is not
recommended. A class name like ".greeting", a tag name like "div", or
a combination of tag name and class name like "div.greeting" are
acceptable. In almost all cases, a single class name is sufficient and
recommended as the best practice. (If you need more complex selectors
you can use a different query library to replace the Grail library
used by default in Maria.)

You can find an element or multiple elements in a view using the
element view's find and findAll methods.

    elementView.find('.name');   // returns a DOM element
    elementView.findAll('span'); // returns an array

Because maria.View objects are composite views, so are
maria.ElementView objects. This means that sub-element-view objects can
be added to an element view. By default the sub-element-view object's
root DOM element will be added to the parent element view's root
DOM element. You can change the element to which they are added by
redefining or overridding the getContainerEl function.

    maria.ElementView.prototype.getContainerEl = function() {
        return this.find('.name');
    };

A particularly useful pattern is using maria.ElementView as the
"superclass" of your application's element views. The following example
shows how this can be done at a low level for a to-do application. See
maria.ElementView.subclass for a much more compact way to accomplish
the same.

    checkit.TodoView = function() {
        maria.ElementView.apply(this, arguments);
    };
    checkit.TodoView.prototype = new maria.ElementView();
    checkit.TodoView.prototype.constructor = checkit.TodoView;
    checkit.TodoView.prototype.getDefaultControllerConstructor = function() {
        return checkit.TodoController;
    };
    checkit.TodoView.prototype.getTemplate = function() {
        return checkit.TodoTemplate;
    };
    checkit.TodoView.prototype.getUIActions = function() {
        return {
            'click     .check'       : 'onClickCheck'     ,
            'dblclick  .todo-content': 'onDblclickDisplay',
            'keyup     .todo-input'  : 'onKeyupInput'     ,
            'keypress  .todo-input'  : 'onKeypressInput'  ,
            'blur      .todo-input'  : 'onBlurInput'
        };
    };
    checkit.TodoView.prototype.onClickCheck = function(evt) {
        this.getController().onClickCheck(evt);
    };
    checkit.TodoView.prototype.onDblclickDisplay = function(evt) {
        this.getController().onDblclickDisplay(evt);
    };
    checkit.TodoView.prototype.onKeyupInput = function(evt) {
        this.getController().onKeyupInput(evt);
    };
    checkit.TodoView.prototype.onKeypressInput = function(evt) {
        this.getController().onKeypressInput(evt);
    };
    checkit.TodoView.prototype.onBlurInput = function(evt) {
        this.getController().onBlurInput(evt);
    };
    checkit.TodoView.prototype.update = function() {
        var model = this.getModel();
        var content = model.getContent();
        this.find('.todo-content').innerHTML =
            content.replace('&', '&').replace('<', '<');
        this.find('.check').checked = model.isDone();
        aristocrat[model.isDone() ? 'addClass' : 'removeClass'](this.getRootEl(), 'done');
    };
    checkit.TodoView.prototype.showEdit = function() {
        var input = this.find('.todo-input');
        input.value = this.getModel().getContent();
        aristocrat.addClass(this.getRootEl(), 'editing');
        input.select();
    };
    checkit.TodoView.prototype.showDisplay = function() {
        aristocrat.removeClass(this.getRootEl(), 'editing');
    };
    checkit.TodoView.prototype.getInputValue = function() {
        return this.find('.todo-input').value;
    };
    checkit.TodoView.prototype.showToolTip = function() {
        this.find('.ui-tooltip-top').style.display = 'block';
    };
    checkit.TodoView.prototype.hideToolTip = function() {
        this.find('.ui-tooltip-top').style.display = 'none';
    };

*/
maria.ElementView = function(model, controller, doc) {
    this._doc = doc || document;
    maria.View.call(this, model, controller);
};

maria.ElementView.prototype = new maria.View();
maria.ElementView.prototype.constructor = maria.ElementView;

maria.ElementView.prototype.getDocument = function() {
    return this._doc;
};

maria.ElementView.prototype.getTemplate = function() {
    return '

';
};

maria.ElementView.prototype.getUIActions = function() {
    return {};
};

(function() {
    var actionRegExp = /^(\S+)\s*(.*)$/;

    maria.ElementView.prototype.getRootEl = function() {
        if (!this._rootEl) {
            // parseHTML returns a DocumentFragment so take firstChild as the rootEl
            var rootEl = this._rootEl = maria.parseHTML(this.getTemplate(), this._doc).firstChild;

            var uiActions = this.getUIActions();
            for (var key in uiActions) {
                if (Object.prototype.hasOwnProperty.call(uiActions, key)) {
                    var matches = key.match(actionRegExp),
                        eventType = matches[1],
                        selector = matches[2],
                        methodName = uiActions[key],
                        elements = maria.findAll(selector, this._rootEl);
                    for (var i = 0, ilen = elements.length; i < ilen; i++) {
                        maria.addEventListener(elements[i], eventType, this, methodName);
                    }
                }
            }

            var childViews = this.childNodes;
            for (var i = 0, ilen = childViews.length; i < ilen; i++) {
                this.getContainerEl().appendChild(childViews[i].getRootEl());
            }

            this.update();
        }
        return this._rootEl;
    };

}());

maria.ElementView.prototype.getContainerEl = function() {
    return this.getRootEl();
};

maria.ElementView.prototype.insertBefore = function(newChild, oldChild) {
    maria.View.prototype.insertBefore.call(this, newChild, oldChild);
    if (this._rootEl) {
        this.getContainerEl().insertBefore(newChild.getRootEl(), oldChild ? oldChild.getRootEl() : null);
    }
};

maria.ElementView.prototype.removeChild = function(oldChild) {
    maria.View.prototype.removeChild.call(this, oldChild);
    if (this._rootEl) {
        this.getContainerEl().removeChild(oldChild.getRootEl());
    }
};

maria.ElementView.prototype.find = function(selector) {
    return maria.find(selector, this.getRootEl());
};

maria.ElementView.prototype.findAll = function(selector) {
    return maria.findAll(selector, this.getRootEl());
};
<|endoftext|>


<commit_before>'use strict';
require('dotenv').config({path: './config.env'})

var gulp = require('gulp');

var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var pump = require('pump');
var sourcemaps = require('gulp-sourcemaps');
var exec = require('child_process').exec;
var child = require('child_process');
var log = require('fancy-log');
const browserSync = require('browser-sync').create();
var awspublish = require('gulp-awspublish');

const siteRoot = 'public';

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

// Copy Javascript files from node_modules
gulp.task('vendor-scripts', function(done) {
  return gulp.src(['./node_modules/bootstrap/dist/js/bootstrap.min.js',
                  './node_modules/jquery/dist/jquery.min.js',
                  './node_modules/popper.js/dist/umd/popper.min.js',
                  './node_modules/bootstrap/dist/js/bootstrap.min.js.map',
                  './node_modules/jquery/dist/jquery.min.map',
                  './node_modules/popper.js/dist/umd/popper.min.js.map'])
    .pipe(gulp.dest('./public/js/vendor'), done);
});

gulp.task('app-scripts', function (done) {
  pump([
        gulp.src('src/js/*.js'),
        // sourcemaps.init(),
        uglify(),
        // sourcemaps.write('./'),
        gulp.dest('public/js')
    ],
    done
  );
});

// Jekyll builds the site after watching files
gulp.task('jekyll-build-and-watch', function() {
  const jekyll = child.spawn('jekyll', ['build',
    '--watch',
    '--incremental',
    '--drafts'
  ]);

  const jekyllLogger = (buffer) => {
    buffer.toString()
      .split(/\n/)
      .forEach((message) => log(message));
  };

  jekyll.stdout.on('data', jekyllLogger);
  jekyll.stderr.on('data', jekyllLogger);
});

gulp.task('jekyll-build', function(done) {
  exec('jekyll build', function (err, stdout, stderr) {
    console.log(stdout);
    console.log(stderr);
    done(err);
  });
});

gulp.task('test', function(done) {
  exec('htmlproofer --assume-extension ./public', function (err, stdout, stderr) {
    console.log(stdout);
    // console.log(stderr);
    done(err);
  });
});

// BroswerSync serves the site and handles reloads
gulp.task('serve', function() {
  browserSync.init({
    files: [siteRoot + '/**'],
    port: 4000,
    server: {
      baseDir: siteRoot
    }
  });
});

gulp.task('staging', function(done) {
  // create a new publisher using S3 options
  // http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property
  var publisher = awspublish.create({
    region: process.env.AWS_REGION,
    params: {
      Bucket: process.env.STAGING_BUCKET
    },
    accessKeyId: process.env.STAGING_ACCESS_KEY,
    secretAccessKey: process.env.STAGING_SECRET_ACCESS_KEY
  }, {
    cacheFileName: 'aws-caches/.aws-staging-cache'
  });

  // define custom headers
  var headers = {
    'Cache-Control': 'max-age=0, no-transform, public'
    // ...
  };

  return gulp.src('./public/**/*.*')
     // gzip, Set Content-Encoding headers and add .gz extension
    .pipe(awspublish.gzip())

    // publisher will add Content-Length, Content-Type and headers specified above
    // If not specified it will set x-amz-acl to public-read by default
    .pipe(publisher.publish(headers))

    // delete files that are not in the local directory
    .pipe(publisher.sync())

    // create a cache file to speed up consecutive uploads
    .pipe(publisher.cache())

     // print upload updates to console
    .pipe(awspublish.reporter(), done);
});

gulp.task('production', function(done) {
  // create a new publisher using S3 options
  // http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property
  var publisher = awspublish.create({
    region: process.env.AWS_REGION,
    params: {
      Bucket: process.env.PRODUCTION_BUCKET
    },
    accessKeyId: process.env.PRODUCTION_ACCESS_KEY,
    secretAccessKey: process.env.PRODUCTION_SECRET_ACCESS_KEY
  }, {
    cacheFileName: 'aws-caches/.aws-production-cache'
  });

  // define custom headers
  var headers = {
    'Cache-Control': 'max-age=0, no-transform, public'
    // ...
  };

  return gulp.src('./public/**/*.*')
     // gzip, Set Content-Encoding headers and add .gz extension
    .pipe(awspublish.gzip())

    // publisher will add Content-Length, Content-Type and headers specified above
    // If not specified it will set x-amz-acl to public-read by default
    .pipe(publisher.publish(headers))

    // delete files that are not in the local directory
    .pipe(publisher.sync())

    // create a cache file to speed up consecutive uploads
    .pipe(publisher.cache())

     // print upload updates to console
    .pipe(awspublish.reporter(), done);
});

gulp.task('js', gulp.series('lint', 'vendor-scripts', 'app-scripts'));
gulp.task('build', gulp.series('jekyll-build', 'js'));
gulp.task('serve', gulp.parallel('jekyll-build-and-watch', 'js', 'serve'));
gulp.task('staging', gulp.series('build', 'staging'));
gulp.task('publish', gulp.series('build', 'production'));
gulp.task('default', gulp.series('build'));
<commit_msg>updated to disable gzip<commit_after>'use strict';
require('dotenv').config({path: './config.env'})

var gulp = require('gulp');

var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var pump = require('pump');
var sourcemaps = require('gulp-sourcemaps');
var exec = require('child_process').exec;
var child = require('child_process');
var log = require('fancy-log');
const browserSync = require('browser-sync').create();
var awspublish = require('gulp-awspublish');

const siteRoot = 'public';

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

// Copy Javascript files from node_modules
gulp.task('vendor-scripts', function(done) {
  return gulp.src(['./node_modules/bootstrap/dist/js/bootstrap.min.js',
                  './node_modules/jquery/dist/jquery.min.js',
                  './node_modules/popper.js/dist/umd/popper.min.js',
                  './node_modules/bootstrap/dist/js/bootstrap.min.js.map',
                  './node_modules/jquery/dist/jquery.min.map',
                  './node_modules/popper.js/dist/umd/popper.min.js.map'])
    .pipe(gulp.dest('./public/js/vendor'), done);
});

gulp.task('app-scripts', function (done) {
  pump([
        gulp.src('src/js/*.js'),
        // sourcemaps.init(),
        uglify(),
        // sourcemaps.write('./'),
        gulp.dest('public/js')
    ],
    done
  );
});

// Jekyll builds the site after watching files
gulp.task('jekyll-build-and-watch', function() {
  const jekyll = child.spawn('jekyll', ['build',
    '--watch',
    '--incremental',
    '--drafts'
  ]);

  const jekyllLogger = (buffer) => {
    buffer.toString()
      .split(/\n/)
      .forEach((message) => log(message));
  };

  jekyll.stdout.on('data', jekyllLogger);
  jekyll.stderr.on('data', jekyllLogger);
});

gulp.task('jekyll-build', function(done) {
  exec('jekyll build', function (err, stdout, stderr) {
    console.log(stdout);
    console.log(stderr);
    done(err);
  });
});

gulp.task('test', function(done) {
  exec('htmlproofer --assume-extension ./public', function (err, stdout, stderr) {
    console.log(stdout);
    // console.log(stderr);
    done(err);
  });
});

// BroswerSync serves the site and handles reloads
gulp.task('serve', function() {
  browserSync.init({
    files: [siteRoot + '/**'],
    port: 4000,
    server: {
      baseDir: siteRoot
    }
  });
});

gulp.task('staging', function(done) {
  // create a new publisher using S3 options
  // http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property
  var publisher = awspublish.create({
    region: process.env.AWS_REGION,
    params: {
      Bucket: process.env.STAGING_BUCKET
    },
    accessKeyId: process.env.STAGING_ACCESS_KEY,
    secretAccessKey: process.env.STAGING_SECRET_ACCESS_KEY
  }, {
    cacheFileName: 'aws-caches/.aws-staging-cache'
  });

  // define custom headers
  var headers = {
    'Cache-Control': 'max-age=0, no-transform, public'
    // ...
  };

  return gulp.src('./public/**/*.*')
     // gzip, Set Content-Encoding headers and add .gz extension
    //.pipe(awspublish.gzip())

    // publisher will add Content-Length, Content-Type and headers specified above
    // If not specified it will set x-amz-acl to public-read by default
    .pipe(publisher.publish(headers))

    // delete files that are not in the local directory
    .pipe(publisher.sync())

    // create a cache file to speed up consecutive uploads
    .pipe(publisher.cache())

     // print upload updates to console
    .pipe(awspublish.reporter(), done);
});

gulp.task('production', function(done) {
  // create a new publisher using S3 options
  // http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property
  var publisher = awspublish.create({
    region: process.env.AWS_REGION,
    params: {
      Bucket: process.env.PRODUCTION_BUCKET
    },
    accessKeyId: process.env.PRODUCTION_ACCESS_KEY,
    secretAccessKey: process.env.PRODUCTION_SECRET_ACCESS_KEY
  }, {
    cacheFileName: 'aws-caches/.aws-production-cache'
  });

  // define custom headers
  var headers = {
    'Cache-Control': 'max-age=0, no-transform, public'
    // ...
  };

  return gulp.src('./public/**/*.*')
     // gzip, Set Content-Encoding headers and add .gz extension
    //.pipe(awspublish.gzip())

    // publisher will add Content-Length, Content-Type and headers specified above
    // If not specified it will set x-amz-acl to public-read by default
    .pipe(publisher.publish(headers))

    // delete files that are not in the local directory
    .pipe(publisher.sync())

    // create a cache file to speed up consecutive uploads
    .pipe(publisher.cache())

     // print upload updates to console
    .pipe(awspublish.reporter(), done);
});

gulp.task('js', gulp.series('lint', 'vendor-scripts', 'app-scripts'));
gulp.task('build', gulp.series('jekyll-build', 'js'));
gulp.task('serve', gulp.parallel('jekyll-build-and-watch', 'js', 'serve'));
gulp.task('staging', gulp.series('build', 'staging'));
gulp.task('publish', gulp.series('build', 'production'));
gulp.task('default', gulp.series('build'));
<|endoftext|>


<commit_before>// Basic stuff we need
var exec   = require('child_process').exec,
    config = require('./barebones.json'),
    gulp   = require('gulp');

// Gulp plugins
var compass = require('gulp-compass'),
    uglify  = require('gulp-uglify'),
    rename  = require("gulp-rename");

// Gulp tasks

/* Default task
 *
 * Compiles dev version (uncompressed css and js)
 */
gulp.task('default', function() {
    gulp.start('bower', 'compass', 'vendor');
});

/* Bower task
 *
 * Installs all bower dependencies
 */
gulp.task('bower', function (cb) {
    // Install bower dependencies
    exec('bower install', function (err, stdout, stderr) {
        if (stdout) console.log(stdout);
        if (stderr) console.log(stderr);
        cb(err);
    });
});

/* Vendor task
 *
 * Copies all vendor dependencies into their respective locations
 */
gulp.task('vendor', function () {
    gulp.start('vendor:normalize', 'vendor:jquery', 'vendor:modernizr');
});

/* Vendor:normalize subtask
 *
 * Copies normalize.scss to style source dir
 */
gulp.task('vendor:normalize', ['bower'], function () {
    gulp.src(config.path.vendor.src + '/normalize-scss/_normalize.scss')
        .pipe(gulp.dest(config.path.style.src + '/base'));
});

/* Vendor:jquery subtask
 *
 * Copies jquery to vendor dest dir
 */
gulp.task('vendor:jquery', ['bower'], function () {
    gulp.src(config.path.vendor.src + '/jquery/dist/jquery.min.js')
        .pipe(rename('jquery-2.1.1.min.js'))
        .pipe(gulp.dest(config.path.vendor.dest));
});

/* Vendor:modernizr subtask
 *
 * Copies modernizr to vendor dest dir
 */
gulp.task('vendor:modernizr', ['bower'], function () {
    gulp.src(config.path.vendor.src + '/modernizr/modernizr.js')
        .pipe(uglify())
        .pipe(rename('modernizr-2.8.2.min.js'))
        .pipe(gulp.dest(config.path.vendor.dest));
});

/* Compass task
 *
 * Compiles main.scss to main.css
 *
 * Does not compress the resulting css
 */
gulp.task('compass', ['vendor:normalize'], function () {
    gulp.src(config.path.style.src + '/main.scss')
        .pipe(compass({
            config_file: 'config.rb',
            css: config.path.style.dest,
            sass: config.path.style.src,
            style: 'expanded'
        }))
        .pipe(gulp.dest(config.path.style.dest));
});

/* Compass:dist subtask
 *
 * Compiles main.scss to main.css
 *
 * Compresses the resulting css
 */
gulp.task('compass-dist', ['vendor:normalize'], function () {
    gulp.src('./' + config.path.style.src + '/main.scss')
        .pipe(compass({
            config_file: './config.rb',
            css: config.path.style.dest,
            sass: config.path.style.src,
            style: 'compressed'
        }))
        .pipe(gulp.dest(config.path.style.dest));
});

/* Watch task
 *
 * Enters watch mode, automatically recompiling assets on source changes
 */
gulp.task('watch', function () {
    gulp.watch([config.path.style.src + '/**/*.scss', '!' + config.path.style.src + '/base/_normalize.scss'], ['compass']);
});

/* Dev task
 *
 * Enters dev mode: compiles all resources and starts watching for changes
 */
gulp.task('dev', function () {
    gulp.start('bower', 'compass', 'vendor', 'watch');
});

/* Dist task
 *
 * Compiles all resources for production
 */
gulp.task('dist', function () {
    gulp.start('bower', 'compass-dist', 'vendor');
});

// validation
<commit_msg>Cleaned up gulpfile a little<commit_after>// Basic stuff we need
var exec   = require('child_process').exec,
    config = require('./barebones.json'),
    gulp   = require('gulp');

// Gulp plugins
var compass = require('gulp-compass'),
    uglify  = require('gulp-uglify'),
    rename  = require("gulp-rename");

// Gulp tasks

/* Bower task
 *
 * Installs all bower dependencies
 */
gulp.task('bower', function (cb) {
    // Install bower dependencies
    exec('bower install', function (err, stdout, stderr) {
        if (stdout) console.log(stdout);
        if (stderr) console.log(stderr);
        cb(err);
    });
});

/* Vendor task
 *
 * Copies all vendor dependencies into their respective locations
 */
gulp.task('vendor', ['vendor:normalize', 'vendor:jquery', 'vendor:modernizr']);

/* Vendor:normalize subtask
 *
 * Copies normalize.scss to style source dir
 */
gulp.task('vendor:normalize', ['bower'], function () {
    gulp.src(config.path.vendor.src + '/normalize-scss/_normalize.scss')
        .pipe(gulp.dest(config.path.style.src + '/base'));
});

/* Vendor:jquery subtask
 *
 * Copies jquery to vendor dest dir
 */
gulp.task('vendor:jquery', ['bower'], function () {
    gulp.src(config.path.vendor.src + '/jquery/dist/jquery.min.js')
        .pipe(rename('jquery-2.1.1.min.js'))
        .pipe(gulp.dest(config.path.vendor.dest));
});

/* Vendor:modernizr subtask
 *
 * Copies modernizr to vendor dest dir
 */
gulp.task('vendor:modernizr', ['bower'], function () {
    gulp.src(config.path.vendor.src + '/modernizr/modernizr.js')
        .pipe(uglify())
        .pipe(rename('modernizr-2.8.2.min.js'))
        .pipe(gulp.dest(config.path.vendor.dest));
});

/* Compass task
 *
 * Compiles main.scss to main.css
 *
 * Does not compress the resulting css
 */
gulp.task('compass', ['vendor:normalize'], function () {
    gulp.src(config.path.style.src + '/main.scss')
        .pipe(compass({
            config_file: 'config.rb',
            css: config.path.style.dest,
            sass: config.path.style.src,
            style: 'expanded'
        }))
        .on('error', function (err) {}) // Error message is output by the plugin
        .pipe(gulp.dest(config.path.style.dest));
});

/* Compass:dist subtask
 *
 * Compiles main.scss to main.css
 *
 * Compresses the resulting css
 */
gulp.task('compass-dist', ['vendor:normalize'], function () {
    gulp.src('./' + config.path.style.src + '/main.scss')
        .pipe(compass({
            config_file: './config.rb',
            css: config.path.style.dest,
            sass: config.path.style.src,
            style: 'compressed'
        }))
        .pipe(gulp.dest(config.path.style.dest));
});

/* Watch task
 *
 * Enters watch mode, automatically recompiling assets on source changes
 */
gulp.task('watch', function () {
    gulp.watch([config.path.style.src + '/**/*.scss', '!' + config.path.style.src + '/base/_normalize.scss'], ['compass']);
});

/* Default task
 *
 * Compiles dev version (uncompressed css and js)
 */
gulp.task('default', ['bower', 'compass', 'vendor']);

/* Dev task
 *
 * Enters dev mode: compiles all resources and starts watching for changes
 */
gulp.task('dev', ['bower', 'compass', 'vendor', 'watch']);

/* Dist task
 *
 * Compiles all resources for production
 */
gulp.task('dist', ['bower', 'compass-dist', 'vendor']);

// validation
<|endoftext|>


<commit_before>'use strict';
const gulp = require('gulp');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
const babel = require('gulp-babel');
const filter = require('gulp-filter');
const sass = require('gulp-sass');
const concat = require('gulp-concat');
const replace = require('gulp-replace');
const rename = require('gulp-rename');
const cleanCSS = require('gulp-clean-css');
const eslint = require('gulp-eslint');

// Clean lib folder.
gulp.task('clean', require('del').bind(null, ['dist', 'lib']));

// ESLint
gulp.task('eslint', function eslintTask() {
  return gulp.src(['./src/**/*.js', '!./src/**/*.spec.js'])
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
});

// Run babel on source code.
gulp.task('babel', gulp.series('eslint', function babelTask() {
  return gulp.src(['./src/**/*.js', '!./src/**/*.spec.js'])
    .pipe(babel())
    .pipe(gulp.dest('lib'));
}));

// Move font-awesome fonts into dist folder.
gulp.task('builder-fonts', function builderFonts() {
  return gulp.src('node_modules/font-awesome/fonts/*').pipe(gulp.dest('dist/fonts'));
});

// Generate styles
const compileStyles = (styles, file) => {
  const sassFilter = filter('**/*.scss', { restore: true });
  return gulp.src(styles)
    .pipe(sassFilter)
    .pipe(sass().on('error', sass.logError))
    .pipe(sassFilter.restore)
    .pipe(concat(`${file}.css`))
    .pipe(replace(/\.\.\/\.\.\/icons\/\/?/g, 'icons/'))
    /* eslint-disable quotes */
    .pipe(replace('icons/cross.svg', `'data:image/svg+xml;charset=utf8,%3Csvg width="21" height="21" viewBox="0 0 21 21" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="%23FFF" fill-rule="evenodd"%3E%3Cpath d="M2.592.044l18.364 18.364-2.548 2.548L.044 2.592z"/%3E%3Cpath d="M0 18.364L18.364 0l2.548 2.548L2.548 20.912z"/%3E%3C/g%3E%3C/svg%3E'`))
    .pipe(replace('icons/cross-inverse.svg', `'data:image/svg+xml;charset=utf8,%3Csvg width="21" height="21" viewBox="0 0 21 21" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="%23000" fill-rule="evenodd"%3E%3Cpath d="M2.592.044l18.364 18.364-2.548 2.548L.044 2.592z"/%3E%3Cpath d="M0 18.364L18.364 0l2.548 2.548L2.548 20.912z"/%3E%3C/g%3E%3C/svg%3E'`))
    /* eslint-enable quotes */
    .pipe(replace(/\.\.\/fonts\/\/?/g, 'fonts/'))
    .pipe(gulp.dest('dist'))
    .pipe(rename(`${file}.min.css`))
    .pipe(cleanCSS({ compatibility: 'ie8' }))
    .pipe(gulp.dest('dist'));
};
gulp.task('styles-form', function formStyles() {
  return compileStyles([
    './node_modules/flatpickr/dist/flatpickr.min.css',
    './node_modules/choices.js/public/assets/styles/choices.min.css',
    './node_modules/dialog-polyfill/dialog-polyfill.css',
    './src/sass/formio.form.scss'
  ], 'formio.form');
});
gulp.task('styles-builder', function builderStyles() {
  return compileStyles([
    './node_modules/flatpickr/dist/flatpickr.min.css',
    './node_modules/choices.js/public/assets/styles/choices.min.css',
    './node_modules/dialog-polyfill/dialog-polyfill.css',
    './node_modules/dragula/dist/dragula.css',
    './src/sass/formio.form.scss',
    './src/sass/formio.form.builder.scss'
  ], 'formio.builder');
});
gulp.task('styles-full', gulp.series('builder-fonts', function fullStyles() {
  return compileStyles([
    './node_modules/flatpickr/dist/flatpickr.min.css',
    './node_modules/choices.js/public/assets/styles/choices.min.css',
    './node_modules/dialog-polyfill/dialog-polyfill.css',
    './node_modules/dragula/dist/dragula.css',
    './node_modules/font-awesome/css/font-awesome.css',
    './src/sass/formio.form.scss',
    './src/sass/formio.form.builder.scss'
  ], 'formio.full');
}));

// Script builds.
const webpackDev = require('./config/webpack.dev');
const webpackProd = require('./config/webpack.prod');
const buildDev = (input, output) => webpackStream(webpackDev(input, output), webpack).pipe(gulp.dest('dist'));
const buildProd = (input, output) => webpackStream(webpackProd(input, output), webpack).pipe(gulp.dest('dist'));
const build = (input, output) => {
  const prodFile = output.replace(/\.js$/, '.min.js');
  gulp.task(output, () => buildDev(input, output));
  gulp.task(prodFile, () => buildProd(input, prodFile));
  return gulp.parallel(output, prodFile);
};
gulp.task('scripts-formio', build('Formio.js', 'formio.js'));
gulp.task('scripts-utils', build('utils/utils.js', 'formio.utils.js'));
gulp.task('scripts-full', build('index.js', 'formio.full.js'));
gulp.task('scripts-form', build('formio.form.js', 'formio.form.js'));
gulp.task('formio.embed.min.js', () => buildProd('formio.embed.js', 'formio.embed.min.js'));
gulp.task('formio.embed.js', () =>
  gulp.src('./dist/formio.embed.min.js')
    .pipe(rename('formio.embed.js'))
    .pipe(gulp.dest('dist')));
gulp.task('scripts-embed', gulp.series('formio.embed.min.js', 'formio.embed.js'));
gulp.task('scripts-contrib', build('contrib/index.js', 'formio.contrib.js'));

gulp.task('jquery', () => gulp.src('./node_modules/jquery/dist/**/*.*').pipe(gulp.dest('./app/jquery')));
gulp.task('fontawesome', () => gulp.src('./node_modules/font-awesome/**/*.*').pipe(gulp.dest('./app/fontawesome')));
gulp.task('bootstrap', () => gulp.src('./node_modules/bootstrap/dist/**/*.*').pipe(gulp.dest('./app/bootstrap')));
gulp.task('bootswatch', () => gulp.src('./node_modules/bootswatch/**/*.*').pipe(gulp.dest('./app/bootswatch')));

// Copy the version and dependencies into the distribution package.json file.
gulp.task('package-version', function() {
  const pkg = require('./package.json');
  return gulp.src([
    'src/package.json'
  ])
    .pipe(replace(/"version": ""/, `"version": "${pkg.version}"`))
    .pipe(replace(/"dependencies": {}/, `"dependencies": ${JSON.stringify(pkg.dependencies)}`))
    .pipe(gulp.dest('lib'));
});

// Copy over the dist folder into the lib folder.
gulp.task('dist', () => gulp.src(['dist/**/*.*']).pipe(gulp.dest('lib/dist')));

// Watch for changes.
gulp.task('watch', () => gulp.watch(['./src/**.js', './src/*/**.js'], gulp.series('formio.full.js')));

// Copy over the moment-timezones to the resource folder.
gulp.task('timezones', () => gulp.src('./node_modules/moment-timezone/data/packed/latest.json').pipe(gulp.dest('./resources')));

// Create a new build.
gulp.task('build', gulp.series(
  'clean',
  'babel',
  'package-version',
  gulp.parallel(
    'jquery',
    'timezones',
    'fontawesome',
    'bootstrap',
    'bootswatch'
  ),
  gulp.parallel(
    'styles-form',
    'styles-builder',
    'styles-full',
    'scripts-formio',
    'scripts-utils',
    'scripts-embed',
    'scripts-contrib',
    'scripts-form',
    'scripts-full'
  ),
  'dist'
));

// Default task. Build and watch.
gulp.task('default', gulp.series('babel', 'scripts-full', 'watch'));
<commit_msg>**.js wasn't picking up changes in JS files.<commit_after>'use strict';
const gulp = require('gulp');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
const babel = require('gulp-babel');
const filter = require('gulp-filter');
const sass = require('gulp-sass');
const concat = require('gulp-concat');
const replace = require('gulp-replace');
const rename = require('gulp-rename');
const cleanCSS = require('gulp-clean-css');
const eslint = require('gulp-eslint');

// Clean lib folder.
gulp.task('clean', require('del').bind(null, ['dist', 'lib']));

// ESLint
gulp.task('eslint', function eslintTask() {
  return gulp.src(['./src/**/*.js', '!./src/**/*.spec.js'])
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
});

// Run babel on source code.
gulp.task('babel', gulp.series('eslint', function babelTask() {
  return gulp.src(['./src/**/*.js', '!./src/**/*.spec.js'])
    .pipe(babel())
    .pipe(gulp.dest('lib'));
}));

// Move font-awesome fonts into dist folder.
gulp.task('builder-fonts', function builderFonts() {
  return gulp.src('node_modules/font-awesome/fonts/*').pipe(gulp.dest('dist/fonts'));
});

// Generate styles
const compileStyles = (styles, file) => {
  const sassFilter = filter('**/*.scss', { restore: true });
  return gulp.src(styles)
    .pipe(sassFilter)
    .pipe(sass().on('error', sass.logError))
    .pipe(sassFilter.restore)
    .pipe(concat(`${file}.css`))
    .pipe(replace(/\.\.\/\.\.\/icons\/\/?/g, 'icons/'))
    /* eslint-disable quotes */
    .pipe(replace('icons/cross.svg', `'data:image/svg+xml;charset=utf8,%3Csvg width="21" height="21" viewBox="0 0 21 21" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="%23FFF" fill-rule="evenodd"%3E%3Cpath d="M2.592.044l18.364 18.364-2.548 2.548L.044 2.592z"/%3E%3Cpath d="M0 18.364L18.364 0l2.548 2.548L2.548 20.912z"/%3E%3C/g%3E%3C/svg%3E'`))
    .pipe(replace('icons/cross-inverse.svg', `'data:image/svg+xml;charset=utf8,%3Csvg width="21" height="21" viewBox="0 0 21 21" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="%23000" fill-rule="evenodd"%3E%3Cpath d="M2.592.044l18.364 18.364-2.548 2.548L.044 2.592z"/%3E%3Cpath d="M0 18.364L18.364 0l2.548 2.548L2.548 20.912z"/%3E%3C/g%3E%3C/svg%3E'`))
    /* eslint-enable quotes */
    .pipe(replace(/\.\.\/fonts\/\/?/g, 'fonts/'))
    .pipe(gulp.dest('dist'))
    .pipe(rename(`${file}.min.css`))
    .pipe(cleanCSS({ compatibility: 'ie8' }))
    .pipe(gulp.dest('dist'));
};
gulp.task('styles-form', function formStyles() {
  return compileStyles([
    './node_modules/flatpickr/dist/flatpickr.min.css',
    './node_modules/choices.js/public/assets/styles/choices.min.css',
    './node_modules/dialog-polyfill/dialog-polyfill.css',
    './src/sass/formio.form.scss'
  ], 'formio.form');
});
gulp.task('styles-builder', function builderStyles() {
  return compileStyles([
    './node_modules/flatpickr/dist/flatpickr.min.css',
    './node_modules/choices.js/public/assets/styles/choices.min.css',
    './node_modules/dialog-polyfill/dialog-polyfill.css',
    './node_modules/dragula/dist/dragula.css',
    './src/sass/formio.form.scss',
    './src/sass/formio.form.builder.scss'
  ], 'formio.builder');
});
gulp.task('styles-full', gulp.series('builder-fonts', function fullStyles() {
  return compileStyles([
    './node_modules/flatpickr/dist/flatpickr.min.css',
    './node_modules/choices.js/public/assets/styles/choices.min.css',
    './node_modules/dialog-polyfill/dialog-polyfill.css',
    './node_modules/dragula/dist/dragula.css',
    './node_modules/font-awesome/css/font-awesome.css',
    './src/sass/formio.form.scss',
    './src/sass/formio.form.builder.scss'
  ], 'formio.full');
}));

// Script builds.
const webpackDev = require('./config/webpack.dev');
const webpackProd = require('./config/webpack.prod');
const buildDev = (input, output) => webpackStream(webpackDev(input, output), webpack).pipe(gulp.dest('dist'));
const buildProd = (input, output) => webpackStream(webpackProd(input, output), webpack).pipe(gulp.dest('dist'));
const build = (input, output) => {
  const prodFile = output.replace(/\.js$/, '.min.js');
  gulp.task(output, () => buildDev(input, output));
  gulp.task(prodFile, () => buildProd(input, prodFile));
  return gulp.parallel(output, prodFile);
};
gulp.task('scripts-formio', build('Formio.js', 'formio.js'));
gulp.task('scripts-utils', build('utils/utils.js', 'formio.utils.js'));
gulp.task('scripts-full', build('index.js', 'formio.full.js'));
gulp.task('scripts-form', build('formio.form.js', 'formio.form.js'));
gulp.task('formio.embed.min.js', () => buildProd('formio.embed.js', 'formio.embed.min.js'));
gulp.task('formio.embed.js', () =>
  gulp.src('./dist/formio.embed.min.js')
    .pipe(rename('formio.embed.js'))
    .pipe(gulp.dest('dist')));
gulp.task('scripts-embed', gulp.series('formio.embed.min.js', 'formio.embed.js'));
gulp.task('scripts-contrib', build('contrib/index.js', 'formio.contrib.js'));

gulp.task('jquery', () => gulp.src('./node_modules/jquery/dist/**/*.*').pipe(gulp.dest('./app/jquery')));
gulp.task('fontawesome', () => gulp.src('./node_modules/font-awesome/**/*.*').pipe(gulp.dest('./app/fontawesome')));
gulp.task('bootstrap', () => gulp.src('./node_modules/bootstrap/dist/**/*.*').pipe(gulp.dest('./app/bootstrap')));
gulp.task('bootswatch', () => gulp.src('./node_modules/bootswatch/**/*.*').pipe(gulp.dest('./app/bootswatch')));

// Copy the version and dependencies into the distribution package.json file.
gulp.task('package-version', function() {
  const pkg = require('./package.json');
  return gulp.src([
    'src/package.json'
  ])
    .pipe(replace(/"version": ""/, `"version": "${pkg.version}"`))
    .pipe(replace(/"dependencies": {}/, `"dependencies": ${JSON.stringify(pkg.dependencies)}`))
    .pipe(gulp.dest('lib'));
});

// Copy over the dist folder into the lib folder.
gulp.task('dist', () => gulp.src(['dist/**/*.*']).pipe(gulp.dest('lib/dist')));

// Watch for changes.
gulp.task('watch', () => gulp.watch(['./src/*.js', './src/**/*.js'], gulp.series('scripts-full')));

// Copy over the moment-timezones to the resource folder.
gulp.task('timezones', () => gulp.src('./node_modules/moment-timezone/data/packed/latest.json').pipe(gulp.dest('./resources')));

// Create a new build.
gulp.task('build', gulp.series(
  'clean',
  'babel',
  'package-version',
  gulp.parallel(
    'jquery',
    'timezones',
    'fontawesome',
    'bootstrap',
    'bootswatch'
  ),
  gulp.parallel(
    'styles-form',
    'styles-builder',
    'styles-full',
    'scripts-formio',
    'scripts-utils',
    'scripts-embed',
    'scripts-contrib',
    'scripts-form',
    'scripts-full'
  ),
  'dist'
));

// Default task. Build and watch.
gulp.task('default', gulp.series('babel', 'scripts-full', 'watch'));
<|endoftext|>


<commit_before>'use strict';

var gulp = require('gulp'),
    browserSync = require('browser-sync'),
    nodemon = require('gulp-nodemon');

var BROWSER_SYNC_RELOAD_DELAY = 500;

gulp.task('nodemon', function(cb) {
  var called = false;
  return nodemon({
    // nodemon our expressjs server
    script: 'restify.js',
    // watch core server file(s) that require server restart on change
    watch: ['restify.js']
  })
  .on('start', function onStart() {
    // ensure start only got called once
    if (!called) { cb(); }
    called = true;
  })
  .on('restart', function onRestart() {
    // reload connected browsers after a slight delay
    setTimeout(function reload() {
      browserSync.reload({
        stream: false
      });
    }, BROWSER_SYNC_RELOAD_DELAY);
  });
});

gulp.task('browser-sync', ['nodemon'], function() {
  // for more browser-sync config options: http://www.browsersync.io/docs/options/
  browserSync({
    // informs browser-sync to proxy our expressjs app which would run at the following location
    proxy: 'http://localhost:8000',
    // informs browser-sync to use the following port for the proxied app
    // notice that the default port is 3000, which would clash with our expressjs
    port: 4000,
    // open the proxied app in chrome
    browser: 'google chrome'
  });
});

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

gulp.task('default', ['browser-sync'], function() {
  //gulp.watch('client/scripts/**/*.js', ['scripts-vendor', 'scripts-app', browserSync.reload]);
});
<commit_msg>Fixing gulp watching *.js files<commit_after>'use strict';

var gulp = require('gulp'),
    browserSync = require('browser-sync'),
    nodemon = require('gulp-nodemon');

var BROWSER_SYNC_RELOAD_DELAY = 500;

gulp.task('nodemon', function(cb) {
  var called = false;
  return nodemon({
    // nodemon our expressjs server
    script: 'restify.js',
    // watch core server file(s) that require server restart on change
    watch: ['*.js']
  })
  .on('start', function onStart() {
    // ensure start only got called once
    if (!called) { cb(); }
    called = true;
  })
  .on('restart', function onRestart() {
    // reload connected browsers after a slight delay
    setTimeout(function reload() {
      browserSync.reload({
        stream: false
      });
    }, BROWSER_SYNC_RELOAD_DELAY);
  });
});

gulp.task('browser-sync', ['nodemon'], function() {
  // for more browser-sync config options: http://www.browsersync.io/docs/options/
  browserSync({
    // informs browser-sync to proxy our expressjs app which would run at the following location
    proxy: 'http://localhost:8000',
    // informs browser-sync to use the following port for the proxied app
    // notice that the default port is 3000, which would clash with our expressjs
    port: 4000,
    // open the proxied app in chrome
    browser: 'google chrome'
  });
});

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

gulp.task('default', ['browser-sync'], function() {
  //gulp.watch('*.js', ['scripts-vendor', 'scripts-app', browserSync.reload]);
});
<|endoftext|>


<commit_before>// gulpfile.js - http://jsua.co/mm-gulp

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

// 1. LOAD PLUGINS

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

// 2. CONFIGURATION

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

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

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

  sassOpts = {
    imagePath: '../images',
    errLogToConsole: true
  },

  autoprefixerOpts = {
    browsers: ['last 3 versions', '> 5%']
  },

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

  uglifyOpts = {
    preserveComments: 'license'
  },

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

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

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

// 3. WORKER TASKS

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

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

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

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

// Web Fonts
gulp.task('fonts', function() {
  return gulp.src(fonts.in)
    .pipe(p.changed(fonts.out))
    .pipe(gulp.dest(fonts.out));
});

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

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

// 4. SUPER TASKS

// Development Task
gulp.task('development', function(done) {
  p.runSequence('clean', 'css', 'fonts', 'js', 'images', done);
});

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

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

  p.browserSync.init(serverOpts);

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

});

function handleError(err) {
  console.log(err.toString());
  this.emit('end');
}
<commit_msg>Run fonts task in production.<commit_after>// gulpfile.js - http://jsua.co/mm-gulp

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

// 1. LOAD PLUGINS

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

// 2. CONFIGURATION

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

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

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

  sassOpts = {
    imagePath: '../images',
    errLogToConsole: true
  },

  autoprefixerOpts = {
    browsers: ['last 3 versions', '> 5%']
  },

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

  uglifyOpts = {
    preserveComments: 'license'
  },

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

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

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

// 3. WORKER TASKS

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

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

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

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

// Web Fonts
gulp.task('fonts', function() {
  return gulp.src(fonts.in)
    .pipe(p.changed(fonts.out))
    .pipe(gulp.dest(fonts.out));
});

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

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

// 4. SUPER TASKS

// Development Task
gulp.task('development', function(done) {
  p.runSequence('clean', 'css', 'fonts', 'js', 'images', done);
});

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

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

  p.browserSync.init(serverOpts);

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

});

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


<commit_before>var gulp = require('gulp'),
    rollup = require('rollup'),
    browserSync = require('browser-sync'),
    uglify = require('gulp-uglify'),
    minifyCss = require('gulp-minify-css');

gulp.task('compress', function() {
  return gulp.src('lib/*.js')
    .pipe(uglify())
    .pipe(gulp.dest('dist'));
});

var ENTRY = 'src/js/main.js';
var DEST = 'js/main.js';

gulp.task('bundle', function() {
    return rollup.rollup({
        entry: ENTRY
    }).then(function (bundle) {
        return bundle.write({
            format: 'iife',
            dest: DEST
        });
    });
});

gulp.task('minify-css', function() {
    return gulp.src('src/styles/*.css')
        .pipe(minifyCss())
        .pipe(gulp.dest('./styles'));
});

gulp.task('minify-js', ['bundle'], function() {
    return gulp.src('js/*.js')
        .pipe(uglify())
        .pipe(gulp.dest('js'));
});

gulp.task('default', ['minify-css', 'minify-js']);

gulp.task('build-and-reload', ['minify-css', 'bundle'], function () {
    browserSync.reload();
});

gulp.task('serve', function(cb) {
  browserSync({
    server: {
      baseDir: './'
    },
    notify: false,
    ui: false,
    ghostMode: false
  });

  gulp.watch(['*.html', 'styles/**/*.css', 'js/**/*.js'], {cwd: 'src'}, ['build-and-reload']);
});
<commit_msg>Clean up gulpfile<commit_after>var gulp = require('gulp'),
    rollup = require('rollup'),
    browserSync = require('browser-sync'),
    uglify = require('gulp-uglify'),
    minifyCss = require('gulp-minify-css');

var ENTRY = 'src/js/main.js';
var DEST = 'js/main.js';

gulp.task('bundle', function() {
    return rollup.rollup({
        entry: ENTRY
        }).then(function (bundle) {
            return bundle.write({
                format: 'iife',
                dest: DEST
                });
            });
        });

gulp.task('minify-css', function() {
    return gulp.src('src/styles/*.css')
    .pipe(minifyCss())
    .pipe(gulp.dest('./styles'));
    });

gulp.task('minify-js', ['bundle'], function() {
    return gulp.src('js/*.js')
    .pipe(uglify())
    .pipe(gulp.dest('js'));
    });

gulp.task('build-and-reload', ['minify-css', 'bundle'], function () {
    browserSync.reload();
    });

gulp.task('serve', function(cb) {
    browserSync({
        server: {
            baseDir: './'
        },
        notify: false,
        ui: false,
        ghostMode: false
    });

    gulp.watch(['*.html', 'styles/**/*.css', 'js/**/*.js'], {cwd: 'src'}, ['build-and-reload']);
});

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