Skip to content

Commit

Permalink
Corrects issue with importing/exporting Blueprints on Windows (#351)
Browse files Browse the repository at this point in the history
* Corrects issue with importing/exporting Blueprints on Windows

* Same for fieldsets

* import blueprint facade & rename variable

* Move the namespace "normalisation" into the exporter

We probably don't need to override the `Blueprint` class to do this, especially since our overridden method is only used in the exporter command.

* 🍺

---------

Co-authored-by: Ryan Mitchell <[email protected]>
Co-authored-by: Duncan McClean <[email protected]>
  • Loading branch information
3 people committed Sep 11, 2024
1 parent 8111023 commit 03d9386
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/Commands/ExportBlueprints.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
use Statamic\Console\RunsInPlease;
use Statamic\Eloquent\Fields\BlueprintModel;
use Statamic\Eloquent\Fields\FieldsetModel;
use Statamic\Facades\Blueprint as BlueprintFacade;
use Statamic\Fields\Blueprint as StacheBlueprint;
use Statamic\Fields\Fieldset as StacheFieldset;
use Statamic\Support\Arr;
use Statamic\Support\Str;

class ExportBlueprints extends Command
{
Expand Down Expand Up @@ -74,7 +76,7 @@ private function exportBlueprints()
->setHandle($model->handle)
->setHidden(Arr::get($model->data, 'hide'))
->setOrder(Arr::get($model->data, 'order'))
->setNamespace($model->namespace)
->setNamespace($this->getBlueprintNamespace($model->namespace))
->setContents($this->updateOrderFromBlueprintSections($model->data))
->save();
});
Expand All @@ -100,6 +102,18 @@ private function exportFieldsets()
$this->info('Fieldsets exported');
}

private function getBlueprintNamespace(string $namespace): string
{
$blueprintDirectory = str_replace('\\', '/', BlueprintFacade::directory());
$blueprintDirectory = str_replace('/', '.', $blueprintDirectory);

if (Str::startsWith($namespace, $blueprintDirectory)) {
return mb_substr($namespace, mb_strlen($blueprintDirectory));
}

return $namespace;
}

private function updateOrderFromBlueprintSections($contents)
{
$contents['tabs'] = collect($contents['tabs'] ?? [])
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/ImportBlueprints.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private function importBlueprints(): void
return;
}

$directory = resource_path('blueprints');
$directory = str_replace('\\', '/', resource_path('blueprints'));

$files = File::withAbsolutePaths()
->getFilesByTypeRecursively($directory, 'yaml');
Expand Down Expand Up @@ -129,7 +129,7 @@ private function importFieldsets(): void
return;
}

$directory = resource_path('fieldsets');
$directory = str_replace('\\', '/', resource_path('fieldsets'));

$files = File::withAbsolutePaths()
->getFilesByTypeRecursively($directory, 'yaml');
Expand Down

0 comments on commit 03d9386

Please sign in to comment.