<commit_before>// This file is a part of Grid - Copyright (c) 2016 <NAME> | For the full copyright and license information, please view the file license.md that was distributed with this source code.

"use strict";

const

	// Modules
	autoprefixer  = require('gulp-autoprefixer'),
	cleanCss = require('gulp-clean-css'),
	gulp  = require('gulp'),
	pipe_if = require('gulp-if'),
	plumber = require('gulp-plumber'),
	rename = require('gulp-rename'),
	sass = require('gulp-sass'),
	sourcemaps = require('gulp-sourcemaps'),
	fs = require('fs'),

	// Setup
	directories = {
		dist: __dirname + '/dist',
		src: __dirname + '/src',
		tests: __dirname + '/tests',
		watch: __dirname + '/src/**/*.sass',
		sourcemaps: __dirname + '/',
		ampTestParts: __dirname + '/tests/amp-test-parts'
	},

	targetFiles = {
		grid: directories.src + '/grid.sass',
		gridMobile: directories.src + '/grid.mobile.sass',
		testsHelpers: directories.tests + '/helpers/tests-helpers.sass'
	},

	autoprefixerPrefixes = {
		mobile: ['iOS >= 6', 'Android >= 4.1', 'UCAndroid >= 11', 'ExplorerMobile >= 11'],
		desktop: ['> 5%', 'last 2 versions', 'IE 10'],
	},

	autoprefixerSettings = autoprefixerPrefixes.desktop.concat(autoprefixerPrefixes.desktop),
	minVersionSuffix = 'min',
	defaultFileType = 'css',

	tasks = {
		grid: null,

		gridMin: {
			minify: true
		},

		gridDev: {
			noPrefixes: true,
			cssMap: false,
			fileType: 'scss',
		},

		gridMobile: {
			targetFile: targetFiles.gridMobile,
			prefixes:  autoprefixerPrefixes.mobile
		},

		gridMobileMin: {
			targetFile: targetFiles.gridMobile,
			minify: true
		},

		gridMobileDev: {
			targetFile: targetFiles.gridMobile,
			noPrefixes: true,
			cssMap: false,
			fileType: 'scss',
		},

		gridTestable: {
			targetFile: targetFiles.grid,
			prefixes: autoprefixerSettings.concat(['Safari >= 4']),
			outputDir: directories.tests,
			cssMap: false
		},

		testsHelpers: {
			minify: true,
			targetFile: targetFiles.testsHelpers,
			outputDir: directories.tests,
			cssMap: false
		}
	};

// Watch and default tasks
gulp
	.task('compile', compile)

	.task('watch', function() {
		gulp.watch(directories.watch, ['compile']);
	})

	.task('default', ['compile', 'watch'])

	.task ('generate-amp-test-file', generateAmpTestFile);


/**
 * @param {object} settings
 * @param {string} settingsOption
 * @param {string} settingsType
 * @returns {boolean}
 */
function settingsExist(settings, settingsOption, settingsType) {
	return settingsOption in settings && typeof settings[settingsOption] === settingsType;
}


function compile() {

	for (var task in tasks) {
		var minify = false,
			targetFile = targetFiles.grid,
			prefixes = autoprefixerSettings,
			prefixesAllowed = true,
			fileType = defaultFileType,
			fileSuffix = minVersionSuffix,
			outputDir = directories.dist,
			cssMap = true,

			taskSettings = tasks[task];

		if (taskSettings && typeof taskSettings === 'object') {
			if (settingsExist(taskSettings, 'minify', 'boolean')) minify = taskSettings.minify;
			if (settingsExist(taskSettings, 'targetFile', 'string')) targetFile = taskSettings.targetFile;
			if (settingsExist(taskSettings, 'cssMap', 'boolean')) cssMap = taskSettings.cssMap;
			if (settingsExist(taskSettings, 'fileType', 'string')) fileType = taskSettings.fileType;
			if (settingsExist(taskSettings, 'noPrefixes', 'boolean')) prefixesAllowed = ! taskSettings.noPrefixes;
			if (settingsExist(taskSettings, 'prefixes', 'object')) prefixes = taskSettings.prefixes;
			if (settingsExist(taskSettings, 'outputDir', 'string')) outputDir = taskSettings.outputDir;
		}

		gulp.src(targetFile)
			.pipe(plumber())
			.pipe(sourcemaps.init())
			.pipe(sass())
			.pipe(pipe_if(prefixesAllowed, autoprefixer({
					browsers: prefixes
				})
			))
			.pipe(pipe_if(minify, cleanCss()))
			.pipe(pipe_if(minify, rename({
					suffix: '.' + fileSuffix
				})
			))
			.pipe(rename({
					extname: '.' + fileType
				})
			)
			.pipe(pipe_if(cssMap, sourcemaps.write(directories.sourcemaps)))
			.pipe(gulp.dest(outputDir));
	}

}

function generateAmpTestFile() {
	var
		partBeforeStyle = fs.readFileSync(directories.ampTestParts + "/before-style.txt", 'utf8'),
		partAfterStyle = fs.readFileSync(directories.ampTestParts + "/after-style.txt", 'utf8'),
		gridMobileCss = fs.readFileSync(directories.dist + "/grid.mobile.css", 'utf8'),
		fileContent = partBeforeStyle + gridMobileCss + partAfterStyle;

	fs.writeFile(directories.tests + '/amp-test.html', fileContent);
}<commit_msg>- v2.0 - Updated gulpfile<commit_after>// This file is a part of Grid - Copyright (c) 2016 <NAME> | For the full copyright and license information, please view the file license.md that was distributed with this source code.

