Skip to content

Commit 03d9386

Browse files
JohnathonKosterryanmitchellduncanmcclean
authored
Corrects issue with importing/exporting Blueprints on Windows (#351)
* 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]>
1 parent 8111023 commit 03d9386

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/Commands/ExportBlueprints.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
use Statamic\Console\RunsInPlease;
99
use Statamic\Eloquent\Fields\BlueprintModel;
1010
use Statamic\Eloquent\Fields\FieldsetModel;
11+
use Statamic\Facades\Blueprint as BlueprintFacade;
1112
use Statamic\Fields\Blueprint as StacheBlueprint;
1213
use Statamic\Fields\Fieldset as StacheFieldset;
1314
use Statamic\Support\Arr;
15+
use Statamic\Support\Str;
1416

1517
class ExportBlueprints extends Command
1618
{
@@ -74,7 +76,7 @@ private function exportBlueprints()
7476
->setHandle($model->handle)
7577
->setHidden(Arr::get($model->data, 'hide'))
7678
->setOrder(Arr::get($model->data, 'order'))
77-
->setNamespace($model->namespace)
79+
->setNamespace($this->getBlueprintNamespace($model->namespace))
7880
->setContents($this->updateOrderFromBlueprintSections($model->data))
7981
->save();
8082
});
@@ -100,6 +102,18 @@ private function exportFieldsets()
100102
$this->info('Fieldsets exported');
101103
}
102104

105+
private function getBlueprintNamespace(string $namespace): string
106+
{
107+
$blueprintDirectory = str_replace('\\', '/', BlueprintFacade::directory());
108+
$blueprintDirectory = str_replace('/', '.', $blueprintDirectory);
109+
110+
if (Str::startsWith($namespace, $blueprintDirectory)) {
111+
return mb_substr($namespace, mb_strlen($blueprintDirectory));
112+
}
113+
114+
return $namespace;
115+
}
116+
103117
private function updateOrderFromBlueprintSections($contents)
104118
{
105119
$contents['tabs'] = collect($contents['tabs'] ?? [])

src/Commands/ImportBlueprints.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private function importBlueprints(): void
6969
return;
7070
}
7171

72-
$directory = resource_path('blueprints');
72+
$directory = str_replace('\\', '/', resource_path('blueprints'));
7373

7474
$files = File::withAbsolutePaths()
7575
->getFilesByTypeRecursively($directory, 'yaml');
@@ -129,7 +129,7 @@ private function importFieldsets(): void
129129
return;
130130
}
131131

132-
$directory = resource_path('fieldsets');
132+
$directory = str_replace('\\', '/', resource_path('fieldsets'));
133133

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

0 commit comments

Comments
 (0)