<commit_before>/**
 * Created by nuintun on 2015/5/5.
 */

'use strict';

// 开启 DEBUG 开关
process.env.DEBUG = 'gulp-*';

// 关闭 DEBUG 开关
//process.env.DEBUG = 'false';

var path = require('path');
var join = path.join;
var relative = path.relative;
var dirname = path.dirname;
var extname = path.extname;
var resolve = path.resolve;
var gulp = require('gulp');
var rimraf = require('del');
var uglify = require('gulp-uglify');
var css = require('gulp-css');
var cmd = require('gulp-cmd');
var colors = cmd.colors;
var pedding = require('pedding');
var chokidar = require('chokidar');
var plumber = require('gulp-plumber');
var switchStream = require('switch-stream');

// alias
var alias = {
  'import-style': 'util/import-style/1.0.0/import-style',
  'jquery': 'base/jquery/1.11.3/jquery',
  'base': 'base/base/1.2.0/base',
  'class': 'base/class/1.2.0/class',
  'events': 'base/events/1.2.0/events',
  'widget': 'base/widget/1.2.0/widget',
  'template': 'base/template/3.0.3/template',
  'templatable': 'base/templatable/0.10.0/templatable',
  'iframe-shim': 'util/iframe-shim/1.1.0/iframe-shim',
  'position': 'util/position/1.1.0/position',
  'messenger': 'util/messenger/2.1.0/messenger',
  'overlay': 'common/overlay/1.2.0/',
  'dialog': 'common/dialog/1.5.1/dialog',
  'confirmbox': 'common/dialog/1.5.1/confirmbox'
};
// bookmark
var bookmark = Date.now();

// file watch
function watch(glob, options, callabck){
  if (typeof options === 'function') {
    callabck = options;
    options = {};
  }

  // get watcher
  var watcher = chokidar.watch(glob, options);

  if (callabck) {
    watcher.on('all', callabck);
  }

  return watcher;
}

// css resource path
function onpath(path, property, file, wwwroot){
  if (/^[^./\\]/.test(path)) {
    path = './' + path;
  }

  if (path.indexOf('.') === 0) {
    path = join(dirname(file), path);
    path = relative(wwwroot, path);
    path = '/' + path;
    path = path.replace(/\\+/g, '/');
  }

  path = path.replace('/static/develop/', '/static/product/');

  return path;
}

// date format
function dateFormat(date, format){
  // 参数错误
  if (!date instanceof Date) {
    throw new TypeError('Param date must be a Date');
  }

  format = format || 'yyyy-MM-dd hh:mm:ss';

  var map = {
    'M': date.getMonth() + 1, //月份
    'd': date.getDate(), //日
    'h': date.getHours(), //小时
    'm': date.getMinutes(), //分
    's': date.getSeconds(), //秒
    'q': Math.floor((date.getMonth() + 3) / 3), //季度
    'S': date.getMilliseconds() //毫秒
  };

  format = format.replace(/([yMdhmsqS])+/g, function (all, t){
    var v = map[t];

    if (v !== undefined) {
      if (all.length > 1) {
        v = '0' + v;
        v = v.substr(v.length - 2);
      }

      return v;
    } else if (t === 'y') {
      return (date.getFullYear() + '').substr(4 - all.length);
    }

    return all;
  });

  return format;
}

// clean task
gulp.task('clean', function (){
  bookmark = Date.now();

  rimraf.sync('static/product');
});

// runtime task
gulp.task('runtime', ['clean'], function (){
  // loader file
  gulp.src('static/develop/loader/**/*.js', { base: 'static/develop' })
    .pipe(uglify())
    .pipe(gulp.dest('static/product'));

  // image file
  gulp.src('static/develop/images/**/*', { base: 'static/develop' })
    .pipe(gulp.dest('static/product'));
});

// product task
gulp.task('product', ['runtime'], function (){
  // complete callback
  var complete = pedding(2, function (){
    var now = new Date();

    console.log(
      '  %s [%s] build complete... √ %s\x07',
      colors.green('gulp-product'),
      dateFormat(now),
      colors.green('+' + (now - bookmark) + 'ms')
    );
  });

  // compress javascript file
  function compress(){
    return switchStream(function (vinyl){
      if (extname(vinyl.path) === '.js') {
        return 'js';
      }
    }, {
      'js': uglify()
    });
  }

  // all js
  gulp.src('static/develop/js/**/*', { base: 'static/develop/js' })
    .pipe(cmd({
      alias: alias,
      ignore: ['jquery'],
      include: function (id){
        return id && id.indexOf('view') === 0 ? 'all' : 'self';
      },
      css: {
        compress: true,
        onpath: onpath
      }
    }))
    .pipe(compress())
    .pipe(gulp.dest('static/product/js'))
    .on('finish', complete);

  // css file
  gulp.src('static/develop/css/?(base|view)/**/*', { base: 'static/develop' })
    .pipe(css({
      compress: true,
      onpath: onpath
    }))
    .pipe(gulp.dest('static/product'))
    .on('finish', complete);
});

// develop task
gulp.task('default', ['runtime'], function (){
  // complete callback
  var complete = pedding(2, function (){
    var now = new Date();

    console.log(
      '  %s [%s] build complete... √ %s\x07',
      colors.green('gulp-default'),
      dateFormat(now),
      colors.green('+' + (now - bookmark) + 'ms')
    );
  });

  // js file
  gulp.src('static/develop/js/**/*', { base: 'static/develop/js' })
    .pipe(cmd({
      alias: alias,
      include: 'self',
      css: { onpath: onpath }
    }))
    .pipe(gulp.dest('static/product/js'))
    .on('finish', complete);

  // css file
  gulp.src('static/develop/css/**/*', { base: 'static/develop' })
    .pipe(css({ onpath: onpath }))
    .pipe(gulp.dest('static/product'))
    .on('finish', complete);
});

// develop watch task
gulp.task('watch', ['default'], function (){
  var base = join(process.cwd(), 'static/develop');

  // debug watcher
  function debugWatcher(event, path){
    var now = new Date();

    console.log(
      '  %s [%s] %s: %s %s',
      colors.green.bold('gulp-watch'),
      dateFormat(now),
      colors.cyan(event),
      colors.magenta(join('static/develop', path).replace(/\\/g, '/')),
      colors.green('+' + (now - bookmark) + 'ms')
    );
  }

  // complete callback
  function complete(){
    var now = new Date();

    console.log(
      '  %s [%s] build complete... √ %s\x07',
      colors.green('gulp-watch'),
      dateFormat(now),
      colors.green('+' + (now - bookmark) + 'ms')
    );
  }

  // watch js file
  watch('static/develop/js/**/*', function (event, path){
    var rpath = relative(base, path);

    bookmark = Date.now();
    event = event.toLowerCase();

    debugWatcher(event, rpath);

    if (event === 'unlink' || event === 'unlinkdir') {
      rimraf.sync(resolve('static/product', rpath));
      complete();
    } else {
      gulp.src(path, { base: 'static/develop/js' })
        .pipe(plumber())
        .pipe(cmd({
          alias: alias,
          include: 'self',
          cache: false,
          css: { onpath: onpath }
        }))
        .pipe(gulp.dest('static/product/js'))
        .on('finish', complete);
    }
  });

  // watch css file
  watch('static/develop/css/**/*', function (event, path){
    var rpath = relative(base, path);

    bookmark = Date.now();
    event = event.toLowerCase();

    debugWatcher(event, rpath);

    if (event === 'unlink' || event === 'unlinkdir') {
      rimraf.sync(resolve('static/product', relative(base, path)));
      complete();
    } else {
      gulp.src(path, { base: 'static/develop' })
        .pipe(plumber())
        .pipe(css({
          onpath: function (path){
            return path.replace('static/develop/', 'static/product/')
          }
        }))
        .pipe(gulp.dest('static/product'))
        .on('finish', complete);
    }
  });

  // watch image file
  watch('static/develop/images/**/*', function (event, path){
    var rpath = relative(base, path);

    bookmark = Date.now();
    event = event.toLowerCase();

    debugWatcher(event, rpath);

    if (event === 'unlink' || event === 'unlinkdir') {
      rimraf.sync(resolve('static/product', relative(base, path)));
      complete();
    } else {
      gulp.src(path, { base: 'static/develop' })
        .pipe(gulp.dest('static/product'))
        .on('finish', complete);
    }
  });
});
<commit_msg>update file<commit_after>/**
 * Created by nuintun on 2015/5/5.
 */

'use strict';

// 开启 DEBUG 开关
process.env.DEBUG = 'gulp-*';

// 关闭 DEBUG 开关
//process.env.DEBUG = 'false';

var path = require('path');
var join = path.join;
var relative = path.relative;
var dirname = path.dirname;
var extname = path.extname;
var resolve = path.resolve;
var gulp = require('gulp');
var rimraf = require('del');
var uglify = require('gulp-uglify');
var css = require('gulp-css');
var cmd = require('gulp-cmd');
var colors = cmd.colors;
var pedding = require('pedding');
var chokidar = require('chokidar');
var plumber = require('gulp-plumber');
var switchStream = require('switch-stream');

// alias
var alias = {
  'import-style': 'util/import-style/1.0.0/import-style',
  'jquery': 'base/jquery/1.11.3/jquery',
  'base': 'base/base/1.2.0/base',
  'class': 'base/class/1.2.0/class',
  'events': 'base/events/1.2.0/events',
  'widget': 'base/widget/1.2.0/widget',
  'template': 'base/template/3.0.3/template',
  'templatable': 'base/templatable/0.10.0/templatable',
  'iframe-shim': 'util/iframe-shim/1.1.0/iframe-shim',
  'position': 'util/position/1.1.0/position',
  'messenger': 'util/messenger/2.1.0/messenger',
  'overlay': 'common/overlay/1.2.0/',
  'dialog': 'common/dialog/1.5.1/dialog',
  'confirmbox': 'common/dialog/1.5.1/confirmbox'
};
// bookmark
var bookmark = Date.now();

// file watch
function watch(glob, options, callabck){
  if (typeof options === 'function') {
    callabck = options;
    options = {};
  }

  // ignore initial add event
  options.ignoreInitial = true;

  // get watcher
  var watcher = chokidar.watch(glob, options);

  if (callabck) {
    watcher.on('all', callabck);
  }

  return watcher;
}

