private void SaveFiles(IDictionary <string, string> filesOut, YamlConfig config) { var copy = new HashSet <string>(); var skip = new HashSet <string>(); foreach (var fileOut in filesOut) { var srcFile = GetSaveFilePath(config.ConfigFolder, fileOut.Key); var srcFolder = Path.GetDirectoryName(srcFile); var outFile = GetSaveFilePath(config.OutputFolder, fileOut.Key); var outFolder = Path.GetDirectoryName(outFile); var same = srcFolder == outFolder; switch (config.MergeStrategy) { case MergeStrategy.Append: if (!File.Exists(srcFile)) { EnsureDirectory(outFolder); File.WriteAllText(outFile, fileOut.Value); } break; case MergeStrategy.Overwrite: EnsureDirectory(outFolder); File.WriteAllText(outFile, fileOut.Value); break; case MergeStrategy.Skip: if (!skip.Contains(srcFolder) && (copy.Contains(srcFolder) || !Directory.Exists(srcFolder) || !Directory.GetFileSystemEntries(srcFolder).Any())) { EnsureDirectory(outFolder); File.WriteAllText(outFile, fileOut.Value); copy.Add(srcFolder); } else { skip.Add(srcFolder); } break; default: throw new NotImplementedException($"Merge strategy '{_config.MergeStrategy}' is not yet implemented!"); } } }
private YamlConfig MergeOptions(ScaffolderOptions options, YamlConfig config) { config.MergeStrategy = options.MergeStrategy; // set config folder var configFile = GetRootedPath(options.ConfigFile); config.ConfigFolder = Path.GetDirectoryName(configFile); // set output folder config.OutputFolder = GetRootedPath(options.OutputFolder); config.ApiUrlPrefix = config.ApiUrlPrefix?.TrimEnd('/'); return(config); }
public Scaffolder([NotNull] ScaffolderOptions options, [NotNull] YamlConfig config, [NotNull] IVerbService verbService) { _config = MergeOptions(options, config); _verbService = verbService; }