Skip to content

Commit bd9dd4c

Browse files
committed
Command options to allow js compression.
1 parent 1508135 commit bd9dd4c

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"php": ">=5.3.0",
1010
"illuminate/support": "4.1.*",
1111
"illuminate/console": "4.1.*",
12-
"illuminate/filesystem": "4.1.*"
12+
"illuminate/filesystem": "4.1.*",
13+
"tedivm/jshrink": "0.5.*"
1314
},
1415
"require-dev": {
1516
"phpunit/phpunit": "4.0.*",

src/Commands/LangJsCommand.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ public function __construct(LangJsGenerator $generator)
2222
public function fire()
2323
{
2424
$target = $this->argument('target');
25+
$options = array(
26+
'compress' => $this->option('compress')
27+
);
2528

26-
if ($this->generator->make($target))
29+
if ($this->generator->make($target, $options))
2730
{
2831
return $this->info("Created: {$target}");
2932
}
@@ -40,6 +43,8 @@ protected function getArguments()
4043

4144
protected function getOptions()
4245
{
43-
return array();
46+
return array(
47+
array('compress', 'c', InputOption::VALUE_NONE, 'Compress the JavaScript file.', null),
48+
);
4449
}
4550
}

src/Generators/LangJsGenerator.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php namespace Mariuzzo\LaravelJsLocalization\Generators;
22

33
use Illuminate\Filesystem\Filesystem as File;
4+
use JShrink\Minifier;
45

56
class LangJsGenerator
67
{
@@ -11,7 +12,7 @@ public function __construct(File $file)
1112
$this->file = $file;
1213
}
1314

14-
public function make($target)
15+
public function make($target, $options)
1516
{
1617
$messages = $this->getMessages();
1718
$this->prepareTarget($target);
@@ -22,6 +23,11 @@ public function make($target)
2223
$template = str_replace('\'{ messages }\'', json_encode($messages), $template);
2324
$template = str_replace('\'{ langjs }\';', $langjs, $template);
2425

26+
if ($options['compress'])
27+
{
28+
$template = Minifier::minify($template);
29+
}
30+
2531
return $this->file->put($target, $template);
2632
}
2733

0 commit comments

Comments
 (0)