Skip to content

Commit

Permalink
simplifyyy man
Browse files Browse the repository at this point in the history
  • Loading branch information
roborourke committed Sep 18, 2019
1 parent 732f3b8 commit 7710d76
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions inc/composer/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,31 @@ public function generate_module_manifest() {
$repository = $this->composer->getRepositoryManager()->getLocalRepository();
$packages = $repository->getCanonicalPackages();
$vendor_dir = $this->composer->getConfig()->get( 'vendor-dir' );
$package_list = array_reduce( $packages, function ( $carry, PackageInterface $package ) use ( $vendor_dir ) {
$module_loader = "<?php\n/**\n * Altis Module Loader.\n *\n * DO NOT EDIT THIS FILE.\n */\n";

foreach ( $packages as $package ) {
$extra = $package->getExtra();

// Only process Altis packages.
if ( ! isset( $extra['altis'] ) ) {
return $carry;
continue;
}

// Determine absolute file path.
$default_base = $vendor_dir . DIRECTORY_SEPARATOR . str_replace( '/', DIRECTORY_SEPARATOR, $package->getName() );
$base = $package->getTargetDir() ?? $default_base;
$file = $base . DIRECTORY_SEPARATOR . 'load.php';

if ( ! file_exists( $file ) ) {
return $carry;
continue;
}

// Make the path relative to work across environments.
$file = str_replace( $vendor_dir, '', $file );

$carry .= "\n// Load {$package->getName()}.\nrequire_once __DIR__ . '{$file}';";

return $carry;
}, "<?php\n/**\n * Altis Module Loader.\n *\n * DO NOT EDIT THIS FILE.\n */\n" );
// Add the require line to the file.
$module_loader .= "\n// Load {$package->getName()}.\nrequire_once __DIR__ . '{$file}';";
}

// Write the loader file.
file_put_contents( $vendor_dir . DIRECTORY_SEPARATOR . 'modules.php', $package_list );
Expand Down

0 comments on commit 7710d76

Please sign in to comment.