// css resource path
function onpath(path, property, file, wwwroot){
  if (/^[^./\\]/.test(path)) {
    path = './' + path;
  }

  if (path.indexOf('.') === 0) {
    path = join(dirname(file), path);
    path = relative(wwwroot, path);
    path = '/' + path;
    path = path.replace(/\\+/g, '/');
  }

  path = path.replace('/static/develop/', '/static/product/');

  return path;
}

// date format
function dateFormat(date, format){
  // 参数错误
  if (!date instanceof Date) {
    throw new TypeError('Param date must be a Date');
  }

  format = format || 'yyyy-MM-dd hh:mm:ss';

  var map = {
    'M': date.getMonth() + 1, //月份
    'd': date.getDate(), //日
    'h': date.getHours(), //小时
    'm': date.getMinutes(), //分
    's': date.getSeconds(), //秒
    'q': Math.floor((date.getMonth() + 3) / 3), //季度
    'S': date.getMilliseconds() //毫秒
  };

  format = format.replace(/([yMdhmsqS])+/g, function (all, t){
    var v = map[t];

    if (v !== undefined) {
      if (all.length > 1) {
        v = '0' + v;
        v = v.substr(v.length - 2);
      }

      return v;
    } else if (t === 'y') {
      return (date.getFullYear() + '').substr(4 - all.length);
    }

    return all;
  });

  return format;
}

// clean task
gulp.task('clean', function (){
  bookmark = Date.now();

  rimraf.sync('static/product');
});

// runtime task
gulp.task('runtime', ['clean'], function (){
  // loader file
  gulp.src('static/develop/loader/**/*.js', { base: 'static/develop' })
    .pipe(uglify())
    .pipe(gulp.dest('static/product'));

  // image file
  gulp.src('static/develop/images/**/*', { base: 'static/develop' })
    .pipe(gulp.dest('static/product'));
});

// product task
gulp.task('product', ['runtime'], function (){
  // complete callback
  var complete = pedding(2, function (){
    var now = new Date();

    console.log(
      '  %s [%s] build complete... √ %s\x07',
      colors.green('gulp-product'),
      dateFormat(now),
      colors.green('+' + (now - bookmark) + 'ms')
    );
  });

  // compress javascript file
  function compress(){
    return switchStream(function (vinyl){
      if (extname(vinyl.path) === '.js') {
        return 'js';
      }
    }, {
      'js': uglify()
    });
  }

  // all js
  gulp.src('static/develop/js/**/*', { base: 'static/develop/js' })
    .pipe(cmd({
      alias: alias,
      ignore: ['jquery'],
      include: function (id){
        return id && id.indexOf('view') === 0 ? 'all' : 'self';
      },
      css: {
        compress: true,
        onpath: onpath
      }
    }))
    .pipe(compress())
    .pipe(gulp.dest('static/product/js'))
    .on('finish', complete);

  // css file
  gulp.src('static/develop/css/?(base|view)/**/*', { base: 'static/develop' })
    .pipe(css({
      compress: true,
      onpath: onpath
    }))
    .pipe(gulp.dest('static/product'))
    .on('finish', complete);
});

// develop task
gulp.task('default', ['runtime'], function (){
  // complete callback
  var complete = pedding(2, function (){
    var now = new Date();

    console.log(
      '  %s [%s] build complete... √ %s\x07',
      colors.green('gulp-default'),
      dateFormat(now),
      colors.green('+' + (now - bookmark) + 'ms')
    );
  });

  // js file
  gulp.src('static/develop/js/**/*', { base: 'static/develop/js' })
    .pipe(cmd({
      alias: alias,
      include: 'self',
      css: { onpath: onpath }
    }))
    .pipe(gulp.dest('static/product/js'))
    .on('finish', complete);

  // css file
  gulp.src('static/develop/css/**/*', { base: 'static/develop' })
    .pipe(css({ onpath: onpath }))
    .pipe(gulp.dest('static/product'))
    .on('finish', complete);
});

// develop watch task
gulp.task('watch', ['default'], function (){
  var base = join(process.cwd(), 'static/develop');

  // debug watcher
  function debugWatcher(event, path){
    var now = new Date();

    console.log(
      '  %s [%s] %s: %s %s',
      colors.green.bold('gulp-watch'),
      dateFormat(now),
      colors.cyan(event),
      colors.magenta(join('static/develop', path).replace(/\\/g, '/')),
      colors.green('+' + (now - bookmark) + 'ms')
    );
  }

  // complete callback
  function complete(){
    var now = new Date();

    console.log(
      '  %s [%s] build complete... √ %s\x07',
      colors.green('gulp-watch'),
      dateFormat(now),
      colors.green('+' + (now - bookmark) + 'ms')
    );
  }

  // watch js file
  watch('static/develop/js/**/*', function (event, path){
    var rpath = relative(base, path);

    bookmark = Date.now();
    event = event.toLowerCase();

    debugWatcher(event, rpath);

    if (event === 'unlink' || event === 'unlinkdir') {
      rimraf.sync(resolve('static/product', rpath));
      complete();
    } else {
      gulp.src(path, { base: 'static/develop/js' })
        .pipe(plumber())
        .pipe(cmd({
          alias: alias,
          include: 'self',
          cache: false,
          css: { onpath: onpath }
        }))
        .pipe(gulp.dest('static/product/js'))
        .on('finish', complete);
    }
  });

  // watch css file
  watch('static/develop/css/**/*', function (event, path){
    var rpath = relative(base, path);

    bookmark = Date.now();
    event = event.toLowerCase();

    debugWatcher(event, rpath);

    if (event === 'unlink' || event === 'unlinkdir') {
      rimraf.sync(resolve('static/product', relative(base, path)));
      complete();
    } else {
      gulp.src(path, { base: 'static/develop' })
        .pipe(plumber())
        .pipe(css({
          onpath: function (path){
            return path.replace('static/develop/', 'static/product/')
          }
        }))
        .pipe(gulp.dest('static/product'))
        .on('finish', complete);
    }
  });

  // watch image file
  watch('static/develop/images/**/*', function (event, path){
    var rpath = relative(base, path);

    bookmark = Date.now();
    event = event.toLowerCase();

    debugWatcher(event, rpath);

    if (event === 'unlink' || event === 'unlinkdir') {
      rimraf.sync(resolve('static/product', relative(base, path)));
      complete();
    } else {
      gulp.src(path, { base: 'static/develop' })
        .pipe(gulp.dest('static/product'))
        .on('finish', complete);
    }
  });
});
<|endoftext|>


<commit_before>var autoprefixer = require('autoprefixer');
var Core = require('css-modules-loader-core');
require('es6-promise');
var fs = require('fs');
var genericNames = require('generic-names');
var gulp = require('gulp');
var concat = require('gulp-concat');
var postcss = require('gulp-postcss');
var sourcemaps = require('gulp-sourcemaps');
var template = require('gulp-template');
var _ = require('lodash');
var _postcss = require('postcss');
var Parser = require('postcss-modules-parser');

var core = new Core([
  Core.values,
  Core.localByDefault,
  Core.extractImports,
  Core.scope({
    generateScopedName: genericNames("[name]__[local]"),
  }),
  autoprefixer,
]);

var templateData = {
  require: require,
};

require.extensions['.css'] = function(module, path) {
  var instance = _postcss(core.plugins.concat(new Parser));
  var css = fs.readFileSync(path, 'utf8');
  var tokens = instance.process(css, { from: path }).root.tokens;
  return module._compile("module.exports = " + JSON.stringify(tokens), path);
};

require.extensions['.html'] = function(module, path) {
  var templateHTML = fs.readFileSync(path, 'utf8');
  var html = _.template(templateHTML)(templateData);
  return module._compile("module.exports = " + JSON.stringify(html), path);
};

gulp.task('styles', ['templates'], function() {
  return gulp.src("./styles/*.css")
    .pipe(sourcemaps.init())
    .pipe(postcss(core.plugins))
    .pipe(concat("./styles.css"))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest("./build"));
});

gulp.task('templates', function() {
  Object.keys(require.cache).map(function(path) {
    if (/\.(css|html)$/.test(path)) delete require.cache[path];
  });
  return gulp.src("./*.html")
    .pipe(template(templateData))
    .pipe(gulp.dest("./build"));
});

gulp.task('build', ['styles', 'templates']);

gulp.task('watch', ['build'], function() {
  gulp.watch("./styles/*.css", ['styles']);
  gulp.watch(["./*.html", "./includes/*.html"], ['templates']);
});

gulp.task('default', ['build']);
<commit_msg>Remove the ./ prefix from the paths<commit_after>var autoprefixer = require('autoprefixer');
var Core = require('css-modules-loader-core');
require('es6-promise');
var fs = require('fs');
var genericNames = require('generic-names');
var gulp = require('gulp');
var concat = require('gulp-concat');
var postcss = require('gulp-postcss');
var sourcemaps = require('gulp-sourcemaps');
var template = require('gulp-template');
var _ = require('lodash');
var _postcss = require('postcss');
var Parser = require('postcss-modules-parser');

var core = new Core([
  Core.values,
  Core.localByDefault,
  Core.extractImports,
  Core.scope({
    generateScopedName: genericNames("[name]__[local]"),
  }),
  autoprefixer,
]);

var templateData = {
  require: require,
};

require.extensions['.css'] = function(module, path) {
  var instance = _postcss(core.plugins.concat(new Parser));
  var css = fs.readFileSync(path, 'utf8');
  var tokens = instance.process(css, { from: path }).root.tokens;
  return module._compile("module.exports = " + JSON.stringify(tokens), path);
};

require.extensions['.html'] = function(module, path) {
  var templateHTML = fs.readFileSync(path, 'utf8');
  var html = _.template(templateHTML)(templateData);
  return module._compile("module.exports = " + JSON.stringify(html), path);
};

gulp.task('styles', ['templates'], function() {
  return gulp.src("styles/*.css")
    .pipe(sourcemaps.init())
    .pipe(postcss(core.plugins))
    .pipe(concat("styles.css"))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest("build"));
});

