Skip to content

Commit 737475f

Browse files
authored
Merge pull request #229 from os2display/feature/3197-load-template-paths
Added options to template command
2 parents ca2dc78 + 68549f1 commit 737475f

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
- [#229](https://github.com/os2display/display-api-service/pull/229)
8+
- Adds options to set paths to component and admin files from path to the json config file.
79
- [#225](https://github.com/os2display/display-api-service/pull/225)
810
- Added ADRs.
911
- [#215](https://github.com/os2display/display-api-service/pull/215)

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
"bin/console doctrine:schema:validate",
131131
"@coding-standards-apply",
132132
"vendor/bin/rector",
133-
"vendor/bin/psalm",
133+
"vendor/bin/psalm --no-cache",
134134
"@test-setup",
135135
"@test"
136136
],

src/Command/LoadTemplateCommand.php

+20-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Console\Command\Command;
1515
use Symfony\Component\Console\Input\InputArgument;
1616
use Symfony\Component\Console\Input\InputInterface;
17+
use Symfony\Component\Console\Input\InputOption;
1718
use Symfony\Component\Console\Output\OutputInterface;
1819
use Symfony\Component\Console\Style\SymfonyStyle;
1920
use Symfony\Component\Uid\Ulid;
@@ -33,6 +34,8 @@ public function __construct(
3334
protected function configure(): void
3435
{
3536
$this->addArgument('filename', InputArgument::REQUIRED, 'json file to load. Can be a local file or a URL');
37+
$this->addOption('path-from-filename', 'p', InputOption::VALUE_NONE, 'Set path to component and admin from filename. Assumes that the config file loaded has the naming format: [templateName]-config[.*].json.', null);
38+
$this->addOption('timestamp', 't', InputOption::VALUE_NONE, 'Add a timestamp to the component and admin urls: ?ts=. Only applies if path-from-filename option is active.', null);
3639
}
3740

3841
final protected function execute(InputInterface $input, OutputInterface $output): int
@@ -41,7 +44,9 @@ final protected function execute(InputInterface $input, OutputInterface $output)
4144
$successMessage = 'Template updated';
4245

4346
try {
47+
/** @var string $filename */
4448
$filename = $input->getArgument('filename');
49+
4550
$content = json_decode(file_get_contents($filename), false, 512, JSON_THROW_ON_ERROR);
4651

4752
// Validate template json.
@@ -87,8 +92,21 @@ final protected function execute(InputInterface $input, OutputInterface $output)
8792
}
8893

8994
$template->setIcon($content->icon);
90-
// @TODO: Resource should be an object.
91-
$template->setResources(get_object_vars($content->resources));
95+
96+
$resources = get_object_vars($content->resources);
97+
98+
if ($input->getOption('path-from-filename')) {
99+
// Set paths to component and admin from filename.
100+
$resources['component'] = preg_replace("/-config.*\.json$/", '.js', $filename);
101+
$resources['admin'] = preg_replace("/-config.*\.json$/", '-admin.json', $filename);
102+
103+
if ($input->getOption('timestamp')) {
104+
$resources['component'] = $resources['component'].'?ts='.time();
105+
$resources['admin'] = $resources['admin'].'?ts='.time();
106+
}
107+
}
108+
109+
$template->setResources($resources);
92110
$template->setTitle($content->title);
93111
$template->setDescription($content->description);
94112

0 commit comments

Comments
 (0)