<commit_before>'use strict';

require('babel-polyfill');
var gulp = require('gulp');
var gulpLoadPlugins = require('gulp-load-plugins');
var del = require('del');
var lazypipe = require('lazypipe');
var browserSync = require('browser-sync');
var rsync = require('rsyncwrapper');
var sseries = require('stream-series');

// Auto load Gulp plugins
const plugins = gulpLoadPlugins({
  rename: {
    'gulp-util': 'gulpUtil',
    'gulp-inject': 'inject',
    'gulp-htmlmin': 'htmlmin',
    'gulp-htmltidy': 'htmltidy',
    'gulp-gm': 'gm',
    'gulp-imageoptim': 'imageOptim'
  }
});

// Simplify calls to browser-sync
const sync = browserSync.create();

//
// Import task configuration
var config = require('./config/config.js');

//
// Image processing via gulp-gm
function imgMagic() {
  return gulp.src('src/img_raw/*.{jpg,png}')
    .pipe(plugins.gm( function (gmfile) {
      return gmfile
        .resize(1280, 1024);
    }))
    //.pipe(plugins.rename(config.magicRename))
    .pipe(gulp.dest('src/img_tmp/'));
}

//
// Responsive Images
// Generate diiferent sized images for srcset
function imgResponsive() {
  return gulp.src('src/img_tmp/**/*.{jpg,png}')
    .pipe(plugins.responsive(config.responsiveOptions, config.responsiveGlobals))
    .pipe(gulp.dest('src/img_responsive/'));
}

//
// Optimize responsive images and copy to final location
function imgOptim () {
  return gulp.src('src/img_responsive/**/*.{jpg,png}')
    .pipe(plugins.imageOptim.optimize(config.imageoptimOptions))
    .pipe(gulp.dest('hugo/static/images/'));
}

//
// Optimize and copy svg or gif images to final destination
function imgMin () {
  return gulp.src('src/img_tmp/**/*.{svg,gif}')
    .pipe(plugins.imagemin(config.imageminOptions))
    .pipe(gulp.dest('hugo/static/images/'));
}

//
// CSS processing
function postCss () {
  return gulp.src('src/styles/*.css', { since: gulp.lastRun(postCss) })
    .pipe(plugins.postcss(config.processors))
    .pipe(gulp.dest('hugo/static/styles/'))
    .pipe(sync.stream());
}

// CSS processing, minification
function minpostCss () {
  return gulp.src('src/styles/*.css', { since: gulp.lastRun(postCss) })
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.postcss(config.minProcessors))
    .pipe(plugins.rename({extname: '.min.css'}))
    .pipe(plugins.sourcemaps.write('.'))
    .pipe(gulp.dest('hugo/static/styles/'));
}

// Copy Vendor CSS into hugo/static
gulp.task('vendorStyles', () => {
  return gulp.src('src/styles_vendor/*.css', { since: gulp.lastRun('vendorStyles') })
    .pipe(gulp.dest('hugo/static/styles_vendor/'));
});

//
// Javascript processing
//
// Linting
// .eslintrc.json can be used by your editor (see README.md)
// eslint rules for js aimed at browser are in config/
let lintJs = lazypipe()
    .pipe(plugins.eslint, 'config/eslint.json')
    .pipe(plugins.eslint.format);

// dev js tasks
function scripts () {
  return gulp.src('src/scripts/*.js', { since: gulp.lastRun(scripts) })
    .pipe(lintJs())
    .pipe(gulp.dest('hugo/static/scripts/'))
  .  pipe(sync.stream());
}
function scriptsHead () {
  return gulp.src('src/scripts_head/*.js', { since: gulp.lastRun(scriptsHead) })
    .pipe(lintJs())
    .pipe(gulp.dest('hugo/static/scripts_head/'))
    .pipe(sync.stream());
}

// Javascript minification and source mapping
// TODO Possibly add concatenation (not really needed when served via HTTP2)
let minJs = lazypipe()
    .pipe(plugins.sourcemaps.init)
      .pipe(plugins.uglify)
      .pipe(plugins.rename, {extname: '.min.js'})
    .pipe(plugins.sourcemaps.write, '.');

// stage and live js tasks
function minscripts () {
  return gulp.src('src/scripts/*.js', { since: gulp.lastRun(minscripts) })
    .pipe(minJs())
    .pipe(gulp.dest('hugo/static/scripts/'));
}
function minscriptsHead () {
  return gulp.src('src/scripts_head/*.js', { since: gulp.lastRun(minscriptsHead) })
    .pipe(minJs())
    .pipe(gulp.dest('hugo/static/scripts_head/'));
}

// Modernizr
// Read custom config and generate a custom build , already minified
gulp.task('custoModernizr', () => {
  let exec = require('child_process').exec;
  let cmd = './node_modules/.bin/modernizr ';
  cmd += '-c ./config/modernizr-config.json ';
  cmd += '-d ./hugo/static/scripts_vendor/modernizr.custom.js';
  return exec(cmd, {encoding: 'utf-8'});
});

// Copy picturefill.js
gulp.task('picturefill', () => {
  return gulp.src('node_modules/picturefill/dist/picturefill.min.js', { since: gulp.lastRun('picturefill') })
    .pipe(gulp.dest('hugo/static/scripts_vendor/'));
});

//
// HTML templates
// Copy HTML templates from src/layouts to hugo/layouts
// We cant lint and minify here because of hugo specific code
function html () {
  return gulp.src('src/layouts/**/*.html', { since: gulp.lastRun(html) })
    .pipe(gulp.dest('hugo/layouts/'));
}

//
// Inject css and js into templates
function injectHead () {
  let picturefillPath = gulp.src('hugo/static/scripts_vendor/picturefill.min.js', {read: false});
  let modernizrPath = gulp.src(['hugo/static/scripts_vendor/modernizr.custom.js'], {read: false});
  let scriptsHead = gulp.src('hugo/static/scripts_head/*.js', {read: false});
  let vendorCss = gulp.src('hugo/static/styles_vendor/*.css', {read: false});
  let projectCss = gulp.src('hugo/static/styles/*.css', {read: false});

  return gulp.src('hugo/layouts/partials/head-meta.html')
    .pipe(plugins.inject(sseries(picturefillPath, modernizrPath, scriptsHead),
      {selfClosingTag: true, ignorePath: 'hugo/static/', name: 'head'}))
    .pipe(plugins.inject(sseries(vendorCss, projectCss), {ignorePath: 'hugo/static/'}))
    .pipe(gulp.dest('hugo/layouts/partials/'));
}

function injectFoot () {
  return gulp.src('hugo/layouts/partials/footer-scripts.html')
    .pipe(plugins.inject(gulp.src(['hugo/static/scripts/*.js'],
      {read: false}), {ignorePath: 'hugo/static/'}))
    .pipe(gulp.dest('hugo/layouts/partials/'));
}

//
// Hugo
// -D is buildDrafts
// -F is buildFuture
function hugo (status) {
  let exec = require('child_process').execSync;
  let cmd = 'hugo --config=hugo/config.toml -s hugo/';
  if (status === 'stage') {
    cmd += ' -D -d published/stage/ --baseURL="' + config.hugoBaseUrl.stage + '"';
    plugins.gulpUtil.log('hugo command: \n' + cmd);
  } else if (status === 'live') {
    cmd += ' -d published/live/ --baseURL="' + config.hugoBaseUrl.live + '"';
    plugins.gulpUtil.log('hugo command: \n' + cmd);
  } else {
    cmd += ' -DF -d published/dev/ --baseURL="' + config.hugoBaseUrl.dev + '"';
    plugins.gulpUtil.log('hugo command: \n' + cmd);
  }

  let result = exec(cmd, {encoding: 'utf-8'});
  plugins.gulpUtil.log('hugo reports: \n' + result);
}

gulp.task('hugoDev', () => {
  return Promise.all([ hugo() ]);
});

gulp.task('hugoStage', () => {
  return Promise.all([ hugo('stage') ]);
});

gulp.task('hugoLive', () => {
  return Promise.all([ hugo('live') ]);
});

//
// HTML linting & minification
gulp.task('htmlDev', () => {
  return gulp.src('hugo/published/dev/**/*.html', { since: gulp.lastRun('htmlDev') })
    .pipe(plugins.htmltidy(config.htmltidyOptions))
    .pipe(gulp.dest('hugo/published/dev/'));
});

gulp.task('htmlStage', () => {
  return gulp.src('hugo/published/stage/**/*.html')
    .pipe(plugins.htmltidy(config.htmltidyOptions))
    .pipe(plugins.htmlmin(config.htmlminOptions))
    .pipe(gulp.dest('hugo/published/stage/'));
});

gulp.task('htmlLive', () => {
  return gulp.src('hugo/published/live/**/*.html')
    .pipe(plugins.htmltidy(config.htmltidyOptions))
    .pipe(plugins.htmlmin(config.htmlminOptions))
    .pipe(gulp.dest('hugo/published/live/'));
});

//
// Testing
// Jasmine, Mocha...
// TODO: what to test?

//
// Cleaning
// Specific cleaning functions for dev/stage/live of hugo/published.
function cleanDev (done) {
  return del(['hugo/published/dev/'], done);
}
function cleanStage (done) {
  return del(['hugo/published/stage/'], done);
}
function cleanLive (done) {
  return del(['hugo/published/live/'], done);
}

// Clean any assets we output into hugo/static (except images)
function cleanStatic (done) {
  return del([
    'hugo/static/scripts/*',
    'hugo/static/scripts_head/*',
    'hugo/static/scripts_vendor/*',
    'hugo/static/styles/*'
  ], done);
}

// Clean any assets we output into hugo/layouts
function cleanLayouts (done) {
  return del(['hugo/layouts/**/*.html'], done);
}

