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);
|
||||
}
|
||||
}
|
|
@ -6,3 +6,34 @@ this project is a means to test the compiler capabilities of NCC
|
|||
|
||||
### Generating a project configuration file.
|
||||
|
||||
You can generate a project configuration file using the NCC
|
||||
command-line interface, you should run the command in the
|
||||
root directory of your project rather than the source directory.
|
||||
|
||||
The argument `src` allows you to specify the source directory
|
||||
which is required, otherwise NCC will assume the src directory is the current working directory.
|
||||
|
||||
```shell
|
||||
$ ls
|
||||
README.md src
|
||||
|
||||
$ ncc project create --src="src/ExampleLibrary" --package="com.example.library" --name="ExampleLibrary"
|
||||
Project successfully created
|
||||
|
||||
$ ls
|
||||
ncc project.json README.md src
|
||||
```
|
||||
|
||||
Upon creating the project, you will see a directory named `ncc`
|
||||
and a file named `project.json`, the `ncc` directory will simply
|
||||
contain extra information about the project, the file `project.json`
|
||||
contains information about the project itself, you can modify
|
||||
and change the contents of the project accordingly
|
||||
|
||||
This process only needs to be done once, any additional changes
|
||||
can be done manually by editing project.json
|
||||
|
||||
Once project.json is created, the project can be compiled using NCC
|
||||
|
||||
|
||||
### Compiling the project
|
57
tests/example_project/project.json
Normal file
57
tests/example_project/project.json
Normal file
|
@ -0,0 +1,57 @@
|
|||
{
|
||||
"project": {
|
||||
"compiler": {
|
||||
"extension": "php",
|
||||
"minimum_version": "7.4",
|
||||
"maximum_version": "8.1"
|
||||
},
|
||||
"options": []
|
||||
},
|
||||
"assembly": {
|
||||
"name": "ExampleLibrary",
|
||||
"package": "com.example.library",
|
||||
"description": null,
|
||||
"company": null,
|
||||
"product": null,
|
||||
"copyright": null,
|
||||
"trademark": null,
|
||||
"version": "1.0.0",
|
||||
"uid": "4a37f1c8-50a2-11ed-9ce4-170520693532"
|
||||
},
|
||||
"build": {
|
||||
"source_path": "src/ExampleLibrary",
|
||||
"default_configuration": "debug",
|
||||
"exclude_files": [],
|
||||
"options": [],
|
||||
"scope": null,
|
||||
"define_constants": {
|
||||
"ASSEMBLY_NAME": "%ASSEMBLY.NAME%",
|
||||
"ASSEMBLY_PACKAGE": "%ASSEMBLY.PACKAGE%",
|
||||
"ASSEMBLY_VERSION": "%ASSEMBLY.VERSION%",
|
||||
"ASSEMBLY_UID": "%ASSEMBLY.UID%"
|
||||
},
|
||||
"dependencies": [],
|
||||
"configurations": [
|
||||
{
|
||||
"name": "debug",
|
||||
"options": [],
|
||||
"output_path": "build/debug",
|
||||
"define_constants": {
|
||||
"DEBUG": "1"
|
||||
},
|
||||
"exclude_files": [],
|
||||
"dependencies": []
|
||||
},
|
||||
{
|
||||
"name": "release",
|
||||
"options": [],
|
||||
"output_path": "build/release",
|
||||
"define_constants": {
|
||||
"DEBUG": "0"
|
||||
},
|
||||
"exclude_files": [],
|
||||
"dependencies": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue