genAst function

void genAst(
  1. List<String> arguments
)

Implementation

void genAst(List<String> arguments) async {
  exitCode = 0; // presume success
  final parser = ArgParser()
    ..addFlag('help',
        negatable: false, abbr: 'h', help: 'Displays help infomation')
    ..addOption('type',
        abbr: 't', defaultsTo: 'widget', help: '选择转换控件的类型,widget/page');

  argResults = parser.parse(arguments);

  switch (argResults['type']) {
    case 'widget':
      type = WidgetType.widget;
      break;
    case 'page':
      type = WidgetType.page;
      break;
    default:
      type = WidgetType.widget;
      break;
  }

  if (argResults['help']) {
    stdout.writeln('''
  ** HELP **
  ${parser.usage}
  ''');
    return;
  }
  stdout.writeln(argResults.rest);
  final paths = argResults.rest;
  if (paths.isEmpty) {
    stdout.writeln('No file found');
  } else {
    var newRootPath = await writeFile(paths[0]);
    stdout.writeln(newRootPath);
    stdout.write('type:${argResults['type']}');

    var _results = conversionToYzJson(await generate(paths[0]), type);
    // _selectedRsult = null;
    if (_results != null && _results.isNotEmpty) {
      _results.forEach((result) {
        var newFile = File(newRootPath + result.functionName + '.json');
        newFile.writeAsStringSync(result.resultJsonString);
      });
    }
  }
}