mirror of
https://github.com/silverstripe/recipe-plugin.git
synced 2024-10-22 14:05:55 +02:00
FIX Only write composer.json if there are changes (#21)
FIX Only write composer.json if there are changes
This commit is contained in:
parent
8a77da94d1
commit
301daf2437
@ -16,6 +16,10 @@ use RegexIterator;
|
||||
|
||||
class RecipeInstaller extends LibraryInstaller
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $hasWrittenFiles = false;
|
||||
|
||||
public function __construct(IOInterface $io, Composer $composer)
|
||||
{
|
||||
@ -67,13 +71,15 @@ class RecipeInstaller extends LibraryInstaller
|
||||
}
|
||||
|
||||
// If any files are written, modify composer.json with newly installed files
|
||||
if ($installedFiles) {
|
||||
if ($this->hasWrittenFiles) {
|
||||
sort($installedFiles);
|
||||
if (!isset($composerData['extra'])) {
|
||||
$composerData['extra'] = [];
|
||||
}
|
||||
$composerData['extra'][$registrationKey] = $installedFiles;
|
||||
$composerFile->write($composerData);
|
||||
// Reset the variable so that we can try this trick again later
|
||||
$this->hasWrittenFiles = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,6 +121,7 @@ class RecipeInstaller extends LibraryInstaller
|
||||
$this->io->write(" - Copying <info>$relativePath</info>");
|
||||
$this->filesystem->ensureDirectoryExists(dirname($destination ?? ''));
|
||||
copy($sourcePath ?? '', $destination ?? '');
|
||||
$this->hasWrittenFiles = true;
|
||||
}
|
||||
return $relativePath;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user