// Clean temporary image files created during processing
function cleanImages (done) {
  return del([
    'src/img_tmp/**/*',
    'hugo/static/images/*',
    'src/img_responsive/*',
    'hugo/static/images/responsive/*'
  ], done);
}

// Clean only responsive image derivatives
function cleanResponsive (done) {
  return del([
    'src/img_responsive/*',
    'hugo/static/images/responsive/*'
  ], done);
}

//
// Watch files and serve with Browsersync
gulp.task('watchnsync', () => {
  sync.init({
    server: {
      baseDir: 'hugo/published/dev'
    }
  });

  gulp.watch('src/img_tmp', gulp.series('responsive', imgOptim, imgMin, 'hugoDev', 'htmlDev'));
  gulp.watch('src/sass/*.scss', gulp.series(postCss, injectHead, 'hugoDev', 'htmlDev'));
  gulp.watch('config/modernizr-config.json', gulp.series('custoModernizr', injectHead, 'hugoDev', 'htmlDev'));
  gulp.watch('src/scripts/*.js', gulp.series(scripts, injectFoot, 'hugoDev', 'htmlDev'));
  gulp.watch('src/scripts_head/*.js', gulp.series(scriptsHead, injectHead, 'hugoDev', 'htmlDev'));
  gulp.watch('src/layouts/**/*.html', gulp.series(injectHead, injectFoot, 'hugoDev','htmlDev'));
  gulp.watch([
    'hugo/archetypes/*',
    'hugo/content/',
    'hugo/data/'
  ], gulp.series('hugoDev')).on('change', sync.reload);
});

//
// Deploy

// Deploy to staging
gulp.task('upstage', () => {
  return Promise.all([
    rsync(config.stageRsyncOptions, function(error, stdout, stderr, cmd) {
      plugins.gulpUtil.log('Running: ' + cmd);
      plugins.gulpUtil.log(stdout);
    })
  ]);
});

// Deploy to live
gulp.task('golive', () => {
  return Promise.all([
    rsync(config.liveRsyncOptions, function(error, stdout, stderr, cmd) {
      plugins.gulpUtil.log('Running: ' + cmd);
      plugins.gulpUtil.log(stdout);
    })
  ]);
});

//
// 'gulp' is the main development task, essentially dev + watch + browsersync
gulp.task('default',
  gulp.series(
    gulp.parallel(cleanStatic, cleanLayouts, cleanDev),
    gulp.parallel('custoModernizr', postCss, scripts, scriptsHead),
    gulp.parallel(html, 'picturefill', 'vendorStyles'),
    gulp.parallel(injectHead, injectFoot),
    'hugoDev',
    'htmlDev',
    'watchnsync'
  )
);
// 'gulp dev' a single run, hugo will generate pages for drafts and future posts
gulp.task('dev',
  gulp.series(
    gulp.parallel(cleanStatic, cleanLayouts, cleanDev),
    gulp.parallel('custoModernizr', postCss, scripts, scriptsHead),
    gulp.parallel(html, 'picturefill', 'vendorStyles'),
    gulp.parallel(injectHead, injectFoot),
    'hugoDev',
    'htmlDev'
  )
);
// 'gulp stage' a single run, hugo will generate pages for drafts
gulp.task('stage',
  gulp.series(
    gulp.parallel(cleanStatic, cleanLayouts, cleanStage),
    gulp.parallel('custoModernizr', minpostCss, minscripts, minscriptsHead),
    gulp.parallel(html, 'picturefill', 'vendorStyles'),
    gulp.parallel(injectHead, injectFoot),
    'hugoStage',
    'htmlStage'
  )
);
// 'gulp live' a single run, production only
gulp.task('live',
  gulp.series(
    gulp.parallel(cleanStatic, cleanLayouts, cleanLive),
    gulp.parallel('custoModernizr', minpostCss, minscripts, minscriptsHead),
    gulp.parallel(html, 'picturefill', 'vendorStyles'),
    gulp.parallel(injectHead, injectFoot),
    'hugoLive',
    'htmlLive'
  )
);

// Clean and regenerate all images
gulp.task('reprocess', gulp.series(cleanImages, imgMagic, imgResponsive, imgOptim, imgMin));
// Clean and regenerate responsive images (use after modifying responsive config)
gulp.task('reprocess:responsive', gulp.series(cleanResponsive, imgResponsive, imgOptim));

// Task used for debugging function based task or tasks
gulp.task('dt', gulp.series('vendorStyles', injectHead));
<commit_msg>Add styles_vendor to static folder cleaning task.<commit_after>'use strict';

require('babel-polyfill');
var gulp = require('gulp');
var gulpLoadPlugins = require('gulp-load-plugins');
var del = require('del');
var lazypipe = require('lazypipe');
var browserSync = require('browser-sync');
var rsync = require('rsyncwrapper');
var sseries = require('stream-series');

// Auto load Gulp plugins
const plugins = gulpLoadPlugins({
  rename: {
    'gulp-util': 'gulpUtil',
    'gulp-inject': 'inject',
    'gulp-htmlmin': 'htmlmin',
    'gulp-htmltidy': 'htmltidy',
    'gulp-gm': 'gm',
    'gulp-imageoptim': 'imageOptim'
  }
});

// Simplify calls to browser-sync
const sync = browserSync.create();

//
// Import task configuration
var config = require('./config/config.js');

//
// Image processing via gulp-gm
function imgMagic() {
  return gulp.src('src/img_raw/*.{jpg,png}')
    .pipe(plugins.gm( function (gmfile) {
      return gmfile
        .resize(1280, 1024);
    }))
    //.pipe(plugins.rename(config.magicRename))
    .pipe(gulp.dest('src/img_tmp/'));
}

//
// Responsive Images
// Generate diiferent sized images for srcset
function imgResponsive() {
  return gulp.src('src/img_tmp/**/*.{jpg,png}')
    .pipe(plugins.responsive(config.responsiveOptions, config.responsiveGlobals))
    .pipe(gulp.dest('src/img_responsive/'));
}

//
// Optimize responsive images and copy to final location
function imgOptim () {
  return gulp.src('src/img_responsive/**/*.{jpg,png}')
    .pipe(plugins.imageOptim.optimize(config.imageoptimOptions))
    .pipe(gulp.dest('hugo/static/images/'));
}

//
// Optimize and copy svg or gif images to final destination
function imgMin () {
  return gulp.src('src/img_tmp/**/*.{svg,gif}')
    .pipe(plugins.imagemin(config.imageminOptions))
    .pipe(gulp.dest('hugo/static/images/'));
}

//
// CSS processing
function postCss () {
  return gulp.src('src/styles/*.css', { since: gulp.lastRun(postCss) })
    .pipe(plugins.postcss(config.processors))
    .pipe(gulp.dest('hugo/static/styles/'))
    .pipe(sync.stream());
}

// CSS processing, minification
function minpostCss () {
  return gulp.src('src/styles/*.css', { since: gulp.lastRun(postCss) })
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.postcss(config.minProcessors))
    .pipe(plugins.rename({extname: '.min.css'}))
    .pipe(plugins.sourcemaps.write('.'))
    .pipe(gulp.dest('hugo/static/styles/'));
}

// Copy Vendor CSS into hugo/static
gulp.task('vendorStyles', () => {
  return gulp.src('src/styles_vendor/*.css', { since: gulp.lastRun('vendorStyles') })
    .pipe(gulp.dest('hugo/static/styles_vendor/'));
});

//
// Javascript processing
//
// Linting
// .eslintrc.json can be used by your editor (see README.md)
// eslint rules for js aimed at browser are in config/
let lintJs = lazypipe()
    .pipe(plugins.eslint, 'config/eslint.json')
    .pipe(plugins.eslint.format);

// dev js tasks
function scripts () {
  return gulp.src('src/scripts/*.js', { since: gulp.lastRun(scripts) })
    .pipe(lintJs())
    .pipe(gulp.dest('hugo/static/scripts/'))
  .  pipe(sync.stream());
}
function scriptsHead () {
  return gulp.src('src/scripts_head/*.js', { since: gulp.lastRun(scriptsHead) })
    .pipe(lintJs())
    .pipe(gulp.dest('hugo/static/scripts_head/'))
    .pipe(sync.stream());
}

// Javascript minification and source mapping
// TODO Possibly add concatenation (not really needed when served via HTTP2)
let minJs = lazypipe()
    .pipe(plugins.sourcemaps.init)
      .pipe(plugins.uglify)
      .pipe(plugins.rename, {extname: '.min.js'})
    .pipe(plugins.sourcemaps.write, '.');

// stage and live js tasks
function minscripts () {
  return gulp.src('src/scripts/*.js', { since: gulp.lastRun(minscripts) })
    .pipe(minJs())
    .pipe(gulp.dest('hugo/static/scripts/'));
}
function minscriptsHead () {
  return gulp.src('src/scripts_head/*.js', { since: gulp.lastRun(minscriptsHead) })
    .pipe(minJs())
    .pipe(gulp.dest('hugo/static/scripts_head/'));
}

// Modernizr
// Read custom config and generate a custom build , already minified
gulp.task('custoModernizr', () => {
  let exec = require('child_process').exec;
  let cmd = './node_modules/.bin/modernizr ';
  cmd += '-c ./config/modernizr-config.json ';
  cmd += '-d ./hugo/static/scripts_vendor/modernizr.custom.js';
  return exec(cmd, {encoding: 'utf-8'});
});

// Copy picturefill.js
gulp.task('picturefill', () => {
  return gulp.src('node_modules/picturefill/dist/picturefill.min.js', { since: gulp.lastRun('picturefill') })
    .pipe(gulp.dest('hugo/static/scripts_vendor/'));
});

