<commit_before>var fs           = require('fs')

var autoprefixer = require('gulp-autoprefixer')
var bump         = require('gulp-bump')
var babelify     = require('babelify')
var browserify   = require('browserify')
var buffer       = require('vinyl-buffer')
var clean        = require('gulp-clean')
var concat       = require('gulp-concat')
var cssnano      = require('gulp-cssnano')
var fileinclude  = require('gulp-file-include')
var git          = require('gulp-git')
var gulp         = require('gulp')
var less         = require('gulp-less')
var notify       = require('gulp-notify')
var plumber      = require('gulp-plumber' )
var rename       = require('gulp-rename')
var shell        = require('gulp-shell')
var source       = require('vinyl-source-stream')
var uglify       = require('gulp-uglify')
var zip          = require('gulp-zip')

var app          = './app/'
var dist         = './dist/'
var dist_CX      = './chrome-extension/'

function onError( error ){
  notify.onError( {
    title:    'Gulp',
    subtitle: 'Error',
    message:  '<%= error.message %>',
    sound:    'Beep'
  } )( error )
  this.emit('end')
}

//html Pages
var htmlFiles = app + 'layouts/*.html'
var tplFiles  = app + 'includes/*.tpl'

gulp.task('html', function () {
 gulp.src(htmlFiles)
     .pipe( plumber     ({ errorHandler: onError                }))
     .pipe( fileinclude ({ prefix: '@@', basepath: '@file'      }))
     .pipe( gulp.dest   (  dist                                  ))
     .pipe( gulp.dest   (  dist_CX                               ))
     .pipe( notify      ({ message:'HTML Complete', onLast:true }))
})

// styles: Compile and Minify Less / CSS Files
var less_watchFolder   = app     + 'styles/**/*.less'
var less_srcFile       = app     + 'styles/etherwallet-master.less'
var less_destFolder    = dist    + 'css'
var less_destFolder_CX = dist_CX + 'css'
var less_destFile      =           'etherwallet-master.css'
var less_destFileMin   =           'etherwallet-master.min.css'

gulp.task( 'styles', function () {
 gulp.src( less_srcFile )
     .pipe( plumber     ({ errorHandler: onError                                   }))
     .pipe( less        ({ compress: false                                         }))
     .pipe( autoprefixer({ browsers: ['last 2 versions', 'iOS > 8'], remove: false }))
     .pipe( rename      (  less_destFile                                           ))
   //.pipe( gulp.dest   (  less_destFolder                                         )) // unminified css
   //.pipe( gulp.dest   (  less_destFolder_CX                                      )) // unminified css
     .pipe( cssnano     ({ autoprefixer: false, safe: true                         }))
     .pipe( rename      (  less_destFileMin                                        ))
     .pipe( gulp.dest   (  less_destFolder                                         ))
     .pipe( gulp.dest   (  less_destFolder_CX                                      ))
     .pipe( notify      ({ message:'Styles Complete', onLast:true                  }))
})

// js: Browserify
var js_watchFolder   = app     + 'scripts/**/*.js'
var js_srcFile       = app     + 'scripts/main.js'
var js_destFolder    = dist    + 'js/'
var js_destFolder_CX = dist_CX + 'js/'
var js_destFile      =           'etherwallet-master.js'
var browseOpts       = { debug: true } // generates inline source maps - not in use bc it makes file huuuuge
var babelOpts        = { presets: ['es2015'], compact: false }

function bundle_js(bundler) {
  return bundler.bundle()
    .pipe( plumber   ({ errorHandler: onError }))
    .pipe( source    ( 'main.js'               ))
    .pipe( buffer    (                         ))
    .pipe( rename    ( js_destFile             ))
    .pipe( gulp.dest ( js_destFolder           ))
    .pipe( gulp.dest ( js_destFolder_CX        ))
    .pipe( notify    ({ message:'JS Complete', onLast:true }))
}

gulp.task('js', function () {
  var bundler = browserify( js_srcFile ).transform( babelify, babelOpts )
  bundle_js( bundler )
})

// Rebuild Static JS
var js_srcFilesStatic   = app + 'scripts/staticJS/to-compile-to-static/*.js'
var js_destFolderStatic = app + 'scripts/staticJS/'
var js_destFileStatic   =       'etherwallet-static.min.js'

gulp.task( 'staticJS', function () {
  gulp.src ( js_srcFilesStatic )
     .pipe( plumber   ({ errorHandler: onError }))
     .pipe( concat    (  js_destFileStatic      ))
     .pipe( uglify    (                         ))
     .pipe( gulp.dest (  js_destFolderStatic    ))
     .pipe( notify    ({ message:'Static JS Complete', onLast:true }))
})

// Copy
var imgSrcFolder          = app                 + 'images/**/*'
var fontSrcFolder         = app                 + 'fonts/*.*'
var cxSrcFiles            = app                 + 'includes/browser_action/*.*'
var cxDestFolder          = dist_CX             + 'browser_action'
var staticJSSrcFile       = js_destFolderStatic + js_destFileStatic
var jQueryFile            = './app/scripts/staticJS/jquery-1.12.3.min.js'
var readMe                = './README.md'

gulp.task('copy', function() {
 gulp.src ( imgSrcFolder )
     .pipe( gulp.dest( dist    + 'images' ))
     .pipe( gulp.dest( dist_CX + 'images' ))

 gulp.src ( fontSrcFolder )
     .pipe( gulp.dest( dist    + 'fonts'  ))
     .pipe( gulp.dest( dist_CX + 'fonts'  ))

 gulp.src ( staticJSSrcFile )
     .pipe( gulp.dest( dist    + 'js'     ))
     .pipe( gulp.dest( dist_CX + 'js'     ))

 gulp.src ( jQueryFile )
     .pipe( gulp.dest( dist    + 'js'     ))
     .pipe( gulp.dest( dist_CX + 'js'     ))

 gulp.src ( readMe )
     .pipe( gulp.dest( dist ))

 return gulp.src ( cxSrcFiles )
     .pipe( gulp.dest( cxDestFolder       ))

 .pipe( notify({ message:'Copy Complete', onLast:true }))
})

// Clean files that get compiled but shouldn't
gulp.task('clean', function () {
  return gulp.src([
      dist_CX + 'images/fav',
      dist_CX + 'embedded.html',
      dist_CX + 'index.html',
      dist    + 'cx-wallet.html',
      dist    + 'images/icons',
      './releases/dist-OOPS_TRY_AGAIN.zip',
      './releases/chrome-extension-OOPS_TRY_AGAIN.zip'
    ], {read: false})
    .pipe( plumber ({ errorHandler: onError }))
    .pipe( clean   (                         ))
    .pipe( notify  ({ message:'Clean Complete', onLast:true }))
})

// Bumps Version Number
function bumpFunc(t) {
  return gulp.src([dist_CX + 'manifest.json'])
    .pipe( plumber   ({ errorHandler: onError      }))
    .pipe( bump      ({ type: t                    }))
    .pipe( gulp.dest (  './chrome-extension'       ))
}

// Get Version Number
var versionNum
var versionMsg
gulp.task('getVersion', function() {
  manifest = JSON.parse(fs.readFileSync(dist_CX + 'manifest.json'))
  versionNum = 'v' + manifest.version
  versionMsg    = 'Release: ' + versionNum
  return gulp.src( './' )
  .pipe( notify    ({ message:'Got Version Number: ' + versionNum }))
})

// zips dist folder
gulp.task('zip', ['getVersion','clean'], function() {
 return gulp.src( dist + '*' )
    .pipe( plumber   ({ errorHandler: onError                      }))
    .pipe( zip       (  './dist-' + versionNum + '.zip'             ))
    .pipe( gulp.dest (  './releases/'                               ))
    .pipe( notify    ({ message:'Zip Dist Complete: ' + versionNum }))

})
// zips cx folder
gulp.task('zipCX', ['getVersion','clean'], function() {
  return gulp.src( dist_CX + '*' )
    .pipe( plumber   ({ errorHandler: onError                       }))
    .pipe( zip       (  './chrome-extension-' + versionNum + '.zip'  ))
    .pipe( gulp.dest (  './releases/'                                ))
    .pipe( notify    ({ message:'Zip CX Complete: ' + versionNum    }))

})

// add all
gulp.task('add', ['getVersion'], function() {
  return gulp.src( './' )
    .pipe( git.add() )
    .pipe( notify ({ message:'Added: ' + versionNum }))
})
// commit with current v# in manifest
gulp.task('commit', ['add'], function() {
  return gulp.src( './' )
    .pipe( git.commit(versionMsg) )
    .pipe( notify ({ message:'Committed: ' + versionNum }))
})
// tag with current v# in manifest
gulp.task('tag', ['commit'], function() {
  git.tag(versionNum, versionMsg, function (err) {
    if (err) throw err;
  });
  return gulp.src( './' ).pipe( notify ({ message:'Tagged: ' + versionNum }))
})
// Push Release to Mercury
gulp.task('push', ['tag'], function() {
  git.push('origin', 'mercury', {args: " --tags"}, function (err) {
    if (err) throw err;
  });
  return gulp.src( './' ).pipe( notify ({ message:'Pushed: ' + versionNum }))
})

// Push Live
gulp.task('pushLive', ['push'], shell.task([
  'git subtree push --prefix dist origin gh-pages'
]))

// Watch Tasks
gulp.task('watchJS',    function() { gulp.watch( js_watchFolder,   ['js'    ]) })
gulp.task('watchLess',  function() { gulp.watch( less_watchFolder, ['styles']) })
gulp.task('watchPAGES', function() { gulp.watch( htmlFiles,        ['html'  ]) })
gulp.task('watchTPL',   function() { gulp.watch( tplFiles,         ['html'  ]) })
gulp.task('watchCX',    function() { gulp.watch( cxSrcFiles,       ['copy'  ]) })

gulp.task('watch',      ['watchJS' , 'watchLess', 'watchPAGES', 'watchTPL', 'watchCX'])

// Build
gulp.task('build',      ['html', 'styles', 'js', 'copy'])

// Bump Version
gulp.task('bump-patch', function() { return bumpFunc( 'patch' ) })
gulp.task('bump-minor', function() { return bumpFunc( 'minor' ) })

// Prep for Release
gulp.task('prep',       ['clean', 'getVersion', 'zip', 'zipCX'])

gulp.task('default',      ['build', 'watch'])
<commit_msg>added git pushLive to gulp<commit_after>var fs           = require('fs')

var autoprefixer = require('gulp-autoprefixer')
var bump         = require('gulp-bump')
var babelify     = require('babelify')
var browserify   = require('browserify')
var buffer       = require('vinyl-buffer')
var clean        = require('gulp-clean')
var concat       = require('gulp-concat')
var cssnano      = require('gulp-cssnano')
var fileinclude  = require('gulp-file-include')
var git          = require('gulp-git')
var gulp         = require('gulp')
var less         = require('gulp-less')
var notify       = require('gulp-notify')
var plumber      = require('gulp-plumber' )
var rename       = require('gulp-rename')
var shell        = require('gulp-shell')
var source       = require('vinyl-source-stream')
var uglify       = require('gulp-uglify')
var zip          = require('gulp-zip')

var app          = './app/'
var dist         = './dist/'
var dist_CX      = './chrome-extension/'

function onError( error ){
  notify.onError( {
    title:    'Gulp',
    subtitle: 'Error',
    message:  '<%= error.message %>',
    sound:    'Beep'
  } )( error )
  this.emit('end')
}

//html Pages
var htmlFiles = app + 'layouts/*.html'
var tplFiles  = app + 'includes/*.tpl'

gulp.task('html', function () {
 gulp.src(htmlFiles)
     .pipe( plumber     ({ errorHandler: onError                }))
     .pipe( fileinclude ({ prefix: '@@', basepath: '@file'      }))
     .pipe( gulp.dest   (  dist                                  ))
     .pipe( gulp.dest   (  dist_CX                               ))
     .pipe( notify      ({ message:'HTML Complete', onLast:true }))
})

// styles: Compile and Minify Less / CSS Files
var less_watchFolder   = app     + 'styles/**/*.less'
var less_srcFile       = app     + 'styles/etherwallet-master.less'
var less_destFolder    = dist    + 'css'
var less_destFolder_CX = dist_CX + 'css'
var less_destFile      =           'etherwallet-master.css'
var less_destFileMin   =           'etherwallet-master.min.css'

