<commit_before>'use strict';
var gulp,
    Config,
    tsc,
    srcmaps,
    showtasks,
    del,
    config,
    indent,
    concat,
    minify,
    beautify,
    tsconfig,
    pkg,
    serve,
    tsd,
    tslint,
    libname,
    browsersync;

/*
 * module loading start
 */

// the base module for gulp build files:
gulp = require('gulp');

// a file that contains the project's layout:
Config = require('./gulpfile.config');

// the typescript compiler
tsc = require('gulp-typescript');

// module for generating source maps linking (unminified/unuglified) typescript
// to the JavaScript (helpful in debugging)
srcmaps = require('gulp-sourcemaps');

// a module that lets you print the available tasks from this file at the
// command line
showtasks = require('gulp-task-listing');

// a module that lets you delete files and directories
del = require('del');

// a module that lets you concatenate files
concat = require('gulp-concat');

// a module that lets you minify files, including file name mangling
minify = require('gulp-minify');

// a module that is able to parse the tsconfig file into a JavaScript object
tsconfig = require('tsconfig');

// a module that lets you read in the contents of package.json, such as the
// package name and version
pkg = require('./package.json');

// webserver
serve = require('gulp-serve');

// this module lets you get TypeScript Definitions/typings from DefinitelyTyped
tsd = require('gulp-tsd');

// this module lets you lint the typescript code according to the rules from
tslint = require('gulp-tslint'),

// use browser-sync for reloading
browsersync = require('browser-sync');
var reload = browsersync.reload;

libname = pkg.name + '-' + pkg.version + '.js';

/*
 * module loading end
 */

// make a new configuration instance:
config = new Config();

// the indent size for gulp's command line stdout
indent = '           ';

/*
 *
 * from here on, it's just task definitions
 * (you can get a list by entering
 * gulp tasks
 * at the command line)
 *
 */

gulp.watch([
    'src/**/*.ts',
    'src/**/*.css'
]).on('change', reload);

gulp.task('assemble',['_copyhtml', '_copycss', '_minify'],function() {

    process.stdout.write(indent + 'TODO: Errors may arise due to the order in which JS files were concatenated.' + '\n');

});

gulp.task('build',['_transpile'],function() {

});

gulp.task('checkout',['clean'],function() {

    process.stdout.write(indent + 'See https://www.npmjs.com/package/del' + '\n');
    return del(['node_modules']).then(function(paths) {
        if (paths.length === 0) {
            process.stdout.write(indent + 'Nothing to clean.\n');
        }
        else {
            process.stdout.write(indent + 'Deleted files and folders:' + '\n');
            for (var path of paths) {
                process.stdout.write(indent + path + '\n');
            }
        };
    });

});

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

    process.stdout.write(indent + 'See https://www.npmjs.com/package/del' + '\n');
    return del([config.build, config.dist, config.typings]).then(function(paths) {
        if (paths.length === 0) {
            process.stdout.write(indent + 'Nothing to clean.\n');
        }
        else {
            // (you need console.log here for some reason)
            process.stdout.write(indent + 'Deleted files and folders:' + '\n');
            for (var path of paths) {
                process.stdout.write(indent + path + '\n');
            }
        };
    });

});

gulp.task('_concatenate', ['build'], function() {

    process.stdout.write(indent + 'See https://www.npmjs.com/package/gulp-concat'  + '\n');
    var s,
        d;

    // take all unminified js sources from build
    s = [config.build + '**/' + config.alljs, '!' + config.build + '**/' + config.allminjs];
    d = config.dist;

    return gulp.src(s)
        .pipe(concat(libname))
        .pipe(gulp.dest(d));

});

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

    var s,
        d;

    s = config.build + '**/' + config.allcss;
    d = config.dist;

    return gulp.src(s).pipe(gulp.dest(d));

});

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

    var s,
        d;

    s = config.build + config.allhtml;
    d = config.dist;

    return gulp.src(s).pipe(gulp.dest(d));

});

gulp.task('default',['assemble'],function() {
    // set default as an alias for assemble
});

// (for some reason, showtasks does not work when it's inside a function)
// process.stdout.write(indent + 'See https://www.npmjs.com/package/gulp-task-listing'  + '\n');
gulp.task('help', showtasks.withFilters(/^[_]{1}/gi) );

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

    process.stdout.write(indent + 'See https://www.npmjs.com/package/tslint'  + '\n');

    var s = config.src + 'ts/' + config.allts;

    return gulp.src(s)
        .pipe(tslint())
        .pipe(tslint.report('verbose'));

});

gulp.task('_minify',['_concatenate'],function() {

    process.stdout.write(indent + 'See https://www.npmjs.com/package/gulp-minify'  + '\n');

    var s,
        d;

    s = config.dist + libname;
    d = config.dist;

    return gulp.src(s)
        .pipe(minify({
            ignoreFiles: ['-min.js'],
            mangle: true
        }))
        .pipe(gulp.dest(d));

});

gulp.task('_tsd', function (callback) {
    tsd({
        command: 'reinstall',
        config: './tsd.json'
    }, callback);
});

gulp.task('serve-build', serve({
    root: config.build,
    port: 8087
}));

gulp.task('serve-dist', serve({
    root: config.dist,
    port: 8088
}));

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

    process.stdout.write('Configuration from ./gulpfile.config.js: '  + '\n');
    process.stdout.write(config);
});

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

    var s,
        d;

    s = config.src + '**/*';
    d = config.build;

    return gulp.src(s, {base: config.src}).pipe(gulp.dest(d));

});

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

    process.stdout.write('test: not yet implemented.'  + '\n');

});

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

    process.stdout.write(indent + 'See https://www.npmjs.com/package/gulp-task-listing'  + '\n');
    showtasks();

});

gulp.task('_transpile',['_srctobuild','_tsd', '_tslint'],function() {

    process.stdout.write(indent + 'See https://www.npmjs.com/package/tsconfig'  + '\n');
    process.stdout.write(indent + 'See https://www.npmjs.com/package/gulp-typescript'  + '\n');
    process.stdout.write(indent + 'See https://www.npmjs.com/package/gulp-sourcemaps'  + '\n');

    var tsconfDir,
        tsconfFile,
        tsconfObj,
        s,
        d,
        tscResult,
        options;

    // the location of the directory that holds tsconfig.json
    tsconfDir = config.build + 'ts/';

    // let the tsconfig module find the tsconfig file in tsconfDir
    tsconfFile = tsconfig.resolveSync(tsconfDir);

    // provide feedback on which file we are using
    process.stdout.write(indent + 'Using file: ' + tsconfFile + '\n');

    // parse the tsconfig file into an object
    tsconfObj = tsconfig.readFileSync(tsconfFile);

    // define the gulp-typescript options
    options = tsconfObj.compilerOptions;

    // source map generation is not supported by gulp-typescript, so we will use
    // gulp-sourcemaps instead. I'm setting the sourceMap option to false here,
    // in order to be more explicit about what we do.
    options.sourceMap = false;

    // define the sources that you want gulp-typescript to compile
    s = tsconfObj.files;

    d = config.build + 'ts/';

    tscResult = gulp.src(s)       // Take the TypeScript sources...
        .pipe(srcmaps.init())     // generate source maps (in memory)...
        .pipe(tsc(options));      // transpile the TypeScript into JavaScript (in memory)

    return tscResult.js           // Take the JavaScript that was just generated...
        .pipe(srcmaps.write('.')) // write the source maps next to where the JavaScript will be...
        .pipe(gulp.dest(d));      // write the JavaScript files.

});

<commit_msg>Use help package<commit_after>'use strict';
var gulp,
    help,
    Config,
    tsc,
    srcmaps,
    showtasks,
    del,
    config,
    indent,
    concat,
    minify,
    beautify,
    tsconfig,
    pkg,
    serve,
    tsd,
    tslint,
    libname,
    browsersync;

/*
 * module loading start
 */

// the base module for gulp build files:
gulp = require('gulp-help')(require('gulp'));

// a file that contains the project's layout:
Config = require('./gulpfile.config');

// the typescript compiler
tsc = require('gulp-typescript');

// module for generating source maps linking (unminified/unuglified) typescript
// to the JavaScript (helpful in debugging)
srcmaps = require('gulp-sourcemaps');

// a module that lets you print the available tasks from this file at the
// command line
showtasks = require('gulp-task-listing');

// a module that lets you delete files and directories
del = require('del');

// a module that lets you concatenate files
concat = require('gulp-concat');

// a module that lets you minify files, including file name mangling
minify = require('gulp-minify');

// a module that is able to parse the tsconfig file into a JavaScript object
tsconfig = require('tsconfig');

// a module that lets you read in the contents of package.json, such as the
// package name and version
pkg = require('./package.json');

// webserver
serve = require('gulp-serve');

// this module lets you get TypeScript Definitions/typings from DefinitelyTyped
tsd = require('gulp-tsd');

// this module lets you lint the typescript code according to the rules from
tslint = require('gulp-tslint'),

// use browser-sync for reloading
browsersync = require('browser-sync');
var reload = browsersync.reload;

libname = pkg.name + '-' + pkg.version + '.js';

/*
 * module loading end
 */

// make a new configuration instance:
config = new Config();

// the indent size for gulp's command line stdout
indent = '           ';

/*
 *
 * from here on, it's just task definitions
 * (you can get a list by entering
 * gulp tasks
 * at the command line)
 *
 */

gulp.watch([
    'src/**/*.ts',
    'src/**/*.css'
]).on('change', reload);

gulp.task('assemble',['_copyhtml', '_copycss', '_minify'],function() {

    process.stdout.write(indent + 'TODO: Errors may arise due to the order in which JS files were concatenated.' + '\n');

});

gulp.task('build',['_transpile'],function() {

});

gulp.task('checkout',['clean'],function() {

    process.stdout.write(indent + 'See https://www.npmjs.com/package/del' + '\n');
    return del(['node_modules']).then(function(paths) {
        if (paths.length === 0) {
            process.stdout.write(indent + 'Nothing to clean.\n');
        }
        else {
            process.stdout.write(indent + 'Deleted files and folders:' + '\n');
            for (var path of paths) {
                process.stdout.write(indent + path + '\n');
            }
        };
    });

});

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

    process.stdout.write(indent + 'See https://www.npmjs.com/package/del' + '\n');
    return del([config.build, config.dist, config.typings]).then(function(paths) {
        if (paths.length === 0) {
            process.stdout.write(indent + 'Nothing to clean.\n');
        }
        else {
            // (you need console.log here for some reason)
            process.stdout.write(indent + 'Deleted files and folders:' + '\n');
            for (var path of paths) {
                process.stdout.write(indent + path + '\n');
            }
        };
    });

});

gulp.task('_concatenate', ['build'], function() {

    process.stdout.write(indent + 'See https://www.npmjs.com/package/gulp-concat'  + '\n');
    var s,
        d;

    // take all unminified js sources from build
    s = [config.build + '**/' + config.alljs, '!' + config.build + '**/' + config.allminjs];
    d = config.dist;

    return gulp.src(s)
        .pipe(concat(libname))
        .pipe(gulp.dest(d));

});

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

    var s,
        d;

    s = config.build + '**/' + config.allcss;
    d = config.dist;

    return gulp.src(s).pipe(gulp.dest(d));

});

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

    var s,
        d;

    s = config.build + config.allhtml;
    d = config.dist;

    return gulp.src(s).pipe(gulp.dest(d));

});

gulp.task('default',['assemble'],function() {
    // set default as an alias for assemble
});

// (for some reason, showtasks does not work when it's inside a function)
// process.stdout.write(indent + 'See https://www.npmjs.com/package/gulp-task-listing'  + '\n');
gulp.task('help', showtasks.withFilters(/^[_]{1}/gi) );

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

    process.stdout.write(indent + 'See https://www.npmjs.com/package/tslint'  + '\n');

    var s = config.src + 'ts/' + config.allts;

    return gulp.src(s)
        .pipe(tslint())
        .pipe(tslint.report('verbose'));

});

gulp.task('_minify',['_concatenate'],function() {

    process.stdout.write(indent + 'See https://www.npmjs.com/package/gulp-minify'  + '\n');

    var s,
        d;

    s = config.dist + libname;
    d = config.dist;

    return gulp.src(s)
        .pipe(minify({
            ignoreFiles: ['-min.js'],
            mangle: true
        }))
        .pipe(gulp.dest(d));

});

