applyConfig function
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;
}
}