From d42dd0705481bacf38c8d2a6c915398046ead014 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Thu, 25 Jul 2019 13:05:08 -0700 Subject: Remove dependency on nodejs and gulp --- app/Console/CssCommand.php | 4 +- app/Console/JsCommand.php | 112 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 app/Console/JsCommand.php (limited to 'app/Console') 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 @@ +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; + } +} -- cgit v1.2.3