cook method

  1. @override
void cook()
override

cooks the brick, and outputs the files to outputDir

Implementation

@override
void cook() {
  final output = di<FileSystem>().directory(outputDir);
  if (output.existsSync()) {
    output.deleteSync(recursive: true);
  }

  final names = <String>{};

  if (partialConfigs != null) {
    for (final MapEntry(key: fileName) in partialConfigs!.entries) {
      if (names.contains(fileName)) {
        throw BrickException(
          brick: name,
          reason: 'Duplicate partials ("$fileName") in $name',
        );
      }

      names.add(fileName);
    }
  }

  final done = di<Logger>().progress('Writing Brick: $name');

  if (watch) {
    watcher.addEvent((_) {
      try {
        _putInTheOven(
          done: done,
        );
      } catch (_) {
        done.fail('Failed to cook brick $name');
      }
    });

    if (masonBrick != null) {
      watcher.addEvent((_) => masonBrick?.check(this));
    }

    watcher.start();

    if (watcher.hasRun) {
      return;
    }
  }

  try {
    _putInTheOven(
      done: done,
    );
  } catch (_) {
    done.fail('Failed to cook brick $name');
  }

  masonBrick?.check(this);
}