gulp.task('_tsd', function (callback) {
    tsd({
        command: 'reinstall',
        config: './tsd.json'
    }, callback);
});

gulp.task('serve-build', serve({
    root: config.build,
    port: 8087
}));

gulp.task('serve-dist', serve({
    root: config.dist,
    port: 8088
}));

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

    process.stdout.write('Configuration from ./gulpfile.config.js: '  + '\n');
    process.stdout.write(config);
});

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

    var s,
        d;

    s = config.src + '**/*';
    d = config.build;

    return gulp.src(s, {base: config.src}).pipe(gulp.dest(d));

});

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

    process.stdout.write('test: not yet implemented.'  + '\n');

});

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

    process.stdout.write(indent + 'See https://www.npmjs.com/package/gulp-task-listing'  + '\n');
    showtasks();

});

gulp.task('_transpile',['_srctobuild','_tsd', '_tslint'],function() {

    process.stdout.write(indent + 'See https://www.npmjs.com/package/tsconfig'  + '\n');
    process.stdout.write(indent + 'See https://www.npmjs.com/package/gulp-typescript'  + '\n');
    process.stdout.write(indent + 'See https://www.npmjs.com/package/gulp-sourcemaps'  + '\n');

    var tsconfDir,
        tsconfFile,
        tsconfObj,
        s,
        d,
        tscResult,
        options;

    // the location of the directory that holds tsconfig.json
    tsconfDir = config.build + 'ts/';

    // let the tsconfig module find the tsconfig file in tsconfDir
    tsconfFile = tsconfig.resolveSync(tsconfDir);

    // provide feedback on which file we are using
    process.stdout.write(indent + 'Using file: ' + tsconfFile + '\n');

    // parse the tsconfig file into an object
    tsconfObj = tsconfig.readFileSync(tsconfFile);

    // define the gulp-typescript options
    options = tsconfObj.compilerOptions;

    // source map generation is not supported by gulp-typescript, so we will use
    // gulp-sourcemaps instead. I'm setting the sourceMap option to false here,
    // in order to be more explicit about what we do.
    options.sourceMap = false;

    // define the sources that you want gulp-typescript to compile
    s = tsconfObj.files;

    d = config.build + 'ts/';

    tscResult = gulp.src(s)       // Take the TypeScript sources...
        .pipe(srcmaps.init())     // generate source maps (in memory)...
        .pipe(tsc(options));      // transpile the TypeScript into JavaScript (in memory)

    return tscResult.js           // Take the JavaScript that was just generated...
        .pipe(srcmaps.write('.')) // write the source maps next to where the JavaScript will be...
        .pipe(gulp.dest(d));      // write the JavaScript files.

});

<|endoftext|>


<commit_before>const gulp = require('gulp');
const rename = require("gulp-rename");
const replace = require("gulp-replace");
const ts = require('gulp-typescript');
const concat = require('gulp-concat');
const fs = require('fs');
const sourcemaps = require('gulp-sourcemaps');
const runSequence = require('run-sequence');
const bump = require('gulp-bump');
const child_process = require('child_process');
const spawn = child_process.spawn;
let projectTypings = ts.createProject('src/tsconfig.json');
let projectCommonjs = ts.createProject('src/tsconfig.json', {
    target: "es6",
});

gulp.task("publish", function(done) {
    runSequence('dist', 'increment-version', "commit-release", 'npm-publish', done);
})

gulp.task('increment-version', function() {
    return gulp.src('./package.json')
        .pipe(bump())
        .pipe(gulp.dest('./'));
});
gulp.task('commit-release', function(done) {
    let json = JSON.parse(fs.readFileSync(__dirname + "/package.json").toString());
    child_process.exec(`git add .; git commit -m "Release ${json.version}" -a; git tag v${json.version}; git push origin master --tags`, (error, stdout, stderr) => {
        if (error) {
            console.error(`exec error: ${error}`);
            return;
        }
        console.log(`stdout: ${stdout}`);
        console.log(`stderr: ${stderr}`);
        done();
    });
});
gulp.task('npm-publish', function(done) {
    var publish = spawn('npm', ['publish'], {
        stdio: 'inherit'
    })
    publish.on('close', function(code) {
        if (code === 8) {
            gulp.log('Error detected, waiting for changes...');
        }
        done()
    });
});
gulp.task("commit", ["dist"], function() {
    const readline = require('readline');

    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });

    rl.question('What are the updates? ', (text) => {
        // TODO: Log the answer in a database
        child_process.exec(`git add .; git commit -m "${text}" -a; git push origin master`, (error, stdout, stderr) => {
            if (error) {
                console.error(`exec error: ${error}`);
                return;
            }
            console.log(`stdout: ${stdout}`);
            console.log(`stderr: ${stderr}`);
            done();
        });

        rl.close();
    });
});

gulp.task("dist-typings", () => {
    let result = gulp.src('src/**/*.ts')
        .pipe(projectTypings());
    return result.dts.pipe(gulp.dest('dist/typings'));
});

gulp.task("dist-commonjs", () => {
    let result = gulp.src('src/**/*.ts')
        .pipe(sourcemaps.init())
        .pipe(projectCommonjs());
    return result.js.pipe(gulp.dest('dist/commonjs'));
});

gulp.task("test-build", ["build"], () => {
    return runSequence("webpack")
});

gulp.task('build', function() {
    let result = gulp.src('src/**/*.ts')
        .pipe(sourcemaps.init())
        .pipe(projectCommonjs());
    return result.js.pipe(gulp.dest('build/commonjs'));
});

let node;

gulp.task('hello', function() {
    if (node) node.kill()
    node = spawn('node', ['hello.js'], {
        stdio: 'inherit'
    })
    node.on('close', function(code) {
        if (code === 8) {
            gulp.log('Error detected, waiting for changes...');
        }
    });
});

gulp.task('watch', ['build'], function() {
    gulp.watch(['assets/**/*.js'], () => {
        runSequence('hello');
    });

    gulp.watch(['src/**/*.ts'], () => {
        runSequence('build');
    });
});

gulp.task('dist', ['dist-typings', 'dist-commonjs'], function() {

});<commit_msg>test gulp commit<commit_after>const gulp = require('gulp');
const rename = require("gulp-rename");
const replace = require("gulp-replace");
const ts = require('gulp-typescript');
const concat = require('gulp-concat');
const fs = require('fs');
const sourcemaps = require('gulp-sourcemaps');
const runSequence = require('run-sequence');
const bump = require('gulp-bump');
const child_process = require('child_process');
const spawn = child_process.spawn;
let projectTypings = ts.createProject('src/tsconfig.json');
let projectCommonjs = ts.createProject('src/tsconfig.json', {
    target: "es6",
});

gulp.task("publish", function(done) {
    runSequence('dist', 'increment-version', "commit-release", 'npm-publish', done);
})

gulp.task('increment-version', function() {
    return gulp.src('./package.json')
        .pipe(bump())
        .pipe(gulp.dest('./'));
});
gulp.task('commit-release', function(done) {
    let json = JSON.parse(fs.readFileSync(__dirname + "/package.json").toString());
    child_process.exec(`git add .; git commit -m "Release ${json.version}" -a; git tag v${json.version}; git push origin master --tags`, (error, stdout, stderr) => {
        if (error) {
            console.error(`exec error: ${error}`);
            return;
        }
        console.log(`stdout: ${stdout}`);
        console.log(`stderr: ${stderr}`);
        done();
    });
});
gulp.task('npm-publish', function(done) {
    var publish = spawn('npm', ['publish'], {
        stdio: 'inherit'
    })
    publish.on('close', function(code) {
        if (code === 8) {
            gulp.log('Error detected, waiting for changes...');
        }
        done()
    });
});
gulp.task("commit", ["dist"], function(done) {
    const readline = require('readline');

    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });

    rl.question('What are the updates? ', (text) => {
        // TODO: Log the answer in a database
        child_process.exec(`git add .; git commit -m "${text}" -a; git push origin master`, (error, stdout, stderr) => {
            if (error) {
                console.error(`exec error: ${error}`);
                return;
            }
            console.log(`stdout: ${stdout}`);
            console.log(`stderr: ${stderr}`);
            done();
        });

        rl.close();
    });
});

gulp.task("dist-typings", () => {
    let result = gulp.src('src/**/*.ts')
        .pipe(projectTypings());
    return result.dts.pipe(gulp.dest('dist/typings'));
});

gulp.task("dist-commonjs", () => {
    let result = gulp.src('src/**/*.ts')
        .pipe(sourcemaps.init())
        .pipe(projectCommonjs());
    return result.js.pipe(gulp.dest('dist/commonjs'));
});

gulp.task("test-build", ["build"], () => {
    return runSequence("webpack")
});

gulp.task('build', function() {
    let result = gulp.src('src/**/*.ts')
        .pipe(sourcemaps.init())
        .pipe(projectCommonjs());
    return result.js.pipe(gulp.dest('build/commonjs'));
});

let node;

gulp.task('hello', function() {
    if (node) node.kill()
    node = spawn('node', ['hello.js'], {
        stdio: 'inherit'
    })
    node.on('close', function(code) {
        if (code === 8) {
            gulp.log('Error detected, waiting for changes...');
        }
    });
});

gulp.task('watch', ['build'], function() {
    gulp.watch(['assets/**/*.js'], () => {
        runSequence('hello');
    });

    gulp.watch(['src/**/*.ts'], () => {
        runSequence('build');
    });
});

gulp.task('dist', ['dist-typings', 'dist-commonjs'], function() {

});<|endoftext|>


<commit_before>var gulp = require('gulp');
var path = require('path');
var tap = require('gulp-tap');
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var replace = require('gulp-replace');
var inject = require('gulp-inject');
var zip = require('gulp-zip');
var mocha = require('gulp-mocha');
var child_process = require('child_process');
var fs = require('fs');
var htmlmin = require('gulp-htmlmin');
var cssmin = require('gulp-cssmin');
var shell = require('gulp-shell');
var jshint = require('gulp-jshint');
var jshStylish = require('jshint-stylish');
var exec = require('child_process').exec;
var docsConf = require('./documentation/docmaker.json');
var runSequence = require('run-sequence');

var version; // used for marking builds w/ version etc

var paths = {
  sources: [
    'src/preamble.js',
    'src/namespace.js',
    'src/is.js',
    'src/util.js',
    'src/math.js',
    'src/instance-registration.js',
    'src/extension.js',
    'src/jquery-plugin.js',
    'src/event.js',
    'src/define.js',
    'src/selector.js',
    'src/style.js',
    'src/style-*.js',
    'src/core.js',
    'src/core-*.js',
    'src/collection.js',
    'src/collection-*.js',
    'src/heap.js',
    'src/extensions/renderer.canvas.define-and-init-etc.js',
    'src/extensions/renderer.canvas.*.js',
    'src/extensions/*.js'
  ],

  docs: {
    js: [
      'documentation/js/fastclick.js',
      'documentation/js/jquery.js',
      'documentation/js/cytoscape.js',
      'documentation/js/load.js',
      'documentation/js/script.js'
    ],

    css: [
      'documentation/css/reset.css',
      'documentation/css/font-awesome.css',
      'documentation/css/highlight/github.css',
      'documentation/css/style.css'
    ]
  }
};

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

});

gulp.task('version', function( next ){
  var now = new Date();
  version = process.env['VERSION'];

  if( version ){
    done();
  } else {
    exec('git rev-parse HEAD', function( error, stdout, stderr ){
      var sha = stdout.substring(0, 10); // shorten so not huge filename

      version = [ 'snapshot', sha, +now ].join('-');
      done();
    });
  }

  function done(){
    console.log('Using version number `%s` for building', version);
    next();
  }

});

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

gulp.task('concat', ['version'], function(){
  return gulp.src( paths.sources )
    .pipe( replace('{{VERSION}}', version) )

    .pipe( concat('cytoscape.js') )

    .pipe( gulp.dest('build') )
  ;
});

