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

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

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

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

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

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

var LIVERELOAD_PORT = 35729;
var BASEDIR = path.join(__dirname, 'server/views');
var STATIC_PAGES_ROOT = __dirname + '/server/views/pages';
var PAGE_WAIT = 2000;

gulp.task('bower', function(){
  return bower();
});

gulp.task('clean-scripts-build', function() {
  gulp.src('build/scripts/*.*', {read: false})
    .pipe(clean());
});

gulp.task('clean-scripts-dist', function() {
  gulp.src('dist/scripts/*.*', {read: false})
    .pipe(clean());
});

gulp.task('clean-third-party-build', function() {
  gulp.src('build/scripts/third-party/*.*', {read: false})
    .pipe(clean());
});

gulp.task('clean-third-party-dist', function() {
  gulp.src('dist/scripts/third-party/*.*', {read: false})
    .pipe(clean());
});

gulp.task('clean-less-build', function() {
  gulp.src('build/styles/*.css', {read: false})
    .pipe(clean());
});

gulp.task('clean-less-dist', function() {
  gulp.src('dist/styles/*.css', {read: false})
    .pipe(clean());
});

gulp.task('clean-templates-build', function() {
  gulp.src('build/**/*.html', {read: false})
    .pipe(clean());
});

gulp.task('clean-templates-dist', function() {
  gulp.src('dist/**/*.html', {read: false})
    .pipe(clean());
});

gulp.task('clean-server', function() {
  gulp.src('server/**/*.js', {read: false})
    .pipe(clean());
});

gulp.task('copy-to-build', function() {
  gulp.src(['client/**/*.*', '!client/**/*.{coffee,less}'])
    .pipe(gulp.dest('build'));
});

gulp.task('copy-to-dist', function() {
  gulp.src(['client/**/*.*', '!client/**/*.{coffee,less}'])
    .pipe(gulp.dest('dist'));
});

gulp.task('third-party-build', ['clean-third-party-build'], function() {
  gulp.src(['third-party/**/*.min.js', '!third-party/bootstrap/**/*.min.js'])
    .pipe(flatten())
    .pipe(gulp.dest('build/scripts'));
  gulp.src(['third-party/bootstrap/dist/css/*.*'])
    .pipe(gulp.dest('build/styles'));
  gulp.src(['third-party/bootstrap/dist/js/*.*'])
    .pipe(gulp.dest('build/scripts'));
  gulp.src(['third-party/bootstrap/dist/fonts/*.*'])
    .pipe(gulp.dest('build/fonts'));
});

gulp.task('third-party-dist', ['clean-third-party-dist'], function() {
  gulp.src(['third-party/**/*.min.js', '!third-party/bootstrap/**/*.min.js'])
    .pipe(flatten())
    .pipe(gulp.dest('dist/scripts'));
  gulp.src(['third-party/bootstrap/dist/css/*.*'])
    .pipe(gulp.dest('dist/styles'));
  gulp.src(['third-party/bootstrap/dist/js/*.*'])
    .pipe(gulp.dest('dist/scripts'));
  gulp.src(['third-party/bootstrap/dist/fonts/*.*'])
    .pipe(gulp.dest('dist/fonts'));
});

