diff options
author | Frédéric Guillot <fred@kanboard.net> | 2019-07-25 13:05:08 -0700 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2019-07-25 13:05:08 -0700 |
commit | d42dd0705481bacf38c8d2a6c915398046ead014 (patch) | |
tree | ba8b448becb5c8ed66f69b37d6daddde6281ff11 /app/Console | |
parent | 9ae185c18eb06e3ce7e2daea0c61e6f6478bdca9 (diff) |
Remove dependency on nodejs and gulp
Diffstat (limited to 'app/Console')
-rw-r--r-- | app/Console/CssCommand.php | 4 | ||||
-rw-r--r-- | app/Console/JsCommand.php | 112 |
2 files changed, 114 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; + } +} |