Skip to content

Commit ccdbdaf

Browse files
author
nejc
committed
Add default preset support
- Add default_preset configuration option - Automatically apply default preset when no specific config is set - Update README with default preset documentation - Improve user experience with sensible defaults
1 parent d7588ca commit ccdbdaf

File tree

3 files changed

+83
-10
lines changed

3 files changed

+83
-10
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ UPSTREAM_LOCAL_BRANCH=main
9797
UPSTREAM_STRATEGY=merge
9898
UPSTREAM_COMMIT_MESSAGE="chore(upstream): sync from upstream"
9999
UPSTREAM_ALLOW_UNRELATED=true
100+
UPSTREAM_DEFAULT_PRESET=vue
101+
UPSTREAM_AUTO_DETECT=true
100102
GIT_BINARY=git
101103
```
102104

@@ -140,6 +142,28 @@ php artisan upstream:setup --preset=custom --url=https://github.com/your-org/you
140142
php artisan upstream:sync --test
141143
```
142144

145+
### Using Default Presets
146+
147+
You can set a default preset in your `.env` file to automatically use a specific starter kit configuration:
148+
149+
```env
150+
# Set Vue as the default preset
151+
UPSTREAM_DEFAULT_PRESET=vue
152+
153+
# Or React
154+
UPSTREAM_DEFAULT_PRESET=react
155+
156+
# Or Livewire
157+
UPSTREAM_DEFAULT_PRESET=livewire
158+
```
159+
160+
With a default preset configured, you can simply run:
161+
162+
```bash
163+
# Uses the default preset automatically
164+
php artisan upstream:sync --test
165+
```
166+
143167
### Advanced Usage
144168

145169
#### Basic Sync

src/Config/upstream.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,30 @@
5757
// 'php artisan up',
5858
],
5959

60+
/*
61+
|--------------------------------------------------------------------------
62+
| Default Preset
63+
|--------------------------------------------------------------------------
64+
|
65+
| Set a default preset to use when no specific configuration is provided.
66+
| Options: vue, react, livewire, custom, or null (no default)
67+
|
68+
*/
69+
'default_preset' => env('UPSTREAM_DEFAULT_PRESET', 'vue'),
70+
71+
72+
73+
/*
74+
|--------------------------------------------------------------------------
75+
| Auto-detect Starter Kit
76+
|--------------------------------------------------------------------------
77+
|
78+
| Automatically detect which starter kit you're using based on
79+
| package.json dependencies and set appropriate defaults.
80+
|
81+
*/
82+
'auto_detect' => env('UPSTREAM_AUTO_DETECT', true),
83+
6084
/*
6185
|--------------------------------------------------------------------------
6286
| Starter Kit Presets
@@ -99,14 +123,4 @@
99123
],
100124
],
101125

102-
/*
103-
|--------------------------------------------------------------------------
104-
| Auto-detect Starter Kit
105-
|--------------------------------------------------------------------------
106-
|
107-
| Automatically detect which starter kit you're using based on
108-
| package.json dependencies and set appropriate defaults.
109-
|
110-
*/
111-
'auto_detect' => env('UPSTREAM_AUTO_DETECT', true),
112126
];

src/Console/Commands/UpstreamSyncCommand.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public function handle(): int
2727
{
2828
$cfg = config('upstream');
2929

30+
// Apply default preset if no specific configuration is set
31+
$cfg = $this->applyDefaultPreset($cfg);
32+
3033
// Run tests if requested
3134
if ($this->option('test')) {
3235
if (!$this->runTests($cfg)) {
@@ -207,6 +210,38 @@ private function runTests(array $cfg): bool
207210
return $allPassed;
208211
}
209212

213+
private function applyDefaultPreset(array $cfg): array
214+
{
215+
// Check if we already have a specific upstream URL configured
216+
if (!empty($cfg['upstream_url']) && $cfg['upstream_url'] !== 'https://github.com/laravel/vue-starter-kit.git') {
217+
return $cfg;
218+
}
219+
220+
// Check if we have a default preset configured
221+
$defaultPreset = $cfg['default_preset'] ?? null;
222+
if (!$defaultPreset || !isset($cfg['presets'][$defaultPreset])) {
223+
return $cfg;
224+
}
225+
226+
// Apply the default preset configuration
227+
$preset = $cfg['presets'][$defaultPreset];
228+
229+
// Merge preset configuration with existing config
230+
$cfg['upstream_url'] = $preset['upstream_url'];
231+
$cfg['upstream_branch'] = $preset['upstream_branch'] ?? $cfg['upstream_branch'];
232+
233+
// Merge hooks if they exist in the preset
234+
if (isset($preset['post_update'])) {
235+
$cfg['post_update'] = array_merge($cfg['post_update'], $preset['post_update']);
236+
}
237+
238+
if (isset($preset['pre_update'])) {
239+
$cfg['pre_update'] = array_merge($cfg['pre_update'], $preset['pre_update']);
240+
}
241+
242+
return $cfg;
243+
}
244+
210245
private function testGitBinary(array $cfg): bool
211246
{
212247
$git = new VersionControl((string) $cfg['git_binary'], (string) $cfg['working_dir']);

0 commit comments

Comments
 (0)