gulp.task( 'styles', function () {
 gulp.src( less_srcFile )
     .pipe( plumber     ({ errorHandler: onError                                   }))
     .pipe( less        ({ compress: false                                         }))
     .pipe( autoprefixer({ browsers: ['last 2 versions', 'iOS > 8'], remove: false }))
     .pipe( rename      (  less_destFile                                           ))
   //.pipe( gulp.dest   (  less_destFolder                                         )) // unminified css
   //.pipe( gulp.dest   (  less_destFolder_CX                                      )) // unminified css
     .pipe( cssnano     ({ autoprefixer: false, safe: true                         }))
     .pipe( rename      (  less_destFileMin                                        ))
     .pipe( gulp.dest   (  less_destFolder                                         ))
     .pipe( gulp.dest   (  less_destFolder_CX                                      ))
     .pipe( notify      ({ message:'Styles Complete', onLast:true                  }))
})

// js: Browserify
var js_watchFolder   = app     + 'scripts/**/*.js'
var js_srcFile       = app     + 'scripts/main.js'
var js_destFolder    = dist    + 'js/'
var js_destFolder_CX = dist_CX + 'js/'
var js_destFile      =           'etherwallet-master.js'
var browseOpts       = { debug: true } // generates inline source maps - not in use bc it makes file huuuuge
var babelOpts        = { presets: ['es2015'], compact: false }

function bundle_js(bundler) {
  return bundler.bundle()
    .pipe( plumber   ({ errorHandler: onError }))
    .pipe( source    ( 'main.js'               ))
    .pipe( buffer    (                         ))
    .pipe( rename    ( js_destFile             ))
    .pipe( gulp.dest ( js_destFolder           ))
    .pipe( gulp.dest ( js_destFolder_CX        ))
    .pipe( notify    ({ message:'JS Complete', onLast:true }))
}

gulp.task('js', function () {
  var bundler = browserify( js_srcFile ).transform( babelify, babelOpts )
  bundle_js( bundler )
})

// Rebuild Static JS
var js_srcFilesStatic   = app + 'scripts/staticJS/to-compile-to-static/*.js'
var js_destFolderStatic = app + 'scripts/staticJS/'
var js_destFileStatic   =       'etherwallet-static.min.js'

gulp.task( 'staticJS', function () {
  gulp.src ( js_srcFilesStatic )
     .pipe( plumber   ({ errorHandler: onError }))
     .pipe( concat    (  js_destFileStatic      ))
     .pipe( uglify    (                         ))
     .pipe( gulp.dest (  js_destFolderStatic    ))
     .pipe( notify    ({ message:'Static JS Complete', onLast:true }))
})

// Copy
var imgSrcFolder          = app                 + 'images/**/*'
var fontSrcFolder         = app                 + 'fonts/*.*'
var cxSrcFiles            = app                 + 'includes/browser_action/*.*'
var cxDestFolder          = dist_CX             + 'browser_action'
var staticJSSrcFile       = js_destFolderStatic + js_destFileStatic
var jQueryFile            = './app/scripts/staticJS/jquery-1.12.3.min.js'
var readMe                = './README.md'

gulp.task('copy', function() {
 gulp.src ( imgSrcFolder )
     .pipe( gulp.dest( dist    + 'images' ))
     .pipe( gulp.dest( dist_CX + 'images' ))

 gulp.src ( fontSrcFolder )
     .pipe( gulp.dest( dist    + 'fonts'  ))
     .pipe( gulp.dest( dist_CX + 'fonts'  ))

 gulp.src ( staticJSSrcFile )
     .pipe( gulp.dest( dist    + 'js'     ))
     .pipe( gulp.dest( dist_CX + 'js'     ))

 gulp.src ( jQueryFile )
     .pipe( gulp.dest( dist    + 'js'     ))
     .pipe( gulp.dest( dist_CX + 'js'     ))

 gulp.src ( readMe )
     .pipe( gulp.dest( dist ))

 return gulp.src ( cxSrcFiles )
     .pipe( gulp.dest( cxDestFolder       ))

 .pipe( notify({ message:'Copy Complete', onLast:true }))
})

// Clean files that get compiled but shouldn't
gulp.task('clean', function () {
  return gulp.src([
      dist_CX + 'images/fav',
      dist_CX + 'embedded.html',
      dist_CX + 'index.html',
      dist    + 'cx-wallet.html',
      dist    + 'images/icons',
      './releases/dist-OOPS_TRY_AGAIN.zip',
      './releases/chrome-extension-OOPS_TRY_AGAIN.zip'
    ], {read: false})
    .pipe( plumber ({ errorHandler: onError }))
    .pipe( clean   (                         ))
    .pipe( notify  ({ message:'Clean Complete', onLast:true }))
})

// Bumps Version Number
function bumpFunc(t) {
  return gulp.src([dist_CX + 'manifest.json'])
    .pipe( plumber   ({ errorHandler: onError      }))
    .pipe( bump      ({ type: t                    }))
    .pipe( gulp.dest (  './chrome-extension'       ))
}

// Get Version Number
var versionNum
var versionMsg
gulp.task('getVersion', function() {
  manifest = JSON.parse(fs.readFileSync(dist_CX + 'manifest.json'))
  versionNum = 'v' + manifest.version
  versionMsg    = 'Release: ' + versionNum
  return gulp.src( './' )
  .pipe( notify    ({ message:'Got Version Number: ' + versionNum }))
})

// zips dist folder
gulp.task('zip', ['getVersion','clean'], function() {
 return gulp.src( dist + '*' )
    .pipe( plumber   ({ errorHandler: onError                      }))
    .pipe( zip       (  './dist-' + versionNum + '.zip'             ))
    .pipe( gulp.dest (  './releases/'                               ))
    .pipe( notify    ({ message:'Zip Dist Complete: ' + versionNum }))

})
// zips cx folder
gulp.task('zipCX', ['getVersion','clean'], function() {
  return gulp.src( dist_CX + '*' )
    .pipe( plumber   ({ errorHandler: onError                       }))
    .pipe( zip       (  './chrome-extension-' + versionNum + '.zip'  ))
    .pipe( gulp.dest (  './releases/'                                ))
    .pipe( notify    ({ message:'Zip CX Complete: ' + versionNum    }))

})

// add all
gulp.task('add', ['getVersion'], function() {
  return gulp.src( './' )
    .pipe( git.add() )
    .pipe( notify ({ message:'Added: ' + versionNum }))
})
// commit with current v# in manifest
gulp.task('commit', ['add'], function() {
  return gulp.src( './' )
    .pipe( git.commit(versionMsg) )
    .pipe( notify ({ message:'Committed: ' + versionNum }))
})
// tag with current v# in manifest
gulp.task('tag', ['commit'], function() {
  git.tag(versionNum, versionMsg, function (err) {
    if (err) throw err;
  });
  return gulp.src( './' ).pipe( notify ({ message:'Tagged: ' + versionNum }))
})
// Push Release to Mercury
gulp.task('push', ['tag'], function() {
  git.push('origin', 'mercury', {args: " --tags"}, function (err) {
    if (err) throw err;
  });
  return gulp.src( './' ).pipe( notify ({ message:'Pushed: ' + versionNum }))
})

// Push Live
gulp.task('pushLive', shell.task([
  'git subtree push --prefix dist origin gh-pages'
]))

// Watch Tasks
gulp.task('watchJS',    function() { gulp.watch( js_watchFolder,   ['js'    ]) })
gulp.task('watchLess',  function() { gulp.watch( less_watchFolder, ['styles']) })
gulp.task('watchPAGES', function() { gulp.watch( htmlFiles,        ['html'  ]) })
gulp.task('watchTPL',   function() { gulp.watch( tplFiles,         ['html'  ]) })
gulp.task('watchCX',    function() { gulp.watch( cxSrcFiles,       ['copy'  ]) })

gulp.task('watch',      ['watchJS' , 'watchLess', 'watchPAGES', 'watchTPL', 'watchCX'])

// Build
gulp.task('build',      ['html', 'styles', 'js', 'copy'])

// Bump Version
gulp.task('bump-patch', function() { return bumpFunc( 'patch' ) })
gulp.task('bump-minor', function() { return bumpFunc( 'minor' ) })

// Prep for Release
gulp.task('prep',       ['clean', 'getVersion', 'zip', 'zipCX'])

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


<commit_before>
require('babel/register');

var gulp = require('gulp');

require('./gulp/binaries');
require('./gulp/browser');
require('./gulp/clean');
require('./gulp/compile');
require('./gulp/copy');
require('./gulp/lint');
require('./gulp/version');
require('./gulp/watch');

gulp.task('bump:patch', ['bump:patch:tag', 'bump:patch:commit']);
gulp.task('bump:minor', ['bump:minor:tag', 'bump:minor:commit']);
gulp.task('bump:major', ['bump:major:tag', 'bump:major:commit']);

gulp.task('release:patch', ['bump:patch', 'upload:binaries', 'deploy']);
gulp.task('release:minor', ['bump:minor', 'upload:binaries', 'deploy']);
gulp.task('release:major', ['bump:major', 'upload:binaries', 'deploy']);

gulp.task('build:all', ['copy:dist', 'build:lib', 'compile:all']);
gulp.task('compile:all', ['compile:js', 'compile:sass', 'compile:jade']);
gulp.task('check', ['build:all']);

gulp.task('default', ['clean:all', 'build:all', 'connect', 'watch:all']);
<commit_msg>fix(build) i don't know what i am doing, sorry<commit_after>
require('babel/register');

var gulp = require('gulp');

require('./gulp/binaries');
require('./gulp/browser');
require('./gulp/clean');
require('./gulp/compile');
require('./gulp/copy');
require('./gulp/lint');
require('./gulp/version');
require('./gulp/watch');

gulp.task('bump:patch', ['bump:patch:tag', 'bump:patch:commit']);
gulp.task('bump:minor', ['bump:minor:tag', 'bump:minor:commit']);
gulp.task('bump:major', ['bump:major:tag', 'bump:major:commit']);

gulp.task('release:patch', ['bump:patch', 'upload:binaries', 'deploy']);
gulp.task('release:minor', ['bump:minor', 'upload:binaries', 'deploy']);
gulp.task('release:major', ['bump:major', 'upload:binaries', 'deploy']);

gulp.task('build', ['build:all']);
gulp.task('build:all', ['copy:dist', 'build:lib', 'compile:all']);
gulp.task('compile:all', ['compile:js', 'compile:sass', 'compile:jade']);
gulp.task('check', ['build:all']);

gulp.task('default', ['clean:all', 'build:all', 'connect', 'watch:all']);
<|endoftext|>


<commit_before>'use strict';

/**
 * Module dependencies.
 */
var _ = require('lodash'),
  defaultAssets = require('./config/assets/default'),
  testAssets = require('./config/assets/test'),
  config = require('./config/config'),
  gulp = require('gulp'),
  gulpLoadPlugins = require('gulp-load-plugins'),
  runSequence = require('run-sequence'),
  mergeStream = require('merge-stream'),
  glob = require('glob'),
  path = require('path'),
  del = require('del'),
  fs = require('fs'),
  argv = require('yargs').argv,
  plugins = gulpLoadPlugins({
    rename: {
      'gulp-angular-templatecache': 'templateCache'
    }
  }),
  KarmaServer = require('karma').Server;

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

// Set NODE_ENV to 'test'
gulp.task('env:test', function() {
  process.env.NODE_ENV = 'test';
});

// Set NODE_ENV to 'development'
gulp.task('env:dev', function() {
  process.env.NODE_ENV = 'development';
});

// Set NODE_ENV to 'production'
gulp.task('env:prod', function() {
  process.env.NODE_ENV = 'production';
});

// Make sure local config file exists
gulp.task('copyConfig', function(done) {
  if(!fs.existsSync('config/env/local.js') ) {
    return gulp
      .src('config/env/local.sample.js')
      .pipe(plugins.rename('local.js'))
      .pipe(gulp.dest('config/env/'));
  }
  else {
    done();
  }
});

// Nodemon task
gulp.task('nodemon', function() {
  return plugins.nodemon({
    script: 'server.js',
    nodeArgs: ['--debug'],
    ext: 'js html',
    watch: _.union(defaultAssets.server.views, defaultAssets.server.allJS, defaultAssets.server.config)
  });
});

