Skip to content

Commit 1452e7c

Browse files
committed
fix(cli): resolve stub paths, injection formatting, and update README
- Fix stub path resolution in InstallCommand and PublishCommand (resolve from .parent instead of .parent.parent for symlinked envs) - Fix code injection regex to use multiline ^ anchors for clean line breaks - Update README with correct package name and all 7 CLI commands - Remove legacy StatusCommand (replaced by DoctorCommand) - Clean up legacy test files replaced by new TDD suite - Update e2e tests for Kernel-based single entry point
1 parent b2a2926 commit 1452e7c

18 files changed

Lines changed: 131 additions & 1342 deletions

README.md

Lines changed: 89 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The fastest way to set up notifications in your Flutter Magic project:
1818

1919
```bash
2020
# Run interactive installation wizard
21-
dart run fluttersdk_magic_notifications:install
21+
dart run magic_notifications install
2222
```
2323

2424
The CLI will:
@@ -32,17 +32,17 @@ The CLI will:
3232

3333
```bash
3434
# Non-interactive mode (for CI/CD)
35-
dart run fluttersdk_magic_notifications:install \
35+
dart run magic_notifications install \
3636
--non-interactive \
3737
--app-id YOUR_ONESIGNAL_APP_ID \
3838
--platforms android,ios,web
3939

4040
# Disable soft prompt
41-
dart run fluttersdk_magic_notifications:install \
41+
dart run magic_notifications install \
4242
--no-soft-prompt
4343

4444
# Web options: Safari Web ID and Notify Button
45-
dart run fluttersdk_magic_notifications:install \
45+
dart run magic_notifications install \
4646
--non-interactive \
4747
--app-id YOUR_APP_ID \
4848
--platforms web \
@@ -68,8 +68,8 @@ Add to your `pubspec.yaml`:
6868

6969
```yaml
7070
dependencies:
71-
fluttersdk_magic_notifications:
72-
path: ./plugins/fluttersdk_magic_notifications
71+
magic_notifications:
72+
path: ./plugins/magic_notifications
7373
```
7474
7575
Then run:
@@ -291,7 +291,7 @@ Get your Safari Web ID from: OneSignal Dashboard → Settings → Platforms →
291291
Or use the CLI to generate this automatically:
292292

293293
```bash
294-
dart run fluttersdk_magic_notifications:install \
294+
dart run magic_notifications install \
295295
--non-interactive \
296296
--app-id YOUR_APP_ID \
297297
--platforms web \
@@ -321,7 +321,7 @@ Add GCM sender ID:
321321
In your app's `lib/config/app.dart`:
322322

