<commit_before><?php

use Neptune\Console\Console;
use Neptune\Console\Generator;
use Neptune\Core\Neptune;
use Neptune\Core\Events;

include('bootstrap.php');

Neptune::handleErrors();
Events::getInstance()->addHandler('\Exception', function($e) {
	Console::getInstance()->error($e->getMessage());
	});

$c = Console::getInstance();
$c->write('Welcome to the Neptune installer.');

$project_dir = $c->read('Create a Neptune project in: ');
Neptune::set('root_namespace', $c->read('Root namespace of application: '));

if(!file_exists($project_dir)) {
	if(!@mkdir($project_dir)) {
	$c->write('Unable to create new directory ' . $project_dir);
	exit(1);
	}
}

$g = Generator::getInstance();
$g->populateAppDirectory($project_dir);
$c->write('Created blank application in ' . $project_dir);
?><commit_msg>Reworking install script to use composer.<commit_after><?php

//really simple console functions before we get everything installed
function write($text) {
	echo $text . PHP_EOL;
}

function read($prompt) {
	if(extension_loaded('readline')) {
		return readline($prompt);
	}
	write($prompt);
	return fgets(STDIN);
}

write('Welcome to the Neptune installer.');

$project_dir = read('Create a Neptune project in the following directory: ');

if(!file_exists($project_dir)) {
	if(!@mkdir($project_dir)) {
		write('Unable to create new directory ' . $project_dir);
		write('Make sure the path is writeable and permissions are set correctly.');
		exit(1);
	}
}

chdir($project_dir);

$json = '{
	"require": {
		"glynnforrest/neptune":"dev-master"
	}
}
';

try {
	$file = new \SplFileObject('composer.json', 'w');
	$file->fwrite($json);
} catch (\Exception $e) {
	write($e->getMessage());
	exit(1);
}



passthru('composer install');

write('Neptune successfully downloaded.');
write('Now change directory to ' . $project_dir . ' and run `php neptune setup`.');

exit(0);
{'fraction_non_alphanumeric': 0.17889662560257097, 'fraction_numerical': 0.0021424745581146223, 'mean_word_length': 5.768115942028985, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3651240', 'n_tokens_mistral': 639, 'n_tokens_neox': 627, 'n_words': 142}