// Watch files for changes
gulp.task('watch', function() {
  // Start livereload
  plugins.livereload.listen();

  // Add watch rules
  gulp.watch(defaultAssets.server.views).on('change', plugins.livereload.changed);
  gulp.watch(defaultAssets.server.allJS, ['jshint']).on('change', plugins.livereload.changed);
  gulp.watch(defaultAssets.server.fontelloConfig, ['fontello']);
  gulp.watch(defaultAssets.client.js, ['jshint', 'clean:js', 'scripts']);
  gulp.watch(defaultAssets.client.less, ['clean:css', 'styles']);

  if (process.env.NODE_ENV === 'production') {
    gulp.watch(defaultAssets.server.gulpConfig, ['templatecache', 'jshint']);
    gulp.watch(defaultAssets.client.views, ['clean:js', 'templatecache', 'jshint', 'scripts']).on('change', plugins.livereload.changed);
  } else {
    gulp.watch(defaultAssets.server.gulpConfig, ['jshint']);
    gulp.watch(defaultAssets.client.views).on('change', plugins.livereload.changed);
  }

  if (process.env.NODE_ENV === 'test') {
    // Add Server Test file rules
    gulp.watch([testAssets.tests.server, defaultAssets.server.allJS], ['test:server']).on('change', function (file) {

      var runOnlyChangedTestFile = argv.onlyChanged ? true : false;

      // check if we should only run a changed test file
      if (runOnlyChangedTestFile) {
        var changedTestFiles = [];

        // iterate through server test glob patterns
        _.forEach(testAssets.tests.server, function (pattern) {
          // determine if the changed (watched) file is a server test
          _.forEach(glob.sync(pattern), function (f) {
            var filePath = path.resolve(f);

            if (filePath === path.resolve(file.path)) {
              changedTestFiles.push(f);
            }
          });
        });

        // set task argument for tracking changed test files
        argv.changedTestFiles = changedTestFiles;
      }

      plugins.livereload.changed();
    });
  }

});

// JS linting task
gulp.task('jshint', function() {
  var assets = _.union(
    defaultAssets.server.gulpConfig,
    defaultAssets.server.allJS,
    defaultAssets.client.js,
    testAssets.tests.server,
    testAssets.tests.client,
    testAssets.tests.e2e
  );

  return gulp.src(assets)
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('default'))
    .pipe(plugins.jshint.reporter('fail'));
});

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

  // In production mode:
  if (process.env.NODE_ENV === 'production') {
    return gulp.src( _.union(defaultAssets.client.lib.js, defaultAssets.client.js, ['public/dist/templates.js']) )
      .pipe(plugins.ngAnnotate())
      .pipe(plugins.uglify({
        mangle: false
      }))
      .pipe(plugins.concat('application.min.js'))
      .pipe(gulp.dest('public/dist'));
  }
  // In development mode:
  else {
    return gulp.src(defaultAssets.client.js)
      .pipe(plugins.sourcemaps.init())
      .pipe(plugins.ngAnnotate())
      .pipe(plugins.concat('application.js'))
      .pipe(plugins.sourcemaps.write())
      .pipe(gulp.dest('public/dist'))
      .pipe(plugins.livereload());
  }
});

// Clean JS files -task
gulp.task('clean:js', function() {
  return del(['public/dist/*.js']);
});

// Clean CSS files -task
gulp.task('clean:css', function() {
  return del(['public/dist/*.css']);
});

// CSS styles task
gulp.task('styles', function() {

  // In production mode:
  if (process.env.NODE_ENV === 'production') {

    var cssStream = gulp.src(defaultAssets.client.lib.css)
        .pipe(plugins.concat('css-files.css'));

    var lessStream = gulp.src( _.union(defaultAssets.client.lib.less, defaultAssets.client.less) )
        .pipe(plugins.concat('less-files.less'))
        .pipe(plugins.less());

    // Combine CSS and LESS streams into one minified css file
    return mergeStream(lessStream, cssStream)
      .pipe(plugins.concat('application.css'))
      .pipe(plugins.autoprefixer())
    	.pipe(plugins.csso())
    	.pipe(plugins.rename({suffix: '.min'}))
      .pipe(gulp.dest('public/dist'));
  }
  // In development mode:
  else {
    // Process only LESS files, since CSS libs will be linked directly at the template
    return gulp.src( _.union(defaultAssets.client.lib.less, defaultAssets.client.less) )
      .pipe(plugins.concat('less-files.less'))
      .pipe(plugins.less())
      .pipe(plugins.autoprefixer())
    	.pipe(plugins.rename({basename: 'application', extname: '.css'}))
      .pipe(gulp.dest('public/dist'))
      .pipe(plugins.livereload());
  }
});

// Angular template cache task
gulp.task('templatecache', function() {
  return gulp.src(defaultAssets.client.views)
    .pipe(plugins.templateCache('templates.js', {
      root: 'modules/',
      module: 'core',
      templateHeader: '(function(){ \'use strict\'; angular.module(\'<%= module %>\'<%= standalone %>).run(templates); templates.$inject = [\'$templateCache\']; function templates($templateCache) {',
      templateBody: '$templateCache.put(\'<%= url %>\', \'<%= contents %>\');',
      templateFooter: '} })();'
    }))
    .pipe(gulp.dest('public/dist'));
});

// Generate font icon files from Fontello.com
gulp.task('fontello', function(done) {
  return gulp.src(defaultAssets.server.fontelloConfig)
    .pipe(plugins.fontello( {
      font:       'font', // Destination dir for Fonts and Glyphs
      css:        'css',  // Destination dir for CSS Styles,
      assetsOnly: true    // extract from ZipFile only CSS Styles and Fonts exclude config.json, LICENSE.txt, README.txt and demo.html
    }))
    .pipe(plugins.print())
    .pipe(gulp.dest('modules/core/client/fonts/fontello'))
    .pipe(plugins.livereload());
});

// Make sure upload directory exists
gulp.task('makeUploadsDir', function () {
  return fs.mkdir(config.uploadDir, function (err) {
    if (err && err.code !== 'EEXIST') {
      console.error(err);
    }
  });
});

// Run Selenium tasks
gulp.task('selenium', plugins.shell.task('python ./scripts/selenium/test.py'));

// Mocha tests task
gulp.task('mocha', function (done) {
  // Open mongoose connections
  var mongoose = require('./config/lib/mongoose');
  var testSuites = Array.isArray(argv.changedTestFiles) && argv.changedTestFiles.length ? argv.changedTestFiles : testAssets.tests.server;
  var error;

  // Connect mongoose
  mongoose.connect(function () {
    mongoose.loadModels();
    // Run the tests
    gulp.src(testSuites)
      .pipe(plugins.mocha({
        reporter: 'spec',
        timeout: 10000
      }))
      .on('error', function (err) {
        // If an error occurs, save it
        error = err;
        console.error(err);
      })
      .on('end', function () {
        // When the tests are done, disconnect mongoose and pass the error state back to gulp
        mongoose.disconnect(function () {
          done(error);
        });
      });
  });

});

// Karma test runner task
gulp.task('karma', function(done) {
  return gulp.src([])
    .pipe(plugins.karma({
      configFile: 'karma.conf.js',
      action: 'run',
      singleRun: true
    }));
});

// Karma test runner task
gulp.task('karma', function (done) {
  new KarmaServer({
    configFile: __dirname + '/karma.conf.js',
    singleRun: true
  }, done).start();
});

// Build assets for development mode
gulp.task('build:dev', function(done) {
  runSequence('env:dev', 'bower', 'jshint', 'clean', ['styles', 'scripts'], done);
});

// Build assets for production mode
gulp.task('build:prod', function(done) {
  runSequence('env:prod', 'bower', 'jshint', 'templatecache', 'clean', ['styles', 'scripts'], done);
});

// Clean dist css and js files
gulp.task('clean', function(done) {
  runSequence(['clean:css', 'clean:js'], done);
});

// Run the project tests
gulp.task('test', function(done) {
  runSequence('env:test', 'copyConfig', 'makeUploadsDir', 'jshint', ['karma', 'mocha'], done);
});

gulp.task('test:server', function(done) {
  runSequence('env:test', 'copyConfig', 'makeUploadsDir', 'jshint', 'mocha', done);
});

// Watch all server files for changes & run server tests (test:server) task on changes
// optional arguments:
//    --onlyChanged - optional argument for specifying that only the tests in a changed Server Test file will be run
// example usage: gulp test:server:watch --onlyChanged
gulp.task('test:server:watch', function (done) {
  runSequence('test:server', 'watch', done);
});

gulp.task('test:client', function(done) {
  runSequence('env:test', 'copyConfig', 'makeUploadsDir', 'jshint', 'karma', done);
});

// Run the project in development mode
gulp.task('develop', function(done) {
  runSequence('env:dev', 'copyConfig', 'makeUploadsDir', 'build:dev', ['nodemon', 'watch'], done);
});

// Run the project in production mode
gulp.task('prod', function(done) {
  runSequence('env:prod', 'copyConfig', 'makeUploadsDir', 'build:prod', ['nodemon', 'watch'], done);
});

// Default to develop mode
gulp.task('default', function(done) {
  runSequence('develop', done);
});
<commit_msg>Move loading config after env:* tasks are run.<commit_after>'use strict';

/**
 * Module dependencies.
 */
var _ = require('lodash'),
  defaultAssets = require('./config/assets/default'),
  testAssets = require('./config/assets/test'),
  gulp = require('gulp'),
  gulpLoadPlugins = require('gulp-load-plugins'),
  runSequence = require('run-sequence'),
  mergeStream = require('merge-stream'),
  glob = require('glob'),
  path = require('path'),
  del = require('del'),
  fs = require('fs'),
  argv = require('yargs').argv,
  plugins = gulpLoadPlugins({
    rename: {
      'gulp-angular-templatecache': 'templateCache'
    }
  }),
  KarmaServer = require('karma').Server;

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

// Set NODE_ENV to 'test'
gulp.task('env:test', function() {
  process.env.NODE_ENV = 'test';
});

// Set NODE_ENV to 'development'
gulp.task('env:dev', function() {
  process.env.NODE_ENV = 'development';
});

// Set NODE_ENV to 'production'
gulp.task('env:prod', function() {
  process.env.NODE_ENV = 'production';
});

// Make sure local config file exists
gulp.task('copyConfig', function(done) {
  if(!fs.existsSync('config/env/local.js') ) {
    return gulp
      .src('config/env/local.sample.js')
      .pipe(plugins.rename('local.js'))
      .pipe(gulp.dest('config/env/'));
  }
  else {
    done();
  }
});

// Nodemon task
gulp.task('nodemon', function() {
  return plugins.nodemon({
    script: 'server.js',
    nodeArgs: ['--debug'],
    ext: 'js html',
    watch: _.union(defaultAssets.server.views, defaultAssets.server.allJS, defaultAssets.server.config)
  });
});

// Watch files for changes
gulp.task('watch', function() {
  // Start livereload
  plugins.livereload.listen();

  // Add watch rules
  gulp.watch(defaultAssets.server.views).on('change', plugins.livereload.changed);
  gulp.watch(defaultAssets.server.allJS, ['jshint']).on('change', plugins.livereload.changed);
  gulp.watch(defaultAssets.server.fontelloConfig, ['fontello']);
  gulp.watch(defaultAssets.client.js, ['jshint', 'clean:js', 'scripts']);
  gulp.watch(defaultAssets.client.less, ['clean:css', 'styles']);

  if (process.env.NODE_ENV === 'production') {
    gulp.watch(defaultAssets.server.gulpConfig, ['templatecache', 'jshint']);
    gulp.watch(defaultAssets.client.views, ['clean:js', 'templatecache', 'jshint', 'scripts']).on('change', plugins.livereload.changed);
  } else {
    gulp.watch(defaultAssets.server.gulpConfig, ['jshint']);
    gulp.watch(defaultAssets.client.views).on('change', plugins.livereload.changed);
  }

  if (process.env.NODE_ENV === 'test') {
    // Add Server Test file rules
    gulp.watch([testAssets.tests.server, defaultAssets.server.allJS], ['test:server']).on('change', function(file) {

      var runOnlyChangedTestFile = argv.onlyChanged ? true : false;

      // check if we should only run a changed test file
      if (runOnlyChangedTestFile) {
        var changedTestFiles = [];

        // iterate through server test glob patterns
        _.forEach(testAssets.tests.server, function(pattern) {
          // determine if the changed (watched) file is a server test
          _.forEach(glob.sync(pattern), function(f) {
            var filePath = path.resolve(f);

            if (filePath === path.resolve(file.path)) {
              changedTestFiles.push(f);
            }
          });
        });

        // set task argument for tracking changed test files
        argv.changedTestFiles = changedTestFiles;
      }

      plugins.livereload.changed();
    });
  }

});

