<commit_before>'use strict';

const os = require('os');
const path = require('path');
const gulp = require('gulp');
const clean = require('gulp-clean');
const eslint = require('gulp-eslint');
const sequence = require('gulp-sequence');
const mocha = require('gulp-mocha');
const istanbul = require('gulp-istanbul');
const sourcemapSupport = require('source-map-support');
const compiler = require('./compiler');
const instrumenter = require('./instrumenter');
const childProcess = require('child_process');
const fs = require('fs-extra');

const buildFolder = 'build';
const resourcesFolder = 'resources';
const sourcesPattern = 'src/**/*.js';
const testsPattern = 'test/**/*.js';
const integrationTestsPattern = 'integration/**/*.js';
const buildReleaseFolder = path.join(buildFolder, 'release');
const buildInstrumentFolder = path.join(buildFolder, 'instrument');
const buildTestFolder = path.join(buildFolder, 'test');
const buildTestDataFolder = path.join(buildTestFolder, 'test-output');
const builtSources = path.join(buildTestFolder, sourcesPattern);
const instrumentedSources = path.join(buildInstrumentFolder, sourcesPattern);
const builtTests = path.join(buildTestFolder, testsPattern);
const builtIntegrationTests = path.join(buildTestFolder, 'integration/**/*.js');
const babelCompiler = compiler.create();
const istanbulInstrumenter = instrumenter.create();

const mochaOptions = {
	reporter: 'spec',
	timeout: 10000
};

const mochaIntegrationTestOptions = Object.assign({}, mochaOptions);

const istanbulOptions = {
	fail: true,
	reporters: ['json', 'html'],
	reportOpts: {
		json: {
			dir: path.join(buildFolder, 'reports'),
			file: 'coverage.json'
		},
		html: {
			dir: path.join(buildFolder, 'reports', 'html')
		}
	}
};

gulp.task('clean', () => {
	return gulp.src(buildFolder)
		.pipe(clean());
});

gulp.task('log-environment', () => {
	console.log('Operating System Type     : ' + os.type());
	console.log('Operating System Release  : ' + os.release());
	console.log('Hostname                  : ' + os.hostname());
	console.log('Free System Memory        : ' + os.freemem());
	console.log('Node Version              : ' + process.versions.node);
});

gulp.task('initialize', () => {
	fs.mkdirsSync(buildFolder);
});

gulp.task('lint', () => {
	return gulp.src([sourcesPattern, testsPattern])
		.pipe(eslint())
		.pipe(eslint.format())
		.pipe(eslint.failAfterError());
});

gulp.task('compile:release', () => {
	return babelCompiler.compile({
		sourcesPattern,
		outputFolder: buildReleaseFolder,
		srcBase: '.'
	});
});

gulp.task('compile:instrument:src', () => {
	return istanbulInstrumenter.instrument({
		sourcesPattern: sourcesPattern,
		outputFolder: buildInstrumentFolder
	});
});

gulp.task('compile:test:src', () => {
	return babelCompiler.compile({
		sourcesPattern: instrumentedSources,
		outputFolder: buildTestFolder,
		srcBase: buildInstrumentFolder
	});
});

gulp.task('compile:test:unit', () => {
	return babelCompiler.compile({
		sourcesPattern: testsPattern,
		outputFolder: buildTestFolder,
		srcBase: '.'
	});
});

gulp.task('compile:test:integration', () => {
	return babelCompiler.compile({
		sourcesPattern: integrationTestsPattern,
		outputFolder: buildTestFolder,
		srcBase: '.'
	});
});

gulp.task('compile:test:resources', () => {
	copyResources(buildTestFolder);
});

gulp.task('test:unit', () => {
	sourcemapSupport.install();
	fs.mkdirSync(buildTestDataFolder);
	return gulp.src([builtSources, builtTests])
		.pipe(mocha(mochaOptions))
		.pipe(istanbul.writeReports(istanbulOptions));
});

gulp.task('test:integration', () => {
	const options = Object.assign({}, mochaOptions);
	return gulp.src([builtSources, builtIntegrationTests])
		.pipe(mocha(mochaIntegrationTestOptions));
});

function copyPackageJson() {
	const packageJson = fs.readJsonSync('package.json');
	delete packageJson.devDependencies;
	delete packageJson.repository;
	const targetFile = path.join(buildReleaseFolder, 'package.json');
	fs.writeJsonSync(targetFile, packageJson);
}

function copyNpmFiles() {
	return gulp.src(['../README.md', '../LICENSE'])
		.pipe(gulp.dest(buildReleaseFolder));
}

function copyResources(dest) {
	return gulp.src(path.join(resourcesFolder, '**/*'))
		.pipe(gulp.dest(path.join(dest, 'resources')));
}

function copyImages() {
	return gulp.src(['img/xipcode-logo-250x100.png'])
		.pipe(gulp.dest(path.join(buildReleaseFolder, 'img')));
}

