diff --git a/pup b/pup index f46b7bd..a337df7 100755 --- a/pup +++ b/pup @@ -3,7 +3,7 @@ namespace StellarWP\Pup; -const PUP_VERSION = '1.3.7'; +const PUP_VERSION = '1.3.8'; define( '__PUP_DIR__', __DIR__ ); if ( ! \Phar::running() ) { diff --git a/src/Commands/Package.php b/src/Commands/Package.php index 2618b41..9c70804 100644 --- a/src/Commands/Package.php +++ b/src/Commands/Package.php @@ -84,6 +84,13 @@ protected function execute( InputInterface $input, OutputInterface $output ) { $output->writeln( '✓ Updating version files...Complete.' ); $output->writeln( '- Synchronizing files to zip directory...' ); + + $distfiles = $this->getDistfilesLines( $this->getSourceDir( $root ) ); + if ( ! empty( $distfiles ) ) { + $distfiles_message = '>>> Your project has a .distfiles file, so .distignore and pup\'s default ignore rules will not be used.'; + $output->writeln( "{$distfiles_message}" ); + } + $pup_zip_dir = $config->getZipDir(); DirectoryUtils::rmdir( $pup_zip_dir ); @@ -201,6 +208,22 @@ protected function createZip( string $dir_to_zip, string $zip_filename, string $ return 0; } + /** + * Get the default things to exclude from sync. + * + * @return array + */ + public function getDefaultIgnoreLines(): array { + $working_dir = App::getConfig()->getWorkingDir(); + $zip_dir = str_replace( $working_dir, '', App::getConfig()->getZipDir() ); + + return [ + '.puprc', + '.pup-*', + $zip_dir, + ]; + } + /** * Get the files to exclude from sync. * @@ -230,33 +253,54 @@ public function getIgnoreLines( string $source ): array { } /** - * Get the files to include in sync. + * Get the distfiles lines to include in sync. * * @param string $source * * @return array */ - public function getIncludeLines( string $source ): array { - $include = []; - $include_files = [ - '.pup-distinclude', - '.pup-distfiles', - ]; + public function getDistfilesLines( string $source ): array { + $include = []; + $include_file = '.pup-distfiles'; - foreach ( $include_files as $include_file ) { - if ( ! file_exists( $source . $include_file ) ) { - continue; - } + if ( ! file_exists( $source . $include_file ) ) { + return []; + } - $lines = file( $source . $include_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ); + $lines = file( $source . $include_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ); - if ( ! $lines ) { - continue; - } + if ( ! $lines ) { + return []; + } + + $include = array_merge( $include, $lines ); + + return $include; + } + + /** + * Get the distinclude lines to include in sync. + * + * @param string $source + * + * @return array + */ + public function getDistincludeLines( string $source ): array { + $include = []; + $include_file = '.pup-include'; + + if ( ! file_exists( $source . $include_file ) ) { + return []; + } + + $lines = file( $source . $include_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ); - $include = array_merge( $include, $lines ); + if ( ! $lines ) { + return []; } + $include = array_merge( $include, $lines ); + return $include; } @@ -392,8 +436,17 @@ protected function syncFiles( string $root, string $destination ): int { $this->buildSyncFiles( $source ); - $include = $this->getIncludeLines( $source ); - $ignore = $this->getIgnoreLines( $source ); + $distfiles = $this->getDistfilesLines( $source ); + $distinclude = $this->getDistincludeLines( $source ); + $include = array_merge( $distfiles, $distinclude ); + + $ignore = $this->getDefaultIgnoreLines(); + + // We only observe .distignore if there is no .distfiles files. + if ( empty( $distfiles ) ) { + $ignore = array_merge( $ignore, $this->getIgnoreLines( $source ) ); + } + $results = $this->migrateNegatedLines( $include, $ignore ); $include = $results['include']; $ignore = $results['ignore'];