Skip to content

Commit

Permalink
Merge pull request #3 from siosphere/tops-4327-force-rebuild-flag
Browse files Browse the repository at this point in the history
Make --force flag actually function by removing target asset
  • Loading branch information
connorjclark authored Sep 4, 2018
2 parents 552f867 + 2ed9249 commit 9f531c3
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/Command/RebuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class RebuildCommand extends DumpCommand
{
static $assetTargetPaths;

/**
* Force the rebuild regardless if asset already exists
*/
protected $force;

protected function configure()
{
$this
Expand Down Expand Up @@ -50,6 +55,12 @@ protected function execute(InputInterface $input, OutputInterface $stdout)
$stdout->writeln(sprintf('Debug mode is <comment>%s</comment>.', $this->am->isDebug() ? 'on' : 'off'));
$stdout->writeln('');

$this->force = $input->getOption('force') ?? false;
if($this->force) {
$stdout->writeln('<comment>Force recompile</comment>.');
$stdout->writeln('');
}

self::$assetTargetPaths = [];
foreach ($this->am->getNames() as $name) {
$this->dumpAsset($name, $stdout);
Expand Down Expand Up @@ -197,13 +208,21 @@ private function doDump(AssetInterface $asset, OutputInterface $stdout)
$stdout->writeln(
'<info>found</info>'
);
continue;
} else {
if(!$this->force) {
continue;
}

$stdout->writeln(
'<comment>creating</comment>'
'<info>force recompile</info>'
);

unlink($target);
}

$stdout->writeln(
'<comment>creating</comment>'
);

if (false === @file_put_contents($target, $asset->dump())) {
throw new \RuntimeException('Unable to write file '.$target);
}
Expand Down

0 comments on commit 9f531c3

Please sign in to comment.