<commit_before>const autoprefixer = require('gulp-autoprefixer');
const awspublish = require('gulp-awspublish');
const cloudfront = require('gulp-cloudfront-invalidate');
const concat = require('gulp-concat');
const cssnano = require('gulp-cssnano');
const fs = require('fs');
const gulp = require('gulp');
const gulpIf = require('gulp-if');
const gulpWebpack = require('webpack-stream');
const header = require('gulp-header');
const htmlmin = require('gulp-htmlmin');
const imagemin = require('gulp-imagemin');
const merge = require('merge-stream');
const os = require('os');
const parallelize = require('concurrent-transform');
const path = require('path');
const process = require('process');
const rename = require('gulp-rename');
const replace = require('gulp-replace');
const resize = require('gulp-image-resize')
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const webpack = require('webpack');

const S3_PATH = '/iuventa/dist/';
const ENV = process.env.ENV || 'dev';
let awsConfig;

try {
  awsConfig = require('./aws.json');
} catch(err) {
  awsConfig = {
    s3: {
      region: process.env.S3_REGION,
      params: {
        Bucket: process.env.S3_PARAMS_BUCKET,
        signatureVersion: process.env.S3_PARAMS_SIGNATUREVERSION,
      },
      accessKeyId: process.env.S3_ACCESSKEYID,
      secretAccessKey: process.env.S3_SECRETACCESSKEY,
    },

    cloudfront: {
      distributionId: process.env.CLOUDFRONT_DISTRIBUTIONID,
    }
  };
}

const cloudfrontConfig = {
  accessKeyId: awsConfig.s3.accessKeyId,
  secretAccessKey: awsConfig.s3.secretAccessKey,
  region: awsConfig.s3.region,
  bucket: awsConfig.s3.bucket,
  distribution: awsConfig.cloudfront.distributionId,
  paths: [
    `/*`,
  ],
};
const IMAGE_SIZES = {
  aside: [ 200, 400, 600, ],
  content: [ 400, 600, 800, 1200, 1400 ],
  full: [ 400, 600, 800, 1200, 1400, 1800, 2000 ],
  max: [ 400, 600, 800, 1200, 1400, 1800, 2000 ],
  'max-half': [ 400, 600, 800, 1200, 1400, 1800, 2000 ],
};

let ASSET_PATH = '/dist/assets';

if (ENV === 'production') {
  ASSET_PATH = 'https://cdn.jib-collective.net/iuventa/dist/assets';
}