gulp.task('templates', function() {
  Object.keys(require.cache).map(function(path) {
    if (/\.(css|html)$/.test(path)) delete require.cache[path];
  });
  return gulp.src("*.html")
    .pipe(template(templateData))
    .pipe(gulp.dest("build"));
});

gulp.task('build', ['styles', 'templates']);

gulp.task('watch', ['build'], function() {
  gulp.watch("styles/*.css", ['styles']);
  gulp.watch(["*.html", "includes/*.html"], ['templates']);
});

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


<commit_before>/**
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
var browserify = require('browserify');
var gulp = require('gulp');
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var buffer = require('vinyl-buffer');
var source = require('vinyl-source-stream');

var SRC_FILE = 'stackdriver-errors.js';
var TYPINGS_FILE = 'stackdriver-errors.d.ts';
var DEST = 'dist/';

var polyfills = [
  'core-js/features/array/filter',
  'core-js/features/array/for-each',
  'core-js/features/array/map',
  'core-js/features/function/bind',
  'core-js/features/promise',
];

gulp.task('lib-concat', function() {
  return browserify({
    debug: true,
    entries: SRC_FILE,
    standalone: 'StackdriverErrorReporter',
  })
    .require(polyfills)
    .plugin('browser-pack-flat/plugin')
    .bundle()
    .pipe(source(SRC_FILE))
    .pipe(rename({suffix: '-concat'}))
    .pipe(buffer())
    .pipe(sourcemaps.init({loadMaps: true}))
    // This will output the non-minified version
    .pipe(gulp.dest(DEST))
    // This will minify and rename to stackdriver-errors.min.js
    .pipe(uglify())
    .pipe(rename({extname: '.min.js'}))
    .pipe(sourcemaps.write('maps'))
    .pipe(gulp.dest(DEST))
    .pipe(gulp.src(TYPINGS_FILE))
    .pipe(gulp.dest(DEST));
});

gulp.task('demo-html', function() {
  return gulp.src('demo/demo.html')
    .pipe(replace(/..\/dist\//g, ''))
    .pipe(replace(/..\/demo\/demo\.js/g, 'demo.min.js'))
    .pipe(rename('index.html'))
    .pipe(gulp.dest('dist'));
});

gulp.task('demo-js', function() {
  return gulp.src('demo/demo.js')
    .pipe(sourcemaps.init())
    .pipe(uglify())
    .pipe(rename({extname: '.min.js'}))
    .pipe(sourcemaps.write('maps'))
    .pipe(gulp.dest('dist'));
});

<commit_msg>Lint fix (no-trailing-spaces) (#103)<commit_after>/**
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
var browserify = require('browserify');
var gulp = require('gulp');
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var buffer = require('vinyl-buffer');
var source = require('vinyl-source-stream');

var SRC_FILE = 'stackdriver-errors.js';
var TYPINGS_FILE = 'stackdriver-errors.d.ts';
var DEST = 'dist/';

var polyfills = [
  'core-js/features/array/filter',
  'core-js/features/array/for-each',
  'core-js/features/array/map',
  'core-js/features/function/bind',
  'core-js/features/promise',
];

gulp.task('lib-concat', function() {
  return browserify({
    debug: true,
    entries: SRC_FILE,
    standalone: 'StackdriverErrorReporter',
  })
    .require(polyfills)
    .plugin('browser-pack-flat/plugin')
    .bundle()
    .pipe(source(SRC_FILE))
    .pipe(rename({suffix: '-concat'}))
    .pipe(buffer())
    .pipe(sourcemaps.init({loadMaps: true}))
    // This will output the non-minified version
    .pipe(gulp.dest(DEST))
    // This will minify and rename to stackdriver-errors.min.js
    .pipe(uglify())
    .pipe(rename({extname: '.min.js'}))
    .pipe(sourcemaps.write('maps'))
    .pipe(gulp.dest(DEST))
    .pipe(gulp.src(TYPINGS_FILE))
    .pipe(gulp.dest(DEST));
});

gulp.task('demo-html', function() {
  return gulp.src('demo/demo.html')
    .pipe(replace(/..\/dist\//g, ''))
    .pipe(replace(/..\/demo\/demo\.js/g, 'demo.min.js'))
    .pipe(rename('index.html'))
    .pipe(gulp.dest('dist'));
});

gulp.task('demo-js', function() {
  return gulp.src('demo/demo.js')
    .pipe(sourcemaps.init())
    .pipe(uglify())
    .pipe(rename({extname: '.min.js'}))
    .pipe(sourcemaps.write('maps'))
    .pipe(gulp.dest('dist'));
});
<|endoftext|>


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

var $ = require('gulp-load-plugins')({
  pattern: ['gulp-*', 'main-bower-files']
});

var config = {
  dir: {
    app: 'app',
    build: 'build',
    build_libs: 'build/libs',
    public: 'public'
  },
  file: {
    template: 'template.js',
    compiled: 'app-compiled.js',
    annotated: 'app-annotated.js',
    concatenated: 'app-concatenated.js',
    compressed: 'app-compressed.js',
    deployed: 'app.js'
  },
  libs: [
    'jquery.js',
    'angular.js',
    'angular-resource.js',
    'angular-sanitize.js',
    'angular-ui-router.js',
    'bootstrap.js',
    'ui-bootstrap-tpls.js'
  ],
  moduleName: 'app'
};

gulp.task('clean', function (callback) {
  del([config.dir.build, config.dir.public], callback);
});

gulp.task('copy:ts', [], function () {
  return gulp.src(path.join(config.dir.app, '**/*.ts'))
    .pipe(gulp.dest(config.dir.build));
});

gulp.task('copy:font', [], function () {
  return gulp.src('./bower_components/bootstrap/dist/fonts/*', {base: './bower_components/bootstrap/dist/'})
    .pipe(gulp.dest(config.dir.public));
});

gulp.task('copy:css', [], function () {
  return gulp.src(
    [
      './bower_components/bootstrap/dist/css/bootstrap.css',
      './bower_components/bootstrap/dist/css/bootstrap-theme.css'
    ],
    {base: './bower_components/bootstrap/dist/'})
    .pipe(gulp.dest(config.dir.public));
});

gulp.task('copy:view', [], function () {
  return gulp.src(path.join(config.dir.app, 'index.html'))
    .pipe(gulp.dest(config.dir.public));
});

gulp.task('copy:static-file', ['copy:font', 'copy:css', 'copy:view']);

gulp.task('template-cache', function () {
  return gulp.src([path.join(config.dir.app, '**/*.html'), '!' + path.join(config.dir.app, 'index.html')])
    .pipe($.angularTemplatecache({
      module: config.moduleName
    }))
    .pipe($.rename(config.file.template))
    .pipe(gulp.dest(config.dir.build));
});

gulp.task('tsc', ['copy:ts'], function () {
  return gulp.src(path.join(config.dir.build, '**/*.ts'))
    .pipe($.plumber())
    .pipe($.tsc({
      out: config.file.compiled,
      target: 'ES5'
    }))
    .pipe(gulp.dest(config.dir.build));
});

gulp.task('bower', function (callback) {
  bower.commands.install()
    .on('end', function () {
      callback()
    });
});

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

gulp.task('copy:lib', function () {
  return gulp.src($.mainBowerFiles())
    .pipe(gulp.dest(config.dir.build_libs));
});

gulp.task('annotate', ['tsc'], function () {
  return gulp.src(path.join(config.dir.build, config.file.compiled))
    .pipe($.ngAnnotate())
    .pipe($.rename(config.file.annotated))
    .pipe(gulp.dest(path.join(config.dir.build)));
});

gulp.task('concat', ['annotate', 'template-cache', 'copy:lib'], function () {
  return gulp.src(config.libs.map(function (lib) {
    return path.join(config.dir.build_libs, lib);
  }).concat(path.join(config.dir.build, config.file.annotated))
    .concat(path.join(config.dir.build, config.file.template)))
    .pipe($.concat(config.file.concatenated))
    .pipe(gulp.dest(config.dir.build));
});

gulp.task('uglify', ['concat'], function () {
  return gulp.src(path.join(config.dir.build, config.file.concatenated))
    .pipe($.uglify())
    .pipe($.rename(config.file.compressed))
    .pipe(gulp.dest(config.dir.build));
});

gulp.task('watch', [], function () {
  gulp.watch(path.join(config.dir.public, 'index.html'), ['copy:view']);
  gulp.watch([
      path.join(config.dir.app, '**/*.ts'),
      path.join(config.dir.app, '**/*.html')
    ],
    ['deploy:dev']);
});

gulp.task('serve', ['watch'], function () {
  return gulp.src(config.dir.public)
    .pipe($.webserver());
});

gulp.task('deploy:dev', ['concat'], function () {
  return gulp.src(path.join(config.dir.build, config.file.concatenated))
    .pipe($.rename(config.file.deployed))
    .pipe(gulp.dest(config.dir.public));
});

gulp.task('deploy:rel', ['uglify'], function () {
  return gulp.src(path.join(config.dir.build, config.file.compressed))
    .pipe($.rename(config.file.deployed))
    .pipe(gulp.dest(config.dir.public));
});

gulp.task('build:dev', ['copy:static-file', 'deploy:dev']);
gulp.task('build:rel', ['copy:static-file', 'deploy:rel']);

gulp.task('init', ['tsd', 'bower']);

gulp.task('default', ['build:dev']);<commit_msg>refactoring<commit_after>var gulp = require('gulp');
var path = require('path');
var del = require('del');
var bower = require('bower');

var $ = require('gulp-load-plugins')({
  pattern: ['gulp-*', 'main-bower-files']
});

var config = {
  paths: {
    app: 'app',
    build: 'build',
    build_libs: 'build/libs',
    public: 'public'
  },
  files: {
    template: 'template.js',
    compiled: 'app-compiled.js',
    annotated: 'app-annotated.js',
    concatenated: 'app-concatenated.js',
    compressed: 'app-compressed.js',
    deployed: 'app.js'
  },
  libraries: [
    'jquery.js',
    'angular.js',
    'angular-resource.js',
    'angular-sanitize.js',
    'angular-ui-router.js',
    'bootstrap.js',
    'ui-bootstrap-tpls.js'
  ],
  moduleName: 'app'
};

gulp.task('clean', function (callback) {
  del([config.paths.build, config.paths.public], callback);
});

