applyConfig function

Future<bool> applyConfig(
  1. BlueprintConfig config
)

Applies config using the engine, streaming progress to stdout.

Implementation

Future<bool> applyConfig(BlueprintConfig config) async {
  final targetDir = config.outputDir == '.' ? Directory.current.path : config.outputDir;
  await Directory(targetDir).create(recursive: true);

  var currentStep = 0;
  var totalSteps = 0;
  SpinnerState? spinnerState;

  final bridge = EngineBridge(onMessage: (msg) {
    if (msg is ProgressMessage) {
      spinnerState?.done();
      currentStep = msg.step;
      totalSteps = msg.total;
      spinnerState = Spinner(
        icon: 'āœ“',
        rightPrompt: (done) => done
            ? '[$currentStep/$totalSteps] ${msg.pack}'
            : '[$currentStep/$totalSteps] ${msg.pack} ...',
      ).interact();
    } else if (msg is LogMessage) {
      if (msg.level == 'error') {
        stderr.writeln('  āœ— ${msg.message}');
      }
    }
  });

  try {
    final ok = await bridge.run(config, targetDir);
    spinnerState?.done();
    return ok;
  } catch (e) {
    spinnerState?.done();
    stderr.writeln('\nāœ— Engine error: $e');
    return false;
  }
}