gulp.task('markup', () => {
  return gulp.src('markup/**/*.html')
    .pipe(replace(/{{([a-z]+) ([a-z]+=".*")}}/gi, (...args) => {
      const [match, type, rawAttrs, position] = args;
      const attrs = rawAttrs.split(' ').reduce((acc, attr) => {
        const [key, value] = attr.split('=');
        acc[key] = value.replace(/\"/gi, '');
        return acc;
      }, {});

      switch(type) {
        case 'asset':
          const package = require('./package.json');
          const cacheBust = `?version=${package.version}`;

          switch(attrs.type) {
            case 'style':
              return `${ASSET_PATH}/styles/app.css${cacheBust}`;
              break;

            case 'script':
              return `${ASSET_PATH}/scripts/app.js${cacheBust}`;
              break;

            case 'image':
              return `${ASSET_PATH}/images/${attrs.name}${cacheBust}`;
          }
          break;

        case 'video':
          const posterMarkup = attrs.poster ?
            `poster="${ASSET_PATH}/images/${attrs.poster}.jpg"` :
            '';

          return `
            <video preload="none" ${posterMarkup}>
              <source src="${ASSET_PATH}/videos/${attrs.name}.webm"
                      type="video/webm" />

              <source src="${ASSET_PATH}/videos/${attrs.name}.mp4"
                      type="video/mp4" />
            </video>
          `;
          break;

        case 'image':
          const captionFileName = `${name}-${attrs.language}.txt`;
          const captionPath = path.resolve(`./assets/images/${captionFileName}`);
          let caption;

          try {
            caption = fs.readFileSync(captionPath, 'utf-8');
          } catch(err) {
            caption = null;
          };

          const getSourceSet = fileName => {
            const sortedSizes = Array.from(IMAGE_SIZES[attrs.type]).reverse();

            return sortedSizes.map(width => `
              ${ASSET_PATH}/images/${attrs.name}-${width}.jpg ${width}w
            `).join(', ');
          };

          const captionMarkup = caption ? `

              ${caption}

          ` : '';

          return `

              ${captionMarkup}

          `;
          break;
      }

      return '';
    }))
    .pipe(gulpIf(ENV === 'production', htmlmin()))
    .pipe(gulp.dest('dist/markup/'));
});

gulp.task('images', () => {
  const flatten = list => list;

  const imageStream = merge();
  const defaults = {
    crop : false,
    imageMagick: true,
    upscale : true,
  };
  const allImageSizes =
    Object.keys(IMAGE_SIZES)
      .map(type => IMAGE_SIZES[type])
      // flatten
      .reduce(
        (a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []
      )
      // unique
      .filter((elem, pos, arr) => {
        return arr.indexOf(elem) == pos;
      });

  console.log('Debug: collected image sizes:', allImageSizes);

  allImageSizes.forEach(width => {
    const options = Object.assign({}, defaults, { width });
    const stream = gulp.src('assets/images/*.jpg')
        .pipe(parallelize(
          resize(options),
          os.cpus().length
        ))
        .pipe(parallelize(
          imagemin([
            imagemin.jpegtran({
              progressive: true,
            }),
          ], {
            verbose: false,
          }),
          os.cpus().length
        ))
        .pipe(rename(path => {
          path.basename += `-${width}`;
        }));

    imageStream.add(stream);
  });

  const socialMedia = gulp.src('assets/images/social-media/**/*.jpg')
                        .pipe(gulp.dest('dist/assets/images/social-media/'));

  imageStream.pipe(gulp.dest('dist/assets/images'))

  return merge(imageStream, socialMedia);
});

gulp.task('scripts', () => {
  return gulp.src('assets/scripts/app.js')
    .pipe(gulpWebpack(require(`./webpack-config.${ENV}`), webpack))
    .pipe(gulp.dest('dist/assets/scripts/'));
});

gulp.task('fonts', () => {
  return gulp.src('assets/fonts/**/*')
    .pipe(gulp.dest('dist/assets/fonts/'));
});

gulp.task('styles', () => {
  return gulp.src('assets/styles/app.scss')
      .pipe(header(`
          $font-path: "${ASSET_PATH}/fonts/";
      `))
      .pipe(sass().on('error', sass.logError))
      .pipe(gulpIf(ENV !== 'production', sourcemaps.init()))
      .pipe(concat('app.css'))
      .pipe(autoprefixer({
          browsers: [
            'Android >= 4.4',
            'last 2 versions',
            'last 4 iOS versions',
          ],
      }))
      .pipe(gulpIf(ENV === 'production', cssnano()))
      .pipe(gulpIf(ENV !== 'production', sourcemaps.write()))
      .pipe(gulp.dest('dist/assets/styles/'));
});

gulp.task('upload', ['build', ], () => {
  let publisher = awspublish.create(awsConfig.s3);
  const cacheTime = (60 * 60 * 24) * 14; // 14 days
  const awsHeaders = {
    'Cache-Control': `public, max-age=${cacheTime}, s-maxage=${cacheTime}`,
  };
  const gzippable = function(file) {
    const match = file.path.match(/\.(html|css|js|ttf|otf)$/gi);
    return match;
  };

  return gulp.src([
    './dist/**/**/*',
  ])
    .pipe(rename((path) => {
        path.dirname = `${S3_PATH}${path.dirname}`;
        return path;
    }))
    .pipe(gulpIf(gzippable, awspublish.gzip()))
    .pipe(publisher.cache())
    .pipe(parallelize(publisher.publish(awsHeaders), 10))
    .pipe(awspublish.reporter())
    .pipe(cloudfront(cloudfrontConfig));
});

gulp.task('watch', ['build',], () => {
  gulp.watch('assets/styles/**/*', ['styles']);
  gulp.watch('assets/scripts/**/*', ['scripts']);
  gulp.watch('assets/images/*.jpg', ['images']);
  gulp.watch([
    'markup/**/*.html',
    'assets/images/**/*.txt',
  ], ['markup']);
});

gulp.task('build', [
  'fonts',
  'markup',
  'images',
  'styles',
  'scripts',
]);
<commit_msg>Fix invalid variable<commit_after>const autoprefixer = require('gulp-autoprefixer');
const awspublish = require('gulp-awspublish');
const cloudfront = require('gulp-cloudfront-invalidate');
const concat = require('gulp-concat');
const cssnano = require('gulp-cssnano');
const fs = require('fs');
const gulp = require('gulp');
const gulpIf = require('gulp-if');
const gulpWebpack = require('webpack-stream');
const header = require('gulp-header');
const htmlmin = require('gulp-htmlmin');
const imagemin = require('gulp-imagemin');
const merge = require('merge-stream');
const os = require('os');
const parallelize = require('concurrent-transform');
const path = require('path');
const process = require('process');
const rename = require('gulp-rename');
const replace = require('gulp-replace');
const resize = require('gulp-image-resize')
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const webpack = require('webpack');

const S3_PATH = '/iuventa/dist/';
const ENV = process.env.ENV || 'dev';
let awsConfig;

try {
  awsConfig = require('./aws.json');
} catch(err) {
  awsConfig = {
    s3: {
      region: process.env.S3_REGION,
      params: {
        Bucket: process.env.S3_PARAMS_BUCKET,
        signatureVersion: process.env.S3_PARAMS_SIGNATUREVERSION,
      },
      accessKeyId: process.env.S3_ACCESSKEYID,
      secretAccessKey: process.env.S3_SECRETACCESSKEY,
    },

    cloudfront: {
      distributionId: process.env.CLOUDFRONT_DISTRIBUTIONID,
    }
  };
}

const cloudfrontConfig = {
  accessKeyId: awsConfig.s3.accessKeyId,
  secretAccessKey: awsConfig.s3.secretAccessKey,
  region: awsConfig.s3.region,
  bucket: awsConfig.s3.bucket,
  distribution: awsConfig.cloudfront.distributionId,
  paths: [
    `/*`,
  ],
};
const IMAGE_SIZES = {
  aside: [ 200, 400, 600, ],
  content: [ 400, 600, 800, 1200, 1400 ],
  full: [ 400, 600, 800, 1200, 1400, 1800, 2000 ],
  max: [ 400, 600, 800, 1200, 1400, 1800, 2000 ],
  'max-half': [ 400, 600, 800, 1200, 1400, 1800, 2000 ],
};

let ASSET_PATH = '/dist/assets';

if (ENV === 'production') {
  ASSET_PATH = 'https://cdn.jib-collective.net/iuventa/dist/assets';
}

gulp.task('markup', () => {
  return gulp.src('markup/**/*.html')
    .pipe(replace(/{{([a-z]+) ([a-z]+=".*")}}/gi, (...args) => {
      const [match, type, rawAttrs, position] = args;
      const attrs = rawAttrs.split(' ').reduce((acc, attr) => {
        const [key, value] = attr.split('=');
        acc[key] = value.replace(/\"/gi, '');
        return acc;
      }, {});

      switch(type) {
        case 'asset':
          const package = require('./package.json');
          const cacheBust = `?version=${package.version}`;

          switch(attrs.type) {
            case 'style':
              return `${ASSET_PATH}/styles/app.css${cacheBust}`;
              break;

            case 'script':
              return `${ASSET_PATH}/scripts/app.js${cacheBust}`;
              break;

            case 'image':
              return `${ASSET_PATH}/images/${attrs.name}${cacheBust}`;
          }
          break;

        case 'video':
          const posterMarkup = attrs.poster ?
            `poster="${ASSET_PATH}/images/${attrs.poster}.jpg"` :
            '';

          return `
            <video preload="none" ${posterMarkup}>
              <source src="${ASSET_PATH}/videos/${attrs.name}.webm"
                      type="video/webm" />

              <source src="${ASSET_PATH}/videos/${attrs.name}.mp4"
                      type="video/mp4" />
            </video>
          `;
          break;

        case 'image':
          const captionFileName = `${attrs.name}-${attrs.language}.txt`;
          const captionPath = path.resolve(`./assets/images/${captionFileName}`);
          let caption;

          try {
            caption = fs.readFileSync(captionPath, 'utf-8');
          } catch(err) {
            caption = null;
          };

          const getSourceSet = fileName => {
            const sortedSizes = Array.from(IMAGE_SIZES[attrs.type]).reverse();

            return sortedSizes.map(width => `
              ${ASSET_PATH}/images/${attrs.name}-${width}.jpg ${width}w
            `).join(', ');
          };

          const captionMarkup = caption ? `

              ${caption}

          ` : '';

          return `

              ${captionMarkup}

          `;
          break;
      }

      return '';
    }))
    .pipe(gulpIf(ENV === 'production', htmlmin()))
    .pipe(gulp.dest('dist/markup/'));
});

gulp.task('images', () => {
  const flatten = list => list;

  const imageStream = merge();
  const defaults = {
    crop : false,
    imageMagick: true,
    upscale : true,
  };
  const allImageSizes =
    Object.keys(IMAGE_SIZES)
      .map(type => IMAGE_SIZES[type])
      // flatten
      .reduce(
        (a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []
      )
      // unique
      .filter((elem, pos, arr) => {
        return arr.indexOf(elem) == pos;
      });

  console.log('Debug: collected image sizes:', allImageSizes);

  allImageSizes.forEach(width => {
    const options = Object.assign({}, defaults, { width });
    const stream = gulp.src('assets/images/*.jpg')
        .pipe(parallelize(
          resize(options),
          os.cpus().length
        ))
        .pipe(parallelize(
          imagemin([
            imagemin.jpegtran({
              progressive: true,
            }),
          ], {
            verbose: false,
          }),
          os.cpus().length
        ))
        .pipe(rename(path => {
          path.basename += `-${width}`;
        }));

    imageStream.add(stream);
  });

  const socialMedia = gulp.src('assets/images/social-media/**/*.jpg')
                        .pipe(gulp.dest('dist/assets/images/social-media/'));

  imageStream.pipe(gulp.dest('dist/assets/images'))

  return merge(imageStream, socialMedia);
});

gulp.task('scripts', () => {
  return gulp.src('assets/scripts/app.js')
    .pipe(gulpWebpack(require(`./webpack-config.${ENV}`), webpack))
    .pipe(gulp.dest('dist/assets/scripts/'));
});

gulp.task('fonts', () => {
  return gulp.src('assets/fonts/**/*')
    .pipe(gulp.dest('dist/assets/fonts/'));
});

gulp.task('styles', () => {
  return gulp.src('assets/styles/app.scss')
      .pipe(header(`
          $font-path: "${ASSET_PATH}/fonts/";
      `))
      .pipe(sass().on('error', sass.logError))
      .pipe(gulpIf(ENV !== 'production', sourcemaps.init()))
      .pipe(concat('app.css'))
      .pipe(autoprefixer({
          browsers: [
            'Android >= 4.4',
            'last 2 versions',
            'last 4 iOS versions',
          ],
      }))
      .pipe(gulpIf(ENV === 'production', cssnano()))
      .pipe(gulpIf(ENV !== 'production', sourcemaps.write()))
      .pipe(gulp.dest('dist/assets/styles/'));
});

gulp.task('upload', ['build', ], () => {
  let publisher = awspublish.create(awsConfig.s3);
  const cacheTime = (60 * 60 * 24) * 14; // 14 days
  const awsHeaders = {
    'Cache-Control': `public, max-age=${cacheTime}, s-maxage=${cacheTime}`,
  };
  const gzippable = function(file) {
    const match = file.path.match(/\.(html|css|js|ttf|otf)$/gi);
    return match;
  };

  return gulp.src([
    './dist/**/**/*',
  ])
    .pipe(rename((path) => {
        path.dirname = `${S3_PATH}${path.dirname}`;
        return path;
    }))
    .pipe(gulpIf(gzippable, awspublish.gzip()))
    .pipe(publisher.cache())
    .pipe(parallelize(publisher.publish(awsHeaders), 10))
    .pipe(awspublish.reporter())
    .pipe(cloudfront(cloudfrontConfig));
});

gulp.task('watch', ['build',], () => {
  gulp.watch('assets/styles/**/*', ['styles']);
  gulp.watch('assets/scripts/**/*', ['scripts']);
  gulp.watch('assets/images/*.jpg', ['images']);
  gulp.watch([
    'markup/**/*.html',
    'assets/images/**/*.txt',
  ], ['markup']);
});

gulp.task('build', [
  'fonts',
  'markup',
  'images',
  'styles',
  'scripts',
]);
<|endoftext|>


<commit_before>var gulp         = require('gulp'),
    rimraf       = require('gulp-rimraf'),
    server       = require('gulp-develop-server'),
    frontMatter  = require('gulp-front-matter'),
    path         = require('path')
    through      = require('through2')
    fs           = require('fs')
    autoprefixer = require('gulp-autoprefixer'),
    sass         = require('gulp-ruby-sass'),
    uglify       = require('gulp-uglify'),
    concat       = require('gulp-concat');

// Clean build directory
gulp.task('clean', function(cb) {
  return gulp.src(['./dist', './build'])
    .pipe(rimraf())
  ;
});

// Copy static files (but not the Angular templates, Sass, or JS)
gulp.task('copy', ['clean'], function() {
  var dirs = [
    './client/**/*.*',
    '!./client/templates/**/*.*',
    '!./client/assets/{scss,js}/**/*.*'
  ];
  return gulp.src(dirs, {
    base: './client/'
  })
    .pipe(gulp.dest('build'));
});

gulp.task('copy-partials', ['clean', 'copy'], function() {
  return gulp.src(['js/angular/partials/**.*'])
    .pipe(gulp.dest('build/partials'));
});

// Compile Sass
gulp.task('sass', ['clean', 'copy'], function() {
  return gulp.src('client/assets/scss/app.scss')
    .pipe(sass({ loadPath: ['client/asets/scss', 'scss'], style: 'expanded', lineNumbers: true  }))
    .pipe(concat('app.css'))
    .pipe(autoprefixer({
      browsers: ['last 2 versions', 'ie 10']
    }))
    .pipe(gulp.dest('./build/assets/css/'))
  ;
});

// Process Foundation JS
gulp.task('uglify', ['copy', 'clean'], function() {
  var libs = [
    'bower_components/jquery/dist/jquery.js',
    'bower_components/fastclick/lib/fastclick.js',
    'bower_components/viewport-units-buggyfill/viewport-units-buggyfill.js',
    'bower_components/notify.js/notify.js',
    'bower_components/tether/tether.js',
    'js/foundation/**/*.js',
    'client/assets/js/app.js'
  ];

  return gulp.src(libs)
    .pipe(uglify({
      beautify: true,
      mangle: false
    }).on('error', function(e) {
      console.log(e);
    }))
    .pipe(concat('app.js'))
    .pipe(gulp.dest('./build/assets/js/'))
  ;
});

// Process Angular JS
gulp.task('uglify-angular', ['copy', 'clean'], function() {
  var libs = [
    'bower_components/angular/angular.js',
    'bower_components/angular-animate/angular-animate.js',
    'bower_components/ui-router/release/angular-ui-router.js',
    'js/angular/**/*.js',
  ];

  return gulp.src(libs)
    .pipe(uglify({
      beautify: true,
      mangle: false
    }))
    .pipe(concat('angular-app.js'))
    .pipe(gulp.dest('./build/assets/js/'))
  ;

});

gulp.task('front-matter', ['clean', 'copy', 'uglify-angular'], function() {
  var config = [];

  return gulp.src('./client/templates/**/*.html')
    .pipe(frontMatter({
      property: 'meta',
      remove: true
    }))
    .pipe(through.obj(function(file, enc, callback) {
      if(file.meta.name) {
        var page = file.meta;

        //path normalizing
        var relativePath = path.relative(__dirname + path.sep + 'client', file.path);
        page.path = relativePath.split(path.sep).join('/');

        config.push(page);
      }
      this.push(file);
      return callback();
    }))
    .pipe(gulp.dest('build/templates'))
    .on('end', function() {
      //routes
      var appPath = ['build', 'assets', 'js', 'angular-app.js'];
      var data = fs.readFileSync(appPath.join(path.sep));
      fs.writeFileSync(appPath.join(path.sep), 'var dynamicRoutes = ' + JSON.stringify(config) + '; \n' + data);
    })
  ;
});

gulp.task('server:start', ['build'], function() {
  server.listen( { path: 'app.js' });
});

gulp.task('build', ['clean', 'copy', 'copy-partials', 'uglify','uglify-angular', 'front-matter'], function() {
  console.log('Successfully built');
});

gulp.task('css', ['build', 'sass'], function() {
  console.log('CSS Recompiled');
});

gulp.task('default', ['build', 'css', 'server:start'], function() {
  return gulp.watch(['./client/**/*.*', './js/**/*.*'], ['build', 'css', server.restart]);
});
<commit_msg>Corrected gulp path solving issue #30<commit_after>var gulp         = require('gulp'),
    rimraf       = require('gulp-rimraf'),
    server       = require('gulp-develop-server'),
    frontMatter  = require('gulp-front-matter'),
    path         = require('path')
    through      = require('through2')
    fs           = require('fs')
    autoprefixer = require('gulp-autoprefixer'),
    sass         = require('gulp-ruby-sass'),
    uglify       = require('gulp-uglify'),
    concat       = require('gulp-concat');

// Clean build directory
gulp.task('clean', function(cb) {
  return gulp.src(['./dist', './build'])
    .pipe(rimraf())
  ;
});

// Copy static files (but not the Angular templates, Sass, or JS)
gulp.task('copy', ['clean'], function() {
  var dirs = [
    './client/**/*.*',
    '!./client/templates/**/*.*',
    '!./client/assets/{scss,js}/**/*.*'
  ];
  return gulp.src(dirs, {
    base: './client/'
  })
    .pipe(gulp.dest('build'));
});

gulp.task('copy-partials', ['clean', 'copy'], function() {
  return gulp.src(['js/angular/partials/**.*'])
    .pipe(gulp.dest('build/partials'));
});

// Compile Sass
gulp.task('sass', ['clean', 'copy'], function() {
  return gulp.src('client/assets/scss/app.scss')
    .pipe(sass({ loadPath: ['client/assets/scss', 'scss'], style: 'expanded', lineNumbers: true  }))
    .pipe(concat('app.css'))
    .pipe(autoprefixer({
      browsers: ['last 2 versions', 'ie 10']
    }))
    .pipe(gulp.dest('./build/assets/css/'))
  ;
});

// Process Foundation JS
gulp.task('uglify', ['copy', 'clean'], function() {
  var libs = [
    'bower_components/jquery/dist/jquery.js',
    'bower_components/fastclick/lib/fastclick.js',
    'bower_components/viewport-units-buggyfill/viewport-units-buggyfill.js',
    'bower_components/notify.js/notify.js',
    'bower_components/tether/tether.js',
    'js/foundation/**/*.js',
    'client/assets/js/app.js'
  ];

  return gulp.src(libs)
    .pipe(uglify({
      beautify: true,
      mangle: false
    }).on('error', function(e) {
      console.log(e);
    }))
    .pipe(concat('app.js'))
    .pipe(gulp.dest('./build/assets/js/'))
  ;
});

// Process Angular JS
gulp.task('uglify-angular', ['copy', 'clean'], function() {
  var libs = [
    'bower_components/angular/angular.js',
    'bower_components/angular-animate/angular-animate.js',
    'bower_components/ui-router/release/angular-ui-router.js',
    'js/angular/**/*.js',
  ];

  return gulp.src(libs)
    .pipe(uglify({
      beautify: true,
      mangle: false
    }))
    .pipe(concat('angular-app.js'))
    .pipe(gulp.dest('./build/assets/js/'))
  ;

});

gulp.task('front-matter', ['clean', 'copy', 'uglify-angular'], function() {
  var config = [];

  return gulp.src('./client/templates/**/*.html')
    .pipe(frontMatter({
      property: 'meta',
      remove: true
    }))
    .pipe(through.obj(function(file, enc, callback) {
      if(file.meta.name) {
        var page = file.meta;

        //path normalizing
        var relativePath = path.relative(__dirname + path.sep + 'client', file.path);
        page.path = relativePath.split(path.sep).join('/');

        config.push(page);
      }
      this.push(file);
      return callback();
    }))
    .pipe(gulp.dest('build/templates'))
    .on('end', function() {
      //routes
      var appPath = ['build', 'assets', 'js', 'angular-app.js'];
      var data = fs.readFileSync(appPath.join(path.sep));
      fs.writeFileSync(appPath.join(path.sep), 'var dynamicRoutes = ' + JSON.stringify(config) + '; \n' + data);
    })
  ;
});

gulp.task('server:start', ['build'], function() {
  server.listen( { path: 'app.js' });
});

gulp.task('build', ['clean', 'copy', 'copy-partials', 'uglify','uglify-angular', 'front-matter'], function() {
  console.log('Successfully built');
});

gulp.task('css', ['build', 'sass'], function() {
  console.log('CSS Recompiled');
});

gulp.task('default', ['build', 'css', 'server:start'], function() {
  return gulp.watch(['./client/**/*.*', './js/**/*.*'], ['build', 'css', server.restart]);
});
<|endoftext|>


<commit_before>/* -------------------------------------------------------------------------------------------------

Build Configuration
Contributors: Luan Gjokaj

-------------------------------------------------------------------------------------------------- */
const { gulp, series, parallel, dest, src, watch } = require('gulp');
const babel = require('gulp-babel');
const browserSync = require('browser-sync').create();
const concat = require('gulp-concat');
const cssnano = require('cssnano');
const del = require('del');
const fileinclude = require('gulp-file-include');
const gutil = require('gulp-util');
const htmlmin = require('gulp-htmlmin');
const imagemin = require('gulp-imagemin');
const modRewrite = require('connect-modrewrite');
const plumber = require('gulp-plumber');
const postcss = require('gulp-postcss');
const postcssImport = require('postcss-import');
const postCSSMixins = require('postcss-mixins');
const postcssPresetEnv = require('postcss-preset-env');
const RevAll = require("gulp-rev-all");
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');

//--------------------------------------------------------------------------------------------------
/* -------------------------------------------------------------------------------------------------
PostCSS Plugins
-------------------------------------------------------------------------------------------------- */
const pluginsDev = [
	postcssImport,
	postCSSMixins,
	postcssPresetEnv({
		stage: 0,
		features: {
			'nesting-rules': true,
			'color-mod-function': true,
			'custom-media': true,
		},
	}),
];
const pluginsProd = [
	postcssImport,
	postCSSMixins,
	postcssPresetEnv({
		stage: 0,
		features: {
			'nesting-rules': true,
			'color-mod-function': true,
			'custom-media': true,
		},
	}),
	require('cssnano')({
		preset: [
			'default',
			{
				discardComments: true,
			},
		],
	}),
];

//--------------------------------------------------------------------------------------------------
/* -------------------------------------------------------------------------------------------------
Header & Footer JavaScript Boundles
-------------------------------------------------------------------------------------------------- */
const headerJS = [
	'./src/etc/analytics.js',
	'./node_modules/aos/dist/aos.js'
];
const footerJS = [
	'./node_modules/webfontloader/webfontloader.js',
	'./node_modules/jquery/dist/jquery.js',
	'./src/assets/js/**'
];

//--------------------------------------------------------------------------------------------------
/* -------------------------------------------------------------------------------------------------
Development Tasks
-------------------------------------------------------------------------------------------------- */
function devServer() {
	browserSync.init({
			logPrefix: 'Static Web Build',
			server: {
			baseDir: './build',
		},
		middleware: [modRewrite(['^.([^\\.]+)$ /$1.html [L]'])],
	});

	watch('./src/assets/css/**/*.css', stylesDev);
	watch('./src/assets/js/**', series(footerScriptsDev, Reload));
	watch('./src/assets/img/**', series(copyImagesDev, Reload));
	watch('./src/assets/fonts/**', series(copyFontsDev, Reload));
	watch('./src/**/*.html', series(staticFilesDev, Reload));
};

function Reload(done) {
	browserSync.reload();
	done();
}

function copyImagesDev() {
	return src('./src/assets/img/**').pipe(
		dest('./build/assets/img'),
	);
}

function copyFontsDev() {
	return src('./src/assets/fonts/**').pipe(
		dest('./build/assets/fonts'),
	);
}

function stylesDev() {
	return src('./src/assets/css/styles.css')
		.pipe(plumber({ errorHandler: onError }))
		.pipe(sourcemaps.init())
		.pipe(postcss(pluginsDev))
		.pipe(sourcemaps.write('.'))
		.pipe(dest('./build/assets/css'))
		.pipe(browserSync.stream({ match: '**/*.css' }));
}

function headerScriptsDev() {
	return src(headerJS)
		.pipe(plumber({ errorHandler: onError }))
		.pipe(sourcemaps.init())
		.pipe(concat('header-bundle.js'))
		.pipe(sourcemaps.write('.'))
		.pipe(dest('./build/assets/js'));
}

function footerScriptsDev() {
	return src(footerJS)
		.pipe(plumber({ errorHandler: onError }))
		.pipe(sourcemaps.init())
		.pipe(
			babel({
				presets: ['@babel/preset-env'],
			}),
		)
		.pipe(concat('footer-bundle.js'))
		.pipe(sourcemaps.write('.'))
		.pipe(dest('./build/assets/js'));
}

function staticFilesDev() {
	return src('./src/*.html')
		.pipe(plumber({ errorHandler: onError }))
		.pipe(
			fileinclude({
				filters: {
					prefix: '@@',
					basepath: '@file',
				},
			}),
		)
		.pipe(dest('./build'));
}

exports.dev = series(
	copyImagesDev,
	copyFontsDev,
	stylesDev,
	headerScriptsDev,
	footerScriptsDev,
	staticFilesDev,
	devServer,
);

/* -------------------------------------------------------------------------------------------------
Production Tasks
-------------------------------------------------------------------------------------------------- */
async function cleanProd() {
	await del(['./dist']);
}

function copyFontsProd() {
	return src('./src/assets/fonts/**').pipe(
		dest('./dist/assets/fonts'),
	);
}

function stylesProd() {
	return src('./src/assets/css/styles.css')
		.pipe(plumber({ errorHandler: onError }))
		.pipe(postcss(pluginsProd))
		.pipe(dest('./dist/assets/css'));
}

function headerScriptsProd() {
	return src(headerJS)
		.pipe(plumber({ errorHandler: onError }))
		.pipe(concat('header-bundle.js'))
		.pipe(uglify())
		.pipe(dest('./dist/assets/js'));
}

function footerScriptsProd() {
	return src(footerJS)
		.pipe(plumber({ errorHandler: onError }))
		.pipe(
			babel({
				presets: ['@babel/preset-env'],
			}),
		)
		.pipe(concat('footer-bundle.js'))
		.pipe(uglify())
		.pipe(dest('./dist/assets/js'));
}

function staticFilesProd() {
	return src('./src/*.html')
		.pipe(plumber({ errorHandler: onError }))
		.pipe(
			fileinclude({
				filters: {
					prefix: '@@',
					basepath: '@file',
				},
			}),
		)
		.pipe(
			htmlmin({
				collapseWhitespace: true,
				ignoreCustomFragments: [/<%[\s\S]*?%>/, /<\?[=|php]?[\s\S]*?\?>/],
			}),
		)
		.pipe(dest('./dist'));
}

function processImages() {
	return src(['./src/assets/img/**', '!./src/assets/img/**/*.ico'])
		.pipe(plumber({ errorHandler: onError }))
		.pipe(
			imagemin([imagemin.svgo({ plugins: [{ removeViewBox: true }] })], {
				verbose: true,
			}),
		)
		.pipe(dest('./dist/assets/img'))
		.on('end', () => {
			gutil.beep();
			gutil.log(filesGenerated);
			gutil.log(thankYou);
		});
}

function bustCaches() {
	return src(['./dist/**'])
	.pipe(RevAll.revision({ dontRenameFile: [/^\/favicon.ico$/g, ".html"] }))
	.pipe(dest('./dist'))
}

exports.prod = series(
	cleanProd,
	copyFontsProd,
	stylesProd,
	headerScriptsProd,
	footerScriptsProd,
	staticFilesProd,
	processImages,
	bustCaches,
);

/* -------------------------------------------------------------------------------------------------
Utility Tasks
-------------------------------------------------------------------------------------------------- */
const onError = err => {
	gutil.beep();
	gutil.log(staticBuild + ' - ' + errorMsg + ' ' + err.toString());
	this.emit('end');
};

/* -------------------------------------------------------------------------------------------------
Messages
-------------------------------------------------------------------------------------------------- */
const errorMsg = '\x1b[41mError\x1b[0m';
const filesGenerated =
	'Your production file are generated in: \x1b[1m' +
	__dirname +
	'/dist/ ✅';

const staticBuild = '\x1b[42m\x1b[1mStaticWebBuild\x1b[0m';
const staticBuildUrl = '\x1b[2m - https://staticbuild.website/\x1b[0m';
const thankYou = 'Thank you for using ' + staticBuild + staticBuildUrl;

/* -------------------------------------------------------------------------------------------------
End of all Tasks
-------------------------------------------------------------------------------------------------- */
<commit_msg>👌 IMPROVE: Image processing<commit_after>/* -------------------------------------------------------------------------------------------------

Build Configuration
Contributors: Luan Gjokaj

-------------------------------------------------------------------------------------------------- */
const { gulp, series, parallel, dest, src, watch } = require('gulp');
const babel = require('gulp-babel');
const browserSync = require('browser-sync').create();
const concat = require('gulp-concat');
const cssnano = require('cssnano');
const del = require('del');
const fileinclude = require('gulp-file-include');
const gutil = require('gulp-util');
const htmlmin = require('gulp-htmlmin');
const imagemin = require('gulp-imagemin');
const modRewrite = require('connect-modrewrite');
const plumber = require('gulp-plumber');
const postcss = require('gulp-postcss');
const postcssImport = require('postcss-import');
const postCSSMixins = require('postcss-mixins');
const postcssPresetEnv = require('postcss-preset-env');
const RevAll = require("gulp-rev-all");
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');

//--------------------------------------------------------------------------------------------------
/* -------------------------------------------------------------------------------------------------
PostCSS Plugins
-------------------------------------------------------------------------------------------------- */
const pluginsDev = [
	postcssImport,
	postCSSMixins,
	postcssPresetEnv({
		stage: 0,
		features: {
			'nesting-rules': true,
			'color-mod-function': true,
			'custom-media': true,
		},
	}),
];
const pluginsProd = [
	postcssImport,
	postCSSMixins,
	postcssPresetEnv({
		stage: 0,
		features: {
			'nesting-rules': true,
			'color-mod-function': true,
			'custom-media': true,
		},
	}),
	require('cssnano')({
		preset: [
			'default',
			{
				discardComments: true,
			},
		],
	}),
];

//--------------------------------------------------------------------------------------------------
/* -------------------------------------------------------------------------------------------------
Header & Footer JavaScript Boundles
-------------------------------------------------------------------------------------------------- */
const headerJS = [
	'./src/etc/analytics.js',
	'./node_modules/aos/dist/aos.js'
];
const footerJS = [
	'./node_modules/webfontloader/webfontloader.js',
	'./node_modules/jquery/dist/jquery.js',
	'./src/assets/js/**'
];

//--------------------------------------------------------------------------------------------------
/* -------------------------------------------------------------------------------------------------
Development Tasks
-------------------------------------------------------------------------------------------------- */
function devServer() {
	browserSync.init({
			logPrefix: 'Static Web Build',
			server: {
			baseDir: './build',
		},
		middleware: [modRewrite(['^.([^\\.]+)$ /$1.html [L]'])],
	});

	watch('./src/assets/css/**/*.css', stylesDev);
	watch('./src/assets/js/**', series(footerScriptsDev, Reload));
	watch('./src/assets/img/**', series(copyImagesDev, Reload));
	watch('./src/assets/fonts/**', series(copyFontsDev, Reload));
	watch('./src/**/*.html', series(staticFilesDev, Reload));
};

function Reload(done) {
	browserSync.reload();
	done();
}

function copyImagesDev() {
	return src('./src/assets/img/**').pipe(
		dest('./build/assets/img'),
	);
}

function copyFontsDev() {
	return src('./src/assets/fonts/**').pipe(
		dest('./build/assets/fonts'),
	);
}

function stylesDev() {
	return src('./src/assets/css/styles.css')
		.pipe(plumber({ errorHandler: onError }))
		.pipe(sourcemaps.init())
		.pipe(postcss(pluginsDev))
		.pipe(sourcemaps.write('.'))
		.pipe(dest('./build/assets/css'))
		.pipe(browserSync.stream({ match: '**/*.css' }));
}

function headerScriptsDev() {
	return src(headerJS)
		.pipe(plumber({ errorHandler: onError }))
		.pipe(sourcemaps.init())
		.pipe(concat('header-bundle.js'))
		.pipe(sourcemaps.write('.'))
		.pipe(dest('./build/assets/js'));
}

function footerScriptsDev() {
	return src(footerJS)
		.pipe(plumber({ errorHandler: onError }))
		.pipe(sourcemaps.init())
		.pipe(
			babel({
				presets: ['@babel/preset-env'],
			}),
		)
		.pipe(concat('footer-bundle.js'))
		.pipe(sourcemaps.write('.'))
		.pipe(dest('./build/assets/js'));
}

function staticFilesDev() {
	return src('./src/*.html')
		.pipe(plumber({ errorHandler: onError }))
		.pipe(
			fileinclude({
				filters: {
					prefix: '@@',
					basepath: '@file',
				},
			}),
		)
		.pipe(dest('./build'));
}

exports.dev = series(
	copyImagesDev,
	copyFontsDev,
	stylesDev,
	headerScriptsDev,
	footerScriptsDev,
	staticFilesDev,
	devServer,
);

/* -------------------------------------------------------------------------------------------------
Production Tasks
-------------------------------------------------------------------------------------------------- */
async function cleanProd() {
	await del(['./dist']);
}

function copyFontsProd() {
	return src('./src/assets/fonts/**').pipe(
		dest('./dist/assets/fonts'),
	);
}

function stylesProd() {
	return src('./src/assets/css/styles.css')
		.pipe(plumber({ errorHandler: onError }))
		.pipe(postcss(pluginsProd))
		.pipe(dest('./dist/assets/css'));
}

function headerScriptsProd() {
	return src(headerJS)
		.pipe(plumber({ errorHandler: onError }))
		.pipe(concat('header-bundle.js'))
		.pipe(uglify())
		.pipe(dest('./dist/assets/js'));
}

function footerScriptsProd() {
	return src(footerJS)
		.pipe(plumber({ errorHandler: onError }))
		.pipe(
			babel({
				presets: ['@babel/preset-env'],
			}),
		)
		.pipe(concat('footer-bundle.js'))
		.pipe(uglify())
		.pipe(dest('./dist/assets/js'));
}

function staticFilesProd() {
	return src('./src/*.html')
		.pipe(plumber({ errorHandler: onError }))
		.pipe(
			fileinclude({
				filters: {
					prefix: '@@',
					basepath: '@file',
				},
			}),
		)
		.pipe(
			htmlmin({
				collapseWhitespace: true,
				ignoreCustomFragments: [/<%[\s\S]*?%>/, /<\?[=|php]?[\s\S]*?\?>/],
			}),
		)
		.pipe(dest('./dist'));
}

function copyImagesProd() {
	return src('./src/assets/img/**').pipe(
		dest('./dist/assets/img'),
	);
}

function processImages() {
	return src(['./dist/assets/img/**', '!./dist/assets/img/**/*.ico'])
		.pipe(plumber({ errorHandler: onError }))
		.pipe(
			imagemin([imagemin.svgo({ plugins: [{ removeViewBox: true }] })], {
				verbose: true,
			}),
		)
		.pipe(dest('./dist/assets/img'))
		.on('end', () => {
			gutil.beep();
			gutil.log(filesGenerated);
			gutil.log(thankYou);
		});
}

function bustCaches() {
	return src(['./dist/**'])
	.pipe(RevAll.revision({ dontRenameFile: [/^\/favicon.ico$/g, ".html"] }))
	.pipe(dest('./dist'))
}

exports.prod = series(
	cleanProd,
	copyFontsProd,
	stylesProd,
	headerScriptsProd,
	footerScriptsProd,
	staticFilesProd,
	copyImagesProd,
	processImages,
	bustCaches,
);

/* -------------------------------------------------------------------------------------------------
Utility Tasks
-------------------------------------------------------------------------------------------------- */
const onError = err => {
	gutil.beep();
	gutil.log(staticBuild + ' - ' + errorMsg + ' ' + err.toString());
	this.emit('end');
};

/* -------------------------------------------------------------------------------------------------
Messages
-------------------------------------------------------------------------------------------------- */
const errorMsg = '\x1b[41mError\x1b[0m';
const filesGenerated =
	'Your production file are generated in: \x1b[1m' +
	__dirname +
	'/dist/ ✅';

const staticBuild = '\x1b[42m\x1b[1mStaticWebBuild\x1b[0m';
const staticBuildUrl = '\x1b[2m - https://staticbuild.website/\x1b[0m';
const thankYou = 'Thank you for using ' + staticBuild + staticBuildUrl;

/* -------------------------------------------------------------------------------------------------
End of all Tasks
-------------------------------------------------------------------------------------------------- */
<|endoftext|>


<commit_before>var _ = require('lodash');
var buildConfig = require('./scripts/build/config');
var fs = require('fs');
var gulp = require('gulp');
var karma = require('karma').server;
var path = require('path');
var VinylFile = require('vinyl');
var argv = require('yargs').argv;
var cached = require('gulp-cached');
var concat = require('gulp-concat');
var del = require('del');
var gulpif = require('gulp-if');
var rename = require('gulp-rename');
var sass = require('gulp-sass');
var through2 = require('through2');
var runSequence = require('run-sequence');
var watch = require('gulp-watch');
var exec = require('child_process').exec;

// !!! TEMP HACK !!!
// first run ./update-angular.sh
gulp.task('watch', function() {

  runSequence(
    'clean',
    'ionic.copy.js',
    'ionic.examples',
    'sass',

    function() {
      watch('ionic/**/*.js', function() {
        gulp.start('ionic.copy.js');
      });

      watch('ionic/components/*/test/**/*', function() {
        gulp.start('ionic.examples');
      });

      watch('ionic/components/**/*.scss', function() {
        gulp.start('sass');
      });
    })

});

gulp.task('clean', function(done) {
  del(['../angular-ionic/modules/ionic, ./angular-ionic/modules/examples/src/ionic'], done);
});

gulp.task('ionic.copy.js', function(done) {
  return gulp.src(['ionic/**/*.js', '!ionic/components/*/test/**/*'])
             .pipe(gulp.dest('../angular/modules/ionic'));
});

gulp.task('ionic.examples', function() {
  var indexContents = _.template( fs.readFileSync('scripts/e2e/angular.template.html') )({
    buildConfig: buildConfig
  });

  // Get each test folder with gulp.src
  return gulp.src('ionic/components/*/test/*/**/*')
    .pipe(rename(function(file) {
      file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep)
    }))
    .pipe(gulpif(/index.js$/, processMain()))
    .pipe(gulp.dest('../angular-ionic/modules/examples/src/ionic'))

    function processMain() {
      return through2.obj(function(file, enc, next) {
        var self = this;
        self.push(new VinylFile({
          base: file.base,
          contents: new Buffer(indexContents),
          path: path.join(path.dirname(file.path), 'index.html'),
        }));
        next(null, file);
      })
    }

});

gulp.task('sass', function() {
  return gulp.src('ionic/ionic.scss')
    .pipe(sass({
      onError: function(err) {
        console.log(err)
      }
    }))
    .pipe(gulp.dest('dist/css'));
});

gulp.task('update.angular', function(done) {

  if (!fs.existsSync('../angular-ionic')) {
    fs.mkdirSync('../angular-ionic');

    console.log('cloning angular master...');
    exec('git clone git@github.com:angular/angular ../angular-ionic', function() {
      npmInstall();
    });

  } else {
    console.log('angular master: cleaning modules');
    del(['../angular-ionic/modules'], function() {

      console.log('angular master: reset --hard...');
      exec('git reset --hard origin/master', {cwd: '../angular-ionic'}, function () {

        console.log('angular master: git pull origin master...');
        exec('git pull origin master', function () {
          npmInstall();
        });
      });

    })
  }

  function npmInstall() {
    console.log('angular master: npm install (may take a while, chill out)...');
    exec('npm install', {cwd: '../angular-ionic'}, function () {
      done();
    });
  }

});

require('./scripts/snapshot/snapshot.task')(gulp, argv, buildConfig);

// gulp.task('watch', ['default'], function() {
//   gulp.watch(buildConfig.src.scss, ['sass'])
//   gulp.watch([].concat(
//     buildConfig.src.js, buildConfig.src.html,
//     'scripts/e2e/index.template.html'
//   ), ['e2e'])
//   gulp.watch([].concat(
//     buildConfig.src.e2e, buildConfig.src.html,
//     'scripts/e2e/index.template.html'
//   ), ['ionic-js'])
// });

gulp.task('karma', function() {
  return karma.start({ configFile: __dirname + '/scripts/test/karma.conf.js' })
});

gulp.task('karma-watch', function() {
  return karma.start({ configFile: __dirname + '/scripts/test/karma-watch.conf.js' })
});

gulp.task('fonts', function() {
  return gulp.src('ionic/components/icon/fonts/**/*')
    .pipe(gulp.dest('dist/fonts'));
});

gulp.task('e2e', ['ionic-js', 'sass'], function() {
  var indexContents = _.template( fs.readFileSync('scripts/e2e/index.template.html') )({
    buildConfig: buildConfig
  });
  var testTemplate = _.template( fs.readFileSync('scripts/e2e/e2e.template.js') )

  var platforms = [
    'android',
    'core',
    'ios',
  ];

  // Get each test folder with gulp.src
  return gulp.src(buildConfig.src.e2e)
    .pipe(cached('e2e'))
    .pipe(rename(function(file) {
      file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep)
    }))
    .pipe(gulpif(/main.js$/, processMain()))
    //.pipe(gulpif(/e2e.js$/, createPlatformTests()))
    //.pipe(gulp.dest(buildConfig.dist + '/e2e'))

    function processMain() {
      return through2.obj(function(file, enc, next) {
        var self = this;
        self.push(new VinylFile({
          base: file.base,
          contents: new Buffer(indexContents),
          path: path.join(path.dirname(file.path), 'index.html'),
        }));
        next(null, file);
      })
    }

    function createPlatformTests(file) {
      return through2.obj(function(file, enc, next) {
        var self = this
        var relativePath = path.dirname(file.path.replace(/^.*?ionic(\/|\\)components(\/|\\)/, ''))
        var contents = file.contents.toString()
        platforms.forEach(function(platform) {
          var platformContents = testTemplate({
            contents: contents,
            buildConfig: buildConfig,
            relativePath: relativePath,
            platform: platform
          })
          self.push(new VinylFile({
            base: file.base,
            contents: new Buffer(platformContents),
            path: file.path.replace(/e2e.js$/, platform + '.e2e.js')
          }))
        })
        next()
      })
    }

});
<commit_msg>z updates<commit_after>var _ = require('lodash');
var buildConfig = require('./scripts/build/config');
var fs = require('fs');
var gulp = require('gulp');
var karma = require('karma').server;
var path = require('path');
var VinylFile = require('vinyl');
var argv = require('yargs').argv;
var cached = require('gulp-cached');
var concat = require('gulp-concat');
var del = require('del');
var gulpif = require('gulp-if');
var rename = require('gulp-rename');
var sass = require('gulp-sass');
var through2 = require('through2');
var runSequence = require('run-sequence');
var watch = require('gulp-watch');
var exec = require('child_process').exec;

// !!! TEMP HACK !!!
// first run ./update-angular.sh
gulp.task('watch', function() {

  runSequence(
    'clean',
    'ionic.copy.js',
    'ionic.examples',
    'sass',

    function() {
      watch('ionic/**/*.js', function() {
        gulp.start('ionic.copy.js');
      });

      watch('ionic/components/*/test/**/*', function() {
        gulp.start('ionic.examples');
      });

      watch('ionic/components/**/*.scss', function() {
        gulp.start('sass');
      });
    })

});

gulp.task('clean', function(done) {
  del(['../angular-ionic/modules/ionic, ./angular-ionic/modules/examples/src/ionic'], done);
});

gulp.task('ionic.copy.js', function(done) {
  return gulp.src(['ionic/**/*.js', '!ionic/components/*/test/**/*'])
             .pipe(gulp.dest('../angular-ionic/modules/ionic'));
});

gulp.task('ionic.examples', function() {
  var indexContents = _.template( fs.readFileSync('scripts/e2e/angular.template.html') )({
    buildConfig: buildConfig
  });

  // Get each test folder with gulp.src
  return gulp.src('ionic/components/*/test/*/**/*')
    .pipe(rename(function(file) {
      file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep)
    }))
    .pipe(gulpif(/index.js$/, processMain()))
    .pipe(gulp.dest('../angular-ionic/modules/examples/src/ionic'))

    function processMain() {
      return through2.obj(function(file, enc, next) {
        var self = this;
        self.push(new VinylFile({
          base: file.base,
          contents: new Buffer(indexContents),
          path: path.join(path.dirname(file.path), 'index.html'),
        }));
        next(null, file);
      })
    }

});

gulp.task('sass', function() {
  return gulp.src('ionic/ionic.scss')
    .pipe(sass({
      onError: function(err) {
        console.log(err)
      }
    }))
    .pipe(gulp.dest('dist/css'));
});

gulp.task('update.angular', function(done) {

  if (!fs.existsSync('../angular-ionic')) {
    fs.mkdirSync('../angular-ionic');

    console.log('cloning angular master...');
    exec('git clone git@github.com:angular/angular ../angular-ionic', function() {
      npmInstall();
    });

  } else {
    console.log('angular master: cleaning modules');
    del(['../angular-ionic/modules'], function() {

      console.log('angular master: reset --hard...');
      exec('git reset --hard origin/master', {cwd: '../angular-ionic'}, function () {

        console.log('angular master: git pull origin master...');
        exec('git pull origin master', function () {
          npmInstall();
        });
      });

    })
  }

  function npmInstall() {
    console.log('angular master: npm install (may take a while, chill out)...');
    exec('npm install', {cwd: '../angular-ionic'}, function () {
      done();
    });
  }

});

require('./scripts/snapshot/snapshot.task')(gulp, argv, buildConfig);

// gulp.task('watch', ['default'], function() {
//   gulp.watch(buildConfig.src.scss, ['sass'])
//   gulp.watch([].concat(
//     buildConfig.src.js, buildConfig.src.html,
//     'scripts/e2e/index.template.html'
//   ), ['e2e'])
//   gulp.watch([].concat(
//     buildConfig.src.e2e, buildConfig.src.html,
//     'scripts/e2e/index.template.html'
//   ), ['ionic-js'])
// });

gulp.task('karma', function() {
  return karma.start({ configFile: __dirname + '/scripts/test/karma.conf.js' })
});

gulp.task('karma-watch', function() {
  return karma.start({ configFile: __dirname + '/scripts/test/karma-watch.conf.js' })
});

gulp.task('fonts', function() {
  return gulp.src('ionic/components/icon/fonts/**/*')
    .pipe(gulp.dest('dist/fonts'));
});

gulp.task('e2e', ['ionic-js', 'sass'], function() {
  var indexContents = _.template( fs.readFileSync('scripts/e2e/index.template.html') )({
    buildConfig: buildConfig
  });
  var testTemplate = _.template( fs.readFileSync('scripts/e2e/e2e.template.js') )

  var platforms = [
    'android',
    'core',
    'ios',
  ];

  // Get each test folder with gulp.src
  return gulp.src(buildConfig.src.e2e)
    .pipe(cached('e2e'))
    .pipe(rename(function(file) {
      file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep)
    }))
    .pipe(gulpif(/main.js$/, processMain()))
    //.pipe(gulpif(/e2e.js$/, createPlatformTests()))
    //.pipe(gulp.dest(buildConfig.dist + '/e2e'))

    function processMain() {
      return through2.obj(function(file, enc, next) {
        var self = this;
        self.push(new VinylFile({
          base: file.base,
          contents: new Buffer(indexContents),
          path: path.join(path.dirname(file.path), 'index.html'),
        }));
        next(null, file);
      })
    }

    function createPlatformTests(file) {
      return through2.obj(function(file, enc, next) {
        var self = this
        var relativePath = path.dirname(file.path.replace(/^.*?ionic(\/|\\)components(\/|\\)/, ''))
        var contents = file.contents.toString()
        platforms.forEach(function(platform) {
          var platformContents = testTemplate({
            contents: contents,
            buildConfig: buildConfig,
            relativePath: relativePath,
            platform: platform
          })
          self.push(new VinylFile({
            base: file.base,
            contents: new Buffer(platformContents),
            path: file.path.replace(/e2e.js$/, platform + '.e2e.js')
          }))
        })
        next()
      })
    }

});
<|endoftext|>


