Skip to content

Commit 112a871

Browse files
authored
feat(install): generate routing config with URL strategy support (#7)
* feat(install): generate routing config with URL strategy support * fix(test): update install tests for routing config (8→9 configs, 6→7 without-auth/db)
1 parent 18fd905 commit 112a871

7 files changed

Lines changed: 42 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ This project follows [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.0.
88

99
## [Unreleased]
1010

11+
### ✨ New Features
12+
13+
- **Routing Config**: Generate `config/routing.dart` with URL strategy setting during `magic install` — enables clean web URLs via `url_strategy: 'path'`
14+
1115
---
1216

1317
## [0.0.1-alpha.4] - 2026-04-06

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ lib/src/
3131
│ └── install_stubs.dart # Install-specific stub utilities
3232
└── helpers/ # Static utilities: file I/O, YAML, console styling, config editing
3333
34-
assets/stubs/ # .stub templates (14 generator + 30 install stubs)
34+
assets/stubs/ # .stub templates (17 generator + 19 install stubs)
3535
```
3636

3737
**Lifecycle**: `bin/magic.dart``Kernel.handle(args)` → lookup command by `args[0]``command.configure(parser)` → parse args → `command.handle()`

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ lib/
153153
│ ├── database.dart
154154
│ ├── logging.dart
155155
│ ├── network.dart
156+
│ ├── routing.dart
156157
│ └── view.dart
157158
├── app/
158159
│ ├── controllers/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// Routing Configuration.
2+
///
3+
/// Controls URL strategy and other routing behavior.
4+
/// Set `'url_strategy'` to `'path'` for clean web URLs (/dashboard instead of /#/dashboard).
5+
/// See: https://magic.fluttersdk.com/docs/basics/routing#url-strategy
6+
Map<String, dynamic> get routingConfig => {
7+
'routing': {
8+
'url_strategy': null, // 'path' for clean URLs on web, null for default hash strategy
9+
},
10+
};

lib/src/commands/install_command.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ class InstallCommand extends Command {
263263
InstallStubs.viewConfigContent(),
264264
);
265265

266+
_writeIfNotExists(
267+
path.join(root, 'lib/config/routing.dart'),
268+
InstallStubs.routingConfigContent(),
269+
);
270+
266271
if (!withoutAuth) {
267272
_writeIfNotExists(
268273
path.join(root, 'lib/config/auth.dart'),
@@ -364,10 +369,15 @@ class InstallCommand extends Command {
364369

365370
final configImports = <String>[
366371
"import 'config/app.dart';",
372+
"import 'config/routing.dart';",
367373
"import 'config/view.dart';",
368374
];
369375

370-
final configFactories = <String>['() => appConfig', '() => viewConfig'];
376+
final configFactories = <String>[
377+
'() => appConfig',
378+
'() => routingConfig',
379+
'() => viewConfig',
380+
];
371381

372382
if (!withoutAuth) {
373383
configImports.add("import 'config/auth.dart';");

lib/src/stubs/install_stubs.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ class InstallStubs {
123123
return StubLoader.load('install/broadcasting_config');
124124
}
125125

126+
/// Generates `lib/config/routing.dart` with URL strategy config.
127+
///
128+
/// Default `url_strategy: null` preserves hash-based URLs.
129+
/// Set to `'path'` for clean web URLs (`/dashboard` instead of `/#/dashboard`).
130+
static String routingConfigContent() {
131+
return StubLoader.load('install/routing_config');
132+
}
133+
126134
// ---------------------------------------------------------------------------
127135
// Service Providers
128136
// ---------------------------------------------------------------------------

test/commands/install_command_test.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,13 @@ void main() {
181181
);
182182
});
183183

184-
test('creates all 8 config files', () {
184+
test('creates all 9 config files', () {
185185
final configs = [
186186
'app.dart',
187187
'auth.dart',
188188
'database.dart',
189189
'network.dart',
190+
'routing.dart',
190191
'view.dart',
191192
'cache.dart',
192193
'logging.dart',
@@ -370,7 +371,7 @@ void main() {
370371
);
371372
});
372373

373-
test('imports all 8 configs by default', () async {
374+
test('imports all 9 configs by default', () async {
374375
cmd.arguments = parser.parse([]);
375376
await cmd.handle();
376377

@@ -382,6 +383,7 @@ void main() {
382383
"import 'config/auth.dart'",
383384
"import 'config/database.dart'",
384385
"import 'config/network.dart'",
386+
"import 'config/routing.dart'",
385387
"import 'config/view.dart'",
386388
"import 'config/cache.dart'",
387389
"import 'config/logging.dart'",
@@ -790,15 +792,15 @@ void main() {
790792
expect(content, isNot(contains('DatabaseServiceProvider')));
791793
});
792794

793-
test('creates only 6 config files', () {
795+
test('creates only 7 config files', () {
794796
final dir = Directory('${tempDir.path}/lib/config');
795797
final files = dir.listSync().whereType<File>().toList();
796798

797799
expect(
798800
files.length,
799-
6,
801+
7,
800802
reason:
801-
'Should create exactly 6 config files (app, network, view, cache, logging, broadcasting)',
803+
'Should create exactly 7 config files (app, network, routing, view, cache, logging, broadcasting)',
802804
);
803805
});
804806
});

0 commit comments

Comments
 (0)