// JS linting task
gulp.task('jshint', function() {
  var assets = _.union(
    defaultAssets.server.gulpConfig,
    defaultAssets.server.allJS,
    defaultAssets.client.js,
    testAssets.tests.server,
    testAssets.tests.client,
    testAssets.tests.e2e
  );

  return gulp.src(assets)
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('default'))
    .pipe(plugins.jshint.reporter('fail'));
});

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

  // In production mode:
  if (process.env.NODE_ENV === 'production') {
    return gulp.src( _.union(defaultAssets.client.lib.js, defaultAssets.client.js, ['public/dist/templates.js']) )
      .pipe(plugins.ngAnnotate())
      .pipe(plugins.uglify({
        mangle: false
      }))
      .pipe(plugins.concat('application.min.js'))
      .pipe(gulp.dest('public/dist'));
  }
  // In development mode:
  else {
    return gulp.src(defaultAssets.client.js)
      .pipe(plugins.sourcemaps.init())
      .pipe(plugins.ngAnnotate())
      .pipe(plugins.concat('application.js'))
      .pipe(plugins.sourcemaps.write())
      .pipe(gulp.dest('public/dist'))
      .pipe(plugins.livereload());
  }
});

// Clean JS files -task
gulp.task('clean:js', function() {
  return del(['public/dist/*.js']);
});

// Clean CSS files -task
gulp.task('clean:css', function() {
  return del(['public/dist/*.css']);
});

// CSS styles task
gulp.task('styles', function() {

  // In production mode:
  if (process.env.NODE_ENV === 'production') {

    var cssStream = gulp.src(defaultAssets.client.lib.css)
        .pipe(plugins.concat('css-files.css'));

    var lessStream = gulp.src( _.union(defaultAssets.client.lib.less, defaultAssets.client.less) )
        .pipe(plugins.concat('less-files.less'))
        .pipe(plugins.less());

    // Combine CSS and LESS streams into one minified css file
    return mergeStream(lessStream, cssStream)
      .pipe(plugins.concat('application.css'))
      .pipe(plugins.autoprefixer())
    	.pipe(plugins.csso())
    	.pipe(plugins.rename({suffix: '.min'}))
      .pipe(gulp.dest('public/dist'));
  }
  // In development mode:
  else {
    // Process only LESS files, since CSS libs will be linked directly at the template
    return gulp.src( _.union(defaultAssets.client.lib.less, defaultAssets.client.less) )
      .pipe(plugins.concat('less-files.less'))
      .pipe(plugins.less())
      .pipe(plugins.autoprefixer())
    	.pipe(plugins.rename({basename: 'application', extname: '.css'}))
      .pipe(gulp.dest('public/dist'))
      .pipe(plugins.livereload());
  }
});

// Angular template cache task
gulp.task('templatecache', function() {
  return gulp.src(defaultAssets.client.views)
    .pipe(plugins.templateCache('templates.js', {
      root: 'modules/',
      module: 'core',
      templateHeader: '(function(){ \'use strict\'; angular.module(\'<%= module %>\'<%= standalone %>).run(templates); templates.$inject = [\'$templateCache\']; function templates($templateCache) {',
      templateBody: '$templateCache.put(\'<%= url %>\', \'<%= contents %>\');',
      templateFooter: '} })();'
    }))
    .pipe(gulp.dest('public/dist'));
});

// Generate font icon files from Fontello.com
gulp.task('fontello', function(done) {
  return gulp.src(defaultAssets.server.fontelloConfig)
    .pipe(plugins.fontello( {
      font:       'font', // Destination dir for Fonts and Glyphs
      css:        'css',  // Destination dir for CSS Styles,
      assetsOnly: true    // extract from ZipFile only CSS Styles and Fonts exclude config.json, LICENSE.txt, README.txt and demo.html
    }))
    .pipe(plugins.print())
    .pipe(gulp.dest('modules/core/client/fonts/fontello'))
    .pipe(plugins.livereload());
});

// Make sure upload directory exists
gulp.task('makeUploadsDir', function() {

  // Loading this before `env:*` task will load configs with wrong environment
  var config = require('./config/config');

  return fs.mkdir(config.uploadDir, function(err) {
    if (err && err.code !== 'EEXIST') {
      console.error(err);
    }
  });
});

// Run Selenium tasks
gulp.task('selenium', plugins.shell.task('python ./scripts/selenium/test.py'));

// Mocha tests task
gulp.task('mocha', function(done) {
  // Open mongoose connections
  var mongoose = require('./config/lib/mongoose');
  var testSuites = Array.isArray(argv.changedTestFiles) && argv.changedTestFiles.length ? argv.changedTestFiles : testAssets.tests.server;
  var error;

  // Connect mongoose
  mongoose.connect(function() {
    mongoose.loadModels();
    // Run the tests
    gulp.src(testSuites)
      .pipe(plugins.mocha({
        reporter: 'spec',
        timeout: 10000
      }))
      .on('error', function(err) {
        // If an error occurs, save it
        error = err;
        console.error(err);
      })
      .on('end', function() {
        // When the tests are done, disconnect mongoose and pass the error state back to gulp
        mongoose.disconnect(function() {
          done(error);
        });
      });
  });

});

// Karma test runner task
gulp.task('karma', function(done) {
  new KarmaServer({
    configFile: __dirname + '/karma.conf.js',
    singleRun: true
  }, done).start();
});

// Build assets for development mode
gulp.task('build:dev', function(done) {
  runSequence('env:dev', 'bower', 'jshint', 'clean', ['styles', 'scripts'], done);
});

// Build assets for production mode
gulp.task('build:prod', function(done) {
  runSequence('env:prod', 'bower', 'jshint', 'templatecache', 'clean', ['styles', 'scripts'], done);
});

// Clean dist css and js files
gulp.task('clean', function(done) {
  runSequence(['clean:css', 'clean:js'], done);
});

// Run the project tests
gulp.task('test', function(done) {
  runSequence('env:test', ['copyConfig', 'makeUploadsDir'], 'jshint', ['karma', 'mocha'], done);
});

gulp.task('test:server', function(done) {
  runSequence('env:test', ['copyConfig', 'makeUploadsDir'], 'jshint', 'mocha', done);
});

// Watch all server files for changes & run server tests (test:server) task on changes
// optional arguments:
//    --onlyChanged - optional argument for specifying that only the tests in a changed Server Test file will be run
// example usage: gulp test:server:watch --onlyChanged
gulp.task('test:server:watch', function(done) {
  runSequence('test:server', 'watch', done);
});

gulp.task('test:client', function(done) {
  runSequence('env:test', ['copyConfig', 'makeUploadsDir'], 'jshint', 'karma', done);
});

// Run the project in development mode
gulp.task('develop', function(done) {
  runSequence('env:dev', ['copyConfig', 'makeUploadsDir'], 'build:dev', ['nodemon', 'watch'], done);
});

// Run the project in production mode
gulp.task('prod', function(done) {
  runSequence('env:prod', ['copyConfig', 'makeUploadsDir'], 'build:prod', ['nodemon', 'watch'], done);
});

// Default to develop mode
gulp.task('default', function(done) {
  runSequence('develop', done);
});
<|endoftext|>


<commit_before>var gulp = require('gulp'),
mainBowerFiles = require('main-bower-files'),
handlebars = require('gulp-handlebars'),
wrap = require('gulp-wrap'),
declare = require('gulp-declare'),
concat = require('gulp-concat'),
filter = require('gulp-filter'),
uglify = require('gulp-uglify'),
less = require('gulp-less'),
minifyCSS = require('gulp-minify-css'),
del = require('del'),
dest = 'build/';

gulp.task('templates', function(){
	return gulp.src(['js/app/templates/table.hbs', 'js/app/templates/logs.hbs'])
	.pipe(handlebars())
	.pipe(wrap('Handlebars.template(<%= contents %>)'))
	.pipe(declare({
		namespace: 'StatusPage.templates',
      noRedeclare: true, // Avoid duplicate declarations
  }))
	.pipe(concat('templates.js'))
	.pipe(gulp.dest('js/app/'));
});

gulp.task('vendors', function() {
	return gulp.src(mainBowerFiles())
	.pipe(filter('*.js'))
	.pipe(concat('vendors.js'))
	.pipe(gulp.dest('js/app/'));
});

gulp.task('jsCombine', ['vendors', 'templates'], function() {
	return gulp.src(['js/app/vendors.js', 'js/app/main.js', 'js/app/templates.js', 'js/app/config.js'])
	.pipe(concat('statuspage.min.js'))
	.pipe(uglify())
	.pipe(gulp.dest(dest + 'js'));
});

gulp.task('icons', function() {
	return gulp.src('bower_components/fontawesome/fonts/**.*')
	.pipe(gulp.dest(dest + 'fonts'));
});

gulp.task('php', function() {
	return gulp.src('backend/statuspage/*')
	.pipe(gulp.dest(dest + 'statuspage'));
});

gulp.task('html', function() {
	return gulp.src('html/*.html')
	.pipe(gulp.dest(dest));
});

gulp.task('less', function() {
	return gulp.src('less/*.less')
	.pipe(less())
	.pipe(concat('statuspage.min.css'))
	.pipe(minifyCSS())
	.pipe(gulp.dest(dest + 'css'));
});

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

gulp.task('default', ['jsCombine', 'icons', 'html', 'less', 'php']);
<commit_msg>Didn't check enough<commit_after>var gulp = require('gulp'),
mainBowerFiles = require('main-bower-files'),
handlebars = require('gulp-handlebars'),
wrap = require('gulp-wrap'),
declare = require('gulp-declare'),
concat = require('gulp-concat'),
filter = require('gulp-filter'),
uglify = require('gulp-uglify'),
less = require('gulp-less'),
minifyCSS = require('gulp-minify-css'),
del = require('del'),
dest = 'build/';

gulp.task('templates', function(){
	return gulp.src(['js/app/templates/table.hbs', 'js/app/templates/logs.hbs'])
	.pipe(handlebars())
	.pipe(wrap('Handlebars.template(<%= contents %>)'))
	.pipe(declare({
		namespace: 'StatusPage.templates',
      noRedeclare: true, // Avoid duplicate declarations
  }))
	.pipe(concat('templates.js'))
	.pipe(gulp.dest('js/app/'));
});

gulp.task('vendors', function() {
	return gulp.src(mainBowerFiles())
	.pipe(filter('*.js'))
	.pipe(concat('vendors.js'))
	.pipe(gulp.dest('js/app/'));
});

gulp.task('jsCombine', ['vendors', 'templates'], function() {
	return gulp.src(['js/app/vendors.js', 'js/app/main.js', 'js/app/templates.js', 'js/app/config.js'])
	.pipe(concat('statuspage.min.js'))
	.pipe(uglify())
	.pipe(gulp.dest(dest + 'js'));
});

gulp.task('icons', function() {
	return gulp.src('bower_components/fontawesome/fonts/**.*')
	.pipe(gulp.dest(dest + 'fonts'));
});

gulp.task('php', function() {
	return gulp.src('backend/statuspage/**/**/*')
	.pipe(gulp.dest(dest + 'statuspage'));
});

gulp.task('html', function() {
	return gulp.src('html/*.html')
	.pipe(gulp.dest(dest));
});

gulp.task('less', function() {
	return gulp.src('less/*.less')
	.pipe(less())
	.pipe(concat('statuspage.min.css'))
	.pipe(minifyCSS())
	.pipe(gulp.dest(dest + 'css'));
});

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

gulp.task('default', ['jsCombine', 'icons', 'html', 'less', 'php']);
<|endoftext|>


<commit_before>var gulp   = require('gulp');
var gutil  = require('gulp-util');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var Karma  = require('karma').Server;
var argv   = require('minimist')(process.argv.slice(2));

gulp.task('lint', function () {
  gutil.log(gutil.colors.red('@todo: Implement eslint step.'));
});

gulp.task('test', function (done) {
  new Karma({
    configFile: __dirname + '/karma.conf.js',
    singleRun: !argv.tdd
  }, done).start();
});