gulp.task('build', ['version'], function(){
  return gulp.src( paths.sources )
    .pipe( replace('{{VERSION}}', version) )

    .pipe( concat('cytoscape.js') )

    .pipe( gulp.dest('build') )

    .pipe( uglify({
      mangle: true,

      preserveComments: 'some'
    }) )

    .pipe( concat('cytoscape.min.js') )

    .pipe( gulp.dest('build') )
  ;
});

gulp.task('debugrefs', function(){
  return gulp.src('debug/index.html')
    .pipe( inject( gulp.src(paths.sources, { read: false }), {
      addPrefix: '..',
      addRootSlash: false
    } ) )

    .pipe( gulp.dest('debug') )
  ;
});

gulp.task('testrefs', function(){
  return gulp.src('test/index.html')
    .pipe( inject( gulp.src(paths.sources, { read: false }), {
      addPrefix: '..',
      addRootSlash: false
    } ) )

    .pipe( gulp.dest('test') )
  ;
});

gulp.task('testlist', function(){
  return gulp.src('test/index.html')
    .pipe( inject( gulp.src('test/*.js', { read: false }), {
      addPrefix: '',
      ignorePath: 'test',
      addRootSlash: false,
      starttag: '<!-- inject:test:{{ext}} -->'
    } ) )

    .pipe( gulp.dest('test') )
  ;
});

gulp.task('refs', ['debugrefs', 'testrefs', 'testlist'], function(next){
  next();
});

gulp.task('zip', ['version', 'build'], function(){
  return gulp.src(['build/cytoscape.js', 'build/cytoscape.min.js', 'LGPL-LICENSE.txt', 'lib/arbor.js'])
    .pipe( zip('cytoscape.js-' + version + '.zip') )

    .pipe( gulp.dest('build') )
  ;
});

gulp.task('test', ['concat'], function(){
  return gulp.src('test/*.js')
    .pipe( mocha({
      reporter: 'spec'
    }) )
  ;
});