<commit_before>/*
Copyright (c) 2011 Cimaron Shanahan

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var del = require('del'),
	gulp = require('gulp'),
	browserify = require('gulp-browserify'),
	concat = require('gulp-concat'),
	include = require('gulp-include'),
	jison = require('gulp-jison'),
	jshint = require('gulp-jshint'),
	rename = require('gulp-rename'),
	uglify = require('gulp-uglify')
	;

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

gulp.task('jison', function() {
	return gulp.src('parser/*.jison')
		.pipe(jison({ moduleType: 'commonjs' }))
		//.pipe(rename('grammar.js'))
		.pipe(gulp.dest('build'))
});

gulp.task('parser', ['jison'], function() {
	return gulp.src([
		'preprocessor/preprocessor.js',
		'preprocessor/comments.js',
		'parser/type.js',
		'parser/symbol.js',
		'parser/ast.js',
		'ir/builtin.js',
		'build/grammar.js',
		'parser/parser.js',
		'parser/lexer.js'
		])
		.pipe(concat('parser.js'))
		.pipe(gulp.dest('build'))
});

gulp.task('generator', function() {
	return gulp.src([
		'ir/generator.js',
		'ir/ir.js',
		'ir/operand.js',
		'ir/instruction.js',
		'output/javascript/program.js',
		'output/javascript/context.js',
		'output/javascript/variables.js'
		])
		.pipe(concat('ir.js'))
		.pipe(gulp.dest('build'))
});

gulp.task('glsl', ['parser', 'generator'], function() {
	return gulp.src([
		'glsl.js',
		'library/util.js',
		'state.js',
		'build/parser.js',
		'build/ir.js'
		])
		.pipe(concat('glsl.part.js'))
		.pipe(gulp.dest('build'))
});

gulp.task('errors', ['glsl'], function() {
	return gulp.src([
		'build/glsl.js'
	])
	.pipe(jshint())
	;
});

gulp.task('watch', function() {
    gulp.watch([
        '*.js',
        'library/*.js',
        'ir/*.js',
        'output/**/*.js',
        'parser/*.js',
        'parser/*.jison',
        'preprocessor/*.js'
    ], ['default']);
});

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

	return gulp.src([
		'index.js'
		])
		.pipe(include())
		/*.pipe(uglify({
			mangle : false,
			output : {
				beautify : true
			},
			compress : false,
			preserveComments : function(node, comment) {
				return !comment.value.match(/Copyright/);
			}
		}))*/
		.pipe(rename('glsl.js'))
		.pipe(gulp.dest('build'))
		;
});