"use strict";

const

	// Modules
	autoprefixer  = require('gulp-autoprefixer'),
	cleanCss = require('gulp-clean-css'),
	gulp  = require('gulp'),
	pipe_if = require('gulp-if'),
	plumber = require('gulp-plumber'),
	rename = require('gulp-rename'),
	sass = require('gulp-sass'),
	sourcemaps = require('gulp-sourcemaps'),
	fs = require('fs'),

	// Setup
	directories = {
		dist: 'dist',
		src: 'src',
		tests: 'tests',
		watch: 'src/**/*.sass',
		sourcemaps: '/',
		ampTestParts: 'tests/amp-test-parts'
	},

	targetFiles = {
		grid: directories.src + '/grid.sass',
		gridMobile: directories.src + '/grid.mobile.sass',
		testsHelpers: directories.tests + '/helpers/tests-helpers.sass'
	},

	autoprefixerPrefixes = {
		mobile: ['iOS >= 6', 'Android >= 4.1', 'UCAndroid >= 11', 'ExplorerMobile >= 11'],
		desktop: ['> 5%', 'last 2 versions', 'IE 10'],
	},

	autoprefixerSettings = autoprefixerPrefixes.desktop.concat(autoprefixerPrefixes.desktop),
	minVersionSuffix = 'min',
	defaultFileType = 'css',

	tasks = {
		grid: null,

		gridMin: {
			minify: true
		},

		gridDev: {
			noPrefixes: true,
			cssMap: false,
			fileType: 'scss',
		},

		gridMobile: {
			targetFile: targetFiles.gridMobile,
			prefixes:  autoprefixerPrefixes.mobile
		},

		gridMobileMin: {
			targetFile: targetFiles.gridMobile,
			minify: true
		},

		gridMobileDev: {
			targetFile: targetFiles.gridMobile,
			noPrefixes: true,
			cssMap: false,
			fileType: 'scss',
		},

		gridTestable: {
			targetFile: targetFiles.grid,
			prefixes: autoprefixerSettings.concat(['Safari >= 4']),
			outputDir: directories.tests,
			cssMap: false
		},

		testsHelpers: {
			minify: true,
			targetFile: targetFiles.testsHelpers,
			outputDir: directories.tests,
			cssMap: false
		}
	};

// Watch and default tasks
gulp
	.task('compile', compile)

	.task('watch', function() {
		gulp.watch(directories.watch, ['compile']);
	})

	.task('default', ['compile', 'watch'])

	.task ('generate-amp-test-file', generateAmpTestFile);


/**
 * @param {object} settings
 * @param {string} settingsOption
 * @param {string} settingsType
 * @returns {boolean}
 */
function settingsExist(settings, settingsOption, settingsType) {
	return settingsOption in settings && typeof settings[settingsOption] === settingsType;
}


function compile() {

	for (var task in tasks) {
		var minify = false,
			targetFile = targetFiles.grid,
			prefixes = autoprefixerSettings,
			prefixesAllowed = true,
			fileType = defaultFileType,
			fileSuffix = minVersionSuffix,
			outputDir = directories.dist,
			cssMap = true,

			taskSettings = tasks[task];

		if (taskSettings && typeof taskSettings === 'object') {
			if (settingsExist(taskSettings, 'minify', 'boolean')) minify = taskSettings.minify;
			if (settingsExist(taskSettings, 'targetFile', 'string')) targetFile = taskSettings.targetFile;
			if (settingsExist(taskSettings, 'cssMap', 'boolean')) cssMap = taskSettings.cssMap;
			if (settingsExist(taskSettings, 'fileType', 'string')) fileType = taskSettings.fileType;
			if (settingsExist(taskSettings, 'noPrefixes', 'boolean')) prefixesAllowed = ! taskSettings.noPrefixes;
			if (settingsExist(taskSettings, 'prefixes', 'object')) prefixes = taskSettings.prefixes;
			if (settingsExist(taskSettings, 'outputDir', 'string')) outputDir = taskSettings.outputDir;
		}

		gulp.src(targetFile)
			.pipe(plumber())
			.pipe(sourcemaps.init())
			.pipe(sass())
			.pipe(pipe_if(prefixesAllowed, autoprefixer({
					browsers: prefixes
				})
			))
			.pipe(pipe_if(minify, cleanCss()))
			.pipe(pipe_if(minify, rename({
					suffix: '.' + fileSuffix
				})
			))
			.pipe(rename({
					extname: '.' + fileType
				})
			)
			.pipe(pipe_if(cssMap, sourcemaps.write(directories.sourcemaps)))
			.pipe(gulp.dest(outputDir));
	}

}

function generateAmpTestFile() {
	var
		partBeforeStyle = fs.readFileSync(directories.ampTestParts + "/before-style.txt", 'utf8'),
		partAfterStyle = fs.readFileSync(directories.ampTestParts + "/after-style.txt", 'utf8'),
		gridMobileCss = fs.readFileSync(directories.dist + "/grid.mobile.css", 'utf8'),
		fileContent = partBeforeStyle + gridMobileCss + partAfterStyle;

	fs.writeFile(directories.tests + '/amp-test.html', fileContent, function () {
		console.log ('Amp test file successfully generated')
	});
}
{'fraction_non_alphanumeric': 0.1501782531194296, 'fraction_numerical': 0.004456327985739751, 'mean_word_length': 4.283696291936433, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '444525', 'n_tokens_mistral': 3372, 'n_tokens_neox': 3004, 'n_words': 624}