Skip to content

Commit

Permalink
fix(bump): add lock files to commit
Browse files Browse the repository at this point in the history
Ref: #11
  • Loading branch information
Marco Cesarato committed Apr 15, 2021
1 parent 29a83e2 commit 4da2061
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Bump/ComposerJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class ComposerJson extends Bump
* {@inheritdoc}
*/
protected $fileName = 'composer.json';
/**
* {@inheritdoc}
*/
protected $lockFiles = ['composer.lock'];
/**
* {@inheritdoc}
*/
Expand Down
4 changes: 4 additions & 0 deletions src/Bump/PackageJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class PackageJson extends Bump
* {@inheritdoc}
*/
protected $fileName = 'package.json';
/**
* {@inheritdoc}
*/
protected $lockFiles = ['package.lock', 'yarn.lock', 'pnpm-lock.yaml'];
/**
* {@inheritdoc}
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,13 @@ public function generate(InputInterface $input, SymfonyStyle $output): int
$bumper->setVersion($newVersion);
$bumper->save();
$filesToCommit[] = $bumper->getFilePath();
$filesToCommit = array_merge($filesToCommit, $bumper->getExistingLockFiles());
}
} catch (Exception $e) {
$output->error('An error occurred bumping package version: ' . $e->getMessage());
}
}
$filesToCommit = array_unique($filesToCommit);
}

// Print summary
Expand Down
31 changes: 31 additions & 0 deletions src/Type/Bump.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ abstract class Bump
* @var string
*/
protected $fileName;
/**
* Package lock files.
*
* @var array
*/
protected $lockFiles;
/**
* Package file type.
*
Expand Down Expand Up @@ -108,6 +114,31 @@ public function getFileName(): string
return $this->fileName;
}

/**
* Get all existing lock files.
*/
public function getExistingLockFiles(): array
{
$paths = [];
foreach ($this->lockFiles as $lockFile) {
$path = $this->getPath() . DIRECTORY_SEPARATOR . $lockFile;
$path = preg_replace('/' . preg_quote(DIRECTORY_SEPARATOR, '/') . '+/', DIRECTORY_SEPARATOR, $path);
if (is_file($path)) {
$paths[] = $path;
}
}

return $paths;
}

/**
* Get lock file name.
*/
public function getLockFiles(): array
{
return $this->lockFiles;
}

/**
* Package file exists.
*/
Expand Down

0 comments on commit 4da2061

Please sign in to comment.