<commit_msg>#14: Add standalone parser build steps<commit_after>/*
Copyright (c) 2011 Cimaron Shanahan

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var del = require('del'),
	gulp = require('gulp'),
	browserify = require('gulp-browserify'),
	concat = require('gulp-concat'),
	include = require('gulp-include'),
	jison = require('gulp-jison'),
	jshint = require('gulp-jshint'),
	rename = require('gulp-rename'),
	uglify = require('gulp-uglify')
	;

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

/**
 * Component Tasks
 */
gulp.task('jison', function() {
	return gulp.src('parser/*.jison')
		.pipe(jison({ moduleType: 'commonjs' }))
		//.pipe(rename('grammar.js'))
		.pipe(gulp.dest('build'))
});

gulp.task('_parser', ['jison'], function() {
	return gulp.src([
		'preprocessor/preprocessor.js',
		'preprocessor/comments.js',
		'parser/type.js',
		'parser/symbol.js',
		'parser/ast.js',
		'ir/builtin.js',
		'build/grammar.js',
		'parser/parser.js',
		'parser/lexer.js'
		])
		.pipe(concat('parser.js'))
		.pipe(gulp.dest('build'))
});

gulp.task('generator', function() {
	return gulp.src([
		'ir/generator.js',
		'ir/ir.js',
		'ir/operand.js',
		'ir/instruction.js',
		'output/javascript/program.js',
		'output/javascript/context.js',
		'output/javascript/variables.js'
		])
		.pipe(concat('ir.js'))
		.pipe(gulp.dest('build'))
});

