main function

void main(
  1. List<String> args
)

Implementation

void main(List<String> args) {
  Console.init();
  final options = parseOptions(args);
  final output = Directory(options.output);
  final inputDir = Directory(options.path);
  final inputFile = File(options.path);
  final _paths = <String>[];
  if (inputDir.existsSync()) {
    _processDirectory(inputDir, inputDir, output, _paths);
  } else if (inputFile.existsSync()) {
    _paths.add(inputFile.path);
  } else {
    throw Exception('Not a valid path!');
  }

  final template = _getTemplate('widget');
  var progress = ProgressBar(complete: _paths.length);
  var i = 0;
  final parser = GenParser();
  for (final path in _paths) {
    _processFile(output, File(path), template, parser);
    progress.update(++i);
  }
  _getFile(output.path, 'base.dart').writeAsStringSync(_base);
  final files = Directory(p.join(output.path, 'classes')).listSync();
  final imports = files
      .map((item) => "export 'classes/${p.basename(item.path)}';")
      .toList();
  imports.sort();
  _getFile(output.path, 'index.dart').writeAsStringSync(imports.join('\n'));
  final sb = StringBuffer();
  sb.writeln("import 'index.dart';");
  sb.writeln("import 'base.dart';");
  sb.writeln();
  sb.writeln("Map<String, BaseWidget> widgetLibrary = {");
  final List<String> _names = [];
  for (final file in files) {
    final _result = cache.getCache(p.basename(file.path));
    if (_result == null) continue;
    for (final item in _result.file.classes) {
      if (item.isValid) _names.add(item.name);
    }
  }
  _names.sort();
  for (final name in _names) {
    sb.writeln("  '${name}': ${name}Base.readOnly(),");
  }
  sb.writeln('};');
  _getFile(output.path, 'library.dart').writeAsStringSync(sb.toString());
  // writeIndex(_paths, output);
  print(parser.toString());
}