Skip to content

Commit

Permalink
Merge pull request #8 from Hodgy/feature/ignore-improvements
Browse files Browse the repository at this point in the history
Be more explicit when ignoring dirs and allow file ignores
  • Loading branch information
Elendev authored Apr 11, 2019
2 parents afd5d94 + 47c8680 commit 4e60c26
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ Many of the options are optional since they can be added directly to the `compos
[--url=<URL to the composer nexus repository>] \
[--username=USERNAME] \
[--password=PASSWORD] \
[--ignore-dirs=test] \
[--ignore-dirs=foo] \
[--ignore=test.php]\
[--ignore=foo/]\
[--ignore-by-git-attributes]
<version>

# Example
$ composer nexus-push --username=admin --password=admin123 --url=http://localhost:8081/repository/composer --ignore-dirs=test --ignore-dirs=foo 0.0.1
$ composer nexus-push --username=admin --password=admin123 --url=http://localhost:8081/repository/composer --ignore=test.php --ignore=foo/ 0.0.1
```

## Configuration
Expand All @@ -34,9 +34,9 @@ It's possible to add some configurations inside the `composer.json` file:
"username": "admin",
"password": "admin123",
"ignore-by-git-attributes": true,
"ignore-dirs": [
"test",
"foo"
"ignore": [
"test.php",
"foo/"
]
}
}
Expand Down
38 changes: 34 additions & 4 deletions src/PushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ protected function configure()
'Username to log in the distant Nexus repository'
),
new InputOption('password', null, InputArgument::OPTIONAL, 'Password to log in the distant Nexus repository'),
new InputOption('ignore-dirs', 'i', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Directories to ignore when creating the zip'),
new InputOption('ignore', 'i', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Directories and files to ignore when creating the zip'),
new InputOption('ignore-dirs', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, '<error>DEPRECATED</error> Directories to ignore when creating the zip'),
new InputOption('ignore-by-git-attributes', null, InputOption::VALUE_NONE, 'Ignore .gitattrbutes export-ignore directories when creating the zip'),
])
->setHelp(
Expand Down Expand Up @@ -69,7 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$packageName . '-' . $input->getArgument('version')
));

$ignoredDirectories = $this->getDirectoriesToIgnore($input);
$ignoredDirectories = $this->getIgnores($input);
$this->getIO()
->write(
'Ignore directories: ' . join(' ', $ignoredDirectories),
Expand Down Expand Up @@ -348,17 +349,46 @@ private function getNexusExtra($parameter, $default = null)
}
}

/**
* Fetch any directories or files to be excluded from zip creation
*
* @param InputInterface $input
* @return array
*/
private function getIgnores(InputInterface $input)
{
// Remove after removal of --ignore-dirs option
$deprecatedIgnores = $this->getDirectoriesToIgnore($input);

$optionalIgnore = $input->getOption('ignore');
$composerIgnores = $this->getNexusExtra('ignore', []);
$gitAttrIgnores = $this->getGitAttributesExportIgnores($input);
$defaultIgnores = ['vendor/'];

$ignore = array_merge($deprecatedIgnores, $composerIgnores, $optionalIgnore, $gitAttrIgnores, $defaultIgnores );
return array_unique($ignore);

}

/**
* @param InputInterface $input
* @deprecated argument has been changed to ignore
* @return array
*/
private function getDirectoriesToIgnore(InputInterface $input)
{
$optionalIgnore = $input->getOption('ignore-dirs');
$composerIgnores = $this->getNexusExtra('ignore-dirs', []);
$gitAttrIgnores = $this->getGitAttributesExportIgnores($input);

$ignore = array_merge($composerIgnores, $optionalIgnore, ['vendor'], $gitAttrIgnores);
if (!empty($optionalIgnore)) {
$this->getIO()->write('<error>The --ignore-dirs option has been deprecated. Please use --ignore instead</error>');
}

if (!empty($composerIgnores)) {
$this->getIO()->write('<error>The ignore-dirs config option has been deprecated. Please use ignore instead</error>');
}

$ignore = array_merge($composerIgnores, $optionalIgnore);
return array_unique($ignore);
}

Expand Down
10 changes: 5 additions & 5 deletions src/ZipArchiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class ZipArchiver
* @param string $destination archive destination
* @param string $subDirectory subdirectory in which the sources will be
* archived. If null, put at the root of the directory.
* @param array $ignorePatterns
*
* @param array $ignores
* @param \Composer\IO\IOInterface|null $io
*
* @throws \Exception
Expand All @@ -28,7 +27,7 @@ public static function archiveDirectory(
$source,
$destination,
$subDirectory = null,
$ignorePatterns = [],
$ignores = [],
$io = null
) {
if (empty($io)) {
Expand All @@ -46,10 +45,11 @@ public static function archiveDirectory(

$finder->in($source)->ignoreVCS(true);

foreach ($ignorePatterns as $ignorePattern) {
$finder->notPath($ignorePattern);
foreach ($ignores as $ignore) {
$finder->notPath($ignore);
}


$archive = new \ZipArchive();

$io->write(
Expand Down

0 comments on commit 4e60c26

Please sign in to comment.