/**
 * Build
 */
gulp.task('glsl-all', ['_parser', 'generator'], function() {
	return gulp.src([
		'glsl.js',
		'library/util.js',
		'state.js',
		'build/parser.js',
		'build/ir.js'
		])
		.pipe(concat('glsl.part.js'))
		.pipe(gulp.dest('build'))
});

gulp.task('glsl-parser', ['_parser'], function() {
	return gulp.src([
		'glsl.js',
		'library/util.js',
		'state.js',
		'build/parser.js'
		])
		.pipe(concat('glsl.part.js'))
		.pipe(gulp.dest('build'))
});

gulp.task('errors', ['glsl-all'], function() {
	return gulp.src([
		'build/glsl.js'
	])
	.pipe(jshint())
	;
});

/**
 * Final processing
 */
gulp.task('default', ['clean', 'glsl-all'], function() {

	return gulp.src([
		'index.js'
		])
		.pipe(include())
		/*.pipe(uglify({
			mangle : false,
			output : {
				beautify : true
			},
			compress : false,
			preserveComments : function(node, comment) {
				return !comment.value.match(/Copyright/);
			}
		}))*/
		/*.pipe(uglify({
			mangle : true,
			output : {
				beautify : false
			},
			compress : true
		}))*/
		.pipe(rename('glsl.js'))
		.pipe(gulp.dest('build'))
		;
});

