run method

  1. @override
void run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
void run() {
  final argGitsYaml = argResults.getOptionGitsYaml();

  YamlHelper.validateGitsYaml(argGitsYaml);

  final gitsYamlHelper = LocalizationHelper(argGitsYaml);

  final dir = find(
    '*',
    recursive: false,
    workingDirectory: gitsYamlHelper.arbDir,
    types: [Find.directory],
  );

  dir.forEach((pathDir) {
    final dirName = pathDir.split(separator).last;
    final pathArbDefault = join(gitsYamlHelper.arbDir, '$dirName.arb');

    final filesArb = find(
      '*.arb',
      workingDirectory: pathDir,
      recursive: true,
      types: [Find.file],
    );

    String merged = '{"@@locale": "$dirName"}';

    if (gitsYamlHelper.replace && exists(pathArbDefault)) {
      merged = readFile(pathArbDefault);
    }

    filesArb.forEach((pathArb) {
      final arb = readFile(pathArb);
      final sorted = sortARB(arb);
      pathArb.write(sorted);

      merged = mergeARBs(merged, sorted);
    });

    pathArbDefault.write(merged);
  });

  FlutterHelper.run(
      'gen-l10n --arb-dir="${gitsYamlHelper.arbDir}" --template-arb-file="${gitsYamlHelper.templateArbFile}" --output-localization-file="${gitsYamlHelper.outputLocalizationFile}" --output-class="${gitsYamlHelper.outputClass}" --output-dir="${gitsYamlHelper.outputDir}" --no-synthetic-package');

  StatusHelper.success('generate l10n to ${gitsYamlHelper.outputDir}');
}