-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef6cf25
commit e8586f6
Showing
9 changed files
with
203 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,19 +9,19 @@ | |
* with this source code in the file LICENSE | ||
*/ | ||
|
||
namespace Bldr\Block\Frontend\Call; | ||
namespace Bldr\Block\Frontend\Task; | ||
|
||
use Bldr\Call\AbstractCall; | ||
use Bldr\Call\Traits\FinderAwareTrait; | ||
use Bldr\Block\Core\Task\AbstractTask; | ||
use Bldr\Block\Core\Task\Traits\FinderAwareTrait; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Finder\Finder; | ||
use Symfony\Component\Finder\SplFileInfo; | ||
use CoffeeScript\Compiler; | ||
|
||
/** | ||
* @author Aaron Scherer <[email protected]> | ||
*/ | ||
class CoffeeCall extends AbstractCall | ||
class CoffeeTask extends AbstractTask | ||
{ | ||
use FinderAwareTrait; | ||
|
||
|
@@ -37,42 +37,43 @@ public function configure() | |
{ | ||
$this->setName('coffee') | ||
->setDescription('Compiles the `src` coffee files') | ||
->addOption('src', true, 'Coffeescript files to compile') | ||
->addOption('dest', true, 'Destination to save to'); | ||
->addParameter('src', true, 'Coffeescript files to compile') | ||
->addParameter('dest', true, 'Destination to save to'); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function run() | ||
public function run(OutputInterface $output) | ||
{ | ||
$this->coffee = new Compiler(); | ||
|
||
$source = $this->getOption('src'); | ||
$source = $this->getParameter('src'); | ||
$files = $this->getFiles($source); | ||
|
||
$this->compileFiles($files, $this->getOption('dest')); | ||
$this->compileFiles($output, $files, $this->getParameter('dest')); | ||
} | ||
|
||
/** | ||
* @param SplFileInfo[] $files | ||
* @param string $destination | ||
* @param OutputInterface $output | ||
* @param SplFileInfo[] $files | ||
* @param string $destination | ||
*/ | ||
private function compileFiles(array $files, $destination) | ||
private function compileFiles(OutputInterface $output, array $files, $destination) | ||
{ | ||
$code = ''; | ||
foreach ($files as $file) { | ||
if ($this->getOutput()->isVerbose()) { | ||
$this->getOutput()->writeln("Compiling ".$file); | ||
if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) { | ||
$output->writeln("Compiling ".$file); | ||
} | ||
|
||
$code .= $file->getContents() . "\n"; | ||
} | ||
|
||
$output = $this->coffee->compile($code); | ||
|
||
if ($this->getOutput()->isVerbose()) { | ||
$this->getOutput()->writeln("Writing to ".$destination); | ||
if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) { | ||
$output->writeln("Writing to ".$destination); | ||
} | ||
|
||
$fs = new Filesystem; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,17 +9,18 @@ | |
* with this source code in the file LICENSE | ||
*/ | ||
|
||
namespace Bldr\Block\Frontend\Call; | ||
namespace Bldr\Block\Frontend\Task; | ||
|
||
use Bldr\Call\AbstractCall; | ||
use Bldr\Call\Traits\FinderAwareTrait; | ||
use Bldr\Block\Core\Task\AbstractTask; | ||
use Bldr\Block\Core\Task\Traits\FinderAwareTrait; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Finder\SplFileInfo; | ||
|
||
/** | ||
* @author Aaron Scherer <[email protected]> | ||
*/ | ||
class ConcatCall extends AbstractCall | ||
class ConcatTask extends AbstractTask | ||
{ | ||
use FinderAwareTrait; | ||
|
||
|
@@ -30,24 +31,24 @@ public function configure() | |
{ | ||
$this->setName('concat') | ||
->setDescription('Concatenates the src files into a dest') | ||
->addOption('src', true, 'The file(s) to concatenate') | ||
->addOption('dest', true, 'The filename and path to save the concatenated file') | ||
->addOption('banner', false, 'Banner to place at the top of the concatenated file') | ||
->addOption('separator', true, 'The separator to use between files', "\n"); | ||
->addParameter('src', true, 'The file(s) to concatenate') | ||
->addParameter('dest', true, 'The filename and path to save the concatenated file') | ||
->addParameter('banner', false, 'Banner to place at the top of the concatenated file') | ||
->addParameter('separator', true, 'The separator to use between files', "\n"); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function run() | ||
public function run(OutputInterface $output) | ||
{ | ||
$destination = $this->getOption('dest'); | ||
$files = $this->getFiles($this->getOption('src')); | ||
$destination = $this->getParameter('dest'); | ||
$files = $this->getFiles($this->getParameter('src')); | ||
|
||
$content = ''; | ||
foreach ($files as $file) { | ||
$fileContents = $this->getFileContents($file); | ||
$content .= $fileContents . $this->getOption('separator'); | ||
$content .= $fileContents . $this->getParameter('separator'); | ||
} | ||
|
||
$fs = new Filesystem(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of frontend-block | ||
* | ||
* (c) Aaron Scherer <[email protected]> | ||
* | ||
* This source file is subject to the license that is bundled | ||
* with this source code in the file LICENSE | ||
*/ | ||
|
||
namespace Bldr\Block\Frontend\Task; | ||
|
||
use Bldr\Block\Core\Task\AbstractTask; | ||
use Bldr\Block\Core\Task\Traits\FinderAwareTrait; | ||
use Less_Parser; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Finder\SplFileInfo; | ||
|
||
/** | ||
* @author Aaron Scherer <[email protected]> | ||
*/ | ||
class LessTask extends AbstractTask | ||
{ | ||
use FinderAwareTrait; | ||
|
||
/** | ||
* @var Less_Parser $less | ||
*/ | ||
private $less; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function configure() | ||
{ | ||
$this->setName('less') | ||
->setDescription('Compiles the `src` less files') | ||
->addParameter('src', true, 'Less files to compile') | ||
->addParameter('dest', true, 'Destination to save to') | ||
->addParameter('compress', false, 'Should bldr remove whitespace and comments') | ||
->addParameter('sourceMap', false, 'Should bldr create a source map') | ||
->addParameter( | ||
'sourceMapWriteTo', | ||
false, | ||
'Where should bldr write to? If this isn\'t set, it will be written to the compiled file.' | ||
) | ||
->addParameter('sourceMapURL', false, 'Url to use for the source map'); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function run() | ||
{ | ||
|
||
$this->less = new Less_Parser($this->getLessOptions()); | ||
|
||
$source = $this->getParameter('src'); | ||
$files = $this->getFiles($source); | ||
|
||
$this->compileFiles($output, $files, $this->getParameter('dest')); | ||
} | ||
|
||
/** | ||
* @return array | ||
* @throws \RuntimeException | ||
*/ | ||
private function getLessOptions() | ||
{ | ||
$options = []; | ||
if ($this->getParameter('compress') === true) { | ||
$options['compres'] = true; | ||
} | ||
|
||
if ($this->hasParameter('sourceMap')) { | ||
$options['sourceMap'] = $this->getParameter('sourceMap'); | ||
} | ||
|
||
if ($this->hasParameter('sourceMapWriteTo')) { | ||
$options['sourceMapWriteTo'] = $this->getParameter('sourceMapWriteTo'); | ||
} | ||
|
||
if ($this->hasParameter('sourceMapURL')) { | ||
$options['sourceMapURL'] = $this->getParameter('sourceMapURL'); | ||
} | ||
|
||
return $options; | ||
} | ||
|
||
/** | ||
* @param OutputInterface $output | ||
* @param SplFileInfo[] $files | ||
* @param string $destination | ||
*/ | ||
private function compileFiles(OutputInterface $output, array $files, $destination) | ||
{ | ||
foreach ($files as $file) { | ||
if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) { | ||
$output->writeln("Compiling ".$file); | ||
} | ||
$this->less->parseFile($file); | ||
} | ||
|
||
$output = $this->less->getCss(); | ||
|
||
if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) { | ||
$output->writeln("Writing to ".$destination); | ||
} | ||
$fs = new Filesystem; | ||
$fs->mkdir(dirname($destination)); | ||
$fs->dumpFile($destination, $output); | ||
} | ||
} |
Oops, something went wrong.