This commit is contained in:
Netkas 2022-09-11 14:44:28 -04:00
parent b60963fe47
commit 88e92f82c4
2 changed files with 20 additions and 17 deletions

View file

@ -23,8 +23,8 @@
use ncc\ThirdParty\Symfony\Filesystem\Exception\IOException; use ncc\ThirdParty\Symfony\Filesystem\Exception\IOException;
use ncc\ThirdParty\Symfony\Filesystem\Filesystem; use ncc\ThirdParty\Symfony\Filesystem\Filesystem;
use ncc\ThirdParty\Symfony\Process\Exception\ProcessFailedException; use ncc\ThirdParty\Symfony\Process\Exception\ProcessFailedException;
use ncc\ThirdParty\Symfony\Process\ExecutableFinder; use ncc\ThirdParty\Symfony\Process\ExecutableFinder;
use ncc\ThirdParty\Symfony\process\PhpExecutableFinder; use ncc\ThirdParty\Symfony\process\PhpExecutableFinder;
use ncc\ThirdParty\Symfony\Process\Process; use ncc\ThirdParty\Symfony\Process\Process;
use ncc\ThirdParty\Symfony\Yaml\Yaml; use ncc\ThirdParty\Symfony\Yaml\Yaml;
use ncc\Utilities\Console; use ncc\Utilities\Console;
@ -37,7 +37,7 @@ use ncc\ThirdParty\Symfony\process\PhpExecutableFinder;
# Global Variables # Global Variables
$NCC_INSTALL_PATH=DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'ncc'; $NCC_INSTALL_PATH=DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'ncc';
$NCC_DATA_PATH=DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'ncc'; $NCC_DATA_PATH=DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'ncc';
$NCC_UPDATE_SOURCE='https://updates.nosial.com/ncc/check_updates?current_version=$VERSION'; # Unused $NCC_COMPOSER_UPDATE_SOURCE='https://getcomposer.org/installer';
$NCC_CHECKSUM=__DIR__ . DIRECTORY_SEPARATOR . 'checksum.bin'; $NCC_CHECKSUM=__DIR__ . DIRECTORY_SEPARATOR . 'checksum.bin';
$NCC_AUTOLOAD=__DIR__ . DIRECTORY_SEPARATOR . 'autoload.php'; $NCC_AUTOLOAD=__DIR__ . DIRECTORY_SEPARATOR . 'autoload.php';
$NCC_PHP_EXECUTABLE=null; $NCC_PHP_EXECUTABLE=null;
@ -154,6 +154,12 @@ use ncc\ThirdParty\Symfony\process\PhpExecutableFinder;
} }
// Check if running as root // Check if running as root
if(function_exists('posix_getuid') == false)
{
Console::outError('The function posix_getuid() is not available on your system, please make sure the extension `php-common` is installed');
exit(1);
}
if (posix_getuid() !== 0) if (posix_getuid() !== 0)
{ {
Console::outError('You must be running as root'); Console::outError('You must be running as root');
@ -463,7 +469,7 @@ use ncc\ThirdParty\Symfony\process\PhpExecutableFinder;
$fp = fopen($NCC_INSTALL_PATH . DIRECTORY_SEPARATOR . 'composer-setup.php', 'w+'); $fp = fopen($NCC_INSTALL_PATH . DIRECTORY_SEPARATOR . 'composer-setup.php', 'w+');
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://getcomposer.org/installer'); curl_setopt($ch, CURLOPT_URL, $NCC_COMPOSER_UPDATE_SOURCE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 600); curl_setopt($ch, CURLOPT_TIMEOUT, 600);
curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_FILE, $fp);
@ -491,7 +497,7 @@ use ncc\ThirdParty\Symfony\process\PhpExecutableFinder;
} }
catch(ProcessFailedException $e) catch(ProcessFailedException $e)
{ {
Console::outError('Cannot install compos)er, ' . $e->getMessage()); Console::outError('Cannot install composer, ' . $e->getMessage());
exit(1); exit(1);
} }
@ -619,11 +625,11 @@ use ncc\ThirdParty\Symfony\process\PhpExecutableFinder;
{ {
if(isset($config_obj[$section])) if(isset($config_obj[$section]))
{ {
foreach($value as $section_item) foreach($value as $section_item => $section_value)
{ {
if(!isset($config_obj[$section][$section_item])) if(!isset($config_obj[$section][$section_item]))
{ {
$config_obj[$section][$section_item] = $value; $config_obj[$section][$section_item] = $section_value;
} }
} }
} }

View file

@ -9,7 +9,7 @@
use ncc\Exceptions\ProjectAlreadyExistsException; use ncc\Exceptions\ProjectAlreadyExistsException;
use ncc\Objects\ProjectConfiguration; use ncc\Objects\ProjectConfiguration;
use ncc\Objects\ProjectConfiguration\Compiler; use ncc\Objects\ProjectConfiguration\Compiler;
use ncc\Symfony\Component\Uid\Uuid; use ncc\ThirdParty\Symfony\Uid\Uuid;
use ncc\Utilities\Validate; use ncc\Utilities\Validate;
class ProjectManager class ProjectManager
@ -53,9 +53,9 @@
* Attempts to resolve the project path from the selected directory * Attempts to resolve the project path from the selected directory
* Returns false if the selected directory is not a proper project or an initialized project * Returns false if the selected directory is not a proper project or an initialized project
* *
* @return bool * @return void
*/ */
private function detectProjectPath(): bool private function detectProjectPath(): void
{ {
$selected_directory = $this->SelectedDirectory; $selected_directory = $this->SelectedDirectory;
@ -69,7 +69,7 @@
// Detect if the folder exists or not // Detect if the folder exists or not
if(!file_exists($selected_directory) || !is_dir($selected_directory)) if(!file_exists($selected_directory) || !is_dir($selected_directory))
{ {
return false; return;
} }
// Detect if project.json exists in the directory // Detect if project.json exists in the directory
@ -77,10 +77,7 @@
{ {
$this->ProjectPath = $selected_directory; $this->ProjectPath = $selected_directory;
$this->ProjectFilePath = $selected_directory . 'project.json'; $this->ProjectFilePath = $selected_directory . 'project.json';
return true;
} }
return false;
} }
/** /**
@ -95,7 +92,7 @@
* @throws MalformedJsonException * @throws MalformedJsonException
* @throws ProjectAlreadyExistsException * @throws ProjectAlreadyExistsException
*/ */
public function initializeProject(Compiler $compiler, string $name, string $package, array $options=[]) public function initializeProject(Compiler $compiler, string $name, string $package, array $options=[]): void
{ {
// Validate the project information first // Validate the project information first
if(!Validate::packageName($package)) if(!Validate::packageName($package))
@ -170,9 +167,9 @@
switch($option) switch($option)
{ {
case InitializeProjectOptions::CREATE_SOURCE_DIRECTORY: case InitializeProjectOptions::CREATE_SOURCE_DIRECTORY:
if(!file_exists($source)) if(!file_exists($this->ProjectPath . DIRECTORY_SEPARATOR . 'src'))
{ {
mkdir($source); mkdir($this->ProjectPath . DIRECTORY_SEPARATOR . 'src');
} }
break; break;
} }