Implemented Composer

This commit is contained in:
Zi Xing 2022-12-04 06:43:54 +00:00
parent d03f31fe6a
commit 5104d00fa7
63 changed files with 6341 additions and 393 deletions

View file

@ -26,6 +26,7 @@
use ncc\Utilities\Console;
use ncc\Utilities\Functions;
use ncc\Utilities\IO;
use ncc\Utilities\PathFinder;
use ncc\Utilities\Resolver;
use ncc\Utilities\Validate;
use ncc\ZiProto\ZiProto;
@ -151,12 +152,6 @@
}
}
// Check if running in a TTY
if(stream_isatty(STDERR) && !$NCC_BYPASS_CLI_CHECK)
{
Console::outWarning('Your terminal may have some issues rendering the output of this installer');
}
// Check if running as root
if(!function_exists('posix_getuid'))
{
@ -453,22 +448,6 @@
}
}
// Backup the configuration file
$config_backup = null;
if($NCC_FILESYSTEM->exists($NCC_INSTALL_PATH . DIRECTORY_SEPARATOR . 'ncc.yaml'))
{
Console::out('ncc.yaml will be updated');
try
{
$config_backup = IO::fread($NCC_INSTALL_PATH . DIRECTORY_SEPARATOR . 'ncc.yaml');
}
catch(Exception $e)
{
Console::outError($e->getMessage(), true, 1);
return;
}
}
// Prepare installation
if($NCC_FILESYSTEM->exists($NCC_INSTALL_PATH))
{
@ -558,7 +537,7 @@
return;
}
$total_items = count($build_files);
$processed_items = 0;
$processed_items = 1;
// Create all the directories first
foreach($build_files as $path)
@ -611,8 +590,7 @@
$bin_paths = [
DIRECTORY_SEPARATOR . 'usr' . DIRECTORY_SEPARATOR . 'bin',
DIRECTORY_SEPARATOR . 'usr' . DIRECTORY_SEPARATOR . 'local' . DIRECTORY_SEPARATOR . 'bin',
DIRECTORY_SEPARATOR . 'usr' . DIRECTORY_SEPARATOR . 'share'
DIRECTORY_SEPARATOR . 'bin'
];
foreach($bin_paths as $path)
@ -628,7 +606,6 @@
try
{
IO::fwrite($path . DIRECTORY_SEPARATOR . 'ncc', $executable_shortcut);
break;
}
catch (Exception $e)
{
@ -718,6 +695,44 @@
}
}
// Overwrite automatic values created by the installer
$config_obj['ncc']['data_directory'] = $NCC_DATA_PATH;
$config_obj['php']['executable_path'] = $NCC_PHP_EXECUTABLE;
$config_obj['git']['executable_path'] = $NCC_EXECUTABLE_FINDER->find('git');
$config_obj['composer']['executable_path'] = $NCC_EXECUTABLE_FINDER->find('composer');
if($config_obj['git']['executable_path'] == null)
{
Console::outWarning('Cannot locate the executable path for \'git\', run \'ncc config -p git.executable_path -v "GIT_PATH_HERE"\' as root to update the path');
}
if(!$update_composer)
{
Console::outWarning('Since composer is not installed alongside NCC, the installer will attempt to locate a install of composer on your system and configure NCC to use that');
$config_obj['composer']['enable_internal_composer'] = false;
if($config_obj['composer']['executable_path'] == null)
{
// TODO: Implement Configuration Tools
Console::outWarning('Cannot locate the executable path for \'composer\', run \'ncc config --composer.executable_path="composer.phar"\' as root to update the path');
}
}
// Backup the configuration file
$config_backup = null;
try
{
if ($NCC_FILESYSTEM->exists(PathFinder::getConfigurationFile()))
{
$config_backup = IO::fread(PathFinder::getConfigurationFile());
}
}
catch (Exception $e)
{
Console::outError($e->getMessage(), true, 1);
return;
}
// Create/Update configuration file
$config_obj = Yaml::parseFile(__DIR__ . DIRECTORY_SEPARATOR . 'default_config.yaml');
@ -744,28 +759,6 @@
}
}
// Overwrite automatic values created by the installer
$config_obj['ncc']['data_directory'] = $NCC_DATA_PATH;
$config_obj['php']['executable_path'] = $NCC_PHP_EXECUTABLE;
$config_obj['git']['executable_path'] = $NCC_EXECUTABLE_FINDER->find('git');
$config_obj['composer']['executable_path'] = $NCC_EXECUTABLE_FINDER->find('composer');
if($config_obj['git']['executable_path'] == null)
{
Console::outWarning('Cannot locate the executable path for \'git\', run \'ncc config --git.executable_path="GIT_PATH_HERE"\' as root to update the path');
}
if(!$update_composer)
{
Console::outWarning('Since composer is not installed alongside NCC, the installer will attempt to locate a install of composer on your system and configure NCC to use that');
$config_obj['composer']['enable_internal_composer'] = false;
if($config_obj['composer']['executable_path'] == null)
{
// TODO: Implement Configuration Tools
Console::outWarning('Cannot locate the executable path for \'composer\', run \'ncc config --composer.executable_path="composer.phar"\' as root to update the path');
}
}
if($config_backup == null)
{
Console::out('Generating ncc.yaml');
@ -778,9 +771,9 @@
try
{
IO::fwrite($NCC_INSTALL_PATH . DIRECTORY_SEPARATOR . 'ncc.yaml', Yaml::dump($config_obj));
IO::fwrite(PathFinder::getConfigurationFile(), Yaml::dump($config_obj), 0755);
}
catch (\ncc\Exceptions\IOException $e)
catch (Exception $e)
{
Console::outException($e->getMessage(), $e, 1);
return;