//
// HTML templates
// Copy HTML templates from src/layouts to hugo/layouts
// We cant lint and minify here because of hugo specific code
function html () {
  return gulp.src('src/layouts/**/*.html', { since: gulp.lastRun(html) })
    .pipe(gulp.dest('hugo/layouts/'));
}

//
// Inject css and js into templates
function injectHead () {
  let picturefillPath = gulp.src('hugo/static/scripts_vendor/picturefill.min.js', {read: false});
  let modernizrPath = gulp.src(['hugo/static/scripts_vendor/modernizr.custom.js'], {read: false});
  let scriptsHead = gulp.src('hugo/static/scripts_head/*.js', {read: false});
  let vendorCss = gulp.src('hugo/static/styles_vendor/*.css', {read: false});
  let projectCss = gulp.src('hugo/static/styles/*.css', {read: false});

  return gulp.src('hugo/layouts/partials/head-meta.html')
    .pipe(plugins.inject(sseries(picturefillPath, modernizrPath, scriptsHead),
      {selfClosingTag: true, ignorePath: 'hugo/static/', name: 'head'}))
    .pipe(plugins.inject(sseries(vendorCss, projectCss), {ignorePath: 'hugo/static/'}))
    .pipe(gulp.dest('hugo/layouts/partials/'));
}

function injectFoot () {
  return gulp.src('hugo/layouts/partials/footer-scripts.html')
    .pipe(plugins.inject(gulp.src(['hugo/static/scripts/*.js'],
      {read: false}), {ignorePath: 'hugo/static/'}))
    .pipe(gulp.dest('hugo/layouts/partials/'));
}

//
// Hugo
// -D is buildDrafts
// -F is buildFuture
function hugo (status) {
  let exec = require('child_process').execSync;
  let cmd = 'hugo --config=hugo/config.toml -s hugo/';
  if (status === 'stage') {
    cmd += ' -D -d published/stage/ --baseURL="' + config.hugoBaseUrl.stage + '"';
    plugins.gulpUtil.log('hugo command: \n' + cmd);
  } else if (status === 'live') {
    cmd += ' -d published/live/ --baseURL="' + config.hugoBaseUrl.live + '"';
    plugins.gulpUtil.log('hugo command: \n' + cmd);
  } else {
    cmd += ' -DF -d published/dev/ --baseURL="' + config.hugoBaseUrl.dev + '"';
    plugins.gulpUtil.log('hugo command: \n' + cmd);
  }

  let result = exec(cmd, {encoding: 'utf-8'});
  plugins.gulpUtil.log('hugo reports: \n' + result);
}

gulp.task('hugoDev', () => {
  return Promise.all([ hugo() ]);
});

gulp.task('hugoStage', () => {
  return Promise.all([ hugo('stage') ]);
});

gulp.task('hugoLive', () => {
  return Promise.all([ hugo('live') ]);
});

//
// HTML linting & minification
gulp.task('htmlDev', () => {
  return gulp.src('hugo/published/dev/**/*.html', { since: gulp.lastRun('htmlDev') })
    .pipe(plugins.htmltidy(config.htmltidyOptions))
    .pipe(gulp.dest('hugo/published/dev/'));
});

gulp.task('htmlStage', () => {
  return gulp.src('hugo/published/stage/**/*.html')
    .pipe(plugins.htmltidy(config.htmltidyOptions))
    .pipe(plugins.htmlmin(config.htmlminOptions))
    .pipe(gulp.dest('hugo/published/stage/'));
});

gulp.task('htmlLive', () => {
  return gulp.src('hugo/published/live/**/*.html')
    .pipe(plugins.htmltidy(config.htmltidyOptions))
    .pipe(plugins.htmlmin(config.htmlminOptions))
    .pipe(gulp.dest('hugo/published/live/'));
});

//
// Testing
// Jasmine, Mocha...
// TODO: what to test?

//
// Cleaning
// Specific cleaning functions for dev/stage/live of hugo/published.
function cleanDev (done) {
  return del(['hugo/published/dev/'], done);
}
function cleanStage (done) {
  return del(['hugo/published/stage/'], done);
}
function cleanLive (done) {
  return del(['hugo/published/live/'], done);
}

// Clean any assets we output into hugo/static (except images)
function cleanStatic (done) {
  return del([
    'hugo/static/scripts/*',
    'hugo/static/scripts_head/*',
    'hugo/static/scripts_vendor/*',
    'hugo/static/styles/*',
    'hugo/static/styles_vendor/*'
  ], done);
}

// Clean any assets we output into hugo/layouts
function cleanLayouts (done) {
  return del(['hugo/layouts/**/*.html'], done);
}

// Clean temporary image files created during processing
function cleanImages (done) {
  return del([
    'src/img_tmp/**/*',
    'hugo/static/images/*',
    'src/img_responsive/*',
    'hugo/static/images/responsive/*'
  ], done);
}

// Clean only responsive image derivatives
function cleanResponsive (done) {
  return del([
    'src/img_responsive/*',
    'hugo/static/images/responsive/*'
  ], done);
}

//
// Watch files and serve with Browsersync
gulp.task('watchnsync', () => {
  sync.init({
    server: {
      baseDir: 'hugo/published/dev'
    }
  });

  gulp.watch('src/img_tmp', gulp.series('responsive', imgOptim, imgMin, 'hugoDev', 'htmlDev'));
  gulp.watch('src/sass/*.scss', gulp.series(postCss, injectHead, 'hugoDev', 'htmlDev'));
  gulp.watch('config/modernizr-config.json', gulp.series('custoModernizr', injectHead, 'hugoDev', 'htmlDev'));
  gulp.watch('src/scripts/*.js', gulp.series(scripts, injectFoot, 'hugoDev', 'htmlDev'));
  gulp.watch('src/scripts_head/*.js', gulp.series(scriptsHead, injectHead, 'hugoDev', 'htmlDev'));
  gulp.watch('src/layouts/**/*.html', gulp.series(injectHead, injectFoot, 'hugoDev','htmlDev'));
  gulp.watch([
    'hugo/archetypes/*',
    'hugo/content/',
    'hugo/data/'
  ], gulp.series('hugoDev')).on('change', sync.reload);
});

//
// Deploy

// Deploy to staging
gulp.task('upstage', () => {
  return Promise.all([
    rsync(config.stageRsyncOptions, function(error, stdout, stderr, cmd) {
      plugins.gulpUtil.log('Running: ' + cmd);
      plugins.gulpUtil.log(stdout);
    })
  ]);
});

// Deploy to live
gulp.task('golive', () => {
  return Promise.all([
    rsync(config.liveRsyncOptions, function(error, stdout, stderr, cmd) {
      plugins.gulpUtil.log('Running: ' + cmd);
      plugins.gulpUtil.log(stdout);
    })
  ]);
});

//
// 'gulp' is the main development task, essentially dev + watch + browsersync
gulp.task('default',
  gulp.series(
    gulp.parallel(cleanStatic, cleanLayouts, cleanDev),
    gulp.parallel('custoModernizr', postCss, scripts, scriptsHead),
    gulp.parallel(html, 'picturefill', 'vendorStyles'),
    gulp.parallel(injectHead, injectFoot),
    'hugoDev',
    'htmlDev',
    'watchnsync'
  )
);
// 'gulp dev' a single run, hugo will generate pages for drafts and future posts
gulp.task('dev',
  gulp.series(
    gulp.parallel(cleanStatic, cleanLayouts, cleanDev),
    gulp.parallel('custoModernizr', postCss, scripts, scriptsHead),
    gulp.parallel(html, 'picturefill', 'vendorStyles'),
    gulp.parallel(injectHead, injectFoot),
    'hugoDev',
    'htmlDev'
  )
);
// 'gulp stage' a single run, hugo will generate pages for drafts
gulp.task('stage',
  gulp.series(
    gulp.parallel(cleanStatic, cleanLayouts, cleanStage),
    gulp.parallel('custoModernizr', minpostCss, minscripts, minscriptsHead),
    gulp.parallel(html, 'picturefill', 'vendorStyles'),
    gulp.parallel(injectHead, injectFoot),
    'hugoStage',
    'htmlStage'
  )
);
// 'gulp live' a single run, production only
gulp.task('live',
  gulp.series(
    gulp.parallel(cleanStatic, cleanLayouts, cleanLive),
    gulp.parallel('custoModernizr', minpostCss, minscripts, minscriptsHead),
    gulp.parallel(html, 'picturefill', 'vendorStyles'),
    gulp.parallel(injectHead, injectFoot),
    'hugoLive',
    'htmlLive'
  )
);

// Clean and regenerate all images
gulp.task('reprocess', gulp.series(cleanImages, imgMagic, imgResponsive, imgOptim, imgMin));
// Clean and regenerate responsive images (use after modifying responsive config)
gulp.task('reprocess:responsive', gulp.series(cleanResponsive, imgResponsive, imgOptim));

// Task used for debugging function based task or tasks
gulp.task('dt', gulp.series('vendorStyles', injectHead));
<|endoftext|>


<commit_before>/**
 * Create references
 */
var gulp = require('gulp');
var glob = require('glob');
var pkg = require('./package.json');
var common = require('./gulp/common.js');

/**
 * Auto load all gulp plugins
 * Load common utilities for gulp
 */
var gulpLoadPlugins = require('gulp-load-plugins');
var plug = gulpLoadPlugins();
var gutil = plug.loadUtils(['colors', 'env', 'log', 'date']);

/**
 * @desc Lint the code
 */
gulp.task('jshint', function () {
    var sources = [].concat(pkg.paths.js, pkg.paths.nodejs);
    return gulp.src(sources)
        .pipe(plug.jshint('./.jshintrc'))
//        .pipe(plug.jshint.reporter('default'));
        .pipe(plug.jshint.reporter('jshint-stylish'));
});

