Skip to content

Commit

Permalink
Adapt command
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmichot committed Oct 31, 2024
1 parent 9a93e45 commit fc1b43c
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions app/Console/Commands/ServicesGenerate.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,45 +39,44 @@ private function processFile(string $file): false|array
{
$content = file_get_contents(base_path("templates/compose/$file"));

preg_match_all(
'/#\s*(documentation|env_file|ignore|logo|minversion|port|slogan|tags)\s*:\s*(.+)\s*/',
$content, $matches
);
$data = collect(explode(PHP_EOL, $content))->mapWithKeys(function ($line): array {
preg_match('/^#(?<key>.*):(?<value>.*)$/U', $line, $m);

$data = array_combine($matches[1], $matches[2]);
return $m ? [trim($m['key']) => trim($m['value'])] : [];
});

if (str($data['ignore'] ?? false)->toBoolean()) {
if (str($data->get('ignore'))->toBoolean()) {
$this->info("Ignoring $file");

return false;
}

$this->info("Processing $file");

$documentation = $data['documentation'] ?? null;
$documentation = $data->get('documentation');
$documentation = $documentation ? $documentation.'?utm_source=coolify.io' : 'https://coolify.io/docs';

$json = Yaml::parse($content);
$compose = base64_encode(Yaml::dump($json, 10, 2));

$tags = str($data['tags'] ?? '')->lower()->explode(',')->map(fn ($tag) => trim($tag))->filter();
$tags = str($data->get('tags'))->lower()->explode(',')->map(fn ($tag) => trim($tag))->filter();
$tags = $tags->isEmpty() ? null : $tags->all();

$payload = [
'name' => pathinfo($file, PATHINFO_FILENAME),
'documentation' => $documentation,
'slogan' => $data['slogan'] ?? str($file)->headline(),
'slogan' => $data->get('slogan', str($file)->headline()),
'compose' => $compose,
'tags' => $tags,
'logo' => $data['logo'] ?? 'svgs/coolify.png',
'minversion' => $data['minversion'] ?? '0.0.0',
'logo' => $data->get('logo', 'svgs/coolify.png'),
'minversion' => $data->get('minversion', '0.0.0'),
];

if ($port = $data['port'] ?? null) {
if ($port = $data->get('port')) {
$payload['port'] = $port;
}

if ($envFile = $data['env_file'] ?? null) {
if ($envFile = $data->get('env_file')) {
$envFileContent = file_get_contents(base_path("templates/compose/$envFile"));
$payload['envs'] = base64_encode($envFileContent);
}
Expand Down

0 comments on commit fc1b43c

Please sign in to comment.