gulp.task('docsver', ['version'], function(){
  return gulp.src('documentation/docmaker.json')
    .pipe( replace(/\"version\"\:\s*\".*?\"/, '"version": "' + version + '"') )

    .pipe( gulp.dest('documentation') )
  ;
});

gulp.task('docsjs', ['version', 'build'], function(){
  return gulp.src([
    'build/cytoscape.js',
    'build/cytoscape.min.js',
    'lib/arbor.js'
  ])
    .pipe( gulp.dest('documentation/js') )

    .pipe( gulp.dest('documentation/api/cytoscape.js-' + version) )

    .pipe( gulp.dest('documentation/api/cytoscape.js-latest') )
  ;
});

gulp.task('docsdl', ['version', 'zip'], function(){
  return gulp.src('build/cytoscape.js-' + version + '.zip')
    .pipe( gulp.dest('documentation/download') )
  ;
});

gulp.task('docsbuildlist', ['docsdl'], function(next){
  var cwd = process.cwd();

  process.chdir('./documentation/download');
  require('./documentation/download/dlmaker')(function(){
    process.chdir( cwd );

    next();
  });

});

gulp.task('snapshotpush', ['docsbuildlist'], shell.task([
  './publish-buildlist.sh'
]));

gulp.task('docs', function(next){
  var cwd = process.cwd();

  process.chdir('./documentation');
  require('./documentation/docmaker')( function(){
    process.chdir( cwd );

    next();
  } );

});

gulp.task('docsmin', ['docshtmlmin'], function(next){
  next();
});

gulp.task('docsclean', function(next){
  return gulp.src(['documentation/js/all.min.js', 'documentation/css/all.min.css', 'documentation/index.html'])
    .pipe( clean({ read: false }) )
  ;
});

gulp.task('docshtmlmin', ['docsminrefs'], function(){
  return gulp.src('documentation/index.html')
    .pipe( htmlmin({
      collapseWhitespace: true,
      keepClosingSlash: true
    }) )

    .pipe( gulp.dest('documentation') )
  ;
});

gulp.task('docsjsmin', ['docs'], function(){
  return gulp.src( paths.docs.js )
    .pipe( concat('all.min.js') )

    .pipe( uglify({
      mangle: true
    }) )

    .pipe( gulp.dest('documentation/js') )
  ;
});

gulp.task('docscssmin', ['docs'], function(){
  return gulp.src( paths.docs.css )
    .pipe( concat('all.min.css') )

    .pipe( cssmin() )

    .pipe( gulp.dest('documentation/css') )
  ;
});

gulp.task('docsminrefs', ['docscssmin', 'docsjsmin'], function(){
  return gulp.src('documentation/index.html')
    .pipe( inject( gulp.src([ 'documentation/js/all.min.js', 'documentation/css/all.min.css' ], { read: false }), {
      addRootSlash: false,
      ignorePath: 'documentation'
    } ) )

    .pipe( gulp.dest('documentation') )
  ;
});

gulp.task('docsrefs', function(){
  return gulp.src([ 'documentation/index.html', 'documentation/template.html' ])
    .pipe( inject( gulp.src(paths.docs.js.concat( paths.docs.css ), { read: false }), {
      addRootSlash: false,
      ignorePath: 'documentation'
    } ) )

    .pipe( gulp.dest('documentation') )
  ;
});

gulp.task('docsdemoshots', function(next){
  var cwd = process.cwd();

  process.chdir('./documentation');
  require('./documentation/demoshots')( function(){
    process.chdir( cwd );

    next();
  } );
});

gulp.task('docspub', function(next){
  runSequence( ['version', 'docsver', 'docsjs', 'docsbuildlist'], 'docsdemoshots', 'docsmin', next );
});

gulp.task('pkgver', function(){
  return gulp.src([
    'package.json',
    'bower.json'
  ])
    .pipe( replace(/\"version\"\:\s*\".*?\"/, '"version": "' + version + '"') )

    .pipe( gulp.dest('./') )
  ;
});

gulp.task('dist', ['build'], function(){
  return gulp.src([
    'build/cytoscape.js',
    'build/cytoscape.min.js',
    'build/arbor.js'
  ])
    .pipe( gulp.dest('dist') )
  ;
});

gulp.task('pub', ['pkgver', 'dist', 'docspub'], function(next){
  next();
});

gulp.task('tag', shell.task([
  './publish-tag.sh'
]));

gulp.task('docspush', shell.task([
  './publish-docs.sh'
]));

gulp.task('npm', shell.task([
  './publish-npm.sh'
]));

gulp.task('watch', function(next){
  var watcher = gulp.watch(paths.sources, ['testrefs','debugrefs']);
  watcher.on('added deleted', function(event){
    console.log('File ' + event.path + ' was ' + event.type + ', updating lib refs in pages...');
  });

  var testWatcher = gulp.watch('test/*.js', ['testlist']);
  testWatcher.on('added deleted', function(event){
    console.log('File ' + event.path + ' was ' + event.type + ', updating test refs in pages...');
  });

  next();
});

gulp.task('lint', function(){
  return gulp.src( paths.sources )
    .pipe( jshint({
      funcscope: true,
      laxbreak: true,
      loopfunc: true,
      strict: true,
      unused: 'vars',
      eqnull: true,
      sub: true,
      shadow: true
    }) )

    .pipe( jshint.reporter(jshStylish) )
  ;
});<commit_msg>fix pkgver<commit_after>var gulp = require('gulp');
var path = require('path');
var tap = require('gulp-tap');
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var replace = require('gulp-replace');
var inject = require('gulp-inject');
var zip = require('gulp-zip');
var mocha = require('gulp-mocha');
var child_process = require('child_process');
var fs = require('fs');
var htmlmin = require('gulp-htmlmin');
var cssmin = require('gulp-cssmin');
var shell = require('gulp-shell');
var jshint = require('gulp-jshint');
var jshStylish = require('jshint-stylish');
var exec = require('child_process').exec;
var docsConf = require('./documentation/docmaker.json');
var runSequence = require('run-sequence');

var version; // used for marking builds w/ version etc

var paths = {
  sources: [
    'src/preamble.js',
    'src/namespace.js',
    'src/is.js',
    'src/util.js',
    'src/math.js',
    'src/instance-registration.js',
    'src/extension.js',
    'src/jquery-plugin.js',
    'src/event.js',
    'src/define.js',
    'src/selector.js',
    'src/style.js',
    'src/style-*.js',
    'src/core.js',
    'src/core-*.js',
    'src/collection.js',
    'src/collection-*.js',
    'src/heap.js',
    'src/extensions/renderer.canvas.define-and-init-etc.js',
    'src/extensions/renderer.canvas.*.js',
    'src/extensions/*.js'
  ],

  docs: {
    js: [
      'documentation/js/fastclick.js',
      'documentation/js/jquery.js',
      'documentation/js/cytoscape.js',
      'documentation/js/load.js',
      'documentation/js/script.js'
    ],

    css: [
      'documentation/css/reset.css',
      'documentation/css/font-awesome.css',
      'documentation/css/highlight/github.css',
      'documentation/css/style.css'
    ]
  }
};

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

});

gulp.task('version', function( next ){
  var now = new Date();
  version = process.env['VERSION'];

  if( version ){
    done();
  } else {
    exec('git rev-parse HEAD', function( error, stdout, stderr ){
      var sha = stdout.substring(0, 10); // shorten so not huge filename

      version = [ 'snapshot', sha, +now ].join('-');
      done();
    });
  }

  function done(){
    console.log('Using version number `%s` for building', version);
    next();
  }

});

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

gulp.task('concat', ['version'], function(){
  return gulp.src( paths.sources )
    .pipe( replace('{{VERSION}}', version) )

    .pipe( concat('cytoscape.js') )

    .pipe( gulp.dest('build') )
  ;
});

gulp.task('build', ['version'], function(){
  return gulp.src( paths.sources )
    .pipe( replace('{{VERSION}}', version) )

    .pipe( concat('cytoscape.js') )

    .pipe( gulp.dest('build') )

    .pipe( uglify({
      mangle: true,

      preserveComments: 'some'
    }) )

    .pipe( concat('cytoscape.min.js') )

    .pipe( gulp.dest('build') )
  ;
});

gulp.task('debugrefs', function(){
  return gulp.src('debug/index.html')
    .pipe( inject( gulp.src(paths.sources, { read: false }), {
      addPrefix: '..',
      addRootSlash: false
    } ) )

    .pipe( gulp.dest('debug') )
  ;
});

gulp.task('testrefs', function(){
  return gulp.src('test/index.html')
    .pipe( inject( gulp.src(paths.sources, { read: false }), {
      addPrefix: '..',
      addRootSlash: false
    } ) )

    .pipe( gulp.dest('test') )
  ;
});

gulp.task('testlist', function(){
  return gulp.src('test/index.html')
    .pipe( inject( gulp.src('test/*.js', { read: false }), {
      addPrefix: '',
      ignorePath: 'test',
      addRootSlash: false,
      starttag: '<!-- inject:test:{{ext}} -->'
    } ) )

    .pipe( gulp.dest('test') )
  ;
});

gulp.task('refs', ['debugrefs', 'testrefs', 'testlist'], function(next){
  next();
});

gulp.task('zip', ['version', 'build'], function(){
  return gulp.src(['build/cytoscape.js', 'build/cytoscape.min.js', 'LGPL-LICENSE.txt', 'lib/arbor.js'])
    .pipe( zip('cytoscape.js-' + version + '.zip') )

    .pipe( gulp.dest('build') )
  ;
});

gulp.task('test', ['concat'], function(){
  return gulp.src('test/*.js')
    .pipe( mocha({
      reporter: 'spec'
    }) )
  ;
});

gulp.task('docsver', ['version'], function(){
  return gulp.src('documentation/docmaker.json')
    .pipe( replace(/\"version\"\:\s*\".*?\"/, '"version": "' + version + '"') )

    .pipe( gulp.dest('documentation') )
  ;
});

gulp.task('docsjs', ['version', 'build'], function(){
  return gulp.src([
    'build/cytoscape.js',
    'build/cytoscape.min.js',
    'lib/arbor.js'
  ])
    .pipe( gulp.dest('documentation/js') )

    .pipe( gulp.dest('documentation/api/cytoscape.js-' + version) )

    .pipe( gulp.dest('documentation/api/cytoscape.js-latest') )
  ;
});

gulp.task('docsdl', ['version', 'zip'], function(){
  return gulp.src('build/cytoscape.js-' + version + '.zip')
    .pipe( gulp.dest('documentation/download') )
  ;
});

gulp.task('docsbuildlist', ['docsdl'], function(next){
  var cwd = process.cwd();

  process.chdir('./documentation/download');
  require('./documentation/download/dlmaker')(function(){
    process.chdir( cwd );

    next();
  });

});

gulp.task('snapshotpush', ['docsbuildlist'], shell.task([
  './publish-buildlist.sh'
]));

gulp.task('docs', function(next){
  var cwd = process.cwd();

  process.chdir('./documentation');
  require('./documentation/docmaker')( function(){
    process.chdir( cwd );

    next();
  } );

});

gulp.task('docsmin', ['docshtmlmin'], function(next){
  next();
});

gulp.task('docsclean', function(next){
  return gulp.src(['documentation/js/all.min.js', 'documentation/css/all.min.css', 'documentation/index.html'])
    .pipe( clean({ read: false }) )
  ;
});

gulp.task('docshtmlmin', ['docsminrefs'], function(){
  return gulp.src('documentation/index.html')
    .pipe( htmlmin({
      collapseWhitespace: true,
      keepClosingSlash: true
    }) )

    .pipe( gulp.dest('documentation') )
  ;
});

gulp.task('docsjsmin', ['docs'], function(){
  return gulp.src( paths.docs.js )
    .pipe( concat('all.min.js') )

    .pipe( uglify({
      mangle: true
    }) )

    .pipe( gulp.dest('documentation/js') )
  ;
});

gulp.task('docscssmin', ['docs'], function(){
  return gulp.src( paths.docs.css )
    .pipe( concat('all.min.css') )

    .pipe( cssmin() )

    .pipe( gulp.dest('documentation/css') )
  ;
});

gulp.task('docsminrefs', ['docscssmin', 'docsjsmin'], function(){
  return gulp.src('documentation/index.html')
    .pipe( inject( gulp.src([ 'documentation/js/all.min.js', 'documentation/css/all.min.css' ], { read: false }), {
      addRootSlash: false,
      ignorePath: 'documentation'
    } ) )

    .pipe( gulp.dest('documentation') )
  ;
});

gulp.task('docsrefs', function(){
  return gulp.src([ 'documentation/index.html', 'documentation/template.html' ])
    .pipe( inject( gulp.src(paths.docs.js.concat( paths.docs.css ), { read: false }), {
      addRootSlash: false,
      ignorePath: 'documentation'
    } ) )

    .pipe( gulp.dest('documentation') )
  ;
});

gulp.task('docsdemoshots', function(next){
  var cwd = process.cwd();

  process.chdir('./documentation');
  require('./documentation/demoshots')( function(){
    process.chdir( cwd );

    next();
  } );
});

gulp.task('docspub', function(next){
  runSequence( ['version', 'docsver', 'docsjs', 'docsbuildlist'], 'docsdemoshots', 'docsmin', next );
});

gulp.task('pkgver', ['version'], function(){
  return gulp.src([
    'package.json',
    'bower.json'
  ])
    .pipe( replace(/\"version\"\:\s*\".*?\"/, '"version": "' + version + '"') )

    .pipe( gulp.dest('./') )
  ;
});

gulp.task('dist', ['build'], function(){
  return gulp.src([
    'build/cytoscape.js',
    'build/cytoscape.min.js',
    'build/arbor.js'
  ])
    .pipe( gulp.dest('dist') )
  ;
});

gulp.task('pub', ['pkgver', 'dist', 'docspub'], function(next){
  next();
});

gulp.task('tag', shell.task([
  './publish-tag.sh'
]));

gulp.task('docspush', shell.task([
  './publish-docs.sh'
]));

gulp.task('npm', shell.task([
  './publish-npm.sh'
]));

gulp.task('watch', function(next){
  var watcher = gulp.watch(paths.sources, ['testrefs','debugrefs']);
  watcher.on('added deleted', function(event){
    console.log('File ' + event.path + ' was ' + event.type + ', updating lib refs in pages...');
  });

  var testWatcher = gulp.watch('test/*.js', ['testlist']);
  testWatcher.on('added deleted', function(event){
    console.log('File ' + event.path + ' was ' + event.type + ', updating test refs in pages...');
  });

  next();
});

gulp.task('lint', function(){
  return gulp.src( paths.sources )
    .pipe( jshint({
      funcscope: true,
      laxbreak: true,
      loopfunc: true,
      strict: true,
      unused: 'vars',
      eqnull: true,
      sub: true,
      shadow: true
    }) )

    .pipe( jshint.reporter(jshStylish) )
  ;
});<|endoftext|>


<commit_before>var fs        = require('fs'),
    gulp      = require('gulp'),
    concat    = require('gulp-concat'),
    uglify    = require('gulp-uglify'),
    header    = require('gulp-header'),
    jshint    = require('gulp-jshint'),
    sass      = require('gulp-sass'),
    rename    = require('gulp-rename'),
    plumber   = require('gulp-plumber'),
    gutil     = require('gulp-util'),
    minifyCSS = require('gulp-minify-css'),
    htmlmin   = require('gulp-html-minifier'),
    replace   = require('gulp-replace'),
    config    = require('./config.json'),
    meta      = require('./package.json');

    var srcDir  = './src/',
        jsDir   = './web/js/',
        cssDir  = './web/css/',
        sassDir = './src/sass/',
        expose  = [],
        dependencies = [
            './bower_components/angular/angular.js',
            './bower_components/angular-route/angular-route.js',
            './bower_components/angular-cookies/angular-cookies.js',
            './bower_components/angular-bootstrap-colorpicker/js/bootstrap-colorpicker-module.js',
            './bower_components/createjs-soundjs/lib/soundjs-0.6.0.min.js',
            './bower_components/tom32i-event-emitter.js/dist/event-emitter.min.js',
            './bower_components/tom32i-option-resolver.js/dist/option-resolver.min.js',
            './bower_components/tom32i-gamepad.js/dist/gamepad.min.js',
            './bower_components/tom32i-key-mapper.js/dist/key-mapper.min.js',
            './bower_components/tom32i-asset-loader.js/dist/asset-loader.min.js'
        ],
        recipes = {
            server: require('./recipes/server.json'),
            client: require('./recipes/client.json')
        },
        banner = [
          '/*!',
          ' * <%= name %> <%= version %>',
          ' * <%= homepage %>',
          ' * <%= license %>',
          ' */\n\n'
        ].join('\n');

var onError = function (err) {
    gutil.beep();
    console.log(err.toString());
    this.emit('end');
};

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

gulp.task('front-expose', function() {
    for (var i = expose.length - 1; i >= 0; i--) {
        gulp.src(expose[i]).pipe(gulp.dest(recipes.client.path));
    }

    return gulp.src(dependencies)
        .pipe(concat('dependencies.js'))
        .pipe(uglify())
        .pipe(gulp.dest(recipes.client.path));
});

gulp.task('front-full', function() {
    return gulp.src(recipes.client.files)
        .pipe(concat(recipes.client.name))
        .pipe(header(banner, meta))
        .pipe(gulp.dest(recipes.client.path));
});

gulp.task('front-min', function(){
    return gulp.src(recipes.client.files)
        .pipe(concat(recipes.client.name))
        .pipe(uglify())
        .pipe(header(banner, meta))
        .pipe(gulp.dest(recipes.client.path));
});

gulp.task('ga', function() {
    var source = gulp.src('./src/client/views/index.html');

    if (typeof(config.googleAnalyticsId) !== 'undefined' && config.googleAnalyticsId) {
        var tag = fs.readFileSync('./src/client/views/google.analytics.html').toString()
            .replace('GoogleAnalyticsToken', config.googleAnalyticsId);

        source.pipe(replace('<!-- Google Analytics -->', tag));
    }

    return source
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest('./web'));
});

gulp.task('views', function() {
    return gulp.src('src/client/views/*/**/*.html')
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest(jsDir + 'views'));
});

gulp.task('server', function() {
    return gulp.src(recipes.server.files)
        .pipe(concat(recipes.server.name))
        .pipe(gulp.dest(recipes.server.path));
});

gulp.task('sass-full', function() {
    return gulp.src(sassDir + 'style.scss')
        .pipe(plumber({ errorHandler: onError }))
        .pipe(sass())
        .pipe(rename('style.css'))
        .pipe(gulp.dest(cssDir));
});

gulp.task('sass-min', function() {
    return gulp.src(sassDir + 'style.scss')
        .pipe(plumber({ errorHandler: onError }))
        .pipe(sass())
        .pipe(minifyCSS())
        .pipe(rename('style.css'))
        .pipe(gulp.dest(cssDir));
});

gulp.task('watch', ['dev'], function () {
    gulp.watch('src/**/*.js', ['jshint', 'server', 'front-full']);
    gulp.watch('src/client/views/**/*', ['views']);
    gulp.watch('src/**/*.scss', ['sass-full']);
});

gulp.task('default', ['jshint', 'server', 'front-expose', 'ga', 'views', 'front-min', 'sass-min']);
gulp.task('dev', ['jshint', 'server', 'front-expose', 'ga', 'views', 'front-full', 'sass-full']);
<commit_msg>Optional commit file<commit_after>var fs        = require('fs'),
    gulp      = require('gulp'),
    concat    = require('gulp-concat'),
    uglify    = require('gulp-uglify'),
    header    = require('gulp-header'),
    jshint    = require('gulp-jshint'),
    sass      = require('gulp-sass'),
    rename    = require('gulp-rename'),
    plumber   = require('gulp-plumber'),
    gutil     = require('gulp-util'),
    minifyCSS = require('gulp-minify-css'),
    htmlmin   = require('gulp-html-minifier'),
    replace   = require('gulp-replace'),
    meta      = require('./package.json'),
    config;

    try {
        config = require('./config.json');
    } catch (error) {
        config = { googleAnalyticsId: false };
    }

    var srcDir  = './src/',
        jsDir   = './web/js/',
        cssDir  = './web/css/',
        sassDir = './src/sass/',
        expose  = [],
        dependencies = [
            './bower_components/angular/angular.js',
            './bower_components/angular-route/angular-route.js',
            './bower_components/angular-cookies/angular-cookies.js',
            './bower_components/angular-bootstrap-colorpicker/js/bootstrap-colorpicker-module.js',
            './bower_components/createjs-soundjs/lib/soundjs-0.6.0.min.js',
            './bower_components/tom32i-event-emitter.js/dist/event-emitter.min.js',
            './bower_components/tom32i-option-resolver.js/dist/option-resolver.min.js',
            './bower_components/tom32i-gamepad.js/dist/gamepad.min.js',
            './bower_components/tom32i-key-mapper.js/dist/key-mapper.min.js',
            './bower_components/tom32i-asset-loader.js/dist/asset-loader.min.js'
        ],
        recipes = {
            server: require('./recipes/server.json'),
            client: require('./recipes/client.json')
        },
        banner = [
          '/*!',
          ' * <%= name %> <%= version %>',
          ' * <%= homepage %>',
          ' * <%= license %>',
          ' */\n\n'
        ].join('\n');

var onError = function (err) {
    gutil.beep();
    console.log(err.toString());
    this.emit('end');
};

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

gulp.task('front-expose', function() {
    for (var i = expose.length - 1; i >= 0; i--) {
        gulp.src(expose[i]).pipe(gulp.dest(recipes.client.path));
    }

    return gulp.src(dependencies)
        .pipe(concat('dependencies.js'))
        .pipe(uglify())
        .pipe(gulp.dest(recipes.client.path));
});

gulp.task('front-full', function() {
    return gulp.src(recipes.client.files)
        .pipe(concat(recipes.client.name))
        .pipe(header(banner, meta))
        .pipe(gulp.dest(recipes.client.path));
});

gulp.task('front-min', function(){
    return gulp.src(recipes.client.files)
        .pipe(concat(recipes.client.name))
        .pipe(uglify())
        .pipe(header(banner, meta))
        .pipe(gulp.dest(recipes.client.path));
});

gulp.task('ga', function() {
    var source = gulp.src('./src/client/views/index.html');

    if (typeof(config.googleAnalyticsId) !== 'undefined' && config.googleAnalyticsId) {
        var tag = fs.readFileSync('./src/client/views/google.analytics.html').toString()
            .replace('GoogleAnalyticsToken', config.googleAnalyticsId);

        source.pipe(replace('<!-- Google Analytics -->', tag));
    }

    return source
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest('./web'));
});

gulp.task('views', function() {
    return gulp.src('src/client/views/*/**/*.html')
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest(jsDir + 'views'));
});

gulp.task('server', function() {
    return gulp.src(recipes.server.files)
        .pipe(concat(recipes.server.name))
        .pipe(gulp.dest(recipes.server.path));
});

gulp.task('sass-full', function() {
    return gulp.src(sassDir + 'style.scss')
        .pipe(plumber({ errorHandler: onError }))
        .pipe(sass())
        .pipe(rename('style.css'))
        .pipe(gulp.dest(cssDir));
});

gulp.task('sass-min', function() {
    return gulp.src(sassDir + 'style.scss')
        .pipe(plumber({ errorHandler: onError }))
        .pipe(sass())
        .pipe(minifyCSS())
        .pipe(rename('style.css'))
        .pipe(gulp.dest(cssDir));
});

gulp.task('watch', ['dev'], function () {
    gulp.watch('src/**/*.js', ['jshint', 'server', 'front-full']);
    gulp.watch('src/client/views/**/*', ['views']);
    gulp.watch('src/**/*.scss', ['sass-full']);
});

gulp.task('default', ['jshint', 'server', 'front-expose', 'ga', 'views', 'front-min', 'sass-min']);
gulp.task('dev', ['jshint', 'server', 'front-expose', 'ga', 'views', 'front-full', 'sass-full']);
<|endoftext|>


<commit_before>var gulp = require('gulp'),
  concat = require('gulp-concat'),
  uglify = require('gulp-uglify'),
  util = require('gulp-util'),
  jshint = require('gulp-jshint'),
  size = require('gulp-size'),
  connect = require('gulp-connect'),
  replace = require('gulp-replace'),
  htmlv = require('gulp-html-validator'),
  insert = require('gulp-insert'),
  inquirer = require('inquirer'),
  semver = require('semver'),
  exec = require('child_process').exec,
  fs = require('fs'),
  package = require('./package.json'),
  bower = require('./bower.json'),
  karma = require('gulp-karma'),
  browserify = require('browserify'),
  streamify = require('gulp-streamify'),
  source = require('vinyl-source-stream'),
  merge = require('merge-stream');

var srcDir = './src/';
var outDir = './dist/';
var testDir = './test/';

var header = "/*!\n\
 * Chart.js\n\
 * http://chartjs.org/\n\
 * Version: {{ version }}\n\
 *\n\
 * Copyright 2016 Nick Downie\n\
 * Released under the MIT license\n\
 * https://github.com/chartjs/Chart.js/blob/master/LICENSE.md\n\
 */\n";

var preTestFiles = [
  './node_modules/moment/min/moment.min.js',
];

var testFiles = [
  './test/mockContext.js',
  './test/*.js',

  // Disable tests which need to be rewritten based on changes introduced by
  // the following changes: https://github.com/chartjs/Chart.js/pull/2346
  '!./test/core.layoutService.tests.js',
  '!./test/defaultConfig.tests.js',
];

gulp.task('build', buildTask);
gulp.task('coverage', coverageTask);
gulp.task('watch', watchTask);
gulp.task('bump', bumpTask);
gulp.task('release', ['build'], releaseTask);
gulp.task('jshint', jshintTask);
gulp.task('test', ['jshint', 'validHTML', 'unittest']);
gulp.task('size', ['library-size', 'module-sizes']);
gulp.task('server', serverTask);
gulp.task('validHTML', validHTMLTask);
gulp.task('unittest', unittestTask);
gulp.task('unittestWatch', unittestWatchTask);
gulp.task('library-size', librarySizeTask);
gulp.task('module-sizes', moduleSizesTask);
gulp.task('_open', _openTask);
gulp.task('dev', ['server', 'default']);

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

function buildTask() {

  var bundled = browserify('./src/chart.js')
    .bundle()
    .pipe(source('Chart.bundle.js'))
    .pipe(insert.prepend(header))
    .pipe(streamify(replace('{{ version }}', package.version)))
    .pipe(gulp.dest(outDir))
    .pipe(streamify(uglify()))
    .pipe(insert.prepend(header))
    .pipe(streamify(replace('{{ version }}', package.version)))
    .pipe(streamify(concat('Chart.bundle.min.js')))
    .pipe(gulp.dest(outDir));

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

  return merge(bundled, nonBundled);

}

/*
 *  Usage : gulp bump
 *  Prompts: Version increment to bump
 *  Output: - New version number written into package.json & bower.json
 */
function bumpTask(complete) {
  util.log('Current version:', util.colors.cyan(package.version));
  var choices = ['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'].map(function(versionType) {
    return versionType + ' (v' + semver.inc(package.version, versionType) + ')';
  });
  inquirer.prompt({
    type: 'list',
    name: 'version',
    message: 'What version update would you like?',
    choices: choices
  }, function(res) {
    var increment = res.version.split(' ')[0],
      newVersion = semver.inc(package.version, increment),
      oldVersion = package.version;

    // Set the new versions into the bower/package object
    package.version = newVersion;
    bower.version = newVersion;

    // Write these to their own files, then build the output
    fs.writeFileSync('package.json', JSON.stringify(package, null, 2));
    fs.writeFileSync('bower.json', JSON.stringify(bower, null, 2));

    var oldCDN = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/'+oldVersion+'/Chart.min.js',
      newCDN = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/'+newVersion+'/Chart.min.js';

    gulp.src(['./README.md'])
      .pipe(replace(oldCDN, newCDN))
      .pipe(gulp.dest('./'));

    complete();
  });
}

function releaseTask() {
  exec('git tag -a v' + package.version);
}

function jshintTask() {
  return gulp.src(srcDir + '**/*.js')
    .pipe(jshint('config.jshintrc'))
    .pipe(jshint.reporter('jshint-stylish'))
    .pipe(jshint.reporter('fail'));
}

function validHTMLTask() {
  return gulp.src('samples/*.html')
    .pipe(htmlv());
}

function unittestTask() {
  var files = ['./src/**/*.js'];
  Array.prototype.unshift.apply(files, preTestFiles);
  Array.prototype.push.apply(files, testFiles);

  return gulp.src(files)
    .pipe(karma({
      configFile: 'karma.conf.ci.js',
      action: 'run'
    }));
}

function unittestWatchTask() {
  var files = ['./src/**/*.js'];
  Array.prototype.unshift.apply(files, preTestFiles);
  Array.prototype.push.apply(files, testFiles);

  return gulp.src(files)
    .pipe(karma({
      configFile: 'karma.conf.js',
      action: 'watch'
    }));
}

function coverageTask() {
  var files = ['./src/**/*.js'];
  Array.prototype.unshift.apply(files, preTestFiles);
  Array.prototype.push.apply(files, testFiles);

  return gulp.src(files)
    .pipe(karma({
      configFile: 'karma.coverage.conf.js',
      action: 'run'
    }));
}

function librarySizeTask() {
  return gulp.src('dist/Chart.bundle.min.js')
    .pipe(size({
      gzip: true
    }));
}

function moduleSizesTask() {
  return gulp.src(srcDir + '**/*.js')
    .pipe(uglify({
      preserveComments: 'some'
    }))
    .pipe(size({
      showFiles: true,
      gzip: true
    }));
}

function watchTask() {
  if (util.env.test) {
    return gulp.watch('./src/**', ['build', 'unittest', 'unittestWatch']);
  }
  return gulp.watch('./src/**', ['build']);
}

function serverTask() {
  connect.server({
    port: 8000
  });
}

// Convenience task for opening the project straight from the command line

function _openTask() {
  exec('open http://localhost:8000');
  exec('subl .');
}
<commit_msg>Clean up gulpfile<commit_after>var gulp = require('gulp'),
  concat = require('gulp-concat'),
  uglify = require('gulp-uglify'),
  util = require('gulp-util'),
  jshint = require('gulp-jshint'),
  size = require('gulp-size'),
  connect = require('gulp-connect'),
  replace = require('gulp-replace'),
  htmlv = require('gulp-html-validator'),
  insert = require('gulp-insert'),
  inquirer = require('inquirer'),
  semver = require('semver'),
  exec = require('child_process').exec,
  fs = require('fs'),
  package = require('./package.json'),
  bower = require('./bower.json'),
  karma = require('gulp-karma'),
  browserify = require('browserify'),
  streamify = require('gulp-streamify'),
  source = require('vinyl-source-stream'),
  merge = require('merge-stream');

var srcDir = './src/';
var outDir = './dist/';

var header = "/*!\n" +
  " * Chart.js\n" +
  " * http://chartjs.org/\n" +
  " * Version: {{ version }}\n" +
  " *\n" +
  " * Copyright 2016 Nick Downie\n" +
  " * Released under the MIT license\n" +
  " * https://github.com/chartjs/Chart.js/blob/master/LICENSE.md\n" +
  " */\n";

var preTestFiles = [
  './node_modules/moment/min/moment.min.js',
];

var testFiles = [
  './test/mockContext.js',
  './test/*.js',

  // Disable tests which need to be rewritten based on changes introduced by
  // the following changes: https://github.com/chartjs/Chart.js/pull/2346
  '!./test/core.layoutService.tests.js',
  '!./test/defaultConfig.tests.js',
];

gulp.task('build', buildTask);
gulp.task('coverage', coverageTask);
gulp.task('watch', watchTask);
gulp.task('bump', bumpTask);
gulp.task('release', ['build'], releaseTask);
gulp.task('jshint', jshintTask);
gulp.task('test', ['jshint', 'validHTML', 'unittest']);
gulp.task('size', ['library-size', 'module-sizes']);
gulp.task('server', serverTask);
gulp.task('validHTML', validHTMLTask);
gulp.task('unittest', unittestTask);
gulp.task('unittestWatch', unittestWatchTask);
gulp.task('library-size', librarySizeTask);
gulp.task('module-sizes', moduleSizesTask);
gulp.task('_open', _openTask);
gulp.task('dev', ['server', 'default']);

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

function buildTask() {

  var bundled = browserify('./src/chart.js')
    .bundle()
    .pipe(source('Chart.bundle.js'))
    .pipe(insert.prepend(header))
    .pipe(streamify(replace('{{ version }}', package.version)))
    .pipe(gulp.dest(outDir))
    .pipe(streamify(uglify()))
    .pipe(insert.prepend(header))
    .pipe(streamify(replace('{{ version }}', package.version)))
    .pipe(streamify(concat('Chart.bundle.min.js')))
    .pipe(gulp.dest(outDir));

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

  return merge(bundled, nonBundled);

}

/*
 *  Usage : gulp bump
 *  Prompts: Version increment to bump
 *  Output: - New version number written into package.json & bower.json
 */
function bumpTask(complete) {
  util.log('Current version:', util.colors.cyan(package.version));
  var choices = ['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'].map(function(versionType) {
    return versionType + ' (v' + semver.inc(package.version, versionType) + ')';
  });
  inquirer.prompt({
    type: 'list',
    name: 'version',
    message: 'What version update would you like?',
    choices: choices
  }, function(res) {
    var increment = res.version.split(' ')[0],
      newVersion = semver.inc(package.version, increment),
      oldVersion = package.version;

    // Set the new versions into the bower/package object
    package.version = newVersion;
    bower.version = newVersion;

    // Write these to their own files, then build the output
    fs.writeFileSync('package.json', JSON.stringify(package, null, 2));
    fs.writeFileSync('bower.json', JSON.stringify(bower, null, 2));

    var oldCDN = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/'+oldVersion+'/Chart.min.js',
      newCDN = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/'+newVersion+'/Chart.min.js';

    gulp.src(['./README.md'])
      .pipe(replace(oldCDN, newCDN))
      .pipe(gulp.dest('./'));

    complete();
  });
}

function releaseTask() {
  exec('git tag -a v' + package.version);
}

function jshintTask() {
  return gulp.src(srcDir + '**/*.js')
    .pipe(jshint('config.jshintrc'))
    .pipe(jshint.reporter('jshint-stylish'))
    .pipe(jshint.reporter('fail'));
}

function validHTMLTask() {
  return gulp.src('samples/*.html')
    .pipe(htmlv());
}

function startTest() {
  var files = ['./src/**/*.js'];
  Array.prototype.unshift.apply(files, preTestFiles);
  Array.prototype.push.apply(files, testFiles);
  return files;
}

function unittestTask() {
  var files = startTest();

  return gulp.src(files)
    .pipe(karma({
      configFile: 'karma.conf.ci.js',
      action: 'run'
    }));
}

function unittestWatchTask() {
  var files = startTest();

  return gulp.src(files)
    .pipe(karma({
      configFile: 'karma.conf.js',
      action: 'watch'
    }));
}

function coverageTask() {
  var files = startTest();

  return gulp.src(files)
    .pipe(karma({
      configFile: 'karma.coverage.conf.js',
      action: 'run'
    }));
}

function librarySizeTask() {
  return gulp.src('dist/Chart.bundle.min.js')
    .pipe(size({
      gzip: true
    }));
}

function moduleSizesTask() {
  return gulp.src(srcDir + '**/*.js')
    .pipe(uglify({
      preserveComments: 'some'
    }))
    .pipe(size({
      showFiles: true,
      gzip: true
    }));
}

function watchTask() {
  if (util.env.test) {
    return gulp.watch('./src/**', ['build', 'unittest', 'unittestWatch']);
  }
  return gulp.watch('./src/**', ['build']);
}

function serverTask() {
  connect.server({
    port: 8000
  });
}

// Convenience task for opening the project straight from the command line

function _openTask() {
  exec('open http://localhost:8000');
  exec('subl .');
}
<|endoftext|>


<commit_before>/* Libraries and imports */
var gulp = require('gulp'),
	connect = require('gulp-connect'),
	plumber = require('gulp-plumber'),
	watch = require('gulp-watch'),
	less = require('gulp-less'),

	path = require("path"),
	fs = require("fs"),
	glob = require('glob'),
	UglifyJS = require("uglify-js"),
	cheerio = require('cheerio'),
	html_minify = require('html-minifier').minify,

	sources = {
		js: ["core/**/*.js", "js/**/*.js"],
		cronos: {
			core: "core",
			libs: "js/libs",
			app: "js/app"
		},
		templates: ["views/**/*.html"],
		less: "styles/**/*.less",
		style: "styles/style.less",
		overwatch: "build/**/*.*" /* Build folder */
	},

	destinations = {
		js: "build/js/",
		build: "build/",
		css: "build/styles/"
	};

/******************************* ****** ********************************/
/******************************* SERVER ********************************/
/*******************************  1234  ********************************/
/******************************* ****** ********************************/

/*SERVER TASK*/
gulp.task('serve', function(event) {
	connect.server({
		root: destinations.build,
		port: 1234,
		livereload: true
	});
	// sets up a livereload that watches for any changes in the root
	watch({
		glob: sources.overwatch
	})
		.pipe(connect.reload());
});

/******************************* ****** ********************************/

var processJSFiles = function(event) {
	var core_files = [];

	var cronos_files = (JSON.parse(fs.readFileSync( path.join(sources.cronos.core, 'package.json'), 'utf8'))).files;
	for (var i = 0; i < cronos_files.length; i++) {
		cronos_files[i] = path.join(sources.cronos.core, cronos_files[i]);
	}
	core_files = core_files.concat(cronos_files);

	var lib_files = (JSON.parse(fs.readFileSync( path.join(sources.cronos.libs, 'package.json'), 'utf8'))).files;
	for (var i = 0; i < lib_files.length; i++) {
		lib_files[i] = path.join(sources.cronos.libs, lib_files[i]);
	}
	core_files = core_files.concat(lib_files);

	//var app_files = glob.sync('app/*.js');
	var app_files = (JSON.parse(fs.readFileSync( path.join(sources.cronos.app, 'package.json'), 'utf8'))).files;
	for (var i = 0; i < app_files.length; i++) {
		app_files[i] = path.join(sources.cronos.app, app_files[i]);
	}
	core_files = core_files.concat(app_files);

	console.info('[JS] ' + core_files.join(', '));

	var result = UglifyJS.minify(core_files, {
		outSourceMap: "app.js.map"
	});

	fs.writeFileSync(path.join( destinations.js, 'app.js' ), '/*\n//@ sourceMappingURL=app.js.map\n*/\n' + result.code);
	fs.writeFileSync(path.join( destinations.js, 'app.js.map' ), result.map);

	if(event) event();
}

/*COFFEE TASK*/
gulp.task('js', function(event) {
	return processJSFiles(event);
});
/*COFFEE WATCH TASK FOR DEVELOPMENT*/
gulp.task('js:watch', function(event) {
	watch({
		glob: sources.js
	}, function(files) {
		processJSFiles();
	});
});

/******************************* STYLES ********************************/
/*LESS TASK*/
gulp.task('less', function(event) {
	return gulp.src(sources.style)
		.pipe(plumber())
		.pipe(less({
			compress: true
		}))
		.pipe(gulp.dest(destinations.css));
});
/*LESS WATCH TASK FOR DEVELOPMENT*/
gulp.task('less:watch', function(event) {
	watch({
		glob: sources.less
	}, function(files) {
		gulp.src(sources.style)
			.pipe(plumber())
			.pipe(less({
				compress: true
			}))
			.pipe(gulp.dest(destinations.css));
	});
});

/******************************* ****** ********************************/

var processTemplatesFiles = function(event) {
	var hf = fs.readFileSync('views/index.html', "utf8");
	var $ = cheerio.load(hf);

	$('script[type="text/cronos"]').each(function(i, elem) {
		$(elem).remove();
	});

	var templates = glob.sync('views/templates/*.html');
	for (var i = 0; i < templates.length; i++) {
		var cf = cheerio.load(fs.readFileSync(templates[i], "utf8"));

		var html = html_minify(cf.html(), {
			collapseWhitespace: true,
			removeComments: true
		});

		var id = 'template_' + path.basename(templates[i], '.html');

		$('body script').first().before('<script type="text/cronos" id="' + id + '">' + html + '</script>');
	}

	fs.writeFileSync('build/index.html', $.html());

	if(event) event();
}

/*TEMPLATES TASK*/
gulp.task('templates', function(event) {
	return processTemplatesFiles(event);
});
/*TEMPLATES WATCH TASK FOR DEVELOPMENT*/
gulp.task('templates:watch', function(event) {
	watch({
		glob: sources.templates
	}, function(files) {
		processTemplatesFiles();
	});
});

/******************************* ****** ********************************/

/*DEFAULT TASK*/
gulp.task('default', ["serve", "templates:watch", "less:watch", "js:watch"]);<commit_msg>Improved gulp<commit_after>/* Libraries and imports */
var gulp = require('gulp'),
	connect = require('gulp-connect'),
	plumber = require('gulp-plumber'),
	watch = require('gulp-watch'),
	less = require('gulp-less'),

	path = require("path"),
	fs = require("fs"),
	glob = require('glob'),
	UglifyJS = require("uglify-js"),
	cheerio = require('cheerio'),
	html_minify = require('html-minifier').minify,

	sources = {
		js: ["core/**/*.js", "js/**/*.js"],
		cronos: {
			core: "core",
			libs: "js/libs",
			app: "js/app"
		},
		templates: ["views/**/*.html"],
		less: "styles/**/*.less",
		style: "styles/style.less",
		overwatch: "build/**/*.*" /* Build folder */
	},

	destinations = {
		js: "build/js/",
		build: "build/",
		css: "build/styles/"
	};

/* HELPERS */
var buildFolders = function() {
	// Check build folders
	if( !fs.existsSync( destinations.build ) ) {
		fs.mkdirSync( destinations.build );
	}

	if( !fs.existsSync( destinations.js ) ) {
		fs.mkdirSync( destinations.js );
	}

	if( !fs.existsSync( destinations.css ) ) {
		fs.mkdirSync( destinations.css );
	}
}
/*		   */

/******************************* ****** ********************************/
/******************************* SERVER ********************************/
/*******************************  1234  ********************************/
/******************************* ****** ********************************/

/*SERVER TASK*/
gulp.task('serve', function(event) {
	connect.server({
		root: destinations.build,
		port: 1234,
		livereload: true
	});
	// sets up a livereload that watches for any changes in the root
	watch({
		glob: sources.overwatch
	})
		.pipe(connect.reload());
});

/******************************* ****** ********************************/

var processJSFiles = function(event) {
	buildFolders();

	var core_files = [];

	var cronos_files = (JSON.parse(fs.readFileSync( path.join(sources.cronos.core, 'package.json'), 'utf8'))).files;
	for (var i = 0; i < cronos_files.length; i++) {
		cronos_files[i] = path.join(sources.cronos.core, cronos_files[i]);
	}
	core_files = core_files.concat(cronos_files);

	var lib_files = (JSON.parse(fs.readFileSync( path.join(sources.cronos.libs, 'package.json'), 'utf8'))).files;
	for (var i = 0; i < lib_files.length; i++) {
		lib_files[i] = path.join(sources.cronos.libs, lib_files[i]);
	}
	core_files = core_files.concat(lib_files);

	//var app_files = glob.sync('app/*.js');
	var app_files = (JSON.parse(fs.readFileSync( path.join(sources.cronos.app, 'package.json'), 'utf8'))).files;
	for (var i = 0; i < app_files.length; i++) {
		app_files[i] = path.join(sources.cronos.app, app_files[i]);
	}
	core_files = core_files.concat(app_files);

	console.info('[JS] ' + core_files.join(', '));

	var result = UglifyJS.minify(core_files, {
		outSourceMap: "app.js.map"
	});

	fs.writeFileSync(path.join( destinations.js, 'app.js' ), '/*\n//@ sourceMappingURL=app.js.map\n*/\n' + result.code);
	fs.writeFileSync(path.join( destinations.js, 'app.js.map' ), result.map);

	if(event) event();
}

/*COFFEE TASK*/
gulp.task('js', function(event) {
	return processJSFiles(event);
});
/*COFFEE WATCH TASK FOR DEVELOPMENT*/
gulp.task('js:watch', function(event) {
	watch({
		glob: sources.js
	}, function(files) {
		processJSFiles();
	});
});

/******************************* STYLES ********************************/
/*LESS TASK*/
gulp.task('less', function(event) {
	return gulp.src(sources.style)
		.pipe(plumber())
		.pipe(less({
			compress: true
		}))
		.pipe(gulp.dest(destinations.css));
});
/*LESS WATCH TASK FOR DEVELOPMENT*/
gulp.task('less:watch', function(event) {
	watch({
		glob: sources.less
	}, function(files) {
		gulp.src(sources.style)
			.pipe(plumber())
			.pipe(less({
				compress: true
			}))
			.pipe(gulp.dest(destinations.css));
	});
});

/******************************* ****** ********************************/

var processTemplatesFiles = function(event) {
	buildFolders();

	var hf = fs.readFileSync('views/index.html', "utf8");
	var $ = cheerio.load(hf);

	$('script[type="text/cronos"]').each(function(i, elem) {
		$(elem).remove();
	});

	var templates = glob.sync('views/templates/*.html');
	for (var i = 0; i < templates.length; i++) {
		var cf = cheerio.load(fs.readFileSync(templates[i], "utf8"));

		var html = html_minify(cf.html(), {
			collapseWhitespace: true,
			removeComments: true
		});

		var id = 'template_' + path.basename(templates[i], '.html');

		$('body script').first().before('<script type="text/cronos" id="' + id + '">' + html + '</script>');
	}

	fs.writeFileSync('build/index.html', $.html());

	if(event) event();
}

/*TEMPLATES TASK*/
gulp.task('templates', function(event) {
	return processTemplatesFiles(event);
});
/*TEMPLATES WATCH TASK FOR DEVELOPMENT*/
gulp.task('templates:watch', function(event) {
	watch({
		glob: sources.templates
	}, function(files) {
		processTemplatesFiles();
	});
});

/******************************* ****** ********************************/

/*DEFAULT TASK*/
gulp.task('default', ["serve", "templates:watch", "less:watch", "js:watch"]);<|endoftext|>


<commit_before>const gulp = require('gulp');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify-es').default;
const clean = require('gulp-clean');
const eslint = require('gulp-eslint');
const gulpIf = require('gulp-if');
const mocha = require('gulp-mocha');
const sourcemaps = require('gulp-sourcemaps');
const livereload = require('gulp-livereload');
const sequence = require('run-sequence');
const symlink = require('gulp-symlink');
const fs = require('fs');
const path = require('path');
const rmdir = require('rmdir');
const yaml = require('gulp-yaml');

gulp.task('lintSrcs', () => {
  return gulp
    .src(['./src/**/*.js'])
    .pipe(
      eslint({
        useEslintrc: true,
        fix: true
      })
    )
    .pipe(eslint.format())
    .pipe(
      gulpIf(file => {
        return file.eslint != null && file.eslint.fixed;
      }, gulp.dest('./src'))
    )
    .pipe(eslint.failAfterError());
});

gulp.task('lintTests', () => {
  return gulp
    .src(['./tests/**/*.js'])
    .pipe(
      eslint({
        emitWarning: true,
        useEslintrc: true,
        fix: true
      })
    )
    .pipe(eslint.format())
    .pipe(
      gulpIf(file => {
        return file.eslint != null && file.eslint.fixed;
      }, gulp.dest('./tests'))
    )
    .pipe(eslint.failAfterError());
});

gulp.task('lint', done => {
  sequence('lintSrcs', 'lintTests', done);
});

gulp.task('clean', () => {
  gulp
    .src([
      './dist/*',
      './dist',
      './*.tgz',
      './services/environment',
      './services/start_systemd.sh',
      './services/systemd/candy-red.service',
      './services/systemd/environment'
    ])
    .pipe(clean({ force: true }));
});

gulp.task('nodes', () => {
  return Promise.all(
    fs
      .readdirSync('node_modules/')
      .filter(f => f.indexOf('local-node-') === 0)
      .filter(f => {
        try {
          return fs.statSync(`node_modules/${f}`).isDirectory();
        } catch (_) {
          return false;
        }
      })
      .map(f => {
        return new Promise((resolve, reject) =>
          rmdir(`node_modules/${f}`, err => {
            if (err) {
              return reject(err);
            }
            return resolve();
          })
        );
      })
  ).then(() => {
    return gulp.src('./dist/nodes/local-*').pipe(
      symlink(f => {
        return path.join(`node_modules/${f.relative}`);
      })
    );
  });
});

gulp.task('copyResources', () => {
  gulp
    .src([
      './src/**/*.{css,ico,png,html,json,yaml,yml}',
      '!./src/mo/**/*.{yaml,yml}'
    ])
    .pipe(gulp.dest('./dist'));
});

gulp.task('favicons', () => {
  return gulp
    .src('./src/public/images/icon*.png')
    .pipe(gulp.dest('./node_modules/node-red-dashboard/dist'));
});

gulp.task('mo', () => {
  return gulp
    .src(['./src/mo/**/*.{yaml,yml}'])
    .pipe(yaml({ safe: true }))
    .pipe(gulp.dest('./dist/mo'));
});

gulp.task('buildSrcs', ['copyResources', 'mo', 'favicons'], () => {
  return gulp
    .src('./src/**/*.js')
    .pipe(sourcemaps.init())
    .pipe(
      babel({
        minified: true,
        compact: true,
        configFile: './.babelrc'
      })
    )
    .on('error', console.error.bind(console))
    .pipe(
      uglify({
        mangle: {},
        compress: {
          dead_code: true,
          drop_debugger: true,
          properties: true,
          unused: true,
          toplevel: true,
          if_return: true,
          drop_console: false,
          conditionals: true,
          unsafe_math: true,
          unsafe: true
        }
      })
    )
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('./dist'))
    .pipe(livereload());
});

gulp.task('build', done => {
  sequence('buildSrcs', 'nodes', done);
});

gulp.task('copyTestResources', () => {
  gulp
    .src('./tests/**/*.{css,ico,png,html,json,yaml,yml}')
    .pipe(gulp.dest('./dist'));
});

gulp.task('buildTests', ['buildSrcs', 'copyTestResources'], () => {
  return gulp
    .src('./tests/**/*.js')
    .pipe(sourcemaps.init())
    .pipe(babel({ configFile: './.babelrc' }))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('./dist'));
});