/**
 * @desc Create $templateCache from the html templates
 */
gulp.task('templatecache', function () {
    gulp.src(pkg.paths.htmltemplates)
        .pipe(plug.angularTemplatecache('templates.js', {
            module: 'app.core',
            standalone: false,
            root: 'app/'
        }))
        .pipe(gulp.dest(pkg.paths.dev));
});

/**
 * @desc Add injection code for @ngInject annotations
 */
gulp.task('ngAnnotate', function () {
    gulp.src(pkg.paths.htmltemplates)
        .pipe(plug.ngAnnotate({
            // true helps add where @ngInject is not used. It infers.
            // Doesn't work with resolve, so we must be explicit there
            add: true
        }))
        .pipe(gulp.dest(pkg.paths.dev));
});

/**
 * @desc Minify and bundle the JavaScript
 */
gulp.task('js', ['jshint', 'templatecache'], function () {
    var source = [].concat(pkg.paths.js, pkg.paths.dev + 'templates.js');
    return gulp.src(source)
//        .pipe(plug.size({showFiles: true}))
        .pipe(plug.sourcemaps.init())
        .pipe(plug.concat('all.min.js'))
        // Annotate before uglify so the code get's min'd properly.
        .pipe(plug.ngAnnotate({
            // true helps add where @ngInject is not used. It infers.
            // Doesn't work with resolve, so we must be explicit there
            add: true
        }))
        .pipe(plug.bytediff.start())
        .pipe(plug.uglify({mangle: true}))
        .pipe(plug.bytediff.stop(common.bytediffFormatter))
        .pipe(plug.sourcemaps.write('./'))
        .pipe(gulp.dest(pkg.paths.dev));
//        .pipe(plug.size({showFiles: true}));
});

/**
 * @desc Copy the Vendor JavaScript
 */
gulp.task('vendorjs', function () {
    return gulp.src(pkg.paths.vendorjs)
        .pipe(plug.concat('vendor.min.js'))
        .pipe(plug.bytediff.start())
        .pipe(plug.uglify())
        .pipe(plug.bytediff.stop(common.bytediffFormatter))
        .pipe(gulp.dest(pkg.paths.dev + 'vendor'))
});

/**
 * @desc Copy the Vendor JavaScript SourceMaps
 */
gulp.task('vendorjsmaps', function () {
    var sourcemaps = [].concat( // pkg.paths.vendorjs,
        pkg.paths.vendorjs.map(function (path) {
            return path + '.map';
        }));
    sourcemaps.push('./bower_components/jquery/dist/jquery.min.map');
    // console.log(sourcemaps);
    return gulp.src(sourcemaps)
        .pipe(gulp.dest(pkg.paths.dev + 'vendor'));
});

/**
 * @desc Minify and bundle the CSS
 */
gulp.task('css', function () {
    return gulp.src(pkg.paths.css)
//        .pipe(plug.size({showFiles: true}))
        .pipe(plug.concat('all.min.css')) // Before bytediff or after
        .pipe(plug.bytediff.start())
        .pipe(plug.minifyCss({}))
        .pipe(plug.bytediff.stop(common.bytediffFormatter))
//        .pipe(plug.concat('all.min.css')) // Before bytediff or after
        .pipe(gulp.dest(pkg.paths.dev + 'content'));
//        .pipe(plug.size({showFiles: true}));
});

/**
 * @desc Minify and bundle the Vendor CSS
 */
gulp.task('vendorcss', function () {
    return gulp.src(pkg.paths.vendorcss)
        .pipe(plug.concat('vendor.min.css'))
        .pipe(plug.bytediff.start())
        .pipe(plug.minifyCss({}))
        .pipe(plug.bytediff.stop(common.bytediffFormatter))
        .pipe(gulp.dest(pkg.paths.dev + 'content'));
});

/**
 * @desc Copy fonts
 */
gulp.task('fonts', function () {
    return gulp.src(pkg.paths.fonts)
        .pipe(gulp.dest(pkg.paths.dev + 'fonts'));
});

/**
 * @desc Compress images
 */
gulp.task('images', function () {
    return gulp.src(pkg.paths.images)
        .pipe(plug.cache(plug.imagemin({optimizationLevel: 3})))
        .pipe(gulp.dest(pkg.paths.dev + 'content/images'));
});

/**
 * @desc Inject all the files into the new index.html
 */
gulp.task('build-stage',
    ['js', 'vendorjs', 'css', 'vendorcss', 'images', 'fonts'], function () {
    var target = gulp.src('./client/index.html');
    // var vjs = pkg.paths.vendorjs.map(function (path) {
    //     var file = path.split('/').pop();
    //     return pkg.paths.dev + 'vendor/' + file;
    // });
    var vjs = pkg.paths.dev + 'vendor/vendor.min.js';
//    console.log(vjs);
    var sources = {
        css: gulp.src([pkg.paths.dev + 'content/all.min.css'], {read: false}),
        vendorcss: gulp.src([pkg.paths.dev + 'content/vendor.min.css'], {read: false}),
        js: gulp.src([pkg.paths.dev + 'all.min.js']),
        vendorjs: gulp.src(vjs)
    };
    var ignorePath = pkg.paths.dev.substring(1);

    target
        .pipe(plug.inject(sources.vendorcss, {name: 'inject-vendor', ignorePath: ignorePath}))
        .pipe(plug.inject(sources.css, {ignorePath: ignorePath}))
        .pipe(plug.inject(sources.vendorjs, {name: 'inject-vendor', ignorePath: ignorePath}))
        .pipe(plug.inject(sources.js, {ignorePath: ignorePath}))

        .pipe(gulp.dest(pkg.paths.dev))
        .pipe(plug.notify({
            onLast: true,
            message: 'linted, bundled, and images compressed!'
        }));
});

/**
 * @desc Remove all files from the output folder
 */
gulp.task('clean', function () {
    return gulp.src([
            pkg.paths.dev
        ]).pipe(plug.clean({force: true}));
});

/**
 * @desc Watch files and build
 */
gulp.task('watchjs', function () {
    var js = ['gulpfile.js'].concat(pkg.paths.js);
    var jswatcher = gulp.watch(js, ['js', 'vendorjs']);

    jswatcher.on('change', function (event) {
        console.log('*** File ' + event.path + ' was ' + event.type + ', running tasks...');
    });

    var css = ['gulpfile.js'].concat(pkg.paths.css, pkg.paths.vendorcss);
    var csswatcher = gulp.watch(css, ['css', 'vendorcss']);

    csswatcher.on('change', function (event) {
        console.log('*** File ' + event.path + ' was ' + event.type + ', running tasks...');
    });
});

/**
 * @desc Run all tests
 */
gulp.task('test', function() {
    var testFiles = [
        'client/test/**.[Ss]pec.js'
    ];
    return gulp.src(testFiles)
        .pipe(plug.karma({
            configFile: pkg.paths.test + '/karma.conf.js',
            action: 'run'
        }))
        .on('error', function(err) {
            // Make sure failed tests cause gulp to exit non-zero
            throw err;
        });
});

/**
 * serve the dev environment
 */
gulp.task('dev', function () {
    plug.nodemon({
        script: 'server/server.js',
        delayTime: 1,
        ext: 'html js',
        env: { 'NODE_ENV': 'dev' },
        ignore: ['build/'],
        nodeArgs: ['--debug=9999']
    })
        .on('change', ['jshint', 'test'])
        .on('restart', function () {
            console.log('restarted!');
        });
});

/**
 * serve the staging environment
 */
gulp.task('stage', function () {
    plug.nodemon({
        script: 'server/server.js',
        delayTime: 1,
        ext: 'html js',
        env: { 'NODE_ENV': 'stage' },
        ignore: ['build/'],
        nodeArgs: ['--debug=9999']
    })
        .on('change', ['jshint', 'test', 'build-stage'])
        .on('restart', function () {
            console.log('restarted!');
        });
});
<commit_msg>modular: gulp stage now builds and serve the site<commit_after>/**
 * Create references
 */
var gulp = require('gulp');
var glob = require('glob');
var pkg = require('./package.json');
var common = require('./gulp/common.js');

/**
 * Auto load all gulp plugins
 * Load common utilities for gulp
 */
var gulpLoadPlugins = require('gulp-load-plugins');
var plug = gulpLoadPlugins();
var gutil = plug.loadUtils(['colors', 'env', 'log', 'date']);

/**
 * @desc Lint the code
 */
gulp.task('jshint', function () {
    var sources = [].concat(pkg.paths.js, pkg.paths.nodejs);
    return gulp.src(sources)
        .pipe(plug.jshint('./.jshintrc'))
//        .pipe(plug.jshint.reporter('default'));
        .pipe(plug.jshint.reporter('jshint-stylish'));
});

/**
 * @desc Create $templateCache from the html templates
 */
gulp.task('templatecache', function () {
    gulp.src(pkg.paths.htmltemplates)
        .pipe(plug.angularTemplatecache('templates.js', {
            module: 'app.core',
            standalone: false,
            root: 'app/'
        }))
        .pipe(gulp.dest(pkg.paths.dev));
});

/**
 * @desc Add injection code for @ngInject annotations
 */
gulp.task('ngAnnotate', function () {
    gulp.src(pkg.paths.htmltemplates)
        .pipe(plug.ngAnnotate({
            // true helps add where @ngInject is not used. It infers.
            // Doesn't work with resolve, so we must be explicit there
            add: true
        }))
        .pipe(gulp.dest(pkg.paths.dev));
});

/**
 * @desc Minify and bundle the JavaScript
 */