gulp.task('copy:ts', [], function () {
  return gulp.src(path.join(config.paths.app, '**/*.ts'))
    .pipe(gulp.dest(config.paths.build));
});

gulp.task('copy:font', [], function () {
  return gulp.src('./bower_components/bootstrap/dist/fonts/*', {base: './bower_components/bootstrap/dist/'})
    .pipe(gulp.dest(config.paths.public));
});

gulp.task('copy:css', [], function () {
  return gulp.src(
    [
      './bower_components/bootstrap/dist/css/bootstrap.css',
      './bower_components/bootstrap/dist/css/bootstrap-theme.css'
    ],
    {base: './bower_components/bootstrap/dist/'})
    .pipe(gulp.dest(config.paths.public));
});

gulp.task('copy:view', [], function () {
  return gulp.src(path.join(config.paths.app, 'index.html'))
    .pipe(gulp.dest(config.paths.public));
});

gulp.task('copy:static-file', ['copy:font', 'copy:css', 'copy:view']);

gulp.task('template-cache', function () {
  return gulp.src([path.join(config.paths.app, '**/*.html'), '!' + path.join(config.paths.app, 'index.html')])
    .pipe($.angularTemplatecache({
      module: config.moduleName
    }))
    .pipe($.rename(config.files.template))
    .pipe(gulp.dest(config.paths.build));
});

gulp.task('tsc', ['copy:ts'], function () {
  return gulp.src(path.join(config.paths.build, '**/*.ts'))
    .pipe($.plumber())
    .pipe($.tsc({
      out: config.files.compiled,
      target: 'ES5'
    }))
    .pipe(gulp.dest(config.paths.build));
});

gulp.task('bower', function (callback) {
  bower.commands.install()
    .on('end', function () {
      callback()
    });
});

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

gulp.task('copy:lib', function () {
  return gulp.src($.mainBowerFiles())
    .pipe(gulp.dest(config.paths.build_libs));
});

gulp.task('annotate', ['tsc'], function () {
  return gulp.src(path.join(config.paths.build, config.files.compiled))
    .pipe($.ngAnnotate())
    .pipe($.rename(config.files.annotated))
    .pipe(gulp.dest(path.join(config.paths.build)));
});

gulp.task('concat', ['annotate', 'template-cache', 'copy:lib'], function () {
  return gulp.src(config.libraries.map(function (lib) {
    return path.join(config.paths.build_libs, lib);
  }).concat(path.join(config.paths.build, config.files.annotated))
    .concat(path.join(config.paths.build, config.files.template)))
    .pipe($.concat(config.files.concatenated))
    .pipe(gulp.dest(config.paths.build));
});

gulp.task('uglify', ['concat'], function () {
  return gulp.src(path.join(config.paths.build, config.files.concatenated))
    .pipe($.uglify())
    .pipe($.rename(config.files.compressed))
    .pipe(gulp.dest(config.paths.build));
});

gulp.task('watch', [], function () {
  gulp.watch(path.join(config.paths.public, 'index.html'), ['copy:view']);
  gulp.watch([
      path.join(config.paths.app, '**/*.ts'),
      path.join(config.paths.app, '**/*.html')
    ],
    ['deploy:dev']);
});

gulp.task('serve', ['watch'], function () {
  return gulp.src(config.paths.public)
    .pipe($.webserver());
});

gulp.task('deploy:dev', ['concat'], function () {
  return gulp.src(path.join(config.paths.build, config.files.concatenated))
    .pipe($.rename(config.files.deployed))
    .pipe(gulp.dest(config.paths.public));
});

gulp.task('deploy:rel', ['uglify'], function () {
  return gulp.src(path.join(config.paths.build, config.files.compressed))
    .pipe($.rename(config.files.deployed))
    .pipe(gulp.dest(config.paths.public));
});

gulp.task('build:dev', ['copy:static-file', 'deploy:dev']);
gulp.task('build:rel', ['copy:static-file', 'deploy:rel']);

gulp.task('init', ['tsd', 'bower']);

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


<commit_before>/*
* Swill Boilerplate v0.5.0beta
* https://github.com/tiagoporto/swill-boilerplate
* Copyright (c) 2014-2016 Tiago Porto (http://tiagoporto.com)
* Released under the MIT license
*/

/* eslint-env node */
/* eslint strict: ["error", "global"]*/
'use strict';

var args = require('yargs').argv,
    browserSync = require('browser-sync'),
    buffer = require('vinyl-buffer'),
    config = require('./config.json'),
    del = require('del'),
    fs = require('fs'),
    gulp = require('gulp'),
    handlebars = require('gulp-hb'),
    Karma = require('karma').Server,
    merge = require('merge-stream'),
    plugins = require('gulp-load-plugins')(),
    sequence = require('run-sequence'),
    spritesmith = require('gulp.spritesmith'),
    svgSprite = require('gulp-svg-sprite'),

    // ***************************** Path configs ***************************** //

    basePaths = config.basePaths,

    paths = {
        html: {
            src: basePaths.src + basePaths.handlebars.src
        },

        images: {
            src: basePaths.src + basePaths.images.src,
            dest: basePaths.dest + basePaths.images.dest,
            build: basePaths.build + basePaths.images.src
        },

        sprite: {
            src: basePaths.src + basePaths.images.src + basePaths.sprite.src
        },

        scripts: {
            src: basePaths.src + basePaths.scripts.src,
            dest: basePaths.dest + basePaths.scripts.dest,
            build: basePaths.build + basePaths.scripts.dest
        },

        styles: {
            src: basePaths.src + basePaths.styles.src,
            dest: basePaths.dest + basePaths.styles.dest,
            build: basePaths.build + basePaths.styles.dest
        }
    },

    // ******************************* Settings ******************************* //
    env = (args.prod) ? 'prod' : 'dev',
    extensionStyle = 'styl',
    headerProject = fs.readFileSync(basePaths.src + 'header-comments.txt', 'utf8');

// ******************************** Tasks ********************************* //

gulp.task('coverall', function() {
    gulp.src('coverage/**/lcov.info')
        .pipe(plugins.coveralls());
});

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

gulp.task('test', function() {
    sequence('karma', 'coverall');
});

gulp.task('handlebars', function() {
    if (config.handlebars) {
        return gulp
            .src(paths.html.src + '**/*.html')
            .pipe(handlebars({
                partials: paths.html.src + basePaths.handlebars.partials.src + '**/*.hbs'
            }))
            .pipe(gulp.dest(basePaths.dest));
    }
});

gulp.task('svg-inline', function() {
    if (config.inlineSVG) {
        return gulp.src(basePaths.dest + '**/*.html')
            .pipe(plugins.inline({
                base: './',
                disabledTypes: ['css', 'js']
            }))
            .pipe(gulp.dest(basePaths.dest));
    }
});

gulp.task('styles-helpers', function() {
    var mixins = gulp.src(paths.styles.src + 'helpers/mixins/*.{styl,scss}')
                    .pipe(plugins.concat('_mixins.' + extensionStyle))
                    .pipe(gulp.dest(paths.styles.src + 'helpers'));

    var functions = gulp.src(paths.styles.src + 'helpers/functions/*.{styl,scss}')
                        .pipe(plugins.concat('_functions.' + extensionStyle))
                        .pipe(gulp.dest(paths.styles.src + 'helpers'));

    return merge(mixins, functions);
});

gulp.task('styles', function() {
    return gulp.src(
        [
            paths.styles.src + '*.styl',
            '!' + paths.styles.src + '_*.styl'
        ])
        .pipe(plugins.plumber())
        .pipe(
            plugins.stylus({
                'include css': true//,use:[koutoSwiss(), rupture()]
            })
            .on('error', function(err) {
                console.log(err.message);

                // If rename the stylus file change here
                plugins.file('styles.css', 'body:before{white-space: pre; font-family: monospace; content: "' + err.message + '";}', { src: true })
                    .pipe(plugins.replace('\\', '/'))
                    .pipe(plugins.replace(/\n/gm, '\\A '))
                    .pipe(plugins.replace('\"', '\''))
                    .pipe(plugins.replace("content: '", 'content: "'))
                    .pipe(plugins.replace('\';}', '";}'))
                    .pipe(gulp.dest(paths.styles.dest))
                    .pipe(plugins.rename({suffix: '.min'}))
                    .pipe(gulp.dest(paths.styles.dest));
            })
        )
        .pipe(plugins.autoprefixer({
            browsers: config.autoprefixerBrowsers
        }))
        .pipe(plugins.wrapper({
            header: headerProject + '\n'
        }))
        .pipe(plugins.if(config.lintCSS, plugins.csslint('./.csslintrc')))
        .pipe(plugins.if(config.lintCSS, plugins.csslint.formatter()))
        .pipe(gulp.dest(paths.styles.dest))
        .pipe(plugins.csso())
        .pipe(plugins.rename({suffix: '.min'}))
        .pipe(gulp.dest(paths.styles.dest))
        .pipe(plugins.notify({message: 'Styles task complete', onLast: true}));
});

// Generate Bitmap Sprite
gulp.task('bitmap-sprite', function() {
    var sprite = gulp.src(paths.sprite.src + '**/*.png')
                    .pipe(plugins.plumber())
                    .pipe(
                        spritesmith({
                            imgName: 'bitmap-sprite.png',
                            cssName: '_bitmap-sprite.' + extensionStyle,
                            cssOpts: {
                                cssSelector: function(item) {
                                    if (item.name.indexOf('~hover') !== -1) {
                                        return '.icon-' + item.name.replace('~hover', ':hover');
                                    } else {
                                        return '.icon-' + item.name;
                                    }
                                }
                            },
                            imgPath: '../' + basePaths.images.dest + 'bitmap-sprite.png',
                            padding: 2,
                            algorithm: 'top-down'
                        })
                    );

    sprite.img
        .pipe(buffer())
        .pipe(plugins.imagemin())
        .pipe(gulp.dest(paths.images.dest));
    sprite.css
        .pipe(gulp.dest(paths.styles.src + 'helpers'))
        .pipe(plugins.notify({message: 'Bitmap sprite task complete', onLast: true}));

    return sprite;
});

