Skip to content

Commit 1d66c6c

Browse files
committed
Add checkExistence() with overwrite option
1 parent f60ca99 commit 1d66c6c

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/Commands/InstallBlock.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public function handle()
3333
$this->instructions = Stringy::between($choice, ': ', ' [');
3434

3535
try {
36+
$this->checkExistence('Fieldset', "resources/fieldsets/{$this->filename}.yaml");
37+
$this->checkExistence('Partial', "resources/views/page_builder/_{$this->filename}.antlers.html");
38+
3639
$this->copyStubs();
3740
$this->updatePageBuilder($this->block_name, $this->instructions, $this->filename);
3841
} catch (\Exception $e) {

src/Commands/InstallPreset.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,13 @@ public function handle()
7171
->replace('{{ singular_handle }}', $this->rename_singular_handle)
7272
->replace('{{ singular_name }}', $this->rename_singular_name);
7373

74-
$target->put($output, $contents);
74+
try {
75+
$this->checkExistence('File', "{$output}");
76+
$target->put($output, $contents);
77+
} catch (\Exception $e) {
78+
exit($this->error($e->getMessage()));
79+
}
80+
7581
$this->info("Installed file: '{$output}'.");
7682
}
7783

src/Commands/SharedFunctions.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ trait SharedFunctions {
1616
public function checkExistence($type, $path)
1717
{
1818
if (File::exists(base_path($path))) {
19-
throw new \Exception("{$type} '{$path}' already exists.");
19+
if ($this->confirm("{$type} '{$path}' already exists. Do you want to continue and overwrite this file?", true)) {
20+
return false;
21+
} else {
22+
throw new \Exception("Aborted. {$type} '{$path}' already exists.");
23+
}
2024
}
2125
}
2226

0 commit comments

Comments
 (0)