diff --git a/composer.json b/composer.json index 9b858a4..4f8a200 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "coffeescript/coffeescript": "~1.3.1" }, "require-dev": { - "bldr-io/bldr": "~6.2@stable", + "bldr-io/bldr": "~7.0@stable", "dflydev/embedded-composer": "dev-master", "composer/composer": "dev-master" }, diff --git a/src/Call/LessCall.php b/src/Call/LessCall.php deleted file mode 100644 index e551860..0000000 --- a/src/Call/LessCall.php +++ /dev/null @@ -1,114 +0,0 @@ - - * - * This source file is subject to the license that is bundled - * with this source code in the file LICENSE - */ - -namespace Bldr\Block\Frontend\Call; - -use Bldr\Call\AbstractCall; -use Bldr\Call\Traits\FinderAwareTrait; -use Less_Parser; -use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Finder\Finder; -use Symfony\Component\Finder\SplFileInfo; - -/** - * @author Aaron Scherer - */ -class LessCall extends AbstractCall -{ - use FinderAwareTrait; - - /** - * @var Less_Parser $less - */ - private $less; - - /** - * {@inheritDoc} - */ - public function configure() - { - $this->setName('less') - ->setDescription('Compiles the `src` less files') - ->addOption('src', true, 'Less files to compile') - ->addOption('dest', true, 'Destination to save to') - ->addOption('compress', false, 'Should bldr remove whitespace and comments') - ->addOption('sourceMap', false, 'Should bldr create a source map') - ->addOption( - 'sourceMapWriteTo', - false, - 'Where should bldr write to? If this isn\'t set, it will be written to the compiled file.' - ) - ->addOption('sourceMapURL', false, 'Url to use for the source map'); - } - - /** - * {@inheritDoc} - */ - public function run() - { - - $this->less = new Less_Parser($this->getLessOptions()); - - $source = $this->getOption('src'); - $files = $this->getFiles($source); - - $this->compileFiles($files, $this->getOption('dest')); - } - - /** - * @return array - * @throws \RuntimeException - */ - private function getLessOptions() - { - $options = []; - if ($this->getOption('compress') === true) { - $options['compres'] = true; - } - - if ($this->hasOption('sourceMap')) { - $options['sourceMap'] = $this->getOption('sourceMap'); - } - - if ($this->hasOption('sourceMapWriteTo')) { - $options['sourceMapWriteTo'] = $this->getOption('sourceMapWriteTo'); - } - - if ($this->hasOption('sourceMapURL')) { - $options['sourceMapURL'] = $this->getOption('sourceMapURL'); - } - - return $options; - } - - /** - * @param SplFileInfo[] $files - * @param string $destination - */ - private function compileFiles(array $files, $destination) - { - foreach ($files as $file) { - if ($this->getOutput()->isVerbose()) { - $this->getOutput()->writeln("Compiling ".$file); - } - $this->less->parseFile($file); - } - - $output = $this->less->getCss(); - - if ($this->getOutput()->isVerbose()) { - $this->getOutput()->writeln("Writing to ".$destination); - } - $fs = new Filesystem; - $fs->mkdir(dirname($destination)); - $fs->dumpFile($destination, $output); - } -} diff --git a/src/FrontendBlock.php b/src/FrontendBlock.php index 3328062..1cf8e01 100644 --- a/src/FrontendBlock.php +++ b/src/FrontendBlock.php @@ -24,11 +24,11 @@ class FrontendBlock extends AbstractBlock */ protected function assemble(array $config, SymfonyContainerBuilder $container) { - $this->addCall('bldr_frontend.less', 'Bldr\Block\Frontend\Call\LessCall'); - $this->addCall('bldr_frontend.sass', 'Bldr\Block\Frontend\Call\SassCall'); - $this->addCall('bldr_frontend.coffee', 'Bldr\Block\Frontend\Call\CoffeeCall'); - $this->addCall('bldr_frontend.concat', 'Bldr\Block\Frontend\Call\ConcatCall'); - $this->addCall('bldr_frontend.minify.css', 'Bldr\Block\Frontend\Call\Minify\CssCall'); - $this->addCall('bldr_frontend.minify.js', 'Bldr\Block\Frontend\Call\Minify\JsCall'); + $this->addTask('bldr_frontend.less', 'Bldr\Block\Frontend\Task\LessTask'); + $this->addTask('bldr_frontend.sass', 'Bldr\Block\Frontend\Task\SassTask'); + $this->addTask('bldr_frontend.coffee', 'Bldr\Block\Frontend\Task\CoffeeTask'); + $this->addTask('bldr_frontend.concat', 'Bldr\Block\Frontend\Task\ConcatTask'); + $this->addTask('bldr_frontend.minify.css', 'Bldr\Block\Frontend\Task\Minify\CssTask'); + $this->addTask('bldr_frontend.minify.js', 'Bldr\Block\Frontend\Task\Minify\JsTask'); } } diff --git a/src/Call/CoffeeCall.php b/src/Task/CoffeeTask.php similarity index 52% rename from src/Call/CoffeeCall.php rename to src/Task/CoffeeTask.php index 1184798..361a53c 100644 --- a/src/Call/CoffeeCall.php +++ b/src/Task/CoffeeTask.php @@ -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 */ -class CoffeeCall extends AbstractCall +class CoffeeTask extends AbstractTask { use FinderAwareTrait; @@ -37,33 +37,34 @@ 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"; @@ -71,8 +72,8 @@ private function compileFiles(array $files, $destination) $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; diff --git a/src/Call/ConcatCall.php b/src/Task/ConcatTask.php similarity index 59% rename from src/Call/ConcatCall.php rename to src/Task/ConcatTask.php index 99903ba..56698cd 100644 --- a/src/Call/ConcatCall.php +++ b/src/Task/ConcatTask.php @@ -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 */ -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(); diff --git a/src/Task/LessTask.php b/src/Task/LessTask.php new file mode 100644 index 0000000..08830e7 --- /dev/null +++ b/src/Task/LessTask.php @@ -0,0 +1,115 @@ + + * + * 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 + */ +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); + } +} diff --git a/src/Call/Minify/CssCall.php b/src/Task/Minify/CssTask.php similarity index 54% rename from src/Call/Minify/CssCall.php rename to src/Task/Minify/CssTask.php index ad11def..c41e922 100644 --- a/src/Call/Minify/CssCall.php +++ b/src/Task/Minify/CssTask.php @@ -9,18 +9,19 @@ * with this source code in the file LICENSE */ -namespace Bldr\Block\Frontend\Call\Minify; +namespace Bldr\Block\Frontend\Task\Minify; -use Bldr\Call\AbstractCall; -use Bldr\Call\Traits\FinderAwareTrait; +use Bldr\Block\Core\Task\AbstractTask; +use Bldr\Block\Core\Task\Traits\FinderAwareTrait; use MatthiasMullie\Minify\CSS; +use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Finder\SplFileInfo; use Symfony\Component\Filesystem\Filesystem; /** * @author Aaron Scherer */ -class CssCall extends AbstractCall +class CssTask extends AbstractTask { use FinderAwareTrait; @@ -28,24 +29,27 @@ public function configure() { $this->setName('minify:css') ->setDescription('Minified the src files into the dest') - ->addOption('src', true, 'Files to Minify') - ->addOption('dest', true, 'Destination to save minified css'); + ->addParameter('src', true, 'Files to Minify') + ->addParameter('dest', true, 'Destination to save minified css'); } - public function run() + /** + * {@inheritdoc} + */ + public function run(OutputInterface $output) { - $destination = $this->getOption('dest'); + $destination = $this->getParameter('dest'); /** @var SplFileInfo[] $files */ - $files = $this->getFiles($this->getOption('src')); + $files = $this->getFiles($this->getParameter('src')); $minifier = new CSS(); foreach ($files as $file) { $minifier->add($file); } - if ($this->getOutput()->isVerbose()) { - $this->getOutput()->writeln("Writing to ".$destination); + if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) { + $output->writeln("Writing to ".$destination); } (new Filesystem)->mkdir(dirname($destination)); diff --git a/src/Call/Minify/JsCall.php b/src/Task/Minify/JsTask.php similarity index 58% rename from src/Call/Minify/JsCall.php rename to src/Task/Minify/JsTask.php index a56ebd3..ab8a362 100644 --- a/src/Call/Minify/JsCall.php +++ b/src/Task/Minify/JsTask.php @@ -9,18 +9,19 @@ * with this source code in the file LICENSE */ -namespace Bldr\Block\Frontend\Call\Minify; +namespace Bldr\Block\Frontend\Task\Minify; -use Bldr\Call\AbstractCall; -use Bldr\Call\Traits\FinderAwareTrait; +use Bldr\Block\Core\Task\AbstractTask; +use Bldr\Block\Core\Task\Traits\FinderAwareTrait; use JShrink\Minifier; +use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Finder\SplFileInfo; use Symfony\Component\Filesystem\Filesystem; /** * @author Aaron Scherer */ -class JsCall extends AbstractCall +class JsTask extends AbstractTask { use FinderAwareTrait; @@ -28,16 +29,19 @@ public function configure() { $this->setName('minify:js') ->setDescription('Minified the src files into the dest') - ->addOption('src', true, 'Files to Minify') - ->addOption('dest', true, 'Destination to save minified js'); + ->addParameter('src', true, 'Files to Minify') + ->addParameter('dest', true, 'Destination to save minified js'); } - public function run() + /** + * {@inheritdoc} + */ + public function run(OutputInterface $output) { - $destination = $this->getOption('dest'); + $destination = $this->getParameter('dest'); /** @var SplFileInfo[] $files */ - $files = $this->getFiles($this->getOption('src')); + $files = $this->getFiles($this->getParameter('src')); $code = ''; foreach ($files as $file) { @@ -47,8 +51,8 @@ public function run() } } - if ($this->getOutput()->isVerbose()) { - $this->getOutput()->writeln("Writing to ".$destination); + if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) { + $output->writeln("Writing to ".$destination); } $fs = new Filesystem(); diff --git a/src/Call/SassCall.php b/src/Task/SassTask.php similarity index 54% rename from src/Call/SassCall.php rename to src/Task/SassTask.php index 8060fa3..ad75e84 100644 --- a/src/Call/SassCall.php +++ b/src/Task/SassTask.php @@ -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 SassParser; +use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\SplFileInfo; /** * @author Aaron Scherer */ -class SassCall extends AbstractCall +class SassTask extends AbstractTask { use FinderAwareTrait; @@ -37,22 +37,22 @@ public function configure() { $this->setName('sass') ->setDescription('Compiles the `src` sass/scss files') - ->addOption('src', true, 'Sass/Scss files to compile') - ->addOption('dest', true, 'Destination to save to') - ->addOption('compress', false, 'Should bldr remove whitespace and comments'); + ->addParameter('src', true, 'Sass/Scss files to compile') + ->addParameter('dest', true, 'Destination to save to') + ->addParameter('compress', false, 'Should bldr remove whitespace and comments'); } /** * {@inheritDoc} */ - public function run() + public function run(OutputInterface $output) { $this->sass = new SassParser($this->getSassOptions()); - $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')); } /** @@ -62,7 +62,7 @@ public function run() private function getSassOptions() { $options = []; - if ($this->getOption('compress') === true) { + if ($this->getParameter('compress') === true) { $options['style'] = \SassRenderer::STYLE_COMPRESSED; } @@ -70,23 +70,24 @@ private function getSassOptions() } /** - * @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) { $fileSet = []; foreach ($files as $file) { - if ($this->getOutput()->isVerbose()) { - $this->getOutput()->writeln("Compiling ".$file); + if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) { + $output->writeln("Compiling ".$file); } $fileSet[] = (string) $file; } $output = $this->sass->toCss($fileSet); - if ($this->getOutput()->isVerbose()) { - $this->getOutput()->writeln("Writing to ".$destination); + if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) { + $output->writeln("Writing to ".$destination); } $fs = new Filesystem;