gulp.task('watch', ['build'], () => {
  livereload.listen();
  gulp.watch('./src/*.js', ['build']);
});

gulp.task('runTests', () => {
  return gulp
    .src(['./dist/**/*.test.js'], { read: false })
    .pipe(
      mocha({
        require: ['source-map-support/register'],
        reporter: 'spec'
      })
    )
    .once('error', () => process.exit(1))
    .once('end', () => process.exit());
});

gulp.task('test', done => {
  sequence('lint', 'buildTests', 'runTests', done);
});

gulp.task('default', ['build']);
<commit_msg>Include *.json to be removed<commit_after>const gulp = require('gulp');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify-es').default;
const clean = require('gulp-clean');
const eslint = require('gulp-eslint');
const gulpIf = require('gulp-if');
const mocha = require('gulp-mocha');
const sourcemaps = require('gulp-sourcemaps');
const livereload = require('gulp-livereload');
const sequence = require('run-sequence');
const symlink = require('gulp-symlink');
const fs = require('fs');
const path = require('path');
const rmdir = require('rmdir');
const yaml = require('gulp-yaml');

gulp.task('lintSrcs', () => {
  return gulp
    .src(['./src/**/*.js'])
    .pipe(
      eslint({
        useEslintrc: true,
        fix: true
      })
    )
    .pipe(eslint.format())
    .pipe(
      gulpIf(file => {
        return file.eslint != null && file.eslint.fixed;
      }, gulp.dest('./src'))
    )
    .pipe(eslint.failAfterError());
});

