createFtsUtilsFile function

void createFtsUtilsFile()

Implementation

void createFtsUtilsFile() {
  var fileContent = kFtsUtils;
  // fileContent = fileContent.replaceAll('##importPath', import);

  var resolveTranslationCode = '';
  var imports = [
    '${p.basename(config.dartOutputDir)}.dart',
    "package:flutter/widgets.dart",
    "package:flutter/foundation.dart",
  ];

  if (config.hasOutputJsonDir) {
    imports.addAll([
      "dart:convert",
      "package:flutter/foundation.dart",
      "package:flutter/services.dart",
    ]);

    fileContent =
        fileContent.replaceAll('##loadJsonSetLocale', kLoadJsonSetLocale);
    fileContent =
        fileContent.replaceAll('##loadJsonFallback', kLoadJsonFallback);
    var loadJsonString = kLoadJsonMethod;

    // var jsonOutput = config.outputJsonTemplate;
    var jsonOutputDir = '${p.dirname(config.outputJsonTemplate)}/';
    loadJsonString = loadJsonString.replaceAll('##jsonDir', jsonOutputDir);
    fileContent = fileContent.replaceAll('##loadJsonMethod', loadJsonString);

    fileContent = fileContent.replaceAll(
        '##decodeTranslationMethod', kDecodeTranslationMethod);
    resolveTranslationCode = kResolveTranslationJson;
  } else {
    fileContent =
        fileContent.replaceAll('##loadJsonSetLocale', '_notifyUpdate();');
    fileContent = fileContent.replaceAll('##loadJsonFallback', '');
    fileContent = fileContent.replaceAll('##loadJsonMethod', '');
    fileContent = fileContent.replaceAll('##decodeTranslationMethod', '');
    if (config.useDartMaps == false) {
      resolveTranslationCode = kResolveTranslationJson;
    } else {
      resolveTranslationCode = kResolveTranslationMap;
    }
  }

  /// only when using `keys_id: true`
  fileContent = fileContent.replaceAll(
    '##translationMapUtils',
    config.validTKeyFile ? kTrKeysUtils : '',
  );
  fileContent = fileContent.replaceAll(
    '##ftsStringExtensionSource',
    config.validTKeyFile ? kFtsStringExtensionSource : '',
  );

  // --
  fileContent =
      fileContent.replaceAll('##resolveTranslations', resolveTranslationCode);

  // --
  fileContent = fileContent.replaceFirst(
    '##argsPattern',
    config.paramFtsUtilsArgsPattern,
  );
  fileContent =
      fileContent.replaceAll('##tData', config.dartTranslationClassname);

  var patt = config.paramOutputPattern;
  if (patt.isEmpty || patt == '*') {
    patt = '{*}';
  }
  patt = patt.replaceFirst('*', '\$key');
  fileContent = fileContent.replaceFirst(
    '##namedArgsPattern',
    patt,
  );

  var importString = imports.map((e) => "import '$e';").join('\n');
  fileContent = fileContent.replaceAll('##imports', importString);

  saveString(config.dartFtsUtilsPath, fileContent);

  // trace("Base name? ${}");
  // exportPaths.sort();
  // var fileContents = exportPaths
  //     .map((path) => 'export "${p.relative(path, from: dir)}";')
  //     .join('\n');
  // var exportFilePath = p.join(dir, p.basename(dir) + '.dart');
  // print("EXPORT PATH: $exportFilePath");
}