<?php

use DevNet\System\Runtime\Launcher;

$root = dirname(__FILE__, 2);

// Loads local devnet core host if exist
if (is_file($root . '/vendor/devnet/core/host/corehost.php')) {
    require $root . '/vendor/devnet/core/host/corehost.php';
}

// Gets the path environment variable
if (PHP_OS_FAMILY == 'Windows') {
    $paths = explode(';', getenv('path'));
} else {
    $paths = explode(':', getenv('PATH'));
}

// Search for the global devnet core host
foreach ($paths as $path) {
    if (is_file($path . '/../devnet/core/host/corehost.php')) {
        require $path . '/../devnet/core/host/corehost.php';
        break;
    }
}


// Gets the console arguments without command name
$args = $GLOBALS['argv'] ?? [];
array_shift($args);

// Initialize and launch the application
$launcher = Launcher::initialize($root . '/devnet.proj');
$launcher->launch($args);