// Generate SVG Sprite
gulp.task('vetor-sprite', function() {
    var spriteOptions = {
        shape: {
            spacing: { padding: 2 }
        },
        mode: {
            css: {
                prefix: '.icon-%s',
                dest: './',
                sprite: '../' + basePaths.images.dest + 'vetor-sprite.svg',
                layout: 'vertical',
                bust: false,
                render: {}
            }
        }
    };

    spriteOptions.mode.css.render[extensionStyle] = {};

    spriteOptions.mode.css.render[extensionStyle].dest = '../../' + paths.styles.src + 'helpers/_vetor-sprite.' + extensionStyle;

    return gulp.src(paths.sprite.src + '*.svg')
                .pipe(plugins.plumber())
                .pipe(svgSprite(spriteOptions))
                .pipe(gulp.dest(paths.images.dest))
                .pipe(plugins.notify({message: 'SVG sprite task complete', onLast: true}));
});

// Fallback convert SVG to PNG
gulp.task('svg2png', function() {
    return gulp.src(paths.images.dest + 'vetor-sprite.svg')
                .pipe(plugins.plumber())
                .pipe(plugins.svg2png())
                .pipe(gulp.dest(paths.images.dest));
});

// Optimize Images
gulp.task('images', function() {
    var images = gulp.src(
        [
            paths.images.src + '**/*.{bmp,gif,jpg,jpeg,png,svg}',
            '!' + paths.sprite.src + '**/*'
        ])
        .pipe(plugins.plumber())
        .pipe(plugins.newer(paths.images.dest))
        .pipe(plugins.imagemin({optimizationLevel: 5, progressive: true}))
        .pipe(gulp.dest(paths.images.dest));

    var svg = gulp.src(
        [
            paths.images.src + '**/*.svg',
            '!' + paths.sprite.src + '**/*'
        ])
        .pipe(plugins.plumber())
        .pipe(plugins.newer(paths.images.dest))
        .pipe(plugins.svg2png())
        .pipe(gulp.dest(paths.images.dest))
        .pipe(plugins.notify({message: 'Images task complete', onLast: true}));

    return merge(images, svg);
});

// Concatenate vendor scripts and Minify
gulp.task('vendor-scripts', function() {
    var envProd = (env === 'prod') ? '' : '!';

    return gulp.src(
        [
            '!' + paths.scripts.src + '**/*{_SEPARATE,_IGNORE}.js',
            paths.scripts.src + 'settings/*.js',
            envProd + paths.scripts.src + 'settings/google_analytics.js'
        ])
        .pipe(plugins.plumber())
        .pipe(plugins.concat('vendors.js'))
        .pipe(gulp.dest(paths.scripts.dest))
        .pipe(plugins.rename('vendors.min.js'))
        .pipe(plugins.uglify())
        .pipe(gulp.dest(paths.scripts.dest));
});

// Concatenate and Minify Main Scripts
gulp.task('scripts', function() {
    var babelOption = { presets: ['@babel/env'] };
    var headerWrapper = { header: headerProject + '\n' };
    var jQueryWrapper = {
        header: 'jQuery(document).ready(function($) {\n\n',
        footer: '\n});'
    };

    var concatenate = gulp.src(
        [
            '!' + paths.scripts.src + '**/*{_SEPARATE,_IGNORE}.js',
            paths.scripts.src + '*.js'
        ])
        .pipe(plugins.plumber())
        .pipe(plugins.cached('scripts'))
        .pipe(plugins.remember('scripts'))
        .pipe(plugins.plumber())
        .pipe(plugins.if(config.lintJS, plugins.eslint()))
        .pipe(plugins.if(config.lintJS, plugins.eslint.format()))
        .pipe(plugins.concat('scripts.js'))
        .pipe(plugins.babel(babelOption))
        .pipe(plugins.if(config.jQuery, plugins.wrapper(jQueryWrapper)))
        .pipe(plugins.wrapper(headerWrapper))
        .pipe(gulp.dest(paths.scripts.dest))
        .pipe(plugins.rename({suffix: '.min'}))
        .pipe(plugins.uglify())
        .pipe(gulp.dest(paths.scripts.dest));

    var copy = gulp.src(paths.scripts.src + '/**/*_SEPARATE.js')
                    .pipe(plugins.plumber())
                    .pipe(plugins.newer(paths.scripts.dest))
                    .pipe(plugins.plumber())
                    .pipe(plugins.if(config.lintJS, plugins.eslint()))
                    .pipe(plugins.if(config.lintJS, plugins.eslint.format()))
                    .pipe(plugins.rename(function(path) {
                        path.basename = path.basename.substring(0, path.basename.length - 9);
                    }))
                    .pipe(plugins.babel(babelOption))
                    .pipe(plugins.wrapper(headerWrapper))
                    .pipe(gulp.dest(paths.scripts.dest))
                    .pipe(plugins.rename({suffix: '.min'}))
                    .pipe(plugins.uglify({preserveComments: 'some'}))
                    .pipe(gulp.dest(paths.scripts.dest))
                    .pipe(plugins.notify({message: 'Scripts task complete', onLast: true}));

    return merge(concatenate, copy);
});

// Copy Files to Build
gulp.task('copy', function() {
    var assets = {searchPath: basePaths.dest};

    // Minify and Copy HTML
    var html = gulp.src(
        [
            basePaths.dest + '**/*.{html,php}'
        ])
        .pipe(plugins.useref(assets))
        .pipe(plugins.if('*.js', plugins.uglify()))
        .pipe(plugins.if('*.css', plugins.csso()))
        .pipe(plugins.if('*.html', plugins.htmlmin({collapseWhitespace: true, spare: true, empty: true, conditionals: true})))
        .pipe(plugins.if('*.php', plugins.htmlmin({collapseWhitespace: true, spare: true, empty: true, conditionals: true})))
        .pipe(gulp.dest(basePaths.build));

    // Copy All Other files except HTML, PHP, CSS e JS Files
    var allFiles = gulp.src(
        [
            basePaths.dest + '**/*',
            '!' + paths.styles.dest + '**/*',
            '!' + paths.scripts.dest + '**/*',
            '!' + basePaths.dest + '**/*.{html,php}'
        ], {dot: true})
        .pipe(gulp.dest(basePaths.build));

    return merge(html, allFiles);
});

gulp.task('outdatedbrowser', function() {
    return gulp.src('node_modules/outdated-browser/outdatedbrowser/lang/*')
        .pipe(gulp.dest(basePaths.dest + 'lang/outdated_browser'));
});

// *************************** Utility Tasks ****************************** //

gulp.task('combine-assets', function() {
    var assets = {searchPath: basePaths.dest};

    // Minify and Copy HTML
    return gulp.src(basePaths.dest + '**/*.{html,php}')
                    .pipe(plugins.useref(assets))
                    .pipe(plugins.if('*.js', plugins.uglify()))
                    .pipe(plugins.if('*.css', plugins.csso()))
                    .pipe(gulp.dest(basePaths.dest));
});

// Clean Directories
gulp.task('clean', function(cb) {
    var cleanPaths = [
        basePaths.build,
        paths.styles.dest,
        paths.scripts.dest,
        paths.styles.src + 'helpers/{_bitmap-sprite,_vetor-sprite}.{styl,scss}',
        paths.images.dest + '**/*'
    ];

    return del(cleanPaths.concat(basePaths.clean.ignore), cb);
});

// ***************************** Main Tasks ******************************* //

// Serve the project and watch
gulp.task('serve', function() {
    browserSync(config.browserSync);

    gulp.watch(
        [
            paths.images.src + '**/*.{bmp,gif,jpg,jpeg,png,svg}',
            '!' + paths.sprite.src + '**/*'
        ],
        ['images', browserSync.reload]
    );

    gulp.watch(paths.sprite.src + '**/*.{png,gif}', ['bitmap-sprite', browserSync.reload]);

    gulp.watch(paths.sprite.src + '**/*.svg', ['vetor-sprite', 'styles', browserSync.reload]);

    gulp.watch(paths.images.dest + '**/*.svg', ['svg2png', 'handlebars', browserSync.reload]);

    gulp.watch(paths.scripts.src + '*.js', ['scripts', browserSync.reload]);

    gulp.watch(paths.scripts.src + 'settings/**/*.js', ['vendor-scripts', browserSync.reload]);

    gulp.watch(
        [
            paths.styles.src + '**/*.{styl,scss,sass}',
            '!' + paths.styles.src + 'helpers/{mixins,functions}/*.{styl,scss,sass}'
        ],

       ['styles', browserSync.reload]
    );

    gulp.watch(paths.styles.src + 'helpers/{mixins,functions}/*.{styl,scss,sass}', ['styles-helpers']);

    gulp.watch(paths.html.src + '**/*.{html,hbs}', ['handlebars']);

    gulp.watch(basePaths.dest + '**/*.{html,php,json}', ['svg-inline', browserSync.reload]);
});

// Serve project and clean, compile and watch if pass the parameter --compile
gulp.task('default', function() {
    if (args.compile) {
        sequence('clean', ['outdatedbrowser', 'handlebars', 'images', 'bitmap-sprite', 'vetor-sprite', 'styles-helpers', 'vendor-scripts'], 'svg2png', 'svg-inline', 'styles', 'scripts', 'serve');
    } else {
        sequence('handlebars', 'serve');
    }
});

// Clean and compile the project
gulp.task('compile', function() {
    sequence('clean', ['outdatedbrowser', 'handlebars', 'images', 'bitmap-sprite', 'vetor-sprite', 'styles-helpers', 'vendor-scripts'], 'svg2png', 'svg-inline', 'styles', 'scripts');
});

// Build Project and serve if pass the parameter --serve
gulp.task('build', ['clean'], function() {
    env = 'prod';
    sequence(['outdatedbrowser', 'handlebars', 'images', 'bitmap-sprite', 'vetor-sprite', 'styles-helpers', 'vendor-scripts'], 'svg2png', 'svg-inline', 'styles', 'scripts', 'copy', function() {args.serve && browserSync(config.browserSyncBuild)}
    );
});
<commit_msg>Update gulpfile.js<commit_after>/*
* Swill Boilerplate v0.5.0beta
* https://github.com/tiagoporto/swill-boilerplate
* Copyright (c) 2014-2016 Tiago Porto (http://tiagoporto.com)
* Released under the MIT license
*/

