private string GetOutputPath(File file) { var path = file.FullName; var directory = GetOutputDirectory(file, _templatePath, path); var filename = GetOutputFilename(file, path); var outputPath = Path.Combine(directory, filename); for (var i = 1; i < 1000; i++) { var item = FindProjectItem(outputPath); if (item == null) { return(outputPath); } var mappedSourceFile = GetMappedSourceFile(item); if (mappedSourceFile == null || path.Equals(mappedSourceFile, StringComparison.InvariantCultureIgnoreCase)) { return(outputPath); } var name = filename.EndsWith(".d.ts", StringComparison.OrdinalIgnoreCase) ? filename.Substring(0, filename.Length - 5) : filename.Substring(0, filename.LastIndexOf(".", StringComparison.Ordinal)); var extension = filename.EndsWith(".d.ts", StringComparison.OrdinalIgnoreCase) ? ".d.ts" : filename.Substring(filename.LastIndexOf(".", StringComparison.Ordinal)); outputPath = Path.Combine(directory, $"{name} ({i}){extension}"); } throw new Exception("GetOutputPath"); }
public string Render(File file, out bool success) { try { return(Parser.Parse(_projectItem, file.FullName, _template.Value, _customExtensions, file, out success)); } catch (Exception ex) { Log.Error(ex.Message + " Template: " + _templatePath); success = false; return(null); } }
public void RenameFile(File file, string oldPath, string newPath) { var item = GetExistingItem(oldPath); if (item != null) { if (Path.GetFileName(oldPath)?.Equals(Path.GetFileName(newPath)) ?? false) { SetMappedSourceFile(item, newPath); return; } var newOutputPath = GetOutputPath(file); item.Name = Path.GetFileName(newOutputPath); SetMappedSourceFile(item, newPath); } }
public bool RenderFile(File file) { bool success; var output = Render(file, out success); if (success) { if (output == null) { DeleteFile(file.FullName); } else { SaveFile(file, output, ref success); } } return(success); }
private string GetOutputDirectory(File file, string templatePath, string sourcePath) { try { if (_configuration.Value.OutputDirectoryFactory != null) { var path = _configuration.Value.OutputDirectoryFactory(file); if (Path.IsPathRooted(path)) { return(path); } return(Path.Combine(Path.GetDirectoryName(templatePath), path)); } } catch (Exception exception) { Log.Warn($"Can't get output directory for '{templatePath}' ({exception.Message})"); } return(Path.GetDirectoryName(templatePath)); }
protected virtual void SaveFile(File file, string output, ref bool success) { var outputPath = GetOutputPath(file); if (string.Equals(file.FullName, outputPath, StringComparison.InvariantCultureIgnoreCase)) { Log.Error("Output filename cannot match source filename."); success = false; return; } ProjectItem item; SaveFile(outputPath, output, out item, ref success); if (item != null) { SetMappedSourceFile(item, file.FullName); } }
private string GetOutputFilename(File file, string sourcePath) { var sourceFilename = Path.GetFileNameWithoutExtension(sourcePath); var extension = GetOutputExtension(); try { if (_configuration.Value.OutputFilenameFactory != null) { var filename = _configuration.Value.OutputFilenameFactory(file); filename = filename .Replace("<", "-") .Replace(">", "-") .Replace(":", "-") .Replace("\"", "-") //.Replace("/", "-") //.Replace("\\", "-") .Replace("|", "-") .Replace("?", "-") .Replace("*", "-"); if (filename.Contains(".") == false) { filename += extension; } return(filename); } } catch (Exception exception) { Log.Warn($"Can't get output filename for '{sourcePath}' ({exception.Message})"); } return(sourceFilename + extension); }