gulp.task('scripts-build', ['clean-scripts-build'], function() {
  gulp.src(['client/**/*.coffee'])
    .pipe(coffeelint())
    .pipe(coffeelint.reporter())
    .pipe(coffee())
    .pipe(jshint())
    .pipe(jshint.reporter('default'))
    .pipe(jshint.reporter('fail'))
    .pipe(concat('main.js'))
    .pipe(gulp.dest('build/scripts'))
    .pipe(rename('main.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest('build/scripts'))
    .pipe(livereload(tinylr));
});

gulp.task('scripts-dist', ['clean-scripts-dist'], function() {
  gulp.src(['client/**/*.coffee'])
    .pipe(coffeelint())
    .pipe(coffeelint.reporter())
    .pipe(coffee())
    .pipe(jshint())
    .pipe(jshint.reporter('default'))
    .pipe(jshint.reporter('fail'))
    .pipe(concat('main.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest('build/scripts'));
});

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

gulp.task('less-build', ['clean-less-build'], function() {
  gulp.src('client/less/*.less')
    .pipe(less())
    .pipe(concat('main.css'))
    .pipe(gulp.dest('build/styles'))
    .pipe(rename('main.min.css'))
    .pipe(minifyCSS({ removeEmpty: true }))
    .pipe(gulp.dest('build/styles'))
    .pipe(livereload(tinylr));
});

gulp.task('less-dist', ['clean-less-dist'], function() {
  gulp.src('client/less/*.less')
    .pipe(less())
    .pipe(concat('main.min.css'))
    .pipe(gulp.dest('dist/styles'));
});

gulp.task('templates-build', ['clean-templates-build'], function() {
  gulp.src('server/views/pages/**/*.jade')
    .pipe(jade({
      basedir: BASEDIR,
      locals: { env: 'dev', liveReloadPort: LIVERELOAD_PORT }
    }))
    .pipe(gulp.dest('build'))
});

gulp.task('templates-dist', ['clean-templates-dist'], function() {
  gulp.src('server/views/pages/**/*.jade')
    .pipe(jade({
      basedir: BASEDIR,
      locals: { env: 'pro' }
    }))
    .pipe(gulp.dest('dist'))
});

gulp.task('serve', function () {
  nodemon({ script: 'server/app.js', ext: 'coffee', watch: 'server' })
    .on('restart', ['scripts-server'])
  tinylr.listen(LIVERELOAD_PORT, function() {
    console.log('TinyLR Listening on %s', LIVERELOAD_PORT);
  });
});

gulp.task('watch', function() {
  gulp.watch('client/scripts/*.coffee', ['scripts-build']).on('change', function(file) {
    tinylr.changed(file.path);
  });
  gulp.watch('client/less/*.less', ['less-build']).on('change', function(file) {
    tinylr.changed(file.path);
  });
  gulp.watch('server/views/**/*.jade', ['templates-build']).on('change', function(file) {
    var filename = '/' + path.relative(STATIC_PAGES_ROOT, file.path).replace(/\.jade$/, '.html');
    setTimeout(function(){tinylr.changed({ body: { files: [filename] } });}, PAGE_WAIT);
  });
});

gulp.task('server', [
  'scripts-server',
  'third-party-build',
  'scripts-build',
  'less-build',
  'templates-build',
  'copy-to-build',
  'serve',
  'watch'
]);

gulp.task('dist', [
  'scripts-server',
  'third-party-dist',
  'scripts-dist',
  'templates-dist',
  'copy-to-dist',
  'less-dist'
]);
<commit_msg>Adding cache-busting timestamp to gulpfile.<commit_after>
var http = require('http');
var path = require('path');
var gulp = require('gulp');

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

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

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

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

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

var LIVERELOAD_PORT = 35729;
var BASEDIR = path.join(__dirname, 'server/views');
var MARKER = (new Date()).getTime();
var STATIC_PAGES_ROOT = __dirname + '/server/views/pages';
var PAGE_WAIT = 2000;

gulp.task('bower', function(){
  return bower();
});

gulp.task('clean-scripts-build', function() {
  gulp.src('build/scripts/*.*', {read: false})
    .pipe(clean());
});

gulp.task('clean-scripts-dist', function() {
  gulp.src('dist/scripts/*.*', {read: false})
    .pipe(clean());
});

gulp.task('clean-third-party-build', function() {
  gulp.src('build/scripts/third-party/*.*', {read: false})
    .pipe(clean());
});

gulp.task('clean-third-party-dist', function() {
  gulp.src('dist/scripts/third-party/*.*', {read: false})
    .pipe(clean());
});

gulp.task('clean-less-build', function() {
  gulp.src('build/styles/*.css', {read: false})
    .pipe(clean());
});

gulp.task('clean-less-dist', function() {
  gulp.src('dist/styles/*.css', {read: false})
    .pipe(clean());
});

gulp.task('clean-templates-build', function() {
  gulp.src('build/**/*.html', {read: false})
    .pipe(clean());
});

gulp.task('clean-templates-dist', function() {
  gulp.src('dist/**/*.html', {read: false})
    .pipe(clean());
});

gulp.task('clean-server', function() {
  gulp.src('server/**/*.js', {read: false})
    .pipe(clean());
});

gulp.task('copy-to-build', function() {
  gulp.src(['client/**/*.*', '!client/**/*.{coffee,less}'])
    .pipe(gulp.dest('build'));
});

gulp.task('copy-to-dist', function() {
  gulp.src(['client/**/*.*', '!client/**/*.{coffee,less}'])
    .pipe(gulp.dest('dist'));
});

gulp.task('third-party-build', ['clean-third-party-build'], function() {
  gulp.src(['third-party/**/*.min.js', '!third-party/bootstrap/**/*.min.js'])
    .pipe(flatten())
    .pipe(gulp.dest('build/scripts'));
  gulp.src(['third-party/bootstrap/dist/css/*.*'])
    .pipe(gulp.dest('build/styles'));
  gulp.src(['third-party/bootstrap/dist/js/*.*'])
    .pipe(gulp.dest('build/scripts'));
  gulp.src(['third-party/bootstrap/dist/fonts/*.*'])
    .pipe(gulp.dest('build/fonts'));
});

gulp.task('third-party-dist', ['clean-third-party-dist'], function() {
  gulp.src(['third-party/**/*.min.js', '!third-party/bootstrap/**/*.min.js'])
    .pipe(flatten())
    .pipe(gulp.dest('dist/scripts'));
  gulp.src(['third-party/bootstrap/dist/css/*.*'])
    .pipe(gulp.dest('dist/styles'));
  gulp.src(['third-party/bootstrap/dist/js/*.*'])
    .pipe(gulp.dest('dist/scripts'));
  gulp.src(['third-party/bootstrap/dist/fonts/*.*'])
    .pipe(gulp.dest('dist/fonts'));
});

gulp.task('scripts-build', ['clean-scripts-build'], function() {
  gulp.src(['client/**/*.coffee'])
    .pipe(coffeelint())
    .pipe(coffeelint.reporter())
    .pipe(coffee())
    .pipe(jshint())
    .pipe(jshint.reporter('default'))
    .pipe(jshint.reporter('fail'))
    .pipe(concat('main.js'))
    .pipe(gulp.dest('build/scripts'))
    .pipe(rename('main.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest('build/scripts'))
    .pipe(livereload(tinylr));
});

gulp.task('scripts-dist', ['clean-scripts-dist'], function() {
  gulp.src(['client/**/*.coffee'])
    .pipe(coffeelint())
    .pipe(coffeelint.reporter())
    .pipe(coffee())
    .pipe(jshint())
    .pipe(jshint.reporter('default'))
    .pipe(jshint.reporter('fail'))
    .pipe(concat('main.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest('build/scripts'));
});

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

gulp.task('less-build', ['clean-less-build'], function() {
  gulp.src('client/less/*.less')
    .pipe(less())
    .pipe(concat('main.css'))
    .pipe(gulp.dest('build/styles'))
    .pipe(rename('main.min.css'))
    .pipe(minifyCSS({ removeEmpty: true }))
    .pipe(gulp.dest('build/styles'))
    .pipe(livereload(tinylr));
});

gulp.task('less-dist', ['clean-less-dist'], function() {
  gulp.src('client/less/*.less')
    .pipe(less())
    .pipe(concat('main.min.css'))
    .pipe(gulp.dest('dist/styles'));
});

gulp.task('templates-build', ['clean-templates-build'], function() {
  gulp.src('server/views/pages/**/*.jade')
    .pipe(jade({
      basedir: BASEDIR,
      locals: { env: 'dev', marker: MARKER, liveReloadPort: LIVERELOAD_PORT }
    }))
    .pipe(gulp.dest('build'))
});

gulp.task('templates-dist', ['clean-templates-dist'], function() {
  gulp.src('server/views/pages/**/*.jade')
    .pipe(jade({
      basedir: BASEDIR,
      locals: { env: 'pro', marker: MARKER }
    }))
    .pipe(gulp.dest('dist'))
});

gulp.task('serve', function () {
  nodemon({ script: 'server/app.js', ext: 'coffee', watch: 'server' })
    .on('restart', ['scripts-server'])
  tinylr.listen(LIVERELOAD_PORT, function() {
    console.log('TinyLR Listening on %s', LIVERELOAD_PORT);
  });
});

gulp.task('watch', function() {
  gulp.watch('client/scripts/*.coffee', ['scripts-build']).on('change', function(file) {
    tinylr.changed(file.path);
  });
  gulp.watch('client/less/*.less', ['less-build']).on('change', function(file) {
    tinylr.changed(file.path);
  });
  gulp.watch('server/views/**/*.jade', ['templates-build']).on('change', function(file) {
    var filename = '/' + path.relative(STATIC_PAGES_ROOT, file.path).replace(/\.jade$/, '.html');
    setTimeout(function(){tinylr.changed({ body: { files: [filename] } });}, PAGE_WAIT);
  });
});

gulp.task('server', [
  'scripts-server',
  'third-party-build',
  'scripts-build',
  'less-build',
  'templates-build',
  'copy-to-build',
  'serve',
  'watch'
]);

gulp.task('dist', [
  'scripts-server',
  'third-party-dist',
  'scripts-dist',
  'templates-dist',
  'copy-to-dist',
  'less-dist'
]);
<|endoftext|>


<commit_before>
/*globals Buffer, __dirname*/

// Native Node Modules
var exec = require("child_process").exec;
var del = require("del");
var fs = require("fs");
var stream = require("stream");

// Gulp & Gulp Plugins
var gulp = require("gulp");
var gutil = require("gulp-util");
var rename = require("gulp-rename");
var ts = require("gulp-typescript");
var tslint = require("gulp-tslint");
var sass = require("gulp-sass");
var sourcemaps = require("gulp-sourcemaps");
var templateCache = require("gulp-angular-templatecache");

// Other Modules
var runSequence = require("run-sequence");
var bower = require("bower");
var packager = require("electron-packager")
// var sh = require("shelljs")
// var async = require("async");
// var xpath = require("xpath");
// var XmlDom = require("xmldom").DOMParser;
// var karma = require("karma").server;

var paths = {
    ts: ["./src/**/*.ts"],
    templates: ["./src/renderer/**/*.html"],
    shell_ts: ["./src/shell/**/*.ts"],
    renderer_ts: ["./src/renderer/**/*.ts"],
    sassIndex: "./src/renderer/Styles/Index.scss",
};

/**
 * Used to determine if the gulp operation was launched for a debug or release build.
 * This is controlled by the scheme parameter, if no scheme is provided, it will default
 * to debug. For example, to specify release build for the ts task you"d use:
 *
 * gulp ts --scheme release
 */
function isDebugScheme() {
    return gutil.env.scheme === "release" ? false : true;
}

/**
 * A custom reporter for the TypeScript linter reporter function. This was copied
 * and modified from gulp-tslint.
 */
function logTsError(message, level) {
    var prefix = "[" + gutil.colors.cyan("gulp-tslint") + "]";

    if (level === "error") {
        gutil.log(prefix, gutil.colors.red("error"), message);
    } else if (level === "warn") {
        gutil.log(prefix, gutil.colors.yellow("warn"), message);
    } else {
        gutil.log(prefix, message);
    }
}

/**
 * A custom reporter for the TypeScript linter so we can pass "warn" instead of
 * "error" to be recognized by Visual Studio Code's pattern matcher as warnings
 * instead of errors. This was copied and modified from gulp-tslint.
 */
var tsLintReporter = function(failures, file) {
    failures.forEach(function(failure) {
        // line + 1 because TSLint's first line and character is 0
        logTsError("(" + failure.ruleName + ") " + file.path +
            "[" + (failure.startPosition.line + 1) + ", " +
            (failure.startPosition.character + 1) + "]: " +
            failure.failure, "warn");
    });
};

/**
 * A custom reporter for the sass compilation task so we can control the formatting
 * of the message for our custom problem matcher in Visual Studio Code.
 */
var sassReporter = function (failure) {
    var file = failure.message.split("\n")[0];
    var message = failure.message.split("\n")[1];

    console.log("[sass] [" + failure.name.toLowerCase() + "] [" + file + "] [" + failure.line + ":" + failure.column + "] - " + message);
}

/**
 * Helper used to pipe an arbitrary string value into a file.
 *
 * http://stackoverflow.com/a/23398200/4005811
 */
function string_src(filename, str) {
    var src = new stream.Readable({ objectMode: true });

    src._read = function () {
        this.push(new gutil.File({ cwd: "", base: "", path: filename, contents: new Buffer(str) }));
        this.push(null);
    };

    return src;
}

/**
 * The default task downloads Cordova plugins, Bower libraries, TypeScript definitions,
 * and then compiles the SASS into CSS and builds the TypeScript source code.
 */
gulp.task("default", function (cb) {
    runSequence("libs", "tsd", "sass", "templates", "ts", cb);
});

/**
 * The watch task will watch for any changes in the TypeScript files and re-execute the
 * ts gulp task if they change. The "ionic serve" command will also invoke this task to
 * refresh the browser window during development.
 */
gulp.task("watch", function() {
    gulp.watch(paths.ts, ["sass", "ts"]);
});

/**
 * Performs linting of the TypeScript source code.
 */
gulp.task("lint", function (cb) {
    var filesToLint = paths.ts;

    return gulp.src(filesToLint)
    .pipe(tslint())
    .pipe(tslint.report(tsLintReporter));
});

/**
 * Uses the tsd command to restore TypeScript definitions to the typings
 * directories and rebuild the tsd.d.ts typings bundle for both the shell
 * and renderer source.
 */
gulp.task("tsd", function (cb) {
    runSequence("tsd:shell", "tsd:renderer", cb);
});

/**
 * Uses the tsd command to restore TypeScript definitions to the typings
 * directory and rebuild the tsd.d.ts typings bundle (for the shell source).
 */
gulp.task("tsd:shell", function (cb) {

    // First reinstall any missing definitions to the typings directory.
    exec("tsd reinstall --config tsd-shell.json", function (err, stdout, stderr) {
        console.log(stdout);
        console.log(stderr);

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

        // Rebuild the src/shell/tsd.d.ts bundle reference file.
        exec("tsd rebundle --config tsd-shell.json", function (err, stdout, stderr) {
            console.log(stdout);
            console.log(stderr);
            cb(err);
        });
    });
});

/**
 * Uses the tsd command to restore TypeScript definitions to the typings
 * directory and rebuild the tsd.d.ts typings bundle (for the renderer source).
 */
gulp.task("tsd:renderer", function (cb) {

    // First reinstall any missing definitions to the typings directory.
    exec("tsd reinstall --config tsd-renderer.json", function (err, stdout, stderr) {
        console.log(stdout);
        console.log(stderr);

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

        // Rebuild the src/renderer/tsd.d.ts bundle reference file.
        exec("tsd rebundle --config tsd-renderer.json", function (err, stdout, stderr) {
            console.log(stdout);
            console.log(stderr);
            cb(err);
        });
    });
});

/**
 * Used to generate the app/build-vars.json file which contains information about
 * the build (such as version number, timestamp, and build scheme).
 *
 * The version number is taken from the config.xml file.
 */
gulp.task("ts:vars", function (cb) {

    var packageInfo = JSON.parse(fs.readFileSync("app/package.json", "utf8"));

    exec("git rev-parse --short HEAD", function (err, stdout, stderr) {

        var commitShortSha = err ? "unknown" : stdout.replace("\n", "");

        // Create the structure of the buildVars variable.
        var buildVars = {
            commitShortSha: commitShortSha,
            debug: isDebugScheme(),
            buildTimestamp: (new Date()).toUTCString(),
            version: packageInfo.version
        }

        // Serialize to JSON.
        var buildVarsJson = JSON.stringify(buildVars);

        // Write the file out to disk for the shell.
        fs.writeFileSync("app/build-vars.json", buildVarsJson, { encoding: "utf8" });

        cb();
    });
});

/**
 * Used to copy the entire TypeScript source into the app/www/js/src directory
 * so that it can be used for debugging purposes.
 *
 * This will only copy the files if the build scheme is not set to release.
 */
gulp.task("ts:src", ["ts:src-read-me"], function (cb) {

    if (!isDebugScheme()) {
        cb();
        return;
    }

    return gulp.src(paths.renderer_ts)
        .pipe(gulp.dest("app/www/js/src/renderer"));
});

/**
 * Used to add a readme file to app/src and www/js/app/src to explain what the
 * directories are for.
 *
 * This will only copy the files if the build scheme is not set to release.
 */
gulp.task("ts:src-read-me", function (cb) {

    if (!isDebugScheme()) {
        cb();
        return;
    }

    var infoMessage = "This directory contains a copy of the TypeScript source files for debug builds; it can be safely deleted and will be regenerated via the gulp ts task.\n\nTo omit this directory create a release build by specifying the scheme:\ngulp ts --scheme release";

    return string_src("readme.txt", infoMessage)
        .pipe(gulp.dest("app/www/js/src"));
});

/**
 * Used to perform compliation of the TypeScript source in the src directory and
 * output the JavaScript to the shell and renderer directories. Compilation parameters
 * are located in src/shell/tsconfig.json and src/renderer/tsconfig.json respectively.
 *
 * It will also delegate to the vars and src tasks to copy in the original source
 * which can be used for debugging purposes. This will only occur if the build scheme
 * is not set to release.
 */
gulp.task("ts", ["ts:vars", "ts:src"], function (cb) {
    exec("tsc -p src/shell", function (err1, stdout1, stderr1) {
        console.log(stdout1);
        console.log(stderr1);

        exec("tsc -p src/renderer", function (err2, stdout2, stderr2) {
            console.log(stdout2);
            console.log(stderr2);
            cb(err1 || err2);
        });
    });
});

/**
 * Used to concatenate all of the HTML templates into a single JavaScript module.
 */
gulp.task("templates", function() {
    return gulp.src(paths.templates)
        .pipe(templateCache({
            "filename": "templates.js",
            "root": "",
            "module": "templates",
            standalone: true
        }))
        .pipe(gulp.dest("./app/www/js"));
});

/**
 * Used to perform compilation of the SASS styles in the styles directory (using
 * Index.scss as the root file) and output the CSS to app/www/css/bundle.css.
 */
gulp.task("sass", function (cb) {

    var sassConfig = {
        outputStyle: isDebugScheme() ? "nested" : "compressed",
        errLogToConsole: false
    };

    return gulp.src(paths.sassIndex)
        .pipe(sourcemaps.init())
        .pipe(sass(sassConfig).on("error", sassReporter))
        .pipe(rename("bundle.css"))
        .pipe(sourcemaps.write("./"))
        .pipe(gulp.dest("./app/www/css"));
});

/**
 * Used to download all of the bower dependencies as defined in bower.json and place
 * the consumable pieces in the app/www/lib directory. Also runs an 'npm install' in
 * the app directory to download libraries specific to the shell source.
 */
gulp.task("libs", function(cb) {
    exec("bower-installer", function (err1, stdout1, stderr1) {
        console.log(stdout1);
        console.log(stderr1);

        exec("npm install", { cwd: "app" }, function (err2, stdout2, stderr2) {
            console.log(stdout2);
            console.log(stderr2);
            cb(err1 || err2);
        });
    });
});

/**
 * Uses electron-packager to package up the contents of the app directory with the Electron
 * runtime and place the output in the build directory. This currently assumes building for
 * the Windows platform and must be run on a Windows machine to properly edit the icon.
 */
gulp.task("package", function (cb) {

    var packageInfo = JSON.parse(fs.readFileSync("app/package.json", "utf8"));

    var options = {
        dir: "app",
        platform: "win32",
        arch: "x64",
        icon: "app/icons/joystick.ico",
        name: packageInfo.name,
        "build-version": packageInfo.version,
        version: packageInfo.dependencies["electron-prebuilt"],
        out: "build",
        overwrite: true,
        "version-string": {
            FileDescription: packageInfo.name
        }
    };

    packager(options, cb);
});

/**
 * Used to perform a file clean-up of the project. This removes all files and directories
 * that don"t need to be committed to source control by delegating to several of the clean
 * sub-tasks.
 */
gulp.task("clean", ["clean:node", "clean:bower", "clean:libs", "clean:ts", "clean:tsd", "clean:templates", "clean:sass", "clean:package"]);

/**
 * Removes the node_modules directory.
 */
gulp.task("clean:node", function (cb) {
    del([
        "node_modules"
    ], cb);
});

/**
 * Removes the bower_components directory.
 */
gulp.task("clean:bower", function (cb) {
    del([
        "bower_components"
    ], cb);
});

/**
 * Removes the www/lib directory.
 */
gulp.task("clean:libs", function (cb) {
    del([
        "app/www/lib"
    ], cb);
});

/**
 * Removes files related to TypeScript compilation.
 */
gulp.task("clean:ts", function (cb) {
    del([
        "app/build-vars.json",
        "app/shell",

        "app/www/js/bundle.js",
        "app/www/js/bundle.js.map",
        "app/www/js/bundle.d.ts",
        "app/www/js/src"
    ], cb);
});

/**
 * Removes files related to TypeScript definitions.
 */
gulp.task("clean:tsd", function (cb) {

    // TODO: These patterns don't actually remove the sub-directories
    // located in the typings directories, they leave the directories
    // but remove the *.d.ts files. The following glob should work for
    // remove directories and preserving the custom directory, but they
    // don't for some reason and the custom directory is always removed:
    // "typings/**"
    // "!typings/custom/**"

    del([
        "src/shell/tsd.d.ts",
        "typings/shell/**/*.d.ts",
        "!typings/shell/custom/*.d.ts",
        // "typings/**",
        // "!typings/shell/custom/**",

        "src/renderer/tsd.d.ts",
        "typings/renderer/**/*.d.ts",
        "!typings/renderer/custom/*.d.ts",
        // "typings/**",
        // "!typings/custom/**",

    ], cb);
});

/**
 * Removes the generated templates JavaScript from the templates target.
 */
gulp.task("clean:templates", function (cb) {
    del([
        "www/js/templates.js"
    ]).then(function () {
        cb();
    });
});

/**
 * Removes the generated css from the SASS target.
 */
gulp.task("clean:sass", function (cb) {
    del([
        "app/www/css/bundle.css",
        "app/www/css/bundle.css.map"
    ], cb);
});

/**
 * Removes the generated build directory from the package target.
 */
gulp.task("clean:package", function (cb) {
    del([
        "build"
    ], cb);
});
<commit_msg>gulp package now runs default task<commit_after>
/*globals Buffer, __dirname*/

// Native Node Modules
var exec = require("child_process").exec;
var del = require("del");
var fs = require("fs");
var stream = require("stream");

// Gulp & Gulp Plugins
var gulp = require("gulp");
var gutil = require("gulp-util");
var rename = require("gulp-rename");
var ts = require("gulp-typescript");
var tslint = require("gulp-tslint");
var sass = require("gulp-sass");
var sourcemaps = require("gulp-sourcemaps");
var templateCache = require("gulp-angular-templatecache");

// Other Modules
var runSequence = require("run-sequence");
var bower = require("bower");
var packager = require("electron-packager")
// var sh = require("shelljs")
// var async = require("async");
// var xpath = require("xpath");
// var XmlDom = require("xmldom").DOMParser;
// var karma = require("karma").server;

var paths = {
    ts: ["./src/**/*.ts"],
    templates: ["./src/renderer/**/*.html"],
    shell_ts: ["./src/shell/**/*.ts"],
    renderer_ts: ["./src/renderer/**/*.ts"],
    sassIndex: "./src/renderer/Styles/Index.scss",
};

/**
 * Used to determine if the gulp operation was launched for a debug or release build.
 * This is controlled by the scheme parameter, if no scheme is provided, it will default
 * to debug. For example, to specify release build for the ts task you"d use:
 *
 * gulp ts --scheme release
 */
function isDebugScheme() {
    return gutil.env.scheme === "release" ? false : true;
}

/**
 * A custom reporter for the TypeScript linter reporter function. This was copied
 * and modified from gulp-tslint.
 */
function logTsError(message, level) {
    var prefix = "[" + gutil.colors.cyan("gulp-tslint") + "]";

    if (level === "error") {
        gutil.log(prefix, gutil.colors.red("error"), message);
    } else if (level === "warn") {
        gutil.log(prefix, gutil.colors.yellow("warn"), message);
    } else {
        gutil.log(prefix, message);
    }
}

/**
 * A custom reporter for the TypeScript linter so we can pass "warn" instead of
 * "error" to be recognized by Visual Studio Code's pattern matcher as warnings
 * instead of errors. This was copied and modified from gulp-tslint.
 */
var tsLintReporter = function(failures, file) {
    failures.forEach(function(failure) {
        // line + 1 because TSLint's first line and character is 0
        logTsError("(" + failure.ruleName + ") " + file.path +
            "[" + (failure.startPosition.line + 1) + ", " +
            (failure.startPosition.character + 1) + "]: " +
            failure.failure, "warn");
    });
};

/**
 * A custom reporter for the sass compilation task so we can control the formatting
 * of the message for our custom problem matcher in Visual Studio Code.
 */
var sassReporter = function (failure) {
    var file = failure.message.split("\n")[0];
    var message = failure.message.split("\n")[1];

    console.log("[sass] [" + failure.name.toLowerCase() + "] [" + file + "] [" + failure.line + ":" + failure.column + "] - " + message);
}

/**
 * Helper used to pipe an arbitrary string value into a file.
 *
 * http://stackoverflow.com/a/23398200/4005811
 */
function string_src(filename, str) {
    var src = new stream.Readable({ objectMode: true });

    src._read = function () {
        this.push(new gutil.File({ cwd: "", base: "", path: filename, contents: new Buffer(str) }));
        this.push(null);
    };

    return src;
}

/**
 * The default task downloads Cordova plugins, Bower libraries, TypeScript definitions,
 * and then compiles the SASS into CSS and builds the TypeScript source code.
 */
gulp.task("default", function (cb) {
    runSequence("libs", "tsd", "sass", "templates", "ts", cb);
});

/**
 * The watch task will watch for any changes in the TypeScript files and re-execute the
 * ts gulp task if they change. The "ionic serve" command will also invoke this task to
 * refresh the browser window during development.
 */
gulp.task("watch", function() {
    gulp.watch(paths.ts, ["sass", "ts"]);
});

/**
 * Performs linting of the TypeScript source code.
 */
gulp.task("lint", function (cb) {
    var filesToLint = paths.ts;

    return gulp.src(filesToLint)
    .pipe(tslint())
    .pipe(tslint.report(tsLintReporter));
});

/**
 * Uses the tsd command to restore TypeScript definitions to the typings
 * directories and rebuild the tsd.d.ts typings bundle for both the shell
 * and renderer source.
 */
gulp.task("tsd", function (cb) {
    runSequence("tsd:shell", "tsd:renderer", cb);
});

/**
 * Uses the tsd command to restore TypeScript definitions to the typings
 * directory and rebuild the tsd.d.ts typings bundle (for the shell source).
 */
gulp.task("tsd:shell", function (cb) {

    // First reinstall any missing definitions to the typings directory.
    exec("tsd reinstall --config tsd-shell.json", function (err, stdout, stderr) {
        console.log(stdout);
        console.log(stderr);

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

        // Rebuild the src/shell/tsd.d.ts bundle reference file.
        exec("tsd rebundle --config tsd-shell.json", function (err, stdout, stderr) {
            console.log(stdout);
            console.log(stderr);
            cb(err);
        });
    });
});

/**
 * Uses the tsd command to restore TypeScript definitions to the typings
 * directory and rebuild the tsd.d.ts typings bundle (for the renderer source).
 */
gulp.task("tsd:renderer", function (cb) {

    // First reinstall any missing definitions to the typings directory.
    exec("tsd reinstall --config tsd-renderer.json", function (err, stdout, stderr) {
        console.log(stdout);
        console.log(stderr);

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

        // Rebuild the src/renderer/tsd.d.ts bundle reference file.
        exec("tsd rebundle --config tsd-renderer.json", function (err, stdout, stderr) {
            console.log(stdout);
            console.log(stderr);
            cb(err);
        });
    });
});

/**
 * Used to generate the app/build-vars.json file which contains information about
 * the build (such as version number, timestamp, and build scheme).
 *
 * The version number is taken from the config.xml file.
 */
gulp.task("ts:vars", function (cb) {

    var packageInfo = JSON.parse(fs.readFileSync("app/package.json", "utf8"));

    exec("git rev-parse --short HEAD", function (err, stdout, stderr) {

        var commitShortSha = err ? "unknown" : stdout.replace("\n", "");

        // Create the structure of the buildVars variable.
        var buildVars = {
            commitShortSha: commitShortSha,
            debug: isDebugScheme(),
            buildTimestamp: (new Date()).toUTCString(),
            version: packageInfo.version
        }

        // Serialize to JSON.
        var buildVarsJson = JSON.stringify(buildVars);

        // Write the file out to disk for the shell.
        fs.writeFileSync("app/build-vars.json", buildVarsJson, { encoding: "utf8" });

        cb();
    });
});

/**
 * Used to copy the entire TypeScript source into the app/www/js/src directory
 * so that it can be used for debugging purposes.
 *
 * This will only copy the files if the build scheme is not set to release.
 */
gulp.task("ts:src", ["ts:src-read-me"], function (cb) {

    if (!isDebugScheme()) {
        cb();
        return;
    }

    return gulp.src(paths.renderer_ts)
        .pipe(gulp.dest("app/www/js/src/renderer"));
});

/**
 * Used to add a readme file to app/src and www/js/app/src to explain what the
 * directories are for.
 *
 * This will only copy the files if the build scheme is not set to release.
 */
gulp.task("ts:src-read-me", function (cb) {

    if (!isDebugScheme()) {
        cb();
        return;
    }

    var infoMessage = "This directory contains a copy of the TypeScript source files for debug builds; it can be safely deleted and will be regenerated via the gulp ts task.\n\nTo omit this directory create a release build by specifying the scheme:\ngulp ts --scheme release";

    return string_src("readme.txt", infoMessage)
        .pipe(gulp.dest("app/www/js/src"));
});

/**
 * Used to perform compliation of the TypeScript source in the src directory and
 * output the JavaScript to the shell and renderer directories. Compilation parameters
 * are located in src/shell/tsconfig.json and src/renderer/tsconfig.json respectively.
 *
 * It will also delegate to the vars and src tasks to copy in the original source
 * which can be used for debugging purposes. This will only occur if the build scheme
 * is not set to release.
 */
gulp.task("ts", ["ts:vars", "ts:src"], function (cb) {
    exec("tsc -p src/shell", function (err1, stdout1, stderr1) {
        console.log(stdout1);
        console.log(stderr1);

        exec("tsc -p src/renderer", function (err2, stdout2, stderr2) {
            console.log(stdout2);
            console.log(stderr2);
            cb(err1 || err2);
        });
    });
});

/**
 * Used to concatenate all of the HTML templates into a single JavaScript module.
 */
gulp.task("templates", function() {
    return gulp.src(paths.templates)
        .pipe(templateCache({
            "filename": "templates.js",
            "root": "",
            "module": "templates",
            standalone: true
        }))
        .pipe(gulp.dest("./app/www/js"));
});

/**
 * Used to perform compilation of the SASS styles in the styles directory (using
 * Index.scss as the root file) and output the CSS to app/www/css/bundle.css.
 */
gulp.task("sass", function (cb) {

    var sassConfig = {
        outputStyle: isDebugScheme() ? "nested" : "compressed",
        errLogToConsole: false
    };

    return gulp.src(paths.sassIndex)
        .pipe(sourcemaps.init())
        .pipe(sass(sassConfig).on("error", sassReporter))
        .pipe(rename("bundle.css"))
        .pipe(sourcemaps.write("./"))
        .pipe(gulp.dest("./app/www/css"));
});

/**
 * Used to download all of the bower dependencies as defined in bower.json and place
 * the consumable pieces in the app/www/lib directory. Also runs an 'npm install' in
 * the app directory to download libraries specific to the shell source.
 */
gulp.task("libs", function(cb) {
    exec("bower-installer", function (err1, stdout1, stderr1) {
        console.log(stdout1);
        console.log(stderr1);

        exec("npm install", { cwd: "app" }, function (err2, stdout2, stderr2) {
            console.log(stdout2);
            console.log(stderr2);
            cb(err1 || err2);
        });
    });
});

/**
 * Uses electron-packager to package up the contents of the app directory with the Electron
 * runtime and place the output in the build directory. This currently assumes building for
 * the Windows platform and must be run on a Windows machine to properly edit the icon.
 */
gulp.task("package", ["default"], function (cb) {

    var packageInfo = JSON.parse(fs.readFileSync("app/package.json", "utf8"));

    var options = {
        dir: "app",
        platform: "win32",
        arch: "x64",
        icon: "app/icons/joystick.ico",
        name: packageInfo.name,
        "build-version": packageInfo.version,
        version: packageInfo.dependencies["electron-prebuilt"],
        out: "build",
        overwrite: true,
        "version-string": {
            FileDescription: packageInfo.name
        }
    };

    packager(options, cb);
});

/**
 * Used to perform a file clean-up of the project. This removes all files and directories
 * that don"t need to be committed to source control by delegating to several of the clean
 * sub-tasks.
 */
gulp.task("clean", ["clean:node", "clean:bower", "clean:libs", "clean:ts", "clean:tsd", "clean:templates", "clean:sass", "clean:package"]);

/**
 * Removes the node_modules directory.
 */
gulp.task("clean:node", function (cb) {
    del([
        "node_modules"
    ], cb);
});

/**
 * Removes the bower_components directory.
 */
gulp.task("clean:bower", function (cb) {
    del([
        "bower_components"
    ], cb);
});

/**
 * Removes the www/lib directory.
 */
gulp.task("clean:libs", function (cb) {
    del([
        "app/www/lib"
    ], cb);
});

/**
 * Removes files related to TypeScript compilation.
 */
gulp.task("clean:ts", function (cb) {
    del([
        "app/build-vars.json",
        "app/shell",

        "app/www/js/bundle.js",
        "app/www/js/bundle.js.map",
        "app/www/js/bundle.d.ts",
        "app/www/js/src"
    ], cb);
});

/**
 * Removes files related to TypeScript definitions.
 */
gulp.task("clean:tsd", function (cb) {

    // TODO: These patterns don't actually remove the sub-directories
    // located in the typings directories, they leave the directories
    // but remove the *.d.ts files. The following glob should work for
    // remove directories and preserving the custom directory, but they
    // don't for some reason and the custom directory is always removed:
    // "typings/**"
    // "!typings/custom/**"

    del([
        "src/shell/tsd.d.ts",
        "typings/shell/**/*.d.ts",
        "!typings/shell/custom/*.d.ts",
        // "typings/**",
        // "!typings/shell/custom/**",

        "src/renderer/tsd.d.ts",
        "typings/renderer/**/*.d.ts",
        "!typings/renderer/custom/*.d.ts",
        // "typings/**",
        // "!typings/custom/**",

    ], cb);
});

/**
 * Removes the generated templates JavaScript from the templates target.
 */
gulp.task("clean:templates", function (cb) {
    del([
        "www/js/templates.js"
    ]).then(function () {
        cb();
    });
});

/**
 * Removes the generated css from the SASS target.
 */
gulp.task("clean:sass", function (cb) {
    del([
        "app/www/css/bundle.css",
        "app/www/css/bundle.css.map"
    ], cb);
});

/**
 * Removes the generated build directory from the package target.
 */
gulp.task("clean:package", function (cb) {
    del([
        "build"
    ], cb);
});
<|endoftext|>


<commit_before>var gulp = require('gulp'),
    cleanhtml = require('gulp-cleanhtml'),
    csslint = require('gulp-csslint'),
    htmlhint = require('gulp-htmlhint'),
    jshint = require('gulp-jshint'),
    notify = require('gulp-notify'),
    plumber = require('gulp-plumber'),
    size = require('gulp-size'),
    uncss = require('gulp-uncss'),
    w3cjs = require('gulp-w3cjs'),
    gulputil = require('gulp-util'),
    stylestats = require('gulp-stylestats-report'),
    clean = require('gulp-clean'),
    cssValidation = require('gulp-css-validator');

var fs = require('fs'),
    mkdirp = require('mkdirp'),
    runSequence = require('run-sequence');

var reportsDir = './reports/json'

    //Individual Tasks

gulp.task('markymark', function() {
  var jsonReporter = function (file) {
    if (file && file.htmlhint) {
      fs.writeFileSync(reportsDir + '/htmlhint-' + file.path.split('/').pop().replace(/\.[^\.]+$/, '') + '.json', JSON.stringify(file.htmlhint, null, 2));
    }
  };

  return gulp.src('build/*.html')
    .pipe(plumber())
    .pipe(htmlhint())
    .pipe(htmlhint.reporter(jsonReporter))
    .pipe(notify("The Funky Bunch has hinted."));
});

gulp.task('wildstyle', function() {
  mkdirp(reportsDir);

  var jsonReporter = function (file) {
    if (file && file.csslint) {
      fs.writeFileSync(reportsDir + '/csshint-' + file.path.split('/').pop().replace(/\.[^\.]+$/, '') + '.json', JSON.stringify(file.csslint, null, 2));
    }
  };

  return gulp.src('build/css/*.css')
    .pipe(plumber())
    .pipe(csslint())
    .pipe(csslint.reporter(jsonReporter))
    .pipe(notify("All right, all right, all right! CSS busted"));
});

gulp.task('stylestats', function() {
  return gulp.src('build/css/*.css')
    .pipe(stylestats({reportDir: './reports/json'}))
    .pipe(notify("stylestats report generated."));
});

gulp.task('css-validation', function() {
  return gulp.src('build/css/*.css')
    .pipe(cssValidation());
});

gulp.task('validation', function() {
  return gulp.src('build/*.html')
    .pipe(w3cjs())
    .pipe(notify("Validation Complete!"));
});

gulp.task('uncss', function() {
  return gulp.src('build/css/*.css')
    .pipe(plumber())
    .pipe(uncss({
      html: ['build/index.html']
    }))
    .pipe(gulp.dest('build/linted/css'))
    .pipe(notify('Removed unused styles'));
});

gulp.task('cleanhtml', function() {
  return gulp.src('build/*.html')
    .pipe(plumber())
    .pipe(cleanhtml())
    .pipe(gulp.dest('build/linted'))
    .pipe(notify('Cleaned up html'));
});

gulp.task('size', function() {
  return gulp.src('build')
    .pipe(size(showFiles));
});

gulp.task('jshint', function() {
  var jsonReporter = function (results, data, s2) {
    var filename = results[0].file.split('/').pop().replace(/\.[^\.]+$/, '');
    var output = {
      results: results,
      data: data
    };

    fs.writeFileSync(reportsDir + '/jshint-' + filename + '.json', JSON.stringify(output, null, 2));
  };

  return gulp.src('build/js/*.js')
    .pipe(jshint('build/js/.jshintrc'))
    .pipe(jshint.reporter(jsonReporter))
    .pipe(notify('JS has been hinted'));
});

gulp.task('clean-reports', function () {
  return gulp.src('./reports/json')
    .pipe(clean());
});

gulp.task('reports-index', function (cb) {
  var reports = fs.readdirSync('./reports/json/');
  var output = {
    css: [],
    stylestats: [],
    html: [],
    js: []
  };

  for (var i = reports.length - 1; i >= 0; i--) {
    if (/^csshint/.test(reports[i])) output.css.push(reports[i]);
    if (/^jshint/.test(reports[i])) output.js.push(reports[i]);
    if (/^htmlhint/.test(reports[i])) output.html.push(reports[i]);
    if (/^stylestats/.test(reports[i])) output.stylestats.push(reports[i]);
  };

  fs.writeFileSync(reportsDir + '/index.json', JSON.stringify(output, null, 2));

  cb();
});

gulp.task('generate-reports', function (cb) {
  runSequence('clean-reports', 'css-validation', ['jshint', 'wildstyle', 'markymark', 'stylestats'], 'reports-index', cb);
});
<commit_msg>adds 'allow browser hacks'<commit_after>var gulp = require('gulp'),
    cleanhtml = require('gulp-cleanhtml'),
    csslint = require('gulp-csslint'),
    htmlhint = require('gulp-htmlhint'),
    jshint = require('gulp-jshint'),
    notify = require('gulp-notify'),
    plumber = require('gulp-plumber'),
    size = require('gulp-size'),
    uncss = require('gulp-uncss'),
    w3cjs = require('gulp-w3cjs'),
    gulputil = require('gulp-util'),
    stylestats = require('gulp-stylestats-report'),
    clean = require('gulp-clean'),
    cssValidation = require('gulp-css-validator');

var fs = require('fs'),
    mkdirp = require('mkdirp'),
    runSequence = require('run-sequence');

var reportsDir = './reports/json'

    //Individual Tasks

gulp.task('markymark', function() {
  var jsonReporter = function (file) {
    if (file && file.htmlhint) {
      fs.writeFileSync(reportsDir + '/htmlhint-' + file.path.split('/').pop().replace(/\.[^\.]+$/, '') + '.json', JSON.stringify(file.htmlhint, null, 2));
    }
  };

  return gulp.src('build/*.html')
    .pipe(plumber())
    .pipe(htmlhint())
    .pipe(htmlhint.reporter(jsonReporter))
    .pipe(notify("The Funky Bunch has hinted."));
});

gulp.task('wildstyle', function() {
  mkdirp(reportsDir);

  var jsonReporter = function (file) {
    if (file && file.csslint) {
      fs.writeFileSync(reportsDir + '/csshint-' + file.path.split('/').pop().replace(/\.[^\.]+$/, '') + '.json', JSON.stringify(file.csslint, null, 2));
    }
  };

  return gulp.src('build/css/*.css')
    .pipe(plumber())
    .pipe(csslint())
    .pipe(csslint.reporter(jsonReporter))
    .pipe(notify("All right, all right, all right! CSS busted"));
});

gulp.task('stylestats', function() {
  return gulp.src('build/css/*.css')
    .pipe(stylestats({reportDir: './reports/json'}))
    .pipe(notify("stylestats report generated."));
});

gulp.task('css-validation', function() {
  return gulp.src('build/css/*.css')
    .pipe(cssValidation({
      allowHacks: true
    }));
});

gulp.task('validation', function() {
  return gulp.src('build/*.html')
    .pipe(w3cjs())
    .pipe(notify("Validation Complete!"));
});

gulp.task('uncss', function() {
  return gulp.src('build/css/*.css')
    .pipe(plumber())
    .pipe(uncss({
      html: ['build/index.html']
    }))
    .pipe(gulp.dest('build/linted/css'))
    .pipe(notify('Removed unused styles'));
});

gulp.task('cleanhtml', function() {
  return gulp.src('build/*.html')
    .pipe(plumber())
    .pipe(cleanhtml())
    .pipe(gulp.dest('build/linted'))
    .pipe(notify('Cleaned up html'));
});

gulp.task('size', function() {
  return gulp.src('build')
    .pipe(size(showFiles));
});

gulp.task('jshint', function() {
  var jsonReporter = function (results, data, s2) {
    var filename = results[0].file.split('/').pop().replace(/\.[^\.]+$/, '');
    var output = {
      results: results,
      data: data
    };

    fs.writeFileSync(reportsDir + '/jshint-' + filename + '.json', JSON.stringify(output, null, 2));
  };

  return gulp.src('build/js/*.js')
    .pipe(jshint('build/js/.jshintrc'))
    .pipe(jshint.reporter(jsonReporter))
    .pipe(notify('JS has been hinted'));
});

gulp.task('clean-reports', function () {
  return gulp.src('./reports/json')
    .pipe(clean());
});

gulp.task('reports-index', function (cb) {
  var reports = fs.readdirSync('./reports/json/');
  var output = {
    css: [],
    stylestats: [],
    html: [],
    js: []
  };

  for (var i = reports.length - 1; i >= 0; i--) {
    if (/^csshint/.test(reports[i])) output.css.push(reports[i]);
    if (/^jshint/.test(reports[i])) output.js.push(reports[i]);
    if (/^htmlhint/.test(reports[i])) output.html.push(reports[i]);
    if (/^stylestats/.test(reports[i])) output.stylestats.push(reports[i]);
  };

  fs.writeFileSync(reportsDir + '/index.json', JSON.stringify(output, null, 2));

  cb();
});

gulp.task('generate-reports', function (cb) {
  runSequence('clean-reports', 'css-validation', ['jshint', 'wildstyle', 'markymark', 'stylestats'], 'reports-index', cb);
});
<|endoftext|>


<commit_before>var __testing_context__;

function defaultSubject(factory, options) {
  return factory.create(options);
}

export function moduleFor(fullName, description, callbacks, delegate) {
  callbacks = callbacks || { };

  var needs = [fullName].concat(callbacks.needs || []);
  var container = isolatedContainer(needs);

  callbacks.subject = callbacks.subject || defaultSubject;

  callbacks.setup    = callbacks.setup    || function() { };
  callbacks.teardown = callbacks.teardown || function() { };

  function factory() {
    return container.lookupFactory(fullName);
  }

  function subject(options) {
    return callbacks.subject(factory(), options);
  }

  __testing_context__ = {
    container: container,
    subject: subject,
    factory: factory,
    __setup_properties__: callbacks
  };

  if (delegate) {
    delegate(factory(), container, __testing_context__);
  }

  var context = __testing_context__;
  var _callbacks = {
    setup: function(){
      buildContextVariables(context);
      callbacks.setup.call(context, container);
    },
    teardown: function(){
      Ember.run(function(){
        container.destroy();
        // destroy all cached variables
      });

      Ember.$('#ember-testing').empty();
      // maybe destroy all the add-hoc objects

      callbacks.teardown(container);
    }
  };

  module(description, _callbacks);
}

// allow arbitrary named factories, like rspec let
function buildContextVariables(context) {
  var cache = { };
  var callbacks = context.__setup_properties__;
  var factory = context.factory;
  var container = context.container;

  Ember.keys(callbacks).filter(function(key){
    // ignore the default setup/teardown keys
    return key !== 'setup' && key && 'teardown';
  }).forEach(function(key){
    context[key] = function(options) {
      if (cache[key]) {
        return cache[key];
      }

      var result = callbacks[key](factory(), options, container);
      cache[key] = result;
      return result;
    };
  });
}

export function test(testName, callback) {
  var context = __testing_context__; // save refence

  function wrapper() {
    var result = callback.call(context);

    function failTestOnPromiseRejection(reason) {
      ok(false, reason);
    }

    Ember.run(function(){
      stop();
      Ember.RSVP.Promise.cast(result)['catch'](failTestOnPromiseRejection)['finally'](start);
    });
  }

  QUnit.test(testName, wrapper);
}

export function moduleForModel(name, description, callbacks) {
  moduleFor('model:' + name, description, callbacks, function(factory, container, context) {
    // custom model specific awesomeness
    container.register('store:main', DS.Store);
    container.register('adapter:application', DS.FixtureAdapter);

    context.__setup_properties__.store = function(){
      return container.lookup('store:main');
    };

    if (context.__setup_properties__.subject === defaultSubject) {
      context.__setup_properties__.subject = function(options) {
        return Ember.run(function() {
          return container.lookup('store:main').createRecord(name, options);
        });
      };
    }
  });
}

export function moduleForComponent(name, description, callbacks) {
  // just a spike...
  moduleFor('component:' + name, description, callbacks, function(factory, container, context) {

    context.__setup_properties__.$ = function(selector) {
      var view = Ember.run(function(){
        return context.subject().appendTo(Ember.$('#ember-testing')[0]);
      });

      return view.$();
    };
  });
}

<commit_msg>Fix bug in recently improved test helpers<commit_after>var __testing_context__;

function defaultSubject(factory, options) {
  return factory.create(options);
}

export function moduleFor(fullName, description, callbacks, delegate) {
  callbacks = callbacks || { };

  var needs = [fullName].concat(callbacks.needs || []);
  var container = isolatedContainer(needs);

  callbacks.subject = callbacks.subject || defaultSubject;

  callbacks.setup    = callbacks.setup    || function() { };
  callbacks.teardown = callbacks.teardown || function() { };

  function factory() {
    return container.lookupFactory(fullName);
  }

  function subject(options) {
    return callbacks.subject(factory(), options);
  }

  __testing_context__ = {
    container: container,
    subject: subject,
    factory: factory,
    __setup_properties__: callbacks
  };

  if (delegate) {
    delegate(factory(), container, __testing_context__);
  }

  var context = __testing_context__;
  var _callbacks = {
    setup: function(){
      buildContextVariables(context);
      callbacks.setup.call(context, container);
    },
    teardown: function(){
      Ember.run(function(){
        container.destroy();
        // destroy all cached variables
      });

      Ember.$('#ember-testing').empty();
      // maybe destroy all the add-hoc objects

      callbacks.teardown(container);
    }
  };

  module(description, _callbacks);
}

// allow arbitrary named factories, like rspec let
function buildContextVariables(context) {
  var cache = { };
  var callbacks = context.__setup_properties__;
  var factory = context.factory;
  var container = context.container;

  Ember.keys(callbacks).filter(function(key){
    // ignore the default setup/teardown keys
    return key !== 'setup' && key !== 'teardown';
  }).forEach(function(key){
    context[key] = function(options) {
      if (cache[key]) {
        return cache[key];
      }

      var result = callbacks[key](factory(), options, container);
      cache[key] = result;
      return result;
    };
  });
}

export function test(testName, callback) {
  var context = __testing_context__; // save refence

  function wrapper() {
    var result = callback.call(context);

    function failTestOnPromiseRejection(reason) {
      ok(false, reason);
    }

    Ember.run(function(){
      stop();
      Ember.RSVP.Promise.cast(result)['catch'](failTestOnPromiseRejection)['finally'](start);
    });
  }

  QUnit.test(testName, wrapper);
}

export function moduleForModel(name, description, callbacks) {
  moduleFor('model:' + name, description, callbacks, function(factory, container, context) {
    // custom model specific awesomeness
    container.register('store:main', DS.Store);
    container.register('adapter:application', DS.FixtureAdapter);

    context.__setup_properties__.store = function(){
      return container.lookup('store:main');
    };

    if (context.__setup_properties__.subject === defaultSubject) {
      context.__setup_properties__.subject = function(options) {
        return Ember.run(function() {
          return container.lookup('store:main').createRecord(name, options);
        });
      };
    }
  });
}

export function moduleForComponent(name, description, callbacks) {
  // just a spike...
  moduleFor('component:' + name, description, callbacks, function(factory, container, context) {

    context.__setup_properties__.$ = function(selector) {
      var view = Ember.run(function(){
        return context.subject().appendTo(Ember.$('#ember-testing')[0]);
      });

      return view.$();
    };
  });
}

<|endoftext|>


<commit_before>/* global require */
'use strict';

var gulp = require('gulp');
var rimraf = require('gulp-rimraf');
//var watch = require('gulp-watch')
var browserSync = require('browser-sync');
//var reload = browserSync.reload;
var concat = require("gulp-concat");
var babel = require("gulp-babel");
var sourcemaps = require("gulp-sourcemaps");
var uglify = require('gulp-uglify');
var cssmin = require('gulp-cssmin');
//var debug = require('gulp-debug');

var config = {
  entryFiles: [
    './src/components/map/core/init.js',
    './src/components/map/core/log.js',
    './src/components/utilities/polyfills.js',
    './src/components/utilities/general.js',
    './src/components/utilities/environment.js',
    './src/components/preloading/Preload.js',
    './src/components/map/core/utils/dataManipulation.js',
    './src/components/map/core/utils/effects.js',
    './src/components/map/core/utils/utils.js',
    './src/components/map/core/mapAPI.js',
    './src/components/map/core/mapEvents.js',
    './src/components/map/core/eventlisteners.js',
    './src/components/map/core/MapLayers.js',
    './src/components/map/core/MapDataManipulator.js',
    './src/components/map/core/UI.js',
    './src/components/map/core/ObjectManager.js',
    './src/components/map/core/Objects.js',
    './src/components/map/core/Sound.js',
    './src/components/map/core/mapStates.js',
    './src/components/map/core/UI.js',
    './src/components/map/core/UITemplateBase.js',
    './src/components/map/core/baseEventlisteners/*.js',
    './src/components/map/core/move/*.js',
    './src/components/map/core/zoom/*.js',
    './src/components/map/extensions/basicActions/*.js',
    './src/components/map/extensions/hexagons/init.js',
    './src/components/map/extensions/hexagons/utils/hexagonMath.js',
    './src/components/map/extensions/hexagons/utils/createHexagon.js',
    './src/components/map/extensions/hexagons/eventListeners/*.js',
    './src/components/map/extensions/hexagons/*.js',
    './src/components/map/extensions/mapMovement/mapMovement.js',
    './src/components/map/UIs/default/init.js',
    './src/components/map/UIs/default/utils/*.js',
    './src/components/map/UIs/default/layout/*.js',
    './src/components/map/UIs/default/default.js',
    './src/components/map/core/Flatworld.js',
    './src/factories/*.js'],
  cssFiles: ['./src/assets/lib/pace/css/loadingBar.css'],
  outputDir: './dist/',
  outputDirDev: './src/dist/',
  outputFile: 'flatworld.js'
};

gulp.task('deploy', ['clean', 'bundleLib', 'bundleCss', 'bundleProd']);

gulp.task('build', ['cleanDev', 'bundleLibDev', 'bundleCssDev', 'bundleDev']);

gulp.task('bundleProd', function() {
  return gulp.src(config.entryFiles)
    .pipe(sourcemaps.init())
    .pipe(babel())
    .pipe(uglify())
    .pipe(concat('flatworld.min.js'))
    .pipe(sourcemaps.write("."))
    .pipe(gulp.dest(config.outputDir));
});

gulp.task('bundleLib', function() {
  return gulp.src('./src/assets/lib/**/*.js', { base: './src/assets/lib/' })
    .pipe(concat('flatworld_libraries.js'))
    .pipe(gulp.dest(config.outputDir));
});

gulp.task('bundleLibDev', function() {
  return gulp.src('./src/assets/lib/**/*.js', { base: './src/assets/lib/' })
    .pipe(concat('flatworld_libraries.js'))
    .pipe(gulp.dest(config.outputDirDev));
});

gulp.task('bundleDev', function() {
  return gulp.src(config.entryFiles)
    .pipe(sourcemaps.init())
    .pipe(babel())
    .pipe(uglify())
    .pipe(concat('flatworld.js'))
    .pipe(sourcemaps.write("."))
    .pipe(gulp.dest(config.outputDirDev));
});

gulp.task('watch', function() {
  return gulp.watch(config.entryFiles, ['bundleDev']);
});

gulp.task('cleanDev', function(){
  return rimraf(config.outputDirDev);
});

gulp.task('clean', function(){
  return rimraf(config.outputDir);
});

gulp.task('bundleCss', function () {
  return gulp.src(config.cssFiles)
    .pipe(cssmin())
    .pipe(concat('flatworld.css'))
    .pipe(gulp.dest(config.outputDir + "css/"));
});

gulp.task('bundleCssDev', function () {
  return gulp.src(config.cssFiles)
    .pipe(concat('flatworld.css'))
    .pipe(gulp.dest(config.outputDirDev + "css/"));
});

gulp.task('develope', ['build', 'watch'], function() {
  return browserSync({
    server: {
      baseDir: './src/'
    },
    startPath: "tests/manualStressTest.html"
  });
});

gulp.task('default', ['deploy', 'build']);<commit_msg>sourcemaps were not working with gulp-uglify with present system, even though uglify should be supported<commit_after>/* global require */
'use strict';

var gulp = require('gulp');
var rimraf = require('gulp-rimraf');
//var watch = require('gulp-watch')
var browserSync = require('browser-sync');
//var reload = browserSync.reload;
var concat = require("gulp-concat");
var babel = require("gulp-babel");
var sourcemaps = require("gulp-sourcemaps");
var uglify = require('gulp-uglify');
var cssmin = require('gulp-cssmin');
//var debug = require('gulp-debug');

var config = {
  entryFiles: [
    './src/components/map/core/init.js',
    './src/components/map/core/log.js',
    './src/components/utilities/polyfills.js',
    './src/components/utilities/general.js',
    './src/components/utilities/environment.js',
    './src/components/preloading/Preload.js',
    './src/components/map/core/utils/dataManipulation.js',
    './src/components/map/core/utils/effects.js',
    './src/components/map/core/utils/utils.js',
    './src/components/map/core/mapAPI.js',
    './src/components/map/core/mapEvents.js',
    './src/components/map/core/eventlisteners.js',
    './src/components/map/core/MapLayers.js',
    './src/components/map/core/MapDataManipulator.js',
    './src/components/map/core/UI.js',
    './src/components/map/core/ObjectManager.js',
    './src/components/map/core/Objects.js',
    './src/components/map/core/Sound.js',
    './src/components/map/core/mapStates.js',
    './src/components/map/core/UI.js',
    './src/components/map/core/UITemplateBase.js',
    './src/components/map/core/baseEventlisteners/*.js',
    './src/components/map/core/move/*.js',
    './src/components/map/core/zoom/*.js',
    './src/components/map/extensions/basicActions/*.js',
    './src/components/map/extensions/hexagons/init.js',
    './src/components/map/extensions/hexagons/utils/hexagonMath.js',
    './src/components/map/extensions/hexagons/utils/createHexagon.js',
    './src/components/map/extensions/hexagons/eventListeners/*.js',
    './src/components/map/extensions/hexagons/*.js',
    './src/components/map/extensions/mapMovement/mapMovement.js',
    './src/components/map/UIs/default/init.js',
    './src/components/map/UIs/default/utils/*.js',
    './src/components/map/UIs/default/layout/*.js',
    './src/components/map/UIs/default/default.js',
    './src/components/map/core/Flatworld.js',
    './src/factories/*.js'],
  cssFiles: ['./src/assets/lib/pace/css/loadingBar.css'],
  outputDir: './dist/',
  outputDirDev: './src/dist/',
  outputFile: 'flatworld.js'
};

gulp.task('deploy', ['clean', 'bundleLib', 'bundleCss', 'bundleProd']);

gulp.task('build', ['cleanDev', 'bundleLibDev', 'bundleCssDev', 'bundleDev']);

gulp.task('bundleProd', function() {
  return gulp.src(config.entryFiles)
    .pipe(babel())
    .pipe(uglify())
    .pipe(concat('flatworld.min.js'))
    .pipe(gulp.dest(config.outputDir));
});

gulp.task('bundleLib', function() {
  return gulp.src('./src/assets/lib/**/*.js', { base: './src/assets/lib/' })
    .pipe(concat('flatworld_libraries.js'))
    .pipe(gulp.dest(config.outputDir));
});

gulp.task('bundleLibDev', function() {
  return gulp.src('./src/assets/lib/**/*.js', { base: './src/assets/lib/' })
    .pipe(concat('flatworld_libraries.js'))
    .pipe(gulp.dest(config.outputDirDev));
});

gulp.task('bundleDev', function() {
  return gulp.src(config.entryFiles)
    .pipe(sourcemaps.init({ debug: true }))
    .pipe(babel())
    .pipe(concat('flatworld.js'))
    .pipe(sourcemaps.write("./maps"))
    .pipe(gulp.dest(config.outputDirDev));
});

gulp.task('watch', function() {
  return gulp.watch(config.entryFiles, ['bundleDev']);
});

gulp.task('cleanDev', function(){
  return rimraf(config.outputDirDev);
});

gulp.task('clean', function(){
  return rimraf(config.outputDir);
});

gulp.task('bundleCss', function () {
  return gulp.src(config.cssFiles)
    .pipe(cssmin())
    .pipe(concat('flatworld.css'))
    .pipe(gulp.dest(config.outputDir + "css/"));
});

gulp.task('bundleCssDev', function () {
  return gulp.src(config.cssFiles)
    .pipe(concat('flatworld.css'))
    .pipe(gulp.dest(config.outputDirDev + "css/"));
});

gulp.task('develope', ['build', 'watch'], function() {
  return browserSync({
    server: {
      baseDir: './src/'
    },
    startPath: "tests/manualStressTest.html"
  });
});

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


<commit_before>'use strict';

//inspired by the gulpfile.js from https://github.com/martinmicunda/employee-scheduling-ui

//use babel transpiler for ES6 files in node without needing --harmony nor a gulpfile.babel.js
require('babel/register');

// require all tasks
require('require-dir')('./gulp/tasks', { recurse: true });

/**
 * Load required dependencies.
 */
var pkg = require('./package.json');
var del = require('del');
var gulp = require('gulp');
var modRewrite = require('connect-modrewrite');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');
var paths = require('./gulp/paths');

/**
 * Load Gulp plugins listed in 'package.json' and attaches
 * them to the `$` variable.
 */
var $ = require('gulp-load-plugins')();

//=============================================
//            DECLARE VARIABLES
//=============================================

var log = $.util.log;
var argv = $.util.env;
var ENV = !!argv.env ? argv.env : 'dev';
var COLORS = $.util.colors;

//=============================================
//               SUB TASKS
//=============================================

//=============================================
//                MAIN TASKS
//=============================================

//---------------------------------------------
//              DEVELOPMENT TASKS
//---------------------------------------------

gulp.task('default', ['serve']);<commit_msg>refactor(gulpfile) cleanup unnecessary code<commit_after>'use strict';

//inspired by the gulpfile.js from https://github.com/martinmicunda/employee-scheduling-ui

//use babel transpiler for ES6 files in node without needing --harmony nor a gulpfile.babel.js
require('babel/register');

// require all tasks
require('require-dir')('./gulp/tasks', { recurse: true });

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


<commit_before>// gulpfile.js
// gulp configuration for sfuco-site
// Reference: https://github.com/shakyShane/jekyll-gulp-sass-browser-sync
// Author: Reinier Evangelista
// 2017

var gulp = require('gulp');

var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync');
var cp = require('child_process');
var concat = require('gulp-concat');
var gutil = require('gulp-util');
var sass = require('gulp-sass');

var jekyll   = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
var messages = {
    jekyllBuild: 'Running: $ jekyll build'
  };

// Build jekyll
gulp.task('jekyll-build', function(done) {
  browserSync.notify(messages.jekyllBuild);
  return cp.spawn(jekyll, ['build'],
    {stdio: 'inherit'})
    .on('close', done);
});

// Rebuild Jekyll/Page reload
gulp.task('jekyll-rebuild', ['jekyll-build'], function() {
    browserSync.reload();
  });

gulp.task('browser-sync', ['build-css', 'jekyll-build'], function() {
  browserSync({server: {baseDir: '_site/'}});
});

// SASS compilation
gulp.task('build-css', function() {
  console.log('--Building CSS--');
  return gulp.src('./_sass/**/*.scss')
  .pipe(sass().on('error', sass.logError))
  .pipe(autoprefixer({browsers: ['last 2 versions'], cascade: false}))
  .pipe(concat('style.css')) // Concatenate into one CSS file
  .pipe(gulp.dest('./_site/css')) // Note: The destination has to be _site/css since that's the live css
  .pipe(browserSync.reload({stream: true}))
  .pipe(gulp.dest('css'));
});

// Watch Tasks
gulp.task('watch', function() {
  gulp.watch('./_sass/**/*.scss', ['build-css']);
  gulp.watch(['*.html', '_layouts/*.html', '_includes/*.html', '_posts/*',
   '_pages/*', 'js/*'],
  ['jekyll-rebuild']);
  gulp.watch(['./*.yml'], ['jekyll-rebuild']);
});

// Default Task
gulp.task('default', ['browser-sync', 'watch']);
<commit_msg>turn off browsersync notifications<commit_after>// gulpfile.js
// gulp configuration for sfuco-site
// Reference: https://github.com/shakyShane/jekyll-gulp-sass-browser-sync
// Author: Reinier Evangelista
// 2017

var gulp = require('gulp');

var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync');
var cp = require('child_process');
var concat = require('gulp-concat');
var gutil = require('gulp-util');
var sass = require('gulp-sass');

var jekyll   = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
var messages = {
    jekyllBuild: 'Running: $ jekyll build'
  };

// Build jekyll
gulp.task('jekyll-build', function(done) {
  browserSync.notify(messages.jekyllBuild);
  return cp.spawn(jekyll, ['build'],
    {stdio: 'inherit'})
    .on('close', done);
});

// Rebuild Jekyll/Page reload
gulp.task('jekyll-rebuild', ['jekyll-build'], function() {
    browserSync.reload();
  });

gulp.task('browser-sync', ['build-css', 'jekyll-build'], function() {
  browserSync({server: {baseDir: '_site/'}, notify: false});
});

// SASS compilation
gulp.task('build-css', function() {
  console.log('--Building CSS--');
  return gulp.src('./_sass/**/*.scss')
  .pipe(sass().on('error', sass.logError))
  .pipe(autoprefixer({browsers: ['last 2 versions'], cascade: false}))
  .pipe(concat('style.css')) // Concatenate into one CSS file
  .pipe(gulp.dest('./_site/css')) // Note: The destination has to be _site/css since that's the live css
  .pipe(browserSync.reload({stream: true}))
  .pipe(gulp.dest('css'));
});

// Watch Tasks
gulp.task('watch', function() {
  gulp.watch('./_sass/**/*.scss', ['build-css']);
  gulp.watch(['*.html', '_layouts/*.html', '_includes/*.html', '_posts/*',
   '_pages/*', 'js/*'],
  ['jekyll-rebuild']);
  gulp.watch(['./*.yml'], ['jekyll-rebuild']);
});

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


<commit_before>'use strict';

var gulp = require('gulp');

// Workaround for eslint bad object-assign version
Object.assign = require('object-assign');

var helper = {
    plugins: {},
    getPlugin: function (name) {
        var plugin = this.plugins[name];
        if (!plugin) {
            plugin = require(name);
            this.plugins[name] = plugin;
        }
        return plugin;
    }
};
var pkg = require('./package.json');

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

gulp.task('clean', function (done) {
    var del = helper.getPlugin('del');
    del(['coverage', 'tmp'], function (err) {
        done(err);
    });
});

gulp.task('build', ['clean', 'eslint', 'coverage'], function () {
});

gulp.task('dist', ['build'], function () {
});

gulp.task('doc', ['mddoc'], function () {
});

gulp.task('eslint', function () {
    var eslint = helper.getPlugin('gulp-eslint');
    return gulp.src(['index.js', 'gulpfile.js', 'make', 'lib/**/*.js', 'test/**/*.js'])
        .pipe(eslint())
        .pipe(eslint.format())
        .pipe(eslint.failOnError());
});

gulp.task('test', function () {
    return gulp.src('test/**/*.spec.js', {read: false})
        .pipe(helper.getPlugin('gulp-mocha')({slow: 200}));
});

gulp.task('coverage', ['clean'], function (done) {
    process.env.COVERAGE = true;
    var mocha = helper.getPlugin('gulp-mocha');
    var istanbul = helper.getPlugin('gulp-istanbul');
    gulp.src(['lib/**/*.js', 'index.js'])
        .pipe(istanbul()) // Covering files
        .pipe(istanbul.hookRequire()) // Force `require` to return covered files
        .on('finish', function () {
            gulp.src('test/**/*.spec.js', {read: false})
                .pipe(mocha({slow: 200}))
                .pipe(istanbul.writeReports({})) // Creating the reports after tests runned
                .on('end', done);
        });
});

gulp.task('mddoc', ['eslint'], function () {
    var gutil = helper.getPlugin('gulp-util');
    var gulpJsdoc2md = helper.getPlugin('gulp-jsdoc-to-markdown');
    var concat = helper.getPlugin('gulp-concat');

    return gulp.src(['index.js', 'lib/**/*.js'])
        .pipe(concat('API.md'))
        .pipe(gulpJsdoc2md())
        .on('error', function (err) {
            gutil.log('jsdoc2md failed:', err.message);
        })
        .pipe(gulp.dest(''));
});
<commit_msg>removing pkg from gulpfile<commit_after>'use strict';

var gulp = require('gulp');

// Workaround for eslint bad object-assign version
Object.assign = require('object-assign');

var helper = {
    plugins: {},
    getPlugin: function (name) {
        var plugin = this.plugins[name];
        if (!plugin) {
            plugin = require(name);
            this.plugins[name] = plugin;
        }
        return plugin;
    }
};

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

gulp.task('clean', function (done) {
    var del = helper.getPlugin('del');
    del(['coverage', 'tmp'], function (err) {
        done(err);
    });
});

gulp.task('build', ['clean', 'eslint', 'coverage'], function () {
});

gulp.task('dist', ['build'], function () {
});

gulp.task('doc', ['mddoc'], function () {
});

gulp.task('eslint', function () {
    var eslint = helper.getPlugin('gulp-eslint');
    return gulp.src(['index.js', 'gulpfile.js', 'make', 'lib/**/*.js', 'test/**/*.js'])
        .pipe(eslint())
        .pipe(eslint.format())
        .pipe(eslint.failOnError());
});

gulp.task('test', function () {
    return gulp.src('test/**/*.spec.js', {read: false})
        .pipe(helper.getPlugin('gulp-mocha')({slow: 200}));
});

gulp.task('coverage', ['clean'], function (done) {
    process.env.COVERAGE = true;
    var mocha = helper.getPlugin('gulp-mocha');
    var istanbul = helper.getPlugin('gulp-istanbul');
    gulp.src(['lib/**/*.js', 'index.js'])
        .pipe(istanbul()) // Covering files
        .pipe(istanbul.hookRequire()) // Force `require` to return covered files
        .on('finish', function () {
            gulp.src('test/**/*.spec.js', {read: false})
                .pipe(mocha({slow: 200}))
                .pipe(istanbul.writeReports({})) // Creating the reports after tests runned
                .on('end', done);
        });
});

gulp.task('mddoc', ['eslint'], function () {
    var gutil = helper.getPlugin('gulp-util');
    var gulpJsdoc2md = helper.getPlugin('gulp-jsdoc-to-markdown');
    var concat = helper.getPlugin('gulp-concat');

    return gulp.src(['index.js', 'lib/**/*.js'])
        .pipe(concat('API.md'))
        .pipe(gulpJsdoc2md())
        .on('error', function (err) {
            gutil.log('jsdoc2md failed:', err.message);
        })
        .pipe(gulp.dest(''));
});
<|endoftext|>


<commit_before>"use strict"

// -- DEPENDENCIES -------------------------------------------------------------
var gulp    = require('gulp');
var coffee  = require('gulp-coffee');
var concat  = require('gulp-concat');
var connect = require('gulp-connect');
var header  = require('gulp-header');
var jasmine = require('gulp-jasmine');
// var jasmine = require('gulp-jasmine2-phantomjs');
var uglify  = require('gulp-uglify');
var gutil   = require('gulp-util');
var stylus  = require('gulp-stylus');
var pkg     = require('./package.json');

// -- FILES --------------------------------------------------------------------
var path = {
  // Exports
  bower: './bower',
  temp : './build',
  // Sources
  quojs: ['quojs/source/quo.coffee',
          'quojs/source/quo.ajax.coffee',
          'quojs/source/quo.css.coffee',
          'quojs/source/quo.element.coffee',
          'quojs/source/quo.environment.coffee',
          'quojs/source/quo.events.coffee',
          'quojs/source/quo.gestures.coffee',
          'quojs/source/quo.gestures.*.coffee',
          'quojs/source/quo.output.coffee',
          'quojs/source/quo.query.coffee'],
  core : ['source/*.coffee', 'source/core/*.coffee', 'source/class/*.coffee'],
  spec : ['spec/*.coffee']};

var app = {
  coffee    : ['extensions/app/*.coffee',
               'extensions/app/atom/*.coffee',
               'extensions/app/molecule/*.coffee',
               'extensions/app/organism/*.coffee'],
  stylus    : ['extensions/app/style/*.styl'],
  theme     : ['extensions/app/theme/*.styl'],
  extensions: ['extensions/app/extension/**/*.coffee',
               'extensions/app/extension/**/*.styl'],
  docs      : ['extensions/app/docs/**/*'],
  example   : ['extensions/test/source/**/*.coffee']};

var extensions = {
  carousel: 'extensions/app/extension/carousel/',
  chart   : 'extensions/app/extension/chart/',
  gmaps   : 'extensions/app/extension/gmaps/',
  leaflet : 'extensions/app/extension/leaflet/',
  stripe  : 'extensions/app/extension/stripe/'};

var appnima = {
  payment: 'extensions/app/extension/appnima/payment',
  user   : 'extensions/app/extension/appnima/user'
};

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

// -- TASKS --------------------------------------------------------------------
gulp.task('webserver', function() {
    connect.server({
      port      : 8000,
      // root      : 'extensions/test',
      livereload: true
    });
});

gulp.task('core', function() {
  gulp.src(path.quojs.concat(path.core))
    .pipe(concat('atoms.coffee'))
    .pipe(coffee().on('error', gutil.log))
    .pipe(gulp.dest(path.temp))
    .pipe(uglify({mangle: true}))
    .pipe(header(banner, {pkg: pkg}))
    .pipe(gulp.dest(path.bower))
    .pipe(connect.reload())

  gulp.src(path.core)
    .pipe(concat('atoms.standalone.coffee'))
    .pipe(coffee().on('error', gutil.log))
    .pipe(gulp.dest(path.temp))
    .pipe(uglify({mangle: true}))
    .pipe(header(banner, {pkg: pkg}))
    .pipe(gulp.dest(path.bower))
});

gulp.task('spec', function() {
  gulp.src(path.spec)
    .pipe(concat('atoms.spec.coffee'))
    .pipe(coffee().on('error', gutil.log))
    .pipe(gulp.dest(path.temp))

  var spec = [
    'spec/components/quojs/quo.js',
    'build/atoms.standalone.js',
    'build/atoms.spec.js'];

  // gulp.src(spec)
  //   .pipe(jasmine())
});

gulp.task('app_coffee', function() {
  gulp.src(app.coffee)
    .pipe(concat('atoms.app.coffee'))
    .pipe(coffee().on('error', gutil.log))
    .pipe(uglify({mangle: false}))
    .pipe(header(banner, {pkg: pkg}))
    .pipe(gulp.dest(path.bower))
});

gulp.task('app_stylus', function() {
  gulp.src(app.stylus)
    .pipe(concat('atoms.app.styl'))
    .pipe(stylus({compress: true, errors: true}))
    .pipe(header(banner, {pkg: pkg}))
    .pipe(gulp.dest(path.bower));
});

gulp.task('app_theme', function() {
  gulp.src(app.theme)
    .pipe(concat('atoms.app.theme.styl'))
    .pipe(stylus({compress: true, errors: true}))
    .pipe(header(banner, {pkg: pkg}))
    .pipe(gulp.dest(path.bower));
});

gulp.task('extensions', function() {
  var key, folder;

  for (key in extensions) {
    folder = extensions[key];

    gulp.src(folder + "**/*.coffee")
      .pipe(concat('atoms.app.' + key + '.coffee'))
      .pipe(coffee().on('error', gutil.log))
      .pipe(uglify({mangle: false}))
      .pipe(gulp.dest(folder));

    gulp.src(folder + "style/*.styl")
      .pipe(concat('atoms.app.' + key + '.styl'))
      .pipe(stylus({compress: true}))
      .pipe(gulp.dest(folder));
  }
});

gulp.task('docs', function() {
  gulp.src(app.docs)
    .pipe(gulp.dest(path.bower + "/docs"));
});

gulp.task('example', function() {
  gulp.src(app.example)
    .pipe(concat('atoms.app.example.coffee'))
    .pipe(coffee().on('error', gutil.log))
    .pipe(gulp.dest(path.temp))
    .pipe(connect.reload())
});

gulp.task('init', function() {
  gulp.run(['core', 'app_coffee', 'app_stylus', 'app_theme', 'extensions', 'docs', 'example']);
});

gulp.task('default', function() {
  gulp.run(['webserver'])
  gulp.watch(path.core, ['core', 'spec']);
  gulp.watch(path.quojs, ['core', 'spec']);
  gulp.watch(app.coffee, ['app_coffee']);
  gulp.watch(app.stylus, ['app_stylus']);
  gulp.watch(app.theme, ['app_theme']);
  gulp.watch(app.extensions, ['extensions']);
  gulp.watch(app.docs, ['docs']);
  gulp.watch(app.example, ['example']);
});
<commit_msg>Change gulpfile to compile appnima.extensions<commit_after>"use strict"

// -- DEPENDENCIES -------------------------------------------------------------
var gulp    = require('gulp');
var coffee  = require('gulp-coffee');
var concat  = require('gulp-concat');
var connect = require('gulp-connect');
var header  = require('gulp-header');
var jasmine = require('gulp-jasmine');
// var jasmine = require('gulp-jasmine2-phantomjs');
var uglify  = require('gulp-uglify');
var gutil   = require('gulp-util');
var stylus  = require('gulp-stylus');
var pkg     = require('./package.json');

// -- FILES --------------------------------------------------------------------
var path = {
  // Exports
  bower: './bower',
  temp : './build',
  // Sources
  quojs: ['quojs/source/quo.coffee',
          'quojs/source/quo.ajax.coffee',
          'quojs/source/quo.css.coffee',
          'quojs/source/quo.element.coffee',
          'quojs/source/quo.environment.coffee',
          'quojs/source/quo.events.coffee',
          'quojs/source/quo.gestures.coffee',
          'quojs/source/quo.gestures.*.coffee',
          'quojs/source/quo.output.coffee',
          'quojs/source/quo.query.coffee'],
  core : ['source/*.coffee', 'source/core/*.coffee', 'source/class/*.coffee'],
  spec : ['spec/*.coffee']};

var app = {
  coffee    : ['extensions/app/*.coffee',
               'extensions/app/atom/*.coffee',
               'extensions/app/molecule/*.coffee',
               'extensions/app/organism/*.coffee'],
  stylus    : ['extensions/app/style/*.styl'],
  theme     : ['extensions/app/theme/*.styl'],
  extensions: ['extensions/app/extension/**/*.coffee',
               'extensions/app/extension/**/*.styl'],
  docs      : ['extensions/app/docs/**/*'],
  example   : ['extensions/test/source/**/*.coffee']};

var extensions = {
  carousel: 'extensions/app/extension/carousel/',
  chart   : 'extensions/app/extension/chart/',
  gmaps   : 'extensions/app/extension/gmaps/',
  leaflet : 'extensions/app/extension/leaflet/',
  stripe  : 'extensions/app/extension/stripe/'};

var appnima = {
  payment: 'extensions/app/extension/appnima/payment/',
  user   : 'extensions/app/extension/appnima/user/'
};

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

// -- TASKS --------------------------------------------------------------------
gulp.task('webserver', function() {
    connect.server({
      port      : 8000,
      // root      : 'extensions/test',
      livereload: true
    });
});

gulp.task('core', function() {
  gulp.src(path.quojs.concat(path.core))
    .pipe(concat('atoms.coffee'))
    .pipe(coffee().on('error', gutil.log))
    .pipe(gulp.dest(path.temp))
    .pipe(uglify({mangle: true}))
    .pipe(header(banner, {pkg: pkg}))
    .pipe(gulp.dest(path.bower))
    .pipe(connect.reload())

  gulp.src(path.core)
    .pipe(concat('atoms.standalone.coffee'))
    .pipe(coffee().on('error', gutil.log))
    .pipe(gulp.dest(path.temp))
    .pipe(uglify({mangle: true}))
    .pipe(header(banner, {pkg: pkg}))
    .pipe(gulp.dest(path.bower))
});

gulp.task('spec', function() {
  gulp.src(path.spec)
    .pipe(concat('atoms.spec.coffee'))
    .pipe(coffee().on('error', gutil.log))
    .pipe(gulp.dest(path.temp))

  var spec = [
    'spec/components/quojs/quo.js',
    'build/atoms.standalone.js',
    'build/atoms.spec.js'];

  // gulp.src(spec)
  //   .pipe(jasmine())
});

gulp.task('app_coffee', function() {
  gulp.src(app.coffee)
    .pipe(concat('atoms.app.coffee'))
    .pipe(coffee().on('error', gutil.log))
    .pipe(uglify({mangle: false}))
    .pipe(header(banner, {pkg: pkg}))
    .pipe(gulp.dest(path.bower))
});

gulp.task('app_stylus', function() {
  gulp.src(app.stylus)
    .pipe(concat('atoms.app.styl'))
    .pipe(stylus({compress: true, errors: true}))
    .pipe(header(banner, {pkg: pkg}))
    .pipe(gulp.dest(path.bower));
});

gulp.task('app_theme', function() {
  gulp.src(app.theme)
    .pipe(concat('atoms.app.theme.styl'))
    .pipe(stylus({compress: true, errors: true}))
    .pipe(header(banner, {pkg: pkg}))
    .pipe(gulp.dest(path.bower));
});

gulp.task('extensions', function() {
  var key, folder;

  var process = function(key, folder, file) {
    gulp.src(folder + "**/*.coffee")
      .pipe(concat(file + key + '.coffee'))
      .pipe(coffee().on('error', gutil.log))
      .pipe(uglify({mangle: false}))
      .pipe(gulp.dest(folder));

    gulp.src(folder + "style/*.styl")
      .pipe(concat(file + key + '.styl'))
      .pipe(stylus({compress: true}))
      .pipe(gulp.dest(folder))
      .pipe(connect.reload());
  }

  for (key in extensions) {
    process(key, extensions[key], 'atoms.app.')
  };

  for (key in appnima) {
    process(key, appnima[key], 'atoms.app.appnima.')
  };
});

gulp.task('docs', function() {
  gulp.src(app.docs)
    .pipe(gulp.dest(path.bower + "/docs"));
});

gulp.task('example', function() {
  gulp.src(app.example)
    .pipe(concat('atoms.app.example.coffee'))
    .pipe(coffee().on('error', gutil.log))
    .pipe(gulp.dest(path.temp))
    .pipe(connect.reload())
});

gulp.task('init', function() {
  gulp.run(['core', 'app_coffee', 'app_stylus', 'app_theme', 'extensions', 'docs', 'example']);
});

gulp.task('default', function() {
  gulp.run(['webserver'])
  gulp.watch(path.core, ['core', 'spec']);
  gulp.watch(path.quojs, ['core', 'spec']);
  gulp.watch(app.coffee, ['app_coffee']);
  gulp.watch(app.stylus, ['app_stylus']);
  gulp.watch(app.theme, ['app_theme']);
  gulp.watch(app.extensions, ['extensions']);
  gulp.watch(app.docs, ['docs']);
  gulp.watch(app.example, ['example']);
});
<|endoftext|>


<commit_before>var gulp = require('gulp');
var webpack = require('gulp-webpack');
var named = require('vinyl-named');
var connect = require('gulp-connect');
var uglify = require('gulp-uglify');

gulp.task('connect', function(){
	connect.server({
		root: './src',
		port: 8080,
		livereload: true
	});
});

var appList = ['app', 'router'];

gulp.task('bundle', function(){
	return gulp.src(mapFiles(appList, 'js'))
				.pipe(named())
				.pipe(webpack({
					module: {
						loaders: [{
							test: /\.vue$/,
							loader: 'vue'
						}, {
							test: /\.(png|jpg)$/,
							loader: 'url'
						}]
					},
					watch: true
				}))
				// .pipe(uglify())
        		.pipe(gulp.dest('src/lib/'))
				.pipe(connect.reload());
});

gulp.task('uglify', function() {
    return gulp.src(['src/lib/js/fastclick.js'])
    .pipe(uglify())
    .pipe(gulp.dest('src/lib/js/*.min.js'));
});

function mapFiles(list, extname) {
	return list.map(function (app){
		return 'src/' + app + '.' + extname;
	});
};

gulp.task('default', ['bundle', 'connect']);
<commit_msg>cancel uglify<commit_after>var gulp = require('gulp');
var webpack = require('gulp-webpack');
var named = require('vinyl-named');
var connect = require('gulp-connect');
var uglify = require('gulp-uglify');

gulp.task('connect', function(){
	connect.server({
		root: './src',
		port: 8080,
		livereload: true
	});
});

var appList = ['app', 'router'];

gulp.task('bundle', function(){
	return gulp.src(mapFiles(appList, 'js'))
				.pipe(named())
				.pipe(webpack({
					module: {
						loaders: [{
							test: /\.vue$/,
							loader: 'vue'
						}, {
							test: /\.(png|jpg)$/,
							loader: 'url'
						}]
					},
					watch: true
				}))
				.pipe(uglify())
        		.pipe(gulp.dest('src/lib/'))
				.pipe(connect.reload());
});

gulp.task('uglify', function() {
    return gulp.src(['src/lib/js/fastclick.js'])
    .pipe(uglify())
    .pipe(gulp.dest('src/lib/js/*.min.js'));
});

function mapFiles(list, extname) {
	return list.map(function (app){
		return 'src/' + app + '.' + extname;
	});
};

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


<commit_before>'use strict';

var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var stringify = require('stringify');
var del = require('del');
var inline = require('gulp-inline');
var minifyInline = require('gulp-minify-inline');
var minifyHTML = require('gulp-minify-html');
var sass = require('gulp-sass');
var sourceMaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');

gulp.task('clean-js', function() {
  return del(['tmp/config-page.js']);
});

gulp.task('js', ['clean-js'], function() {
  return browserify('src/scripts/config-page.js', { debug: true })
    .transform(stringify(['.html', '.tpl']))
    .transform('deamdify')
    .bundle()
    .pipe(source('config-page.js'))
    .pipe(gulp.dest('./tmp/'));
});

gulp.task('clean-sass', function() {
  return del(['tmp/config-page.scss']);
});
gulp.task('sass', ['clean-sass'], function() {
  gulp.src('./src/styles/config-page.scss')
    .pipe(sourceMaps.init())
    .pipe(sass().on('error', sass.logError))
    .pipe(autoprefixer({
      browsers: ['Android 4', 'iOS 8'],
      cascade: false
    }))
    .pipe(sourceMaps.write('./'))
    .pipe(gulp.dest('tmp'));
});

gulp.task('inlineHtml', ['js', 'sass'], function() {
  return gulp.src('src/config-page.html')
    .pipe(inline())
    .pipe(minifyInline({
      js: {},
      jsSelector: 'script[uglify]'
    }))
    .pipe(minifyHTML())
    .pipe(gulp.dest('tmp/'));
});

gulp.task('clay', ['inlineHtml'], function() {
  return browserify('index.js', { debug: false })
    .transform(stringify(['.html', '.tpl']))
    .require(require.resolve('./index'), {expose: 'pebble-clay'})
    .bundle()
    .pipe(source('clay.js'))
    .pipe(gulp.dest('./dist/'));
});

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

gulp.task('dev', ['js', 'sass'], function() {

  gulp.watch('src/styles/**/*.scss', ['sass']);
  gulp.watch(['src/scripts/**/*.js', 'src/templates/**/*.tpl'], ['js']);

  return browserify('dev/dev.js', { debug: true })
    .bundle()
    .pipe(source('dev.js'))
    .pipe(gulp.dest('./tmp/'));
});
<commit_msg>add watcher for dev folder<commit_after>'use strict';

var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var stringify = require('stringify');
var del = require('del');
var inline = require('gulp-inline');
var minifyInline = require('gulp-minify-inline');
var minifyHTML = require('gulp-minify-html');
var sass = require('gulp-sass');
var sourceMaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');

gulp.task('clean-js', function() {
  return del(['tmp/config-page.js']);
});

gulp.task('js', ['clean-js'], function() {
  return browserify('src/scripts/config-page.js', { debug: true })
    .transform(stringify(['.html', '.tpl']))
    .transform('deamdify')
    .bundle()
    .pipe(source('config-page.js'))
    .pipe(gulp.dest('./tmp/'));
});

gulp.task('clean-sass', function() {
  return del(['tmp/config-page.scss']);
});
gulp.task('sass', ['clean-sass'], function() {
  gulp.src('./src/styles/config-page.scss')
    .pipe(sourceMaps.init())
    .pipe(sass().on('error', sass.logError))
    .pipe(autoprefixer({
      browsers: ['Android 4', 'iOS 8'],
      cascade: false
    }))
    .pipe(sourceMaps.write('./'))
    .pipe(gulp.dest('tmp'));
});

gulp.task('inlineHtml', ['js', 'sass'], function() {
  return gulp.src('src/config-page.html')
    .pipe(inline())
    .pipe(minifyInline({
      js: {},
      jsSelector: 'script[uglify]'
    }))
    .pipe(minifyHTML())
    .pipe(gulp.dest('tmp/'));
});

gulp.task('clay', ['inlineHtml'], function() {
  return browserify('index.js', { debug: false })
    .transform(stringify(['.html', '.tpl']))
    .require(require.resolve('./index'), {expose: 'pebble-clay'})
    .bundle()
    .pipe(source('clay.js'))
    .pipe(gulp.dest('./dist/'));
});

gulp.task('dev-js', ['js', 'sass'], function() {
  return browserify('dev/dev.js', { debug: true })
    .bundle()
    .pipe(source('dev.js'))
    .pipe(gulp.dest('./tmp/'));
});

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

gulp.task('dev', ['dev-js'], function() {
  gulp.watch('src/styles/**/*.scss', ['sass']);
  gulp.watch(['src/scripts/**/*.js', 'src/templates/**/*.tpl'], ['js']);
  gulp.watch(['dev/**/*.js'], ['dev-js']);
});
<|endoftext|>