function createDistributionFile() {
	const options = {
		cwd: buildFolder
	};
	const callback = (error, stdout, stderr) => {
		if (error) {
			console.log('Error packing release folder: ' + error);
			console.log('stdout: ' + stdout);
			console.log('stderr: ' + stderr);
		}
	};<commit_msg>Allow the repository field to be included in the published package.json<commit_after>'use strict';

const os = require('os');
const path = require('path');
const gulp = require('gulp');
const clean = require('gulp-clean');
const eslint = require('gulp-eslint');
const sequence = require('gulp-sequence');
const mocha = require('gulp-mocha');
const istanbul = require('gulp-istanbul');
const sourcemapSupport = require('source-map-support');
const compiler = require('./compiler');
const instrumenter = require('./instrumenter');
const childProcess = require('child_process');
const fs = require('fs-extra');

const buildFolder = 'build';
const resourcesFolder = 'resources';
const sourcesPattern = 'src/**/*.js';
const testsPattern = 'test/**/*.js';
const integrationTestsPattern = 'integration/**/*.js';
const buildReleaseFolder = path.join(buildFolder, 'release');
const buildInstrumentFolder = path.join(buildFolder, 'instrument');
const buildTestFolder = path.join(buildFolder, 'test');
const buildTestDataFolder = path.join(buildTestFolder, 'test-output');
const builtSources = path.join(buildTestFolder, sourcesPattern);
const instrumentedSources = path.join(buildInstrumentFolder, sourcesPattern);
const builtTests = path.join(buildTestFolder, testsPattern);
const builtIntegrationTests = path.join(buildTestFolder, 'integration/**/*.js');
const babelCompiler = compiler.create();
const istanbulInstrumenter = instrumenter.create();

const mochaOptions = {
	reporter: 'spec',
	timeout: 10000
};

const mochaIntegrationTestOptions = Object.assign({}, mochaOptions);

const istanbulOptions = {
	fail: true,
	reporters: ['json', 'html'],
	reportOpts: {
		json: {
			dir: path.join(buildFolder, 'reports'),
			file: 'coverage.json'
		},
		html: {
			dir: path.join(buildFolder, 'reports', 'html')
		}
	}
};

gulp.task('clean', () => {
	return gulp.src(buildFolder)
		.pipe(clean());
});

gulp.task('log-environment', () => {
	console.log('Operating System Type     : ' + os.type());
	console.log('Operating System Release  : ' + os.release());
	console.log('Hostname                  : ' + os.hostname());
	console.log('Free System Memory        : ' + os.freemem());
	console.log('Node Version              : ' + process.versions.node);
});

gulp.task('initialize', () => {
	fs.mkdirsSync(buildFolder);
});

gulp.task('lint', () => {
	return gulp.src([sourcesPattern, testsPattern])
		.pipe(eslint())
		.pipe(eslint.format())
		.pipe(eslint.failAfterError());
});

gulp.task('compile:release', () => {
	return babelCompiler.compile({
		sourcesPattern,
		outputFolder: buildReleaseFolder,
		srcBase: '.'
	});
});

gulp.task('compile:instrument:src', () => {
	return istanbulInstrumenter.instrument({
		sourcesPattern: sourcesPattern,
		outputFolder: buildInstrumentFolder
	});
});

gulp.task('compile:test:src', () => {
	return babelCompiler.compile({
		sourcesPattern: instrumentedSources,
		outputFolder: buildTestFolder,
		srcBase: buildInstrumentFolder
	});
});

gulp.task('compile:test:unit', () => {
	return babelCompiler.compile({
		sourcesPattern: testsPattern,
		outputFolder: buildTestFolder,
		srcBase: '.'
	});
});

gulp.task('compile:test:integration', () => {
	return babelCompiler.compile({
		sourcesPattern: integrationTestsPattern,
		outputFolder: buildTestFolder,
		srcBase: '.'
	});
});

gulp.task('compile:test:resources', () => {
	copyResources(buildTestFolder);
});

gulp.task('test:unit', () => {
	sourcemapSupport.install();
	fs.mkdirSync(buildTestDataFolder);
	return gulp.src([builtSources, builtTests])
		.pipe(mocha(mochaOptions))
		.pipe(istanbul.writeReports(istanbulOptions));
});

gulp.task('test:integration', () => {
	const options = Object.assign({}, mochaOptions);
	return gulp.src([builtSources, builtIntegrationTests])
		.pipe(mocha(mochaIntegrationTestOptions));
});

function copyPackageJson() {
	const packageJson = fs.readJsonSync('package.json');
	delete packageJson.devDependencies;
	const targetFile = path.join(buildReleaseFolder, 'package.json');
	fs.writeJsonSync(targetFile, packageJson);
}

function copyNpmFiles() {
	return gulp.src(['../README.md', '../LICENSE'])
		.pipe(gulp.dest(buildReleaseFolder));
}

function copyResources(dest) {
	return gulp.src(path.join(resourcesFolder, '**/*'))
		.pipe(gulp.dest(path.join(dest, 'resources')));
}

function copyImages() {
	return gulp.src(['img/xipcode-logo-250x100.png'])
		.pipe(gulp.dest(path.join(buildReleaseFolder, 'img')));
}

function createDistributionFile() {
	const options = {
		cwd: buildFolder
	};
	const callback = (error, stdout, stderr) => {
		if (error) {
			console.log('Error packing release folder: ' + error);
			console.log('stdout: ' + stdout);
			console.log('stderr: ' + stderr);
		}
	};
{'fraction_non_alphanumeric': 0.17138297872340424, 'fraction_numerical': 0.002340425531914894, 'mean_word_length': 5.537552155771905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '1852317', 'n_tokens_mistral': 3099, 'n_tokens_neox': 2964, 'n_words': 542}