Updated ExampleLibrary and fixed the project creation command to use the correct source directory
This commit is contained in:
parent
b0718aeb74
commit
191b121542
6 changed files with 130 additions and 7 deletions
|
@ -726,5 +726,8 @@
|
|||
}
|
||||
|
||||
file_put_contents($NCC_INSTALL_PATH . DIRECTORY_SEPARATOR . 'ncc.yaml', Yaml::dump($config_obj));
|
||||
|
||||
Console::out('NCC version: ' . NCC_VERSION_NUMBER . ' has been successfully installed');
|
||||
Console::out('For licensing information see \'' . $NCC_INSTALL_PATH . DIRECTORY_SEPARATOR . 'LICENSE\' or run \'ncc help --license\'');
|
||||
|
||||
exit(0);
|
|
@ -38,7 +38,8 @@
|
|||
public static function createProject($args): void
|
||||
{
|
||||
// First determine the source directory of the project
|
||||
$src = getcwd();
|
||||
$current_directory = getcwd();
|
||||
$real_src = $current_directory;
|
||||
if(isset($args['src']))
|
||||
{
|
||||
// Make sure directory separators are corrected
|
||||
|
@ -55,7 +56,7 @@
|
|||
|
||||
if(file_exists($full_path) && is_dir($full_path))
|
||||
{
|
||||
$src = getcwd() . DIRECTORY_SEPARATOR . $args['src'];
|
||||
$real_src = getcwd() . DIRECTORY_SEPARATOR . $args['src'];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -63,6 +64,9 @@
|
|||
}
|
||||
}
|
||||
|
||||
// Remove basename from real_src
|
||||
$real_src = \ncc\Utilities\Functions::removeBasename($real_src, $current_directory);
|
||||
|
||||
// Fetch the rest of the information needed for the project
|
||||
//$compiler_extension = Console::getOptionInput($args, 'ce', 'Compiler Extension (php, java): ');
|
||||
$compiler_extension = 'php'; // Always php, for now.
|
||||
|
@ -76,10 +80,11 @@
|
|||
$Compiler->MinimumVersion = '7.4';
|
||||
|
||||
// Now create the project
|
||||
$ProjectManager = new ProjectManager($src);
|
||||
$ProjectManager = new ProjectManager($current_directory);
|
||||
|
||||
try
|
||||
{
|
||||
$ProjectManager->initializeProject($Compiler, $project_name, $package_name);
|
||||
$ProjectManager->initializeProject($Compiler, $project_name, $package_name, $real_src);
|
||||
}
|
||||
catch (InvalidPackageNameException $e)
|
||||
{
|
||||
|
@ -91,7 +96,7 @@
|
|||
}
|
||||
catch (ProjectAlreadyExistsException $e)
|
||||
{
|
||||
Console::outException('A project has already been initialized in \'' . $src . '\'', $e, 1);
|
||||
Console::outException('A project has already been initialized in \'' . $current_directory . '\'', $e, 1);
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
|
|
|
@ -84,13 +84,14 @@
|
|||
* @param Compiler $compiler
|
||||
* @param string $name
|
||||
* @param string $package
|
||||
* @param string $src
|
||||
* @param array $options
|
||||
* @throws InvalidPackageNameException
|
||||
* @throws InvalidProjectNameException
|
||||
* @throws MalformedJsonException
|
||||
* @throws ProjectAlreadyExistsException
|
||||
*/
|
||||
public function initializeProject(Compiler $compiler, string $name, string $package, array $options=[]): void
|
||||
public function initializeProject(Compiler $compiler, string $name, string $package, string $src, array $options=[]): void
|
||||
{
|
||||
// Validate the project information first
|
||||
if(!Validate::packageName($package))
|
||||
|
@ -120,7 +121,7 @@
|
|||
$Project->Assembly->UUID = Uuid::v1()->toRfc4122();
|
||||
|
||||
// Set the build information
|
||||
$Project->Build->SourcePath = $this->SelectedDirectory;
|
||||
$Project->Build->SourcePath = $src;
|
||||
$Project->Build->DefaultConfiguration = 'debug';
|
||||
|
||||
// Assembly constants if the program wishes to check for this
|
||||
|
|
|
@ -184,4 +184,30 @@
|
|||
|
||||
return $banner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the basename from a path, eg; extracts "foo/bar.txt" from "/root/foo/bar.txt" if "/root" is the
|
||||
* current working directory, optionally accepts a different basename using the $basename parameter.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string|null $basename
|
||||
* @return string
|
||||
*/
|
||||
public static function removeBasename(string $path, ?string $basename=null): string
|
||||
{
|
||||
if($basename == null)
|
||||
$basename = getcwd();
|
||||
|
||||
// Append the trailing slash if it's not already there
|
||||
// "/etc/foo" becomes "/etc/foo/"
|
||||
if(substr($basename, -1) !== DIRECTORY_SEPARATOR)
|
||||
{
|
||||
$basename .= DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
var_dump($basename);
|
||||
|
||||
// If the path is "/etc/foo/text.txt" and the basename is "/etc" then the returned path will be "foo/test.txt"
|
||||
return str_replace($basename, (string)null, $path);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue