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() async {
  final argMorphemeYaml = argResults.getOptionMorphemeYaml();

  YamlHelper.validateMorphemeYaml(argMorphemeYaml);

  final morphemeYamlHelper = LocalizationHelper(argMorphemeYaml);

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

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

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

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

    if (morphemeYamlHelper.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);
  });

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

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