Skip to content

Commit

Permalink
Try and rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jul 12, 2024
1 parent 3a489b0 commit 40a40f0
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions monorepo/DevTools/src/RefactorConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Hyde\MonorepoDevTools;

use Hyde\Hyde;
use Throwable;
use Hyde\Enums\Feature;
use Illuminate\Support\Str;
use Symfony\Component\Yaml\Yaml;
Expand All @@ -15,6 +16,7 @@
use function copy;
use function config;
use function substr;
use function unlink;
use function collect;
use function implode;
use function in_array;
Expand Down Expand Up @@ -63,14 +65,23 @@ protected function migrateToYaml(): void
copy(Hyde::path('hyde.yml'), Hyde::path('hyde.yml.bak'));
}

$config = config('hyde');
$config = $this->serializePhpData($config);
try {
$config = config('hyde');
$config = $this->serializePhpData($config);

$yaml = Yaml::dump($config, 16, 4, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK | Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE);
$yaml = Yaml::dump($config, 16, 4, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK | Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE);

// Todo: Diff out defaults? (unless with argument)
// Todo: Diff out defaults? (unless with argument)

file_put_contents(Hyde::path('hyde.yml'), $yaml);
file_put_contents(Hyde::path('hyde.yml'), $yaml);
} catch (Throwable $exception) {
$this->error('Failed to migrate configuration: '.$exception->getMessage());
$this->warn('Rolling back changes...');
copy(Hyde::path('hyde.yml.bak'), Hyde::path('hyde.yml'));
unlink(Hyde::path('hyde.yml.bak'));

return;
}
}

protected function serializePhpData(array $config): array
Expand Down

0 comments on commit 40a40f0

Please sign in to comment.