/* eslint-env node */
/* eslint strict: ["error", "global"]*/
'use strict';

var args = require('yargs').argv,
    browserSync = require('browser-sync'),
    buffer = require('vinyl-buffer'),
    config = require('./config.json'),
    del = require('del'),
    fs = require('fs'),
    gulp = require('gulp'),
    handlebars = require('gulp-hb'),
    Karma = require('karma').Server,
    merge = require('merge-stream'),
    plugins = require('gulp-load-plugins')(),
    sequence = require('run-sequence'),
    spritesmith = require('gulp.spritesmith'),
    svgSprite = require('gulp-svg-sprite'),

    // ***************************** Path configs ***************************** //

    basePaths = config.basePaths,

    paths = {
        html: {
            src: basePaths.src + basePaths.handlebars.src
        },

        images: {
            src: basePaths.src + basePaths.images.src,
            dest: basePaths.dest + basePaths.images.dest,
            build: basePaths.build + basePaths.images.src
        },

        sprite: {
            src: basePaths.src + basePaths.images.src + basePaths.sprite.src
        },

        scripts: {
            src: basePaths.src + basePaths.scripts.src,
            dest: basePaths.dest + basePaths.scripts.dest,
            build: basePaths.build + basePaths.scripts.dest
        },

        styles: {
            src: basePaths.src + basePaths.styles.src,
            dest: basePaths.dest + basePaths.styles.dest,
            build: basePaths.build + basePaths.styles.dest
        }
    },

    // ******************************* Settings ******************************* //
    env = (args.prod) ? 'prod' : 'dev',
    extensionStyle = 'styl',
    headerProject = fs.readFileSync(basePaths.src + 'header-comments.txt', 'utf8');

// ******************************** Tasks ********************************* //

gulp.task('coverall', function () {
    gulp.src('coverage/**/lcov.info')
        .pipe(plugins.coveralls());
});

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

gulp.task('test', function () {
    sequence('karma', 'coverall');
});

gulp.task('handlebars', function () {
    if (config.handlebars) {
        return gulp
            .src(paths.html.src + '**/*.html')
            .pipe(handlebars({
                partials: paths.html.src + basePaths.handlebars.partials.src + '**/*.hbs'
            }))
            .pipe(gulp.dest(basePaths.dest));
    }
});

gulp.task('svg-inline', function () {
    if (config.inlineSVG) {
        return gulp.src(basePaths.dest + '**/*.html')
            .pipe(plugins.inline({
                base: './',
                disabledTypes: ['css', 'js']
            }))
            .pipe(gulp.dest(basePaths.dest));
    }
});

gulp.task('styles-helpers', function () {
    var mixins = gulp.src(paths.styles.src + 'helpers/mixins/*.{styl,scss}')
        .pipe(plugins.concat('_mixins.' + extensionStyle))
        .pipe(gulp.dest(paths.styles.src + 'helpers'));

    var functions = gulp.src(paths.styles.src + 'helpers/functions/*.{styl,scss}')
        .pipe(plugins.concat('_functions.' + extensionStyle))
        .pipe(gulp.dest(paths.styles.src + 'helpers'));

    return merge(mixins, functions);
});

gulp.task('styles', function () {
    return gulp.src(
        [
            paths.styles.src + '*.styl',
            '!' + paths.styles.src + '_*.styl'
        ])
        .pipe(plugins.plumber())
        .pipe(
            plugins.stylus({
                'include css': true//,use:[koutoSwiss(), rupture()]
            })
                .on('error', function (err) {
                    console.log(err.message);

                    // If rename the stylus file change here
                    plugins.file('styles.css', 'body:before{white-space: pre; font-family: monospace; content: "' + err.message + '";}', { src: true })
                        .pipe(plugins.replace('\\', '/'))
                        .pipe(plugins.replace(/\n/gm, '\\A '))
                        .pipe(plugins.replace('\"', '\''))
                        .pipe(plugins.replace("content: '", 'content: "'))
                        .pipe(plugins.replace('\';}', '";}'))
                        .pipe(gulp.dest(paths.styles.dest))
                        .pipe(plugins.rename({ suffix: '.min' }))
                        .pipe(gulp.dest(paths.styles.dest));
                })
        )
        .pipe(plugins.autoprefixer({
            browsers: config.autoprefixerBrowsers
        }))
        .pipe(plugins.wrapper({
            header: headerProject + '\n'
        }))
        .pipe(gulp.dest(paths.styles.dest))
        .pipe(plugins.csso())
        .pipe(plugins.rename({ suffix: '.min' }))
        .pipe(gulp.dest(paths.styles.dest))
        .pipe(plugins.notify({ message: 'Styles task complete', onLast: true }));
});

// Generate Bitmap Sprite
gulp.task('bitmap-sprite', function () {
    var sprite = gulp.src(paths.sprite.src + '**/*.png')
        .pipe(plugins.plumber())
        .pipe(
            spritesmith({
                imgName: 'bitmap-sprite.png',
                cssName: '_bitmap-sprite.' + extensionStyle,
                cssOpts: {
                    cssSelector: function (item) {
                        if (item.name.indexOf('~hover') !== -1) {
                            return '.icon-' + item.name.replace('~hover', ':hover');
                        } else {
                            return '.icon-' + item.name;
                        }
                    }
                },
                imgPath: '../' + basePaths.images.dest + 'bitmap-sprite.png',
                padding: 2,
                algorithm: 'top-down'
            })
        );

    sprite.img
        .pipe(buffer())
        .pipe(plugins.imagemin())
        .pipe(gulp.dest(paths.images.dest));
    sprite.css
        .pipe(gulp.dest(paths.styles.src + 'helpers'))
        .pipe(plugins.notify({ message: 'Bitmap sprite task complete', onLast: true }));

    return sprite;
});

// Generate SVG Sprite
gulp.task('vetor-sprite', function () {
    var spriteOptions = {
        shape: {
            spacing: { padding: 2 }
        },
        mode: {
            css: {
                prefix: '.icon-%s',
                dest: './',
                sprite: '../' + basePaths.images.dest + 'vetor-sprite.svg',
                layout: 'vertical',
                bust: false,
                render: {}
            }
        }
    };

    spriteOptions.mode.css.render[extensionStyle] = {};

    spriteOptions.mode.css.render[extensionStyle].dest = '../../' + paths.styles.src + 'helpers/_vetor-sprite.' + extensionStyle;

    return gulp.src(paths.sprite.src + '*.svg')
        .pipe(plugins.plumber())
        .pipe(svgSprite(spriteOptions))
        .pipe(gulp.dest(paths.images.dest))
        .pipe(plugins.notify({ message: 'SVG sprite task complete', onLast: true }));
});

// Fallback convert SVG to PNG
gulp.task('svg2png', function () {
    return gulp.src(paths.images.dest + 'vetor-sprite.svg')
        .pipe(plugins.plumber())
        .pipe(plugins.svg2png())
        .pipe(gulp.dest(paths.images.dest));
});

// Optimize Images
gulp.task('images', function () {
    var images = gulp.src(
        [
            paths.images.src + '**/*.{bmp,gif,jpg,jpeg,png,svg}',
            '!' + paths.sprite.src + '**/*'
        ])
        .pipe(plugins.plumber())
        .pipe(plugins.newer(paths.images.dest))
        .pipe(plugins.imagemin({ optimizationLevel: 5, progressive: true }))
        .pipe(gulp.dest(paths.images.dest));

    var svg = gulp.src(
        [
            paths.images.src + '**/*.svg',
            '!' + paths.sprite.src + '**/*'
        ])
        .pipe(plugins.plumber())
        .pipe(plugins.newer(paths.images.dest))
        .pipe(plugins.svg2png())
        .pipe(gulp.dest(paths.images.dest))
        .pipe(plugins.notify({ message: 'Images task complete', onLast: true }));

    return merge(images, svg);
});

// Concatenate vendor scripts and Minify
gulp.task('vendor-scripts', function () {
    var envProd = (env === 'prod') ? '' : '!';

    return gulp.src(
        [
            '!' + paths.scripts.src + '**/*{_SEPARATE,_IGNORE}.js',
            paths.scripts.src + 'settings/*.js',
            envProd + paths.scripts.src + 'settings/google_analytics.js'
        ])
        .pipe(plugins.plumber())
        .pipe(plugins.concat('vendors.js'))
        .pipe(gulp.dest(paths.scripts.dest))
        .pipe(plugins.rename('vendors.min.js'))
        .pipe(plugins.uglify())
        .pipe(gulp.dest(paths.scripts.dest));
});

// Concatenate and Minify Main Scripts
gulp.task('scripts', function () {
    var babelOption = { presets: ['@babel/env'] };
    var headerWrapper = { header: headerProject + '\n' };
    var jQueryWrapper = {
        header: 'jQuery(document).ready(function($) {\n\n',
        footer: '\n});'
    };

    var concatenate = gulp.src(
        [
            '!' + paths.scripts.src + '**/*{_SEPARATE,_IGNORE}.js',
            paths.scripts.src + '*.js'
        ])
        .pipe(plugins.plumber())
        .pipe(plugins.cached('scripts'))
        .pipe(plugins.remember('scripts'))
        .pipe(plugins.plumber())
        .pipe(plugins.if(config.lintJS, plugins.eslint()))
        .pipe(plugins.if(config.lintJS, plugins.eslint.format()))
        .pipe(plugins.concat('scripts.js'))
        .pipe(plugins.babel(babelOption))
        .pipe(plugins.if(config.jQuery, plugins.wrapper(jQueryWrapper)))
        .pipe(plugins.wrapper(headerWrapper))
        .pipe(gulp.dest(paths.scripts.dest))
        .pipe(plugins.rename({ suffix: '.min' }))
        .pipe(plugins.uglify())
        .pipe(gulp.dest(paths.scripts.dest));

    var copy = gulp.src(paths.scripts.src + '/**/*_SEPARATE.js')
        .pipe(plugins.plumber())
        .pipe(plugins.newer(paths.scripts.dest))
        .pipe(plugins.plumber())
        .pipe(plugins.if(config.lintJS, plugins.eslint()))
        .pipe(plugins.if(config.lintJS, plugins.eslint.format()))
        .pipe(plugins.rename(function (path) {
            path.basename = path.basename.substring(0, path.basename.length - 9);
        }))
        .pipe(plugins.babel(babelOption))
        .pipe(plugins.wrapper(headerWrapper))
        .pipe(gulp.dest(paths.scripts.dest))
        .pipe(plugins.rename({ suffix: '.min' }))
        .pipe(plugins.uglify({ preserveComments: 'some' }))
        .pipe(gulp.dest(paths.scripts.dest))
        .pipe(plugins.notify({ message: 'Scripts task complete', onLast: true }));

    return merge(concatenate, copy);
});