gulp.task('lintTests', () => {
  return gulp
    .src(['./tests/**/*.js'])
    .pipe(
      eslint({
        emitWarning: true,
        useEslintrc: true,
        fix: true
      })
    )
    .pipe(eslint.format())
    .pipe(
      gulpIf(file => {
        return file.eslint != null && file.eslint.fixed;
      }, gulp.dest('./tests'))
    )
    .pipe(eslint.failAfterError());
});

gulp.task('lint', done => {
  sequence('lintSrcs', 'lintTests', done);
});

gulp.task('clean', () => {
  gulp
    .src([
      './dist/*',
      './dist/*.*',
      './dist',
      './*.tgz',
      './services/environment',
      './services/start_systemd.sh',
      './services/systemd/candy-red.service',
      './services/systemd/environment'
    ])
    .pipe(clean({ force: true }));
});

gulp.task('nodes', () => {
  return Promise.all(
    fs
      .readdirSync('node_modules/')
      .filter(f => f.indexOf('local-node-') === 0)
      .filter(f => {
        try {
          return fs.statSync(`node_modules/${f}`).isDirectory();
        } catch (_) {
          return false;
        }
      })
      .map(f => {
        return new Promise((resolve, reject) =>
          rmdir(`node_modules/${f}`, err => {
            if (err) {
              return reject(err);
            }
            return resolve();
          })
        );
      })
  ).then(() => {
    return gulp.src('./dist/nodes/local-*').pipe(
      symlink(f => {
        return path.join(`node_modules/${f.relative}`);
      })
    );
  });
});

