Skip to content
This repository has been archived by the owner on Jan 27, 2020. It is now read-only.

Commit

Permalink
Option to force build by clearing the cache
Browse files Browse the repository at this point in the history
* Add --force option to build command

* Clear the cache if --force is true
  • Loading branch information
dailysleaze authored and themsaid committed Apr 6, 2016
1 parent 8d8d402 commit 9a49809
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/Commands/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ protected function configure()
{
$this->setName('build')
->setDescription('Generate the site static files.')
->addOption('env', null, InputOption::VALUE_REQUIRED, 'Application Environment.', 'default');
->addOption('env', null, InputOption::VALUE_REQUIRED, 'Application Environment.', 'default')
->addOption('force', null, InputOption::VALUE_NONE, 'Clear the cache before building');
}

/**
Expand All @@ -66,11 +67,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$siteBuilder = new SiteBuilder(
$this->filesystem,
$this->viewFactory,
$input->getOption('env')
$input->getOption('env'),
$input->getOption('force')
);

$siteBuilder->build();

$output->writeln("<info>Site was generated successfully.</info>");
}
}
}
17 changes: 15 additions & 2 deletions src/SiteBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,21 @@ class SiteBuilder
*/
protected $blogDirectory = '_blog';

/**
* Clear the cache before building
*
* @var array
*/
protected $forceBuild = false;

/**
* SiteBuilder constructor.
*
* @param Filesystem $filesystem
* @param Factory $viewFactory
* @param string $environment
*/
public function __construct(Filesystem $filesystem, Factory $viewFactory, $environment)
public function __construct(Filesystem $filesystem, Factory $viewFactory, $environment, $forceBuild = false)
{
$this->filesystem = $filesystem;

Expand All @@ -76,6 +83,8 @@ public function __construct(Filesystem $filesystem, Factory $viewFactory, $envir
$this->fileHandler = new BaseHandler($filesystem, $viewFactory);

$this->blogPostHandler = new BlogPostHandler($filesystem, $viewFactory);

$this->forceBuild = $forceBuild;
}

/**
Expand Down Expand Up @@ -105,6 +114,10 @@ public function build()

$this->filesystem->cleanDirectory(KATANA_PUBLIC_DIR);

if ($this->forceBuild) {
$this->filesystem->cleanDirectory(KATANA_CACHE_DIR);
}

$this->handleSiteFiles($otherFiles);

if (@$this->configs['enableBlog']) {
Expand Down Expand Up @@ -231,4 +244,4 @@ private function buildBlogPagination()

$builder->build();
}
}
}

0 comments on commit 9a49809

Please sign in to comment.