gulp.task('js', ['jshint', 'templatecache'], function () {
    var source = [].concat(pkg.paths.js, pkg.paths.dev + 'templates.js');
    return gulp.src(source)
//        .pipe(plug.size({showFiles: true}))
        .pipe(plug.sourcemaps.init())
        .pipe(plug.concat('all.min.js'))
        // Annotate before uglify so the code get's min'd properly.
        .pipe(plug.ngAnnotate({
            // true helps add where @ngInject is not used. It infers.
            // Doesn't work with resolve, so we must be explicit there
            add: true
        }))
        .pipe(plug.bytediff.start())
        .pipe(plug.uglify({mangle: true}))
        .pipe(plug.bytediff.stop(common.bytediffFormatter))
        .pipe(plug.sourcemaps.write('./'))
        .pipe(gulp.dest(pkg.paths.dev));
//        .pipe(plug.size({showFiles: true}));
});

/**
 * @desc Copy the Vendor JavaScript
 */
gulp.task('vendorjs', function () {
    return gulp.src(pkg.paths.vendorjs)
        .pipe(plug.concat('vendor.min.js'))
        .pipe(plug.bytediff.start())
        .pipe(plug.uglify())
        .pipe(plug.bytediff.stop(common.bytediffFormatter))
        .pipe(gulp.dest(pkg.paths.dev + 'vendor'))
});

/**
 * @desc Minify and bundle the CSS
 */
gulp.task('css', function () {
    return gulp.src(pkg.paths.css)
//        .pipe(plug.size({showFiles: true}))
        .pipe(plug.concat('all.min.css')) // Before bytediff or after
        .pipe(plug.bytediff.start())
        .pipe(plug.minifyCss({}))
        .pipe(plug.bytediff.stop(common.bytediffFormatter))
//        .pipe(plug.concat('all.min.css')) // Before bytediff or after
        .pipe(gulp.dest(pkg.paths.dev + 'content'));
//        .pipe(plug.size({showFiles: true}));
});

/**
 * @desc Minify and bundle the Vendor CSS
 */
gulp.task('vendorcss', function () {
    return gulp.src(pkg.paths.vendorcss)
        .pipe(plug.concat('vendor.min.css'))
        .pipe(plug.bytediff.start())
        .pipe(plug.minifyCss({}))
        .pipe(plug.bytediff.stop(common.bytediffFormatter))
        .pipe(gulp.dest(pkg.paths.dev + 'content'));
});

/**
 * @desc Copy fonts
 */
gulp.task('fonts', function () {
    return gulp.src(pkg.paths.fonts)
        .pipe(gulp.dest(pkg.paths.dev + 'fonts'));
});

/**
 * @desc Compress images
 */
gulp.task('images', function () {
    return gulp.src(pkg.paths.images)
        .pipe(plug.cache(plug.imagemin({optimizationLevel: 3})))
        .pipe(gulp.dest(pkg.paths.dev + 'content/images'));
});

/**
 * @desc Inject all the files into the new index.html
 */
gulp.task('build-stage',
    ['js', 'vendorjs', 'css', 'vendorcss', 'images', 'fonts'], function () {
    var target = gulp.src('./client/index.html');
    // var vjs = pkg.paths.vendorjs.map(function (path) {
    //     var file = path.split('/').pop();
    //     return pkg.paths.dev + 'vendor/' + file;
    // });
    var vjs = pkg.paths.dev + 'vendor/vendor.min.js';
//    console.log(vjs);
    var sources = {
        css: gulp.src([pkg.paths.dev + 'content/all.min.css'], {read: false}),
        vendorcss: gulp.src([pkg.paths.dev + 'content/vendor.min.css'], {read: false}),
        js: gulp.src([pkg.paths.dev + 'all.min.js']),
        vendorjs: gulp.src(vjs)
    };
    var ignorePath = pkg.paths.dev.substring(1);

    target
        .pipe(plug.inject(sources.vendorcss, {name: 'inject-vendor', ignorePath: ignorePath}))
        .pipe(plug.inject(sources.css, {ignorePath: ignorePath}))
        .pipe(plug.inject(sources.vendorjs, {name: 'inject-vendor', ignorePath: ignorePath}))
        .pipe(plug.inject(sources.js, {ignorePath: ignorePath}))

        .pipe(gulp.dest(pkg.paths.dev))
        .pipe(plug.notify({
            onLast: true,
            message: 'linted, bundled, and images compressed!'
        }));
});

/**
 * @desc Remove all files from the output folder
 */
gulp.task('clean', function () {
    return gulp.src([
            pkg.paths.dev
        ]).pipe(plug.clean({force: true}));
});

/**
 * @desc Watch files and build
 */
gulp.task('watchjs', function () {
    var js = ['gulpfile.js'].concat(pkg.paths.js);
    var jswatcher = gulp.watch(js, ['js', 'vendorjs']);

    jswatcher.on('change', function (event) {
        console.log('*** File ' + event.path + ' was ' + event.type + ', running tasks...');
    });

    var css = ['gulpfile.js'].concat(pkg.paths.css, pkg.paths.vendorcss);
    var csswatcher = gulp.watch(css, ['css', 'vendorcss']);

    csswatcher.on('change', function (event) {
        console.log('*** File ' + event.path + ' was ' + event.type + ', running tasks...');
    });
});

/**
 * @desc Run all tests
 */
gulp.task('test', function() {
    var testFiles = [
        'client/test/**.[Ss]pec.js'
    ];
    return gulp.src(testFiles)
        .pipe(plug.karma({
            configFile: pkg.paths.test + '/karma.conf.js',
            action: 'run'
        }))
        .on('error', function(err) {
            // Make sure failed tests cause gulp to exit non-zero
            throw err;
        });
});

/**
 * serve the dev environment
 */
gulp.task('dev', ['jshint', 'test'], function () {
    plug.nodemon({
        script: 'server/server.js',
        delayTime: 1,
        ext: 'html js',
        env: { 'NODE_ENV': 'dev' },
        ignore: ['build/'],
        nodeArgs: ['--debug=9999']
    })
        .on('change', ['jshint', 'test'])
        .on('restart', function () {
            console.log('restarted!');
        });
});

/**
 * serve the staging environment
 */
gulp.task('stage', ['jshint', 'test', 'build-stage'], function () {
    plug.nodemon({
        script: 'server/server.js',
        delayTime: 1,
        ext: 'html js',
        env: { 'NODE_ENV': 'stage' },
        ignore: ['build/'],
        nodeArgs: ['--debug=9999']
    })
        .on('change', ['jshint', 'test', 'build-stage'])
        .on('restart', function () {
            console.log('restarted!');
        });
});
<|endoftext|>


<commit_before>var
	gulp       = require('gulp'),
	browserify = require('gulp-browserify'),
	changed    = require('gulp-changed'),
	concat     = require('gulp-concat'),
	filter     = require('gulp-filter'),
	gutil      = require('gulp-util'),
	jscs       = require('gulp-jscs'),
	less       = require('gulp-less'),
	rename     = require('gulp-rename'),
	uglify     = require('gulp-uglify'),
	watch      = require('gulp-watch'),
	path       = require('path')
	;

gulp.task('default', function()
{
	gulp.run('lint', 'css', 'js', 'libs');
});

gulp.task('css', function()
{
	gulp.src('./build/less/**/*.less')
	.pipe(changed('./site/public/css'))
	.pipe(less({
		paths: [ path.join(__dirname, 'bower_components', 'bootstrap', 'less') ]
	}))
	.pipe(gulp.dest('./site/public/css'));
});

gulp.task('images', function()
{
	// TODO
});

gulp.task('libs', function()
{
	gulp.src(['./bower_components/rivets/dist/rivets.min.js'], { base: './bower_components/rivets/dist' })
	.pipe(changed('./site/public/js'))
	.pipe(gulp.dest('./site/public/js'));

	gulp.src(['./bower_components/bootstrap/dist/js/*.js'], { base: './bower_components/bootstrap/dist/js' })
	.pipe(changed('./site/public/js'))
	.pipe(gulp.dest('./site/public/js'));

/*
	gulp.src('./js/*.js')
	.pipe(concat('libraries.js'))
	.pipe(gulp.dest('./site/public/js'))
	.pipe(rename('libraries.min.js'))
	.pipe(uglify())
	.pipe(gulp.dest('./site/public/js'));
*/
});

gulp.task('js', function()
{
	gulp.src('./build/js/app.js')
	.pipe(changed('./site/public/js'))
	.pipe(browserify(
	{
		shim:
		{
			jquery:
			{
				path: './bower_components/jquery/jquery.min.js',
				exports: '$'
			}
		}
	}))
	.pipe(gulp.dest('./site/public/js'));
});

gulp.task('watch-css', function()
{
	gulp.src('./build/less/**/*.less')
	.pipe(watch())
	.pipe(less({
		paths: [ path.join(__dirname, 'bower_components', 'bootstrap', 'less') ]
	}))
	.pipe(gulp.dest('./site/public/css'));
});

gulp.task('lint', function()
{
	gulp.src(['*.js', './lib/**/*.js', '.test/*.js', './site/routes/*.js', './site/app.js'])
	.pipe(jscs());
});
<commit_msg>Removing more stuff.<commit_after><|endoftext|>


<commit_before>// jchck_'s gulpfile

//
// gulp plugin registry
//

var gulp 			=		require('gulp');
var postcss 		=		require('gulp-postcss');
var cssnext 		= 		require('postcss-cssnext');
var precss			=		require('precss');
var autoprefixer	=		require('autoprefixer');
var atImport		=		require('postcss-import');
var mqpacker		=		require('css-mqpacker');
var cssnano			=		require('cssnano');
var size			=		require('gulp-size');
var	cssvariables	=		require('postcss-css-variables');
var browserSync		=		require('browser-sync').create();
var devUrl			=		'http://vagrant.local/jchck/';

