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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea/
vendor/
*.phar
.vscode/

tests/_output
tests/_support/_generated
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"codeception/module-phpbrowser": "^2.0.3",
"codeception/module-asserts": "^2.0.1",
"codeception/module-cli": "^2.0",
"lucatume/codeception-snapshot-assertions": "^0.2.4"
"lucatume/codeception-snapshot-assertions": "^0.4.0"
},
"autoload": {
"psr-4": {
Expand Down
24 changes: 12 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ src/styles/*.css
By default, `pup` will use its own `.distignore-defaults` file to exclude a number of common patterns. You can turn the
default exclusion rules off by adding `"zip_use_default_ignore": false` to your `.puprc` file.

If you have a `.distfile` or `.distinclude` in your project, `pup` will NOT use its own `.distignore-defaults` regardless of the
property's `zip_use_default_ignore` value.

The zip that is generated will be placed in your project's root directory.

### Usage
Expand Down
2 changes: 1 addition & 1 deletion pup
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace StellarWP\Pup;

const PUP_VERSION = '1.3.8';
const PUP_VERSION = '1.3.9';
define( '__PUP_DIR__', __DIR__ );

if ( ! \Phar::running() ) {
Expand Down
32 changes: 6 additions & 26 deletions src/Commands/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ protected function execute( InputInterface $input, OutputInterface $output ) {

$output->writeln( '<fg=gray>- Synchronizing files to zip directory...</>' );

$distfiles = $this->getDistfilesLines( $this->getSourceDir( $root ) );
if ( ! empty( $distfiles ) ) {
$distfiles_message = '>>> Your project has a <fg=yellow>.distfiles</> file, so <fg=yellow>.distignore</> and pup\'s default ignore rules will not be used.';
$distfiles = $this->getDistfilesLines( $this->getSourceDir( $root ) );
$distincludes = $this->getDistincludeLines( $this->getSourceDir( $root ) );
if ( ! empty( $distfiles ) || ! empty( $distincludes ) ) {
$distfiles_message = '>>> Your project has a <fg=yellow>.distfiles</> file or a <fg=yellow>.distinclude</> file or both, so pup\'s default ignore rules will not be used.';
$output->writeln( "<fg=gray>{$distfiles_message}</>" );
}

Expand Down Expand Up @@ -208,22 +209,6 @@ protected function createZip( string $dir_to_zip, string $zip_filename, string $
return 0;
}

/**
* Get the default things to exclude from sync.
*
* @return array<int, string>
*/
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.
*
Expand Down Expand Up @@ -287,7 +272,7 @@ public function getDistfilesLines( string $source ): array {
*/
public function getDistincludeLines( string $source ): array {
$include = [];
$include_file = '.pup-include';
$include_file = '.pup-distinclude';

if ( ! file_exists( $source . $include_file ) ) {
return [];
Expand Down Expand Up @@ -440,12 +425,7 @@ protected function syncFiles( string $root, string $destination ): int {
$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 ) );
}
$ignore = $this->getIgnoreLines( $source );

$results = $this->migrateNegatedLines( $include, $ignore );
$include = $results['include'];
Expand Down
25 changes: 21 additions & 4 deletions src/Filesystem/SyncFiles/AbstractFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
use Symfony\Component\Finder\Glob;

class AbstractFile {
/**
* An array of our default files.
*
* @var array<int, string>
*/
protected const DEFAULTS = [
'.distignore-defaults',
'.puprc-defaults'
];

/**
* @var string
*/
Expand Down Expand Up @@ -94,12 +104,15 @@ public function writeContents( string $target_file ): string {

foreach ( $this->getPaths() as $file ) {
if ( ! file_exists( $this->getRoot() . $file ) ) {
if ( ! file_exists( $file ) || strpos( $file, __PUP_DIR__ ) === false ) {
$is_default = true;
if ( ! file_exists( $file ) ) {
continue;
} else {
$path = $file;
}

if ( $this->is_default( $file ) ) {
$is_default = true;
}

$path = $file;
} else {
$path = $this->getRoot() . $file;
}
Expand Down Expand Up @@ -146,6 +159,10 @@ public function writeContents( string $target_file ): string {
return (string) file_get_contents( $this->getRoot() . $target_file );
}

public function is_default( string $file ): bool {
return in_array( $file, array_map( fn( $default_file ) => __PUP_DIR__ . '/' . $default_file, static::DEFAULTS ), true );
}

/**
* Writes the file.
*
Expand Down
4 changes: 3 additions & 1 deletion src/Filesystem/SyncFiles/SyncFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public static function getDistIgnore( string $root, array $paths = [] ): DistIgn
$use_ignore_defaults = App::getConfig()->getZipUseDefaultIgnore();
$files = static::getSyncFiles( '.distignore' );

if ( $use_ignore_defaults ) {
$there_is_safelist = file_exists( $root . '/.distfiles' ) || file_exists( $root . '/.distinclude' );

if ( ! $there_is_safelist && $use_ignore_defaults ) {
$files[] = __PUP_DIR__ . '/.distignore-defaults';
}

Expand Down
Empty file.
4 changes: 4 additions & 0 deletions tests/cli/AbstractBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ class AbstractBase {

protected $pup;
protected $pup_root;
protected $plugin_root;
protected $tests_root;

public function __construct() {
$this->tests_root = dirname( __DIR__ );
$this->pup_root = dirname( $this->tests_root );
$this->plugin_root = dirname( $this->pup_root );
}

public function _before( CliTester $I ) {
Expand All @@ -22,6 +24,7 @@ public function _before( CliTester $I ) {
}

public function _after( CliTester $I ) {
$I->runShellCommand( "php {$this->pup} clean" );
$this->reset_data_and_location();
}

Expand All @@ -31,6 +34,7 @@ protected function reset_data_and_location() {
'.puprc',
'.distignore',
'.distinclude',
'.distfiles',
'.gitattributes',
'fake-project.1.0.0.zip',
'fake-project.1.0.0.1.zip',
Expand Down
4 changes: 2 additions & 2 deletions tests/cli/Commands/CloneCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function it_should_clone_the_default_branch_of_a_git_repo( CliTester $I )
$I->assertTrue( file_exists( '.pup-build/bootstrap.php' ) );

$output = $I->grabShellOutput();
$this->assertMatchesStringSnapshot( $output );
$this->assertMatchesStringSnapshot( str_replace( $this->plugin_root, '{PUP_ROOT}', $output ) );

$I->runShellCommand( "php {$this->pup} clean" );

Expand Down Expand Up @@ -72,7 +72,7 @@ public function it_should_clone_a_specific_branch_of_a_git_repo( CliTester $I )
$I->assertTrue( file_exists( '.pup-build/new-file.txt' ) );

$output = $I->grabShellOutput();
$this->assertMatchesStringSnapshot( $output );
$this->assertMatchesStringSnapshot( str_replace( $this->plugin_root, '{PUP_ROOT}', $output ) );

$I->runShellCommand( "php {$this->pup} clean" );

Expand Down
12 changes: 6 additions & 6 deletions tests/cli/Commands/InfoCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function it_should_provide_info( CliTester $I ) {
$I->runShellCommand( "php {$this->pup} info" );
$I->seeResultCodeIs( 0 );

$output = $this->removeDynamicDataFromOutput( $I->grabShellOutput() );
$output = $this->removeDynamicDataFromOutput( str_replace( $this->plugin_root, '{PUP_ROOT}', $I->grabShellOutput() ) );

$this->assertMatchesStringSnapshot( $output );
}
Expand All @@ -39,7 +39,7 @@ public function it_should_provide_info_with_puprc( CliTester $I ) {
$I->runShellCommand( "php {$this->pup} info" );
$I->seeResultCodeIs( 0 );

$output = $this->removeDynamicDataFromOutput( $I->grabShellOutput() );
$output = $this->removeDynamicDataFromOutput( str_replace( $this->plugin_root, '{PUP_ROOT}', $I->grabShellOutput() ) );

$this->assertMatchesStringSnapshot( $output );
}
Expand All @@ -55,7 +55,7 @@ public function it_should_provide_info_with_distignore( CliTester $I ) {
$I->runShellCommand( "php {$this->pup} info" );
$I->seeResultCodeIs( 0 );

$output = $this->removeDynamicDataFromOutput( $I->grabShellOutput() );
$output = $this->removeDynamicDataFromOutput( str_replace( $this->plugin_root, '{PUP_ROOT}', $I->grabShellOutput() ) );

$this->assertMatchesStringSnapshot( $output );

Expand All @@ -73,7 +73,7 @@ public function it_should_provide_info_with_distinclude( CliTester $I ) {
$I->runShellCommand( "php {$this->pup} info" );
$I->seeResultCodeIs( 0 );

$output = $this->removeDynamicDataFromOutput( $I->grabShellOutput() );
$output = $this->removeDynamicDataFromOutput( str_replace( $this->plugin_root, '{PUP_ROOT}', $I->grabShellOutput() ) );

$this->assertMatchesStringSnapshot( $output );

Expand All @@ -91,7 +91,7 @@ public function it_should_provide_info_with_gitattributes( CliTester $I ) {
$I->runShellCommand( "php {$this->pup} info" );
$I->seeResultCodeIs( 0 );

$output = $this->removeDynamicDataFromOutput( $I->grabShellOutput() );
$output = $this->removeDynamicDataFromOutput( str_replace( $this->plugin_root, '{PUP_ROOT}', $I->grabShellOutput() ) );

$this->assertMatchesStringSnapshot( $output );

Expand All @@ -111,7 +111,7 @@ public function it_should_show_invalid_puprc( CliTester $I ) {
$I->runShellCommand( "php {$this->pup} info" );
$I->seeResultCodeIs( 0 );

$output = $this->removeDynamicDataFromOutput( $I->grabShellOutput() );
$output = $this->removeDynamicDataFromOutput( str_replace( $this->plugin_root, '{PUP_ROOT}', $I->grabShellOutput() ) );

$this->assertMatchesStringSnapshot( $output );
}
Expand Down
Loading
Loading