<commit_before>const gulp = require('gulp');
const gulpLoadPlugins = require('gulp-load-plugins');
const del = require('del');
const $ = gulpLoadPlugins();
const bower = require('./bower.json');
const fs = require('fs');
const ssri = require('ssri');

// ===============================================================
// PLUGIN SETTINGS SHARED ACCROSS MULTIPLE TASKS
// ===============================================================
const revManifestsBase = '.tmp/rev-manifests';

// ===============================================================
// ENVIROMENT VARIABLES
// ===============================================================
let ENV = 'dist';
let DEST = 'dist';

const setEnvDev = () => new Promise((resolve, reject) => {
							ENV = 'dev';
							resolve();
						});

const setDestDev = () => new Promise((resolve, reject) => {
							DEST = 'dev';
							resolve();
						});

// ===============================================================
// CLEAN
// ===============================================================
// Empty directories to start fresh.
const clean = () => del(['.tmp', 'dev', 'dist']);

// ===============================================================
// SCSS -> CSS
// ===============================================================
const sass = () => gulp.src('src/assets/scss/*.scss')
					.pipe($.plumber())
					.pipe($.sass({
						includePaths: ['src/assets/scss', 'bower_components'],
						precision: 6
					}).on('error', $.sass.logError))
					.pipe(gulp.dest('.tmp/css/compiled'));

// ===============================================================
// CONCAT CSS
// ===============================================================
// Source should be compiled CSS (.tmp/css/copmiled), resp. vendor CSS (bower_components resp. src/assets/vendor/css).
const concatCSS = () => gulp.src([
							'bower_components/normalize.css/normalize.css',
							'.tmp/css/compiled/main.css'
						])
						.pipe($.concat('main.css'))
						.pipe(gulp.dest('.tmp/css/concated'));

// ===============================================================
// CSS PROCESSING
// ===============================================================
const processCSS = () => {
	var stream = gulp.src('.tmp/css/concated/**/*.css')
		.pipe($.autoprefixer());

	if ( ENV == 'dist' ) {
		return stream
			.pipe($.combineMq())
			.pipe($.cleanCss())
			.pipe($.rev())
			.pipe(gulp.dest(DEST + '/assets/css'))
			.pipe($.rev.manifest(revManifestsBase + '/css.json', {
				base: revManifestsBase
			}))
			.pipe(gulp.dest(revManifestsBase));
	}
	else {
		return stream
			.pipe($.combineMq())
			.pipe(gulp.dest(DEST + '/assets/css'))
			.pipe($.connect.reload());
	}
};

// ===============================================================
// MAIN CSS TASK
// ===============================================================
const css = gulp.series(sass, concatCSS, processCSS);

// ===============================================================
// CONCAT JS
// ===============================================================
const concatJSMain = () => gulp.src([
								'src/assets/js/plugins.js',
								'src/assets/js/main.js'
							])
							.pipe($.concat('main.js'))
							.pipe(gulp.dest('.tmp/js/concated'));

const concatJS = gulp.series(
	concatJSMain
);

// ===============================================================
// JS PROCESSING
// ===============================================================
const processJS = () => {
	var stream = gulp.src('.tmp/js/concated/**/*.js');

	if ( ENV == 'dist' ) {
		return stream
			.pipe($.uglify())
			.pipe($.rev())
			.pipe(gulp.dest(DEST + '/assets/js'))
			.pipe($.rev.manifest(revManifestsBase + '/js.json', {
				base: revManifestsBase
			}))
			.pipe(gulp.dest(revManifestsBase));
	}
	else {
		return stream
			.pipe(gulp.dest(DEST + '/assets/js'))
			.pipe($.connect.reload());
	}
};

// ===============================================================
// MAIN JS TASK
// ===============================================================
const js = gulp.series(concatJS, processJS);

// ===============================================================
// IMAGE PROCESSING
// ===============================================================
const img = () => gulp.src([
						'src/assets/img/**/*.{gif,jpg,png,svg}'
					])
					.pipe($.if(ENV == 'dist', $.imagemin()))
					.pipe(gulp.dest(DEST + '/assets/img'))
					.pipe($.connect.reload());

