-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathLangJsCommand.php
More file actions
120 lines (106 loc) · 3 KB
/
LangJsCommand.php
File metadata and controls
120 lines (106 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace Mariuzzo\LaravelJsLocalization\Commands;
use Illuminate\Support\Facades\Config;
use Illuminate\Console\Command;
use Mariuzzo\LaravelJsLocalization\Generators\LangJsGenerator;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
/**
* The LangJsCommand class.
*
* @author Rubens Mariuzzo <rubens@mariuzzo.com>
*/
class LangJsCommand extends Command
{
/**
* The command name.
*
* @var string
*/
protected $name = 'lang:js';
/**
* The command description.
*
* @var string
*/
protected $description = 'Generate JS lang files.';
/**
* The generator instance.
*
* @var LangJsGenerator
*/
protected $generator;
/**
* Construct a new LangJsCommand.
*
* @param LangJsGenerator $generator The generator.
*/
public function __construct(LangJsGenerator $generator)
{
$this->generator = $generator;
parent::__construct();
}
/**
* Fire the command. (Compatibility for < 5.0)
*/
public function fire()
{
$this->handle();
}
/**
* Handle the command.
*/
public function handle()
{
$target = $this->argument('target');
$options = [
'compress' => $this->option('compress'),
'json' => $this->option('json'),
'no-lib' => $this->option('no-lib') || $this->option('module'),
'module' => $this->option('module'),
'source' => $this->option('source'),
'no-sort' => $this->option('no-sort'),
];
if ($this->generator->generate($target, $options)) {
$this->info("Created: {$target}");
return;
}
$this->error("Could not create: {$target}");
}
/**
* Return all command arguments.
*
* @return array
*/
protected function getArguments()
{
return [
['target', InputArgument::OPTIONAL, 'Target path.', $this->getDefaultPath()],
];
}
/**
* Return the path to use when no path is specified.
*
* @return string
*/
protected function getDefaultPath()
{
return Config::get('localization-js.path', public_path('messages.js'));
}
/**
* Return all command options.
*
* @return array
*/
protected function getOptions()
{
return [
['compress', 'c', InputOption::VALUE_NONE, 'Compress the JavaScript file.', null],
['no-lib', 'nl', InputOption::VALUE_NONE, 'Do not include the lang.js library.', null],
['module', 'm', InputOption::VALUE_NONE, 'Output as ES module instead of commonjs, implies --no-lib', null],
['json', 'j', InputOption::VALUE_NONE, 'Only output the messages json.', null],
['source', 's', InputOption::VALUE_REQUIRED, 'Specifying a custom source folder', null],
['no-sort', 'ns', InputOption::VALUE_NONE, 'Do not sort the messages', null],
];
}
}