gulp.task('test:browser', function (done) {
  new Karma({
    configFile: __dirname + '/karma.conf.js',
    singleRun: !argv.tdd,
    browsers: [ 'Firefox', 'Chrome', 'Opera' ]
  }, done).start();
});

gulp.task('ci', ['lint', 'test']);

gulp.task('build', function () {
  return gulp
    .src('src/bindNotifier.js')
    .pipe(rename('angular-bind-notifier.js'))
    .pipe(gulp.dest('dist'))
    .pipe(rename('angular-bind-notifier.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest('dist'));
});

gulp.task('package', ['lint', 'test', 'build']);
gulp.task('default', ['build']);
<commit_msg>chore(gulp): reorganize tasks<commit_after>var gulp   = require('gulp');
var gutil  = require('gulp-util');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var Karma  = require('karma').Server;
var argv   = require('minimist')(process.argv.slice(2));

gulp.task('lint', function () {
  gutil.log(gutil.colors.red('@todo: Implement eslint step.'));
});

gulp.task('test', function (done) {
  new Karma({
    configFile: __dirname + '/karma.conf.js',
    singleRun: !argv.tdd
  }, done).start();
});

gulp.task('test:browser', function (done) {
  new Karma({
    configFile: __dirname + '/karma.conf.js',
    singleRun: !argv.tdd,
    browsers: [ 'Firefox', 'Chrome', 'Opera' ]
  }, done).start();
});

gulp.task('build', function () {
  return gulp
    .src('src/bindNotifier.js')
    .pipe(rename('angular-bind-notifier.js'))
    .pipe(gulp.dest('dist'))
    .pipe(rename('angular-bind-notifier.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest('dist'));
});

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


<commit_before>'use strict';

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

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

});

gulp.task('sass', function () {
    return gulp.src('./styles/warriormachines_2016/theme/sass/app.scss')
        .pipe(sass().on('error', sass.logError))
        .pipe(gulp.dest('./styles/warriormachines_2016/theme/gulp-generated/css'));
});

gulp.task('fonts', function() {
    gulp.src('./node_modules/font-awesome/fonts/**/*.{eot,svg,ttf,woff,woff2}')
        .pipe(gulp.dest('./styles/warriormachines_2016/theme/gulp-generated/fonts'));
});

gulp.task('sass:watch', function () {
    gulp.watch('./styles/warriormachines_2016/theme/sass/app.scss', ['sass']);
});
<commit_msg>Remove `fonts` gulp task from default task<commit_after>'use strict';

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

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

});

gulp.task('sass', function () {
    return gulp.src('./styles/warriormachines_2016/theme/sass/app.scss')
        .pipe(sass().on('error', sass.logError))
        .pipe(gulp.dest('./styles/warriormachines_2016/theme/gulp-generated/css'));
});

gulp.task('fonts', function() {
    gulp.src('./node_modules/font-awesome/fonts/**/*.{eot,svg,ttf,woff,woff2}')
        .pipe(gulp.dest('./styles/warriormachines_2016/theme/gulp-generated/fonts'));
});

gulp.task('sass:watch', function () {
    gulp.watch('./styles/warriormachines_2016/theme/sass/app.scss', ['sass']);
});
<|endoftext|>


<commit_before>'use strict'

const gulp=require('gulp')
const gulpTasks=require('crnx-build/gulp-tasks')

gulpTasks(
	gulp,
	{
		en: "Web Audio API example generator",
		ru: "Генератор примеров Web Audio API",
	},
	['http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/styles/default.min.css'],
	['http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/highlight.min.js'],
	[require.resolve('crnx-base')]
)
<commit_msg>updated highlight.js - fixes unquoted html attrs highlighting<commit_after>'use strict'

const gulp=require('gulp')
const gulpTasks=require('crnx-build/gulp-tasks')

gulpTasks(
	gulp,
	{
		en: "Web Audio API example generator",
		ru: "Генератор примеров Web Audio API",
	},
	['http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.3.0/styles/default.min.css'],
	['http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.3.0/highlight.min.js'],
	[require.resolve('crnx-base')]
)
<|endoftext|>


<commit_before>const gulp = require('gulp');
const glob = require('glob');
const shell = cmd => require('child_process').execSync(cmd, { stdio: [0, 1, 2] });
const del = require('del');
const extend = require('extend');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const $ = require('gulp-load-plugins')();
const seq = require('run-sequence');
const browserify = require('browserify');
const tsify = require('tsify');
const Server = require('karma').Server;

const pkg = require('./package.json');
const config = {
  browsers: ['Chrome', 'Firefox'].concat((os => {
    switch (os) {
      case 'Windows_NT':
        return ['Edge'];
      case 'Darwin':
        return [];
     default:
        return [];
    }
  })(require('os').type())),
  ts: {
    dist: {
      src: [
        '*.ts'
      ],
      dest: 'dist'
    },
    test: {
      src: [
        '*.ts',
        'src/**/*.ts',
        'test/**/*.ts'
      ],
      dest: 'dist'
    },
    bench: {
      src: [
        '*.ts',
        'benchmark/**/*.ts'
      ],
      dest: 'dist'
    }
  },
  banner: [
    `/*! ${pkg.name} v${pkg.version} ${pkg.repository.url} | (c) 2016, ${pkg.author} | ${pkg.license} License */`,
    ''
  ].join('\n'),
  clean: {
    dist: 'dist'
  }
};

function compile(paths) {
  let done = true;
  return browserify({
      basedir: '.',
      debug: false,
      entries: Object.values(paths).map(p => glob.sync(p)),
      cache: {},
      packageCache: {}
    })
    .require(`./${pkg.name}.ts`, { expose: pkg.name })
    .plugin(tsify, require('./tsconfig.json').compilerOptions)
    .bundle()
    .on("error", err => done = console.log(err + ''))
    .pipe(source(`${pkg.name}.js`))
    .pipe(buffer())
    .pipe($.derequire())
    .once("finish", () => done || process.exit(1));
}

gulp.task('ts:watch', function () {
  gulp.watch(config.ts.test.src, ['ts:test']);
});

gulp.task('ts:test', function () {
  return compile(config.ts.test.src)
    .pipe(gulp.dest(config.ts.test.dest));
});

gulp.task('ts:bench', function () {
  return compile(config.ts.bench.src)
    .pipe($.unassert())
    .pipe(gulp.dest(config.ts.bench.dest));
});

gulp.task('ts:dist', function () {
  return compile(config.ts.dist.src)
    .pipe($.unassert())
    .pipe($.header(config.banner))
    .pipe(gulp.dest(config.ts.dist.dest))
    .pipe($.uglify({ preserveComments: 'license' }))
    .pipe($.rename({ extname: '.min.js' }))
    .pipe(gulp.dest(config.ts.dist.dest));
});

gulp.task('karma:watch', function (done) {
  new Server({
    configFile: __dirname + '/karma.conf.js',
    browsers: config.browsers,
    preprocessors: {
      'dist/*.js': ['espower']
    },
  }, done).start();
});

gulp.task('karma:test', function (done) {
  new Server({
    configFile: __dirname + '/karma.conf.js',
    browsers: config.browsers,
    reporters: ['dots', 'coverage'],
    preprocessors: {
      'dist/*.js': ['coverage', 'espower']
    },
    singleRun: true
  }, done).start();
});

gulp.task('karma:bench', function (done) {
  new Server({
    configFile: __dirname + '/karma.conf.js',
    browsers: config.browsers,
    singleRun: true
  }, done).start();
});

gulp.task('karma:ci', function (done) {
  new Server({
    configFile: __dirname + '/karma.conf.js',
    browsers: config.browsers,
    reporters: ['dots', 'coverage', 'coveralls'],
    preprocessors: {
      'dist/*.js': ['coverage', 'espower']
    },
    singleRun: true
  }, done).start();
});

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

gulp.task('install', function () {
  shell('npm i');
});

gulp.task('update', function () {
  shell('ncu -ua');
  shell('npm i');
});

gulp.task('watch', ['clean'], function () {
  seq(
    'ts:test',
    [
      'ts:watch',
      'karma:watch'
    ]
  );
});

gulp.task('test', ['clean'], function (done) {
  seq(
    'ts:test',
    'karma:test',
    function () {
      done();
    }
  );
});

gulp.task('bench', ['clean'], function (done) {
  seq(
    'ts:bench',
    'karma:bench',
    function () {
      done();
    }
  );
});

gulp.task('dist', ['clean'], function (done) {
  seq(
    'ts:dist',
    done
  );
});

gulp.task('ci', ['clean'], function (done) {
  seq(
    'ts:test',
    'karma:ci',
    'dist',
    function () {
      done();
    }
  );
});
<commit_msg>chore(config): update build scripts<commit_after>const gulp = require('gulp');
const glob = require('glob');
const shell = cmd => require('child_process').execSync(cmd, { stdio: [0, 1, 2] });
const del = require('del');
const extend = require('extend');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const $ = require('gulp-load-plugins')();
const seq = require('run-sequence');
const browserify = require('browserify');
const tsify = require('tsify');
const Server = require('karma').Server;

const pkg = require('./package.json');
const config = {
  browsers: ['Chrome', 'Firefox'].concat((os => {
    switch (os) {
      case 'Windows_NT':
        return ['Edge'];
      case 'Darwin':
        return [];
     default:
        return [];
    }
  })(require('os').type())),
  ts: {
    dist: {
      src: [
        '*.ts'
      ],
      dest: 'dist'
    },
    test: {
      src: [
        '*.ts',
        'src/**/*.ts',
        'test/**/*.ts'
      ],
      dest: 'dist'
    },
    bench: {
      src: [
        '*.ts',
        'benchmark/**/*.ts'
      ],
      dest: 'dist'
    }
  },
  banner: [
    `/*! ${pkg.name} v${pkg.version} ${pkg.repository.url} | (c) 2016, ${pkg.author} | ${pkg.license} License */`,
    ''
  ].join('\n'),
  clean: {
    dist: 'dist'
  }
};

function compile(paths) {
  let done = true;
  return browserify({
      basedir: '.',
      debug: false,
      entries: Object.values(paths).map(p => glob.sync(p)),
      bundleExternal: false,
      cache: {},
      packageCache: {}
    })
    .require(`./${pkg.name}.ts`, { expose: pkg.name })
    .plugin(tsify, require('./tsconfig.json').compilerOptions)
    .bundle()
    .on("error", err => done = console.log(err + ''))
    .pipe(source(`${pkg.name}.js`))
    .pipe(buffer())
    .pipe($.derequire())
    .once("finish", () => done || process.exit(1));
}

gulp.task('ts:watch', function () {
  gulp.watch(config.ts.test.src, ['ts:test']);
});

gulp.task('ts:test', function () {
  return compile(config.ts.test.src)
    .pipe(gulp.dest(config.ts.test.dest));
});

gulp.task('ts:bench', function () {
  return compile(config.ts.bench.src)
    .pipe($.unassert())
    .pipe(gulp.dest(config.ts.bench.dest));
});

gulp.task('ts:dist', function () {
  return compile(config.ts.dist.src)
    .pipe($.unassert())
    .pipe($.header(config.banner))
    .pipe(gulp.dest(config.ts.dist.dest))
    .pipe($.uglify({ preserveComments: 'license' }))
    .pipe($.rename({ extname: '.min.js' }))
    .pipe(gulp.dest(config.ts.dist.dest));
});

gulp.task('karma:watch', function (done) {
  new Server({
    configFile: __dirname + '/karma.conf.js',
    browsers: config.browsers,
    preprocessors: {
      'dist/*.js': ['espower']
    },
  }, done).start();
});

gulp.task('karma:test', function (done) {
  new Server({
    configFile: __dirname + '/karma.conf.js',
    browsers: config.browsers,
    reporters: ['dots', 'coverage'],
    preprocessors: {
      'dist/*.js': ['coverage', 'espower']
    },
    singleRun: true
  }, done).start();
});

gulp.task('karma:bench', function (done) {
  new Server({
    configFile: __dirname + '/karma.conf.js',
    browsers: config.browsers,
    singleRun: true
  }, done).start();
});

gulp.task('karma:ci', function (done) {
  new Server({
    configFile: __dirname + '/karma.conf.js',
    browsers: config.browsers,
    reporters: ['dots', 'coverage', 'coveralls'],
    preprocessors: {
      'dist/*.js': ['coverage', 'espower']
    },
    singleRun: true
  }, done).start();
});

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

gulp.task('install', function () {
  shell('npm i');
});