// ===============================================================
// COPY FILES
// ===============================================================
const copyMisc = () => gulp.src([
							'src/robots.txt',
							'src/browserconfig.xml',
							'src/*.{ico,png,svg}', // icons
							'src/assets/font/**/*.{woff,woff2}',
							'!src/assets/font/original/**/*'
						], {
							base: 'src'
						})
						.pipe(gulp.dest(DEST))
						.pipe($.connect.reload());

const copyModules = () => gulp.src([
								'node_modules/apache-server-configs/dist/.htaccess'
							])
							.pipe(gulp.dest(DEST));

const copyJQuery = () => gulp.src([
								'bower_components/jquery/dist/jquery.min.js'
							])
							.pipe($.rename('jquery-'+bower.dependencies.jquery+'.min.js'))
							.pipe(gulp.dest(DEST + '/assets/js/vendor'));

const copy = gulp.parallel(
	copyMisc,
	copyModules,
	copyJQuery
);

// ===============================================================
// HTML PROCESSING
// ===============================================================
const html = () => {
	var manifests = gulp.src(revManifestsBase + '/*.json'),
		jquerySRIHash = ssri.fromData(
			fs.readFileSync('bower_components/jquery/dist/jquery.min.js'),
			{ algorithms: ['sha256'] }
		);

	return gulp.src('src/templates/pages/**/*.twig')
		.pipe($.twig({
			data: {
				jquery: {
					version: bower.dependencies.jquery,
					sri_hash: jquerySRIHash
				}
			},
			errorLogToConsole: true,
			extname: '.html'
		}))
		.pipe($.if(ENV == 'dist', $.revReplace({
			canonicalUris: false,<commit_msg>`var` -> `const` & `let`<commit_after>const gulp = require('gulp');
const gulpLoadPlugins = require('gulp-load-plugins');
const del = require('del');
const $ = gulpLoadPlugins();
const bower = require('./bower.json');
const fs = require('fs');
const ssri = require('ssri');

// ===============================================================
// PLUGIN SETTINGS SHARED ACCROSS MULTIPLE TASKS
// ===============================================================
const revManifestsBase = '.tmp/rev-manifests';

// ===============================================================
// ENVIROMENT VARIABLES
// ===============================================================
let ENV = 'dist';
let DEST = 'dist';

const setEnvDev = () => new Promise((resolve, reject) => {
							ENV = 'dev';
							resolve();
						});

const setDestDev = () => new Promise((resolve, reject) => {
							DEST = 'dev';
							resolve();
						});

// ===============================================================
// CLEAN
// ===============================================================
// Empty directories to start fresh.
const clean = () => del(['.tmp', 'dev', 'dist']);

// ===============================================================
// SCSS -> CSS
// ===============================================================
const sass = () => gulp.src('src/assets/scss/*.scss')
					.pipe($.plumber())
					.pipe($.sass({
						includePaths: ['src/assets/scss', 'bower_components'],
						precision: 6
					}).on('error', $.sass.logError))
					.pipe(gulp.dest('.tmp/css/compiled'));

// ===============================================================
// CONCAT CSS
// ===============================================================
// Source should be compiled CSS (.tmp/css/copmiled), resp. vendor CSS (bower_components resp. src/assets/vendor/css).
const concatCSS = () => gulp.src([
							'bower_components/normalize.css/normalize.css',
							'.tmp/css/compiled/main.css'
						])
						.pipe($.concat('main.css'))
						.pipe(gulp.dest('.tmp/css/concated'));

// ===============================================================
// CSS PROCESSING
// ===============================================================
const processCSS = () => {
	const stream = gulp.src('.tmp/css/concated/**/*.css')
		.pipe($.autoprefixer());

	if ( ENV == 'dist' ) {
		return stream
			.pipe($.combineMq())
			.pipe($.cleanCss())
			.pipe($.rev())
			.pipe(gulp.dest(DEST + '/assets/css'))
			.pipe($.rev.manifest(revManifestsBase + '/css.json', {
				base: revManifestsBase
			}))
			.pipe(gulp.dest(revManifestsBase));
	}
	else {
		return stream
			.pipe($.combineMq())
			.pipe(gulp.dest(DEST + '/assets/css'))
			.pipe($.connect.reload());
	}
};

// ===============================================================
// MAIN CSS TASK
// ===============================================================
const css = gulp.series(sass, concatCSS, processCSS);

// ===============================================================
// CONCAT JS
// ===============================================================
const concatJSMain = () => gulp.src([
								'src/assets/js/plugins.js',
								'src/assets/js/main.js'
							])
							.pipe($.concat('main.js'))
							.pipe(gulp.dest('.tmp/js/concated'));

const concatJS = gulp.series(
	concatJSMain
);

// ===============================================================
// JS PROCESSING
// ===============================================================
const processJS = () => {
	const stream = gulp.src('.tmp/js/concated/**/*.js');

	if ( ENV == 'dist' ) {
		return stream
			.pipe($.uglify())
			.pipe($.rev())
			.pipe(gulp.dest(DEST + '/assets/js'))
			.pipe($.rev.manifest(revManifestsBase + '/js.json', {
				base: revManifestsBase
			}))
			.pipe(gulp.dest(revManifestsBase));
	}
	else {
		return stream
			.pipe(gulp.dest(DEST + '/assets/js'))
			.pipe($.connect.reload());
	}
};

// ===============================================================
// MAIN JS TASK
// ===============================================================
const js = gulp.series(concatJS, processJS);

// ===============================================================
// IMAGE PROCESSING
// ===============================================================
const img = () => gulp.src([
						'src/assets/img/**/*.{gif,jpg,png,svg}'
					])
					.pipe($.if(ENV == 'dist', $.imagemin()))
					.pipe(gulp.dest(DEST + '/assets/img'))
					.pipe($.connect.reload());

// ===============================================================
// COPY FILES
// ===============================================================
const copyMisc = () => gulp.src([
							'src/robots.txt',
							'src/browserconfig.xml',
							'src/*.{ico,png,svg}', // icons
							'src/assets/font/**/*.{woff,woff2}',
							'!src/assets/font/original/**/*'
						], {
							base: 'src'
						})
						.pipe(gulp.dest(DEST))
						.pipe($.connect.reload());

const copyModules = () => gulp.src([
								'node_modules/apache-server-configs/dist/.htaccess'
							])
							.pipe(gulp.dest(DEST));

const copyJQuery = () => gulp.src([
								'bower_components/jquery/dist/jquery.min.js'
							])
							.pipe($.rename('jquery-'+bower.dependencies.jquery+'.min.js'))
							.pipe(gulp.dest(DEST + '/assets/js/vendor'));

const copy = gulp.parallel(
	copyMisc,
	copyModules,
	copyJQuery
);

// ===============================================================
// HTML PROCESSING
// ===============================================================
const html = () => {
	const manifests = gulp.src(revManifestsBase + '/*.json');
	const jquerySRIHash = ssri.fromData(
			fs.readFileSync('bower_components/jquery/dist/jquery.min.js'),
			{ algorithms: ['sha256'] }
		);

	return gulp.src('src/templates/pages/**/*.twig')
		.pipe($.twig({
			data: {
				jquery: {
					version: bower.dependencies.jquery,
					sri_hash: jquerySRIHash
				}
			},
			errorLogToConsole: true,
			extname: '.html'
		}))
		.pipe($.if(ENV == 'dist', $.revReplace({
			canonicalUris: false,
{'fraction_non_alphanumeric': 0.4302248126561199, 'fraction_numerical': 0.0008326394671107411, 'mean_word_length': 3.9714403973509933, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '5969782', 'n_tokens_mistral': 4248, 'n_tokens_neox': 3472, 'n_words': 524}