//
// css processing task
//
// $ gulp css
//

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

	// postcss plugin registry
	var postcssPlugins = [
		atImport,
		cssvariables,
		cssnano,
		autoprefixer({
			browsers: ['last 2 versions']
		}),
		cssnext,
		mqpacker,
		precss
	];

	// processing plumbing
	return gulp.src('./src/css/jchck_.css')

		// postcss it
		.pipe(postcss(postcssPlugins))

		// what's the size?
		.pipe(size({gzip: false, showFiles: true, title: 'Processed!'}))
		.pipe(size({gzip: true, showFiles: true, title: 'Processed & gZipped!'}))

		// spit it out
		.pipe(gulp.dest('./dest'))

		// add to the browser sync stream
		.pipe(browserSync.stream());
});

//
// watch task
//
// $ gulp watch
//

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

	browserSync.init({

		// the php files to watch
		files: [
			'{lib,templates}/**/*.php',
			'*.php'
		],

		// the url getting proxied, defined above
		proxy: devUrl,

		// @see https://www.browsersync.io/docs/options/#option-snippetOptions
		snippetOptions: {
			whitelist: ['/wp-admin/admin-ajax.php'],
			blacklist: ['/wp-admin/**']
		}
	});

	// the css files to watch on change runs the css processing task
	gulp.watch(['./src/css/*'], ['css']);
});

//
// default task
//
// $ gulp
//

gulp.task('default', ['css', 'watch']);
<commit_msg>move the location of devUrl variable<commit_after>// jchck_'s gulpfile

//
// site's dev URL (used in the watch task below)
//

var devUrl			=		'http://vagrant.local/jchck/';

//
// gulp plugin registry
//

var gulp 			=		require('gulp');
var postcss 		=		require('gulp-postcss');
var cssnext 		= 		require('postcss-cssnext');
var precss			=		require('precss');
var autoprefixer	=		require('autoprefixer');
var atImport		=		require('postcss-import');
var mqpacker		=		require('css-mqpacker');
var cssnano			=		require('cssnano');
var size			=		require('gulp-size');
var	cssvariables	=		require('postcss-css-variables');
var browserSync		=		require('browser-sync').create();

//
// css processing task
//
// $ gulp css
//

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

	// postcss plugin registry
	var postcssPlugins = [
		atImport,
		cssvariables,
		cssnano,
		autoprefixer({
			browsers: ['last 2 versions']
		}),
		cssnext,
		mqpacker,
		precss
	];

	// processing plumbing
	return gulp.src('./src/css/jchck_.css')

		// postcss it
		.pipe(postcss(postcssPlugins))

		// what's the size?
		.pipe(size({gzip: false, showFiles: true, title: 'Processed!'}))
		.pipe(size({gzip: true, showFiles: true, title: 'Processed & gZipped!'}))

		// spit it out
		.pipe(gulp.dest('./dest'))

		// add to the browser sync stream
		.pipe(browserSync.stream());
});

//
// watch task
//
// $ gulp watch
//

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

	browserSync.init({

		// the php files to watch
		files: [
			'{lib,templates}/**/*.php',
			'*.php'
		],

		// the url getting proxied, defined above
		proxy: devUrl,

		// @see https://www.browsersync.io/docs/options/#option-snippetOptions
		snippetOptions: {
			whitelist: ['/wp-admin/admin-ajax.php'],
			blacklist: ['/wp-admin/**']
		}
	});

	// the css files to watch on change runs the css processing task
	gulp.watch(['./src/css/*'], ['css']);
});

//
// default task
//
// $ gulp
//

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


<commit_before>const gulp = require('gulp');
const HubRegistry = require('gulp-hub');
const browserSync = require('browser-sync');
const csslint = require('gulp-csslint');
const conf = require('./conf/gulp.conf');

// Load some files into the registry
const hub = new HubRegistry([conf.paths.tasks+'/*.js']);

// Tell gulp to use the tasks just loaded
gulp.registry(hub);

gulp.task('inject', gulp.series(gulp.parallel('styles', 'eslint'), 'inject'));
gulp.task('build', gulp.series('eslint-failonerror','appconfig', 'partials', 'inject', 'other', 'test', 'build', 'assets', 'build-apidocs'));
gulp.task('test', gulp.series('eslint', 'karma:single-run'));
gulp.task('test:auto', gulp.series('watch', 'karma:auto-run'));
gulp.task('protractor:src', gulp.series('browsersync:e2e', 'webdriver-update', 'run-protractor'));
gulp.task('protractor:dist', gulp.series('build','browsersync:e2e-dist', 'webdriver-update', 'run-protractor'));
gulp.task('protractor', gulp.series('protractor:src'));
gulp.task('serve', gulp.series('clean', 'appconfig', 'inject', 'watch', 'browsersync'));
gulp.task('serve:dist', gulp.series('clean', 'default', 'browsersync:dist'));
gulp.task('serve:apidoc', gulp.series('clean', 'build-apidocs', 'browsersync:apidoc'));
gulp.task('default', gulp.series('clean', 'build'));
gulp.task('watch', watch);

gulp.task('css', function() {
  return gulp.src(['src/assets/css/*.css', 'src/app/components/*/*.css', '!src/assets/css/*min.css'])
    .pipe(csslint())
    .pipe(csslint.formatter())
});

function reloadBrowserSync(cb) {
  browserSync.reload();
  cb();
}

function watch(done) {
  gulp.watch([
    conf.paths.src+'index.html',
    'bower.json'
  ], gulp.parallel('inject'));

  gulp.watch(conf.paths.src+'/app/**/*.html', reloadBrowserSync);
  gulp.watch([
    conf.paths.src+'/**/*.css'
  ], gulp.series('styles'));
  gulp.watch(conf.paths.src+'/**/*.js', gulp.series('inject'));
  done();
}
<commit_msg>desactivados tests en build<commit_after>const gulp = require('gulp');
const HubRegistry = require('gulp-hub');
const browserSync = require('browser-sync');
const csslint = require('gulp-csslint');
const conf = require('./conf/gulp.conf');

// Load some files into the registry
const hub = new HubRegistry([conf.paths.tasks+'/*.js']);

// Tell gulp to use the tasks just loaded
gulp.registry(hub);

gulp.task('inject', gulp.series(gulp.parallel('styles', 'eslint'), 'inject'));
gulp.task('build', gulp.series('eslint-failonerror','appconfig', 'partials', 'inject', 'other'/*, 'test'*/, 'build', 'assets', 'build-apidocs'));
gulp.task('test', gulp.series('eslint', 'karma:single-run'));
gulp.task('test:auto', gulp.series('watch', 'karma:auto-run'));
gulp.task('protractor:src', gulp.series('browsersync:e2e', 'webdriver-update', 'run-protractor'));
gulp.task('protractor:dist', gulp.series('build','browsersync:e2e-dist', 'webdriver-update', 'run-protractor'));
gulp.task('protractor', gulp.series('protractor:src'));
gulp.task('serve', gulp.series('clean', 'appconfig', 'inject', 'watch', 'browsersync'));
gulp.task('serve:dist', gulp.series('clean', 'default', 'browsersync:dist'));
gulp.task('serve:apidoc', gulp.series('clean', 'build-apidocs', 'browsersync:apidoc'));
gulp.task('default', gulp.series('clean', 'build'));
gulp.task('watch', watch);

gulp.task('css', function() {
  return gulp.src(['src/assets/css/*.css', 'src/app/components/*/*.css', '!src/assets/css/*min.css'])
    .pipe(csslint())
    .pipe(csslint.formatter())
});

function reloadBrowserSync(cb) {
  browserSync.reload();
  cb();
}

function watch(done) {
  gulp.watch([
    conf.paths.src+'index.html',
    'bower.json'
  ], gulp.parallel('inject'));

  gulp.watch(conf.paths.src+'/app/**/*.html', reloadBrowserSync);
  gulp.watch([
    conf.paths.src+'/**/*.css'
  ], gulp.series('styles'));
  gulp.watch(conf.paths.src+'/**/*.js', gulp.series('inject'));
  done();
}
<|endoftext|>


<commit_before>var gulp = require('gulp');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var jshint = require('gulp-jshint');
var del = require('rimraf');
require('jshint-stylish');

var lint = ['index.js', 'lib/utils.js', 'test/*.js'];

gulp.task('coverage', function () {
  return gulp.src(lint)
    .pipe(istanbul())
    .pipe(istanbul.hookRequire());
});

gulp.task('coverage:clean', function (cb) {
  del('coverage', cb);
});

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

gulp.task('jshint', function () {
  return gulp.src(lint)
    .pipe(jshint())
    .pipe(jshint.reporter('jshint-stylish'))
});

gulp.task('default', ['mocha', 'jshint'], function (cb) {
  console.log('Finished "default"');

  // force the process to end since `verb.watch`
  // holds it open in the tests
  process.exit();
  cb();
});
<commit_msg>remove del from gulpfile<commit_after>var gulp = require('gulp');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var jshint = require('gulp-jshint');
require('jshint-stylish');

var lint = ['index.js', 'lib/utils.js', 'test/*.js'];

gulp.task('coverage', function () {
  return gulp.src(lint)
    .pipe(istanbul())
    .pipe(istanbul.hookRequire());
});

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

gulp.task('jshint', function () {
  return gulp.src(lint)
    .pipe(jshint())
    .pipe(jshint.reporter('jshint-stylish'))
});

gulp.task('default', ['mocha', 'jshint'], function (cb) {
  console.log('Finished "default"');

  // force the process to end since `verb.watch`
  // holds it open in the tests
  process.exit();
  cb();
});
<|endoftext|>


<commit_before>/* jshint node:true */

'use strict';

var gulp    = require('gulp'),
    gutil   = require('gulp-util'),
    clear   = require('clear'),
    mocha   = require('gulp-mocha'),
    jshint  = require('gulp-jshint');