gulp.task('update', function () {
  shell('ncu -ua');
  shell('npm i');
});

gulp.task('watch', ['clean'], function () {
  seq(
    'ts:test',
    [
      'ts:watch',
      'karma:watch'
    ]
  );
});

gulp.task('test', ['clean'], function (done) {
  seq(
    'ts:test',
    'karma:test',
    function () {
      done();
    }
  );
});

gulp.task('bench', ['clean'], function (done) {
  seq(
    'ts:bench',
    'karma:bench',
    function () {
      done();
    }
  );
});

gulp.task('dist', ['clean'], function (done) {
  seq(
    'ts:dist',
    done
  );
});

gulp.task('ci', ['clean'], function (done) {
  seq(
    'ts:test',
    'karma:ci',
    'dist',
    function () {
      done();
    }
  );
});
<|endoftext|>


<commit_before>'use strict';
var path = require('path');
var gulp = require('gulp');
var eslint = require('gulp-eslint');
var excludeGitignore = require('gulp-exclude-gitignore');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var nsp = require('gulp-nsp');
var plumber = require('gulp-plumber');
var coveralls = require('gulp-coveralls');

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

gulp.task('nsp', function (cb) {
  nsp({package: path.resolve('package.json')}, cb);
});

gulp.task('pre-test', function () {
  return gulp.src('generators/**/*.js')
    .pipe(excludeGitignore())
    .pipe(istanbul({
      includeUntested: true
    }))
    .pipe(istanbul.hookRequire());
});

gulp.task('test', ['pre-test'], function (cb) {
  var mochaErr;

  gulp.src('test/**/*.js')
    .pipe(plumber())
    .pipe(mocha({reporter: 'spec'}))
    .on('error', function (err) {
      mochaErr = err;
    })
    .pipe(istanbul.writeReports())
    .on('end', function () {
      cb(mochaErr);
    });
});

gulp.task('watch', function () {
  gulp.watch(['generators/**/*.js', 'test/**'], ['test']);
});

gulp.task('coveralls', ['test'], function () {
  if (!process.env.CI) {
    return undefined;
  }

  return gulp.src(path.join(__dirname, 'coverage/lcov.info'))
    .pipe(coveralls());
});

gulp.task('prepublish', ['nsp']);
gulp.task('default', ['static', 'test', 'coveralls']);
<commit_msg>Increase test timeout<commit_after>'use strict';
var path = require('path');
var gulp = require('gulp');
var eslint = require('gulp-eslint');
var excludeGitignore = require('gulp-exclude-gitignore');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var nsp = require('gulp-nsp');
var plumber = require('gulp-plumber');
var coveralls = require('gulp-coveralls');

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

gulp.task('nsp', function (cb) {
  nsp({package: path.resolve('package.json')}, cb);
});

gulp.task('pre-test', function () {
  return gulp.src('generators/**/*.js')
    .pipe(excludeGitignore())
    .pipe(istanbul({
      includeUntested: true
    }))
    .pipe(istanbul.hookRequire());
});

gulp.task('test', ['pre-test'], function (cb) {
  var mochaErr;

  gulp.src('test/**/*.js')
    .pipe(plumber())
    .pipe(mocha({reporter: 'spec', timeout: 4000}))
    .on('error', function (err) {
      mochaErr = err;
    })
    .pipe(istanbul.writeReports())
    .on('end', function () {
      cb(mochaErr);
    });
});

gulp.task('watch', function () {
  gulp.watch(['generators/**/*.js', 'test/**'], ['test']);
});

gulp.task('coveralls', ['test'], function () {
  if (!process.env.CI) {
    return undefined;
  }

  return gulp.src(path.join(__dirname, 'coverage/lcov.info'))
    .pipe(coveralls());
});

gulp.task('prepublish', ['nsp']);
gulp.task('default', ['static', 'test', 'coveralls']);
<|endoftext|>


<commit_before>const babelify = require('babelify');
const browserify = require('browserify');
const buffer = require('vinyl-buffer');
const cssnano = require('gulp-cssnano');
const del = require('del');
const gulp = require('gulp');
const gutil = require('gulp-util');
const htmlmin = require('gulp-htmlmin');
const jsonMinify = require('gulp-json-minify');
const source = require('vinyl-source-stream');
const uglify = require('gulp-uglify');
const zip = require('gulp-zip');

function processJsFile(fileName, debug) {
  // https://github.com/gulpjs/gulp/blob/master/docs/recipes/browserify-uglify-sourcemap.md

  let uglifyConfigs = {};

  // remove console.log if debug is false
  if (!debug) {
    uglifyConfigs = {
      compress: {
        pure_funcs: [
          'console.log',
          'console.error',
        ],
      },
    };
  }

  const b = browserify({
    entries: `src/js/${fileName}.js`,
  }).transform(babelify.configure({
    presets: ['es2015'],
  })).bundle()
    .on('error', gutil.log)
    .pipe(source(`${fileName}.js`))
    .pipe(buffer());
  if (!debug) {
    b.pipe(uglify(uglifyConfigs));
  }
  b.pipe(gulp.dest('dist/js'));
}

function buildJs(debug) {
  processJsFile('eventPage', debug);
  processJsFile('options', debug);
  processJsFile('popup', debug);
  processJsFile('content-google', debug);
  processJsFile('content-duckduckgo', debug);
}

function buildCss() {
  gulp.src('src/css/*.css')
    .pipe(cssnano())
    .on('error', gutil.log)
    .pipe(gulp.dest('dist/css'));
}

function buildHtml() {
  gulp.src('src/html/*.html')
    .pipe(htmlmin({
      collapseWhitespace: true,
      removeComments: true,
    }))
    .on('error', gutil.log)
    .pipe(gulp.dest('dist/html'));
}

function buildManifest() {
  gulp.src([
    'src/manifest.json',
  ]).pipe(jsonMinify())
    .pipe(gulp.dest('dist'));
}

function buildImg() {
  gulp.src([
    'src/img/*',
  ]).pipe(gulp.dest('dist/img'));
}

function buildMisc() {
  gulp.src([
    'node_modules/jquery/dist/jquery.min.js',
  ]).pipe(gulp.dest('src/js/lib'))
    .pipe(gulp.dest('dist/js/lib'));

  gulp.src([
    'src/js/lib/jquery.tooltipster.min.js',
  ]).pipe(gulp.dest('dist/js/lib'));

  gulp.src([
    'src/css/lib/tooltipster.css',
  ]).pipe(cssnano())
    .pipe(gulp.dest('dist/css/lib'));
}

gulp.task('js', () => {
  buildJs(false);
});

gulp.task('js:debug', () => {
  buildJs(true);
});

gulp.task('css', () => {
  buildCss();
});

gulp.task('html', () => {
  buildHtml();
});

gulp.task('manifest', () => {
  buildManifest();
});

gulp.task('img', () => {
  buildImg();
});

gulp.task('misc', () => {
  buildMisc();
});

gulp.task('build', ['clean'], () => {
  buildJs(false);
  buildCss();
  buildHtml();
  buildManifest();
  buildImg();
  buildMisc();
});

gulp.task('zip', () => {
  gulp.src('dist/**')
    .pipe(zip('archive.zip'))
    .pipe(gulp.dest('.'));
});

gulp.task('build:debug', ['clean'], () => {
  buildJs(true);
  buildCss();
  buildHtml();
  buildManifest();
  buildImg();
  buildMisc();
});

gulp.task('clean', () =>
  del([
    'dist/**',
  ])
);

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

gulp.task('watch:debug', () => {
  gulp.watch('src/js/*.js', ['js:debug']);
  gulp.watch('src/css/*.css', ['css']);
  gulp.watch('src/html/*.html', ['html']);
  gulp.watch('src/img/*', ['img']);
  gulp.watch('src/manifest.json', ['manifest']);
});

gulp.task('default', ['build']);
<commit_msg>Remove archive when running gulp clean<commit_after>const babelify = require('babelify');
const browserify = require('browserify');
const buffer = require('vinyl-buffer');
const cssnano = require('gulp-cssnano');
const del = require('del');
const gulp = require('gulp');
const gutil = require('gulp-util');
const htmlmin = require('gulp-htmlmin');
const jsonMinify = require('gulp-json-minify');
const source = require('vinyl-source-stream');
const uglify = require('gulp-uglify');
const zip = require('gulp-zip');

function processJsFile(fileName, debug) {
  // https://github.com/gulpjs/gulp/blob/master/docs/recipes/browserify-uglify-sourcemap.md

  let uglifyConfigs = {};

  // remove console.log if debug is false
  if (!debug) {
    uglifyConfigs = {
      compress: {
        pure_funcs: [
          'console.log',
          'console.error',
        ],
      },
    };
  }

  const b = browserify({
    entries: `src/js/${fileName}.js`,
  }).transform(babelify.configure({
    presets: ['es2015'],
  })).bundle()
    .on('error', gutil.log)
    .pipe(source(`${fileName}.js`))
    .pipe(buffer());
  if (!debug) {
    b.pipe(uglify(uglifyConfigs));
  }
  b.pipe(gulp.dest('dist/js'));
}

function buildJs(debug) {
  processJsFile('eventPage', debug);
  processJsFile('options', debug);
  processJsFile('popup', debug);
  processJsFile('content-google', debug);
  processJsFile('content-duckduckgo', debug);
}

function buildCss() {
  gulp.src('src/css/*.css')
    .pipe(cssnano())
    .on('error', gutil.log)
    .pipe(gulp.dest('dist/css'));
}

function buildHtml() {
  gulp.src('src/html/*.html')
    .pipe(htmlmin({
      collapseWhitespace: true,
      removeComments: true,
    }))
    .on('error', gutil.log)
    .pipe(gulp.dest('dist/html'));
}

function buildManifest() {
  gulp.src([
    'src/manifest.json',
  ]).pipe(jsonMinify())
    .pipe(gulp.dest('dist'));
}

function buildImg() {
  gulp.src([
    'src/img/*',
  ]).pipe(gulp.dest('dist/img'));
}

function buildMisc() {
  gulp.src([
    'node_modules/jquery/dist/jquery.min.js',
  ]).pipe(gulp.dest('src/js/lib'))
    .pipe(gulp.dest('dist/js/lib'));

  gulp.src([
    'src/js/lib/jquery.tooltipster.min.js',
  ]).pipe(gulp.dest('dist/js/lib'));

  gulp.src([
    'src/css/lib/tooltipster.css',
  ]).pipe(cssnano())
    .pipe(gulp.dest('dist/css/lib'));
}

gulp.task('js', () => {
  buildJs(false);
});

gulp.task('js:debug', () => {
  buildJs(true);
});

gulp.task('css', () => {
  buildCss();
});

gulp.task('html', () => {
  buildHtml();
});

gulp.task('manifest', () => {
  buildManifest();
});

gulp.task('img', () => {
  buildImg();
});

gulp.task('misc', () => {
  buildMisc();
});

gulp.task('build', ['clean'], () => {
  buildJs(false);
  buildCss();
  buildHtml();
  buildManifest();
  buildImg();
  buildMisc();
});

gulp.task('zip', () => {
  gulp.src('dist/**')
    .pipe(zip('archive.zip'))
    .pipe(gulp.dest('.'));
});

gulp.task('build:debug', ['clean'], () => {
  buildJs(true);
  buildCss();
  buildHtml();
  buildManifest();
  buildImg();
  buildMisc();
});

gulp.task('clean', () => {
  del([
    'dist/**',
  ]);
  del([
    'archive/**',
  ]);
  del([
    'archive.zip',
  ]);
});

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

gulp.task('watch:debug', () => {
  gulp.watch('src/js/*.js', ['js:debug']);
  gulp.watch('src/css/*.css', ['css']);
  gulp.watch('src/html/*.html', ['html']);
  gulp.watch('src/img/*', ['img']);
  gulp.watch('src/manifest.json', ['manifest']);
});

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


<commit_before>// ==[ Dependencies ]======================================
var gulp = require('gulp'),
    _ = require('underscore'),
    less = require('gulp-less'),
    path = require('path'),
    template = require('gulp-template'),
    jshint = require('gulp-jshint'),
    uglify = require('gulp-uglify'),
    imagemin = require('gulp-imagemin'),
    rename = require('gulp-rename'),
    concat = require('gulp-concat'),
    notify = require('gulp-notify'),
    cache = require('gulp-cache'),
    sourcemaps = require('gulp-sourcemaps'),
    vulcanize = require('gulp-vulcanize'),
    webserver = require('gulp-webserver'),
    config = require('./app/config.json'),
    pkg = require('./package.json'),
    yargs = require('yargs'),
    gutil = require('gulp-util'),
    plumber = require('gulp-plumber'),
    del = require('del');
