<commit_before>import { dest, parallel, series, src } from 'gulp';

import browserSync from 'browser-sync';
import cssnano from 'gulp-cssnano';
import envalid from 'envalid';
import gulpif from 'gulp-if';
import htmlmin from 'gulp-htmlmin';
import merge2 from 'merge2';
import plumber from 'gulp-plumber';
import sass from 'gulp-sass';
import ssi from 'gulp-ssi';
import uglify from 'gulp-uglify';
import util from 'gulp-util';
import watch from 'gulp-watch';

const environment = envalid.cleanEnv(process.env);
const browserSyncInstance = browserSync.create();

/**
 * Auxiliary function to log a plugin error with color support and a formatted message.
 *
 * @param {object} event Event information pertaining to an `EventEmitter` event.
 */
function logPluginError(event) {
    util.log(new util.PluginError(event.plugin, event.formatted).toString());
}

/**
 * Launch the `browser-sync` HTTP server while watching for file changes and refreshing the browser
 * or the assets accordingly.
 */
function initializeBrowserSync() {
    browserSyncInstance.init({
        files: './dist/**/*',
        server: './dist',
        online: false,
        open: false
    });
}

/**
 * Compile development source Sass files when changes are detected and pipes them into the build
 * destination folder only for changed files.
 */
function watchStylesTask() {
    return watch('./src/assets/sass/**/*.scss')
        .pipe(plumber())
        .pipe(sass().on('error', logPluginError))
        .pipe(plumber.stop())
        .pipe(dest('./dist/assets/css'))
        .pipe(browserSyncInstance.stream());
}

/**
 * Compile development source Sass files and pipes them into the build destination folder.
 */
function buildStylesTask() {
    return src('./src/assets/sass/**/*.scss')
        .pipe(plumber())
        .pipe(sass().on('error', logPluginError))
        .pipe(plumber.stop())
        .pipe(gulpif(environment.isProduction, cssnano()))
        .pipe(dest('./dist/assets/css'));
}

/**
 * Watch for script changes and pipes the modified files into the build destination folder.
 */
function watchScriptsTask() {
    return watch('./src/assets/js/**/*.js')
        .pipe(dest('./dist/assets/js'))
        .pipe(browserSyncInstance.stream());
}

/**
 * Beautify (development) or uglify (production) JS files and pipes them into the build destination
 * folder. Any scripts already minified will be copied as-is.
 */
function buildScriptsTask() {
    return merge2(
        src(['./src/assets/js/**/*.js', '!**/*.min.js'])
            .pipe(gulpif(environment.isProduction, uglify())),
        src('./src/assets/js/**/*.min.js')
    ).pipe(dest('./dist/assets/js'));
}

/**
 * Watch for template changes and pipes the modified files into the build destination folder.
 */
function watchTemplateTask() {
    return watch('./src/**/!(*.js|*.scss)')
        .pipe(dest('./dist'))
        .pipe(browserSyncInstance.stream());
}

/**
 * Minify the main HTML template and pipes it into the build destination folder along with all
 * related files not previously processed by other tasks.
 */
function buildTemplateTask() {
    return merge2(
        src('./src/index.html')
            .pipe(gulpif(environment.isProduction, ssi({ root: './' })))
            .pipe(gulpif(environment.isProduction, htmlmin({
                collapseBooleanAttributes: true,
                collapseWhitespace: true,
                minifyCSS: true,
                minifyJS: true,
                removeComments: true,
                removeEmptyAttributes: true,
                removeOptionalTags: true,
                removeRedundantAttributes: true
            }))),
        src('./src/**/!(*.html|*.js|*.scss)', { nodir: true })
    ).pipe(dest('./dist'));
}

/**
 * Compile source files and launch `browser-sync` development server. Changes you make will either
 * be injected into the page (CSS and images) or will cause all browsers to do a full-page refresh.
 *
 * @export `development` task.
 */
export const development = series(
    parallel(buildStylesTask, buildScriptsTask, buildTemplateTask),
    parallel(watchStylesTask, watchScriptsTask, watchTemplateTask, initializeBrowserSync)
);

/**
 * Compile source files ready for deployment to GitHub pages.
 *
 * @export `production` task.
 */
export const production = parallel(buildStylesTask, buildScriptsTask, buildTemplateTask);<commit_msg>Cleanup Gulp tasks documentation<commit_after>import { dest, parallel, series, src } from 'gulp';