gulp.task('lint', function () {
    gulp.src('*.js')
        .pipe(jshint())
        .pipe(jshint.reporter('jshint-stylish'))
        .pipe(mocha());
});

gulp.task('default', function() {
    gulp.run('lint');
    gulp.watch('*.js', function(event) {
        clear();
        gutil.log(gutil.colors.cyan(event.path.replace(process.cwd(), '')) + ' ' + event.type + '. (' + gutil.colors.magenta(gutil.date('HH:MM:ss')) + ')');
        gulp.run('lint');
    });
});
<commit_msg>Update build process.<commit_after>/* jshint node:true */

'use strict';

var gulp   = require('gulp'),
    mocha  = require('gulp-mocha'),
    jshint = require('gulp-jshint');

gulp.task('develop', function() {
    function scripts() {
        return gulp.src('*.js')
            .pipe(jshint())
            .pipe(jshint.reporter('jshint-stylish'))
            .pipe(mocha({ reporter: 'mocha-silent-reporter' }));
    }

    var watcher = gulp.watch('*.js');
    watcher.on('change', scripts);

    return scripts();
});
<|endoftext|>


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

// Include plugins
// Removes gulp- and gulp. prefixes
var p = require("gulp-load-plugins")({
	pattern: ['gulp-*', 'gulp.*', 'main-bower-files'],
	replaceString: /\bgulp[\-.]/
});

// Path Variables
var src = "src/";   // working files
var dest = "dist/"; // production files

// Copy unmodified files
gulp.task('copy', function(){
  gulp.src([
      src + '*',
      "!" + src + '*.{html,png,ico,txt}',
      src + '*.{html,png,ico,txt}'],
      {
        dot: true
    }).pipe(gulp.dest(dest));
});

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

// CSS SASS Preprocessing
// + Autoprefixer Postprocessing
gulp.task('sass', function() {
  gulp.src(src + 'scss/main.scss')
    .pipe(p.sass({outputStyle: 'expanded'}))
    .pipe(p.autoprefixer({
      browsers: ['last 2 versions'],
      cascade: false
    }))
    .pipe(gulp.dest(dest + 'css'))
    .pipe(p.connect.reload())

});

// JavaScript
gulp.task('scripts', function() {

  // Bower Vendor Libraries
  var jsFiles = ['dist/*.js'];
  gulp.src(p.mainBowerFiles(jsFiles))
  	.pipe(p.filter('*.js'))
    .pipe(p.order([
  			'jquery.min.js',  // JQuery First
  			'*'
  		]))
    .pipe(p.uglify())
    .pipe(p.concat('libs.js'))
  	.pipe(gulp.dest(dest + 'js/lib'));

  // Custom JS
  gulp.src(src + 'js/*.js')
    .pipe(p.uglify())
    .pipe(p.concat('main.js'))
    .pipe(gulp.dest(dest + 'js'))
    .pipe(p.connect.reload())

});

// Add needed Modernizr features
gulp.task('modernizr', function() {
  gulp.src([
      dest + 'js/*.js',
      dest + 'js/lib/*.js'
    ]).pipe(p.modernizr())
    .pipe(gulp.dest(dest + 'js/lib'))
});

// Live Server
gulp.task('connect', function() {
  p.connect.server({
    root: dest,
    livereload: true
  })
});

// Run Tasks

gulp.task('default', ['copy','images','sass','scripts','modernizr','connect']);

gulp.task('watch', function(){
  gulp.watch(src + 'sass/**/*.scss', ['sass']);
  gulp.watch(src + '**/*.html', ['copy']);
  gulp.watch(src + 'js/**/*.js', ['scripts']);
})
<commit_msg>added image watch directive<commit_after>var gulp = require("gulp");

// Include plugins
// Removes gulp- and gulp. prefixes
var p = require("gulp-load-plugins")({
	pattern: ['gulp-*', 'gulp.*', 'main-bower-files'],
	replaceString: /\bgulp[\-.]/
});

// Path Variables
var src = "src/";   // working files
var dest = "dist/"; // production files

// Copy unmodified files
gulp.task('copy', function(){
  gulp.src([
      src + '*',
      "!" + src + '*.{html,png,ico,txt}',
      src + '*.{html,png,ico,txt}'],
      {
        dot: true
    }).pipe(gulp.dest(dest));
});

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

// CSS SASS Preprocessing
// + Autoprefixer Postprocessing
gulp.task('sass', function() {
  gulp.src(src + 'scss/main.scss')
    .pipe(p.sass({outputStyle: 'expanded'}))
    .pipe(p.autoprefixer({
      browsers: ['last 2 versions'],
      cascade: false
    }))
    .pipe(gulp.dest(dest + 'css'))
    .pipe(p.connect.reload())

});

// JavaScript
gulp.task('scripts', function() {

  // Bower Vendor Libraries
  var jsFiles = ['dist/*.js'];
  gulp.src(p.mainBowerFiles(jsFiles))
  	.pipe(p.filter('*.js'))
    .pipe(p.order([
  			'jquery.min.js',  // JQuery First
  			'*'
  		]))
    .pipe(p.uglify())
    .pipe(p.concat('libs.js'))
  	.pipe(gulp.dest(dest + 'js/lib'));

  // Custom JS
  gulp.src(src + 'js/*.js')
    .pipe(p.uglify())
    .pipe(p.concat('main.js'))
    .pipe(gulp.dest(dest + 'js'))
    .pipe(p.connect.reload())

});

// Add needed Modernizr features
gulp.task('modernizr', function() {
  gulp.src([
      dest + 'js/*.js',
      dest + 'js/lib/*.js'
    ]).pipe(p.modernizr())
    .pipe(gulp.dest(dest + 'js/lib'))
});

// Live Server
gulp.task('connect', function() {
  p.connect.server({
    root: dest,
    livereload: true
  })
});

// Run Tasks

gulp.task('default', ['copy','images','sass','scripts','modernizr','connect']);

gulp.task('watch', function(){
  gulp.watch(src + 'sass/**/*.scss', ['sass']);
  gulp.watch(src + '**/*.html', ['copy']);
  gulp.watch(src + 'images/**/*', ['images']);
  gulp.watch(src + 'js/**/*.js', ['scripts']);
})
<|endoftext|>


<commit_before>'use strict';

const APP_NAME = 'common-voice';
const TS_CONFIG = 'tsconfig.json';
const TS_GLOB = 'src/**/*';
const DIR_CLIENT = './web/';
const DIR_SERVER = './server/';
const DIR_UPLOAD = DIR_SERVER + 'upload/';
const DIR_SERVER_JS = DIR_SERVER + 'js/';
const DIR_DIST = DIR_CLIENT + 'dist/';

const PATH_CSS = DIR_CLIENT + 'css/*.css';
const PATH_TS = DIR_CLIENT + TS_GLOB;
const PATH_TS_SERVER = DIR_SERVER + TS_GLOB;
const PATH_VENDOR = DIR_CLIENT + 'vendor/';
const RELOAD_DELAY = 2500;

// Add gulp help functionality.
let gulp = require('gulp-help')(require('gulp'));
let shell = require('gulp-shell');
let path = require('path');
let ts = require('gulp-typescript');
let insert = require('gulp-insert');

function compile(project) {
  return project.src().pipe(project()).js;
}

function listen() {
  require('gulp-nodemon')({
    script: 'server/js/server.js',
    // Use [c] here to workaround nodemon bug #951
    watch: ['server/js', '[c]onfig.json'],
    delay: RELOAD_DELAY,
  });
}

function watch() {
  gulp.watch('package.json', ['npm-install']);
  gulp.watch(PATH_TS, ['ts']);
  gulp.watch(PATH_VENDOR, ['ts']);
  gulp.watch(PATH_TS_SERVER, ['ts-server']);
  gulp.watch(PATH_CSS, ['css']);
}

function watchAndListen() {
  watch();
  listen();
}

function doEverything() {
  return Promise.all([compileClient, compileServer, compileCSS])
    .then(watchAndListen);
}

function getVendorJS() {
  let fs = require('fs');
  let files = fs.readdirSync(PATH_VENDOR);
  return files.reduce((acc, file) => {
    return acc + fs.readFileSync(PATH_VENDOR + file) + '\n';
  }, '');
}

function compileCSS() {
  var cleanCSS = require('gulp-clean-css');
  return gulp.src(PATH_CSS)
    .pipe(cleanCSS())
    .pipe(gulp.dest(DIR_DIST));
}

function compileClient() {
  let project = ts.createProject(DIR_CLIENT + TS_CONFIG);
  let insert = require('gulp-insert');
  let uglify = require('gulp-uglify');
  let uglifyOptions = {
    mangle: false,
    compress: false,
    output: {
      beautify: true,
      indent_level: 2,
      semicolons: false
    }
  };

  return compile(project)
    .pipe(uglify(uglifyOptions))
    .pipe(insert.prepend(getVendorJS()))
    .pipe(gulp.dest(DIR_DIST));
}

function compileServer() {
  let project = ts.createProject(DIR_SERVER + TS_CONFIG);
  return compile(project)
    .pipe(gulp.dest(DIR_SERVER_JS));
}

gulp.task('css', 'Minify CSS files', compileCSS);

gulp.task('ts', 'Compile typescript files into bundle.js', compileClient);

gulp.task('ts-server', 'Compile typescript server files.', compileServer);

gulp.task('build', 'Build both server and client js', ['ts', 'ts-server', 'css']);

gulp.task('npm-install', 'Install npm dependencies.',
  shell.task(['npm install']));

gulp.task('clean', 'Remove uploaded clips.',
  shell.task([`git clean -idx ${DIR_UPLOAD}`]));

gulp.task('listen', 'Run development server.', listen);

gulp.task('watch', 'Rebuild, rebundle, re-install on file changes.', watch);