// ========================================================

// ==[ Error Handling ]====================================
// `gulp --fatal=error` determines what kind of errors should be fatal
// - see for more info: http://www.artandlogic.com/blog/2014/05/error-handling-in-gulp/
// - more examples: http://truongtx.me/2014/07/15/handle-errors-while-using-gulp-watch/

var fatalLevel = yargs.argv.fatal,
    ERROR_LEVELS = ['error', 'warning'];

function isFatal(level) {
  return ERROR_LEVELS.indexOf(level) <= ERROR_LEVELS.indexOf(fatalLevel || 'error');
}

function handleError(level, error) {
  notify.onError({
    title: "Gulp",
    subtitle: level + "!",
    message: "Error: <%= error.message %>",
    sound: "Sosumi"
  })(error);

  gutil.log(error.message);
  gutil.log(error.stack);

  if (isFatal(level)) {
    process.exit(1);
  }

  this.emit('end');
}

function onError(error) {
  handleError.call(this, 'error', error);
}
function onWarning(error) {
  handleError.call(this, 'warning', error);
}

// ========================================================

//TODO: fix path problems in components/build.html (wtf google-code-prettify, marked.js, context-free-parser.js)
//TODO: stream jshint task into js task
//TODO: common piped task for multi-env configuration?
//TODO: generate for multiple environments simultaneously?
//TODO: FIX LiveReload
//TODO: setup basic angular app
//TODO: task for angular templates [gulp-html2tpl](https://www.npmjs.org/package/gulp-html2tpl)
//TODO: alternate lib for angular templates [gulp-jst-concat](https://www.npmjs.org/package/gulp-jst-concat)
//TODO: errors task
//TODO: polymer js/platform.js
//TODO: google analytics config
//TODO: gulp rss?
//TODO: sitemap?
//TODO: asset fingerprinting?
//TODO: jshintrc - look at https://gist.github.com/connor/1597131
//TODO: add 404.html and other templates

//gulp-notify defaults for completed tasks
//  official config examples: https://github.com/mikaelbr/gulp-notify/blob/master/examples/gulpfile.js
var notifyConf = {
  title: "Gulp",
  subtitle: "Finished",
  sound: "Tink" // refer to OSX Sound Preferences
}

//merge env config into common config
var node_env = process.env.NODE_ENV || 'development',
    conf = _.extend(
        _.pick(pkg, 'title', 'description'),
        config['common'],
        config[node_env]);

gulp.task('html', function () {
  return gulp.src('app/pages/**/*.html')
      .pipe(plumber({errorHandler: onError}))
      .pipe(template(conf))
      .pipe(gulp.dest('dist'))
      .pipe(notify(_.extend(notifyConf,{message: 'HTML task complete'})));
});

//TODO: update jshint & js tasks so that one streams into the other, for efficiency
gulp.task('jshint', function () {
  return gulp.src('app/js/**/*.js')
      .pipe(plumber({errorHandler: onWarning}))
      .pipe(template(conf))
      .pipe(jshint('.jshintrc'))
      .pipe(jshint.reporter('default'))
      .pipe(notify(_.extend(notifyConf,{message: 'JSHint task complete'})));
});

gulp.task('js', function () {
  return gulp.src('app/js/**/*.js')
      .pipe(plumber({errorHandler: onError}))
      .pipe(sourcemaps.init())
      .pipe(template(conf))
      .pipe(concat('app.js'))
      .pipe(gulp.dest('dist/js'))
      .pipe(rename({suffix: '.min'}))
      .pipe(uglify())
      .pipe(sourcemaps.write())
      .pipe(gulp.dest('dist/js'))
      .pipe(notify(_.extend(notifyConf,{message: 'JS task complete'})));
});

gulp.task('less', function () {
  return gulp.src('./app/css/**/*.less')
      .pipe(plumber({errorHandler: onError}))
      .pipe(sourcemaps.init())
      .pipe(less({
        paths: [path.join(__dirname, 'less', 'includes')]
      }))
      .pipe(sourcemaps.write())
      .pipe(gulp.dest('./dist/css'))
      .pipe(notify(_.extend(notifyConf,{message: 'LESS task complete'})));
});

gulp.task('img', function () {
  return gulp.src('app/img/**/*')
      .pipe(plumber({errorHandler: onError}))
      .pipe(imagemin({optimizationLevel: 3, progressive: true, interlaced: true}))
      .pipe(gulp.dest('dist/img'))
      .pipe(notify(_.extend(notifyConf,{message: 'Img task complete'})));
});

gulp.task('vulcanize', function () {
  return gulp.src('app/components/build.html')
      .pipe(plumber({errorHandler: onError}))
      .pipe(vulcanize({
        // refer here for options: https://github.com/Polymer/grunt-vulcanize#options
        dest: 'dist/components',
        inline: true,
        csp: true
      }))
      .pipe(gulp.dest('dist/components'))
      .pipe(notify(_.extend(notifyConf,{message: 'Vulcanize task complete'})));
});

gulp.task('clean', function (cb) {
  del(['dist/css', 'dist/js', 'dist/img', 'dist/components', 'dist/index.html'], cb)
});

gulp.task('default', ['clean'], function () {
  gulp.start('html', 'less', 'jshint', 'js', 'img', 'vulcanize');
});

gulp.task('watch', function () {
  fatalLevel = fatalLevel || 'off';
  gulp.watch('app/config.json', ['js', 'html']);
  gulp.watch('app/css/**/*.less', ['less']);
  gulp.watch('app/js/**/*.js', ['jshint', 'js']);
  gulp.watch('app/img/**/*', ['img']);
  gulp.watch('app/pages/**/*.html', ['html']);
  gulp.watch('app/components/build.html', ['vulcanize']);
});

gulp.task('webserver', function () {
  gulp.src('dist')
      .pipe(webserver({
        livereload: {
          filter: 'dist'
        },
        directoryListing: {
          enable: true,
          path: 'dist'
        },
        open: true
      }));
});<commit_msg>* fixes livereload problems<commit_after>// ==[ Dependencies ]======================================
var gulp = require('gulp'),
    _ = require('underscore'),
    less = require('gulp-less'),
    path = require('path'),
    template = require('gulp-template'),
    jshint = require('gulp-jshint'),
    uglify = require('gulp-uglify'),
    imagemin = require('gulp-imagemin'),
    rename = require('gulp-rename'),
    concat = require('gulp-concat'),
    notify = require('gulp-notify'),
    cache = require('gulp-cache'),
    sourcemaps = require('gulp-sourcemaps'),
    vulcanize = require('gulp-vulcanize'),
    webserver = require('gulp-webserver'),
    config = require('./app/config.json'),
    pkg = require('./package.json'),
    yargs = require('yargs'),
    gutil = require('gulp-util'),
    plumber = require('gulp-plumber'),
    del = require('del');
// ========================================================

// ==[ Error Handling ]====================================
// `gulp --fatal=error` determines what kind of errors should be fatal
// - see for more info: http://www.artandlogic.com/blog/2014/05/error-handling-in-gulp/
// - more examples: http://truongtx.me/2014/07/15/handle-errors-while-using-gulp-watch/

var fatalLevel = yargs.argv.fatal,
    ERROR_LEVELS = ['error', 'warning'];

function isFatal(level) {
  return ERROR_LEVELS.indexOf(level) <= ERROR_LEVELS.indexOf(fatalLevel || 'error');
}

function handleError(level, error) {
  notify.onError({
    title: "Gulp",
    subtitle: level + "!",
    message: "Error: <%= error.message %>",
    sound: "Sosumi"
  })(error);

  gutil.log(error.message);
  gutil.log(error.stack);

  if (isFatal(level)) {
    process.exit(1);
  }

  this.emit('end');
}

function onError(error) {
  handleError.call(this, 'error', error);
}
function onWarning(error) {
  handleError.call(this, 'warning', error);
}

// ========================================================

//TODO: fix path problems in components/build.html (wtf google-code-prettify, marked.js, context-free-parser.js)
//TODO: stream jshint task into js task
//TODO: common piped task for multi-env configuration?
//TODO: generate for multiple environments simultaneously?
//TODO: FIX LiveReload
//TODO: setup basic angular app
//TODO: task for angular templates [gulp-html2tpl](https://www.npmjs.org/package/gulp-html2tpl)
//TODO: alternate lib for angular templates [gulp-jst-concat](https://www.npmjs.org/package/gulp-jst-concat)
//TODO: errors task
//TODO: polymer js/platform.js
//TODO: google analytics config
//TODO: gulp rss?
//TODO: sitemap?
//TODO: asset fingerprinting?
//TODO: jshintrc - look at https://gist.github.com/connor/1597131
//TODO: add 404.html and other templates

//gulp-notify defaults for completed tasks
//  official config examples: https://github.com/mikaelbr/gulp-notify/blob/master/examples/gulpfile.js
var notifyConf = {
  title: "Gulp",
  subtitle: "Finished",
  sound: "Tink" // refer to OSX Sound Preferences
}

//merge env config into common config
var node_env = process.env.NODE_ENV || 'development',
    conf = _.extend(
        _.pick(pkg, 'title', 'description'),
        config['common'],
        config[node_env]);

gulp.task('html', function () {
  return gulp.src('app/pages/**/*.html')
      .pipe(plumber({errorHandler: onError}))
      .pipe(template(conf))
      .pipe(gulp.dest('dist'))
      .pipe(notify(_.extend(notifyConf,{message: 'HTML task complete'})));
});

//TODO: update jshint & js tasks so that one streams into the other, for efficiency
gulp.task('jshint', function () {
  return gulp.src('app/js/**/*.js')
      .pipe(plumber({errorHandler: onWarning}))
      .pipe(template(conf))
      .pipe(jshint('.jshintrc'))
      .pipe(jshint.reporter('default'))
      .pipe(notify(_.extend(notifyConf,{message: 'JSHint task complete'})));
});

gulp.task('js', function () {
  return gulp.src('app/js/**/*.js')
      .pipe(plumber({errorHandler: onError}))
      .pipe(sourcemaps.init())
      .pipe(template(conf))
      .pipe(concat('app.js'))
      .pipe(gulp.dest('dist/js'))
      .pipe(rename({suffix: '.min'}))
      .pipe(uglify())
      .pipe(sourcemaps.write())
      .pipe(gulp.dest('dist/js'))
      .pipe(notify(_.extend(notifyConf,{message: 'JS task complete'})));
});

gulp.task('less', function () {
  return gulp.src('./app/css/**/*.less')
      .pipe(plumber({errorHandler: onError}))
      .pipe(sourcemaps.init())
      .pipe(less({
        paths: [path.join(__dirname, 'less', 'includes')]
      }))
      .pipe(sourcemaps.write())
      .pipe(gulp.dest('./dist/css'))
      .pipe(notify(_.extend(notifyConf,{message: 'LESS task complete'})));
});

gulp.task('img', function () {
  return gulp.src('app/img/**/*')
      .pipe(plumber({errorHandler: onError}))
      .pipe(imagemin({optimizationLevel: 3, progressive: true, interlaced: true}))
      .pipe(gulp.dest('dist/img'))
      .pipe(notify(_.extend(notifyConf,{message: 'Img task complete'})));
});

gulp.task('vulcanize', function () {
  return gulp.src('app/components/build.html')
      .pipe(plumber({errorHandler: onError}))
      .pipe(vulcanize({
        // refer here for options: https://github.com/Polymer/grunt-vulcanize#options
        dest: 'dist/components',
        inline: true,
        csp: true
      }))
      .pipe(gulp.dest('dist/components'))
      .pipe(notify(_.extend(notifyConf,{message: 'Vulcanize task complete'})));
});

gulp.task('clean', function (cb) {
  del(['dist/css', 'dist/js', 'dist/img', 'dist/components', 'dist/index.html'], cb)
});

gulp.task('default', ['clean'], function () {
  gulp.start('html', 'less', 'jshint', 'js', 'img', 'vulcanize');
});

