Improved devmode
* Added --init option to generate a new configuration file * Improved prompt * Added support for generating a dynamic .env.local file
This commit is contained in:
@ -8,6 +8,8 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Spark\DevMode\DevMode;
|
||||
|
||||
#[AsCommand(name:'dev', description:'Enter development mode')]
|
||||
@ -15,15 +17,61 @@ class DevCommand extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->addOption("init", null, InputOption::VALUE_NONE, "Initialize a new devmode.json file");
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$env = $this->getEnvironment();
|
||||
|
||||
if ($input->getOption("init")) {
|
||||
$conffile = $env->getConfigDirectory()."/devmode.json";
|
||||
if (file_exists($conffile)) {
|
||||
$output->writeln("<error>You have already created a devmode.json file</>");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
$this->initConfig($conffile, $input, $output);
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$devmode = new DevMode($env);
|
||||
$devmode->run();
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
private function initConfig(string $file, InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$qh = new QuestionHelper();
|
||||
|
||||
$titleQuestion = new Question("Window title []: ", null);
|
||||
$title = $qh->ask($input, $output, $titleQuestion);
|
||||
|
||||
$commandQuestion = new Question(" Command []: ", null);
|
||||
|
||||
$startup = [];
|
||||
$output->writeln("Startup commands. Enter an empty line to continue.");
|
||||
while ($command = $qh->ask($input, $output, $commandQuestion)) {
|
||||
$startup[] = $command;
|
||||
}
|
||||
|
||||
$shutdown = [];
|
||||
$output->writeln("Shutdown commands. Enter an empty line to continue.");
|
||||
while ($command = $qh->ask($input, $output, $commandQuestion)) {
|
||||
$shutdown[] = $command;
|
||||
}
|
||||
|
||||
$json = [
|
||||
'devmode' => [
|
||||
]
|
||||
];
|
||||
if ($title)
|
||||
$json['devmode']['title'] = $title;
|
||||
$json['devmode']['startup'] = $startup;
|
||||
$json['devmode']['shutdown'] = $shutdown;
|
||||
|
||||
$out = json_encode($json, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
||||
|
||||
file_put_contents($file, $out);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user