// Copy Files to Build
gulp.task('copy', function () {
    var assets = { searchPath: basePaths.dest };

    // Minify and Copy HTML
    var html = gulp.src(
        [
            basePaths.dest + '**/*.{html,php}'
        ])
        .pipe(plugins.useref(assets))
        .pipe(plugins.if('*.js', plugins.uglify()))
        .pipe(plugins.if('*.css', plugins.csso()))
        .pipe(plugins.if('*.html', plugins.htmlmin({ collapseWhitespace: true, spare: true, empty: true, conditionals: true })))
        .pipe(plugins.if('*.php', plugins.htmlmin({ collapseWhitespace: true, spare: true, empty: true, conditionals: true })))
        .pipe(gulp.dest(basePaths.build));

    // Copy All Other files except HTML, PHP, CSS e JS Files
    var allFiles = gulp.src(
        [
            basePaths.dest + '**/*',
            '!' + paths.styles.dest + '**/*',
            '!' + paths.scripts.dest + '**/*',
            '!' + basePaths.dest + '**/*.{html,php}'
        ], { dot: true })
        .pipe(gulp.dest(basePaths.build));

    return merge(html, allFiles);
});

gulp.task('outdatedbrowser', function () {
    return gulp.src('node_modules/outdated-browser/outdatedbrowser/lang/*')
        .pipe(gulp.dest(basePaths.dest + 'lang/outdated_browser'));
});

// *************************** Utility Tasks ****************************** //

gulp.task('combine-assets', function () {
    var assets = { searchPath: basePaths.dest };

    // Minify and Copy HTML
    return gulp.src(basePaths.dest + '**/*.{html,php}')
        .pipe(plugins.useref(assets))
        .pipe(plugins.if('*.js', plugins.uglify()))
        .pipe(plugins.if('*.css', plugins.csso()))
        .pipe(gulp.dest(basePaths.dest));
});

// Clean Directories
gulp.task('clean', function (cb) {
    var cleanPaths = [
        basePaths.build,
        paths.styles.dest,
        paths.scripts.dest,
        paths.styles.src + 'helpers/{_bitmap-sprite,_vetor-sprite}.{styl,scss}',
        paths.images.dest + '**/*'
    ];

    return del(cleanPaths.concat(basePaths.clean.ignore), cb);
});

// ***************************** Main Tasks ******************************* //

// Serve the project and watch
gulp.task('serve', function () {
    browserSync(config.browserSync);

    gulp.watch(
        [
            paths.images.src + '**/*.{bmp,gif,jpg,jpeg,png,svg}',
            '!' + paths.sprite.src + '**/*'
        ],
        ['images', browserSync.reload]
    );

    gulp.watch(paths.sprite.src + '**/*.{png,gif}', ['bitmap-sprite', browserSync.reload]);

    gulp.watch(paths.sprite.src + '**/*.svg', ['vetor-sprite', 'styles', browserSync.reload]);

    gulp.watch(paths.images.dest + '**/*.svg', ['svg2png', 'handlebars', browserSync.reload]);

    gulp.watch(paths.scripts.src + '*.js', ['scripts', browserSync.reload]);

    gulp.watch(paths.scripts.src + 'settings/**/*.js', ['vendor-scripts', browserSync.reload]);

    gulp.watch(
        [
            paths.styles.src + '**/*.{styl,scss,sass}',
            '!' + paths.styles.src + 'helpers/{mixins,functions}/*.{styl,scss,sass}'
        ],

        ['styles', browserSync.reload]
    );

    gulp.watch(paths.styles.src + 'helpers/{mixins,functions}/*.{styl,scss,sass}', ['styles-helpers']);

    gulp.watch(paths.html.src + '**/*.{html,hbs}', ['handlebars']);

    gulp.watch(basePaths.dest + '**/*.{html,php,json}', ['svg-inline', browserSync.reload]);
});

// Serve project and clean, compile and watch if pass the parameter --compile
gulp.task('default', function () {
    if (args.compile) {
        sequence('clean', ['outdatedbrowser', 'handlebars', 'images', 'bitmap-sprite', 'vetor-sprite', 'styles-helpers', 'vendor-scripts'], 'svg2png', 'svg-inline', 'styles', 'scripts', 'serve');
    } else {
        sequence('handlebars', 'serve');
    }
});

// Clean and compile the project
gulp.task('compile', function () {
    sequence('clean', ['outdatedbrowser', 'handlebars', 'images', 'bitmap-sprite', 'vetor-sprite', 'styles-helpers', 'vendor-scripts'], 'svg2png', 'svg-inline', 'styles', 'scripts');
});

// Build Project and serve if pass the parameter --serve
gulp.task('build', ['clean'], function () {
    env = 'prod';
    sequence(['outdatedbrowser', 'handlebars', 'images', 'bitmap-sprite', 'vetor-sprite', 'styles-helpers', 'vendor-scripts'], 'svg2png', 'svg-inline', 'styles', 'scripts', 'copy', function () { args.serve && browserSync(config.browserSyncBuild) }
    );
});
<|endoftext|>


<commit_before>
var gulp = require('gulp');
var watch = require('gulp-watch');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var compass = require('gulp-compass');
var minifyCss = require('gulp-minify-css');
var traceur = require('gulp-traceur');

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

var watch = {};

;(function(scripts) {
    gulp.task('scripts', function() {
        gulp.src(scripts).
             pipe(gulp.dest('build/assets/js'));
             /*
        gulp.src(scripts).
             pipe(concat('monad.min.js')).
             pipe(uglify()).
             pipe(gulp.dest('build/assets/js'));
        gulp.src(scripts).
             pipe(concat('monad.es5.js')).
             pipe(traceur()).
             pipe(gulp.dest('build/assets/js'));
        gulp.src(scripts).
             pipe(concat('monad.es5.min.js')).
             pipe(traceur()).
             pipe(uglify()).
             pipe(gulp.dest('build/assets/js'));
             */
    });
    watch.scripts = scripts;
})([
    'vendor/angular-translate/angular-translate.js',
    'src/monad.js',
    'src/**/*.js'
]);

;(function(styles) {
    gulp.task('styles-project', function() {
        gulp.src('./src/_sass/project.scss').
             pipe(concat('project.scss')).
             pipe(compass({
                css: 'httpdocs/css',
                sass: 'src/_sass',
                import_path: [
                    'vendor/sensi/sensi/src',
                    'httpdocs/css/formalize/assets/css'
                ]
             })).
             pipe(minifyCss()).
             pipe(gulp.dest('httpdocs/css'));
    });
    watch.project_styles = styles;
})([
    'src/_sass/**/*.scss',
    'vendor/sensi/sensi/src/**/*.scss',
    'httpdocs/css/formalize/assest/css/**/*.scss'
]);

;(function(assets) {
    gulp.task('assets-html', function() {
        gulp.src(assets).
             pipe(gulp.dest('build/assets/html'));
    });
    watch.assets_html = assets;
})(['src/**/*.html']);

gulp.task('watch', function() {
//    gulp.watch(watch['3rdparty'], ['scripts-3rdparty']);
//    gulp.watch(watch.libraries, ['scripts-libraries']);
    gulp.watch(watch.scripts, ['scripts']);
    gulp.watch(watch.assets_html, ['assets-html']);
//    gulp.watch(watch.project_styles, ['styles-project']);
});

<commit_msg>v1 of cleanup<commit_after>
var gulp = require('gulp');
var watch = require('gulp-watch');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var compass = require('gulp-compass');
var traceur = require('gulp-traceur');

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

var watch = {};

;(function(scripts) {
    gulp.task('scripts', function() {
        gulp.src(scripts).
             pipe(gulp.dest('build/assets/js'));
             /*
        gulp.src(scripts).
             pipe(concat('monad.min.js')).
             pipe(uglify()).
             pipe(gulp.dest('build/assets/js'));
        gulp.src(scripts).
             pipe(concat('monad.es5.js')).
             pipe(traceur()).
             pipe(gulp.dest('build/assets/js'));
        gulp.src(scripts).
             pipe(concat('monad.es5.min.js')).
             pipe(traceur()).
             pipe(uglify()).
             pipe(gulp.dest('build/assets/js'));
             */
    });
    watch.scripts = scripts;
})([
    'vendor/angular-translate/angular-translate.js',
    'src/monad.js',
    'src/**/*.js'
]);

;(function(styles) {
    gulp.task('styles-project', function() {
        gulp.src('./src/_sass/project.scss').
             pipe(concat('project.scss')).
             pipe(compass({
                css: 'httpdocs/css',
                sass: 'src/_sass',
                import_path: [
                    'vendor/sensi/sensi/src',
                    'httpdocs/css/formalize/assets/css'
                ]
             })).
             pipe(gulp.dest('httpdocs/css'));
    });
    watch.project_styles = styles;
})([
    'src/_sass/**/*.scss',
    'vendor/sensi/sensi/src/**/*.scss',
    'httpdocs/css/formalize/assest/css/**/*.scss'
]);

;(function(assets) {
    gulp.task('assets-html', function() {
        gulp.src(assets).
             pipe(gulp.dest('build/assets/html'));
    });
    watch.assets_html = assets;
})(['src/**/*.html']);

gulp.task('watch', function() {
//    gulp.watch(watch['3rdparty'], ['scripts-3rdparty']);
//    gulp.watch(watch.libraries, ['scripts-libraries']);
    gulp.watch(watch.scripts, ['scripts']);
    gulp.watch(watch.assets_html, ['assets-html']);
//    gulp.watch(watch.project_styles, ['styles-project']);
});

<|endoftext|>