gulp.task('copyResources', () => {
  gulp
    .src([
      './src/**/*.{css,ico,png,html,json,yaml,yml}',
      '!./src/mo/**/*.{yaml,yml}'
    ])
    .pipe(gulp.dest('./dist'));
});

gulp.task('favicons', () => {
  return gulp
    .src('./src/public/images/icon*.png')
    .pipe(gulp.dest('./node_modules/node-red-dashboard/dist'));
});

gulp.task('mo', () => {
  return gulp
    .src(['./src/mo/**/*.{yaml,yml}'])
    .pipe(yaml({ safe: true }))
    .pipe(gulp.dest('./dist/mo'));
});

gulp.task('buildSrcs', ['copyResources', 'mo', 'favicons'], () => {
  return gulp
    .src('./src/**/*.js')
    .pipe(sourcemaps.init())
    .pipe(
      babel({
        minified: true,
        compact: true,
        configFile: './.babelrc'
      })
    )
    .on('error', console.error.bind(console))
    .pipe(
      uglify({
        mangle: {},
        compress: {
          dead_code: true,
          drop_debugger: true,
          properties: true,
          unused: true,
          toplevel: true,
          if_return: true,
          drop_console: false,
          conditionals: true,
          unsafe_math: true,
          unsafe: true
        }
      })
    )
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('./dist'))
    .pipe(livereload());
});

gulp.task('build', done => {
  sequence('buildSrcs', 'nodes', done);
});

gulp.task('copyTestResources', () => {
  gulp
    .src('./tests/**/*.{css,ico,png,html,json,yaml,yml}')
    .pipe(gulp.dest('./dist'));
});

gulp.task('buildTests', ['buildSrcs', 'copyTestResources'], () => {
  return gulp
    .src('./tests/**/*.js')
    .pipe(sourcemaps.init())
    .pipe(babel({ configFile: './.babelrc' }))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('./dist'));
});

gulp.task('watch', ['build'], () => {
  livereload.listen();
  gulp.watch('./src/*.js', ['build']);
});

gulp.task('runTests', () => {
  return gulp
    .src(['./dist/**/*.test.js'], { read: false })
    .pipe(
      mocha({
        require: ['source-map-support/register'],
        reporter: 'spec'
      })
    )
    .once('error', () => process.exit(1))
    .once('end', () => process.exit());
});

gulp.task('test', done => {
  sequence('lint', 'buildTests', 'runTests', done);
});

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


<commit_before>'use strict';

var gulp = require('gulp');
// var gutil = require('gulp-util');
var sourcemaps = require('gulp-sourcemaps');
var transform = require('vinyl-transform');
var rename = require('gulp-rename');
var browserify = require('browserify');
var mocha = require('gulp-mocha');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
// var minifyCSS = require('gulp-minify-css');
var karma = require('karma');
var protractor = require('gulp-protractor').protractor;
var webdriver = require('gulp-protractor').webdriver;
// var webdriver_standalone = webdriver.webdriver_standalone;
var webdriverUpdate = require('gulp-protractor').webdriver_update;

var nodeFilesToWatch = ['app.js', 'api/**/*.js'];
var nodeTestFiles = ['api/**/test/*.js'];

/*
    Api tasks
*/
gulp.task('mocha', function () {
    return gulp.src(nodeTestFiles, {read: false})
        .pipe(mocha({reporter: 'spec'}));
});

