Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 10 additions & 108 deletions src/Commands/BuildIosAppCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Process;
use Illuminate\Support\Str;
use Native\Mobile\Plugins\Compilers\IOSPluginCompiler;
use Native\Mobile\Plugins\PluginHookRunner;
use Native\Mobile\Plugins\PluginRegistry;
use Native\Mobile\Plugins\PluginSecretsValidator;
use Native\Mobile\Support\BundleFileManager;
use Native\Mobile\Traits\ChecksLatestBuildNumber;
use Native\Mobile\Traits\CleansEnvFile;
use Native\Mobile\Traits\DisplaysMarketingBanners;
Expand Down Expand Up @@ -86,7 +86,11 @@ private function bundleLaravelApp(): void
{
@mkdir($this->appPath, 0755, true);

$this->copyLaravelAppIntoIosApp();
$this->components->task('Copying Laravel app', fn () => BundleFileManager::copy(
base_path(),
$this->appPath,
config('nativephp.cleanup_exclude_files', [])
));

// Set ASSET_URL in .env
file_put_contents($this->appPath.'.env', PHP_EOL.'ASSET_URL="/_assets"'.PHP_EOL, FILE_APPEND);
Expand All @@ -107,7 +111,10 @@ private function bundleLaravelApp(): void
});
});

$this->components->task('Removing unnecessary files', fn () => $this->removeUnnecessaryFiles());
$this->components->task('Removing unnecessary files', fn () => BundleFileManager::removeUnnecessaryFiles(
$this->appPath,
config('nativephp.cleanup_exclude_files', [])
));
$this->cleanEnvFile($this->appPath.'.env');
$this->createAppZip();
}
Expand Down Expand Up @@ -167,64 +174,6 @@ private function updateIcuConfiguration(): void
$this->components->twoColumnDetail('ICU support', 'Enabled');
}

private function copyLaravelAppIntoIosApp()
{
$destination = $this->appPath;

// Make sure we clear out any old version
shell_exec("rm -rf {$destination}/*");

$source = rtrim(str_replace('\\', '/', base_path()), '/').'/';

$visitedRealPaths = [];
$files = [];

$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator(
$source,
\RecursiveDirectoryIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS
),
\RecursiveIteratorIterator::LEAVES_ONLY
);

foreach ($iterator as $file) {
$realPath = $file->getRealPath();

// Skip if we've already visited this real path (prevents infinite loops from circular symlinks)
if ($realPath === false || isset($visitedRealPaths[$realPath])) {
continue;
}

$visitedRealPaths[$realPath] = true;
$files[] = $file;
}

foreach ($files as $file) {
// Where the *link* lives (keeps relative paths correct)
$logicalPath = str_replace('\\', '/', $file->getPathname());
// Where the link **points** (or the same file if not a link)
$realPath = str_replace('\\', '/', $file->getRealPath());

$relativePath = ltrim(substr($logicalPath, strlen($source)), '/');

if (Str::startsWith($relativePath, 'vendor/nativephp/mobile/resources') ||
Str::startsWith($relativePath, 'vendor/nativephp/mobile/vendor') ||
Str::startsWith($relativePath, 'nativephp') ||
Str::startsWith($relativePath, 'output/') ||
Str::startsWith($relativePath, 'build/') ||
Str::startsWith($relativePath, 'dist/') ||
Str::startsWith($relativePath, 'artifacts/') ||
Str::startsWith($relativePath, '.git/') ||
Str::startsWith($relativePath, 'storage/logs/') ||
Str::startsWith($relativePath, 'storage/framework/cache/')) {
continue;
}

@File::makeDirectory(dirname($destination.$relativePath), recursive: true, force: true);
@File::copy($realPath, $destination.$relativePath);
}
}

private function updateAppVersion(): void
{
$appVersion = config('nativephp.version');
Expand Down Expand Up @@ -819,53 +768,6 @@ private function installGoogleServicesPlist(): void
@copy($path, $destinationPath);
}

private function removeUnnecessaryFiles(): void
{

$directoriesToRemove = [
'.git',
'.github',
'node_modules',
'vendor/bin',
'tests',
'storage/logs',
'storage/framework',
'vendor/laravel/pint/builds',
'public/storage',
];

foreach ($directoriesToRemove as $dir) {
if (is_dir($this->appPath.$dir)) {
File::deleteDirectory($this->appPath.$dir);
}
}

$filesToRemove = [
'database/database.sqlite',
'*.js',
'*.md',
'*.lock',
'*.xml',
'.env.example',
'artisan',
'.gitignore',
'.gitattributes',
'.gitkeep',
'.editorconfig',
'.DS_Store',
'vendor/livewire/livewire/src/Features/SupportFileUploads/browser_test_image_big.jpg',
];

foreach ($filesToRemove as $pattern) {
$files = glob($this->appPath.$pattern);
foreach ($files as $file) {
if (is_file($file)) {
unlink($file);
}
}
}
}

private function determineApsEnvironment(): string
{
// Check if we're in a package command with export method
Expand Down
71 changes: 71 additions & 0 deletions src/Support/BundleExclusions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace Native\Mobile\Support;

class BundleExclusions
{
/** Excluded at any depth, including inside vendor packages. */
public const ANY_DEPTH = [
'.git',
'.github',
'.idea',
'.vscode',
'node_modules',
'tests',
'.DS_Store',
'.gitignore',
'.gitattributes',
'.gitkeep',
'.editorconfig',
];

/** Project-root paths excluded during copy AND removed during cleanup. */
public const PROJECT = [
'nativephp',
'output',
'build',
'dist',
'artifacts',
'storage/logs',
'storage/framework',
'storage/app/native-build',
'public/storage',
'database/database.sqlite',
'*.js',
'*.md',
'*.xml',
'*.jks',
'*.zip',
'.env.example',
];

/** Excluded during copy only — kept after composer install regenerates them. */
public const COPY_ONLY = [
'bootstrap/cache/*',
];

/** Copied for composer install, removed during cleanup only. */
public const CLEANUP_ONLY = [
'*.lock',
'artisan',
];

/** Non-runtime patterns inside vendor packages. */
public const VENDOR_PATTERNS = [
'*.md',
'LICENSE*',
'docs',
'*.yml',
'*.yaml',
'*.neon',
'*.neon.dist',
];

/** Specific vendor paths to exclude. */
public const VENDOR_PATHS = [
'vendor/nativephp/mobile/resources',
'vendor/*/*/vendor',
'vendor/laravel/pint/builds',
'vendor/livewire/livewire/src/Features/SupportFileUploads/browser_test_image_big.jpg',
];
}
Loading