gulp.task('parser', ['clean', 'glsl-parser'], function() {
	return gulp.src([
		'index.js'
		])
		.pipe(include())
		.pipe(rename('glsl.parser.js'))
		.pipe(gulp.dest('build'))
		;
});

/**
 * Watch
 */
gulp.task('watch', function() {
    gulp.watch([
        '*.js',
        'library/*.js',
        'ir/*.js',
        'output/**/*.js',
        'parser/*.js',
        'parser/*.jison',
        'preprocessor/*.js'
    ], ['default']);
});

gulp.task('watch-parser', function() {
    gulp.watch([
        '*.js',
        'library/*.js',
        'parser/*.js',
        'parser/*.jison',
        'preprocessor/*.js'
    ], ['parser']);
});

<|endoftext|>


<commit_before>var gulp = require('gulp');
var minifyHTML = require('gulp-minify-html');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var changed = require('gulp-changed');
var imagemin = require('gulp-imagemin');
var autoprefix = require('gulp-autoprefixer');
var minifyCSS = require('gulp-minify-css');
var del = require('del');
var concat = require('gulp-concat');
var refresh = require('gulp-livereload');
var modRewrite = require('connect-modrewrite');
var RevAll = require('gulp-rev-all');
var runSequence = require('run-sequence');
var sourcemaps = require('gulp-sourcemaps');

var paths = {
    dist: 'dist',
    jshint: [
        'app/scripts/**/*.js',
        'app/theme/**/*.js'
    ],
    html: 'app/**/*.html',
    misc: 'app/*.{txt,htaccess,ico}',
    scripts: [
        'app/scripts/config.js',
        'app/scripts/main.js',
        'app/scripts/**/init.js',
        'app/scripts/**/*.js'
    ],
    theme: {
        dist: 'dist/theme',
        css: 'app/theme/styles/**/*.css',
        images: 'app/theme/**/*.{png,gif,jpg,jpec,ico,svg,mp4}',
        fonts: 'app/theme/fonts/**/*',
        scripts: [
            'app/theme/lib/**/*.js',
            'app/theme/**/*.js'
        ]
    },
    lib: {
        dist: 'dist/lib',
        scripts: [
            'app/lib/jquery.min.js',
            'app/lib/angular.min.js',
            'app/lib/*.js' // NOTE: no folder glob, or it would clobber .ie
        ],
        ie: 'app/lib/ie/*.js'
    }
};

var host = {
    port: '8080',
    lrPort: '35729'
};

var env = process.env.NODE_ENV || 'development';

// Empties folders to start fresh
gulp.task('clean', function (cb) {
    return del(['dist/*', '!dist/media'], cb);
});

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

gulp.task('html', function () {
    return gulp.src(paths.html)
        .pipe(changed(paths.dist))
        .pipe(minifyHTML({
            collapseWhitespace: true,
            collapseBooleanAttributes: true,
            removeCommentsFromCDATA: true,
            removeOptionalTags: true,
            conditionals: true,
            quotes: true,
            empty: true
        }))
        .pipe(gulp.dest(paths.dist));
});

gulp.task('misc', function () {
    return gulp.src(paths.misc)
        .pipe(gulp.dest(paths.dist));
});

gulp.task('scripts', function () {
    return gulp.src(paths.scripts)
        .pipe(sourcemaps.init())
        .pipe(concat('main.js'))
        .pipe(uglify({
            mangle: false
        }))
        .pipe(sourcemaps.write('./maps'))
        .pipe(gulp.dest(paths.dist + '/scripts'))
        .pipe(refresh());
});