gulp.task('lint-api', function() {
    return gulp.src(['app.js', './api/**/*.js'])
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

/*
    Client tasks
*/
gulp.task('browserify', function() {
    var bundle = transform(function(filename) {
        var b = browserify({
            entries: filename,
            debug: true,
            insertGlobals: true
        });
        return b.bundle();
    });

    return gulp.src(['./client/main.js'])
        .pipe(bundle)
        .pipe(sourcemaps.init({loadMaps: true}))
        // .pipe(uglify())
        .pipe(rename('bundle.js'))
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest('./public'));
});

gulp.task('views', function () {
    gulp.src('client/index.html')
        .pipe(gulp.dest('public/'));

    gulp.src('client/todo/*.html')
        .pipe(gulp.dest('public/todo/'));
});

gulp.task('sass', function () {
    gulp.src('client/sass/*.scss')
        .pipe(sass({ onError: function (err) {
            console.error(err);
        }}))
        .pipe(autoprefixer('last 2 versions', '> 1%', 'ie 8'))
        .pipe(gulp.dest('public/css/'));
});

gulp.task('lint-client', function() {
    return gulp.src(['client/**/*.js', '!client/test/*.js'])
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

gulp.task('webdriver-update', webdriverUpdate);
gulp.task('webdriver', webdriver);

// gulp.task('webdriver_standalone', webdriver_standalone);

gulp.task('protractor', ['webdriver-update', 'webdriver'], function () {

    return gulp.src('client/**/test/*.e2e.js')
        .pipe(protractor({
            configFile: './protractor.conf.js',
            args: ['--baseUrl', 'http://127.0.0.1:3000']
        }))
        .on('error', function(err) {
            // Make sure failed tests cause gulp to exit non-zero
            throw err;
        });

});

/*
    Watchers
*/
gulp.task('watch', function () {
    gulp.watch(['app.js', 'api/**/*.js'], ['lint-api']);
    gulp.watch(['client/**/*.js', '!client/test/*.js'], ['lint-client', 'browserify']);
    gulp.watch(['client/**/*.html'], ['views']);
    gulp.watch(['client/sass/*.scss'], ['sass']);
});

gulp.task('test', function () {
    gulp.watch(nodeFilesToWatch, ['mocha']);
    karma.server.start({
        configFile: __dirname + '/karma.conf.js'
    });
});
<commit_msg>added protractor to gulp watch<commit_after>'use strict';

var gulp = require('gulp');
// var gutil = require('gulp-util');
var sourcemaps = require('gulp-sourcemaps');
var transform = require('vinyl-transform');
var rename = require('gulp-rename');
var browserify = require('browserify');
var mocha = require('gulp-mocha');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var jshint = require('gulp-jshint');
// var uglify = require('gulp-uglify');
// var minifyCSS = require('gulp-minify-css');
var karma = require('karma');
var protractor = require('gulp-protractor').protractor;
var webdriver = require('gulp-protractor').webdriver;
// var webdriver_standalone = webdriver.webdriver_standalone;
var webdriverUpdate = require('gulp-protractor').webdriver_update;

var nodeFilesToWatch = ['app.js', 'api/**/*.js'];
var nodeTestFiles = ['api/**/test/*.js'];

/*
    Api tasks
*/
gulp.task('mocha', function () {
    return gulp.src(nodeTestFiles, {read: false})
        .pipe(mocha({reporter: 'spec'}));
});

gulp.task('lint-api', function() {
    return gulp.src(['app.js', './api/**/*.js'])
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

/*
    Client tasks
*/
gulp.task('browserify', function() {
    var bundle = transform(function(filename) {
        var b = browserify({
            entries: filename,
            debug: true,
            insertGlobals: true
        });
        return b.bundle();
    });

    return gulp.src(['./client/main.js'])
        .pipe(bundle)
        .pipe(sourcemaps.init({loadMaps: true}))
        // .pipe(uglify())
        .pipe(rename('bundle.js'))
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest('./public'));
});

gulp.task('views', function () {
    gulp.src('client/index.html')
        .pipe(gulp.dest('public/'));

    gulp.src('client/todo/*.html')
        .pipe(gulp.dest('public/todo/'));
});

gulp.task('sass', function () {
    gulp.src('client/sass/*.scss')
        .pipe(sass({ onError: function (err) {
            console.error(err);
        }}))
        .pipe(autoprefixer('last 2 versions', '> 1%', 'ie 8'))
        .pipe(gulp.dest('public/css/'));
});

gulp.task('lint-client', function() {
    return gulp.src(['client/**/*.js', '!client/test/*.js'])
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

gulp.task('webdriver-update', webdriverUpdate);
gulp.task('webdriver', webdriver);

// gulp.task('webdriver_standalone', webdriver_standalone);

gulp.task('protractor', ['webdriver-update', 'webdriver'], function () {

    return gulp.src('client/**/test/*.e2e.js')
        .pipe(protractor({
            configFile: './protractor.conf.js',
            args: ['--baseUrl', 'http://127.0.0.1:3000']
        }))
        .on('error', function(err) {
            // Make sure failed tests cause gulp to exit non-zero
            throw err;
        });

});

/*
    Watchers
*/
gulp.task('watch', function () {
    gulp.watch(['app.js', 'api/**/*.js'], ['lint-api']);
    gulp.watch(['client/**/*.js', '!client/test/*.js'], ['lint-client', 'browserify', 'protractor']);
    gulp.watch(['client/**/*.html'], ['views']);
    gulp.watch(['client/sass/*.scss'], ['sass']);
});

gulp.task('test', function () {
    gulp.watch(nodeFilesToWatch, ['mocha']);
    karma.server.start({
        configFile: __dirname + '/karma.conf.js'
    });
});
<|endoftext|>


<commit_before>var gulp = require('gulp');
var concat = require('gulp-concat');
var rev = require('gulp-rev');
var minifyCSS = require('gulp-cssnano');
var uglifyJS = require('gulp-uglify');

gulp.task('copy-fonts', function() {
  var fontPaths = [
    './public/vendor/bootstrap/fonts/**',
    './public/vendor/font-awesome/fonts/**'
  ];
  gulp.src(fontPaths)
      .pipe(gulp.dest('./dist/fonts/'));
});

gulp.task('build-css', ['copy-fonts'], function() {
  var cssPaths = [
    './public/vendor/bootstrap/css/bootstrap.css',
    './public/vendor/bootstrap/css/bootstrap-theme.css',
    './public/vendor/font-awesome/css/font-awesome.css',
    './public/vendor/bootstrap-markdown/css/bootstrap-markdown.min.css',
    './public/css/bootstrap_overrides.css',
    './public/css/general.css'
  ];
  gulp.src(cssPaths)
      .pipe(concat('all.css'))
      .pipe(minifyCSS())
      .pipe(gulp.dest('./dist/'));
});

gulp.task('build-js', function() {
  var jsPaths = [
    'public/vendor/jquery/jquery-2.1.3.min.js',
    'public/vendor/jquery-hotkeys/jquery.hotkeys.js',
    'public/vendor/timeago/jquery.timeago.js',
    'public/vendor/markdown/markdown.js',
    'public/vendor/bootstrap-markdown/js/bootstrap-markdown.js',
    'public/vendor/jquery-appear/jquery.appear.js',
    'public/vendor/bootstrap/js/bootstrap.js',
    'public/vendor/js/bootstrap.js',
    // Symlinked to node_modules/autolinker
    'public/vendor/autolinker/dist/Autolinker.js',
    'public/vendor/xbbcode/xbbcode/bbcode.js', // Symlinked to server/bbcode.js
    // Don't bundle typeahead since it's just used on edit_topic.js right now
    // 'public/vendor/typeahead/typeahead.bundle.js',
    'public/js/bbcode_editor.js',
  ];
  gulp.src(jsPaths)
      .pipe(concat('all.js'))
      .pipe(uglifyJS())
      .pipe(gulp.dest('./dist/'));
});

gulp.task('build-chat-js', function() {
  var paths = [
    'public/js/chat.js'
  ];
  gulp.src(paths)
    .pipe(concat('chat.js'))
    .pipe(uglifyJS())
    .pipe(gulp.dest('./dist/'));
});

//
// Note: I usually have to run `gulp build-assets` twice for it
// to work. Need to look into why.
//
gulp.task('build-assets', ['build-css', 'build-js', 'build-chat-js'], function() {
  gulp.src(['dist/all.css', 'dist/all.js', 'dist/chat.js'])
  .pipe(rev())
  .pipe(gulp.dest('dist'))
  .pipe(rev.manifest())
  .pipe(gulp.dest('dist'));
});
<commit_msg>Fix gulpfile<commit_after>var gulp = require('gulp');
var concat = require('gulp-concat');
var rev = require('gulp-rev');
var minifyCSS = require('gulp-cssnano');
var uglifyJS = require('gulp-uglify');

gulp.task('copy-fonts', function() {
  var fontPaths = [
    './public/vendor/bootstrap/fonts/**',
    './public/vendor/font-awesome/fonts/**'
  ];
  return gulp.src(fontPaths)
      .pipe(gulp.dest('./dist/fonts/'));
});

gulp.task('build-css', ['copy-fonts'], function() {
  var cssPaths = [
    './public/vendor/bootstrap/css/bootstrap.css',
    './public/vendor/bootstrap/css/bootstrap-theme.css',
    './public/vendor/font-awesome/css/font-awesome.css',
    './public/vendor/bootstrap-markdown/css/bootstrap-markdown.min.css',
    './public/css/bootstrap_overrides.css',
    './public/css/general.css'
  ];
  return gulp.src(cssPaths)
      .pipe(concat('all.css'))
      .pipe(minifyCSS())
      .pipe(gulp.dest('./dist/'));
});

gulp.task('build-js', function() {
  var jsPaths = [
    'public/vendor/jquery/jquery-2.1.3.min.js',
    'public/vendor/jquery-hotkeys/jquery.hotkeys.js',
    'public/vendor/timeago/jquery.timeago.js',
    'public/vendor/markdown/markdown.js',
    'public/vendor/bootstrap-markdown/js/bootstrap-markdown.js',
    'public/vendor/jquery-appear/jquery.appear.js',
    'public/vendor/bootstrap/js/bootstrap.js',
    'public/vendor/js/bootstrap.js',
    // Symlinked to node_modules/autolinker
    'public/vendor/autolinker/dist/Autolinker.js',
    'public/vendor/xbbcode/xbbcode/bbcode.js', // Symlinked to server/bbcode.js
    // Don't bundle typeahead since it's just used on edit_topic.js right now
    // 'public/vendor/typeahead/typeahead.bundle.js',
    'public/js/bbcode_editor.js',
  ];
  return gulp.src(jsPaths)
      .pipe(concat('all.js'))
      .pipe(uglifyJS())
      .pipe(gulp.dest('./dist/'));
});

gulp.task('build-chat-js', function() {
  var paths = [
    'public/js/chat.js'
  ];
  return gulp.src(paths)
    .pipe(concat('chat.js'))
    .pipe(uglifyJS())
    .pipe(gulp.dest('./dist/'));
});

//
// Note: I usually have to run `gulp build-assets` twice for it
// to work. Need to look into why.
//
gulp.task('build-assets', ['build-css', 'build-js', 'build-chat-js'], function() {
  return gulp.src(['dist/all.css', 'dist/all.js', 'dist/chat.js'])
  .pipe(rev())
  .pipe(gulp.dest('dist'))
  .pipe(rev.manifest())
  .pipe(gulp.dest('dist'));
});
<|endoftext|>


<commit_before>'use strict';

// Includes packages
var gulp 				= require('gulp');
var sass 				= require('gulp-sass');
var autoprefixer 		= require('gulp-autoprefixer');
var mergeMediaQueries 	= require('gulp-merge-media-queries');
var cleanCss 			= require('gulp-clean-css');
var notify 				= require('gulp-notify');

// Paths variables
var paths = {
	dist		: 'dist',
	mainsass 	: ['src/style.scss'],
	scss 		: ['src/**/*.scss' ]
};

// Compile SASS
gulp.task('sass', function () {
	return gulp.src(paths.scss)
		.pipe(sass().on('error', sass.logError))
		.pipe(autoprefixer({browsers: ['IE 8', 'IE 9', 'last 5 versions']}))
		.pipe(mergeMediaQueries())
		.pipe(cleanCss())
		.pipe(gulp.dest(paths.dist))
		.pipe(notify({ message: 'Task SASS. Compiled successful. Happy Code!', onLast: true}));
});

// Rerun the task when a file changes
gulp.task('watch', function() {
	gulp.watch(paths.scss, ['sass']);
});

// Run default task
gulp.task('default', ['sass', 'watch']);<commit_msg>Change task<commit_after>'use strict';

// Includes packages
var gulp 				= require('gulp');
var sass 				= require('gulp-sass');
var autoprefixer 		= require('gulp-autoprefixer');
var mergeMediaQueries 	= require('gulp-merge-media-queries');
var cleanCss 			= require('gulp-clean-css');
var notify 				= require('gulp-notify');

// Paths variables
var paths = {
	dist		: 'dist',
	mainsass 	: ['src/style.scss'],
	scss 		: ['src/**/*.scss' ]
};

// Compile SASS
gulp.task('sass', function () {
	return gulp.src(paths.scss)
		.pipe(sass().on('error', sass.logError))
		.pipe(autoprefixer({browsers: ['IE 8', 'IE 9', 'last 5 versions']}))
		.pipe(mergeMediaQueries())
		.pipe(cleanCss())
		.pipe(gulp.dest(paths.dist))
		.pipe(notify({ message: 'Task SASS. Compiled successful.', onLast: true}));
});

// Rerun the task when a file changes
gulp.task('watch', function() {
	gulp.watch(paths.scss, ['sass']);
});

// Run default task
gulp.task('default', ['sass', 'watch']);<|endoftext|>