gulp.task('watch', function () {
  fatalLevel = fatalLevel || 'off';
  gulp.watch('app/config.json', ['js', 'html']);
  gulp.watch('app/css/**/*.less', ['less']);
  gulp.watch('app/js/**/*.js', ['jshint', 'js']);
  gulp.watch('app/img/**/*', ['img']);
  gulp.watch('app/pages/**/*.html', ['html']);
  gulp.watch('app/components/build.html', ['vulcanize']);
});

gulp.task('webserver', function () {
  gulp.src('dist')
      .pipe(webserver({
        livereload: true,
        directoryListing: {
          enable: true,
          path: 'dist'
        },
        port: 8000,
        //https: true,
        open: true
      }));
});<|endoftext|>


<commit_before>"use strict";
var fs = require('fs');
var assert = require('assert');
var helper = require("../helper.js");
var coreMail = helper.requireModule('./modules/soajs.core/mail/index');
var soajsMail = helper.requireModule('./index.js').mail;

var recipient = "mike.hajj@gmail.com"; //valid email address

describe("testing mail functionality", function() {

	describe("testing core mail", function() {
		var mailer;

		it("fail - invalid declaration", function(done) {
			try {
				mailer = new coreMail({});
			} catch(e) {
				assert.ok(e);
				assert.equal(e.message, "transport error: 'type' is required - 'options' is required");
			}
			done();
		});

		it("success - should initialize mail default", function(done) {
			mailer = new coreMail();
			assert.ok(mailer);
			done();
		});

		it("success - should initialize mail direct", function(done) {
			mailer = new coreMail({'type': 'direct', 'options': {}});
			assert.ok(mailer);
			done();
		});

		it("success - should initialize mail smtp", function(done) {
			mailer = new coreMail({
				'type': 'smtp',
				'options': {
					'host': 'localhost', //mandatory param if type is smtp
					'port': '25',        //mandatory param if type is smtp
					ignoreTLS: true,     //mandatory param if type is smtp
					secure: false,       //mandatory param if type is smtp
					'auth': {            //mandatory param if type is smtp
						'user': 'username',
						'pass': 'password'
					}
				}
			});
			assert.ok(mailer);
			done();
		});

		it("success - should initialize mail sendmail", function(done) {
			mailer = new coreMail({
				'type': 'sendmail',
				'options': {
				}
			});
			assert.ok(mailer);
			done();
		});

		it("fail - should not send mail, missing arguments", function(done) {
			var mailOptions = {
				'from': 'me@myself.com',
				'to': 'me@myself.com'
			};
			mailer.send(mailOptions, function(error, info) {
				assert.ok(error);
				assert.ok(!info);
				assert.equal(error.message, "mailOptions error: 'subject' is required - 'text' is required");
				done();
			});
		});

		it("fail - should not send mail", function(done) {

			mailer.send({'mailOptions': {}}, function(error, info) {
				assert.ok(error);
				assert.ok(!info);
				assert.equal(error.message, "mailOptions error: 'from' is required - 'to' is required - 'subject' is required - 'text' is required");
				done();
			});
		});

		it("success - should send mail", function(done) {

			var mailOptions = {
				'from': 'me@localhost.com',
				'to': recipient,
				'subject': 'Register Notification',
				'html': "
Dear {{ username }},

Regards,
SOAJS Team.
",
				'text': "Dear {{ username }},\n\rRegards,\nSOAJS Team."
			};
			mailer.send(mailOptions, function(error, info) {
				assert.ifError(error);
				assert.ok(info);
				console.log(info);
				done();
			});
		});
	});

	describe("testing soajs.mail library", function() {
		var soajsMailer;
		it("initialise soajsMail", function(done) {
			soajsMailer = new soajsMail({
				'type': 'sendmail',
				'options': {
					'path': '/usr/sbin/sendmail'
				}
			});
			assert.ok(soajsMailer);
			done();
		});

		it("fail - should not send mail missing fields", function(done) {

			var mailOptions = {
				'from': 'me@localhost.com',
				'to': recipient
			};

			soajsMailer.send(mailOptions, function(error, info) {
				assert.ok(error);
				assert.ok(!info);
				assert.equal(error.message, "soajs.mail error: 'subject' is required");
				done();
			});
		});

		it("success - should send mail with html no template", function(done) {

			var mailOptions = {
				'from': 'me@localhost.com',
				'to': recipient,
				'subject': 'Hello World',
				'html': '
foo!!
',
				'text': 'foo!!'
			};

			soajsMailer.send(mailOptions, function(error, info) {
				assert.ifError(error);
				assert.ok(info);
				console.log(info);
				done();
			});
		});

		it("success - should send mail with template as string", function(done) {

			var mailOptions = {
				'from': 'me@localhost.com',
				'to': recipient,
				'subject': 'Register Notification',
				'content': "
Dear {{ username }},

Regards,
SOAJS Team.
",
				'data': {
					'username': 'johndoe'
				}
			};
			soajsMailer.renderTemplate(mailOptions);
			soajsMailer.send(mailOptions, function(error, info) {
				assert.ifError(error);
				assert.ok(info);
				console.log(info);
				done();
			});
		});

		it("success - should send mail with template from file", function(done) {
			fs.writeFileSync(__dirname + "/mytmpl.txt", "
Dear {{ username }},

Regards,
SOAJS Team.
");
			var mailOptions = {
				'from': 'me@localhost.com',
				'to': recipient,
				'subject': 'Register Notification',
				'path': __dirname + '/mytmpl.txt',
				'data': {
					'username': 'johndoe'
				}
			};
			soajsMailer.renderTemplate(mailOptions);
			soajsMailer.send(mailOptions, function(error, info) {
				assert.ifError(error);
				assert.ok(info);
				console.log(info);
				done();
			});
		});

		it("success - should send mail with more options", function(done) {
			fs.writeFileSync(__dirname + '/att2.txt', "Hello world.");

			var mailOptions = {
				'from': 'me@localhost.com',
				'to': recipient,
				'service': 'urac',
				'subject': 'Register Notification with attachments',
				'path': __dirname + '/mytmpl.txt',
				'data': {
					'username': 'johndoe'
				},
				attachments: [
					{
						"filename": "att1.txt",
						"content": "Hello world."
					},
					{
						"filename": "att2.txt",
						"path": __dirname + "/att2.txt"
					}
				]
			};

			soajsMailer.renderTemplate(mailOptions);
			soajsMailer.send(mailOptions, function(error, info) {
				assert.ifError(error);
				assert.ok(info);
				console.log(info);
				fs.unlinkSync(__dirname + "/att2.txt");
				fs.unlinkSync(__dirname + "/mytmpl.txt");
				done();
			});
		});

	});
});<commit_msg>fixed mail unit test configuration<commit_after>"use strict";
var fs = require('fs');
var assert = require('assert');
var helper = require("../helper.js");
var coreMail = helper.requireModule('./modules/soajs.core/mail/index');
var soajsMail = helper.requireModule('./index.js').mail;

var recipient = "mike.hajj@gmail.com"; //valid email address

describe("testing mail functionality", function() {

	describe("testing core mail", function() {
		var mailer;

		it("fail - invalid declaration", function(done) {
			try {
				mailer = new coreMail({});
			} catch(e) {
				assert.ok(e);
				assert.equal(e.message, "transport error: 'type' is required - 'options' is required");
			}
			done();
		});

		it("success - should initialize mail default", function(done) {
			mailer = new coreMail();
			assert.ok(mailer);
			done();
		});

		it("success - should initialize mail direct", function(done) {
			mailer = new coreMail({'type': 'direct', 'options': {}});
			assert.ok(mailer);
			done();
		});

		it("success - should initialize mail smtp", function(done) {
			mailer = new coreMail({
				'type': 'smtp',
				'options': {
					'host': 'localhost', //mandatory param if type is smtp
					'port': '25',        //mandatory param if type is smtp
					ignoreTLS: true,     //mandatory param if type is smtp
					secure: false,       //mandatory param if type is smtp
					'auth': {            //mandatory param if type is smtp
						'user': 'username',
						'pass': 'password'
					}
				}
			});
			assert.ok(mailer);
			done();
		});

		it("success - should initialize mail sendmail", function(done) {
			mailer = new coreMail({
				'type': 'sendmail',
				'options': {
				}
			});
			assert.ok(mailer);
			done();
		});

		it("fail - should not send mail, missing arguments", function(done) {
			var mailOptions = {
				'from': 'me@myself.com',
				'to': 'me@myself.com'
			};
			mailer.send(mailOptions, function(error, info) {
				assert.ok(error);
				assert.ok(!info);
				assert.equal(error.message, "mailOptions error: 'subject' is required - 'text' is required");
				done();
			});
		});

		it("fail - should not send mail", function(done) {

			mailer.send({'mailOptions': {}}, function(error, info) {
				assert.ok(error);
				assert.ok(!info);
				assert.equal(error.message, "mailOptions error: 'from' is required - 'to' is required - 'subject' is required - 'text' is required");
				done();
			});
		});

		it("success - should send mail", function(done) {

			var mailOptions = {
				'from': 'me@localhost.com',
				'to': recipient,
				'subject': 'Register Notification',
				'html': "
Dear {{ username }},

Regards,
SOAJS Team.
",
				'text': "Dear {{ username }},\n\rRegards,\nSOAJS Team."
			};
			mailer.send(mailOptions, function(error, info) {
				assert.ifError(error);
				assert.ok(info);
				console.log(info);
				done();
			});
		});
	});

	describe("testing soajs.mail library", function() {
		var soajsMailer;
		it("initialise soajsMail", function(done) {
			soajsMailer = new soajsMail({
				'type': 'sendmail',
				'options': {
				}
			});
			assert.ok(soajsMailer);
			done();
		});

		it("fail - should not send mail missing fields", function(done) {

			var mailOptions = {
				'from': 'me@localhost.com',
				'to': recipient
			};

			soajsMailer.send(mailOptions, function(error, info) {
				assert.ok(error);
				assert.ok(!info);
				assert.equal(error.message, "soajs.mail error: 'subject' is required");
				done();
			});
		});

		it("success - should send mail with html no template", function(done) {

			var mailOptions = {
				'from': 'me@localhost.com',
				'to': recipient,
				'subject': 'Hello World',
				'html': '
foo!!
',
				'text': 'foo!!'
			};

			soajsMailer.send(mailOptions, function(error, info) {
				assert.ifError(error);
				assert.ok(info);
				console.log(info);
				done();
			});
		});

		it("success - should send mail with template as string", function(done) {

			var mailOptions = {
				'from': 'me@localhost.com',
				'to': recipient,
				'subject': 'Register Notification',
				'content': "
Dear {{ username }},

Regards,
SOAJS Team.
",
				'data': {
					'username': 'johndoe'
				}
			};
			soajsMailer.renderTemplate(mailOptions);
			soajsMailer.send(mailOptions, function(error, info) {
				assert.ifError(error);
				assert.ok(info);
				console.log(info);
				done();
			});
		});

		it("success - should send mail with template from file", function(done) {
			fs.writeFileSync(__dirname + "/mytmpl.txt", "
Dear {{ username }},

Regards,
SOAJS Team.
");
			var mailOptions = {
				'from': 'me@localhost.com',
				'to': recipient,
				'subject': 'Register Notification',
				'path': __dirname + '/mytmpl.txt',
				'data': {
					'username': 'johndoe'
				}
			};
			soajsMailer.renderTemplate(mailOptions);
			soajsMailer.send(mailOptions, function(error, info) {
				assert.ifError(error);
				assert.ok(info);
				console.log(info);
				done();
			});
		});

		it("success - should send mail with more options", function(done) {
			fs.writeFileSync(__dirname + '/att2.txt', "Hello world.");

			var mailOptions = {
				'from': 'me@localhost.com',
				'to': recipient,
				'service': 'urac',
				'subject': 'Register Notification with attachments',
				'path': __dirname + '/mytmpl.txt',
				'data': {
					'username': 'johndoe'
				},
				attachments: [
					{
						"filename": "att1.txt",
						"content": "Hello world."
					},
					{
						"filename": "att2.txt",
						"path": __dirname + "/att2.txt"
					}
				]
			};

			soajsMailer.renderTemplate(mailOptions);
			soajsMailer.send(mailOptions, function(error, info) {
				assert.ifError(error);
				assert.ok(info);
				console.log(info);
				fs.unlinkSync(__dirname + "/att2.txt");
				fs.unlinkSync(__dirname + "/mytmpl.txt");
				done();
			});
		});

	});
});<|endoftext|>