import browserSync from 'browser-sync';
import cssnano from 'gulp-cssnano';
import envalid from 'envalid';
import gulpif from 'gulp-if';
import htmlmin from 'gulp-htmlmin';
import merge2 from 'merge2';
import plumber from 'gulp-plumber';
import sass from 'gulp-sass';
import ssi from 'gulp-ssi';
import uglify from 'gulp-uglify';
import util from 'gulp-util';
import watch from 'gulp-watch';

const environment = envalid.cleanEnv(process.env);
const browserSyncInstance = browserSync.create();

/**
 * Auxiliary function to log a plugin error with color support and a formatted message.
 *
 * @param {object} event Event information pertaining to an `EventEmitter` event.
 */
function logPluginError(event) {
    util.log(new util.PluginError(event.plugin, event.formatted).toString());
}

/**
 * Launch the Browsersync HTTP server while watching for file changes and refreshing the browser
 * or injecting assets on-the-fly.
 */
function initializeBrowserSync() {
    browserSyncInstance.init({
        files: './dist/**/*',
        server: './dist',
        online: false,
        open: false
    });
}

/**
 * Watch style related files for changes and pipe the modified ones into the build destination
 * folder, eventually notifying Browsersync of all changes causing a browser reload.
 */
function watchStylesTask() {
    return watch('./src/assets/sass/**/*.scss')
        .pipe(plumber())
        .pipe(sass().on('error', logPluginError))
        .pipe(plumber.stop())
        .pipe(dest('./dist/assets/css'))
        .pipe(browserSyncInstance.stream());
}

/**
 * Build style related files for either production or development. If building for production,
 * all CSS files will be minified and optimized.
 */
function buildStylesTask() {
    return src('./src/assets/sass/**/*.scss')
        .pipe(plumber())
        .pipe(sass().on('error', logPluginError))
        .pipe(plumber.stop())
        .pipe(gulpif(environment.isProduction, cssnano()))
        .pipe(dest('./dist/assets/css'));
}

/**
 * Watch script related files for changes and pipe the modified ones into the build destination
 * folder, eventually notifying Browsersync of all changes causing a browser reload.
 */
function watchScriptsTask() {
    return watch('./src/assets/js/**/*.js')
        .pipe(dest('./dist/assets/js'))
        .pipe(browserSyncInstance.stream());
}

/**
 * Build script related files for either production or development. If building for production,
 * all JS filles will be uglified.
 */
function buildScriptsTask() {
    return merge2(
        src(['./src/assets/js/**/*.js', '!**/*.min.js'])
            .pipe(gulpif(environment.isProduction, uglify())),
        src('./src/assets/js/**/*.min.js')
    ).pipe(dest('./dist/assets/js'));
}

/**
 * Watch template related files for changes and pipe the modified ones into the build destination
 * folder, eventually notifying Browsersync of all changes causing a browser reload.
 */
function watchTemplateTask() {
    return watch('./src/**/!(*.js|*.scss)')
        .pipe(dest('./dist'))
        .pipe(browserSyncInstance.stream());
}

/**
 * Build template related files for either production or development. If building for production,
 * all HTML will be minified and server-side includes will be parsed.
 */
function buildTemplateTask() {
    return merge2(
        src('./src/index.html')
            .pipe(gulpif(environment.isProduction, ssi({ root: './' })))
            .pipe(gulpif(environment.isProduction, htmlmin({
                collapseBooleanAttributes: true,
                collapseWhitespace: true,
                minifyCSS: true,
                minifyJS: true,
                removeComments: true,
                removeEmptyAttributes: true,
                removeOptionalTags: true,
                removeRedundantAttributes: true
            }))),
        src('./src/**/!(*.html|*.js|*.scss)', { nodir: true })
    ).pipe(dest('./dist'));
}

/**
 * Compile source files and launch a Browsersync development server. Changes made will either be
 * injected into the page or will cause all browsers to do a full-page refresh.
 *
 * @export `development` task.
 */
export const development = series(
    parallel(buildStylesTask, buildScriptsTask, buildTemplateTask),
    parallel(watchStylesTask, watchScriptsTask, watchTemplateTask, initializeBrowserSync)
);

/**
 * Compile source files ready for deployment to GitHub pages.
 *
 * @export `production` task.
 */
export const production = parallel(buildStylesTask, buildScriptsTask, buildTemplateTask);
{'fraction_non_alphanumeric': 0.1333703498056635, 'fraction_numerical': 0.0008883953359244864, 'mean_word_length': 3.196644920782852, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '302816', 'n_tokens_mistral': 2522, 'n_tokens_neox': 2477, 'n_words': 760}