{"size": 1600, "ext": "js", "max_stars_repo_path": "tasks/usemin.js", "max_stars_repo_name": "alishagarric/dads-birthday", "max_stars_repo_stars_event_min_datetime": "2018-03-01T03:42:47.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-09T23:03:36.000Z", "max_issues_repo_path": "tasks/usemin.js", "max_issues_repo_name": "amazingSurge/jekyll-starter-kit", "max_issues_repo_issues_event_min_datetime": "2020-04-06T00:47:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-06T00:47:35.000Z", "max_forks_repo_path": "tasks/usemin.js", "max_forks_repo_name": "amazingSurge/jekyll-starter-kit", "max_forks_repo_forks_event_min_datetime": "2018-03-01T03:42:53.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-21T17:00:14.000Z"}
{"max_stars_count": 5, "max_issues_count": 1, "max_forks_count": 3, "avg_line_length": 27.5862068966, "max_line_length": 74, "alphanum_fraction": 0.489375}
import gulp from 'gulp';
import config from '../config';
import plumber from 'gulp-plumber';
import flatmap from 'gulp-flatmap';
import usemin from 'gulp-usemin';
import cssnano from 'gulp-cssnano';
import uglify from 'gulp-uglify';
import gulpif from 'gulp-if';
import notify from 'gulp-notify';
import htmlmin from 'gulp-htmlmin';

gulp.task('usemin', () => {
  return gulp
    .src(`${config.html.build}/**/*.html`)
    .pipe(
      flatmap((stream) => {
        return stream
          .pipe(
            plumber({
              errorHandler: notify.onError('Error: <%= error.message %>'),
            })
          )
          .pipe(
            gulpif(
              config.production,
              usemin({
                // see https://www.npmjs.com/package/gulp-usemin
                // path: config.html.build,
                css: [cssnano()],
                js: [uglify()],
                html: [htmlmin({
                  removeComments: true,
                  collapseWhitespace: true,
                  removeRedundantAttributes: true,
                  keepClosingSlash: true,
                  minifyCSS: true,
                  minifyJS: true,
                  collapseBooleanAttributes: true,
                  removeAttributeQuotes: false,
                })],
              })
            )
          )
          .pipe(gulp.dest(config.html.build));
      })
    )
    .pipe(
      gulpif(
        config.enable.notify,
        notify({
          title: config.notify.title,
          message: 'Usemin task complete',
          onLast: true,
        })
      )
    );
});
