appConfigContent static method

String appConfigContent({
  1. required StubDriver stubs,
  2. required List<String> providerImports,
  3. required List<String> providerEntries,
  4. List<String> authProviderEntries = const [],
  5. List<String>? searchPaths,
})

Generates lib/config/app.dart with a dynamic providers list.

Stub loading is routed through the per-install StubDriver supplied by the caller (the active InstallContext's stubs field) and an explicit searchPaths list pointing at magic's bundled assets/stubs/. The static StubLoader defaults resolve to fluttersdk_artisan's own assets/stubs/, where magic-only stubs do not exist; routing through the driver preserves multi-publisher correctness and lets in-memory test drivers serve fixture content without touching the host filesystem.

stubs — the active StubDriver (production: RealStubDriver; tests: an in-memory fixture driver). Required so resolution honours the magic-side stub bundle rather than the substrate's default. searchPaths — directories to search before the driver's defaults. In production the caller resolves magic's stub directory via the consumer's package_config.json and passes it here; pass null when the test driver ignores searchPaths. providerImports — additional provider import statements beyond the always-present RouteServiceProvider and AppServiceProvider. providerEntries — infrastructure (app) => Provider(app), strings. These boot BEFORE AppServiceProvider and AuthServiceProvider. authProviderEntries — auth-related providers that must boot AFTER AppServiceProvider (which registers setUserFactory).

Implementation

static String appConfigContent({
  required StubDriver stubs,
  required List<String> providerImports,
  required List<String> providerEntries,
  List<String> authProviderEntries = const [],
  List<String>? searchPaths,
}) {
  final allImports = [
    "import 'package:magic/magic.dart';",
    "import '../app/providers/app_service_provider.dart';",
    "import '../app/providers/route_service_provider.dart';",
    ...providerImports,
  ].join('\n');

  // Boot order matters:
  // 1. RouteServiceProvider — routes
  // 2. Infrastructure providers — cache, database, network, vault, etc.
  // 3. AppServiceProvider — registers userFactory via setUserFactory()
  // 4. AuthServiceProvider — calls Auth.restore() (needs userFactory)
  final allProviders = [
    '      (app) => RouteServiceProvider(app),',
    ...providerEntries.map((e) => '      $e'),
    '      (app) => AppServiceProvider(app),',
    ...authProviderEntries.map((e) => '      $e'),
  ].join('\n');

  return stubs.replace(
    stubs.load('install/app_config', searchPaths: searchPaths),
    {'allImports': allImports, 'allProviders': allProviders},
  );
}