Example #1
0
gulp.task('html-minify', 'Minify the HTML', function(done) {
  var buildMetaData = buildMetaDataFactory.create(process.cwd() + '/gulp/build-meta-data/html.json');
  var changedFiles = buildMetaData.getChangedFiles(gulpConfig.sourceFiles.html);

  if(changedFiles.length > 0) {
    var stream = gulp.src(changedFiles, {
      base: gulpConfig.webPath
    })
    .pipe(minifyHtml({
      empty: true,
      quotes: true,
      conditionals: true,
      comments: true
    }))
    .pipe(gulp.dest(gulpConfig.buildPath));

    stream.on('end', function() {
      buildMetaData.addBuildMetaDataFiles(changedFiles);

      if(buildMetaData.writeFile()) {
        gutil.log(gutil.colors.cyan('writing build meta data file: ' + buildMetaData.filePath));
      }

      done();
    });

    stream.on('error', function(err) {
      done(err);
    });
  } else {
    done();
  }
});
Example #2
0
gulp.task('svg-to-commonjs', 'Creates a commonjs compatible file that exports the svg in a JSON object', function(done) {
  var buildMetaData = buildMetaDataFactory.create(process.cwd() + '/gulp/build-meta-data/svg-to-commonjs.json');
  var files = globArray.sync(gulpConfig.sourceFiles.svg);
  var json = {};

  if(buildMetaData.hasChangedFile(files)) {
    files.forEach(function(filePath, key) {
      var fileName = path.basename(filePath).replace('.svg', '');

      var parts = fileName.split(/-/);
      var size = parts[parts.length - 1];
      var iconName = parts.slice(0, parts.length - 1).join('-');

      if(!json[size]) {
        json[size] = {};
      }

      json[size][iconName] = fs.readFileSync(filePath, 'utf-8')
      .replace(/\s?id="[a-zA-Z0-9\-\_]*"/g, '')
      .replace(/<svg /, '<svg class="svg-icon" ');
    });

    fs.writeFileSync(process.cwd() + '/svg.js', 'module.exports=' + JSON.stringify(json) + ';');

    buildMetaData.addBuildMetaDataFiles(files);

    if(buildMetaData.writeFile()) {
      gutil.log(gutil.colors.cyan('writing build meta data file: ' + buildMetaData.filePath));
    }
  }

  done();
});
Example #3
0
gulp.task('javascript', 'Concat and minify JavaScript (with UglifyJS)', function(done) {
  var buildMetaData = buildMetaDataFactory.create(process.cwd() + '/gulp/build-meta-data/javascript.json');
  var count = 0;

  _.forEach(gulpConfig.compileFiles.javascript, function(buildFiles, buildFileName) {
    var fullBuildFilePath = process.cwd() + '/' + gulpConfig.buildPath + '/' + buildFileName;
    var relativeBuildFilePath = gulpConfig.buildPath + '/' + buildFileName;

    if(
      !fs.existsSync(fullBuildFilePath)
      || buildMetaData.hasChangedFile(buildFiles)
      || !buildMetaData.hasSameFiles(relativeBuildFilePath, buildFiles)
    ) {
      count += 1;
      gulp.src(buildFiles)
      .pipe(uglify(buildFileName, {
        basePath: gulpConfig.webPath,
        outSourceMap: true
      }))
      .pipe(gulp.dest(gulpConfig.buildPath))
      .pipe(through.obj(function(file, encoding, cb) {
        //don't process the map file
        if(file.relative !== buildFileName) {
          return;
        }

        count -= 1;
        buildMetaData.addBuildMetaDataFiles(buildFiles, relativeBuildFilePath);

        if(count == 0) {
          if(buildMetaData.writeFile()) {
            gutil.log(gutil.colors.cyan('writing build meta data file: ' + buildMetaData.filePath));
          }

          done();
        }

        cb();
      }));
    }
  });

  if(count === 0) {
    done();
  }
});
Example #4
0
gulp.task('sass', 'Compile SASS into CSS', function(done) {
  var buildMetaData = buildMetaDataFactory.create(process.cwd() + '/gulp/build-meta-data/sass.json');
  var sassFiles = buildMetaData.getChangedFiles(gulpConfig.sourceFiles.sass);

  if(sassFiles.length > 0) {
    var files = gulpConfig.compileFiles.sass;
    var count = Object.keys(files).length;

    _.forEach(files, function(destination, source) {
      var command = 'sass --scss -q -t compressed --scss ' + source + ' ' + destination;
      gutil.log(gutil.colors.cyan('running command:'), command);

      // we are calling ruby sass manually because gulp-ruby-sass currently does not work with imports and older versions are too slow
      gulp.src('', {read: false})
      .pipe(shell([
        command
      ]))
      .pipe(through.obj(function(file, excoding, cb) {
        count -= 1;

        if(count == 0) {
          buildMetaData.addBuildMetaDataFiles(sassFiles);

          if(buildMetaData.writeFile()) {
            gutil.log(gutil.colors.cyan('writing build meta data file: ' + buildMetaData.filePath));
          }

          done();
        }

        cb();
      }));
    });
  } else {
    done();
  }
});