<commit_before>var through = require('through2'),
	gutil = require('gulp-util'),
	merge = require('deepmerge'),
	PluginError = gutil.PluginError,
	spawn = require('child_process').spawn,
	debug = require('debug')('gulp-koa'),
	fs = require('fs'),
	path = require('path'),
	info = gutil.colors.cyan,
	error = gutil.colors.bold.red,
	dbg = gutil.colors.gray,
	server = null;



module.exports = function(script, options) {
	if (!script || typeof(script) !== "string") {
		debug(error('No script file passed or script is not a string'))
		throw new PluginError('gulp-koa', 'Missing or invalid script for gulp-koa', {showProperties: false});
	}
	fs.exists(script, function(exists) {
		if (!exists) {
			debug(error('Script file does not exist. ') + dbg(script));
			throw new PluginError('gulp-koa', 'Script file does not exist (' + info(script) + ')', {showProperties: false});
		}
	});
	options = options || {};
	var opts = merge({
		cwd: undefined,
		env: process.env,
		stdio: 'inherit'
	}, options);
	return through.obj(function() {
		if (server && server.kill) {
			debug(info('Server is already running: ') + dbg(server.pid || 0));
			server.kill('SIGTERM');
			server = null;
		}
		
		debug(info('Spawning new server with: ' + script));

		server = spawn('node', ['--harmony', script], opts);
	});
}<commit_msg>added ability to stop koa service<commit_after>var through = require('through2'),
	gutil = require('gulp-util'),
	merge = require('deepmerge'),
	PluginError = gutil.PluginError,
	spawn = require('child_process').spawn,
	debug = require('debug')('gulp-koa'),
	fs = require('fs'),
	path = require('path'),
	info = gutil.colors.cyan,
	error = gutil.colors.bold.red,
	dbg = gutil.colors.gray,
	server = null;


function stop(){
	if (server && server.kill) {
		debug(info('Server is already running: ') + dbg(server.pid || 0));
		server.kill('SIGTERM');
		server = null;
	}
}

module.exports = function(script, options) {
	if (!script || typeof(script) !== "string") {
		debug(error('No script file passed or script is not a string'))
		throw new PluginError('gulp-koa', 'Missing or invalid script for gulp-koa', {showProperties: false});
	}
	fs.exists(script, function(exists) {
		if (!exists) {
			debug(error('Script file does not exist. ') + dbg(script));
			throw new PluginError('gulp-koa', 'Script file does not exist (' + info(script) + ')', {showProperties: false});
		}
	});
	options = options || {};
	var opts = merge({
		cwd: undefined,
		env: process.env,
		stdio: 'inherit'
	}, options);
	return through.obj(function() {
		stop();
		
		debug(info('Spawning new server with: ' + script));

		server = spawn('node', ['--harmony', script], opts);
	});
}

module.exports.stop = stop;
{'fraction_non_alphanumeric': 0.18091009988901222, 'fraction_numerical': 0.0014798372179060304, 'mean_word_length': 4.4188376753507015, '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': '2584762', 'n_tokens_mistral': 955, 'n_tokens_neox': 894, 'n_words': 230}