323323
```dart
324-
import 'package:fluttersdk_magic_notifications/fluttersdk_magic_notifications.dart';
324+
import 'package:magic_notifications/magic_notifications.dart';
325325
326326
final appConfig = {
327327
'name': 'Your App',
@@ -363,7 +363,7 @@ The recommended approach is to start polling when the authenticated layout mount
363363

364364
```dart
365365
// In your AppLayout or AuthenticatedLayout widget:
366-
import 'package:fluttersdk_magic_notifications/fluttersdk_magic_notifications.dart';
366+
import 'package:magic_notifications/magic_notifications.dart';
367367
368368
class _AppLayoutState extends State<AppLayout> {
369369
@override
@@ -385,7 +385,7 @@ class _AppLayoutState extends State<AppLayout> {
385385
In your `AuthController` or login handler:
386386

387387
```dart
388-
import 'package:fluttersdk_magic_notifications/fluttersdk_magic_notifications.dart';
388+
import 'package:magic_notifications/magic_notifications.dart';
389389
390390
Future<void> onLoginSuccess(User user) async {
391391
// 1. Request push notification permission
@@ -493,16 +493,18 @@ For framework-specific setup instructions, see:
493493

494494
## CLI Commands
495495

496+
All commands use the single entry point `dart run magic_notifications [command]`:
497+
496498
### Install
497499

498500
Interactive wizard to set up notifications:
499501

500502
```bash
501503
# Interactive mode
502-
dart run fluttersdk_magic_notifications:install
504+
dart run magic_notifications install
503505

504506
# Non-interactive mode
505-
dart run fluttersdk_magic_notifications:install \
507+
dart run magic_notifications install \
506508
--non-interactive \
507509
--app-id YOUR_APP_ID \
508510
--platforms android,ios,web \
@@ -515,72 +517,124 @@ Update notification configuration:
515517

516518
```bash
517519
# Show current configuration
518-
dart run fluttersdk_magic_notifications:configure --show
520+
dart run magic_notifications configure --show
519521

520522
# Update OneSignal App ID
521-
dart run fluttersdk_magic_notifications:configure --app-id NEW_APP_ID
523+
dart run magic_notifications configure --app-id NEW_APP_ID
522524

523525
# Update polling interval (5-600 seconds)
524-
dart run fluttersdk_magic_notifications:configure --polling-interval 60
526+
dart run magic_notifications configure --polling-interval 60
525527

526528
# Enable/disable soft prompt
527-
dart run fluttersdk_magic_notifications:configure --soft-prompt
528-
dart run fluttersdk_magic_notifications:configure --no-soft-prompt
529+
dart run magic_notifications configure --soft-prompt
530+
dart run magic_notifications configure --no-soft-prompt
529531
```
530532

531-
### Status
533+
### Doctor
532534

533-
Check installation and configuration status:
535+
Check installation and configuration health:
534536

535537
```bash
536-
# Check status
537-
dart run fluttersdk_magic_notifications:status
538+
# Run health check
539+
dart run magic_notifications doctor
538540

539541
# Verbose output
540-
dart run fluttersdk_magic_notifications:status --verbose
542+
dart run magic_notifications doctor --verbose
541543
```
542544

543545
Verifies:
544546
- Plugin installed in `pubspec.yaml`
545-
- Configuration file exists
546-
- Platform-specific setup (Android, iOS, Web)
547-
- Lists any missing requirements
547+
- Configuration file exists at `lib/config/notifications.dart`
548+
- Config validation: App ID format, polling interval range
549+
- Platform setup (Android, iOS, Web)
550+
551+
Exits with code `0` if all checks pass, `1` if any check fails.
548552

549553
### Test
550554

551555
Send test notifications to verify setup:
552556

553557
```bash
554558
# Preview notification (dry run)
555-
dart run fluttersdk_magic_notifications:test --dry-run
559+
dart run magic_notifications test --dry-run
556560

557561
# Send test database notification
558-
dart run fluttersdk_magic_notifications:test
562+
dart run magic_notifications test
559563

560564
# Send custom notification
561-
dart run fluttersdk_magic_notifications:test \
565+
dart run magic_notifications test \
562566
--title "Hello" \
563567
--body "World"
564568

565569
# Send push notification
566-
dart run fluttersdk_magic_notifications:test \
570+
dart run magic_notifications test \
567571
--channel push \
568572
--api-url http://localhost:8000
569573

570574
# Test different channels
571-
dart run fluttersdk_magic_notifications:test --channel database
572-
dart run fluttersdk_magic_notifications:test --channel push
573-
dart run fluttersdk_magic_notifications:test --channel mail
575+
dart run magic_notifications test --channel database
576+
dart run magic_notifications test --channel push
577+
dart run magic_notifications test --channel mail
578+
```
579+
580+
### Uninstall
581+
582+
Remove plugin integration from your project:
583+
584+
```bash
585+
# Interactive uninstall (asks for confirmation)
586+
dart run magic_notifications uninstall
587+
588+
# Skip confirmation prompt
589+
dart run magic_notifications uninstall --force
574590
```
575591

592+
Removes:
593+
- `lib/config/notifications.dart`
594+
- `magic_notifications` dependency from `pubspec.yaml`
595+
- `NotificationServiceProvider` injection from `lib/config/app.dart`
596+
- `notificationConfig` factory from `lib/main.dart`
597+
598+
> [!WARNING]
599+
> Platform files (`android/app/src/main/AndroidManifest.xml`, `web/index.html`,
600+
> `web/OneSignalSDKWorker.js`) are NOT reverted automatically — manual cleanup required.
601+
602+
### Publish
603+
604+
Laravel vendor:publish style — copies the notification config stub to your project:
605+
606+
```bash
607+
# Publish config stub (skips if already exists)
608+
dart run magic_notifications publish
609+
610+
# Overwrite existing config
611+
dart run magic_notifications publish --force
612+
```
613+
614+
Copies the default `notifications.dart` config to `lib/config/notifications.dart`.
615+
After publishing, update `YOUR_ONESIGNAL_APP_ID` with your actual OneSignal App ID.
616+
617+
### Channels
618+
619+
List all notification channels and their current status:
620+
621+
```bash
622+
dart run magic_notifications channels
623+
```
624+
625+
Shows each channel (database, push, mail) with:
626+
- Enabled / disabled status
627+
- Polling interval (database channel)
628+
- App ID presence (masked, push channel)
629+
576630
## Usage
577631

578632
### Display Notifications in UI
579633

580634
Use the `NotificationDropdownWithStream` widget:
581635

582636
```dart
583-
import 'package:fluttersdk_magic_notifications/fluttersdk_magic_notifications.dart';
637+
import 'package:magic_notifications/magic_notifications.dart';
584638
585639
AppBar(
586640
actions: [
@@ -634,7 +688,7 @@ public function routeNotificationForOneSignal(): array
634688
### Create Custom Notifications
635689

636690
```dart
637-
import 'package:fluttersdk_magic_notifications/fluttersdk_magic_notifications.dart';
691+
import 'package:magic_notifications/magic_notifications.dart';
638692
639693
class CustomNotification extends Notification {
640694
final String title;
@@ -689,7 +743,7 @@ await Notify.updatePreferences(NotificationPreference(
689743
### Run Plugin Tests
690744

691745
```bash
692-
cd plugins/fluttersdk_magic_notifications
746+
cd plugins/magic_notifications
693747
flutter test
694748
```
695749

bin/magic_notifications.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,27 @@ import 'package:magic_cli/magic_cli.dart' hide InstallCommand;
22

33
import 'package:magic_notifications/src/cli/commands/install_command.dart';
44
import 'package:magic_notifications/src/cli/commands/configure_command.dart';
5-
import 'package:magic_notifications/src/cli/commands/status_command.dart';
65
import 'package:magic_notifications/src/cli/commands/test_command.dart';
6+
import 'package:magic_notifications/src/cli/commands/doctor_command.dart';
7+
import 'package:magic_notifications/src/cli/commands/uninstall_command.dart';
8+
import 'package:magic_notifications/src/cli/commands/publish_command.dart';
9+
import 'package:magic_notifications/src/cli/commands/channels_command.dart';
10+
11+
712

813
/// Magic Notifications CLI entry point.
914
void main(List<String> args) async {
1015
final kernel = Kernel();
1116

12-
// 1. Register notification specific commands.
17+
// 1. Register all notification commands.
1318
kernel.registerMany([
1419
InstallCommand(),
1520
ConfigureCommand(),
16-
StatusCommand(),
1721
TestCommand(),
22+
DoctorCommand(),
23+
UninstallCommand(),
24+
PublishCommand(),
25+
ChannelsCommand(),
1826
]);
1927

2028
// 2. Execute requested command.

lib/src/cli/commands/install_command.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class InstallCommand extends Command {
358358
if (!content.contains('NotificationServiceProvider')) {
359359
ConfigEditor.insertCodeBeforePattern(
360360
filePath: appPath,
361-
pattern: RegExp(r'\s+\]\,\s*\},?'),
361+
pattern: RegExp(r'^\s+\],', multiLine: true),
362362
code: ' (app) => NotificationServiceProvider(app),\n',
363363
);
364364
success('Injected NotificationServiceProvider into lib/config/app.dart');
@@ -376,7 +376,7 @@ class InstallCommand extends Command {
376376
if (!content.contains('notificationConfig')) {
377377
ConfigEditor.insertCodeBeforePattern(
378378
filePath: mainPath,
379-
pattern: RegExp(r'\s+\]\,\s*\);'),
379+
pattern: RegExp(r'^\s+\],', multiLine: true),
380380
code: ' () => notificationConfig,\n',
381381
);
382382
success('Injected notificationConfig into lib/main.dart');
@@ -463,9 +463,7 @@ class InstallCommand extends Command {
463463
if (rootUri.startsWith('file://')) {
464464
parsedPath = Uri.parse(rootUri).toFilePath();
465465
} else if (rootUri.startsWith('../')) {
466-
parsedPath = Uri.parse(rootUri).toFilePath();
467466
parsedPath = File(packageConfigPath)
468-
.parent
469467
.parent
470468
.uri
471469
.resolve(rootUri)
@@ -491,8 +489,8 @@ class InstallCommand extends Command {
491489
info(' 1. Run: ${ConsoleStyle.cyan}flutter pub get${ConsoleStyle.reset}');
492490
info(' 2. Configure your OneSignal dashboard');
493491
info(
494-
' 3. Test: ${ConsoleStyle.cyan}dart run magic_notifications:test --dry-run${ConsoleStyle.reset}');
492+
' 3. Test: ${ConsoleStyle.cyan}dart run magic_notifications test --dry-run${ConsoleStyle.reset}');
495493
info(
496-
' 4. Check status: ${ConsoleStyle.cyan}dart run magic_notifications:status${ConsoleStyle.reset}');
494+
' 4. Check status: ${ConsoleStyle.cyan}dart run magic_notifications doctor${ConsoleStyle.reset}');
497495
}
498496
}

lib/src/cli/commands/publish_command.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ class PublishCommand extends Command {
124124
parsedPath = Uri.parse(rootUri).toFilePath();
125125
} else if (rootUri.startsWith('../')) {
126126
parsedPath = File(packageConfigPath)
127-
.parent
128127
.parent
129128
.uri
130129
.resolve(rootUri)

0 commit comments

Comments
 (0)