gulp.task('create', 'Create the database.', ['ts-server'], (done) => {
  let create = require('./tools/createDb');
  create.run(err => {
    if (!err) {
      console.log('Db created.');
    }
    done();
  });
});

gulp.task('drop', 'Detroy the database.', ['ts-server'], (done) => {
  let drop = require('./tools/dropDb');
  drop.run(done);
});

gulp.task('deploy', 'deploy production',
  ['npm-install', 'build'], (done) => {
    let config = require('./config.json');
    let pm2 = require('pm2');
    let ff = require('ff');
    let f = ff(() => {
      pm2.connect(f.wait());
    }, () => {
      pm2.stop(APP_NAME, f.waitPlain());
    }, () => {
      pm2.start({
        name: APP_NAME,
        script: "./gulpfile.js",
        output: config.logfile || "log.txt",
        error: config.logfile || "log.txt",
      }, f());
    }).onComplete((err) => {
      if (err) {
        console.log('prod error', err);
      }
      pm2.disconnect();
      done();
    });
  });

gulp.task('default', 'Running just `gulp`.', ['build'], () => {
  watchAndListen();
});

// Deploy script also runs this file, so exec the default task.
if (require.main === module) {
  doEverything();
}
<commit_msg>Create a run target that *just* runs the node app<commit_after>'use strict';

const APP_NAME = 'common-voice';
const TS_CONFIG = 'tsconfig.json';
const TS_GLOB = 'src/**/*';
const DIR_CLIENT = './web/';
const DIR_SERVER = './server/';
const DIR_UPLOAD = DIR_SERVER + 'upload/';
const DIR_SERVER_JS = DIR_SERVER + 'js/';
const DIR_DIST = DIR_CLIENT + 'dist/';

const PATH_CSS = DIR_CLIENT + 'css/*.css';
const PATH_TS = DIR_CLIENT + TS_GLOB;
const PATH_TS_SERVER = DIR_SERVER + TS_GLOB;
const PATH_VENDOR = DIR_CLIENT + 'vendor/';
const RELOAD_DELAY = 2500;
const SERVER_SCRIPT = 'server/js/server.js'

// Add gulp help functionality.
let gulp = require('gulp-help')(require('gulp'));
let shell = require('gulp-shell');
let path = require('path');
let ts = require('gulp-typescript');
let insert = require('gulp-insert');

function compile(project) {
  return project.src().pipe(project()).js;
}

function listen() {
  require('gulp-nodemon')({
    script: SERVER_SCRIPT,
    // Use [c] here to workaround nodemon bug #951
    watch: ['server/js', '[c]onfig.json'],
    delay: RELOAD_DELAY,
  });
}

function watch() {
  gulp.watch('package.json', ['npm-install']);
  gulp.watch(PATH_TS, ['ts']);
  gulp.watch(PATH_VENDOR, ['ts']);
  gulp.watch(PATH_TS_SERVER, ['ts-server']);
  gulp.watch(PATH_CSS, ['css']);
}

function watchAndListen() {
  watch();
  listen();
}

function doEverything() {
  return Promise.all([compileClient, compileServer, compileCSS])
    .then(watchAndListen);
}

function getVendorJS() {
  let fs = require('fs');
  let files = fs.readdirSync(PATH_VENDOR);
  return files.reduce((acc, file) => {
    return acc + fs.readFileSync(PATH_VENDOR + file) + '\n';
  }, '');
}

function compileCSS() {
  var cleanCSS = require('gulp-clean-css');
  return gulp.src(PATH_CSS)
    .pipe(cleanCSS())
    .pipe(gulp.dest(DIR_DIST));
}

function compileClient() {
  let project = ts.createProject(DIR_CLIENT + TS_CONFIG);
  let insert = require('gulp-insert');
  let uglify = require('gulp-uglify');
  let uglifyOptions = {
    mangle: false,
    compress: false,
    output: {
      beautify: true,
      indent_level: 2,
      semicolons: false
    }
  };

  return compile(project)
    .pipe(uglify(uglifyOptions))
    .pipe(insert.prepend(getVendorJS()))
    .pipe(gulp.dest(DIR_DIST));
}

function compileServer() {
  let project = ts.createProject(DIR_SERVER + TS_CONFIG);
  return compile(project)
    .pipe(gulp.dest(DIR_SERVER_JS));
}

gulp.task('css', 'Minify CSS files', compileCSS);

gulp.task('ts', 'Compile typescript files into bundle.js', compileClient);

gulp.task('ts-server', 'Compile typescript server files.', compileServer);

gulp.task('build', 'Build both server and client js', ['ts', 'ts-server', 'css']);

gulp.task('npm-install', 'Install npm dependencies.',
  shell.task(['npm install']));

gulp.task('clean', 'Remove uploaded clips.',
  shell.task([`git clean -idx ${DIR_UPLOAD}`]));

gulp.task('listen', 'Run development server.', listen);

gulp.task('run', 'Just run the server', shell.task(['node ' + SERVER_SCRIPT]));

gulp.task('watch', 'Rebuild, rebundle, re-install on file changes.', watch);

gulp.task('create', 'Create the database.', ['ts-server'], (done) => {
  let create = require('./tools/createDb');
  create.run(err => {
    if (!err) {
      console.log('Db created.');
    }
    done();
  });
});

gulp.task('drop', 'Detroy the database.', ['ts-server'], (done) => {
  let drop = require('./tools/dropDb');
  drop.run(done);
});

gulp.task('deploy', 'deploy production',
  ['npm-install', 'build'], (done) => {
    let config = require('./config.json');
    let pm2 = require('pm2');
    let ff = require('ff');
    let f = ff(() => {
      pm2.connect(f.wait());
    }, () => {
      pm2.stop(APP_NAME, f.waitPlain());
    }, () => {
      pm2.start({
        name: APP_NAME,
        script: "./gulpfile.js",
        output: config.logfile || "log.txt",
        error: config.logfile || "log.txt",
      }, f());
    }).onComplete((err) => {
      if (err) {
        console.log('prod error', err);
      }
      pm2.disconnect();
      done();
    });
  });

gulp.task('default', 'Running just `gulp`.', ['build'], () => {
  watchAndListen();
});

// Deploy script also runs this file, so exec the default task.
if (require.main === module) {
  doEverything();
}
<|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/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: false,
      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) )
  ;
});<commit_msg>improve docspub stability<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 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/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', function(next){
  runSequence( 'docshtmlmin', 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', 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>// Gulp tools
var gulp = require('gulp');
var u = require('gulp-util');
var log = u.log;
var c = u.colors;

// Project deps
var nodemon = require('gulp-nodemon');
var sass = require('gulp-sass');
var prefix = require('gulp-autoprefixer');
var bs = require('browser-sync');
var reload = bs.reload;

// -----------------------------------------------------------------------------
// Sass Task
//
// Compiles Sass and runs the CSS through autoprefixer.
// -----------------------------------------------------------------------------
gulp.task('sass', function() {
  bs.notify('Running: Sass task');
  return gulp.src('sass/**/*')
    .pipe(sass({
        outputStyle: 'nested',
      })
      .on('error', function(err, res) {
        gutil.log(c.red('sass'), 'failed to compile');
        gutil.log(c.red('> ') + err.message);
        bs.notify('Sass failed to compile');
      })
    )
    .pipe(prefix('last 2 versions', '> 1%'))
    .pipe(gulp.dest('public/css'))
    .pipe(reload({stream:true}));
});

// -----------------------------------------------------------------------------
// Watch tasks
// -----------------------------------------------------------------------------
gulp.task('watch', function() {
  gulp.watch('sass/**/*', ['sass']);
});

// -----------------------------------------------------------------------------
// Run the dev server
// -----------------------------------------------------------------------------
gulp.task('start', ['sass', 'watch'], function () {
  nodemon({
    script: 'index.js',
    ext: 'js html',
    env: { 'NODE_ENV': 'development' }
  });
});

// -----------------------------------------------------------------------------
// Default should just start the server
// -----------------------------------------------------------------------------
gulp.task('default', ['start']);
<commit_msg>:mask: clean up gulp logging<commit_after>// Gulp tools
var gulp = require('gulp');
var u = require('gulp-util');
var log = u.log;
var c = u.colors;

// Project deps
var nodemon = require('gulp-nodemon');
var sass = require('gulp-sass');
var prefix = require('gulp-autoprefixer');
var bs = require('browser-sync');
var reload = bs.reload;

// -----------------------------------------------------------------------------
// Sass Task
//
// Compiles Sass and runs the CSS through autoprefixer.
// -----------------------------------------------------------------------------
gulp.task('sass', function() {
  bs.notify('Running: Sass task');
  return gulp.src('sass/**/*')
    .pipe(sass({
        outputStyle: 'nested',
      })
      .on('error', function(err, res) {
        log(c.red('sass'), 'failed to compile');
        log(c.red('> ') + err.message);
        bs.notify('Sass failed to compile');
      })
    )
    .pipe(prefix('last 2 versions', '> 1%'))
    .pipe(gulp.dest('public/css'))
    .pipe(reload({stream:true}));
});

// -----------------------------------------------------------------------------
// Watch tasks
// -----------------------------------------------------------------------------
gulp.task('watch', function() {
  gulp.watch('sass/**/*', ['sass']);
});

// -----------------------------------------------------------------------------
// Run the dev server
// -----------------------------------------------------------------------------
gulp.task('start', ['sass', 'watch'], function () {
  nodemon({
    script: 'index.js',
    ext: 'js html',
    env: { 'NODE_ENV': 'development' }
  });
});

// -----------------------------------------------------------------------------
// Default should just start the server
// -----------------------------------------------------------------------------
gulp.task('default', ['start']);
<|endoftext|>