diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/Console/CssCommand.php | 4 | ||||
-rw-r--r-- | app/Console/JsCommand.php | 112 | ||||
-rw-r--r-- | app/ServiceProvider/CommandProvider.php | 2 |
3 files changed, 116 insertions, 2 deletions
diff --git a/app/Console/CssCommand.php b/app/Console/CssCommand.php index f141519e..a246a0db 100644 --- a/app/Console/CssCommand.php +++ b/app/Console/CssCommand.php @@ -98,7 +98,7 @@ class CssCommand extends BaseCommand { $this ->setName('css') - ->setDescription('Minify CSS') + ->setDescription('Minify CSS files') ; } @@ -114,7 +114,7 @@ class CssCommand extends BaseCommand $minifier = new Minify\CSS(); foreach ($files as $file) { - $filename = $folder. $file; + $filename = $folder.$file; if (! file_exists($filename)) { die("$filename not found\n"); } diff --git a/app/Console/JsCommand.php b/app/Console/JsCommand.php new file mode 100644 index 00000000..4adf42be --- /dev/null +++ b/app/Console/JsCommand.php @@ -0,0 +1,112 @@ +<?php + +namespace Kanboard\Console; + +use MatthiasMullie\Minify; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +$path = __DIR__ . '/../../libs'; +require_once $path . '/minify/src/Minify.php'; +require_once $path . '/minify/src/CSS.php'; +require_once $path . '/minify/src/JS.php'; +require_once $path . '/minify/src/Exception.php'; +require_once $path . '/minify/src/Exceptions/BasicException.php'; +require_once $path . '/minify/src/Exceptions/FileImportException.php'; +require_once $path . '/minify/src/Exceptions/IOException.php'; +require_once $path . '/path-converter/src/ConverterInterface.php'; +require_once $path . '/path-converter/src/Converter.php'; + +/** + * Class JsCommand + * + * @package Kanboard\Console + * @author Frederic Guillot + */ +class JsCommand extends BaseCommand +{ + const CSS_DIST_PATH = 'assets/js/'; + + private $appFiles = [ + 'assets/vendor/textarea-caret/index.js', + 'assets/js/polyfills/*.js', + 'assets/js/core/base.js', + 'assets/js/core/dom.js', + 'assets/js/core/html.js', + 'assets/js/core/http.js', + 'assets/js/core/modal.js', + 'assets/js/core/tooltip.js', + 'assets/js/core/utils.js', + 'assets/js/components/*.js', + 'assets/js/core/bootstrap.js', + 'assets/js/src/Namespace.js', + 'assets/js/src/App.js', + 'assets/js/src/BoardCollapsedMode.js', + 'assets/js/src/BoardColumnView.js', + 'assets/js/src/BoardHorizontalScrolling.js', + 'assets/js/src/BoardPolling.js', + 'assets/js/src/Column.js', + 'assets/js/src/Dropdown.js', + 'assets/js/src/Search.js', + 'assets/js/src/Swimlane.js', + 'assets/js/src/Task.js', + 'assets/js/src/BoardDragAndDrop.js', + 'assets/js/src/Bootstrap.js' + ]; + + private $vendorFiles = [ + 'assets/vendor/jquery/jquery-3.3.1.min.js', + 'assets/vendor/jquery-ui/jquery-ui.min.js', + 'assets/vendor/jquery-ui/i18n/datepicker-*.js', + 'assets/vendor/jqueryui-timepicker-addon/jquery-ui-timepicker-addon.min.js', + 'assets/vendor/jqueryui-timepicker-addon/i18n/jquery-ui-timepicker-addon-i18n.min.js', + 'assets/vendor/jqueryui-touch-punch/jquery.ui.touch-punch.min.js', + 'assets/vendor/select2/js/select2.min.js', + 'assets/vendor/select2/js/i18n/*.js', + 'assets/vendor/d3/d3.min.js', + 'assets/vendor/c3/c3.min.js', + 'assets/vendor/isMobile/isMobile.min.js', + 'assets/vendor/marked/marked.min.js', + ]; + + protected function configure() + { + $this + ->setName('js') + ->setDescription('Minify Javascript files') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $appBundle = $this->concat($this->appFiles); + $vendorBundle = $this->concat($this->vendorFiles); + + $minifier = new Minify\JS($appBundle); + + file_put_contents('assets/js/app.min.js', $minifier->minify()); + file_put_contents('assets/js/vendor.min.js', $vendorBundle); + } + + private function concat(array $files) + { + $data = ''; + foreach ($files as $pattern) { + foreach (glob($pattern) as $filename) { + echo $filename.PHP_EOL; + if (! file_exists($filename)) { + die("$filename not found\n"); + } + + $contents = file_get_contents($filename); + if ($contents === false) { + die("Unable to read $filename\n"); + } + + $data .= $contents; + } + } + + return $data; + } +} diff --git a/app/ServiceProvider/CommandProvider.php b/app/ServiceProvider/CommandProvider.php index 77c8b395..f08f76cc 100644 --- a/app/ServiceProvider/CommandProvider.php +++ b/app/ServiceProvider/CommandProvider.php @@ -25,6 +25,7 @@ use Kanboard\Console\TransitionExportCommand; use Kanboard\Console\VersionCommand; use Kanboard\Console\WorkerCommand; use Kanboard\Console\CssCommand; +use Kanboard\Console\JsCommand; use Pimple\Container; use Pimple\ServiceProviderInterface; use Symfony\Component\Console\Application; @@ -69,6 +70,7 @@ class CommandProvider implements ServiceProviderInterface $application->add(new DatabaseVersionCommand($container)); $application->add(new VersionCommand($container)); $application->add(new CssCommand($container)); + $application->add(new JsCommand($container)); $container['cli'] = $application; return $container; |