gulp.task('theme.css', function () {
    return gulp.src(paths.theme.css)
        .pipe(autoprefix('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
        .pipe(minifyCSS())
        .pipe(gulp.dest(paths.theme.dist + '/styles'));
});

gulp.task('theme.fonts', function() {
    return gulp.src(paths.theme.fonts)
        .pipe(gulp.dest(paths.theme.dist + '/fonts'));
});

gulp.task('theme.scripts', function () {
    return gulp.src(paths.theme.scripts)
        .pipe(sourcemaps.init())
        .pipe(concat('main.js'))
        .pipe(uglify({
            mangle: false
        }))
        .pipe(sourcemaps.write('./maps'))
        .pipe(gulp.dest(paths.theme.dist))
        .pipe(refresh());
});

gulp.task('theme.images', function () {
    return gulp.src(paths.theme.images)
        .pipe(changed(paths.theme.dist))
        .pipe(imagemin())
        .pipe(gulp.dest(paths.theme.dist));
});

gulp.task('lib.scripts', function () {
    return gulp.src(paths.lib.scripts)
        .pipe(concat('lib.js'))
        .pipe(gulp.dest(paths.lib.dist));
});

// IE libs can stick together, but need to be separate from other libs
gulp.task('lib.ie', function() {
    return gulp.src(paths.lib.ie)
        .pipe(concat('ie-libs.js'))
        .pipe(gulp.dest(paths.lib.dist));
});

gulp.task('watch',function(){
    refresh.listen({ basePath: paths.dist });

    gulp.start('livereload');

    gulp.watch(["app/**/*.html"],['html']);
    gulp.watch(["app/**/*.css"],['theme.css']);
    gulp.watch(["app/scripts/**/*.js"],['scripts']);
    gulp.watch(["app/theme/**/*.js"],['theme.scripts']);
});

gulp.task('livereload', function(){
    var path = require('path');
    var express = require('express');
    var app = express();
    var staticFolder = path.join(__dirname, 'dist');

    app.use(modRewrite([
        '!\\. /index.html [L]'
    ]))
        .use(express.static(staticFolder));

    app.listen( host.port, function() {
        console.log('server started: http://localhost:' + host.port);
        return gulp;
    });
});

gulp.task('revision', function(){
    if(env === 'production') {
        var revAll = new RevAll({
            dontUpdateReference: [/^((?!.js|.css).)*$/g],
            dontRenameFile: [/^((?!.js|.css).)*$/g]
        });
        gulp.src('dist/**')
            .pipe(revAll.revision())
            .pipe(gulp.dest('dist'));
    }
});

gulp.task('lib', ['lib.ie', 'lib.scripts']);
gulp.task('theme', [
    'theme.css',
    'theme.fonts',
    'theme.scripts',
    'theme.images'
]);

// For production
gulp.task('build', function(){
    // note: revision has a short circuit for dev
    runSequence('clean', [
        'html',
        'misc',
        'scripts',
        'theme',
        'lib'
    ], 'revision');
});

// For development
gulp.task('serve', ['default']);
gulp.task('default', ['build'], function(){
    gulp.start('watch');
});<commit_msg>refresh on css update<commit_after>var gulp = require('gulp');
var minifyHTML = require('gulp-minify-html');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var changed = require('gulp-changed');
var imagemin = require('gulp-imagemin');
var autoprefix = require('gulp-autoprefixer');
var minifyCSS = require('gulp-minify-css');
var del = require('del');
var concat = require('gulp-concat');
var refresh = require('gulp-livereload');
var modRewrite = require('connect-modrewrite');
var RevAll = require('gulp-rev-all');
var runSequence = require('run-sequence');
var sourcemaps = require('gulp-sourcemaps');

var paths = {
    dist: 'dist',
    jshint: [
        'app/scripts/**/*.js',
        'app/theme/**/*.js'
    ],
    html: 'app/**/*.html',
    misc: 'app/*.{txt,htaccess,ico}',
    scripts: [
        'app/scripts/config.js',
        'app/scripts/main.js',
        'app/scripts/**/init.js',
        'app/scripts/**/*.js'
    ],
    theme: {
        dist: 'dist/theme',
        css: 'app/theme/styles/**/*.css',
        images: 'app/theme/**/*.{png,gif,jpg,jpec,ico,svg,mp4}',
        fonts: 'app/theme/fonts/**/*',
        scripts: [
            'app/theme/lib/**/*.js',
            'app/theme/**/*.js'
        ]
    },
    lib: {
        dist: 'dist/lib',
        scripts: [
            'app/lib/jquery.min.js',
            'app/lib/angular.min.js',
            'app/lib/*.js' // NOTE: no folder glob, or it would clobber .ie
        ],
        ie: 'app/lib/ie/*.js'
    }
};

var host = {
    port: '8080',
    lrPort: '35729'
};

var env = process.env.NODE_ENV || 'development';

// Empties folders to start fresh
gulp.task('clean', function (cb) {
    return del(['dist/*', '!dist/media'], cb);
});

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

gulp.task('html', function () {
    return gulp.src(paths.html)
        .pipe(changed(paths.dist))
        .pipe(minifyHTML({
            collapseWhitespace: true,
            collapseBooleanAttributes: true,
            removeCommentsFromCDATA: true,
            removeOptionalTags: true,
            conditionals: true,
            quotes: true,
            empty: true
        }))
        .pipe(gulp.dest(paths.dist));
});

gulp.task('misc', function () {
    return gulp.src(paths.misc)
        .pipe(gulp.dest(paths.dist));
});

gulp.task('scripts', function () {
    return gulp.src(paths.scripts)
        .pipe(sourcemaps.init())
        .pipe(concat('main.js'))
        .pipe(uglify({
            mangle: false
        }))
        .pipe(sourcemaps.write('./maps'))
        .pipe(gulp.dest(paths.dist + '/scripts'))
        .pipe(refresh());
});

gulp.task('theme.css', function () {
    return gulp.src(paths.theme.css)
        .pipe(autoprefix('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
        .pipe(minifyCSS())
        .pipe(gulp.dest(paths.theme.dist + '/styles'))
        .pipe(refresh());
});

gulp.task('theme.fonts', function() {
    return gulp.src(paths.theme.fonts)
        .pipe(gulp.dest(paths.theme.dist + '/fonts'));
});

gulp.task('theme.scripts', function () {
    return gulp.src(paths.theme.scripts)
        .pipe(sourcemaps.init())
        .pipe(concat('main.js'))
        .pipe(uglify({
            mangle: false
        }))
        .pipe(sourcemaps.write('./maps'))
        .pipe(gulp.dest(paths.theme.dist))
        .pipe(refresh());
});

gulp.task('theme.images', function () {
    return gulp.src(paths.theme.images)
        .pipe(changed(paths.theme.dist))
        .pipe(imagemin())
        .pipe(gulp.dest(paths.theme.dist));
});

gulp.task('lib.scripts', function () {
    return gulp.src(paths.lib.scripts)
        .pipe(concat('lib.js'))
        .pipe(gulp.dest(paths.lib.dist));
});

// IE libs can stick together, but need to be separate from other libs
gulp.task('lib.ie', function() {
    return gulp.src(paths.lib.ie)
        .pipe(concat('ie-libs.js'))
        .pipe(gulp.dest(paths.lib.dist));
});

gulp.task('watch',function(){
    refresh.listen({ basePath: paths.dist });

    gulp.start('livereload');

    gulp.watch(["app/**/*.html"],['html']);
    gulp.watch(["app/**/*.css"],['theme.css']);
    gulp.watch(["app/scripts/**/*.js"],['scripts']);
    gulp.watch(["app/theme/**/*.js"],['theme.scripts']);
});

gulp.task('livereload', function(){
    var path = require('path');
    var express = require('express');
    var app = express();
    var staticFolder = path.join(__dirname, 'dist');

    app.use(modRewrite([
        '!\\. /index.html [L]'
    ]))
        .use(express.static(staticFolder));

    app.listen( host.port, function() {
        console.log('server started: http://localhost:' + host.port);
        return gulp;
    });
});

gulp.task('revision', function(){
    if(env === 'production') {
        var revAll = new RevAll({
            dontUpdateReference: [/^((?!.js|.css).)*$/g],
            dontRenameFile: [/^((?!.js|.css).)*$/g]
        });
        gulp.src('dist/**')
            .pipe(revAll.revision())
            .pipe(gulp.dest('dist'));
    }
});

gulp.task('lib', ['lib.ie', 'lib.scripts']);
gulp.task('theme', [
    'theme.css',
    'theme.fonts',
    'theme.scripts',
    'theme.images'
]);

// For production
gulp.task('build', function(){
    // note: revision has a short circuit for dev
    runSequence('clean', [
        'html',
        'misc',
        'scripts',
        'theme',
        'lib'
    ], 'revision');
});

// For development
gulp.task('serve', ['default']);
gulp.task('default', ['build'], function(){
    gulp.start('watch');
});<|endoftext|>


<commit_before>var gulp = require('gulp');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var uglify = require('gulp-uglify');
var exec = require('child_process').exec;
var rename = require('gulp-rename');
var watch = require('gulp-watch');
var Server = require('karma').Server;

gulp.task('build', function(cb) {
  exec('browserify --transform babelify --standalone Cape lib/cape.js > dist/cape.js', function (err, stdout, stderr) {
    console.log(stdout);
    console.log(stderr);
    cb(err);
  })
});

gulp.task('minify', function() {
  return gulp.src('dist/cape.js')
  .pipe(uglify())
  .pipe(rename('cape.min.js'))
  .pipe(gulp.dest('./dist'));
})

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

gulp.task('test', ['build'], function (done) {
  new Server({
    configFile: __dirname + '/test/karma.conf.js',
    singleRun: true
  }, function(exitCode) {
    process.exit(exitCode)
  }).start();
});

gulp.task('default', ['build']);
<commit_msg>Improve gulpfile.js (minify task) [ci skip]<commit_after>var gulp = require('gulp');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var uglify = require('gulp-uglify');
var exec = require('child_process').exec;
var rename = require('gulp-rename');
var watch = require('gulp-watch');
var Server = require('karma').Server;

gulp.task('build', function(cb) {
  exec('browserify --transform babelify --standalone Cape lib/cape.js > dist/cape.js', function (err, stdout, stderr) {
    console.log(stdout);
    console.log(stderr);
    cb(err);
  })
});

gulp.task('minify', function() {
  return gulp.src('dist/cape.js')
  .pipe(uglify().on('error', function(e) {
    console.log(e)
  }))
  .pipe(rename('cape.min.js'))
  .pipe(gulp.dest('./dist'));
})

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

gulp.task('test', ['build'], function (done) {
  new Server({
    configFile: __dirname + '/test/karma.conf.js',
    singleRun: true
  }, function(exitCode) {
    process.exit(exitCode)
  }).start();
});

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


<commit_before>// Include gulp
var gulp = require('gulp');

// Include Our Plugins
var sass = require('gulp-sass'),
  jshint = require('gulp-jshint'),
  concat = require('gulp-concat'),
  uglify = require('gulp-uglify'),
  rename = require('gulp-rename'),
  notify = require('gulp-notify'),
  sourcemaps = require('gulp-sourcemaps');

// Paths
var SRC = 'assets';
var DEST = 'dist';

var STYLES_SRC = SRC + '/stylesheets';
var STYLES_DEST = DEST + '/stylesheets';

var JAVASCRIPT_SRC = SRC + '/javascript';
var JAVASCRIPT_DEST = DEST + '/javascript';

var IMAGE_SRC = SRC + '/images';
var IMAGE_DEST = DEST + '/images';

var HTML_SRC = SRC;
var HTML_DEST = DEST;

var CNAME_SRC = SRC;
var CNAME_DEST = DEST;

var ROOT = DEST;

// Tasks
// ----------------------------------------

// Lint Task
gulp.task('lint', function() {
  return gulp.src(JAVASCRIPT_SRC + '/**/*.js')
    .pipe(jshint())
    .pipe(jshint.reporter('default'));
});

// Compile and Source Map our Sass
gulp.task('dev:scss', function() {
  return gulp.src(STYLES_SRC + '/main.scss')
    .pipe(sourcemaps.init())
    .pipe(sass())
    .on('error', notify.onError({
      title: 'Sass Compile Error',
      sound: 'Basso'
    }))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest(STYLES_DEST));
});

// Concatenate & Minify JS
gulp.task('scripts', function() {
  gulp.src(JAVASCRIPT_SRC + '/**/*.js')
    .pipe(concat('bundle.js'))
    .pipe(uglify())
    .pipe(gulp.dest(JAVASCRIPT_DEST));
});

// Move Images to Dist
gulp.task('images', function () {
  gulp.src(IMAGE_SRC + '/**/*.*')
    .pipe(gulp.dest(IMAGE_DEST));
});

// Refresh when HTML changes
gulp.task('html', function () {
  gulp.src(HTML_SRC + '/**/*.html')
    .pipe(gulp.dest(HTML_DEST));
});

gulp.task('domain-config', function() {
  gulp.src(CNAME_SRC + '/' + 'CNAME')
    .pipe(gulp.dest(CNAME_DEST + '/'));
});

// Watch files for changes
gulp.task('watch', function () {

  // Watch .html files
  gulp.watch([HTML_SRC + '/**/*.html'], ['html']);

  // Watch .scss files
  gulp.watch([STYLES_SRC + '/**/*.scss'], ['dev:scss']);

  // Watch .js files
  gulp.watch([JAVASCRIPT_SRC + '/**/*.js'], ['scripts']);

  // Watch image directory
  gulp.watch([IMAGE_SRC + '/**/*.*'], ['images']);

});

// Default Task
gulp.task('default', ['html', 'dev:scss', 'scripts', 'watch', 'images', 'domain-config']);
<commit_msg>Update deploy script<commit_after>// Include gulp
var gulp = require('gulp');

// Include Our Plugins
var sass = require('gulp-sass'),
  jshint = require('gulp-jshint'),
  concat = require('gulp-concat'),
  uglify = require('gulp-uglify'),
  rename = require('gulp-rename'),
  notify = require('gulp-notify'),
  sourcemaps = require('gulp-sourcemaps');

// Paths
var SRC = 'assets';
var DEST = 'dist';

var STYLES_SRC = SRC + '/stylesheets';
var STYLES_DEST = DEST + '/stylesheets';

var JAVASCRIPT_SRC = SRC + '/javascript';
var JAVASCRIPT_DEST = DEST + '/javascript';

var IMAGE_SRC = SRC + '/images';
var IMAGE_DEST = DEST + '/images';

var HTML_SRC = SRC;
var HTML_DEST = DEST;

var CNAME_SRC = './';
var CNAME_DEST = DEST;

var ROOT = DEST;

// Tasks
// ----------------------------------------

// Lint Task
gulp.task('lint', function() {
  return gulp.src(JAVASCRIPT_SRC + '/**/*.js')
    .pipe(jshint())
    .pipe(jshint.reporter('default'));
});

// Compile and Source Map our Sass
gulp.task('dev:scss', function() {
  return gulp.src(STYLES_SRC + '/main.scss')
    .pipe(sourcemaps.init())
    .pipe(sass())
    .on('error', notify.onError({
      title: 'Sass Compile Error',
      sound: 'Basso'
    }))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest(STYLES_DEST));
});

// Concatenate & Minify JS
gulp.task('scripts', function() {
  gulp.src(JAVASCRIPT_SRC + '/**/*.js')
    .pipe(concat('bundle.js'))
    .pipe(uglify())
    .pipe(gulp.dest(JAVASCRIPT_DEST));
});

// Move Images to Dist
gulp.task('images', function () {
  gulp.src(IMAGE_SRC + '/**/*.*')
    .pipe(gulp.dest(IMAGE_DEST));
});

// Refresh when HTML changes
gulp.task('html', function () {
  gulp.src(HTML_SRC + '/**/*.html')
    .pipe(gulp.dest(HTML_DEST));
});

gulp.task('domain-config', function() {
  gulp.src(CNAME_SRC + '/' + 'CNAME')
    .pipe(gulp.dest(CNAME_DEST + '/'));
});

// Watch files for changes
gulp.task('watch', function () {

  // Watch .html files
  gulp.watch([HTML_SRC + '/**/*.html'], ['html']);

  // Watch .scss files
  gulp.watch([STYLES_SRC + '/**/*.scss'], ['dev:scss']);

  // Watch .js files
  gulp.watch([JAVASCRIPT_SRC + '/**/*.js'], ['scripts']);

  // Watch image directory
  gulp.watch([IMAGE_SRC + '/**/*.*'], ['images']);

});

// Default Task
gulp.task('default', ['html', 'dev:scss', 'scripts', 'watch', 'images', 'domain-config']);
<|endoftext|>


<commit_before>/******************************************************
 * DESCRIPTION
 * Special thanks to oscar-g (https://github.com/oscar-g) for starting this at https://github.com/oscar-g/patternlab-node/tree/dev-gulp
******************************************************/
var pkg = require('./package.json'),
    gulp = require('gulp'),
    path = require('path'),
    del = require('del'),
    browserSync = require('browser-sync').create();

require('gulp-load')(gulp);

/******************************************************
 * PATTERN LAB CONFIGURATION
******************************************************/
//read all paths from our namespaced config file
var config = require('./patternlab-config.json'),
    pl = require('patternlab-node')(config);

function paths() {
  return config.paths;
}

gulp.task('patternlab', ['prelab'], function (done) {
  pl.build(true);
  done();
});

//clean patterns dir
gulp.task('pl-clean', function(cb){
  del.sync([path.resolve(paths().public.patterns, '*')], {force: true});
  cb();
});

/******************************************************
 * COPY TASKS
******************************************************/
// JS copy
gulp.task('pl-copy:js', function(){
  return gulp.src('**/*.js', {cwd: path.resolve(paths().source.js)} )
    .pipe(gulp.dest(path.resolve(paths().public.js)));
});

// Images copy
gulp.task('pl-copy:img', function(){
  return gulp.src(
    [ '**/*.gif', '**/*.png', '**/*.jpg', '**/*.jpeg'  ],
    {cwd: path.resolve(paths().source.images)} )
    .pipe(gulp.dest(path.resolve(paths().public.images)));
});

// Fonts copy
gulp.task('pl-copy:font', function(){
  return gulp.src('*', {cwd: path.resolve(paths().source.fonts)})
    .pipe(gulp.dest(path.resolve(paths().public.fonts)));
});

// Data copy
gulp.task('pl-copy:data', function(){
  return gulp.src('annotations.js', {cwd: path.resolve(paths().source.data)})
    .pipe(gulp.dest(path.resolve(paths().public.data)));
});

// CSS Copy
gulp.task('pl-copy:css', function(){
  return gulp.src(path.resolve(paths().source.css, 'style.css'))
    .pipe(gulp.dest(path.resolve(paths().public.css)))
    .pipe(browserSync.stream());
});

// Styleguide Copy
gulp.task('pl-copy:styleguide', function(){
  return gulp.src(
      ['**/*'],
      {cwd: path.resolve(paths().source.styleguide)})
      .pipe(gulp.dest(path.resolve(paths().public.styleguide)))
      .pipe(browserSync.stream());
});

/******************************************************
 * SERVER AND WATCH TASKS
******************************************************/
// watch task utility functions
function getSupportedTemplateExtensions() {
  var engines = require('./node_modules/patternlab-node/core/lib/pattern_engines');
  return engines.getSupportedFileExtensions();
}
function getTemplateWatches() {
  return getSupportedTemplateExtensions().map(function (dotExtension) {
    return path.resolve(paths().source.patterns, '**/*' + dotExtension);
  });
}

gulp.task('pl-connect', ['lab'], function() {
  browserSync.init({
    server: {
      baseDir: path.resolve(paths().public.root)
    },
    snippetOptions: {
      // Ignore all HTML files within the templates folder
      blacklist: ['/index.html', '/', '/?*']
    },
    notify: {
      styles: [
        'display: none',
        'padding: 15px',
        'font-family: sans-serif',
        'position: fixed',
        'font-size: 1em',
        'z-index: 9999',
        'bottom: 0px',
        'right: 0px',
        'border-top-left-radius: 5px',
        'background-color: #1B2032',
        'opacity: 0.4',
        'margin: 0',
        'color: white',
        'text-align: center'
      ]
    }
  });
  gulp.watch(path.resolve(paths().source.css, '**/*.css'), ['pl-copy:css']);

  gulp.watch(path.resolve(paths().source.styleguide, '**/*.*'), ['pl-copy:styleguide']);

  var patternWatches = [
    path.resolve(paths().source.patterns, '**/*.json'),
    path.resolve(paths().source.data, '*.json'),
    path.resolve(paths().source.fonts + '/*'),
    path.resolve(paths().source.images + '/*')
  ].concat(getTemplateWatches());

  gulp.watch(patternWatches, ['lab-pipe'], function () { browserSync.reload(); });
});

gulp.task('lab-pipe', ['lab'], function(cb){
  cb();
  browserSync.reload();
});

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

gulp.task('assets', ['pl-copy:js', 'pl-copy:img', 'pl-copy:font', 'pl-copy:data', 'pl-copy:css', 'pl-copy:styleguide' ]);
gulp.task('prelab', ['pl-clean', 'assets']);
gulp.task('lab', ['prelab', 'patternlab'], function(cb){cb();});
gulp.task('patterns', ['patternlab:only_patterns']);
gulp.task('pl-serve', ['lab', 'pl-connect']);

gulp.task('version', ['patternlab:version']);
gulp.task('help', ['patternlab:help']);
<commit_msg>(Hopefully) correct copying of styleguide assets to public/<commit_after>/******************************************************
 * DESCRIPTION
 * Special thanks to oscar-g (https://github.com/oscar-g) for starting this at https://github.com/oscar-g/patternlab-node/tree/dev-gulp
******************************************************/
var pkg = require('./package.json'),
    gulp = require('gulp'),
    path = require('path'),
    del = require('del'),
    browserSync = require('browser-sync').create();

require('gulp-load')(gulp);

/******************************************************
 * PATTERN LAB CONFIGURATION
******************************************************/
//read all paths from our namespaced config file
var config = require('./patternlab-config.json'),
    pl = require('patternlab-node')(config);

function paths() {
  return config.paths;
}

gulp.task('patternlab', ['prelab'], function (done) {
  pl.build(true);
  done();
});

//clean patterns dir
gulp.task('pl-clean', function(cb){
  del.sync([path.resolve(paths().public.patterns, '*')], {force: true});
  cb();
});

/******************************************************
 * COPY TASKS
******************************************************/
// JS copy
gulp.task('pl-copy:js', function(){
  return gulp.src('**/*.js', {cwd: path.resolve(paths().source.js)} )
    .pipe(gulp.dest(path.resolve(paths().public.js)));
});

// Images copy
gulp.task('pl-copy:img', function(){
  return gulp.src(
    [ '**/*.gif', '**/*.png', '**/*.jpg', '**/*.jpeg'  ],
    {cwd: path.resolve(paths().source.images)} )
    .pipe(gulp.dest(path.resolve(paths().public.images)));
});

// Fonts copy
gulp.task('pl-copy:font', function(){
  return gulp.src('*', {cwd: path.resolve(paths().source.fonts)})
    .pipe(gulp.dest(path.resolve(paths().public.fonts)));
});

// Data copy
gulp.task('pl-copy:data', function(){
  return gulp.src('annotations.js', {cwd: path.resolve(paths().source.data)})
    .pipe(gulp.dest(path.resolve(paths().public.data)));
});

// CSS Copy
gulp.task('pl-copy:css', function(){
  return gulp.src(path.resolve(paths().source.css, 'style.css'))
    .pipe(gulp.dest(path.resolve(paths().public.css)))
    .pipe(browserSync.stream());
});

// Styleguide Copy
gulp.task('pl-copy:styleguide', function(){
  return gulp.src(path.resolve(paths().source.styleguide, '**/*'))
    .pipe(gulp.dest(path.resolve(paths().public.root)))
    .pipe(browserSync.stream());
});

/******************************************************
 * SERVER AND WATCH TASKS
******************************************************/
// watch task utility functions
function getSupportedTemplateExtensions() {
  var engines = require('./node_modules/patternlab-node/core/lib/pattern_engines');
  return engines.getSupportedFileExtensions();
}
function getTemplateWatches() {
  return getSupportedTemplateExtensions().map(function (dotExtension) {
    return path.resolve(paths().source.patterns, '**/*' + dotExtension);
  });
}

gulp.task('pl-connect', ['lab'], function() {
  browserSync.init({
    server: {
      baseDir: path.resolve(paths().public.root)
    },
    snippetOptions: {
      // Ignore all HTML files within the templates folder
      blacklist: ['/index.html', '/', '/?*']
    },
    notify: {
      styles: [
        'display: none',
        'padding: 15px',
        'font-family: sans-serif',
        'position: fixed',
        'font-size: 1em',
        'z-index: 9999',
        'bottom: 0px',
        'right: 0px',
        'border-top-left-radius: 5px',
        'background-color: #1B2032',
        'opacity: 0.4',
        'margin: 0',
        'color: white',
        'text-align: center'
      ]
    }
  });
  gulp.watch(path.resolve(paths().source.css, '**/*.css'), ['pl-copy:css']);

  gulp.watch(path.resolve(paths().source.styleguide, '**/*.*'), ['pl-copy:styleguide']);

  var patternWatches = [
    path.resolve(paths().source.patterns, '**/*.json'),
    path.resolve(paths().source.data, '*.json'),
    path.resolve(paths().source.fonts + '/*'),
    path.resolve(paths().source.images + '/*')
  ].concat(getTemplateWatches());

  gulp.watch(patternWatches, ['lab-pipe'], function () { browserSync.reload(); });
});

gulp.task('lab-pipe', ['lab'], function(cb){
  cb();
  browserSync.reload();
});

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

gulp.task('assets', ['pl-copy:js', 'pl-copy:img', 'pl-copy:font', 'pl-copy:data', 'pl-copy:css', 'pl-copy:styleguide' ]);
gulp.task('prelab', ['pl-clean', 'assets']);
gulp.task('lab', ['prelab', 'patternlab'], function(cb){cb();});
gulp.task('patterns', ['patternlab:only_patterns']);
gulp.task('pl-serve', ['lab', 'pl-connect']);

gulp.task('version', ['patternlab:version']);
gulp.task('help', ['patternlab:help']);
<|endoftext|>