<commit_before>// Gulp and gulp extensions
var gulp  = require('gulp');
var debug = require('gulp-debug');

// Load envs from .env files
var dotenv = require('dotenv');
dotenv.load({ silent: true });

// Deploying zipped files
gulp.task('deploy', function() {

  // Select bucket
  var yargs  = require('yargs');
  var bucket = process.env[
    "AWS_BUCKET_" + (yargs.argv.production ? "PROD" : "STAGE")
  ];

  // create a new publisher
  var awspublish = require('gulp-awspublish');
  var publisher  = awspublish.create({
    params: {
      Bucket: bucket,
    },
    accessKeyId: process.env.AWS_ACCESS_KEY_ID,
    secretAccessKey: process.env.AWS_SECRET_KEY,
    region: 'sa-east-1',
  });

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

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

  // Replaces for production from .env
  var src = gulp.src("./start.sh");
  if (! yargs.argv.production) {
    // Replacing azk repository
    src = src.pipe(
      replace(/http:\/\/www\.azk\.io\/install\.sh \| bash/,
              "http://www.azk.io/install.sh | bash -s stage")
    );
  }

  return src
    .pipe(debug())
    // publisher will add Content-Length, Content-Type and headers specified above
    // If not specified it will set x-amz-acl to public-read by default
    .pipe(publisher.publish(headers))
    // create a cache file to speed up consecutive uploads
    .pipe(publisher.cache())
    // print upload updates to console
    .pipe(awspublish.reporter());
});

gulp.task('default', ['deploy']);<commit_msg>Improving comments in gulpfile<commit_after>// Gulp and gulp extensions
var gulp  = require('gulp');
var debug = require('gulp-debug');

// Load envs from .env files
var dotenv = require('dotenv');
dotenv.load({ silent: true });

// Deploying zipped files
gulp.task('deploy', function() {

  // Select bucket
  var yargs  = require('yargs');
  var bucket = process.env[
    "AWS_BUCKET_" + (yargs.argv.production ? "PROD" : "STAGE")
  ];

  // create a new publisher
  var awspublish = require('gulp-awspublish');
  var publisher  = awspublish.create({
    params: {
      Bucket: bucket,
    },
    accessKeyId: process.env.AWS_ACCESS_KEY_ID,
    secretAccessKey: process.env.AWS_SECRET_KEY,
    region: 'sa-east-1',
  });

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

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

  // Replaces for production
  var src = gulp.src("./start.sh");
  if (! yargs.argv.production) {
    // Replacing azk repository
    src = src.pipe(
      replace(/http:\/\/www\.azk\.io\/install\.sh \| bash/,
              "http://www.azk.io/install.sh | bash -s stage")
    );
  }

  return src
    .pipe(debug())
    // publisher will add Content-Length, Content-Type and headers specified above
    // If not specified it will set x-amz-acl to public-read by default
    .pipe(publisher.publish(headers))
    // create a cache file to speed up consecutive uploads
    .pipe(publisher.cache())
    // print upload updates to console
    .pipe(awspublish.reporter());
});

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


<commit_before>/*!
* gulpfile
*/

// Load plugins
var gulp         = require('gulp');
var stylus       = require('gulp-stylus');
var rename       = require('gulp-rename');
var jade         = require('gulp-jade');
var inline       = require('gulp-inline-css');

// Paths
var sourcePath   = 'src';
var paths = {
    emails: sourcePath + '/emails/**/*.jade',
    styles: sourcePath + '/themes/**/*.styl'
};

// Styles
gulp.task('styles', function() {
    return gulp.src(paths.styles)
        .pipe(stylus({
            compress: true
        }))
        .pipe(rename({
            suffix: '.min'
        }))
        .pipe(gulp.dest(sourcePath + '/themes'));
});

// Templates
gulp.task('emails', ['styles'], function() {
    return gulp.src(paths.emails)
        .pipe(jade({
            pretty: true
        }))
        .pipe(inline({
            applyStyleTags: false,
            removeStyleTags: false
        }))
        .pipe(gulp.dest('dist'));
});

// Watch
gulp.task('watch', function() {
    gulp.watch(sourcePath + '/**/*.jade', ['emails']);
    gulp.watch(sourcePath + '/themes/**/*.styl', ['emails']);
});

// Default
gulp.task('default', ['watch', 'emails']);
<commit_msg>Add Gulp build task<commit_after>/*!
* gulpfile
*/

// Load plugins
var gulp         = require('gulp');
var stylus       = require('gulp-stylus');
var rename       = require('gulp-rename');
var jade         = require('gulp-jade');
var inline       = require('gulp-inline-css');

// Paths
var sourcePath   = 'src';
var paths = {
    emails: sourcePath + '/emails/**/*.jade',
    styles: sourcePath + '/themes/**/*.styl'
};

// Styles
gulp.task('styles', function() {
    return gulp.src(paths.styles)
        .pipe(stylus({
            compress: true
        }))
        .pipe(rename({
            suffix: '.min'
        }))
        .pipe(gulp.dest(sourcePath + '/themes'));
});

// Templates
gulp.task('emails', ['styles'], function() {
    return gulp.src(paths.emails)
        .pipe(jade({
            pretty: true
        }))
        .pipe(inline({
            applyStyleTags: false,
            removeStyleTags: false
        }))
        .pipe(gulp.dest('dist'));
});

// Watch
gulp.task('watch', function() {
    gulp.watch(sourcePath + '/**/*.jade', ['emails']);
    gulp.watch(sourcePath + '/themes/**/*.styl', ['emails']);
});

// Build
gulp.task('build', ['emails']);

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


<commit_before>/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

'use strict';

var connect = require('gulp-connect');
var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var oghliner = require('oghliner');

gulp.task('browserify', function() {
    return browserify('app/scripts/app.js')
        .bundle()
        //Pass desired output filename to vinyl-source-stream
        .pipe(source('bundle.js'))
        // Start piping stream to tasks!
        .pipe(gulp.dest('app/scripts/'));
});

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

gulp.task('build', ['browserify'], function(callback) {
  return gulp.src('app/**').pipe(gulp.dest('dist'));
});

gulp.task('configure', oghliner.configure);

gulp.task('deploy', function() {
  return oghliner.deploy({
    rootDir: 'dist',
  });
});

gulp.task('offline', ['build'], function() {
  return oghliner.offline({
    rootDir: 'dist/',
    fileGlobs: [
      'images/**',
      'index.html',
      'scripts/**',
      'styles/**',
    ],
  });
});

gulp.task('serve', function () {
  connect.server({
    root: 'dist',
  });
});
<commit_msg>do build as prerequisite for serve<commit_after>/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

'use strict';

var connect = require('gulp-connect');
var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var oghliner = require('oghliner');

gulp.task('browserify', function() {
    return browserify('app/scripts/app.js')
        .bundle()
        //Pass desired output filename to vinyl-source-stream
        .pipe(source('bundle.js'))
        // Start piping stream to tasks!
        .pipe(gulp.dest('app/scripts/'));
});

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

gulp.task('build', ['browserify'], function(callback) {
  return gulp.src('app/**').pipe(gulp.dest('dist'));
});

gulp.task('configure', oghliner.configure);

gulp.task('deploy', function() {
  return oghliner.deploy({
    rootDir: 'dist',
  });
});

gulp.task('offline', ['build'], function() {
  return oghliner.offline({
    rootDir: 'dist/',
    fileGlobs: [
      'images/**',
      'index.html',
      'scripts/**',
      'styles/**',
    ],
  });
});

gulp.task('serve', ['build'], function () {
  connect.server({
    root: 'dist',
  });
});
<|endoftext|>


<commit_before>// configuration
var input = 'pro/static/src/style.css';
var output = 'pro/static/css/';
var autoprefixerOptions = {browsers: ['> 1%', 'IE 7']};
var atImport = require('postcss-import');

var gulp = require('gulp');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer-core');
var nano = require('gulp-cssnano');
var csslint = require('gulp-csslint');
var vhash = require('gulp-vhash');

processors = [
    atImport({path: ['pro/static/sass']}),
    require('autoprefixer-core'),
    require('postcss-nested'),
    autoprefixer(autoprefixerOptions)
];

gulp.task('sass', function () {
    return gulp.src(input)
        .pipe(postcss(processors))
        //.pipe(nano())
        .pipe(gulp.dest(output));
});

gulp.task('hash', function () {
    return gulp.src(
        'pro/static/{css,js}/*.{css,js}'
    )
    .pipe(vhash('pro/templates/**/*.html'));
});

gulp.task('csstest', function () {
    gulp.src('pro/static/css/style.css')
    .pipe(csslint({
        'compatible-vendor-prefixes':false,
        'box-sizing':false,
        'star-property-hack':false,
        'unique-headings':false,
        'qualified-headings':false

    }))
    .pipe(csslint.reporter());
});

gulp.task('default', ['sass', 'csstest', 'hash']);
<commit_msg>sync gulp calls<commit_after>// configuration
var input = 'pro/static/src/style.css';
var output = 'pro/static/css/';
var autoprefixerOptions = {browsers: ['> 1%', 'IE 7']};
var atImport = require('postcss-import');

var gulp = require('gulp');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer-core');
var nano = require('gulp-cssnano');
var csslint = require('gulp-csslint');
var vhash = require('gulp-vhash');

processors = [
    atImport({path: ['pro/static/sass']}),
    require('autoprefixer-core'),
    require('postcss-nested'),
    autoprefixer(autoprefixerOptions)
];

gulp.task('sass', function () {
    return gulp.src(input)
        .pipe(postcss(processors))
        //.pipe(nano())
        .pipe(gulp.dest(output));
});

gulp.task('hash', ['sass'], function () {
    return gulp.src(
        'pro/static/{css,js}/*.{css,js}'
    )
    .pipe(vhash('pro/templates/**/*.html'));
});

gulp.task('csstest', ['sass'], function () {
    gulp.src('pro/static/css/style.css')
    .pipe(csslint({
        'compatible-vendor-prefixes':false,
        'box-sizing':false,
        'star-property-hack':false,
        'unique-headings':false,
        'qualified-headings':false

    }))
    .pipe(csslint.reporter());
});

gulp.task('default', ['sass', 'csstest', 'hash']);
<|endoftext|>