<commit_before>/*
Builds client JS and CSS
 */
'use strict'

const _ = require('underscore'),
	cache = require('gulp-cached'),
	fs = require('fs-extra'),
	gulp = require('gulp'),
	gutil = require('gulp-util'),
	jsonminify = require('gulp-jsonminify'),
	less = require('gulp-less'),
	nano = require('gulp-cssnano'),
	rename = require('gulp-rename'),
	sourcemaps = require('gulp-sourcemaps'),
	ts = require('gulp-typescript'),
	uglify = require('gulp-uglify')

fs.mkdirsSync('./www/js/vendor')

// Keep script alive and rebuild on file changes
// Triggered with the `-w` flag
const watch = gutil.env.w

// Dependancy tasks for the default tasks
const tasks = []

// Client JS files
buildClient()

// Various little scripts
createTask('scripts', './clientScripts/*.js', src =>
	src
		.pipe(sourcemaps.init())
		.pipe(uglify())
		.pipe(sourcemaps.write('./maps'))
		.pipe(gulp.dest('./www/js/scripts')))

// Compile Less to CSS
createTask('css', './less/*.less', src =>
	src
		.pipe(sourcemaps.init())
		.pipe(less())
		.pipe(nano())
		.pipe(sourcemaps.write('./maps'))
		.pipe(gulp.dest('./www/css')))

// Language packs
createTask('lang', './lang/*.json', src =>
	src
		.pipe(jsonminify())
		.pipe(gulp.dest('./www/lang')))

// Dependancy libraries
copyVendor([
	'./node_modules/systemjs/dist/system.js',
	'./node_modules/systemjs/dist/system.js.map',
	'./node_modules/dom4/build/dom4.js',
	'./node_modules/underscore/underscore-min.js',
	'./node_modules/underscore/underscore-min.map'
])
compileVendor('stack-blur', './lib/stack-blur.js')

gulp.task('default', tasks)

const tsProject = ts.createProject('./client/tsconfig.json')

// Builds the client files of the apropriate ECMAScript version
function buildClient() {
	const name = 'client',
		path = './client/**/*.ts'
	tasks.push(name)
	gulp.task(name, () =>
		gulp.src(path)
			.on('error', gutil.log)
			.pipe(sourcemaps.init())
			.pipe(ts(tsProject))
			.pipe(sourcemaps.write('./maps'))
			.pipe(gulp.dest('./www/js/')))

	// Recompile on source update, if running with the `-w` flag
	if (watch) {
		gulp.watch(path, [name])
	}
}

// Create a new gulp taks and set it to execute on default and incrementally
function createTask(name, path, task) {
	tasks.push(name)
	gulp.task(name, () =>
		task(gulp.src(path)
			.on('error', gutil.log)
			.pipe(cache(name))))

	// Recompile on source update, if running with the `-w` flag
	if (watch) {
		gulp.watch(path, [name])
	}
}

// Copy a dependancy library, minify and generate sourcemaps
function compileVendor(name, path) {
	createTask(name, path, src =>
		src
			.pipe(rename({basename: name}))
			.pipe(sourcemaps.init())
			.pipe(uglify())
			.pipe(sourcemaps.write('./maps'))
			.pipe(gulp.dest('./www/js/vendor')))
}

// Copies a dependancy library from node_modules to the vendor directory
function copyVendor(paths) {
	for (let path of paths) {
		fs.copySync(
			path,
			'./www/js/vendor/' + _.last(path.split('/')),
			{clobber: true}
		)
	}
}<commit_msg>guplfile Abort build on TS syntax errors in non-watch mode<commit_after>/*
Builds client JS and CSS
 */
'use strict'

const _ = require('underscore'),
	cache = require('gulp-cached'),
	fs = require('fs-extra'),
	gulp = require('gulp'),
	gutil = require('gulp-util'),
	jsonminify = require('gulp-jsonminify'),
	less = require('gulp-less'),
	nano = require('gulp-cssnano'),
	rename = require('gulp-rename'),
	sourcemaps = require('gulp-sourcemaps'),
	ts = require('gulp-typescript'),
	uglify = require('gulp-uglify')

fs.mkdirsSync('./www/js/vendor')

// Keep script alive and rebuild on file changes
// Triggered with the `-w` flag
const watch = gutil.env.w

// Dependancy tasks for the default tasks
const tasks = []

// Client JS files
buildClient()

// Various little scripts
createTask('scripts', './clientScripts/*.js', src =>
	src
		.pipe(sourcemaps.init())
		.pipe(uglify())
		.on('error', handleError)
		.pipe(sourcemaps.write('./maps'))
		.pipe(gulp.dest('./www/js/scripts')))

// Compile Less to CSS
createTask('css', './less/*.less', src =>
	src
		.pipe(sourcemaps.init())
		.pipe(less())
		.on('error', handleError)
		.pipe(nano())
		.pipe(sourcemaps.write('./maps'))
		.pipe(gulp.dest('./www/css')))

// Language packs
createTask('lang', './lang/*.json', src =>
	src
		.pipe(jsonminify())
		.on('error', handleError)
		.pipe(gulp.dest('./www/lang')))

// Dependancy libraries
copyVendor([
	'./node_modules/systemjs/dist/system.js',
	'./node_modules/systemjs/dist/system.js.map',
	'./node_modules/dom4/build/dom4.js',
	'./node_modules/underscore/underscore-min.js',
	'./node_modules/underscore/underscore-min.map'
])
compileVendor('stack-blur', './lib/stack-blur.js')

gulp.task('default', tasks)

const tsProject = ts.createProject('./client/tsconfig.json')

// Builds the client files of the apropriate ECMAScript version
function buildClient() {
	const name = 'client',
		path = './client/**/*.ts'
	tasks.push(name)
	gulp.task(name, () =>
		gulp.src(path)
			.pipe(sourcemaps.init())
			.pipe(ts(tsProject))
			.on('error', handleError)
			.pipe(sourcemaps.write('./maps'))
			.pipe(gulp.dest('./www/js/')))

	// Recompile on source update, if running with the `-w` flag
	if (watch) {
		gulp.watch(path, [name])
	}
}

// Simply log the error on continous builds, but fail the build and exit with
// an error status, if failing a one-time build. This way we can use failure to
// build the client to not pass Travis CL tests.
function handleError(err) {
	if (!watch) {
		throw err
	}
}

// Create a new gulp taks and set it to execute on default and incrementally
function createTask(name, path, task) {
	tasks.push(name)
	gulp.task(name, () =>
		task(gulp.src(path).pipe(cache(name))))

	// Recompile on source update, if running with the `-w` flag
	if (watch) {
		gulp.watch(path, [name])
	}
}

// Copy a dependancy library, minify and generate sourcemaps
function compileVendor(name, path) {
	createTask(name, path, src =>
		src
			.pipe(rename({basename: name}))
			.pipe(sourcemaps.init())
			.pipe(uglify())
			.on('error', handleError)
			.pipe(sourcemaps.write('./maps'))
			.pipe(gulp.dest('./www/js/vendor')))
}

// Copies a dependancy library from node_modules to the vendor directory
function copyVendor(paths) {
	for (let path of paths) {
		fs.copySync(
			path,
			'./www/js/vendor/' + _.last(path.split('/')),
			{clobber: true}
		)
	}
}
{'fraction_non_alphanumeric': 0.1852202747513027, 'fraction_numerical': 0.0006316121901152693, 'mean_word_length': 3.8388082505729564, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 14, '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': '5772361', 'n_tokens_mistral': 2380, 'n_tokens_neox': 2252, 'n_words': 516}